Browse Source

feat(app): 更新店铺信息时同步修改应用配置

- 在工作台、店铺信息和登录页面中,更新店铺名称和 logo 时同步更新应用配置
- 使用 Pinia store 管理应用配置,确保全局一致性
- 优化代码结构,提高可维护性
tangy 1 month ago
parent
commit
bbb765fb8b

+ 8 - 7
src/stores/modules/user.ts

@@ -1,11 +1,12 @@
-import { defineStore } from 'pinia'
+import {defineStore} from 'pinia'
 import cache from '@/utils/cache'
-import type { RouteRecordRaw } from 'vue-router'
-import { getUserInfo, login, logout, getMenu } from '@/api/user'
-import router, { filterAsyncRoutes } from '@/router'
-import { TOKEN_KEY } from '@/enums/cacheEnums'
-import { PageEnum } from '@/enums/pageEnum'
-import { clearAuthInfo, getHouseId, getToken, getBrandId, getUserId} from '@/utils/auth'
+import type {RouteRecordRaw} from 'vue-router'
+import {getMenu, getUserInfo, login} from '@/api/user'
+import router, {filterAsyncRoutes} from '@/router'
+import {TOKEN_KEY} from '@/enums/cacheEnums'
+import {PageEnum} from '@/enums/pageEnum'
+import {clearAuthInfo, getBrandId, getHouseId, getToken, getUserId} from '@/utils/auth'
+
 export interface UserState {
     token: string
     houseId: string

+ 10 - 1
src/views/account/login.vue

@@ -125,6 +125,10 @@ const handleEnterStore = () => {
   if (currentRow.value.id) {
     cache.set(SHOP_ID, currentRow.value.id)
     window.localStorage.setItem("like_admin_houseId", currentRow.value.houseId)
+    config.value.webName = currentRow.name
+    if(currentRow.image){
+      config.value.webLogo = currentRow.image
+    }
     const {
       query: {redirect}
     } = route
@@ -145,6 +149,10 @@ const handleShopConfig = (params: any) => {
       if (res.length == 1) {
         cache.set(SHOP_ID, res[0].id)
         window.localStorage.setItem("like_admin_houseId",res[0].houseId)
+        config.value.webName = res[0].name
+        if(res[0].image){
+          config.value.webLogo = res[0].image
+        }
         const {
           query: {redirect}
         } = route
@@ -156,7 +164,8 @@ const handleShopConfig = (params: any) => {
           return {
             id: item.id,
             name: item.name,
-            houseId: item.houseId
+            houseId: item.houseId,
+            image: item.image
           }
         })
       }

+ 7 - 0
src/views/shop/info.vue

@@ -121,6 +121,9 @@ import feedback from '@/utils/feedback'
 import type {FormInstance} from 'element-plus'
 import cache from "@/utils/cache";
 import {ACCOUNT_KEY, SHOP_ID} from "@/enums/cacheEnums";
+import useAppStore from "@/stores/modules/app";
+const appStore = useAppStore()
+const config = computed(() => appStore.config)
 
 const formRef = ref<FormInstance>()
 // 表单数据
@@ -183,6 +186,10 @@ const getData = async () => {
     formData.operatingLicense = '';
   }
   cache.set(SHOP_ID, formData.id)
+  config.value.webName = formData.name
+  if(formData.image){
+    config.value.webLogo = formData.image
+  }
 }
 
 // 保存店铺信息

+ 7 - 0
src/views/workbench/index.vue

@@ -171,6 +171,9 @@ import service_code from './image/service_code.png'
 import {changeShopStatus, getShopConfig, statisticsDishTop10} from '@/api/shop'
 import cache from "@/utils/cache";
 import {ACCOUNT_KEY, SHOP_ID} from "@/enums/cacheEnums";
+import useAppStore from "@/stores/modules/app";
+const appStore = useAppStore()
+const config = computed(() => appStore.config)
 
 const activeIndex = ref(0)
 // 表单数据
@@ -435,6 +438,10 @@ const shopInfo = () => {
         workbenchData.shopName = res.name
         workbenchData.shopStatus = res.status
         cache.set(SHOP_ID, res.id)
+      config.value.webName = res.name
+      if(res.image){
+        config.value.webLogo = res.image
+      }
     })
 }
 const changeStatus = () => {