fix:优化代码

This commit is contained in:
MJ 2025-08-05 19:20:06 +08:00
parent 1405cf7aea
commit 3c5e2578c0
14 changed files with 108 additions and 52 deletions

View File

@ -13,10 +13,24 @@
'" />', '" />',
) )
</script> </script>
<script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.3.4/vconsole.min.js"></script>
<script> <script>
// 初始化 // 只在开发环境加载vConsole
// 判断是否为开发环境本地开发或包含debug参数
var isDev = window.location.hostname === 'test.xuexiaole.com'
if (isDev) {
// 动态加载vConsole脚本
var script = document.createElement('script')
script.src = 'https://cdn.bootcdn.net/ajax/libs/vConsole/3.3.4/vconsole.min.js'
script.onload = function () {
// 脚本加载完成后初始化vConsole
var vConsole = new VConsole() var vConsole = new VConsole()
console.log('vConsole已在开发环境中启用')
}
script.onerror = function () {
console.warn('vConsole加载失败')
}
document.head.appendChild(script)
}
</script> </script>
<title></title> <title></title>
<!--preload-links--> <!--preload-links-->

View File

@ -84,7 +84,7 @@
"@dcloudio/vite-plugin-uni": "3.0.0-3081220230817001", "@dcloudio/vite-plugin-uni": "3.0.0-3081220230817001",
"@typescript-eslint/eslint-plugin": "^6.8.0", "@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0", "@typescript-eslint/parser": "^6.8.0",
"@vue/runtime-core": "^3.2.45", "@vue/runtime-core": "^3.4.21",
"@vue/tsconfig": "^0.1.3", "@vue/tsconfig": "^0.1.3",
"eslint": "^8.51.0", "eslint": "^8.51.0",
"eslint-config-alloy": "^5.1.2", "eslint-config-alloy": "^5.1.2",
@ -106,5 +106,25 @@
"prettier --write", "prettier --write",
"eslint --fix" "eslint --fix"
] ]
},
"uni-app": {
"scripts": {
"h5-test": {
"title": "h5-test",
"env": {
"UNI_PLATFORM": "h5",
"VITE_HOST": "http://127.0.0.1:9053",
"VITE_WS_URL": "wss://test.pi.xuexiaole.com/ws/device"
}
},
"h5-prod": {
"title": "h5-prod",
"env": {
"UNI_PLATFORM": "h5",
"VITE_HOST": "https://pi.xuexiaole.com",
"VITE_WS_URL": "wss://pi.xuexiaole.com/ws/device"
}
}
}
} }
} }

26
pnpm-lock.yaml generated
View File

