perf: 优化时间组件

This commit is contained in:
kuaifan 2024-09-22 17:42:46 +03:00
parent 33cd9358c0
commit dcd41b4be2
21 changed files with 67 additions and 66 deletions

View File

@ -49,7 +49,7 @@ export default {
return {
routePath: null,
appInter: null,
countDown: Math.min(30, 60 - $A.dayjs().second()),
countDown: Math.min(30, 60 - $A.daytz().second()),
}
},
@ -168,7 +168,7 @@ export default {
//
this.countDown--
if (this.countDown <= 0) {
this.countDown = Math.min(30, 60 - $A.dayjs().second())
this.countDown = Math.min(30, 60 - $A.daytz().second())
this.$store.dispatch("todayAndOverdue")
}
},

View File

@ -134,9 +134,9 @@ export default {
return function(index) {
let mouseDay = mouseWidth == 0 ? 0 : mouseWidth / dateWidth;
//00:00:00
let nowDay = $A.dayjs().startOf('day');
let nowDay = $A.daytz().startOf('day');
//
let curDay = nowDay.clone().add(mouseDay, 'day');
let curDay = nowDay.clone().add(mouseDay * 86400, 'second');
//
let lastDay = curDay.clone().endOf('month');
//
@ -157,7 +157,7 @@ export default {
return function(index) {
let mouseDay = mouseWidth == 0 ? 0 : mouseWidth / dateWidth;
//00:00:00
let nowDay = $A.dayjs().startOf('day');
let nowDay = $A.daytz().startOf('day');
//
let curDay = nowDay.clone().add(mouseDay, 'day');
//
@ -182,7 +182,7 @@ export default {
mouseData--;
}
let j = mouseWidth == 0 ? index - 1 : mouseData;
let date = $A.dayjs().add(j, 'day');
let date = $A.daytz().add(j, 'day');
if ([0, 6].indexOf(date.day()) !== -1) {
style.backgroundColor = '#f9fafb';
}
@ -204,7 +204,7 @@ export default {
mouseData--;
}
let j = mouseWidth == 0 ? index - 1 : mouseData;
let date = $A.dayjs().add(j, 'day');
let date = $A.daytz().add(j, 'day');
if (type == 'day') {
return date.date();
} else if (type == 'week') {
@ -220,13 +220,13 @@ export default {
const {start, end} = item.time;
const {style, moveX, moveW} = item;
//00:00:00
let nowTime = $A.dayjs().startOf('day').valueOf();
let nowTime = $A.daytz().startOf('day').valueOf();
//
let diffStartDay = (start - nowTime) / 1000 / 60 / 60 / 24;
let diffEndDay = (end - nowTime) / 1000 / 60 / 60 / 24;
//
let left = dateWidth * diffStartDay + (mouseWidth * -1);
let width = dateWidth * (diffEndDay - diffStartDay);
let width = Math.max(10, dateWidth * (diffEndDay - diffStartDay));
if (typeof moveX === "number") {
left+= moveX;
}
@ -419,7 +419,7 @@ export default {
},
scrollPosition(pos) {
//00:00:00
let nowDay = $A.dayjs().startOf('day').valueOf();
let nowDay = $A.daytz().startOf('day').valueOf();
//
let oneWidthTime = 86400000 / this.dateWidth;
//

View File

@ -109,7 +109,7 @@ export default {
if (this.user.online || this.$store.state.userId === this.userid) {
this.$emit('update:online', true)
} else {
const now = $A.dayjs()
const now = $A.daytz()
const line = $A.dayjs(this.user.line_at)
const seconds = now.unix() - line.unix()
let stats = '最后在线于很久以前';

View File

@ -1912,7 +1912,7 @@ const timezone = require("dayjs/plugin/timezone");
if (!$A.timezoneName) {
return $A.timezoneDifference = 0;
}
const local = $A.dayjs().startOf('hour');
const local = $A.daytz().startOf('hour');
const server = local.tz($A.timezoneName);
return $A.timezoneDifference = local.startOf('hour').diff(server.format("YYYY-MM-DD HH:mm:ss"), 'hour')
},

View File

@ -119,41 +119,41 @@ import {MarkdownPreview} from "../store/markdown";
* @returns {(*)[]|[{text, value(): [Date,*]},{text, value(): [Date,*]},{text, value(): [*,*]},{text, value(): [*,*]},{text, value(): [Date,*]},null,null]|(Date|*)[]}
*/
timeOptionShortcuts() {
const startSecond = $A.dayjs().startOf('day').toDate();
const startSecond = $A.daytz().startOf('day').toDate();
return [{
text: $A.L('今天'),
value() {
return [startSecond, $A.dayjs().endOf('day').toDate()];
return [startSecond, $A.daytz().endOf('day').toDate()];
}
}, {
text: $A.L('明天'),
value() {
return [startSecond, $A.dayjs().add(1, 'day').endOf('day').toDate()];
return [startSecond, $A.daytz().add(1, 'day').endOf('day').toDate()];
}
}, {
text: $A.L('本周'),
value() {
return [startSecond, $A.dayjs().endOf('week').toDate()];
return [startSecond, $A.daytz().endOf('week').toDate()];
}
}, {
text: $A.L('本月'),
value() {
return [startSecond, $A.dayjs().endOf('month').toDate()];
return [startSecond, $A.daytz().endOf('month').toDate()];
}
}, {
text: $A.L('3天'),
value() {
return [startSecond, $A.dayjs().add(2, 'day').endOf('day').toDate()];
return [startSecond, $A.daytz().add(2, 'day').endOf('day').toDate()];
}
}, {
text: $A.L('5天'),
value() {
return [startSecond, $A.dayjs().add(4, 'day').endOf('day').toDate()];
return [startSecond, $A.daytz().add(4, 'day').endOf('day').toDate()];
}
}, {
text: $A.L('7天'),
value() {
return [startSecond, $A.dayjs().add(6, 'day').endOf('day').toDate()];
return [startSecond, $A.daytz().add(6, 'day').endOf('day').toDate()];
}
}];
},

View File

@ -404,7 +404,7 @@ export default {
this.getUnreadList();
}
this.addData.department_id = this.userInfo.department[0] || 0;
this.addData.startTime = this.addData.endTime = $A.dayjs().format('YYYY-MM-DD');
this.addData.startTime = this.addData.endTime = $A.daytz().format('YYYY-MM-DD');
this.isShowIcon = this.windowWidth < 515
},

View File

@ -87,13 +87,13 @@ export default {
dateShortcuts(act) {
if (act === 'prev') {
return [
$A.dayjs().subtract(1, 'month').startOf('month').format('YYYY-MM-DD'),
$A.dayjs().subtract(1, 'month').endOf('month').format('YYYY-MM-DD'),
$A.daytz().subtract(1, 'month').startOf('month').format('YYYY-MM-DD'),
$A.daytz().subtract(1, 'month').endOf('month').format('YYYY-MM-DD'),
];
} else if (act === 'this') {
return [
$A.dayjs().startOf('month').format('YYYY-MM-DD'),
$A.dayjs().endOf('month').format('YYYY-MM-DD'),
$A.daytz().startOf('month').format('YYYY-MM-DD'),
$A.daytz().endOf('month').format('YYYY-MM-DD'),
]
}
},

View File

@ -75,7 +75,7 @@ export default {
};
},
created() {
const today = $A.dayjs()
const today = $A.daytz()
this.year = today.year();
this.month = today.month() + 1;
@ -100,7 +100,7 @@ export default {
computed: {
hasNextMonth() {
const {year, month} = this;
const today = $A.dayjs()
const today = $A.daytz()
return parseInt(year) != today.year() || parseInt(month) < today.month() + 1;
}
},
@ -121,7 +121,7 @@ export default {
}).join('<br/>')
},
generateCalendar() {
let today = $A.dayjs().startOf('day')
let today = $A.daytz().startOf('day')
let one = $A.dayjs([this.year, this.month, 1])
let calcTime = one.valueOf() - one.day() * 86400 * 1000
let array = []
@ -166,7 +166,7 @@ export default {
this.$emit('changeMonth', this.ym())
},
nowMonth() {
const today = $A.dayjs()
const today = $A.daytz()
this.year = today.year();
this.month = today.month() + 1;
this.generateCalendar();

View File

@ -95,13 +95,13 @@ export default {
dateShortcuts(act) {
if (act === 'prev') {
return [
$A.dayjs().subtract(1, 'month').startOf('day').format('YYYY-MM-DD'),
$A.dayjs().subtract(1, 'month').endOf('day').format('YYYY-MM-DD'),
$A.daytz().subtract(1, 'month').startOf('day').format('YYYY-MM-DD'),
$A.daytz().subtract(1, 'month').endOf('day').format('YYYY-MM-DD'),
];
} else if (act === 'this') {
return [
$A.dayjs().startOf('day').format('YYYY-MM-DD'),
$A.dayjs().endOf('day').format('YYYY-MM-DD'),
$A.daytz().startOf('day').format('YYYY-MM-DD'),
$A.daytz().endOf('day').format('YYYY-MM-DD'),
]
}
},

View File

@ -1962,7 +1962,7 @@ export default {
}).then(({data}) => {
this.$store.dispatch("saveDialogTodo", {
id: this.todoViewId,
done_at: $A.dayjs().format("YYYY-MM-DD HH:mm:ss")
done_at: $A.daytz().format("YYYY-MM-DD HH:mm:ss")
})
this.$store.dispatch("saveDialog", {
id: this.dialogId,

View File

@ -93,7 +93,7 @@ export default {
methods: {
logDate(itemA) {
let md = $A.dayjs().format("MM-DD");
let md = $A.daytz().format("MM-DD");
return md == itemA.ymd ? (itemA.ymd + ' ' + this.$L('今天')) : itemA.key;
},

View File

@ -428,7 +428,7 @@ export default {
},
async choosePriority(item) {
const start = $A.dayjs();
const start = $A.daytz();
const days = $A.runNum(item.days);
if (days > 0) {
const end = start.clone().add(days, 'day');

View File

@ -240,7 +240,7 @@ export default {
choosePriority(item) {
if ($A.runNum(item.days) > 0) {
let start = $A.dayjs();
let start = $A.daytz();
let end = start.clone().add($A.runNum(item.days), 'day');
this.$set(this.addData, 'times', $A.newDateString([start, end]))
} else {

View File

@ -87,13 +87,13 @@ export default {
dateShortcuts(act) {
if (act === 'prev') {
return [
$A.dayjs().subtract(1, 'month').startOf('day').format('YYYY-MM-DD'),
$A.dayjs().subtract(1, 'month').endOf('day').format('YYYY-MM-DD'),
$A.daytz().subtract(1, 'month').startOf('day').format('YYYY-MM-DD'),
$A.daytz().subtract(1, 'month').endOf('day').format('YYYY-MM-DD'),
];
} else if (act === 'this') {
return [
$A.dayjs().startOf('day').format('YYYY-MM-DD'),
$A.dayjs().endOf('day').format('YYYY-MM-DD'),
$A.daytz().startOf('day').format('YYYY-MM-DD'),
$A.daytz().endOf('day').format('YYYY-MM-DD'),
]
}
},

View File

@ -257,7 +257,7 @@ export default {
completeTemp(true)
}
this.updateTask({
complete_at: $A.dayjs().format('YYYY-MM-DD HH:mm:ss')
complete_at: $A.daytz().format('YYYY-MM-DD HH:mm:ss')
}).then(() => {
completeTemp(true)
}).catch(() => {

View File

@ -268,7 +268,7 @@ export default {
completeAtFormat(date) {
let time = $A.dayjs(date);
if ($A.dayjs().year() === time.year()) {
if ($A.daytz().year() === time.year()) {
return time.format('MM-DD HH:mm')
} else {
return time.format('YYYY-MM-DD')

View File

@ -679,7 +679,7 @@ export default {
{
text: '12:00',
value () {
return $A.dayjs().startOf('day').add(12, 'hour').toDate();
return $A.daytz().startOf('day').add(12, 'hour').toDate();
},
onClick: (picker) => {
picker.handlePickSuccess();
@ -688,7 +688,7 @@ export default {
{
text: '17:00',
value () {
return $A.dayjs().startOf('day').add(17, 'hour').toDate();
return $A.daytz().startOf('day').add(17, 'hour').toDate();
},
onClick: (picker) => {
picker.handlePickSuccess();
@ -697,7 +697,7 @@ export default {
{
text: '18:00',
value () {
return $A.dayjs().startOf('day').add(18, 'hour').toDate();
return $A.daytz().startOf('day').add(18, 'hour').toDate();
},
onClick: (picker) => {
picker.handlePickSuccess();
@ -706,7 +706,7 @@ export default {
{
text: '19:00',
value () {
return $A.dayjs().startOf('day').add(19, 'hour').toDate();
return $A.daytz().startOf('day').add(19, 'hour').toDate();
},
onClick: (picker) => {
picker.handlePickSuccess();
@ -715,7 +715,7 @@ export default {
{
text: this.$L('现在'),
value () {
return $A.dayjs().toDate();
return $A.daytz().toDate();
},
onClick: (picker) => {
picker.handlePickSuccess();

View File

@ -795,25 +795,26 @@ export default {
return false;
}
if (dialog.type == 'group') {
const timestamp = $A.dayjs().unix()
if (['project', 'task'].includes(dialog.group_type) && $A.isJson(dialog.group_info)) {
if (dialog.group_type == 'task' && dialog.group_info.complete_at) {
// 5
let time = Math.max($A.dayjs(dialog.last_at).unix(), $A.dayjs(dialog.group_info.complete_at).unix())
if (5 * 86400 + time < $A.dayjs().unix()) {
if (5 * 86400 + time < timestamp) {
return false
}
}
if (dialog.group_info.deleted_at) {
// 2
let time = Math.max($A.dayjs(dialog.last_at).unix(), $A.dayjs(dialog.group_info.deleted_at).unix())
if (2 * 86400 + time < $A.dayjs().unix()) {
if (2 * 86400 + time < timestamp) {
return false
}
}
if (dialog.group_info.archived_at) {
// 3
let time = Math.max($A.dayjs(dialog.last_at).unix(), $A.dayjs(dialog.group_info.archived_at).unix())
if (3 * 86400 + time < $A.dayjs().unix()) {
if (3 * 86400 + time < timestamp) {
return false
}
}

View File

@ -163,7 +163,7 @@ export default {
this.$store.dispatch("call", {
url: 'users/checkin/list',
data: {
ym: $A.dayjs().format("YYYY-MM"),
ym: $A.daytz().format("YYYY-MM"),
before: 1
}
}).then(({data}) => {
@ -176,7 +176,7 @@ export default {
latelyFormat(data) {
this.latelyData = [];
for (let i = 0; i < 5; i++) {
const ymd = $A.dayjs().subtract(i, 'day').format("YYYY-MM-DD")
const ymd = $A.daytz().subtract(i, 'day').format("YYYY-MM-DD")
const item = data.find(({date}) => date == ymd) || {date: ymd, section: []}
this.latelyData.push(item)
}
@ -204,7 +204,7 @@ export default {
}
this.calendarData = data;
//
if (ym == $A.dayjs().format("YYYY-MM")) {
if (ym == $A.daytz().format("YYYY-MM")) {
this.latelyFormat(data)
}
}).catch(({msg}) => {

View File

@ -1618,7 +1618,7 @@ export default {
* @param dispatch
*/
todayAndOverdue({state, dispatch}) {
const now = $A.dayjs();
const now = $A.daytz();
const today = now.format("YYYY-MM-DD");
state.cacheTasks.some(task => {
if (!task.end_at) {
@ -2516,7 +2516,7 @@ export default {
const updateData = {
id: data.dialog_id,
last_msg: data,
last_at: data.created_at || $A.dayjs().format("YYYY-MM-DD HH:mm:ss")
last_at: data.created_at || $A.daytz().format("YYYY-MM-DD HH:mm:ss")
}
if (data.mtype == 'tag') {
updateData.has_tag = true;
@ -2625,7 +2625,7 @@ export default {
*/
async getDialogBeyonds({state, dispatch}) {
const key = await $A.IDBString("dialogBeyond")
const val = $A.dayjs().format("YYYY-MM-DD HH")
const val = $A.daytz().format("YYYY-MM-DD HH")
if (key == val) {
return // 一小时取一次
}
@ -3233,7 +3233,7 @@ export default {
if ($A.isJson(data)) {
if (data.userid == state.userId) return;
if (data.read_at) return;
data.read_at = $A.dayjs().format("YYYY-MM-DD HH:mm:ss");
data.read_at = $A.daytz().format("YYYY-MM-DD HH:mm:ss");
state.readWaitData[data.id] = state.readWaitData[data.id] || 0
//
const dialog = state.cacheDialogs.find(({id}) => id == data.dialog_id);
@ -3280,7 +3280,7 @@ export default {
if (ids.hasOwnProperty(id) && /^\d+$/.test(ids[id])) {
state.dialogMsgs.some(item => {
if (item.dialog_id == ids[id] && item.id >= id) {
item.read_at = $A.dayjs().format("YYYY-MM-DD HH:mm:ss")
item.read_at = $A.daytz().format("YYYY-MM-DD HH:mm:ss")
}
})
}
@ -3335,7 +3335,7 @@ export default {
if (typeof data.after_msg_id !== "undefined") {
state.dialogMsgs.some(item => {
if (item.dialog_id == data.dialog_id && item.id >= data.after_msg_id) {
item.read_at = $A.dayjs().format("YYYY-MM-DD HH:mm:ss")
item.read_at = $A.daytz().format("YYYY-MM-DD HH:mm:ss")
}
})
}
@ -3556,7 +3556,7 @@ export default {
//
state.ws = new WebSocket(url);
state.ws.onopen = async (e) => {
wgLog && console.log("[WS] Open", e, $A.dayjs().format("YYYY-MM-DD HH:mm:ss"))
wgLog && console.log("[WS] Open", e, $A.daytz().format("YYYY-MM-DD HH:mm:ss"))
state.wsOpenNum++;
//
if (window.systemInfo.debug === "yes" || state.systemConfig.e2e_message !== 'open') {
@ -3571,7 +3571,7 @@ export default {
})
};
state.ws.onclose = async (e) => {
wgLog && console.log("[WS] Close", e, $A.dayjs().format("YYYY-MM-DD HH:mm:ss"))
wgLog && console.log("[WS] Close", e, $A.daytz().format("YYYY-MM-DD HH:mm:ss"))
state.ws = null;
//
clearTimeout(state.wsTimeout);
@ -3580,7 +3580,7 @@ export default {
}, 3000);
};
state.ws.onerror = async (e) => {
wgLog && console.log("[WS] Error", e, $A.dayjs().format("YYYY-MM-DD HH:mm:ss"))
wgLog && console.log("[WS] Error", e, $A.daytz().format("YYYY-MM-DD HH:mm:ss"))
state.ws = null;
//
clearTimeout(state.wsTimeout);

View File

@ -114,9 +114,9 @@ export default {
* @returns {{overdue: *, today: *,all:*}}
*/
dashboardTask(state) {
const todayStart = $A.dayjs().startOf('day'),
todayEnd = $A.dayjs().endOf('day'),
todayNow = $A.dayjs();
const todayStart = $A.daytz().startOf('day'),
todayEnd = $A.daytz().endOf('day'),
todayNow = $A.daytz();
const filterTask = (task, chackCompleted = true) => {
if (task.archived_at) {
return false;