|
|
@ -9,6 +9,7 @@ import Option from "@/api/option"; |
|
|
import Contract from "@/api/contract"; |
|
|
import Contract from "@/api/contract"; |
|
|
import Socket from "@/api/server/Socket.js"; |
|
|
import Socket from "@/api/server/Socket.js"; |
|
|
import tvStyle from "@/assets/js/tvStyle.js"; |
|
|
import tvStyle from "@/assets/js/tvStyle.js"; |
|
|
|
|
|
import bus from "@/components/bus.js"; |
|
|
import { mapState } from "vuex"; |
|
|
import { mapState } from "vuex"; |
|
|
let exchangeAjax = { |
|
|
let exchangeAjax = { |
|
|
getKline: Option.getKline, |
|
|
getKline: Option.getKline, |
|
|
@ -110,7 +111,7 @@ export default { |
|
|
)}_${this.resolution(this.interval)}`; |
|
|
)}_${this.resolution(this.interval)}`; |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
data() { |
|
|
data() { |
|
|
return { |
|
|
return { |
|
|
TView: undefined, |
|
|
TView: undefined, |
|
|
ws: undefined, |
|
|
ws: undefined, |
|
|
@ -121,8 +122,8 @@ export default { |
|
|
isCreateSocket: false, |
|
|
isCreateSocket: false, |
|
|
page: {}, |
|
|
page: {}, |
|
|
}; |
|
|
}; |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
// 链接socket |
|
|
// 链接socket |
|
|
linkSocket(call) { |
|
|
linkSocket(call) { |
|
|
const ws = new Socket(this.wsUrl); |
|
|
const ws = new Socket(this.wsUrl); |
|
|
@ -134,6 +135,7 @@ export default { |
|
|
let { data, msg, code, sub, type, status, req, cmd } = res; |
|
|
let { data, msg, code, sub, type, status, req, cmd } = res; |
|
|
if (sub == this.sub && this.onRealtimeCallback) { |
|
|
if (sub == this.sub && this.onRealtimeCallback) { |
|
|
this.onRealtimeCallback(this.getMap(data)); |
|
|
this.onRealtimeCallback(this.getMap(data)); |
|
|
|
|
|
bus.$emit('collapse', data); |
|
|
} else if (type == "ping" || cmd == "ping") { |
|
|
} else if (type == "ping" || cmd == "ping") { |
|
|
this.ws.send({ |
|
|
this.ws.send({ |
|
|
cmd: "pong", |
|
|
cmd: "pong", |
|
|
@ -203,6 +205,7 @@ export default { |
|
|
onLoadedCallback, |
|
|
onLoadedCallback, |
|
|
onErrorCallback |
|
|
onErrorCallback |
|
|
) { |
|
|
) { |
|
|
|
|
|
console.info(resolution) |
|
|
this.page[this.symbol] = this.page[this.symbol] || 1; |
|
|
this.page[this.symbol] = this.page[this.symbol] || 1; |
|
|
let page = this.page[this.symbol] > 3 ? 3 : this.page[this.symbol]; |
|
|
let page = this.page[this.symbol] > 3 ? 3 : this.page[this.symbol]; |
|
|
let data = { |
|
|
let data = { |
|
|
@ -242,7 +245,6 @@ export default { |
|
|
} |
|
|
} |
|
|
}, 60); |
|
|
}, 60); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 发送消息 |
|
|
// 发送消息 |
|
|
let msgObj = { |
|
|
let msgObj = { |
|
|
cmd: "sub", |
|
|
cmd: "sub", |
|
|
@ -283,18 +285,20 @@ export default { |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
initView() { |
|
|
initView() { |
|
|
|
|
|
let _this = this; |
|
|
let Tdata = new VDatafeed(this); |
|
|
let Tdata = new VDatafeed(this); |
|
|
this.TView = new TradingView.widget({ |
|
|
console.info(Tdata) |
|
|
|
|
|
let widget=(_this.TView = new TradingView.widget({ |
|
|
width: "100%", |
|
|
width: "100%", |
|
|
height: 590, |
|
|
height: 590, |
|
|
interval: this.timer, |
|
|
interval: _this.timer, |
|
|
timezone: "Asia/Shanghai", |
|
|
timezone: "Asia/Shanghai", |
|
|
theme: "light", // 自定义主题 |
|
|
theme: "light", // 自定义主题 |
|
|
style: "1", |
|
|
style: "1", |
|
|
library_path: "/static/Kline/charting_library/", |
|
|
library_path: "/static/Kline/charting_library/", |
|
|
datafeed: Tdata, |
|
|
datafeed: Tdata, |
|
|
locale: this.lang, |
|
|
locale: _this.lang, |
|
|
toolbar_bg: this.theme == "light" ? "#f1f3f6" : "#222e3d", |
|
|
toolbar_bg: _this.theme == "light" ? "#f1f3f6" : "#222e3d", |
|
|
enable_publishing: false, |
|
|
enable_publishing: false, |
|
|
withdateranges: true, |
|
|
withdateranges: true, |
|
|
hide_side_toolbar: false, |
|
|
hide_side_toolbar: false, |
|
|
@ -305,9 +309,9 @@ export default { |
|
|
container_id: "tradingview_1355aw2", |
|
|
container_id: "tradingview_1355aw2", |
|
|
disabled_features: [ |
|
|
disabled_features: [ |
|
|
"header_symbol_search", |
|
|
"header_symbol_search", |
|
|
|
|
|
// "widget_logo", |
|
|
"header_compare", |
|
|
"header_compare", |
|
|
"volume_force_overlay", |
|
|
"volume_force_overlay", |
|
|
"header_widget_dom_node", |
|
|
|
|
|
'timeframes_toolbar', |
|
|
'timeframes_toolbar', |
|
|
"control_bar", |
|
|
"control_bar", |
|
|
"main_series_scale_menu", |
|
|
"main_series_scale_menu", |
|
|
@ -316,14 +320,94 @@ export default { |
|
|
"symbol_search_hot_key", |
|
|
"symbol_search_hot_key", |
|
|
"symbol_info", |
|
|
"symbol_info", |
|
|
"pane_context_menu", |
|
|
"pane_context_menu", |
|
|
"header_widget_dom_node", |
|
|
// "header_widget_dom_node", |
|
|
'timeframes_toolbar', |
|
|
'timeframes_toolbar', |
|
|
], |
|
|
], |
|
|
supported_resolutions: ["5", "15", "30", "60", "240", "1D", "1W", "1M"], |
|
|
supported_resolutions: ["5", "15", "30", "60", "240", "1D", "1W", "1M"], |
|
|
overrides: tvStyle[this.theme], |
|
|
overrides: tvStyle[_this.theme], |
|
|
custom_css_url: `/static/Kline/charting_library/static/css/tradingview_${ |
|
|
custom_css_url: `/static/Kline/charting_library/static/css/tradingview_${ |
|
|
this.theme == "light" ? "white" : "black" |
|
|
_this.theme == "light" ? "white" : "black" |
|
|
}.css`, |
|
|
}.css`, |
|
|
|
|
|
})); |
|
|
|
|
|
widget.onChartReady(function () { |
|
|
|
|
|
let buttonArr = [ |
|
|
|
|
|
{ |
|
|
|
|
|
title: "1" + _this.$t("exchange.min"), |
|
|
|
|
|
resolution: "1", |
|
|
|
|
|
chartType: 1 |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
title: "5" + _this.$t("exchange.min"), |
|
|
|
|
|
resolution: "5", |
|
|
|
|
|
chartType: 1 |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
title: "15" + _this.$t("exchange.min"), |
|
|
|
|
|
resolution: "15", |
|
|
|
|
|
chartType: 1 |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
title: "30" + _this.$t("exchange.min"), |
|
|
|
|
|
resolution: "30", |
|
|
|
|
|
chartType: 1 |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
title: "1" + _this.$t("exchange.hour"), |
|
|
|
|
|
resolution: "60", |
|
|
|
|
|
chartType: 1 |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
title: "1" + _this.$t("exchange.day"), |
|
|
|
|
|
resolution: "1D", |
|
|
|
|
|
chartType: 1 |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
title: "1" + _this.$t("exchange.week"), |
|
|
|
|
|
resolution: "1W", |
|
|
|
|
|
chartType: 1 |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
title: "1" + _this.$t("exchange.month"), |
|
|
|
|
|
resolution: "1M", |
|
|
|
|
|
chartType: 1 |
|
|
|
|
|
} |
|
|
|
|
|
]; |
|
|
|
|
|
let btn = {}; |
|
|
|
|
|
let nowTime = ""; |
|
|
|
|
|
|
|
|
|
|
|
buttonArr.forEach((v, i) => { |
|
|
|
|
|
let button = widget.createButton(); |
|
|
|
|
|
button.attr("title", v.title).addClass("my-date").text(v.title); |
|
|
|
|
|
if (v.resolution === "1") { |
|
|
|
|
|
button.css({ |
|
|
|
|
|
color: "#5786d2", |
|
|
|
|
|
"border-bottom": "1px solid #5786d2", |
|
|
|
|
|
}); |
|
|
|
|
|
localStorage.setItem("tim", "1"); |
|
|
|
|
|
} |
|
|
|
|
|
btn = button.on("click", function (e) { |
|
|
|
|
|
$(this).parents(".left").children().find(".my-date").removeAttr("style"); |
|
|
|
|
|
handleClick(e, v.resolution); |
|
|
|
|
|
button.css({ |
|
|
|
|
|
color: "#5786d2", |
|
|
|
|
|
"border-bottom": "1px solid #5786d2", |
|
|
|
|
|
}); |
|
|
|
|
|
// _this.$store.commit("upType", v.type); |
|
|
|
|
|
widget.chart().setChartType(v.chartType); //改变K线类型 |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
let handleClick = (e, value) => { |
|
|
|
|
|
_this.setSymbol = function (symbol, value) { |
|
|
|
|
|
gh.chart().setSymbol(symbol, value); |
|
|
|
|
|
}; |
|
|
|
|
|
widget.chart().setResolution(value, function onReadyCallback() {}); //改变分辨率 |
|
|
|
|
|
$(e.target) |
|
|
|
|
|
.addClass("mydate") |
|
|
|
|
|
.closest("div.space-single") |
|
|
|
|
|
.siblings("div.space-single") |
|
|
|
|
|
.find("div.button") |
|
|
|
|
|
.removeClass("mydate"); |
|
|
|
|
|
}; |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
|