涨停分析选中修改

This commit is contained in:
renzhijun
2026-02-04 15:40:55 +08:00
parent b957844c6b
commit eeca65538c
3 changed files with 504 additions and 515 deletions

View File

@@ -25,12 +25,12 @@
</view> </view>
<view class="monthDateList" style="display: grid; grid-template-columns: repeat(7, 1fr); gap: 17rpx;"> <view class="monthDateList" style="display: grid; grid-template-columns: repeat(7, 1fr); gap: 17rpx;">
<view class="item" v-for="(item,index) in monthDateList[selectMonthIndex]" :key="index" <view class="item" v-for="(item,index) in monthDateList[selectMonthIndex]" :key="index"
@click="clickSelectDate(item)"> @click="clickSelectDate(item, index)">
<block v-if="item.date==selectDateStr"> <block v-if="item.date==selectDateStr">
<view :class="[ <view :class="[
'date', 'date',
'select', 'select',
getZtCountBgClass(getCalendarItemByDate(item.date)?.zt_count) getZtCountBgClass(getCalendarItemByDate(item.date)?.zt_count),selectedDateKey === item.date ? 'selected-border' : ''
]"> ]">
{{item.day}} {{item.day}}
<view v-if="index % 7 == 0 || index % 7 == 6" style="color: #999999; font-size: 18rpx;">休市 <view v-if="index % 7 == 0 || index % 7 == 6" style="color: #999999; font-size: 18rpx;">休市
@@ -57,7 +57,7 @@
<block v-else> <block v-else>
<view :class="[ <view :class="[
'date', 'date',
getZtCountBgClass(getCalendarItemByDate(item.date)?.zt_count) getZtCountBgClass(getCalendarItemByDate(item.date)?.zt_count),selectedDateKey === item.date ? 'selected-border' : ''
]"> ]">
<view :style="{color: (index % 7 == 0 || index % 7 == 6 ? '#999999' : '#2A2A2A')}"> <view :style="{color: (index % 7 == 0 || index % 7 == 6 ? '#999999' : '#2A2A2A')}">
@@ -105,6 +105,8 @@
selectYear: '', selectYear: '',
Month: '', Month: '',
calendarApiData: [], // 新增:存储接口返回的日历数据 calendarApiData: [], // 新增:存储接口返回的日历数据
selectedDateKey: '', // 新增选中日期的唯一标识格式YYYY-MM-DD
}; };
}, },
created() { created() {
@@ -120,20 +122,22 @@
//结束日期默认为当前日期 //结束日期默认为当前日期
// this.endDateStr = this.selectDateStr = currentYear + '-' + (currentMonth > 9 ? currentMonth : ('0' + // this.endDateStr = this.selectDateStr = currentYear + '-' + (currentMonth > 9 ? currentMonth : ('0' +
// currentMonth)) + '-' + (currentDay > 9 ? currentDay : ('0' + currentDay)) // currentMonth)) + '-' + (currentDay > 9 ? currentDay : ('0' + currentDay))
this.endDateStr = this.selectDateStr = this.endDateStr = this.selectDateStr =
`${currentYear}-${currentMonth > 9 ? currentMonth : '0' + currentMonth}-${currentDay > 9 ? currentDay : '0' + currentDay}` `${currentYear}-${currentMonth > 9 ? currentMonth : '0' + currentMonth}-${currentDay > 9 ? currentDay : '0' + currentDay}`
this.getYesterdayDateData() this.getYesterdayDateData()
this.generateMonthDateListData() this.generateMonthDateListData()
// 新增:初始化时触发一次事件,传递当天数据给父页面 // 新增:初始化时触发一次事件,传递当天数据给父页面
//this.emitDateChange(currentYear, currentMonth, currentDay, this.getTodayItem(currentYear, currentMonth, currentDay)) //this.emitDateChange(currentYear, currentMonth, currentDay, this.getTodayItem(currentYear, currentMonth, currentDay))
this.emitDateChange( this.emitDateChange(
currentYear, currentYear,
currentMonth, currentMonth,
currentDay, currentDay,
this.getTodayItem(currentYear, currentMonth, currentDay), this.getTodayItem(currentYear, currentMonth, currentDay),
this.getPrevDayItem(currentYear, currentMonth, currentDay) // 新增上一天数据 this.getPrevDayItem(currentYear, currentMonth, currentDay) // 新增上一天数据
) )
}, },
mounted() { mounted() {
this.getCalendarCombinedData() this.getCalendarCombinedData()
@@ -144,94 +148,75 @@ this.emitDateChange(
* 获取指定日期的上一天数据 * 获取指定日期的上一天数据
*/ */
getPrevDayItem(year, month, day) { getPrevDayItem(year, month, day) {
// 计算上一天日期 // 计算上一天日期
const currentDate = new Date(`${year}-${month}-${day}`); const currentDate = new Date(`${year}-${month}-${day}`);
const prevDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000); const prevDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000);
const prevYear = prevDate.getFullYear(); const prevYear = prevDate.getFullYear();
const prevMonth = prevDate.getMonth() + 1; const prevMonth = prevDate.getMonth() + 1;
const prevDay = prevDate.getDate(); const prevDay = prevDate.getDate();
// 获取上一天的完整数据 // 获取上一天的完整数据
const targetDate = `${prevYear}-${prevMonth > 9 ? prevMonth : '0' + prevMonth}-${prevDay > 9 ? prevDay : '0' + prevDay}`; const targetDate =
const currentMonthList = this.monthDateList[this.selectMonthIndex] || []; `${prevYear}-${prevMonth > 9 ? prevMonth : '0' + prevMonth}-${prevDay > 9 ? prevDay : '0' + prevDay}`;
const localItem = currentMonthList.find(item => item.date === targetDate) || null; const currentMonthList = this.monthDateList[this.selectMonthIndex] || [];
const apiData = this.getCalendarItemByDate(targetDate) || {}; const localItem = currentMonthList.find(item => item.date === targetDate) || null;
const apiData = this.getCalendarItemByDate(targetDate) || {};
return { return {
...localItem, ...localItem,
zt_count: apiData.zt_count || 0, zt_count: apiData.zt_count || 0,
top_sector: apiData.top_sector || '-', top_sector: apiData.top_sector || '-',
zaban_rate: apiData.zaban_rate || '0%' zaban_rate: apiData.zaban_rate || '0%'
}; };
}, },
/** /**
* 获取当天的item数据合并接口数据 * 获取当天的item数据合并接口数据
*/ */
getTodayItem(year, month, day) { getTodayItem(year, month, day) {
const targetDate = `${year}-${month > 9 ? month : '0' + month}-${day > 9 ? day : '0' + day}`; const targetDate = `${year}-${month > 9 ? month : '0' + month}-${day > 9 ? day : '0' + day}`;
const currentMonthList = this.monthDateList[this.selectMonthIndex] || []; const currentMonthList = this.monthDateList[this.selectMonthIndex] || [];
// 先获取本地日期item // 先获取本地日期item
const localItem = currentMonthList.find(item => item.date === targetDate) || null; const localItem = currentMonthList.find(item => item.date === targetDate) || null;
if (!localItem) return null; if (!localItem) return null;
// 获取接口数据并合并 // 获取接口数据并合并
const apiData = this.getCalendarItemByDate(targetDate) || {}; const apiData = this.getCalendarItemByDate(targetDate) || {};
// 合并本地item和接口数据 // 合并本地item和接口数据
return { return {
...localItem, ...localItem,
zt_count: apiData.zt_count || 0, zt_count: apiData.zt_count || 0,
top_sector: apiData.top_sector || '-', top_sector: apiData.top_sector || '-',
// 可补充其他接口字段 // 可补充其他接口字段
zaban_rate: apiData.zaban_rate || '0%' // 示例:炸板率 zaban_rate: apiData.zaban_rate || '0%' // 示例:炸板率
}; };
}, },
/**
* 触发日期变更事件传递包含接口数据的item emitDateChange(year, month, day, item, prevItem = {
*/ zt_count: 0
// emitDateChange(year, month, day, item) { }) { // 新增prevItem参数设置默认值兜底
// const yearMonth = `${year}-${month > 9 ? month : '0' + month}`; const yearMonth = `${year}-${month > 9 ? month : '0' + month}`;
// const fullDate = `${year}-${month > 9 ? month : '0' + month}-${day > 9 ? day : '0' + day}`; const fullDate = `${year}-${month > 9 ? month : '0' + month}-${day > 9 ? day : '0' + day}`;
// this.$emit('date-change', { this.$emit('date-change', {
// yearMonth, yearMonth,
// fullDate, fullDate,
// item: item || { // 兜底无item时赋值空对象+默认值 item: item || { // 兜底:无当前item时赋值空对象+默认值
// date: fullDate, date: fullDate,
// year, year,
// month, month,
// day, day,
// zt_count: 0, zt_count: 0,
// top_sector: '-', top_sector: '-',
// zaban_rate: '0%' zaban_rate: '0%'
// }, },
// year, prevItem: prevItem || { // 新增:传递上一天数据,兜底默认值
// month, zt_count: 0,
// day top_sector: '-',
// }); zaban_rate: '0%'
// }, },
emitDateChange(year, month, day, item, prevItem = { zt_count: 0 }) { // 新增prevItem参数设置默认值兜底 year,
const yearMonth = `${year}-${month > 9 ? month : '0' + month}`; month,
const fullDate = `${year}-${month > 9 ? month : '0' + month}-${day > 9 ? day : '0' + day}`; day
this.$emit('date-change', { });
yearMonth, },
fullDate,
item: item || { // 兜底无当前item时赋值空对象+默认值
date: fullDate,
year,
month,
day,
zt_count: 0,
top_sector: '-',
zaban_rate: '0%'
},
prevItem: prevItem || { // 新增:传递上一天数据,兜底默认值
zt_count: 0,
top_sector: '-',
zaban_rate: '0%'
},
year,
month,
day
});
},
/** /**
* 获取当前时间前一天的数据 * 获取当前时间前一天的数据
@@ -304,36 +289,37 @@ this.emitDateChange(
* 获取日历接口数据 * 获取日历接口数据
*/ */
async getCalendarCombinedData() { async getCalendarCombinedData() {
try {
let param = { try {
year: this.selectYear, let param = {
month: this.Month year: this.selectYear,
} month: this.Month
const res = await calendarCombinedData(param); }
if (res.success && Array.isArray(res.data)) { const res = await calendarCombinedData(param);
this.calendarApiData = res.data; if (res.success && Array.isArray(res.data)) {
//console.log('日历数据加载成功', this.calendarApiData); this.calendarApiData = res.data;
// 接口数据加载后,重新触发一次当前选中日期的事件,更新数据 //console.log('日历数据加载成功', this.calendarApiData);
if (this.selectDateStr) { // 接口数据加载后,重新触发一次当前选中日期的事件,更新数据
const [year, month, day] = this.selectDateStr.split('-').map(Number); if (this.selectDateStr) {
//this.emitDateChange(year, month, day, this.getTodayItem(year, month, day)); const [year, month, day] = this.selectDateStr.split('-').map(Number);
this.emitDateChange( //this.emitDateChange(year, month, day, this.getTodayItem(year, month, day));
year, // this.emitDateChange(
month, // year,
day, // month,
this.getTodayItem(year, month, day), // day,
this.getPrevDayItem(year, month, day) // 新增上一天数据 // this.getTodayItem(year, month, day),
) // this.getPrevDayItem(year, month, day) // 新增上一天数据
} // )
} else { }
this.calendarApiData = []; } else {
console.warn('日历接口返回数据格式异常', res); this.calendarApiData = [];
} console.warn('日历接口返回数据格式异常', res);
} catch (error) { }
this.calendarApiData = []; } catch (error) {
console.error('获取日历数据失败', error); this.calendarApiData = [];
} console.error('获取日历数据失败', error);
}, }
},
/** /**
* 生成日期数组 * 生成日期数组
*/ */
@@ -440,6 +426,8 @@ this.emitDateChange(
*/ */
clickPreMonth() { clickPreMonth() {
if (this.selectMonthIndex > 0) { if (this.selectMonthIndex > 0) {
// 新增:切换月份时清空选中标识
this.selectedDateKey = '';
this.selectMonthIndex-- this.selectMonthIndex--
let monthList = this.monthDateList[this.selectMonthIndex] let monthList = this.monthDateList[this.selectMonthIndex]
let year = '' let year = ''
@@ -464,16 +452,19 @@ this.emitDateChange(
this.selectYear = year this.selectYear = year
this.Month = month; this.Month = month;
this.selectDateStr =this.startDateStr ;
this.getCalendarCombinedData() this.getCalendarCombinedData()
console.log('点击上个月'); console.log('点击上个月');
} }
}, },
/** /**
* 点击下个月 * 点击下个月
*/ */
clickNextMonth() { clickNextMonth() {
if (this.selectMonthIndex < this.monthDateList.length - 1) { if (this.selectMonthIndex < this.monthDateList.length - 1) {
// 新增:切换月份时清空选中标识
this.selectedDateKey = '';
this.selectMonthIndex++ this.selectMonthIndex++
let monthList = this.monthDateList[this.selectMonthIndex] let monthList = this.monthDateList[this.selectMonthIndex]
let year = '' let year = ''
@@ -498,9 +489,18 @@ this.emitDateChange(
console.log('点击下个月'); console.log('点击下个月');
this.selectYear = year this.selectYear = year
this.Month = month; this.Month = month;
this.selectDateStr =this.startDateStr ; // 统一格式 YYYY-MM
this.getCalendarCombinedData() this.getCalendarCombinedData()
} }
}, },
/**
* 通用补零函数确保数字为两位数不足则前面补0
* @param {number|string} num - 需要补零的数字
* @returns {string} 补零后的字符串
*/
padZero(num) {
return String(num).padStart(2, '0');
},
monthChange(e) { monthChange(e) {
let currentDate = new Date(); let currentDate = new Date();
//当前年份 //当前年份
@@ -526,82 +526,67 @@ this.emitDateChange(
* @param {Object} item * @param {Object} item
*/ */
clickSelectDate(item, index) { // 新增index参数 clickSelectDate(item, index) { // 新增index参数
if (!item.isCurrentMonth) return if (!item.isCurrentMonth) return
if (this.selectDateStr != item.date) { if (this.selectDateStr != item.date) {
this.selectDateStr = item.date
// 1. 获取该日期的接口数据
const apiData = this.getCalendarItemByDate(item.date) || {};
// 2. 合并本地item和接口数据补充默认值
const mergedItem = {
...item, // 本地日期基础数据
zt_count: apiData.zt_count || 0, // 涨停家数默认0
top_sector: apiData.top_sector || '-', // 热门板块,默认'-'
zaban_rate: apiData.zaban_rate || '0%', // 炸板率,示例字段
isWeekend: index % 7 === 0 || index % 7 === 6 // 是否周末
};
// ===== 新增:获取上一天的日期和数据 ===== this.selectedDateKey = item.date;
// 2.1 计算上一天的日期 this.selectDateStr = item.date
const currentDate = new Date(item.date); // 1. 获取该日期的接口数据
const prevDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000); // 减一天 const apiData = this.getCalendarItemByDate(item.date) || {};
const prevYear = prevDate.getFullYear(); // 2. 合并本地item和接口数据补充默认值
const prevMonth = prevDate.getMonth() + 1; const mergedItem = {
const prevDay = prevDate.getDate(); ...item, // 本地日期基础数据
const prevDateStr = `${prevYear}-${prevMonth > 9 ? prevMonth : '0' + prevMonth}-${prevDay > 9 ? prevDay : '0' + prevDay}`; zt_count: apiData.zt_count || 0, // 涨停家数默认0
top_sector: apiData.top_sector || '-', // 热门板块,默认'-'
zaban_rate: apiData.zaban_rate || '0%', // 炸板率,示例字段
isWeekend: index % 7 === 0 || index % 7 === 6 // 是否周末
};
// 2.2 获取上一天的接口数据 // ===== 新增:获取上一天的日期和数据 =====
const prevApiData = this.getCalendarItemByDate(prevDateStr) || {}; // 2.1 计算上一天的日期
// 2.3 查找上一天的本地item用于补全基础信息 const currentDate = new Date(item.date);
let prevLocalItem = null; const prevDate = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000); // 减一天
// 先在当前月份列表找 const prevYear = prevDate.getFullYear();
const currentMonthList = this.monthDateList[this.selectMonthIndex] || []; const prevMonth = prevDate.getMonth() + 1;
prevLocalItem = currentMonthList.find(i => i.date === prevDateStr); const prevDay = prevDate.getDate();
// 如果当前月份没有(跨月),找对应月份的列表 const prevDateStr =
if (!prevLocalItem) { `${prevYear}-${prevMonth > 9 ? prevMonth : '0' + prevMonth}-${prevDay > 9 ? prevDay : '0' + prevDay}`;
const prevMonthIndex = this.selectMonthIndex - (prevMonth < item.month ? 1 : 0);
const prevMonthList = this.monthDateList[prevMonthIndex] || [];
prevLocalItem = prevMonthList.find(i => i.date === prevDateStr);
}
// 2.4 合并上一天的完整数据 // 2.2 获取上一天的接口数据
const prevMergedItem = { const prevApiData = this.getCalendarItemByDate(prevDateStr) || {};
...(prevLocalItem || {}), // 2.3 查找上一天的本地item用于补全基础信息
zt_count: prevApiData.zt_count || 0, let prevLocalItem = null;
top_sector: prevApiData.top_sector || '-', // 先在当前月份列表找
zaban_rate: prevApiData.zaban_rate || '0%', const currentMonthList = this.monthDateList[this.selectMonthIndex] || [];
isWeekend: false // 兜底默认值 prevLocalItem = currentMonthList.find(i => i.date === prevDateStr);
}; // 如果当前月份没有(跨月),找对应月份的列表
// ======================================= if (!prevLocalItem) {
const prevMonthIndex = this.selectMonthIndex - (prevMonth < item.month ? 1 : 0);
const prevMonthList = this.monthDateList[prevMonthIndex] || [];
prevLocalItem = prevMonthList.find(i => i.date === prevDateStr);
}
this.chgStockData = mergedItem; // 2.4 合并上一天的完整数据
// 3. 解析日期,触发事件传递【当前数据+上一天数据】 const prevMergedItem = {
const [year, month, day] = item.date.split('-').map(Number); ...(prevLocalItem || {}),
this.emitDateChange(year, month, day, mergedItem, prevMergedItem); // 新增传递上一天数据 zt_count: prevApiData.zt_count || 0,
console.log('点击某天(含接口数据)', { current: mergedItem, prev: prevMergedItem }); top_sector: prevApiData.top_sector || '-',
} zaban_rate: prevApiData.zaban_rate || '0%',
isWeekend: false // 兜底默认值
};
// =======================================
this.chgStockData = mergedItem;
// 3. 解析日期,触发事件传递【当前数据+上一天数据】
const [year, month, day] = item.date.split('-').map(Number);
this.emitDateChange(year, month, day, mergedItem, prevMergedItem); // 新增传递上一天数据
console.log('点击某天(含接口数据)', {
current: mergedItem,
prev: prevMergedItem
});
}
} }
// clickSelectDate(item, index) {
// if (!item.isCurrentMonth) return
// if (this.selectDateStr != item.date) {
// this.selectDateStr = item.date
// const apiData = this.getCalendarItemByDate(item.date) || {};
// const mergedItem = {
// ...item,
// zt_count: apiData.zt_count || 0,
// top_sector: apiData.top_sector || '-',
// zaban_rate: apiData.zaban_rate || '0%',
// isWeekend: index % 7 === 0 || index % 7 === 6
// };
// this.chgStockData = mergedItem;
// const [year, month, day] = item.date.split('-').map(Number);
// this.emitDateChange(year, month, day, mergedItem);
// console.log('点击某天(含接口数据)', mergedItem);
// }
// }
} }
} }
</script> </script>
@@ -673,6 +658,10 @@ this.emitDateChange(
.chg.down { .chg.down {
color: #38A169; color: #38A169;
} }
&.selected-border {
border: 1px solid #FFCC00; // 黄色边框(可根据需求调整色值)
box-sizing: border-box; // 保证边框不超出容器
}
} }
// zt_count ≥80 背景色 // zt_count ≥80 背景色

View File

@@ -1,6 +1,6 @@
{ {
"name" : "JiaZhiQianYan", "name" : "JiaZhiQianYan",
"appid" : "__UNI__1836EC9", "appid" : "__UNI__C546BDE",
"description" : "", "description" : "",
"versionName" : "1.0.0", "versionName" : "1.0.0",
"versionCode" : "100", "versionCode" : "100",

View File

@@ -460,7 +460,7 @@
// 获取当前日期,并减去一天 // 获取当前日期,并减去一天
const now = new Date() const now = new Date()
// 核心修改:将日期减去 1 天1 天 = 24 * 60 * 60 * 1000 毫秒) // 核心修改:将日期减去 1 天1 天 = 24 * 60 * 60 * 1000 毫秒)
now.setTime(now.getTime() - 24 * 60 * 60 * 1000) // now.setTime(now.getTime() - 24 * 60 * 60 * 1000)
const year = now.getFullYear() const year = now.getFullYear()
const month = (now.getMonth() + 1).toString().padStart(2, '0') const month = (now.getMonth() + 1).toString().padStart(2, '0')