Skip to content

Commit

Permalink
fix:抓马播报时区调整
Browse files Browse the repository at this point in the history
  • Loading branch information
fifthThirteen committed Jul 16, 2024
1 parent aa9c2f2 commit c6fda39
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/components/common/toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default {
type: String,
default: "#6b52ff",
},
actColor:{
actColor: {
type: String,
default: "#ffffff",
},
Expand Down Expand Up @@ -105,7 +105,6 @@ export default {
immediate: true,
deep: true,
handler: function (list) {
console.log(list);
if (list && list.length) {
this.type = this.active || list[0].value;
}
Expand Down
57 changes: 41 additions & 16 deletions src/components/horse/HorseBroadcastV2.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ export default {
isPhone() {
return document.documentElement.clientWidth <= 820;
},
isAsia() {
// 是否是东八区
const _timezone = this.$store.state.timezone;
return _timezone === "Asia/Shanghai";
},
},
watch: {
server() {
Expand All @@ -171,8 +176,11 @@ export default {
if (!list.length) {
return;
}
// 最近刷新时间
const created_at = dayjs.tz(list?.[0].created_at || dayjs.tz());
// 最近刷新时间 返回的时间已经是东八区时间,其余对比时间同样需要换算到东八区时间
let created_at = dayjs(list?.[0].created_at || dayjs.tz());
if (!this.isAsia) {
created_at = dayjs.tz(list?.[0].created_at || dayjs.tz());
}
const now = dayjs.tz();
const now_day = now.day();
let cd_from_time = now.day(1).hour(10).minute(0).second(0).millisecond(0);
Expand All @@ -183,7 +191,7 @@ export default {
cd_to_time = dayjs.tz(cd_to_time).add(-1, "week");
}
// 最近刷新时间是否在当前CD中
const isBetween = dayjs.tz(created_at).isBetween(cd_from_time, cd_to_time);
const isBetween = created_at.isBetween(cd_from_time, cd_to_time);
this.diluHasExist = isBetween;
if (isBetween) {
const content = list?.[0]?.content || "";
Expand All @@ -192,7 +200,7 @@ export default {
: "";
this.diluExistData = {
map_name: mapName,
time: dayjs.tz(created_at).format("YYYY-MM-DD HH:mm:ss"),
time: created_at.format("YYYY-MM-DD HH:mm:ss"),
is_dilu: true,
};
}
Expand Down Expand Up @@ -225,8 +233,11 @@ export default {
...coor,
},
];
// 最近刷新时间
const created_at = dayjs.tz(list?.[0].created_at || dayjs.tz());
// 最近刷新时间 返回的时间已经是东八区时间,其余对比时间同样需要换算到东八区时间
let created_at = dayjs(list?.[0].created_at || dayjs.tz());
if (!this.isAsia) {
created_at = dayjs.tz(list?.[0].created_at || dayjs.tz());
}
const now = dayjs.tz();
const now_day = now.day();
const now_hour = now.hour();
Expand All @@ -238,7 +249,7 @@ export default {
cd_to_time = dayjs.tz(cd_to_time).add(-1, "week");
}
// 最近刷新时间是否在当前CD中
const isBetween = dayjs.tz(created_at).isBetween(cd_from_time, cd_to_time);
const isBetween = created_at.isBetween(cd_from_time, cd_to_time);
this.hasExist = isBetween;
const data = {
horses: horses,
Expand All @@ -249,7 +260,7 @@ export default {
time: "",
};
if (isBetween) {
data.time = dayjs.tz(created_at).format("YYYY-MM-DD HH:mm:ss");
data.time = created_at.format("YYYY-MM-DD HH:mm:ss");
}
this.existData = data;
})
Expand Down Expand Up @@ -355,15 +366,29 @@ export default {
let fromTime = "";
let toTime = "";
if (!!("minute" in item)) {
fromTime = dayjs
.tz(new Date(item.created_at).valueOf() + (item.minute + 5) * 60 * 1000)
.format("HH:mm");
toTime = dayjs
.tz(new Date(item.created_at).valueOf() + (item.minute + 10) * 60 * 1000)
.format("HH:mm");
if (!this.isAsia) {
fromTime = dayjs
.tz(new Date(item.created_at).valueOf() + (item.minute + 5) * 60 * 1000)
.format("HH:mm");
toTime = dayjs
.tz(new Date(item.created_at).valueOf() + (item.minute + 10) * 60 * 1000)
.format("HH:mm");
} else {
fromTime = dayjs(
new Date(item.created_at).valueOf() + (item.minute + 5) * 60 * 1000
).format("HH:mm");
toTime = dayjs(new Date(item.created_at).valueOf() + (item.minute + 10) * 60 * 1000).format(
"HH:mm"
);
}
} else {
fromTime = dayjs.tz(new Date(item.created_at).valueOf() + 5 * 60 * 1000).format("HH:mm");
toTime = dayjs.tz(new Date(item.created_at).valueOf() + 10 * 60 * 1000).format("HH:mm");
if (!this.isAsia) {
fromTime = dayjs.tz(new Date(item.created_at).valueOf() + 5 * 60 * 1000).format("HH:mm");
toTime = dayjs.tz(new Date(item.created_at).valueOf() + 10 * 60 * 1000).format("HH:mm");
} else {
fromTime = dayjs(new Date(item.created_at).valueOf() + 5 * 60 * 1000).format("HH:mm");
toTime = dayjs(new Date(item.created_at).valueOf() + 10 * 60 * 1000).format("HH:mm");
}
}
return {
...item,
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/day.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
import isToday from "dayjs/plugin/isToday";
import isoWeek from "dayjs/plugin/isoWeek";
import isBetween from "dayjs/plugin/isBetween"
import isBetween from "dayjs/plugin/isBetween";
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.extend(isoWeek);
dayjs.extend(isToday);
dayjs.extend(isBetween);

// 默认时区为东八区
const _timezone = "Asia/Shanghai";
import store from "@/store";
store.state.timezone = dayjs.tz.guess();
const _timezone = store.state.timezone;
dayjs.tz.setDefault(_timezone);

export default dayjs;
1 change: 1 addition & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let store = {
client: location.href.includes("origin") ? "origin" : "std",
faceSingle: {},
isCollapse: false,
timezone: "Asia/Shanghai", // 时区
},
mutations: {
toState(state, data) {
Expand Down

0 comments on commit c6fda39

Please sign in to comment.