Browse Source

Merge pull request '修改测试' (#135) from test-change into master

Reviewed-on: #135
master
zhangqi 6 days ago
parent
commit
e8b46ff949
  1. 101
      src/utils/common.js
  2. 36
      src/views/super/Ranking/RankBatchList.vue

101
src/utils/common.js

@ -2,7 +2,10 @@
export function setHighActive(dom) { export function setHighActive(dom) {
const ele = document.getElementById(dom) const ele = document.getElementById(dom)
ele.classList.add('ceshi') ele.classList.add('ceshi')
ele.scrollIntoView({behavior:'smooth',block:'start'}) ele.scrollIntoView({
behavior: 'smooth',
block: 'start'
})
setTimeout(() => { setTimeout(() => {
ele.classList.remove('ceshi') ele.classList.remove('ceshi')
}, 1000) }, 1000)
@ -30,3 +33,99 @@ export function getServicePriceDesc(price, price_unit, unit_num, unit_name) {
return price + price_unit + "/" + unit_str + unit_name; return price + price_unit + "/" + unit_str + unit_name;
} }
/**
* 获取格式化的日期字符串--是当下日期
* @param {string} format - 日期格式可选值'YYYY-MM-DD', 'YYYY-MM', 'YYYY', 'HH:mm:ss'
* @returns {string} 格式化后的日期字符串
*
// 使用示例
// console.log(getFormattedDate('YYYY')); // 2024
// console.log(getFormattedDate('YYYY-MM')); // 2024-01
// console.log(getFormattedDate('YYYY-MM-DD')); // 2024-01-15
*/
export const getFormattedDate = (format = 'YYYY-MM-DD') => {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
const hour = String(now.getHours()).padStart(2, '0');
const minute = String(now.getMinutes()).padStart(2, '0');
const second = String(now.getSeconds()).padStart(2, '0');
const formats = {
'YYYY': year,
'YYYY-MM': `${year}-${month}`,
'YYYY-MM-DD': `${year}-${month}-${day}`,
'HH:mm:ss': `${hour}:${minute}:${second}`,
'YYYY-MM-DD HH:mm:ss': `${year}-${month}-${day} ${hour}:${minute}:${second}`,
'YYYY/MM/DD': `${year}/${month}/${day}`,
'YYYY年MM月DD日': `${year}${month}${day}`,
};
return formats[format] || formats['YYYY-MM-DD'];
};
// 根据指定日期获取年月格式字符串
/**
* 日期格式化函数
*
* @param {string} dateStr - 日期字符串可被Date构造函数解析
* @param {string} [format='yyyy-mm'] - 输出格式可选值'year''month''year-month''yyyy''mm''m''yyyy-mm''yyyy-m'
* @returns {string} 格式化后的日期字符串如果日期无效则返回'Invalid date'
* 使用示例
* 1. console.log(getDate('2023-12-31')); // 输出: "2023-12"
* 2. console.log(getDate('2023-12-31', 'yyyy' || 'year')); // 输出: "2023"
* 3. console.log(getDate('2023-12-31', 'yyyy-m')); // 输出: "2023-12"
* 4. console.log(getDate('2023-12-31', 'm' || 'month')); // 输出: "12"
* 7. console.log(getDate('2023-12-31', 'year-month')); // 输出: "2023-12"
* 8. console.log(getDate('2023-12-31', 'yyyy/mm')); // 输出: "Invalid date"(因为格式'yyyy/mm'不在可选值中)
* 9.console.log(getDate('2025-03-15T10:30:00', 'yyyy-mm')); // ISO格式
* 10.console.log(getDate('March 15, 2025', 'yyyy'));//2023 // 英文日期
* 11.console.log(getDate('2025/03/15', 'year-month')); // 输出: "2025-03"
*/
export function getDate(dateStr, format = 'yyyy-mm') {
try {
const date = new Date(dateStr);
// 检查日期是否有效
if (isNaN(date.getTime())) {
throw new Error('日期无效');
}
const year = date.getFullYear();
const month = date.getMonth() + 1;
const formats = {
'year': `${year}`,
'month': `${month.toString().padStart(2, '0')}`,
'year-month': `${year}-${month.toString().padStart(2, '0')}`,
'yyyy': `${year}`,
'mm': `${month.toString().padStart(2, '0')}`,
'm': `${month}`,
'yyyy-mm': `${year}-${month.toString().padStart(2, '0')}`, //补0
'yyyy-m': `${year}-${month}`//不补0
};
return formats[format] || formats['yyyy-mm'];
} catch (error) {
console.error('Error parsing date:', error);
return 'Invalid date';
}
}
//金额千分符 会在整数后添加两个0 --适用于直接显示的
export function stateFormat(row, column, cellValue) {
if (cellValue) {
return Number(cellValue)
.toFixed(2)
.replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
return $1 + ",";
})
.replace(/\.$/, "");
}
}
//金额千分符 自定义渲染表格内容情况下,调用此方法
export function formatNumber(value) {
if (value === null || value === undefined) return '';
return Number(value).toLocaleString();
}

