From 973c4f5ab6fc6c9f72aac3565ccca2491f9b466c Mon Sep 17 00:00:00 2001 From: MJ Date: Wed, 6 Aug 2025 15:14:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A4=A7=E6=94=B9=E9=80=A0=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 100 +++++++------- .vscode/settings.json | 2 +- package.json | 4 +- src/api/global.ts | 4 - src/api/login.ts | 12 +- src/api/modules/inspector.ts | 6 +- src/api/request/interceptor.ts | 8 +- src/hooks/useSocket.ts | 6 +- src/main.ts | 7 +- src/pages/academicReport/index.vue | 4 +- src/pages/applicationManagement/index.vue | 4 +- src/pages/home/bindDevice/index.vue | 8 +- src/pages/home/index.vue | 31 +++-- src/pages/inspector/mine/min-base-info.vue | 8 +- src/pages/inspector/personalData/index.vue | 4 +- src/pages/login/index.vue | 4 +- .../mine/TaskManage/patriarchSendObject.vue | 130 +++++++++--------- src/pages/mine/aboutMine.vue | 16 +-- src/pages/mine/details/childrenDetails.vue | 4 +- src/pages/mine/details/deviceDetails.vue | 4 +- src/pages/mine/patriarchCard.vue | 50 ++++--- src/pages/mine/prefectInformation/index.vue | 8 +- src/plugins/pinia-plugin-persist/index.ts | 48 +++++++ src/router/router.ts | 6 +- src/store/H5Authorization.ts | 9 +- src/store/socket.ts | 7 +- src/store/user.ts | 55 +------- .../wot-design-uni/components/common/util.ts | 2 +- .../components/composables/useCountDown.ts | 2 +- 29 files changed, 274 insertions(+), 279 deletions(-) create mode 100644 src/plugins/pinia-plugin-persist/index.ts diff --git a/.eslintrc.js b/.eslintrc.js index d1aa4f3..fce7508 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,54 +1,54 @@ module.exports = { - extends: ['alloy', 'alloy/vue', 'alloy/typescript', 'plugin:@typescript-eslint/recommended'], - parser: 'vue-eslint-parser', - parserOptions: { - parser: { - js: '@babel/eslint-parser', - jsx: '@babel/eslint-parser', - ts: '@typescript-eslint/parser', - tsx: '@typescript-eslint/parser', - }, + extends: ['alloy', 'alloy/vue', 'alloy/typescript', 'plugin:@typescript-eslint/recommended'], + parser: 'vue-eslint-parser', + parserOptions: { + parser: { + js: '@babel/eslint-parser', + jsx: '@babel/eslint-parser', + ts: '@typescript-eslint/parser', + tsx: '@typescript-eslint/parser', }, - rules: { - '@typescript-eslint/consistent-type-assertions': 'off', - '@typescript-eslint/prefer-optional-chain': 'off', - '@typescript-eslint/explicit-member-accessibility': 'off', - '@typescript-eslint/no-non-null-assertion': 'off', - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-unused-vars': 'off', - '@typescript-eslint/no-empty-interface': 'off', - 'no-return-assign': 'off', - 'guard-for-in': 'off', + }, + rules: { + '@typescript-eslint/consistent-type-assertions': 'off', + '@typescript-eslint/prefer-optional-chain': 'off', + '@typescript-eslint/explicit-member-accessibility': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-empty-interface': 'off', + 'no-return-assign': 'off', + 'guard-for-in': 'off', - 'vue/no-setup-props-destructure': 'off', - 'vue/no-duplicate-attr-inheritance': 'off', - 'no-eq-null': 'off', // 允许 == 用于 null + 'vue/no-setup-props-destructure': 'off', + 'vue/no-duplicate-attr-inheritance': 'off', + 'no-eq-null': 'off', // 允许 == 用于 null - 'vue/v-on-event-hyphenation': 'off', // 关闭 vue 中 @ 使用短横线命名 - 'no-duplicate-imports': 'off', // 使用ts-eslint的重复导入规则 - 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', - 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', - 'vue/multi-word-component-names': 'off', - 'vue/no-duplicate-attributes': [ - 'error', - { - allowCoexistClass: true, // 启用v-bind:class指令可以与普通class属性共存。默认值为true。 - allowCoexistStyle: true, - }, - ], - // 圈复杂度 每个函数的最高圈复杂度 - complexity: [ - 'error', - { - max: 12, - }, - ], - }, - globals: { - defineProps: 'readonly', - defineEmits: 'readonly', - defineExpose: 'readonly', - withDefaults: 'readonly', - }, - plugins: ['@typescript-eslint'], -}; + 'vue/v-on-event-hyphenation': 'off', // 关闭 vue 中 @ 使用短横线命名 + 'no-duplicate-imports': 'off', // 使用ts-eslint的重复导入规则 + 'no-console': import.meta.env.NODE_ENV === 'production' ? 'warn' : 'off', + 'no-debugger': import.meta.env.NODE_ENV === 'production' ? 'warn' : 'off', + 'vue/multi-word-component-names': 'off', + 'vue/no-duplicate-attributes': [ + 'error', + { + allowCoexistClass: true, // 启用v-bind:class指令可以与普通class属性共存。默认值为true。 + allowCoexistStyle: true, + }, + ], + // 圈复杂度 每个函数的最高圈复杂度 + complexity: [ + 'error', + { + max: 12, + }, + ], + }, + globals: { + defineProps: 'readonly', + defineEmits: 'readonly', + defineExpose: 'readonly', + withDefaults: 'readonly', + }, + plugins: ['@typescript-eslint'], +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 76f5dcf..24402b9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -48,5 +48,5 @@ "src/uni_modules/uni-search-bar/components/uni-search-bar/i18n", "src/uni_modules/z-paging/components/z-paging/i18n" ], - "cSpell.words": ["iconfont", "pinia", "VITE", "xuexiaole"] + "cSpell.words": ["iconfont", "persistedstate", "pinia", "VITE", "Wechat", "Weixin", "xuexiaole"] } diff --git a/package.json b/package.json index 60c495b..a01fd4c 100644 --- a/package.json +++ b/package.json @@ -62,13 +62,13 @@ "dayjs": "^1.11.13", "echarts": "^5.5.1", "lint-staged": "^15.0.1", + "lodash": "4.17.21", "pinia": "^2.0.36", "qs": "^6.14.0", "sass": "^1.72.0", "unplugin-vue-define-options": "^1.4.2", "vue": "^3.3.4", "vue-i18n": "^9.1.9", - "lodash": "4.17.21", "vue-qrcode-reader": "^5.5.7", "weixin-js-sdk": "^1.6.5" }, @@ -82,6 +82,7 @@ "@dcloudio/uni-cli-shared": "3.0.0-3081220230817001", "@dcloudio/uni-stacktracey": "3.0.0-3081220230817001", "@dcloudio/vite-plugin-uni": "3.0.0-3081220230817001", + "@types/lodash": "4.17.16", "@typescript-eslint/eslint-plugin": "^6.8.0", "@typescript-eslint/parser": "^6.8.0", "@vue/runtime-core": "^3.4.21", @@ -94,7 +95,6 @@ "prettier": "^3.0.3", "typescript": "^4.9.5", "vite": "4.1.4", - "@types/lodash": "4.17.16", "vue-eslint-parser": "^9.3.2", "vue-tsc": "^1.0.24" }, diff --git a/src/api/global.ts b/src/api/global.ts index a474bfe..be5a4f4 100644 --- a/src/api/global.ts +++ b/src/api/global.ts @@ -1,9 +1,5 @@ import { http } from './request/request' -// 获取客服信息 -export const getCsInfo = async (id: string) => - await http.get(`/customerService/getInfoByUserId/${id}`) - // 更新用户信息 export const updateUserInfo = async (data: any) => await http.post('/sysUser/editPerfectMessage', data) diff --git a/src/api/login.ts b/src/api/login.ts index 1ccdcec..6153819 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -46,16 +46,6 @@ export const wxLoginApi = async data => clientType: 'PARENT', }) -// /** -// * 微信绑定账号 -// * @param data 请求参数 -// */ -// export const wxBindAccountApi = async data => -// await http.post('/wxBindAccount', { -// ...data, -// clientType: 'PARENT', -// }) - /** * 获取用户信息 * @param data 请求参数 @@ -83,4 +73,4 @@ export const bindAuthInfoApi = async data => export const getAuthUrlApi = async () => await http.get('/wechatPublic/getAuthUrl') // 退出登录 -export const logout = async () => await http.get('/logout') +export const logoutApi = async () => await http.get('/logout') diff --git a/src/api/modules/inspector.ts b/src/api/modules/inspector.ts index 5b2b30d..eef6923 100644 --- a/src/api/modules/inspector.ts +++ b/src/api/modules/inspector.ts @@ -1,8 +1,8 @@ import { http } from '../request/request' import { storeToRefs } from 'pinia' -import { user } from '@/store' import { getCache } from '@/utils' import db from '@/utils/db' +import { userStore } from '@/store' // 课表日历 export const getScheduleList = async (data?: Record): Promise => @@ -64,9 +64,9 @@ export const getUserInfo = async (data?: Record): Promise => await http.get('/phone/inspectorTeacher/getCurrentTeacher') // 文件上传 export const uploadFile = async (file): Promise => { - const { token } = storeToRefs(user()) + const { token } = storeToRefs(userStore()) - const mergerToken = token.value || db.get('token') + const mergerToken = token.value const data = await uni.uploadFile({ url: `/api/main/sysFileInfo/tenUploadAll`, // ${import.meta.env.VITE_HOST} diff --git a/src/api/request/interceptor.ts b/src/api/request/interceptor.ts index 526e6ad..f765ab0 100644 --- a/src/api/request/interceptor.ts +++ b/src/api/request/interceptor.ts @@ -5,6 +5,8 @@ import { HTTP_STATUS, ERROR_MSG } from './config' import router from '@/router/router' import db from '@/utils/db' import toast from '@/utils/hud' +import { storeToRefs } from 'pinia' +import { userStore } from '@/store' // 请求拦截器 export const requestInterceptor = async (options: RequestOptions): Promise => { @@ -12,12 +14,12 @@ export const requestInterceptor = async (options: RequestOptions): Promise export const useSocket = () => { - const { token, userInfo } = user() + const { token, userInfo } = userStore() const inspectorMessage = ref() const inspectorDesktopMessage = ref([]) const desktopPath = ref() @@ -18,7 +18,7 @@ export const useSocket = () => { } function init() { SOCKET = useWebSocket( - `${process.env.VITE_WS_URL}?accessToken=${token.replace('Bearer ', '')}`, + `${import.meta.env.VITE_WS_URL}?accessToken=${token.replace('Bearer ', '')}`, { autoReconnect: { retries: 5, diff --git a/src/main.ts b/src/main.ts index 5120730..04e9dab 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,11 +5,14 @@ import * as Pinia from 'pinia' import './styles/global.scss' import './styles/font.scss' import './styles/iconfont.scss' -import BackBar from '@/components/BackBar/index' +import PiniaPluginPersist from './plugins/pinia-plugin-persist' +import BackBar from '@/components/BackBar/index.vue' export function createApp() { const app = createSSRApp(App) - app.use(Pinia.createPinia()) + const pinia = Pinia.createPinia() + pinia.use(PiniaPluginPersist) + app.use(pinia) app.component('BackBar', BackBar) return { app, diff --git a/src/pages/academicReport/index.vue b/src/pages/academicReport/index.vue index b84a9dd..032722a 100644 --- a/src/pages/academicReport/index.vue +++ b/src/pages/academicReport/index.vue @@ -47,11 +47,11 @@ import type { ChildrenType } from '@/pages/mine/interface' import type { SubjectType } from './interface' import './index.scss' import { getParentBindChildApi, subjectApi } from '@/api' -import { user } from '@/store' +import { userStore } from '@/store' import { storeToRefs } from 'pinia' import hud from '@/utils/hud' -const { userInfo } = storeToRefs(user()) +const { userInfo } = storeToRefs(userStore()) const childrenList = ref() // 所有孩子 const empty = ref(false) diff --git a/src/pages/applicationManagement/index.vue b/src/pages/applicationManagement/index.vue index 8e8a695..400072e 100644 --- a/src/pages/applicationManagement/index.vue +++ b/src/pages/applicationManagement/index.vue @@ -143,10 +143,10 @@ import { getParentBindDeviceApi, parentDeviceCurrentLoginApi, queryAppRecordApi import TabBar from '@/components/Tabbar/index.vue' import CustomPopup from '@/components/CustomPopup/index.vue' import Empty from '@/components/Empty/index.vue' -import { user } from '@/store' +import { userStore } from '@/store' import { storeToRefs } from 'pinia' -const { userInfo } = storeToRefs(user()) +const { userInfo } = storeToRefs(userStore()) const OSS_URL = import.meta.env.VITE_OSS_HOST const defaultAvatar = `${OSS_URL}/urm/default_avatar.png` const arrow = `${OSS_URL}/iconfont/down_arrow.png` diff --git a/src/pages/home/bindDevice/index.vue b/src/pages/home/bindDevice/index.vue index c5a3b49..4c65730 100644 --- a/src/pages/home/bindDevice/index.vue +++ b/src/pages/home/bindDevice/index.vue @@ -108,14 +108,14 @@