From 7ccd96a77540f5fcb462cffb9938b6fc1693913a Mon Sep 17 00:00:00 2001 From: GaoHao <1210693421@qq.com> Date: Tue, 8 Apr 2025 17:49:08 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A4=9A=E9=97=A8=E5=BA=97=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/account/shop.ts | 6 +++ .../Sidebar/components/SidebarLogo.vue | 30 +++++------ src/store/modules/user.ts | 4 +- src/utils/request.ts | 4 +- src/views/login/index.vue | 54 ++++--------------- src/views/shop/list/components/addShop.vue | 2 +- 6 files changed, 38 insertions(+), 62 deletions(-) diff --git a/src/api/account/shop.ts b/src/api/account/shop.ts index a04df6c..4a45291 100644 --- a/src/api/account/shop.ts +++ b/src/api/account/shop.ts @@ -17,6 +17,12 @@ const ShopApi = { params: params, }); }, + getBranchChange(id: PageQuery) { + return request({ + url: `${baseURL}/change/${id}`, + method: "post", + }); + }, add(data: ShopInfoEditDTO) { return request({ url: `${baseURL}`, diff --git a/src/layout/components/Sidebar/components/SidebarLogo.vue b/src/layout/components/Sidebar/components/SidebarLogo.vue index aab4d3a..1e8491c 100644 --- a/src/layout/components/Sidebar/components/SidebarLogo.vue +++ b/src/layout/components/Sidebar/components/SidebarLogo.vue @@ -5,18 +5,16 @@ - - {{ state.shopName }} + @@ -43,22 +41,24 @@ onMounted(() => { async function geiShopList() { let res = await ShopApi.getBranchList() state.branchList = res; - if ( !localStorage.getItem("shopName") ) { + if (!localStorage.getItem("shopName")) { state.shopName = state.branchList[0].shopName - // localStorage.setItem("shopId", state.branchList[0].shopId ) - localStorage.setItem("shopName", state.branchList[0].shopName ) + localStorage.setItem("branch_shopId", data.shopInfo.id) + localStorage.setItem("shopName", state.branchList[0].shopName) } else { state.shopName = localStorage.getItem("shopName") } } -function handleCommand(command) { +async function handleCommand(command) { console.log(command) - let res = state.branchList.filter(v=> v.shopId == command)[0] + let res = state.branchList.filter(v => v.shopId == command)[0] // localStorage.setItem("shopId", res.shopId ) - localStorage.setItem("shopName", res.shopName ) + await ShopApi.getBranchChange(res.shopId) + // localStorage.setItem("branch_shopId", res.shopId) + localStorage.setItem("shopName", res.shopName) state.shopName = res.shopName - + location.reload() console.log(res) console.log(command) } @@ -87,7 +87,7 @@ defineProps({ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; - max-width: 150px; + max-width: 100px; } } diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 039339a..296ff1b 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -31,13 +31,14 @@ export const useUserStore = defineStore("user", () => { return new Promise((resolve, reject) => { AuthAPI.login(loginRequest) .then((data) => { - isShopAdmin.value = data.loginType == 0 ? true : false; Object.assign(userInfo.value, { ...data.shopInfo, shopId: data.shopInfo.id }); promissionList.value = data.promissionList; const token = data.tokenInfo.tokenValue; setToken(token); setRefreshToken(token); + localStorage.setItem("shopId", "" + data.shopInfo.id); + localStorage.setItem("branch_shopId",data.shopInfo.id) resolve(); }) .catch((error) => { @@ -59,6 +60,7 @@ export const useUserStore = defineStore("user", () => { reject("Verification failed, please Login again."); return; } + console.log(userInfo) localStorage.setItem("shopId", "" + userInfo.value.shopId); Object.assign(userInfo.value, { ...data, roles: [], promissionList: [], shopId: userInfo.value.shopId }); resolve(userInfo.value); diff --git a/src/utils/request.ts b/src/utils/request.ts index c3f8bd3..dca818b 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -22,8 +22,8 @@ service.interceptors.request.use( } else { delete config.headers.token; } - config.headers.shopId = config.headers.shopId || localStorage.getItem("shopId"); - // config.headers.shopId = config.headers.shopId || useUserStoreHook().userInfo.id; + // config.headers.shopId = config.headers.shopId || localStorage.getItem("branch_shopId"); + config.headers.shopId = config.headers.shopId || useUserStoreHook().userInfo.id; return config; }, (error) => Promise.reject(error) diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 77d56cc..5b1a3f2 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -1,13 +1,7 @@