chore: 引入vant组件

This commit is contained in:
zhangyh
2025-10-09 11:33:47 +08:00
parent ef6db09d46
commit 92d23601e3
7 changed files with 167 additions and 252 deletions

View File

@@ -1,6 +1,5 @@
import axios from 'axios'
// import { Message, Loading, MessageBox } from 'element-ui'
import { ElMessage, ElLoading, ElMessageBox } from 'element-plus'
import { showToast, showLoading, showConfirmDialog, closeToast } from 'vant'
import { useUserInfoStore } from '@/stores/modules/userInfo'
const store = useUserInfoStore()
import { getLocal } from '@/utils/local'
@@ -62,17 +61,18 @@ service.interceptors.response.use(
const res = response.data
// 处理异常的情况
if (res.errCode != 0) {
ElMessage({
showToast({
message: res.errMsg,
type: 'error',
duration: 5 * 1000
type: 'fail',
duration: 5000
})
// 403:非法的token; 50012:其他客户端登录了; 401:Token 过期了;
if (res.errCode === 403 || res.errCode === 50012 || res.errCode === 401) {
ElMessageBox.confirm('你已被登出,可以取消继续留在该页面,或者重新登录', '确定登出', {
showConfirmDialog({
title: '确定登出',
message: '你已被登出,可以取消继续留在该页面,或者重新登录',
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
cancelButtonText: '取消'
}).then(() => {
store.loginOut().then(() => {
location.reload() // 为了重新实例化vue-router对象 避免bug
@@ -98,10 +98,10 @@ service.interceptors.response.use(
closeLoading()
}
console.log('err' + error) // for debug
ElMessage({
showToast({
message: error.message,
type: 'error',
duration: 5 * 1000
type: 'fail',
duration: 5000
})
return Promise.reject(error)
}
@@ -154,18 +154,16 @@ const LoadingInstance: { _target: any; _count: number } = {
_count: 0
}
function openLoading(loadingDom: any) {
LoadingInstance._target = ElLoading.service({
lock: true,
text: '数据正在加载中',
spinner: 'el-icon-loading',
background: 'rgba(25, 32, 53, 1)',
target: loadingDom || 'body'
LoadingInstance._target = showLoading({
message: '数据正在加载中',
forbidClick: true,
background: 'rgba(25, 32, 53, 1)'
})
}
function closeLoading() {
if (LoadingInstance._count > 0) LoadingInstance._count--
if (LoadingInstance._count === 0) {
LoadingInstance._target.close()
LoadingInstance._target?.close()
LoadingInstance._target = null
}
}