diff --git a/pages/ztfx/ztfx.vue b/pages/ztfx/ztfx.vue index 3853fbf..c86fbac 100644 --- a/pages/ztfx/ztfx.vue +++ b/pages/ztfx/ztfx.vue @@ -94,14 +94,14 @@ - + }" > {{item.title}} {{item.count}}只 @@ -132,7 +132,7 @@ style="width: 100%; height: 500rpx; display: flex; align-items: center; justify-content: center; color: #999;"> 板块关联图内容区域 --> - @@ -361,7 +361,7 @@ // '热门概念词云' // ], bkTypes: [ - + '板块分布', '热门概念词云' ], @@ -442,13 +442,17 @@ this.activeIndex = e.index this.contentTop = this.navH + 20 / 750 * inject('windowWidth') - - + //this.selectedFullDate = this.getPreviousDayDate(); + //console.log("selectedFullDate", this.selectedFullDate) + //this.fetchData() }, onReady() { - this.fetchData() + + + + // 页面就绪后,若默认选中的是板块分布,初始化饼图 //if (this.activeType === 0) { //this.initPieChart(); // 初始化关系图 @@ -473,18 +477,29 @@ switch (index) { case 0: //this.$refs.graphChartRef && this.initGraphChart(); // 增加存在性判断 - this.$refs.chartRef && this.initPieChart(); // 增加存在性判断 + this.$refs.chartRef && this.initPieChart(); // 增加存在性判断 break; case 1: //this.$refs.chartRef && this.initPieChart(); // 增加存在性判断 - this.initWordCloud(); + this.initWordCloud(); break; case 2: this.initWordCloud(); break; } }, - getPreviousDayDate(dateStr) { + + + getPreviousDayDate() { + const now = new Date(); + + // 步骤2:将系统时间格式化为 YYYY-MM-DD 格式(适配后续校验逻辑) + const currentYear = now.getFullYear(); + const currentMonth = String(now.getMonth() + 1).padStart(2, '0'); + const currentDay = String(now.getDate()).padStart(2, '0'); + const dateStr = `${currentYear}-${currentMonth}-${currentDay}`; // 示例:2026-02-04 + + // 校验输入日期格式是否正确 if (!/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) { console.error('日期格式错误,请传入 YYYY-MM-DD 格式的日期'); @@ -496,7 +511,7 @@ const date = new Date(year, month - 1, day); // 将日期减一天 - date.setDate(date.getDate() - 2); + date.setDate(date.getDate() - 1); // 格式化前一天的日期为 YYYYMMDD 格式(补零处理) const prevYear = date.getFullYear(); @@ -515,7 +530,8 @@ // 调用上面的函数,获取前一天的格式化日期(YYYYMMDD) - const formattedDate = this.getPreviousDayDate(this.selectedFullDate); + // const formattedDate = this.getPreviousDayDate(this.selectedFullDate); + const formattedDate = this.selectedFullDate; const baseURL = getBaseURL1(); const requestUrl = `${baseURL}/data/zt/daily/${formattedDate}.json?t=${timestamp}`; @@ -664,7 +680,7 @@ }); // 赋值到父页面的变量中 this.selectedYearMonth = data.yearMonth; - this.selectedFullDate = data.fullDate; + this.selectedFullDate = data.fullDate ? data.fullDate.replace(/-/g, '') : ''; this.selectedItem = data.item; // 2. 格式化日期:年-月-日 → 月日(如 2026-01-14 → 1月14日) @@ -686,27 +702,49 @@ ztCount - prevZtCount; this.tabTypes[1].change = changeValue; // ======================================= + // ===== 新增:判断选中日期是否为系统当天,若是则日期减一天 ===== + if (this.selectedFullDate) { + // 获取系统当前日期并格式化为 YYYYMMDD + const today = new Date(); + const todayYear = today.getFullYear(); + const todayMonth = String(today.getMonth() + 1).padStart(2, '0'); + const todayDay = String(today.getDate()).padStart(2, '0'); + const todayFormatted = `${todayYear}${todayMonth}${todayDay}`; + + // 判断选中日期是否等于系统当天 + if (this.selectedFullDate === todayFormatted) { + // 创建选中日期的Date对象 + const selectedDate = new Date( + parseInt(this.selectedFullDate.substring(0, 4)), // 年 + parseInt(this.selectedFullDate.substring(4, 6)) - 1, // 月(月份从0开始) + parseInt(this.selectedFullDate.substring(6, 8)) // 日 + ); + + // 将日期减一天 + selectedDate.setDate(selectedDate.getDate() - 1); + + // 格式化前一天的日期为 YYYYMMDD 格式(补零处理) + const prevYear = selectedDate.getFullYear(); + const prevMonth = String(selectedDate.getMonth() + 1).padStart(2, '0'); + const prevDay = String(selectedDate.getDate()).padStart(2, '0'); + const prevDateFormatted = `${prevYear}${prevMonth}${prevDay}`; + + // 更新选中的日期为前一天 + this.selectedFullDate = prevDateFormatted; + + console.log(`选中日期为当天(${todayFormatted}),已自动调整为前一天:`, prevDateFormatted); + } + } this.fetchData() - // this.analyseHighStocks() + }, - analyseHighStocks() { - const formatDate = this.getPreviousDayDate(this.selectedFullDate); - let param = { - date: formatDate - } - analyseHighStocks(param).then(res => { - - }).catch(error => { - - }) - }, bkydAction(index) { uni.navigateTo({ - url: `/pagesStock/stockCenterDetails/bkydmx?index=${index}` + url: `/pagesStock/stockCenterDetails/bkydmx?index=${index}&data=${this.selectedFullDate}` }) } } diff --git a/pagesStock/stockCenterDetails/bkydmx.vue b/pagesStock/stockCenterDetails/bkydmx.vue index d6f42a6..42f7466 100644 --- a/pagesStock/stockCenterDetails/bkydmx.vue +++ b/pagesStock/stockCenterDetails/bkydmx.vue @@ -68,92 +68,120 @@ import { inject } from 'vue' - +import { + getBaseURL1 + } from '@/request/http.js' + export default { data() { return { navH: inject('navHeight'), contentTop: '', activeIndex: 0, - bkList: [{ - title: '存储芯片', - count: 8 - }, { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - }, - { - title: '存储芯片', - count: 8 - } - ], + bkList: [], bkFilters: [ '按涨幅', '按连板数', '只看龙头' ], - filterIndex: 0 + filterIndex: 0, + selectedFullDate: '', // 年-月-日 } }, onLoad(e) { this.activeIndex = e.index + this.selectedFullDate=e.data this.contentTop = this.navH + 20 / 750 * inject('windowWidth') + + this.fetchData() }, methods: { + + getPreviousDayDate(dateStr) { + // 校验输入日期格式是否正确 + if (!/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) { + console.error('日期格式错误,请传入 YYYY-MM-DD 格式的日期'); + return ''; + } + + // 创建日期对象(注意:月份是 0 开始的,所以需要处理) + const [year, month, day] = dateStr.split('-').map(Number); + const date = new Date(year, month - 1, day); + + // 将日期减一天 + date.setDate(date.getDate() - 2); + + // 格式化前一天的日期为 YYYYMMDD 格式(补零处理) + const prevYear = date.getFullYear(); + const prevMonth = String(date.getMonth() + 1).padStart(2, '0'); + const prevDay = String(date.getDate()).padStart(2, '0'); + + return `${prevYear}${prevMonth}${prevDay}`; + }, + + /** + * 请求接口数据(优化:动态日期+自动时间戳) + */ + async fetchData() { + try { + // 1. 自动生成当前时间戳(替代固定值) + const timestamp = new Date().getTime(); + + // 调用上面的函数,获取前一天的格式化日期(YYYYMMDD) + const formattedDate = this.getPreviousDayDate(this.selectedFullDate); + const baseURL = getBaseURL1(); + const requestUrl = `${baseURL}/data/zt/daily/${formattedDate}.json?t=${timestamp}`; + + console.log('请求URL:', requestUrl); // 打印URL便于调试 + + const res = await uni.request({ + url: requestUrl, + method: 'GET' + }); + + if (res.statusCode === 200 && res.data) { + this.originData = res.data; + + + const chartData = this.originData.chart_data || {}; + const labels = chartData.labels || []; + const counts = chartData.counts || []; + + // 1. 找到counts中的最大值(用于计算热度颜色) + const maxCount = counts.length > 0 ? Math.max(...counts) : 0; + + // 2. 遍历组装bkList(包含标题、数量、背景色、占比),先保证labels和counts长度一致 + let bkList = []; + const maxLen = Math.min(labels.length, counts.length); // 取两者较短的长度,避免越界 + for (let i = 0; i < maxLen; i++) { + const title = labels[i]; + const count = counts[i] || 0; + + bkList.push({ + title, // 板块名称 + count, // 数量 + }); + } + + + this.bkList = bkList; + + } else { + uni.showToast({ + title: '数据请求失败', + icon: 'none' + }); + } + } catch (error) { + console.error('请求异常:', error); + uni.showToast({ + title: '网络异常', + icon: 'none' + }); + } + }, } }