|
@@ -1,9 +1,10 @@
|
|
|
import { defineStore } from 'pinia';
|
|
import { defineStore } from 'pinia';
|
|
|
-import { AppStoreState, ConfigItem, DictItem, PickerItem } from '@/types';
|
|
|
|
|
-import { getConfig, getProvinces } from '@/api/modules/system';
|
|
|
|
|
|
|
+import type { AppStoreState, ConfigItem, DictItem, PickerItem, System } from '@/types';
|
|
|
|
|
+import { getConfig, getProvinces, getSystemNotice } from '@/api/modules/system';
|
|
|
import { useDictStore } from '@/store/dictStore';
|
|
import { useDictStore } from '@/store/dictStore';
|
|
|
import { EnumDictName } from '@/common/enum';
|
|
import { EnumDictName } from '@/common/enum';
|
|
|
import { useUserStore } from '@/store/userStore';
|
|
import { useUserStore } from '@/store/userStore';
|
|
|
|
|
+
|
|
|
const preloadDicts: string[] = [
|
|
const preloadDicts: string[] = [
|
|
|
EnumDictName.EXAM_TYPE
|
|
EnumDictName.EXAM_TYPE
|
|
|
];
|
|
];
|
|
@@ -15,7 +16,8 @@ export const useAppStore = defineStore('ie-app', {
|
|
|
activeTabbar: 0,
|
|
activeTabbar: 0,
|
|
|
statusBarHeight: 0,
|
|
statusBarHeight: 0,
|
|
|
systemInfo: null as UniApp.GetSystemInfoResult | null,
|
|
systemInfo: null as UniApp.GetSystemInfoResult | null,
|
|
|
- appConfig: [] as ConfigItem[]
|
|
|
|
|
|
|
+ appConfig: [] as ConfigItem[],
|
|
|
|
|
+ maintainNotice: null
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
getters: {
|
|
getters: {
|
|
@@ -31,6 +33,12 @@ export const useAppStore = defineStore('ie-app', {
|
|
|
isMp(): boolean {
|
|
isMp(): boolean {
|
|
|
return this.sysInfo.uniPlatform === 'mp-weixin';
|
|
return this.sysInfo.uniPlatform === 'mp-weixin';
|
|
|
},
|
|
},
|
|
|
|
|
+ hasMaintain(): boolean {
|
|
|
|
|
+ return this.maintainNotice !== null;
|
|
|
|
|
+ },
|
|
|
|
|
+ isMaintaining(): boolean {
|
|
|
|
|
+ return isBetweenTime(this.maintainNotice?.beginTime, this.maintainNotice?.endTime);
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
actions: {
|
|
actions: {
|
|
|
async init() {
|
|
async init() {
|
|
@@ -84,7 +92,31 @@ export const useAppStore = defineStore('ie-app', {
|
|
|
getAppConfig(key: string): string | undefined {
|
|
getAppConfig(key: string): string | undefined {
|
|
|
return this.appConfig.find(item => item.configKey === key)?.configValue;
|
|
return this.appConfig.find(item => item.configKey === key)?.configValue;
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+ async getMaintainNotice() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const { rows } = await getSystemNotice(2);
|
|
|
|
|
+ if (rows && rows.length) {
|
|
|
|
|
+ const notice = extractMaintenanceContent(rows[0].noticeContent);
|
|
|
|
|
+ if (notice) {
|
|
|
|
|
+ const { beginTime, endTime, content } = notice;
|
|
|
|
|
+ this.maintainNotice = {
|
|
|
|
|
+ beginTime,
|
|
|
|
|
+ endTime,
|
|
|
|
|
+ content,
|
|
|
|
|
+ read: this.maintainNotice?.read || false
|
|
|
|
|
+ };
|
|
|
|
|
+ return Promise.resolve(isBetweenTime(beginTime, endTime));
|
|
|
|
|
+ }
|
|
|
|
|
+ return Promise.resolve(false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.maintainNotice = null;
|
|
|
|
|
+ return Promise.resolve(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('获取维护公告失败:', error);
|
|
|
|
|
+ return Promise.resolve(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
setActiveTabbar(index: number) {
|
|
setActiveTabbar(index: number) {
|
|
|
this.activeTabbar = index;
|
|
this.activeTabbar = index;
|
|
|
},
|
|
},
|
|
@@ -102,3 +134,45 @@ export const useAppStore = defineStore('ie-app', {
|
|
|
omit: [],
|
|
omit: [],
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+// 将中文格式转换为标准格式
|
|
|
|
|
+const convertToStandardFormat = (dateStr: string): string => {
|
|
|
|
|
+ // 使用正则提取各部分并补零
|
|
|
|
|
+ const match = dateStr.match(/(\d{4})年(\d{1,2})月(\d{1,2})日(\d{1,2}):(\d{1,2}):(\d{1,2})/);
|
|
|
|
|
+ if (!match) {
|
|
|
|
|
+ return dateStr
|
|
|
|
|
+ .replace(/年/g, '-')
|
|
|
|
|
+ .replace(/月/g, '-')
|
|
|
|
|
+ .replace(/日/g, ' ');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 对月、日、时、分、秒补零
|
|
|
|
|
+ const [, year, month, day, hour, minute, second] = match;
|
|
|
|
|
+ return `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')} ${hour.padStart(2, '0')}:${minute.padStart(2, '0')}:${second.padStart(2, '0')}`;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+function extractMaintenanceContent(htmlString: string): System.MaintainNotice | null {
|
|
|
|
|
+ const content = htmlString.replaceAll("</p><p>", "\n").replaceAll("</p>", "").replaceAll("<br>", "").replaceAll("<p>", "");
|
|
|
|
|
+ // 使用正则表达式匹配维护时间范围(完整的一次匹配)
|
|
|
|
|
+ const timeMatch = content.match(/维护开始时间:(\d{4}年\d{1,2}月\d{1,2}日\d{1,2}:\d{1,2}:\d{1,2})\n维护结束时间:(\d{4}年\d{1,2}月\d{1,2}日\d{1,2}:\d{1,2}:\d{1,2})/);
|
|
|
|
|
+ if (timeMatch) {
|
|
|
|
|
+ // 提取开始时间和结束时间
|
|
|
|
|
+ const startTimeStr = timeMatch[1];
|
|
|
|
|
+ const endTimeStr = timeMatch[2];
|
|
|
|
|
+ const beginTime = convertToStandardFormat(startTimeStr);
|
|
|
|
|
+ const endTime = convertToStandardFormat(endTimeStr);
|
|
|
|
|
+
|
|
|
|
|
+ return { content, beginTime, endTime, read: false };
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const isBetweenTime = (beginTime?: string, endTime?: string) => {
|
|
|
|
|
+ const now = Date.now();
|
|
|
|
|
+ if (beginTime && endTime) {
|
|
|
|
|
+ beginTime = beginTime.replaceAll('-', '/');
|
|
|
|
|
+ endTime = endTime.replaceAll('-', '/');
|
|
|
|
|
+ return new Date(beginTime).getTime() <= now && new Date(endTime).getTime() >= now;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|