perf: 优化时间组件

This commit is contained in:
kuaifan 2024-09-22 15:21:54 +03:00
parent 912d229bdd
commit f586938fe9
3 changed files with 21 additions and 9 deletions

View File

@ -1890,12 +1890,17 @@ const timezone = require("dayjs/plugin/timezone");
/** /**
* 设置时区 * 设置时区
* @param tz * @param tz
* @returns {number}
*/ */
setTimezone(tz) { setTimezone(tz) {
const local = $A.dayjs().startOf('hour'); const local = $A.dayjs().startOf('hour');
const server = local.tz(tz); const server = local.tz(tz);
$A.timezoneDifference = local.startOf('hour').diff(server.format("YYYY-MM-DD HH:mm:ss"), 'hour') return $A.timezoneDifference = local.startOf('hour').diff(server.format("YYYY-MM-DD HH:mm:ss"), 'hour')
}, },
/**
* 本地时间与服务器时间差小时
*/
timezoneDifference: 0, timezoneDifference: 0,
/** /**

View File

@ -8,6 +8,7 @@
<div class="dashboard-hello">{{$L('欢迎您,' + userInfo.nickname)}}</div> <div class="dashboard-hello">{{$L('欢迎您,' + userInfo.nickname)}}</div>
<div class="dashboard-desc"> <div class="dashboard-desc">
{{$L('以下是你当前的任务统计数据')}} {{$L('以下是你当前的任务统计数据')}}
<template v-if="systemConfig.timezoneDifference">, {{$L('服务器时间')}}: {{$A.dayjs().subtract(systemConfig.timezoneDifference, 'hour').format('YYYY-MM-DD HH:mm:ss')}}</template>
<transition name="dashboard-load"> <transition name="dashboard-load">
<div v-if="loadDashboardTasks" class="dashboard-load"><Loading/></div> <div v-if="loadDashboardTasks" class="dashboard-load"><Loading/></div>
</transition> </transition>
@ -129,7 +130,7 @@ export default {
}, },
computed: { computed: {
...mapState(['userInfo', 'userIsAdmin', 'cacheTasks', 'taskCompleteTemps', 'loadDashboardTasks']), ...mapState(['systemConfig', 'userInfo', 'userIsAdmin', 'cacheTasks', 'taskCompleteTemps', 'loadDashboardTasks']),
...mapGetters(['dashboardTask', 'assistTask', 'transforTasks']), ...mapGetters(['dashboardTask', 'assistTask', 'transforTasks']),
@ -203,17 +204,23 @@ export default {
}, },
scrollTo(type) { scrollTo(type) {
let refs = this.$refs[`type_${type}`] const refs = this.$refs[`type_${type}`]
if (refs) { if (refs) {
const index = this.hiddenColumns.indexOf(type);
if (index !== -1) {
this.hiddenColumns.splice(index, 1)
}
this.$nextTick(_ => {
$A.scrollToView(refs[0], { $A.scrollToView(refs[0], {
behavior: 'smooth', behavior: 'smooth',
inline: 'end', inline: 'end',
}); });
})
} }
}, },
onDashboardHidden(type) { onDashboardHidden(type) {
let index = this.hiddenColumns.indexOf(type); const index = this.hiddenColumns.indexOf(type);
if (index === -1) { if (index === -1) {
this.hiddenColumns.push(type) this.hiddenColumns.push(type)
} else { } else {

View File

@ -340,8 +340,8 @@ export default {
dispatch("call", { dispatch("call", {
url: "system/setting", url: "system/setting",
}).then(({data}) => { }).then(({data}) => {
$A.setTimezone(data.server_timezone);
state.systemConfig = Object.assign(data, { state.systemConfig = Object.assign(data, {
timezoneDifference: $A.setTimezone(data.server_timezone),
__state: "success", __state: "success",
}) })
resolve(state.systemConfig) resolve(state.systemConfig)