stockprogram.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <view>
  3. <!-- 顶部导航 -->
  4. <fa-navbar :title="pagetitle || '编程工具'"></fa-navbar>
  5. <view >
  6. <HQChartControl ref="HQChartCtrl" DefaultChart="{Type:'KLine'}" DefaultSymbol="000001.sz"> </HQChartControl>
  7. </view>
  8. <!-- 控制图1 !-->
  9. <!-- <view class="button-sp-area">
  10. <button class="mini-btn" type="default" size="mini" @click="ChangeMinutePeriod(1)">分时</button>
  11. <button class="mini-btn" type="default" size="mini" @click="ChangeMinutePeriod(5)">5日</button>
  12. <button class="mini-btn" type="default" size="mini" @click="ChangeKLinePeriod(0)">日K</button>
  13. <button class="mini-btn" type="default" size="mini" @click="ChangeKLinePeriod(1)">周K</button>
  14. <button class="mini-btn" type="default" size="mini" @click="ChangeKLinePeriod(4)">1K</button>
  15. <button class="mini-btn" type="default" size="mini" @click="ChangeKLinePeriod(5)">5K</button>
  16. <button class="mini-btn" type="default" size="mini" @click="ChangeKLinePeriod(6)">15K</button>
  17. <button class="mini-btn" type="default" size="mini" @click="ChangeKLinePeriod(7)">30K</button>
  18. <button class="mini-btn" type="default" size="mini" @click="ChangeKLinePeriod(8)">60K</button>
  19. <button class="mini-btn" type="default" size="mini" @click="ChangeSymbol('600999.sh')">招商证券</button>
  20. <button class="mini-btn" type="default" size="mini" @click="ChangeSymbol('000002.sz')">万科A</button>
  21. </view> -->
  22. <view class="ptip" v-if="showtip">点此按钮重新打开编程框</view>
  23. <!-- 底部导航 -->
  24. <u-popup v-model="showtool" mode="bottom" height="300px" :mask="false" z-index="996">
  25. <view style="background-color: rgb(55, 68, 134); height: 35px;padding: 5px;">
  26. <u-icon name="edit-pen" color="#ffffff" size="48" style="float: left;margin-right: 5px;" @click="editcode()"></u-icon>
  27. <u-tag :text="scripttype?'主图':'副图'" shape="circle" style="float: left;margin-right: 5px;" :mode="scripttype?'light':'dark'" @click="changsctype()"/>
  28. <u-icon name="checkbox-mark" color="#ffffff" size="48" style="float: right;" @click="checkcode()"></u-icon>
  29. <u-tag text="教程" shape="circle" style="float: right;margin-right: 5px;" v-if="studyid>0" @click="openstudy()"/>
  30. <u-action-sheet :list="downoption" @click="downclick" v-model="showdown"></u-action-sheet>
  31. <u-tag type="success" text="下载源码" shape="circle" @click="showdown=!showdown" style="float: right;margin-right: 5px;"/>
  32. </view>
  33. <scroll-view scroll-y="true" :style="viewstyle">
  34. <u-input v-model="mycode" type="textarea" :maxlength="1024" :border="false" v-if="editmode" height="100%" @input="vinInput"/>
  35. <mp-html :content="myhtml" ref="article" width="100%" height="90%" :editable="false" v-if="!editmode"/>
  36. </scroll-view>
  37. <view :style="'height: 50px;background-color: #2d2d2d; color: '+errColor+'; padding-left: 20px;'" v-if="!editmode">{{codeError}}</view>
  38. </u-popup>
  39. <fa-tabbar></fa-tabbar>
  40. </view>
  41. </template>
  42. <script>
  43. import mpHtml from '@/node_modules/mp-html/dist/uni-app/components/mp-html/mp-html'
  44. import HQChartControl from '@/uni_modules/jones-hqchart2/js_sdk/HQChartControl.vue'
  45. import JSHQData from "./hq.data.js"
  46. // #ifdef H5
  47. import HQChart from '@/uni_modules/jones-hqchart2/js_sdk/umychart.uniapp.h5.js'
  48. //HQChart.MARKET_SUFFIX_NAME.GetMarketStatus = (symbol) => { return 2; }
  49. HQChart.JSChart.GetMinuteTimeStringData().CreateSHSZData=()=>{ return JSHQData.HQData.CreateSHSZData(HQChart.JSChart.GetMinuteTimeStringData()); } //替换交易时间段
  50. HQChart.JSChart.GetMinuteCoordinateData().GetSHSZData=(upperSymbol,width)=> { return JSHQData.HQData.GetSHSZData(upperSymbol,width); } //替换X轴刻度信息
  51. // #endif
  52. // #ifndef H5
  53. import {JSCommon} from '@/uni_modules/jones-hqchart2/js_sdk/umychart.wechat.3.0.js'
  54. import {JSConsole} from '@/uni_modules/jones-hqchart2/js_sdk/umychart.console.wechat.js'
  55. import {JSCommonCoordinateData} from '@/uni_modules/jones-hqchart2/js_sdk/umychart.coordinatedata.wechat.js'
  56. import {JSCommonComplier} from "@/uni_modules/jones-hqchart2/js_sdk/umychart.complier.wechat.js"
  57. import { } from "@/uni_modules/jones-hqchart2/js_sdk/umychart.explainer.wechat.js"
  58. JSCommonCoordinateData.MinuteTimeStringData.CreateSHSZData=()=>{ return JSHQData.HQData.CreateSHSZData(JSCommonCoordinateData.MinuteTimeStringData); }
  59. JSCommonCoordinateData.MinuteCoordinateData.GetSHSZData=(upperSymbol,width)=> { return JSHQData.HQData.GetSHSZData(upperSymbol,width); }
  60. //JSCommon.MARKET_SUFFIX_NAME.GetMarketStatus = (symbol) => { return 2; }
  61. //禁用日志
  62. JSConsole.Complier.Log=()=>{ };
  63. JSConsole.Chart.Log=()=>{ };
  64. // #endif
  65. let that;
  66. export default
  67. {
  68. components: { HQChartControl,mpHtml },
  69. data()
  70. {
  71. let data=
  72. {
  73. Symbol:'600000.sh',
  74. ChartWidth:350,
  75. ChartHeight:500,
  76. showtool: true,
  77. showtip:true,
  78. mycode:"JX1:=MA(CLOSE,13);\nJX2:=MA(CLOSE,49);\nDRAWICON(CROSS(JX1,JX2),L,1);\nDRAWICON(CROSS(JX2,JX1),H,2);",
  79. myhtml:"",
  80. scripts:'',
  81. editmode:false,
  82. scripttype:true,
  83. codeError:'',
  84. errColor:'#ff0000',
  85. viewstyle:"height: 200px; background-color: #2d2d2d;",
  86. pagetitle:'',
  87. codeloaded:false,
  88. productid:0,
  89. studyid:0,
  90. downtype:0,
  91. showdown:false,
  92. downoption:[{
  93. text: '复制到剪贴板',
  94. color: 'blue',
  95. fontSize: 28
  96. },
  97. {
  98. text: '下载到电脑安装',
  99. color: 'blue',
  100. fontSize: 28
  101. }
  102. ]
  103. };
  104. return data;
  105. },
  106. watch:{
  107. showtool:function(val){
  108. if(!val){
  109. this.showtip=true;
  110. let that=this;
  111. setTimeout(function(){
  112. that.showtip=false;
  113. },1000);
  114. }
  115. }
  116. },
  117. onLoad(option){
  118. uni.$on("centerButtonClick",(rel)=>{
  119. this.switchtab(rel);
  120. });
  121. if(option.productid){
  122. console.log(option.productid);
  123. this.productid=option.productid;
  124. }
  125. },
  126. onShow()
  127. { console.log('onshow');
  128. uni.getSystemInfo({
  129. success: (res) => {
  130. var width = res.windowWidth;
  131. var height = res.windowHeight;
  132. this.ChartWidth = width;
  133. this.ChartHeight = height - 100;
  134. this.$nextTick(() => {
  135. console.log('createchart');
  136. let that=this;
  137. setTimeout(function(
  138. ){
  139. that.CreateHQChart();
  140. that.codeloaded=false;
  141. that.checkcode();
  142. },1000);
  143. })
  144. }
  145. });
  146. },
  147. onHide()
  148. {
  149. this.ClearHQChart();
  150. },
  151. onUnload()
  152. {
  153. this.ClearHQChart();
  154. },
  155. methods:
  156. { switchtab(index){
  157. console.log('switch');
  158. console.log(index);
  159. let that=this;
  160. if (index==2){
  161. this.showtool=!this.showtool;
  162. if (this.showtool){
  163. this.checkcode();
  164. }
  165. return false;
  166. }
  167. return true;
  168. },
  169. CreateHQChart()
  170. {
  171. var chartHeight=this.ChartHeight;
  172. let hqchartCtrl=this.$refs.HQChartCtrl;
  173. hqchartCtrl.NetworkFilter=this.NetworkFilter; //绑定数据回调
  174. hqchartCtrl.KLine.Option.IsApiPeriod=true; //周期使用api数据
  175. hqchartCtrl.KLine.Option.IsClickShowCorssCursor=true;
  176. hqchartCtrl.KLine.Option.IsAutoUpdate=true; //自动更新
  177. hqchartCtrl.KLine.Option.AutoUpdateFrequency=10000; //更新频率 ms
  178. hqchartCtrl.KLine.Option.KLineTitle = {
  179. IsShowName: false,
  180. IsShowSettingInfo: false,
  181. IsShowDateTime: true
  182. };
  183. //标题设置
  184. hqchartCtrl.KLine.Option.Windows=[{
  185. Script: 'MA1:MA(CLOSE,N);MA2:MA(CLOSE,M);',
  186. Args: [{
  187. Name: 'N',
  188. Value: 13
  189. }, {
  190. Name: 'M',
  191. Value: 49
  192. }],
  193. Name: "我的主图",
  194. Modify: false,
  195. Change: false
  196. },
  197. {
  198. Script: 'DIF:EMA(CLOSE,SHORT)-EMA(CLOSE,LONG);DEA:EMA(DIF,MID);MACD:(DIF-DEA)*2,COLORSTICK;',
  199. Args: [{
  200. Name: 'SHORT',
  201. Value: 12
  202. }, {
  203. Name: 'LONG',
  204. Value: 26
  205. },{
  206. Name: 'MID',
  207. Value: 9
  208. }],
  209. Name: "我的副图",
  210. Modify: false,
  211. Change: false
  212. },
  213. {
  214. Index: "RSI",
  215. Modify: false,
  216. Change: false
  217. }];
  218. hqchartCtrl.Minute.Option.IsAutoUpdate=true;
  219. hqchartCtrl.Minute.Option.AutoUpdateFrequency=10000; //更新频率 ms
  220. hqchartCtrl.SetSize(this.ChartWidth,chartHeight);
  221. hqchartCtrl.OnSize();
  222. hqchartCtrl.CreateHQChart();
  223. },
  224. ClearHQChart()
  225. {
  226. let hqchartCtrl=this.$refs.HQChartCtrl;
  227. if (hqchartCtrl) hqchartCtrl.ClearChart();
  228. },
  229. ChangeMinutePeriod(days)
  230. {
  231. let hqchartCtrl=this.$refs.HQChartCtrl;
  232. hqchartCtrl.ChangeMinutePeriod(days);
  233. },
  234. ChangeKLinePeriod(period)
  235. {
  236. let hqchartCtrl=this.$refs.HQChartCtrl;
  237. hqchartCtrl.ChangeKLinePeriod(period);
  238. },
  239. ChangeSymbol(symbol)
  240. {
  241. let hqchartCtrl=this.$refs.HQChartCtrl;
  242. hqchartCtrl.ChangeSymbol(symbol);
  243. },
  244. NetworkFilter(data, callback)
  245. {
  246. console.log(`[App:NetworkFilter] Name=${data.Name} Explain=${data.Explain}` );
  247. JSHQData.HQData.NetworkFilter(data, callback);
  248. },
  249. changsctype(){
  250. this.scripttype=!this.scripttype;
  251. },
  252. vinInput(e) {
  253. let val = e;
  254. // if (/[^a-zA-Z0-9]/g.test(val)) { // 先过滤不需要的字符,只保留数字和字母
  255. // val = val.replace(/[^a-zA-Z0-9]/g, '');
  256. // }
  257. // if (!/^[A-Z\d]+$/.test(val)) {// 再进行转换,小写转为大写
  258. // val = val.toUpperCase();
  259. // }
  260. val = val.toUpperCase();
  261. this.mycode = val; //这里对应的是value绑定的变量
  262. return val; // 最后输出值,要保证输入框的值和value绑定的值一致
  263. },
  264. editcode(){
  265. this.viewstyle="height: 180px; background-color: #fff;"
  266. this.editmode=true;
  267. },
  268. checkcode: async function(){
  269. let pid=this.productid;
  270. if(pid>0 && !this.codeloaded){
  271. console.log(pid);
  272. let res = await this.$api.getArchivesDetail({ id: pid, diyname: '' });
  273. console.log(res);
  274. if (res.code>0){
  275. this.pagetitle= res.data.archivesInfo.title;
  276. this.mycode=res.data.archivesInfo.tongdaxin;
  277. this.studyid=res.data.archivesInfo.studyid;
  278. //console.log(this.mycode);
  279. this.codeloaded=true;
  280. }
  281. }
  282. this.editmode=false;
  283. this.viewstyle="height: 180px; background-color: #2d2d2d;"
  284. this.myhtml="<pre><code>"+this.mycode+"</code></pre>";
  285. let that=this;
  286. // setTimeout(function(){
  287. // let ctx = that.$refs.article;
  288. // if(ctx){
  289. // ctx.setContent("<pre><code>"+that.mycode+"</code></pre>");
  290. // }
  291. // },500);
  292. var option=
  293. {
  294. Callback:(data)=>
  295. {
  296. console.log("[Explain] data ", data);
  297. for(var i in data)
  298. {
  299. var item=data[i]; //每一句翻译好的语句
  300. }
  301. that.errColor="#00FF00";
  302. that.codeError="语法正确";
  303. if(that.scripttype){//主图
  304. //console.log(that.mycode);
  305. var indexdata={Name:"我的主图", Script:that.mycode, Args:[]};
  306. let hqchartCtrl=this.$refs.HQChartCtrl;
  307. hqchartCtrl.ChangeScriptIndex(0,indexdata);
  308. }else{
  309. var indexdata={Name:"我的副图", Script:that.mycode, Args:[]};
  310. let hqchartCtrl=this.$refs.HQChartCtrl;
  311. hqchartCtrl.ChangeScriptIndex(1,indexdata);
  312. }
  313. },
  314. ErrorCallback:(error, data)=>
  315. { if(error.LineNumber){
  316. that.errColor="#FF0000";
  317. that.codeError=`语法错误: 行号:${error.LineNumber}, ${error.Description}`;
  318. }
  319. }
  320. };
  321. // #ifdef H5
  322. HQChart.JSComplier.Explain(that.mycode,option,option.ErrorCallback);
  323. // #endif
  324. // #ifndef H5
  325. JSCommonComplier.JSComplier.Explain(that.mycode,option,option.ErrorCallback);
  326. // #endif
  327. },
  328. openstudy(){
  329. this.$Router.push({
  330. path: '/pages/article/detail',
  331. query: { id: this.studyid }
  332. });
  333. },
  334. copycode(){
  335. uni.setClipboardData({
  336. data:this.mycode,
  337. success: function (res) {
  338. uni.showToast({
  339. title: '已复制到剪贴板',
  340. })
  341. }
  342. });
  343. },
  344. downcode(){
  345. uni.showToast({
  346. title: '本功能暂未开放',
  347. })
  348. },
  349. getUserIndex: async function() {
  350. let res = await this.$api.getUserIndex();
  351. uni.stopPullDownRefresh();
  352. if (!res.code) {
  353. this.$u.toast(res.msg);
  354. return;
  355. }
  356. this.$u.vuex('vuex_user', res.data.userInfo || {});
  357. },
  358. downclick(index){
  359. if(index==0){
  360. this.copycode();
  361. }
  362. if(index==1){
  363. if (this.vuex_token) {
  364. this.getUserIndex();
  365. } else {
  366. this.$u.vuex('vuex_user', {});
  367. }
  368. if (!this.vuex_token) {
  369. this.$u.toast('请先登录再操作!');
  370. return;
  371. }
  372. this.downcode();
  373. }
  374. }
  375. }
  376. }
  377. </script>
  378. <style lang="scss">
  379. @import "~ng-codemirror/index.scss";
  380. .ptip {
  381. background-color: #0066CC;width: 80%;height: 40px;
  382. position: fixed;
  383. background-color: #3d7bb8;
  384. bottom:80px;
  385. border-radius: 15px;
  386. color:#ffffff;
  387. vertical-align:middle;
  388. text-align: center;
  389. z-index: 995;
  390. padding-top: 12px;
  391. left:10%;
  392. }
  393. .ptip:after {
  394. content: "";
  395. position: fixed;
  396. left: 49%;
  397. z-index: 994;
  398. width: 10px;
  399. height: 10px;
  400. bottom: 75px;
  401. background-color: #3d7bb8;
  402. /* border-top: 1px solid #dcdcdc;
  403. border-right: 1px solid #dcdcdc; */
  404. transform: rotate(
  405. -45deg
  406. );
  407. }
  408. </style>