mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-15 21:32:49 +00:00
perf: 优化时间组件
This commit is contained in:
parent
51a3ad25d1
commit
33cd9358c0
@ -141,6 +141,7 @@ export default {
|
|||||||
windowActive(active) {
|
windowActive(active) {
|
||||||
if (active) {
|
if (active) {
|
||||||
this.autoTheme()
|
this.autoTheme()
|
||||||
|
$A.updateTimezone()
|
||||||
this.__windowTimer && clearTimeout(this.__windowTimer)
|
this.__windowTimer && clearTimeout(this.__windowTimer)
|
||||||
this.__windowTimer = setTimeout(_ => {
|
this.__windowTimer = setTimeout(_ => {
|
||||||
this.$store.dispatch("call", {
|
this.$store.dispatch("call", {
|
||||||
@ -313,6 +314,7 @@ export default {
|
|||||||
// APP进入前台
|
// APP进入前台
|
||||||
window.__onAppActive = () => {
|
window.__onAppActive = () => {
|
||||||
this.autoTheme()
|
this.autoTheme()
|
||||||
|
$A.updateTimezone()
|
||||||
$A.IDBTest()
|
$A.IDBTest()
|
||||||
}
|
}
|
||||||
// 页面失活
|
// 页面失活
|
||||||
|
|||||||
36
resources/assets/js/functions/common.js
vendored
36
resources/assets/js/functions/common.js
vendored
@ -1888,19 +1888,35 @@ const timezone = require("dayjs/plugin/timezone");
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置时区
|
* 时间对象(减去时区差)
|
||||||
* @param tz
|
* @param v
|
||||||
* @returns {number}
|
* @returns {*|dayjs.Dayjs}
|
||||||
*/
|
*/
|
||||||
setTimezone(tz) {
|
daytz(v = undefined) {
|
||||||
const local = $A.dayjs().startOf('hour');
|
const t = $A.dayjs(v)
|
||||||
const server = local.tz(tz);
|
if ($A.timezoneDifference) {
|
||||||
return $A.timezoneDifference = local.startOf('hour').diff(server.format("YYYY-MM-DD HH:mm:ss"), 'hour')
|
return t.subtract($A.timezoneDifference, "hour")
|
||||||
|
}
|
||||||
|
return t;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地时间与服务器时间差(小时)
|
* 更新时区
|
||||||
|
* @param tz
|
||||||
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
|
updateTimezone(tz = undefined) {
|
||||||
|
if (typeof tz !== "undefined") {
|
||||||
|
$A.timezoneName = tz;
|
||||||
|
}
|
||||||
|
if (!$A.timezoneName) {
|
||||||
|
return $A.timezoneDifference = 0;
|
||||||
|
}
|
||||||
|
const local = $A.dayjs().startOf('hour');
|
||||||
|
const server = local.tz($A.timezoneName);
|
||||||
|
return $A.timezoneDifference = local.startOf('hour').diff(server.format("YYYY-MM-DD HH:mm:ss"), 'hour')
|
||||||
|
},
|
||||||
|
timezoneName: null,
|
||||||
timezoneDifference: 0,
|
timezoneDifference: 0,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2000,7 +2016,7 @@ const timezone = require("dayjs/plugin/timezone");
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
timeFormat(date) {
|
timeFormat(date) {
|
||||||
const local = $A.dayjs().subtract($A.timezoneDifference, "hour"),
|
const local = $A.daytz(),
|
||||||
time = $A.dayjs(date);
|
time = $A.dayjs(date);
|
||||||
if (local.format("YYYY-MM-DD") === time.format("YYYY-MM-DD")) {
|
if (local.format("YYYY-MM-DD") === time.format("YYYY-MM-DD")) {
|
||||||
return time.format("HH:mm")
|
return time.format("HH:mm")
|
||||||
@ -2021,7 +2037,7 @@ const timezone = require("dayjs/plugin/timezone");
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
countDownFormat(s, e) {
|
countDownFormat(s, e) {
|
||||||
s = $A.dayjs(s).subtract($A.timezoneDifference, "hour")
|
s = $A.daytz(s)
|
||||||
e = $A.dayjs(e)
|
e = $A.dayjs(e)
|
||||||
const diff = e.diff(s, 'second');
|
const diff = e.diff(s, 'second');
|
||||||
if (diff == 0) {
|
if (diff == 0) {
|
||||||
|
|||||||
@ -1395,7 +1395,7 @@ export default {
|
|||||||
|
|
||||||
windowScrollY(val) {
|
windowScrollY(val) {
|
||||||
if ($A.isIos() && !this.$slots.head) {
|
if ($A.isIos() && !this.$slots.head) {
|
||||||
this.$refs.nav.style.marginTop = `${val}px`
|
this.$refs.nav.style.marginTop = `${Math.max(0, val)}px`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,11 @@
|
|||||||
<div class="dashboard-wrapper" :style="wrapperStyle">
|
<div class="dashboard-wrapper" :style="wrapperStyle">
|
||||||
<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('以下是你当前的任务统计数据')}}
|
<span>{{$L('以下是你当前的任务统计数据')}}</span>
|
||||||
<template v-if="systemConfig.timezoneDifference">, {{$L('服务器时间')}}: {{$A.dayjs().subtract(systemConfig.timezoneDifference, 'hour').format('YYYY-MM-DD HH:mm:ss')}}</template>
|
<template v-if="systemConfig.timezoneDifference">,
|
||||||
|
<span class="dashboard-time">{{$L('服务器时间')}}:</span>
|
||||||
|
<span class="dashboard-time">{{$A.daytz().format('YYYY-MM-DD HH:mm:ss')}}</span>
|
||||||
|
</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>
|
||||||
|
|||||||
2
resources/assets/js/store/actions.js
vendored
2
resources/assets/js/store/actions.js
vendored
@ -341,7 +341,7 @@ export default {
|
|||||||
url: "system/setting",
|
url: "system/setting",
|
||||||
}).then(({data}) => {
|
}).then(({data}) => {
|
||||||
state.systemConfig = Object.assign(data, {
|
state.systemConfig = Object.assign(data, {
|
||||||
timezoneDifference: $A.setTimezone(data.server_timezone),
|
timezoneDifference: $A.updateTimezone(data.server_timezone),
|
||||||
__state: "success",
|
__state: "success",
|
||||||
})
|
})
|
||||||
resolve(state.systemConfig)
|
resolve(state.systemConfig)
|
||||||
|
|||||||
@ -51,6 +51,9 @@
|
|||||||
padding: 0 12px;
|
padding: 0 12px;
|
||||||
color: #888888;
|
color: #888888;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
|
.dashboard-time {
|
||||||
|
padding-left: 4px;
|
||||||
|
}
|
||||||
.dashboard-load {
|
.dashboard-load {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user