@ -127,8 +127,8 @@ importers:
specifier: ^6.8.0 specifier: ^6.8.0
version: 6.8.0(eslint@8.51.0)(typescript@4.9.5) version: 6.8.0(eslint@8.51.0)(typescript@4.9.5)
'@vue/runtime-core': '@vue/runtime-core':
specifier: ^3.2.45 specifier: ^3.4.21
version: 3.3.4 version: 3.5.18
'@vue/tsconfig': '@vue/tsconfig':
specifier: ^0.1.3 specifier: ^0.1.3
version: 0.1.3(@types/node@20.5.1) version: 0.1.3(@types/node@20.5.1)
@ -1829,9 +1829,15 @@ packages:
'@vue/reactivity@3.3.4': '@vue/reactivity@3.3.4':
resolution: {integrity: sha512-kLTDLwd0B1jG08NBF3R5rqULtv/f8x3rOFByTDz4J53ttIQEDmALqKqXY0J+XQeN0aV2FBxY8nJDf88yvOPAqQ==} resolution: {integrity: sha512-kLTDLwd0B1jG08NBF3R5rqULtv/f8x3rOFByTDz4J53ttIQEDmALqKqXY0J+XQeN0aV2FBxY8nJDf88yvOPAqQ==}
'@vue/reactivity@3.5.18':
resolution: {integrity: sha512-x0vPO5Imw+3sChLM5Y+B6G1zPjwdOri9e8V21NnTnlEvkxatHEH5B5KEAJcjuzQ7BsjGrKtfzuQ5eQwXh8HXBg==}
'@vue/runtime-core@3.3.4': '@vue/runtime-core@3.3.4':
resolution: {integrity: sha512-R+bqxMN6pWO7zGI4OMlmvePOdP2c93GsHFM/siJI7O2nxFRzj55pLwkpCedEY+bTMgp5miZ8CxfIZo3S+gFqvA==} resolution: {integrity: sha512-R+bqxMN6pWO7zGI4OMlmvePOdP2c93GsHFM/siJI7O2nxFRzj55pLwkpCedEY+bTMgp5miZ8CxfIZo3S+gFqvA==}
'@vue/runtime-core@3.5.18':
resolution: {integrity: sha512-DUpHa1HpeOQEt6+3nheUfqVXRog2kivkXHUhoqJiKR33SO4x+a5uNOMkV487WPerQkL0vUuRvq/7JhRgLW3S+w==}
'@vue/runtime-dom@3.3.4': '@vue/runtime-dom@3.3.4':
resolution: {integrity: sha512-Aj5bTJ3u5sFsUckRghsNjVTtxZQ1OyMWCr5dZRAPijF/0Vy4xEoRCwLyHXcj4D0UFbJ4lbx3gPTgg06K/GnPnQ==} resolution: {integrity: sha512-Aj5bTJ3u5sFsUckRghsNjVTtxZQ1OyMWCr5dZRAPijF/0Vy4xEoRCwLyHXcj4D0UFbJ4lbx3gPTgg06K/GnPnQ==}
@ -1854,6 +1860,9 @@ packages:
'@vue/shared@3.4.21': '@vue/shared@3.4.21':
resolution: {integrity: sha512-PuJe7vDIi6VYSinuEbUIQgMIRZGgM8e4R+G+/dQTk0X1NEdvgvvgv7m+rfmDH1gZzyA1OjjoWskvHlfRNfQf3g==} resolution: {integrity: sha512-PuJe7vDIi6VYSinuEbUIQgMIRZGgM8e4R+G+/dQTk0X1NEdvgvvgv7m+rfmDH1gZzyA1OjjoWskvHlfRNfQf3g==}
'@vue/shared@3.5.18':
resolution: {integrity: sha512-cZy8Dq+uuIXbxCZpuLd2GJdeSO/lIzIspC2WtkqIpje5QyFbvLaI5wZtdUjLHjGZrlVX6GilejatWwVYYRc8tA==}
'@vue/tsconfig@0.1.3': '@vue/tsconfig@0.1.3':
resolution: {integrity: sha512-kQVsh8yyWPvHpb8gIc9l/HIDiiVUy1amynLNpCy8p+FoCiZXCo6fQos5/097MmnNZc9AtseDsCrfkhqCrJ8Olg==} resolution: {integrity: sha512-kQVsh8yyWPvHpb8gIc9l/HIDiiVUy1amynLNpCy8p+FoCiZXCo6fQos5/097MmnNZc9AtseDsCrfkhqCrJ8Olg==}
peerDependencies: peerDependencies:
@ -7298,7 +7307,7 @@ snapshots:
'@volar/source-map': 1.10.4 '@volar/source-map': 1.10.4
'@vue/compiler-dom': 3.3.4 '@vue/compiler-dom': 3.3.4
'@vue/reactivity': 3.3.4 '@vue/reactivity': 3.3.4
'@vue/shared': 3.3.4 '@vue/shared': 3.4.21
minimatch: 9.0.3 minimatch: 9.0.3
muggle-string: 0.3.1 muggle-string: 0.3.1
vue-template-compiler: 2.7.14 vue-template-compiler: 2.7.14
@ -7325,11 +7334,20 @@ snapshots:
dependencies: dependencies:
'@vue/shared': 3.3.4 '@vue/shared': 3.3.4
'@vue/reactivity@3.5.18':
dependencies:
'@vue/shared': 3.5.18
'@vue/runtime-core@3.3.4': '@vue/runtime-core@3.3.4':
dependencies: dependencies:
'@vue/reactivity': 3.3.4 '@vue/reactivity': 3.3.4
'@vue/shared': 3.3.4 '@vue/shared': 3.3.4
'@vue/runtime-core@3.5.18':
dependencies:
'@vue/reactivity': 3.5.18
'@vue/shared': 3.5.18
'@vue/runtime-dom@3.3.4': '@vue/runtime-dom@3.3.4':
dependencies: dependencies:
'@vue/runtime-core': 3.3.4 '@vue/runtime-core': 3.3.4
@ -7354,6 +7372,8 @@ snapshots:
'@vue/shared@3.4.21': {} '@vue/shared@3.4.21': {}
'@vue/shared@3.5.18': {}
'@vue/tsconfig@0.1.3(@types/node@20.5.1)': '@vue/tsconfig@0.1.3(@types/node@20.5.1)':
optionalDependencies: optionalDependencies:
'@types/node': 20.5.1 '@types/node': 20.5.1

View File

