瀏覽代碼

feat(shop): 添加店铺ID缓存并集成到相关功能中- 在 auth.ts 中添加 getShopId 方法以获取店铺ID
- 在 cacheEnums.ts 中添加 SHOP_ID 枚举项
- 更新 goods list、workbench、shop info等组件,集成店铺ID缓存
- 修改 login 逻辑,记住账号时缓存店铺ID

tangy 1 月之前
父節點
當前提交
23f314acc3

+ 2 - 0
src/enums/cacheEnums.ts

@@ -14,3 +14,5 @@ export const LIKE_ADMIN_BRANDID = 'like_admin_brandId'
 export const LIKE_ADMIN_USERID = 'like_admin_userId'
 //设置
 export const LIKE_ADMIN_HOUSEID = 'like_admin_houseId'
+//设置
+export const SHOP_ID = 'shop_id'

+ 17 - 1
src/utils/auth.ts

@@ -1,4 +1,11 @@
-import {LIKE_ADMIN_BRANDID, LIKE_ADMIN_TOKEN, LIKE_ADMIN_USERID, LIKE_ADMIN_HOUSEID, TOKEN_KEY} from '@/enums/cacheEnums'
+import {
+    LIKE_ADMIN_BRANDID,
+    LIKE_ADMIN_HOUSEID,
+    LIKE_ADMIN_TOKEN,
+    LIKE_ADMIN_USERID,
+    SHOP_ID,
+    TOKEN_KEY
+} from '@/enums/cacheEnums'
 import cache from './cache'
 
 export function getToken() {
@@ -16,12 +23,21 @@ export function getHouseId() {
 export function getUserId() {
     return cache.get("userId")
 }
+
+
+export function getShopId() {
+    if (cache.get(SHOP_ID))
+        return JSON.parse(<string>cache.get(SHOP_ID)).value
+    return ''
+}
+
 export function clearAuthInfo() {
     cache.remove(TOKEN_KEY)
     cache.remove(LIKE_ADMIN_TOKEN)
     cache.remove(LIKE_ADMIN_BRANDID)
     cache.remove(LIKE_ADMIN_USERID)
     cache.remove(LIKE_ADMIN_HOUSEID)
+    cache.remove(SHOP_ID)
     // 确认窗体
     /*ElMessageBox.confirm("已经在其他地方登录", '温馨提示', {
         confirmButtonText: '确定',

+ 10 - 9
src/utils/request/index.ts

@@ -1,14 +1,12 @@
-import { merge } from 'lodash'
+import {merge} from 'lodash'
 import configs from '@/config'
-import { Axios } from './axios'
-import { ContentTypeEnum, RequestCodeEnum, RequestMethodsEnum } from '@/enums/requestEnums'
-import type { AxiosHooks } from './type'
-import { clearAuthInfo, getToken,getUserId,getBrandId,getHouseId } from '../auth'
+import {Axios} from './axios'
+import {ContentTypeEnum, RequestCodeEnum, RequestMethodsEnum} from '@/enums/requestEnums'
+import type {AxiosHooks} from './type'
+import {clearAuthInfo, getBrandId, getHouseId, getShopId, getToken, getUserId} from '../auth'
 import feedback from '../feedback'
 import NProgress from 'nprogress'
-import { AxiosError, type AxiosRequestConfig } from 'axios'
-import router from '@/router'
-import { PageEnum } from '@/enums/pageEnum'
+import {AxiosError, type AxiosRequestConfig} from 'axios'
 
 // 处理axios的钩子函数
 const axiosHooks: AxiosHooks = {
@@ -20,6 +18,7 @@ const axiosHooks: AxiosHooks = {
         const userId = getUserId();
         const brandId = getBrandId();
         const houseId = getHouseId();
+        const shopId = getShopId();
         headers['userId'] = userId || ""
         headers['brandId'] = brandId || ""
         headers['houseId'] = houseId || ""
@@ -38,6 +37,7 @@ const axiosHooks: AxiosHooks = {
             config.data = params
             config.data.brandId = brandId
             config.data.houseId = houseId
+            config.data.shopId = shopId
             config.params = {}
         }
         // 如果是GET请求,将brandId和houseId添加到params中
@@ -45,7 +45,8 @@ const axiosHooks: AxiosHooks = {
             config.params = {
                 ...config.params,
                 brandId: brandId,
-                houseId: houseId
+                houseId: houseId,
+                shopId: shopId
             }
         }
         config.headers = headers

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

@@ -135,7 +135,7 @@ const handleLogin = async () => {
     // 记住账号,缓存
     cache.set(ACCOUNT_KEY, {
         remember: remAccount.value,
-        account: remAccount.value ? formData.account : ''
+        account: formData.account
     })
     try {
         let _data = {

+ 3 - 2
src/views/goods/list/edit.vue

@@ -243,13 +243,13 @@ import useMultipleTabs from '@/hooks/useMultipleTabs'
 import Editor from '@/components/editor/index.vue'
 import {goodsCategoryPage} from "@/api/goods/category";
 import {goodsEdit, goodsDetail} from "@/api/goods/list";
+import { getShopId } from '@/utils/auth'
 import { Close } from '@element-plus/icons-vue'
 
 const route = useRoute()
 const router = useRouter()
 const formData = reactive<any>({
   id: null,
-  shopId: null,
   title: '',
   productCategoryId: null,
   price: null,
@@ -265,7 +265,8 @@ const formData = reactive<any>({
   mainResourceList: null,
   video: '',
   detail: '',
-  useDates: ''
+  useDates: '',
+  shopId: getShopId()
 })
 const goodsTagOption = [{
   value: '日用品',

+ 3 - 1
src/views/goods/list/index.vue

@@ -114,12 +114,14 @@ import {goodsCategoryPage} from '@/api/goods/category'
 import {useDictOptions} from '@/hooks/useDictOptions'
 import {usePaging} from '@/hooks/usePaging'
 import {getRoutePath} from '@/router'
+import { getShopId } from '@/utils/auth'
 import feedback from '@/utils/feedback'
 
 const queryParams = reactive({
   title: '',
   cid: '',
-  isShow: ''
+  isShow: '',
+  shopId: getShopId()
 })
 const {pager, getLists, resetPage, resetParams} = usePaging({
   fetchFun: goodsPage,

+ 9 - 1
src/views/shop/info.vue

@@ -119,6 +119,8 @@
 import {getShopConfig, saveShopConfig} from '@/api/shop'
 import feedback from '@/utils/feedback'
 import type {FormInstance} from 'element-plus'
+import cache from "@/utils/cache";
+import {ACCOUNT_KEY, SHOP_ID} from "@/enums/cacheEnums";
 
 const formRef = ref<FormInstance>()
 // 表单数据
@@ -142,7 +144,12 @@ const formData = reactive({
 
 // 获取店铺信息
 const getData = async () => {
-  const data = await getShopConfig()
+  const accountCache = cache.get(ACCOUNT_KEY)
+  let account = ''
+  if (accountCache) {
+    account = JSON.parse(accountCache).value.account
+  }
+  const data = await getShopConfig({"contactTel": account})
   for (const key in formData) {
     //@ts-ignore
     formData[key] = data[key]
@@ -168,6 +175,7 @@ const getData = async () => {
   if (!formData.operatingLicense) {//不能是null,会报错
     formData.operatingLicense = '';
   }
+  cache.set(SHOP_ID, formData.id)
 }
 
 // 保存店铺信息

+ 13 - 5
src/views/workbench/index.vue

@@ -156,9 +156,8 @@
 </template>
 
 <script lang="ts" setup name="workbench">
-import { getWorkbench } from '@/api/app'
-import vCharts from 'vue-echarts'
-import { SwitchButton } from '@element-plus/icons-vue'
+import {getWorkbench} from '@/api/app'
+import {SwitchButton} from '@element-plus/icons-vue'
 import menu_admin from './image/menu_admin.png'
 import menu_role from './image/menu_role.png'
 import menu_dept from './image/menu_dept.png'
@@ -169,7 +168,10 @@ import menu_auth from './image/menu_auth.png'
 import menu_web from './image/menu_web.png'
 import oa_code from './image/oa_code.png'
 import service_code from './image/service_code.png'
-import { getShopConfig, changeShopStatus, statisticsDishTop10 } from '@/api/shop'
+import {changeShopStatus, getShopConfig, statisticsDishTop10} from '@/api/shop'
+import cache from "@/utils/cache";
+import {ACCOUNT_KEY, SHOP_ID} from "@/enums/cacheEnums";
+
 const activeIndex = ref(0)
 // 表单数据
 const workbenchData: any = reactive({
@@ -416,10 +418,16 @@ const getData = async () => {
     workbenchData.visitorOption.series[0].data = res.visitor.list
 }
 const shopInfo = () => {
-    getShopConfig().then((res) => {
+  const accountCache = cache.get(ACCOUNT_KEY)
+  let account = ''
+  if (accountCache) {
+    account = JSON.parse(accountCache).value.account
+  }
+    getShopConfig({"contactTel": account}).then((res) => {
         workbenchData.shopId = res.id
         workbenchData.shopName = res.name
         workbenchData.shopStatus = res.status
+        cache.set(SHOP_ID, res.id)
     })
 }
 const changeStatus = () => {