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 src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.3.4/vconsole.min.js"></script>
<script>
// 初始化
var vConsole = new VConsole()
// 只在开发环境加载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()
console.log('vConsole已在开发环境中启用')
}
script.onerror = function () {
console.warn('vConsole加载失败')
}
document.head.appendChild(script)
}
</script>
<title></title>
<!--preload-links-->

View File

@ -84,7 +84,7 @@
"@dcloudio/vite-plugin-uni": "3.0.0-3081220230817001",
"@typescript-eslint/eslint-plugin": "^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",
"eslint": "^8.51.0",
"eslint-config-alloy": "^5.1.2",
@ -106,5 +106,25 @@
"prettier --write",
"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
version: 6.8.0(eslint@8.51.0)(typescript@4.9.5)
'@vue/runtime-core':
specifier: ^3.2.45
version: 3.3.4
specifier: ^3.4.21
version: 3.5.18
'@vue/tsconfig':
specifier: ^0.1.3
version: 0.1.3(@types/node@20.5.1)
@ -1829,9 +1829,15 @@ packages:
'@vue/reactivity@3.3.4':
resolution: {integrity: sha512-kLTDLwd0B1jG08NBF3R5rqULtv/f8x3rOFByTDz4J53ttIQEDmALqKqXY0J+XQeN0aV2FBxY8nJDf88yvOPAqQ==}
'@vue/reactivity@3.5.18':
resolution: {integrity: sha512-x0vPO5Imw+3sChLM5Y+B6G1zPjwdOri9e8V21NnTnlEvkxatHEH5B5KEAJcjuzQ7BsjGrKtfzuQ5eQwXh8HXBg==}
'@vue/runtime-core@3.3.4':
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':
resolution: {integrity: sha512-Aj5bTJ3u5sFsUckRghsNjVTtxZQ1OyMWCr5dZRAPijF/0Vy4xEoRCwLyHXcj4D0UFbJ4lbx3gPTgg06K/GnPnQ==}
@ -1854,6 +1860,9 @@ packages:
'@vue/shared@3.4.21':
resolution: {integrity: sha512-PuJe7vDIi6VYSinuEbUIQgMIRZGgM8e4R+G+/dQTk0X1NEdvgvvgv7m+rfmDH1gZzyA1OjjoWskvHlfRNfQf3g==}
'@vue/shared@3.5.18':
resolution: {integrity: sha512-cZy8Dq+uuIXbxCZpuLd2GJdeSO/lIzIspC2WtkqIpje5QyFbvLaI5wZtdUjLHjGZrlVX6GilejatWwVYYRc8tA==}
'@vue/tsconfig@0.1.3':
resolution: {integrity: sha512-kQVsh8yyWPvHpb8gIc9l/HIDiiVUy1amynLNpCy8p+FoCiZXCo6fQos5/097MmnNZc9AtseDsCrfkhqCrJ8Olg==}
peerDependencies:
@ -7298,7 +7307,7 @@ snapshots:
'@volar/source-map': 1.10.4
'@vue/compiler-dom': 3.3.4
'@vue/reactivity': 3.3.4
'@vue/shared': 3.3.4
'@vue/shared': 3.4.21
minimatch: 9.0.3
muggle-string: 0.3.1
vue-template-compiler: 2.7.14
@ -7325,11 +7334,20 @@ snapshots:
dependencies:
'@vue/shared': 3.3.4
'@vue/reactivity@3.5.18':
dependencies:
'@vue/shared': 3.5.18
'@vue/runtime-core@3.3.4':
dependencies:
'@vue/reactivity': 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':
dependencies:
'@vue/runtime-core': 3.3.4
@ -7354,6 +7372,8 @@ snapshots:
'@vue/shared@3.4.21': {}
'@vue/shared@3.5.18': {}
'@vue/tsconfig@0.1.3(@types/node@20.5.1)':
optionalDependencies:
'@types/node': 20.5.1

View File

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

View File

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

View File

@ -1,24 +1,24 @@
import { http } from '../request/request';
import { http } from '../request/request'
/**
*
* @param data
*/
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
*/
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> => {
return await http.get<any>('/sysUser/changeAdminType', {
adminType,
});
};
})
}

View File

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

View File

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

View File

@ -84,7 +84,9 @@ import { storeToRefs } from 'pinia'
import hud from '@/utils/hud'
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 scanQr = `${OSS_URL}/iconfont/scan_qr.png`
const arrow = `${OSS_URL}/iconfont/down_arrow.png`
@ -200,6 +202,7 @@ async function getParentBindDevice() {
})
}
onMounted(async () => {
await getUserInfo()
getParentBindDevice()
})
</script>

View File

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

View File

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

View File

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

View File

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

View File

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