@ -6,6 +6,7 @@ import db from './utils/db'
onLaunch(() => { onLaunch(() => {
const { code } = parseUrlParams() const { code } = parseUrlParams()
if (code) { if (code) {
console.log('code', code)
// code // code
db.set('code', code) db.set('code', code)
} }

View File

@ -1,9 +1,5 @@
import { http } from './request/request' import { http } from './request/request'
// 获取用户信息
export const getUserInfo = async () =>
await http.get<any>('/sysUser/selectUser')
// 获取客服信息 // 获取客服信息
export const getCsInfo = async (id: string) => export const getCsInfo = async (id: string) =>
await http.get<any>(`/customerService/getInfoByUserId/${id}`) await http.get<any>(`/customerService/getInfoByUserId/${id}`)
@ -21,8 +17,7 @@ export const getAgreeInfo = async (id: string, isChat = false) =>
}) })
// 获取字典 // 获取字典
export const getDict = async () => export const getDict = async () => await http.get<any>('/sysDictType/tree')
await http.get<any>('/sysDictType/tree')
// 设备通知注册 // 设备通知注册
export const bindRegId = async (data: any) => export const bindRegId = async (data: any) =>

View File

@ -1,24 +1,24 @@
import { http } from '../request/request'; import { http } from '../request/request'
/** /**
* *
* @param data * @param data
*/ */
export const getUserInfo = async (data = {}): Promise<any> => { export const getUserInfo = async (data = {}): Promise<any> => {
return await http.post<any>('/phone/inspectorTeacher/myInfo', data); return await http.post<any>('/phone/inspectorTeacher/myInfo', data)
}; }
/** /**
* *
* @param params * @param params
*/ */
export const queryUserRoles = async (params = {}): Promise<any> => { export const queryUserRoles = async (params = {}): Promise<any> => {
return await http.get<any>('/sysUser/getAdminTypeByPhone', params); return await http.get<any>('/sysUser/getAdminTypeByPhone', params)
}; }
/** /**
* *
*/ */
export const switchRole = async (adminType: number): Promise<any> => { export const switchRole = async (adminType: number): Promise<any> => {
return await http.get<any>('/sysUser/changeAdminType', { return await http.get<any>('/sysUser/changeAdminType', {
adminType, adminType,
}); })
}; }

View File

@ -80,8 +80,10 @@ export const errorInterceptor = (error: any): Promise<ErrorResponse> => {
} }
// 显示错误提示 // 显示错误提示
let showed = false
if (message) { if (message) {
toast.error(message) toast.error(message)
showed = true
if (toLogin) { if (toLogin) {
router.toLogin() router.toLogin()
} }
@ -91,5 +93,6 @@ export const errorInterceptor = (error: any): Promise<ErrorResponse> => {
code: -1, code: -1,
message, message,
data: error, data: error,
showed,
}) })
} }

View File

@ -1,18 +1,18 @@
import { createSSRApp } from 'vue'; import { createSSRApp } from 'vue'
import App from './App.vue'; import App from './App.vue'
import * as Pinia from 'pinia'; import * as Pinia from 'pinia'
import './styles/global.scss'; import './styles/global.scss'
import './styles/font.scss'; import './styles/font.scss'
import './styles/iconfont.scss'; import './styles/iconfont.scss'
import BackBar from '@/components/BackBar/index'; import BackBar from '@/components/BackBar/index'
export function createApp() { export function createApp() {
const app = createSSRApp(App); const app = createSSRApp(App)
app.use(Pinia.createPinia()); app.use(Pinia.createPinia())
app.component('BackBar', BackBar); app.component('BackBar', BackBar)
return { return {
app, app,
Pinia, Pinia,
}; }
} }

View File

@ -84,7 +84,9 @@ import { storeToRefs } from 'pinia'
import hud from '@/utils/hud' import hud from '@/utils/hud'
import router from '@/router/router' import router from '@/router/router'
const { userInfo } = storeToRefs(user()) const userStore = user()
const { getUserInfo } = userStore
const { userInfo } = storeToRefs(userStore)
const OSS_URL = import.meta.env.VITE_OSS_HOST const OSS_URL = import.meta.env.VITE_OSS_HOST
const scanQr = `${OSS_URL}/iconfont/scan_qr.png` const scanQr = `${OSS_URL}/iconfont/scan_qr.png`
const arrow = `${OSS_URL}/iconfont/down_arrow.png` const arrow = `${OSS_URL}/iconfont/down_arrow.png`
@ -200,6 +202,7 @@ async function getParentBindDevice() {
}) })
} }
onMounted(async () => { onMounted(async () => {
await getUserInfo()
getParentBindDevice() getParentBindDevice()
}) })
</script> </script>

