259 lines
7.3 KiB
JavaScript
259 lines
7.3 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../../common/vendor.js");
|
|
const request_api = require("../../../request/api.js");
|
|
const common_assets = require("../../../common/assets.js");
|
|
const echarts = require("../../../uni_modules/lime-echart/static/echarts.min.js");
|
|
const _sfc_main = {
|
|
data() {
|
|
return {
|
|
navH: common_vendor.inject("navHeight"),
|
|
contentTop: "",
|
|
navTitle: "",
|
|
stockCode: "",
|
|
//股票code
|
|
categoryList: ["分钟线", "分时图", "日K线"],
|
|
selectCategory: 0,
|
|
option: {
|
|
title: {
|
|
show: false
|
|
},
|
|
tooltip: {
|
|
trigger: "axis",
|
|
axisPointer: {
|
|
type: "cross"
|
|
}
|
|
},
|
|
legend: {
|
|
show: false
|
|
},
|
|
grid: {
|
|
left: "10%",
|
|
right: "10%",
|
|
bottom: "15%"
|
|
},
|
|
xAxis: {
|
|
type: "category",
|
|
data: [],
|
|
boundaryGap: false,
|
|
axisLine: { onZero: false },
|
|
splitLine: { show: false },
|
|
min: "dataMin",
|
|
max: "dataMax"
|
|
},
|
|
yAxis: {
|
|
scale: true,
|
|
splitArea: {
|
|
show: true
|
|
}
|
|
},
|
|
dataZoom: [
|
|
{
|
|
type: "inside",
|
|
start: 50,
|
|
end: 100
|
|
},
|
|
{
|
|
show: true,
|
|
type: "slider",
|
|
top: "90%",
|
|
start: 50,
|
|
end: 100
|
|
}
|
|
],
|
|
series: [
|
|
{
|
|
name: "日K",
|
|
type: "candlestick",
|
|
data: [],
|
|
itemStyle: {
|
|
color: "#ec0000",
|
|
color0: "#8A0000",
|
|
borderColor: "#00da3c",
|
|
borderColor0: "#008F28"
|
|
},
|
|
markPoint: {
|
|
label: {
|
|
formatter: function(param) {
|
|
return param != null ? Math.round(param.value) + "" : "";
|
|
}
|
|
},
|
|
data: [
|
|
{
|
|
name: "Mark",
|
|
coord: ["2013/5/31", 2300],
|
|
value: 2300,
|
|
itemStyle: {
|
|
color: "rgb(41,60,85)"
|
|
}
|
|
},
|
|
{
|
|
name: "highest value",
|
|
type: "max",
|
|
valueDim: "highest"
|
|
},
|
|
{
|
|
name: "lowest value",
|
|
type: "min",
|
|
valueDim: "lowest"
|
|
},
|
|
{
|
|
name: "average value on close",
|
|
type: "average",
|
|
valueDim: "close"
|
|
}
|
|
],
|
|
tooltip: {
|
|
formatter: function(param) {
|
|
return param.name + "<br>" + (param.data.coord || "");
|
|
}
|
|
}
|
|
},
|
|
markLine: {
|
|
symbol: ["none", "none"],
|
|
data: [
|
|
[
|
|
{
|
|
name: "from lowest to highest",
|
|
type: "min",
|
|
valueDim: "lowest",
|
|
symbol: "circle",
|
|
symbolSize: 10,
|
|
label: {
|
|
show: false
|
|
},
|
|
emphasis: {
|
|
label: {
|
|
show: false
|
|
}
|
|
}
|
|
},
|
|
{
|
|
type: "max",
|
|
valueDim: "highest",
|
|
symbol: "circle",
|
|
symbolSize: 10,
|
|
label: {
|
|
show: false
|
|
},
|
|
emphasis: {
|
|
label: {
|
|
show: false
|
|
}
|
|
}
|
|
}
|
|
],
|
|
{
|
|
name: "min line on close",
|
|
type: "min",
|
|
valueDim: "close"
|
|
},
|
|
{
|
|
name: "max line on close",
|
|
type: "max",
|
|
valueDim: "close"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
};
|
|
},
|
|
onLoad(e) {
|
|
this.contentTop = this.navH + (60 + 10) / 750 * common_vendor.inject("windowWidth");
|
|
if (e.code) {
|
|
this.stockCode = e.code;
|
|
this.getStockDetailsData();
|
|
this.getStockCandlestickChartData();
|
|
}
|
|
},
|
|
methods: {
|
|
async init() {
|
|
const chart = await this.$refs.chartRef.init(echarts);
|
|
chart.setOption(this.option);
|
|
},
|
|
/**
|
|
* 点击切换分类
|
|
* @param {Object} index
|
|
*/
|
|
clickCategoryItem(index) {
|
|
if (this.selectCategory != index) {
|
|
this.selectCategory = index;
|
|
if (index == 0 || index == 2) {
|
|
this.getStockCandlestickChartData();
|
|
}
|
|
}
|
|
},
|
|
/**
|
|
* 获取股票详情数据
|
|
*/
|
|
getStockDetailsData() {
|
|
let stockCode = this.stockCode;
|
|
request_api.stockDetails(stockCode).then((res) => {
|
|
if (res.code == 200) {
|
|
this.navTitle = res.data.basic_info.stock_name + "(" + res.data.basic_info.stock_code + ")";
|
|
} else
|
|
common_vendor.index.showToast({
|
|
title: res.message,
|
|
icon: "none"
|
|
});
|
|
}).catch((error) => {
|
|
});
|
|
},
|
|
/**
|
|
* 获取股票K线数据
|
|
*/
|
|
getStockCandlestickChartData() {
|
|
let stockCode = this.stockCode;
|
|
let param = { chart_type: "minute" };
|
|
if (this.selectCategory == 2) {
|
|
param.chart_type = "daily";
|
|
}
|
|
request_api.stockCandlestickChartData(stockCode, param).then((res) => {
|
|
let data = res.data;
|
|
let categoryData = [];
|
|
for (let item of data) {
|
|
categoryData.push(item.time);
|
|
}
|
|
this.option.xAxis.data = categoryData;
|
|
this.init();
|
|
}).catch((error) => {
|
|
});
|
|
}
|
|
}
|
|
};
|
|
if (!Array) {
|
|
const _easycom_navBar2 = common_vendor.resolveComponent("navBar");
|
|
const _easycom_l_echart2 = common_vendor.resolveComponent("l-echart");
|
|
(_easycom_navBar2 + _easycom_l_echart2)();
|
|
}
|
|
const _easycom_navBar = () => "../../../components/navBar/navBar.js";
|
|
const _easycom_l_echart = () => "../../../uni_modules/lime-echart/components/l-echart/l-echart.js";
|
|
if (!Math) {
|
|
(_easycom_navBar + _easycom_l_echart)();
|
|
}
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
return {
|
|
a: common_vendor.p({
|
|
leftText: $data.navTitle
|
|
}),
|
|
b: common_assets._imports_0,
|
|
c: common_vendor.f($data.categoryList, (item, index, i0) => {
|
|
return common_vendor.e({
|
|
a: common_vendor.t(item),
|
|
b: $data.selectCategory == index
|
|
}, $data.selectCategory == index ? {} : {}, {
|
|
c: common_vendor.n("item relative " + ($data.selectCategory == index ? "select" : "")),
|
|
d: index,
|
|
e: common_vendor.o(($event) => $options.clickCategoryItem(index), index)
|
|
});
|
|
}),
|
|
d: common_vendor.s("top:" + $data.navH + "px;"),
|
|
e: common_vendor.sr("chartRef", "42054871-1"),
|
|
f: common_vendor.s("top:" + $data.contentTop + "px;")
|
|
};
|
|
}
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../../.sourcemap/mp-weixin/pages/index/stockDetails/stockDetails.js.map
|