diff --git a/components/kline/kline.vue b/components/kline/kline.vue index 9b02035..5398a17 100644 --- a/components/kline/kline.vue +++ b/components/kline/kline.vue @@ -1,8 +1,26 @@ @@ -13,11 +31,59 @@ mixins: [props], data() { return { - + type:'1min', + index_activeCycle:1 }; }, created() { + } + ,methods: { + onChangeType(type) { + // 1min + // + // 5min + // + // 15min + // + // 30min + // + // 60min + // + // 1day + // + // 1week + // + // 1mon + // + this.type = type + switch(type){ + case '1min': + this.index_activeCycle=1; + break; + case '5min': + this.index_activeCycle=5; + break; + case '15min': + this.index_activeCycle=15; + break; + case '30min': + this.index_activeCycle=30; + break; + case '60min': + this.index_activeCycle=60; + break; + case '1day': + this.index_activeCycle='1D'; + break; + case '1week': + this.index_activeCycle='1W'; + break; + case '1mon': + this.index_activeCycle='1M'; + break; + } + }, } } @@ -34,8 +100,6 @@ var widgetObj = null // 进入页面 默认展示的产品 var index_market = 'btcusdt' - // 进入页面 默认展示的产品周期 - var index_activeCycle = '1' export default { data() { @@ -48,7 +112,7 @@ //该生命周期慢于不是renderjs的生命周期 mounted() { //初始化图表 - this.initChart() + this.initChart("1") }, methods: { setSymbol(symbol){ @@ -62,17 +126,21 @@ setHeight(height) { console.log("可用窗口高度:", height) this.chartHeight = 300 - }, - initChart() { + }, + changindex_activeCycle(index_activeCycle){ + this.initChart(index_activeCycle) + } + , + initChart(index_activeCycle) { // chartConfig 在chartConfig.js里面 // 给chartConfig添加展示周期 - chartConfig.interval = index_activeCycle - chartConfig.intervals = ['1','5'] + chartConfig.interval = index_activeCycle // 给chartConfig添加展示产品 chartConfig.symbol = this.symbol //设置图表宽高 chartConfig.width = this.chartWidth - chartConfig.height = this.chartHeight + chartConfig.height = this.chartHeight + chartConfig.time_frames=[] // 初始化 TradingView console.log(window.TradingView.version()) const language = uni.getStorageSync("language")|| 'en_US'; @@ -84,7 +152,8 @@ widgetObj = new widget(chartConfig) - console.log(widgetObj) + console.log(11111,widgetObj) + widgetObj._options.interval=5 widgetObj.onChartReady(() => { // 这是k线图 展示的 7日均线和30日均线。 widgetObj.chart().createStudy('Moving Average', false, false, [5], null, { @@ -100,5 +169,27 @@ } } - + + diff --git a/components/kline/tradingView/chartConfig.js b/components/kline/tradingView/chartConfig.js index f63813c..7a0f4c1 100644 --- a/components/kline/tradingView/chartConfig.js +++ b/components/kline/tradingView/chartConfig.js @@ -13,7 +13,8 @@ var chartConfig = { fullscreen: false, //布尔值显示图表是否占用窗口中所有可用的空间。 //如果上面参数开启会影响到宽高项 timeframe: '1', - timezone: "Asia/Bangkok", + timezone: "Asia/Bangkok", + intervals: ['1', '5', '15', '30', '60', '1D', '1W', '1M'], container: "kline", datafeed: new FeedBase(), library_path: "./static/charting_library/", @@ -29,6 +30,7 @@ var chartConfig = { //禁用功能 disabled_features: [ // 需要屏蔽掉的 参考 https://tradingview.gitee.io/featuresets/ "widget_logo", //LOGO + "header_resolutions", "left_toolbar", "header_screenshot", "header_fullscreen_button", diff --git a/components/kline/tradingView/datafeed.js b/components/kline/tradingView/datafeed.js index 806f9fd..08a2016 100644 --- a/components/kline/tradingView/datafeed.js +++ b/components/kline/tradingView/datafeed.js @@ -58,11 +58,11 @@ FeedBase.prototype.resolveSymbol = function(symbolName, onResolve, onError) { "has_intraday": true, "intraday_multipliers": ['1', '5', '15', '30', '60', '1D', '1W','1M'], // 时间 "supported_resolutions": ['1', '5', '15', '30', '60', '1D', '1W','1M'], // 时间 - "supports_marks": false, - "supports_timescale_marks": false, + "supports_marks": true, + "supports_timescale_marks": true, "supported_time": true, - "has_weekly_and_monthly": false, - "has_no_volume": false, + "has_weekly_and_monthly": true, + "has_no_volume": true, "regular_session": "24x7", }) @@ -100,9 +100,9 @@ const resolutionFormat = (resolution, name, to) => { let from = null; if (to) { - from = to - 50 * minutes * 60; + from = to - 50 * minutes * 500; if (resolution.includes('M') || resolution.includes('W')) { // 周线月线控制条数,时间超出火币规定范围, ws报错 - from = to - 50 * minutes * 60; + from = to - 50 * minutes * 500; } } return { @@ -118,7 +118,11 @@ FeedBase.prototype.getBars = function(symbolInfo, resolution, periodParams, onHi // 切换产品周期 或者 切换产品 会执行这个函数 let reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to > detafeed_historyTime ? periodParams .to : - detafeed_historyTime) + detafeed_historyTime) + if (resolution.includes('M') || resolution.includes('W')) { // 周线月线控制条数,时间超出火币规定范围, ws报错 + reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to) + } + // 是历史数据 var history = true /* diff --git a/components/kline/tradingView/websocket.js b/components/kline/tradingView/websocket.js index 0d6f089..b50c591 100644 --- a/components/kline/tradingView/websocket.js +++ b/components/kline/tradingView/websocket.js @@ -83,13 +83,20 @@ var socket = { }else { if(resp.event === 'req'){ + + Event.emit('data', resp.data) + this.sendWsRequest({ + event: 'un_sub', + type: 'kline', + id: this.id, + channel:[this.lastRealTimeData], + }) this.sendWsRequest({ event: 'sub', type: 'kline', id: this.id, channel:[this.lastRealTimeData], }) - Event.emit('data', resp.data) }else{ Event.emit('realTime', resp.data) diff --git a/utils/language/vi_VN.js b/utils/language/vi_VN.js index 4ffa2e5..5ead1d1 100644 --- a/utils/language/vi_VN.js +++ b/utils/language/vi_VN.js @@ -81,7 +81,7 @@ export default { customerService: 'dịch vụ trực tuyến', homeMessage: 'Vui lòng liên hệ với dịch vụ khách hàng ở góc trên bên trái để xác minh danh tính Vui lòng liên hệ với dịch vụ khách hàng ở góc trên bên trái để xác minh danh tính ...', Recharge: 'nạp điện', - Mine: 'khai thác mỏ', + Mine: 'của tôi', Subcription: 'Đăng ký', Order: 'Gọi món', TodaySteps: 'các bước hôm nay',