View File

@ -52,23 +52,13 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, nextTick, onMounted, watch } from 'vue' import { ref, computed, nextTick, onMounted } from 'vue'
import { import { sendCodeMessageApi, smsLoginApi, wxLoginApi } from '@/api'
getBindPhoneTypeApi,
sendCodeMessageApi,
smsLoginApi,
getUserInfoApi,
getAuthUrlApi,
wxLoginApi,
} from '@/api'
import { setCache, getCache } from '@/utils'
import { getUserInfo as dx_getUserInfoApi } from '@/api/inspector/mine'
import { user } from '@/store' import { user } from '@/store'
import router from '@/router/router' import router from '@/router/router'
import db from '@/utils/db' import db from '@/utils/db'
import hud from '@/utils/hud' import hud from '@/utils/hud'
import { onLoad, onShow } from '@dcloudio/uni-app'
const emits = defineEmits(['reloadFun']) const emits = defineEmits(['reloadFun'])
const OSS_URL = import.meta.env.VITE_OSS_HOST const OSS_URL = import.meta.env.VITE_OSS_HOST
@ -160,6 +150,10 @@ async function wxLogin() {
const data = await wxLoginApi({ const data = await wxLoginApi({
code, code,
}) })
// openid
if (data.wxUser.openid) {
db.set('openid', data.wxUser.openid)
}
if (data.accessToken) { if (data.accessToken) {
// //
await loginSuccess(data.accessToken) await loginSuccess(data.accessToken)
@ -175,7 +169,7 @@ async function wxLogin() {
async function loginSuccess(accessToken: any) { async function loginSuccess(accessToken: any) {
setToken(accessToken) setToken(accessToken)
await getUserInfo() await getUserInfo()
router.reLaunch('/pages/home/index') router.toHome()
} }
onMounted(async () => { onMounted(async () => {

View File

@ -82,7 +82,7 @@ function handleJump(i: any) {
function handlePrefectInfo() { function handlePrefectInfo() {
// router.navigateTo({ // router.navigateTo({
// path: `/pages/mine/prefectInformation/index`, // path: `/pages/mine/prefectInformation/index`,
// query: { type: '1' } // query: { type: '1' },
// }) // })
} }

View File

@ -1,6 +1,5 @@
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
import db from '../utils/db' import db from '../utils/db'
import dict from '../utils/dict'
import page from '../utils/page' import page from '../utils/page'
import qs from 'qs' import qs from 'qs'

View File

@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
import { ref } from 'vue' import { ref } from 'vue'
import { import {
// phoneLogin as phoneLoginApi, // phoneLogin as phoneLoginApi,
getUserInfo as getUserInfoApi, getUserInfoApi,
// psdLogin as psdLoginApi, // psdLogin as psdLoginApi,
logout as logoutApi, logout as logoutApi,
getCsInfo as getCsInfoApi, getCsInfo as getCsInfoApi,
@ -12,7 +12,6 @@ import {
} from '@/api' } from '@/api'
// import type { smsLoginType, accountLoginType, updatePasswordType } from '@/api'; // import type { smsLoginType, accountLoginType, updatePasswordType } from '@/api';
// import defaultAvatar from "@/static/default_avatar.png"; // import defaultAvatar from "@/static/default_avatar.png";
import { setCache, getCache } from '@/utils'
import { global } from '@/store' import { global } from '@/store'
import router from '@/router/router' import router from '@/router/router'
import db from '@/utils/db' import db from '@/utils/db'
@ -39,14 +38,20 @@ export const user = defineStore('user', () => {
// #endif // #endif
await logoutApi() await logoutApi()
clear() clear()
router.reLaunch('/pages/login/index') router.toLogin()
} }
const getUserInfo = async () => { const getUserInfo = async () => {
// 如果不是微信公众号环境,直接跳回登录页面
if (!db.get('openid')) {
router.toLogin()
return
}
const res = await getUserInfoApi() const res = await getUserInfoApi()
userInfo.value = res userInfo.value = res
db.set('userInfo', res) db.set('userInfo', res)
getUserInfoPermit() await getUserInfoPermit()
return res return res
} }
// 当前登录用户是否管理员身份 // 当前登录用户是否管理员身份

View File

@ -117,7 +117,9 @@ async function load(options: LoadOptions) {
errorContent += `${err.message}` errorContent += `${err.message}`
} }
} }
if (!err?.showed) {
!options.hideError && error(errorContent) !options.hideError && error(errorContent)
}
throw err throw err
} finally { } finally {
hide() hide()