异常处理

This commit is contained in:
Waiting 2024-06-05 17:54:18 +08:00
parent f0ca5624ea
commit 9d138814f2
4 changed files with 24 additions and 14 deletions

View File

@ -196,10 +196,14 @@ const fetchCompanyList = (fn: any = undefined) => {
} else { } else {
let index = companyList.value.findIndex((res: { id: string }) => res.id === getApp().globalData?.companyId); let index = companyList.value.findIndex((res: { id: string }) => res.id === getApp().globalData?.companyId);
// //
if(index < 0 && !getApp()?.globalData?.storeId) { if(index < 0) {
goPath('/pages/common/register/index'); if(!getApp()?.globalData?.storeId) {
return; goPath('/pages/common/register/index');
return;
}
index = 0;
} }
userStore.setUserInfo(userList.value[index]); userStore.setUserInfo(userList.value[index]);
userStore.setCompanyInfo(companyList.value[index]); userStore.setCompanyInfo(companyList.value[index]);
avatarModifyRemind(); avatarModifyRemind();

View File

@ -99,10 +99,10 @@ const useUserStore = defineStore('user', {
setToken(res.token); setToken(res.token);
setSessionKey(res.sessionKey); setSessionKey(res.sessionKey);
setOpenId(res.maOpenId); setOpenId(res.maOpenId);
if(res.user){ if(res.user) {
await this.setUserInfo(res.user); this.setUserInfo(res.user);
}else { } else {
this.setUserInfo(res.userInfo) this.setUserInfo(res.userInfo);
} }
// } // }
resolve(res); resolve(res);
@ -155,7 +155,9 @@ const useUserStore = defineStore('user', {
if(this.userInfo) { if(this.userInfo) {
this.userInfo.userDiscount = this.getUserDiscount; this.userInfo.userDiscount = this.getUserDiscount;
await setCompanyId(this.userInfo.companyId); await setCompanyId(this.userInfo.companyId);
getApp().globalData!.companyId = this.userInfo.companyId; if(getApp().globalData){
getApp().globalData.companyId = this.userInfo.companyId;
}
} else { } else {
await clearToken(); await clearToken();
} }
@ -165,7 +167,9 @@ const useUserStore = defineStore('user', {
setCompanyInfo(partial: Partial<any>) { setCompanyInfo(partial: Partial<any>) {
this.companyInfo = partial as any; this.companyInfo = partial as any;
getApp().globalData!.companyId = this.companyInfo.id; if(getApp()?.globalData) {
getApp().globalData.companyId = this.companyInfo.id;
}
}, },
setDeliveryAddress(partial: Partial<any>) { setDeliveryAddress(partial: Partial<any>) {

View File

@ -40,9 +40,11 @@ function getCompanyId() {
} }
function setCompanyId(companyId: string) { function setCompanyId(companyId: string) {
uni.setStorageSync(CompanyIdKey, companyId); if(companyId) {
if(getApp()?.globalData) { uni.setStorageSync(CompanyIdKey, companyId);
getApp().globalData!.companyId = companyId; if(getApp()?.globalData) {
getApp().globalData.companyId = companyId;
}
} }
} }

View File

@ -1,5 +1,5 @@
import type { HttpError, HttpRequestConfig, HttpResponse } from 'uview-plus/libs/luch-request'; import type { HttpError, HttpRequestConfig, HttpResponse } from 'uview-plus/libs/luch-request';
import { getToken } from '@/utils/auth'; import { getCompanyId, getToken } from '@/utils/auth';
import { showMessage } from '@/utils/request/status'; import { showMessage } from '@/utils/request/status';
import { useUserStore } from '@/store'; import { useUserStore } from '@/store';
@ -22,7 +22,7 @@ function requestInterceptors() {
const token = getToken(); const token = getToken();
if(token && config.header) { if(token && config.header) {
config.header.token = token; config.header.token = token;
config.header.companyid = getApp().globalData?.companyId; config.header.companyid = getCompanyId();
// config.header.contentType = "x-www-form-urlencoded" // config.header.contentType = "x-www-form-urlencoded"
} }