36
src/views/super/Ranking/RankBatchList.vue

@ -29,7 +29,6 @@
<el-table-column fixed="left" <el-table-column fixed="left"
v-if="(dataRank == 1 || dataRank == 2) && (dataType == 'ver_type' || dataType == 'check_type')" v-if="(dataRank == 1 || dataRank == 2) && (dataType == 'ver_type' || dataType == 'check_type')"
prop="name" :key="selectedType" :label="type_select[selectedType]" min-width="120"> prop="name" :key="selectedType" :label="type_select[selectedType]" min-width="120">
<template slot="header"> <template slot="header">
<el-select class="custom-select tableHeaderSelect" popper-class="custom-select-dropdown" <el-select class="custom-select tableHeaderSelect" popper-class="custom-select-dropdown"
v-model="selectedType" @change="changeRankType"> v-model="selectedType" @change="changeRankType">
@ -50,13 +49,11 @@
:prop="String(index + 1)" :prop="String(index + 1)"
:render-header=" (h, scope) => index == 3 ? renderHeaderWithIcon(h, scope, require('@/assets/require.svg')) : scope.column.label" :render-header=" (h, scope) => index == 3 ? renderHeaderWithIcon(h, scope, require('@/assets/require.svg')) : scope.column.label"
sortable="custom" min-width="170"> sortable="custom" min-width="170">
<!--产品利润排行展示查看更多--> <!--产品利润排行展示查看更多-->
<template v-if="index == 3 && dataRank == 1" scope="{ row, $index }"> <template v-if="index == 3 && dataRank == 1" scope="{ row, $index }">
<el-popover v-model="row.id_popover" :ref="`popover-${row.id}`" <el-popover v-model="row.id_popover" :ref="`popover-${row.id}`"
placement="bottom" trigger="manual" :append-to-body="false" :visible-arrow="true" placement="bottom" trigger="manual" :append-to-body="false" :visible-arrow="true"
popper-class="custom-popover" @show="popshow" > popper-class="custom-popover" @show="popshow" >
<div v-if="type != 'agent'" class="pop-wrap"> <div v-if="type != 'agent'" class="pop-wrap">
<div class="flex-between flex pop-top"> <div class="flex-between flex pop-top">
<h3> <h3>
@ -69,7 +66,6 @@
</div> </div>
<el-table :data="tableData1" style="width: 100%"> <el-table :data="tableData1" style="width: 100%">
<el-table-column prop="value_1" width="200" label="日期"></el-table-column> <el-table-column prop="value_1" width="200" label="日期"></el-table-column>
<el-table-column width="200" :label="rank_type_desc[dataRank]"> <el-table-column width="200" :label="rank_type_desc[dataRank]">
<template slot-scope="scope"> <template slot-scope="scope">
<div class="flex"> <div class="flex">
@ -91,7 +87,6 @@
</div> </div>
<el-table :data="tableData1" style="width: 100%"> <el-table :data="tableData1" style="width: 100%">
<el-table-column prop="sort" width="95" label="排序"> <el-table-column prop="sort" width="95" label="排序">
</el-table-column> </el-table-column>
<el-table-column prop="name" width="250" label="服务名称"></el-table-column> <el-table-column prop="name" width="250" label="服务名称"></el-table-column>
<el-table-column prop="rate" width="130" label="毛利占比"> <el-table-column prop="rate" width="130" label="毛利占比">
@ -111,7 +106,6 @@
<el-table-column prop="value_2" width="130" label="订单数"></el-table-column> <el-table-column prop="value_2" width="130" label="订单数"></el-table-column>
</el-table> </el-table>
</div> </div>
<div class="flex" slot="reference"> <div class="flex" slot="reference">
<!-- {{ row[field] }} --> <!-- {{ row[field] }} -->
{{ $formatNumber(row[field]) }} {{ $formatNumber(row[field]) }}
@ -120,7 +114,6 @@
:hoverColor="'#006AFF'" @click="handleClick(row, $index, 'id')" /> :hoverColor="'#006AFF'" @click="handleClick(row, $index, 'id')" />
</div> </div>
</el-popover> </el-popover>
</template> </template>
<template v-else slot-scope="scope"> <template v-else slot-scope="scope">
<div class="flex"> <div class="flex">
@ -128,7 +121,6 @@
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
<!--产品利润排行展示代理商排行--> <!--产品利润排行展示代理商排行-->
<el-table-column v-if="dataRank == 1 && (dataType == 'ver_type' || dataType == 'check_type')" <el-table-column v-if="dataRank == 1 && (dataType == 'ver_type' || dataType == 'check_type')"
:render-header=" (h, scope) => renderHeaderWithIcon(h, scope, require('@/assets/require.svg')) " :render-header=" (h, scope) => renderHeaderWithIcon(h, scope, require('@/assets/require.svg')) "
@ -183,6 +175,7 @@ import GuipTable from '@/components/GuipTable.vue';
import CustomDropdown from '@/components/CustomDropdown.vue'; import CustomDropdown from '@/components/CustomDropdown.vue';
import SvgIcon from '@/components/SvgIcon.vue'; import SvgIcon from '@/components/SvgIcon.vue';
import GuipToolTip from '@/components/GuipToolTip.vue'; import GuipToolTip from '@/components/GuipToolTip.vue';
import {getDate,getFormattedDate} from "@/utils/common.js"
// import HoverImage from '@/components/super/HoverImage.vue'; // import HoverImage from '@/components/super/HoverImage.vue';
export default { export default {
name: 'rank_batch_list', name: 'rank_batch_list',
@ -269,8 +262,6 @@ export default {
this.text = this.getNowDate() this.text = this.getNowDate()
this.dataType = this.type this.dataType = this.type
this.dataRank = this.rank_type this.dataRank = this.rank_type
this.getRankingData(); this.getRankingData();
}, },
handleUpdateView(newView) { handleUpdateView(newView) {
@ -278,32 +269,17 @@ export default {
}, },
getNowDate() { getNowDate() {
const viewdesc = this.viewDesc[this.view]; const viewdesc = this.viewDesc[this.view];
const now = new Date(); const currentYearMonth = getFormattedDate('YYYY-MM')
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0'); // 0
const currentYearMonth = `${year}-${month}`;
this.textDesc = viewdesc + currentYearMonth; this.textDesc = viewdesc + currentYearMonth;
return `${currentYearMonth}` return `${currentYearMonth}`
}, },
getDate(dateStr) {
const date = new Date(dateStr);
const year = date.getFullYear(); // 2025
const month = date.getMonth() + 1; // 3 (3)
if (this.view == 'year') {
return `${year}`
} else {
return `${year}-${month}`
}
},
handleDateChange(date) { handleDateChange(date) {
const viewdesc = this.viewDesc[this.view]; const viewdesc = this.viewDesc[this.view];
this.text = this.getDate(date) this.text = this.view == 'year' ? getDate(date,'yyyy') : getDate(date,'yyyy-mm')
this.textDesc = viewdesc + this.text; this.textDesc = viewdesc + this.text;
this.selectedDate = date; this.selectedDate = date;
localStorage.setItem('date', JSON.stringify(date)) localStorage.setItem('date', JSON.stringify(date))
this.$refs.dropdownRef.closeDropdown(); this.$refs.dropdownRef.closeDropdown();
this.currentPage = 1; this.currentPage = 1;
this.getRankingData() this.getRankingData()
}, },
@ -366,7 +342,6 @@ export default {
}); });
// //
row[type + '_popover'] = true; row[type + '_popover'] = true;
let obj = {} let obj = {}
if (this.dataType == 'agent') { if (this.dataType == 'agent') {
obj.aid = row.id obj.aid = row.id
@ -396,7 +371,6 @@ export default {
}); });
// //
row[type + '_popover_2'] = true; row[type + '_popover_2'] = true;
let obj = {} let obj = {}
if (this.dataType == 'agent') { if (this.dataType == 'agent') {
obj.aid = row.id obj.aid = row.id
@ -414,7 +388,6 @@ export default {
ariaEls.forEach((item) => { ariaEls.forEach((item) => {
item.removeAttribute('aria-hidden') item.removeAttribute('aria-hidden')
}) })
ariaEls = document.querySelectorAll('.el-radio__original') ariaEls = document.querySelectorAll('.el-radio__original')
ariaEls.forEach((item) => { ariaEls.forEach((item) => {
item.removeAttribute('aria-hidden') item.removeAttribute('aria-hidden')
@ -464,10 +437,8 @@ export default {
const date = new Date(this.text); const date = new Date(this.text);
const year = date.getFullYear(); const year = date.getFullYear();
const month = date.getMonth() + 1; const month = date.getMonth() + 1;
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
const currentMonth = new Date().getMonth() + 1; const currentMonth = new Date().getMonth() + 1;
this.current_month = ''; this.current_month = '';
if (this.view === 'month' && year == currentYear && month == currentMonth) { if (this.view === 'month' && year == currentYear && month == currentMonth) {
this.current_month = '(当月)'; this.current_month = '(当月)';
@ -483,7 +454,6 @@ export default {
for (let i = 3; i >= 0; i--) { for (let i = 3; i >= 0; i--) {
let m = month - i; let m = month - i;
if (m <= 0) m += 12; if (m <= 0) m += 12;
monthLabels.push(m + '月' + this.rank_type_desc[this.rank_type]); monthLabels.push(m + '月' + this.rank_type_desc[this.rank_type]);
} }
this.labels = monthLabels; this.labels = monthLabels;

Loading…
Cancel
Save