mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-14 12:42:51 +00:00
perf: 优化时间组件
This commit is contained in:
parent
51a3ad25d1
commit
33cd9358c0
@ -141,6 +141,7 @@ export default {
|
||||
windowActive(active) {
|
||||
if (active) {
|
||||
this.autoTheme()
|
||||
$A.updateTimezone()
|
||||
this.__windowTimer && clearTimeout(this.__windowTimer)
|
||||
this.__windowTimer = setTimeout(_ => {
|
||||
this.$store.dispatch("call", {
|
||||
@ -313,6 +314,7 @@ export default {
|
||||
// APP进入前台
|
||||
window.__onAppActive = () => {
|
||||
this.autoTheme()
|
||||
$A.updateTimezone()
|
||||
$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
|
||||
* @returns {number}
|
||||
* 时间对象(减去时区差)
|
||||
* @param v
|
||||
* @returns {*|dayjs.Dayjs}
|
||||
*/
|
||||
setTimezone(tz) {
|
||||
const local = $A.dayjs().startOf('hour');
|
||||
const server = local.tz(tz);
|
||||
return $A.timezoneDifference = local.startOf('hour').diff(server.format("YYYY-MM-DD HH:mm:ss"), 'hour')
|
||||
daytz(v = undefined) {
|
||||
const t = $A.dayjs(v)
|
||||
if ($A.timezoneDifference) {
|
||||
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,
|
||||
|
||||
/**
|
||||
@ -2000,7 +2016,7 @@ const timezone = require("dayjs/plugin/timezone");
|
||||
* @returns {string}
|
||||
*/
|
||||
timeFormat(date) {
|
||||
const local = $A.dayjs().subtract($A.timezoneDifference, "hour"),
|
||||
const local = $A.daytz(),
|
||||
time = $A.dayjs(date);
|
||||
if (local.format("YYYY-MM-DD") === time.format("YYYY-MM-DD")) {
|
||||
return time.format("HH:mm")
|
||||
@ -2021,7 +2037,7 @@ const timezone = require("dayjs/plugin/timezone");
|
||||
* @returns {string}
|
||||
*/
|
||||
countDownFormat(s, e) {
|
||||
s = $A.dayjs(s).subtract($A.timezoneDifference, "hour")
|
||||
s = $A.daytz(s)
|
||||
e = $A.dayjs(e)
|
||||
const diff = e.diff(s, 'second');
|
||||
if (diff == 0) {
|
||||
|
||||
@ -1395,7 +1395,7 @@ export default {
|
||||
|
||||
windowScrollY(val) {
|
||||
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-hello">{{$L('欢迎您,' + userInfo.nickname)}}</div>
|
||||
<div class="dashboard-desc">
|
||||
{{$L('以下是你当前的任务统计数据')}}
|
||||
<template v-if="systemConfig.timezoneDifference">, {{$L('服务器时间')}}: {{$A.dayjs().subtract(systemConfig.timezoneDifference, 'hour').format('YYYY-MM-DD HH:mm:ss')}}</template>
|
||||
<span>{{$L('以下是你当前的任务统计数据')}}</span>
|
||||
<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">
|
||||
<div v-if="loadDashboardTasks" class="dashboard-load"><Loading/></div>
|
||||
</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",
|
||||
}).then(({data}) => {
|
||||
state.systemConfig = Object.assign(data, {
|
||||
timezoneDifference: $A.setTimezone(data.server_timezone),
|
||||
timezoneDifference: $A.updateTimezone(data.server_timezone),
|
||||
__state: "success",
|
||||
})
|
||||
resolve(state.systemConfig)
|
||||
|
||||
@ -51,6 +51,9 @@
|
||||
padding: 0 12px;
|
||||
color: #888888;
|
||||
font-size: 13px;
|
||||
.dashboard-time {
|
||||
padding-left: 4px;
|
||||
}
|
||||
.dashboard-load {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user