stockprogram.vue 13 KB

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