diff --git a/.env.development b/.env.development index 605cb43..4d28888 100644 --- a/.env.development +++ b/.env.development @@ -1 +1 @@ -VITE_APP_URL = '' \ No newline at end of file +VITE_APP_URL = http://18.167.251.121:10096 \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 687d2ec..bd9617a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,9 +1,17 @@ diff --git a/src/main.ts b/src/main.ts index d212212..266529a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,6 +13,7 @@ import 'vant/lib/index.css' import { Locale } from 'vant'; import enUS from 'vant/es/locale/lang/en-US'; Locale.use('en-US', enUS); +import { Loading } from 'vant'; import flexible from "./utils/flexible.js"; @@ -32,6 +33,7 @@ document.addEventListener('touchend', function(event) { const app = createApp(App) app.use(router) .use(store) +.use(Loading) .component("SvgIcon", SvgIcon) .mount('#app') diff --git a/src/stores/index.ts b/src/stores/index.ts index ca31d10..e8fe839 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -5,4 +5,5 @@ const store = createPinia() // 使用持久化插件(全局持久化) store.use(createPersistedState()) export default store -export * from './modules/generate' \ No newline at end of file +export * from './modules/generate' +export * from './modules/overall' diff --git a/src/stores/modules/generate.ts b/src/stores/modules/generate.ts index 918f693..21283d8 100644 --- a/src/stores/modules/generate.ts +++ b/src/stores/modules/generate.ts @@ -13,6 +13,9 @@ export const useGenerateStore = defineStore({ id:-1, oldId:-1,//表示从生成页面返回回来,需要调整的样式id }, + model:{ + id:-1, + } }, queryList:[] } @@ -35,6 +38,11 @@ export const useGenerateStore = defineStore({ if(data.id == this.userData.style.oldId){ this.userData.style.oldId = -1 } + }, + //模特相关 + selectModel(data:any){ + this.userData.model.id = data.id + console.log(this.userData) } } }) diff --git a/src/stores/modules/overall.ts b/src/stores/modules/overall.ts new file mode 100644 index 0000000..7689f34 --- /dev/null +++ b/src/stores/modules/overall.ts @@ -0,0 +1,19 @@ +// 每一个存储的模块,命名规则use开头,store结尾 +import { defineStore } from 'pinia' +export const useOverallStore = defineStore({ + id: 'overall', // 必须指明唯一的pinia仓库的id + state: () => { + return { + loading:false, + } + }, + getters: { + // doubleCount: (state) => state.num * 2 + }, + actions: { + // 全局loading + setLoading(data:boolean){ + this.loading = data + } + } +}) diff --git a/src/utils/request.ts b/src/utils/request.ts index 4272946..99aae49 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,11 +1,14 @@ import axios from 'axios' -import { showToast, showLoading, showConfirmDialog, closeToast } from 'vant' +import { showToast, showNotify, showConfirmDialog, closeToast } from 'vant' import { useUserInfoStore } from '@/stores/modules/userInfo' const store = useUserInfoStore() import { getLocal } from '@/utils/local' +import router from '@/router/index' +import { useOverallStore } from '@/stores' + // 创建axios实例 -console.log(import.meta.env.VITE_APP_URL) +console.log(import.meta.env.VITE_APP_URL,123) const service = axios.create({ baseURL: import.meta.env.VITE_APP_URL, // api的base_url // baseURL: import.meta.env.VITE_APP_URL, // api的base_url @@ -57,7 +60,6 @@ service.interceptors.response.use( if (response.config.loading) { closeLoading() } - const res = response.data // 处理异常的情况 if (res.errCode != 0) { @@ -66,19 +68,7 @@ service.interceptors.response.use( type: 'fail', duration: 5000 }) - // 403:非法的token; 50012:其他客户端登录了; 401:Token 过期了; - if (res.errCode === 403 || res.errCode === 50012 || res.errCode === 401) { - showConfirmDialog({ - title: '确定登出', - message: '你已被登出,可以取消继续留在该页面,或者重新登录', - confirmButtonText: '重新登录', - cancelButtonText: '取消' - }).then(() => { - store.loginOut().then(() => { - location.reload() // 为了重新实例化vue-router对象 避免bug - }) - }) - } + return Promise.reject(new Error('error')) } else { // 默认只返回data,不返回状态码和message @@ -92,6 +82,20 @@ service.interceptors.response.use( } }, (error) => { + if(error?.response?.status === 401){//如果是记录浏览器页面就不跳转login + // showConfirmDialog({ + // title: '确定登出', + // message: '你已被登出,可以取消继续留在该页面,或者重新登录', + // confirmButtonText: '重新登录', + // cancelButtonText: '取消' + // }).then(() => { + // store.loginOut().then(() => { + // location.reload() // 为了重新实例化vue-router对象 避免bug + // }) + // }) + router.replace('/login') + return Promise.reject(error) + } error.config && removePending(error.config) // 关闭loading if (error.config?.loading) { @@ -149,23 +153,18 @@ function removePending(config: any) { } } // ----------------------------------loading的函数------------------------------- -const LoadingInstance: { _target: any; _count: number } = { - _target: null, // 保存Loading实例 +const LoadingInstance: { _count: number } = { _count: 0 } function openLoading(loadingDom: any) { - LoadingInstance._target = showLoading({ - message: '数据正在加载中', - forbidClick: true, - background: 'rgba(25, 32, 53, 1)' - }) + useOverallStore().setLoading(true) } function closeLoading() { if (LoadingInstance._count > 0) LoadingInstance._count-- if (LoadingInstance._count === 0) { - LoadingInstance._target?.close() - LoadingInstance._target = null + useOverallStore().setLoading(false) } + } export default service diff --git a/src/views/Workshop/selectModel.vue b/src/views/Workshop/selectModel.vue index 0bdd44a..cf6b415 100644 --- a/src/views/Workshop/selectModel.vue +++ b/src/views/Workshop/selectModel.vue @@ -1,14 +1,16 @@