Эх сурвалжийг харах

fix(登录系统): 修复其他用户无法登录的BUG

登录流程改为:先获取用户可访问的游戏ID,重设用户选择的GID,然后重新请求
fxs 1 долоо хоног өмнө
parent
commit
69e2297608

+ 3 - 1
src/components/dataAnalysis/StatisticText.vue

@@ -73,9 +73,11 @@ watch(
     props.fieldsInfo
   ],
   () => {
+    console.log('请求了')
     // 如果有请求配置,要去更新一下
-    if (props.requestConfig)
+    if (props.requestConfig) {
       updateReqConfig(props.requestConfig, { gid: props.requestConfig?.otherOptions.gid })
+    }
 
     getData()
   },

+ 68 - 17
src/stores/useCommon.ts

@@ -7,6 +7,9 @@
  * @Description:通用的store,在多个页面均会使用
  *
  */
+import { useRequest } from '@/hooks/useRequest.ts'
+import type { ResponseInfo } from '@/types/res.ts'
+import axiosInstance from '@/utils/axios/axiosInstance.ts'
 import { reactive } from 'vue'
 import { defineStore } from 'pinia'
 import { getLocalInfo, saveLocalInfo } from '@/utils/localStorage/localStorage'
@@ -29,17 +32,19 @@ interface GameInfo {
 
 const defaultPf = ['web']
 const defaultGid = '1001'
+const { AllApi } = useRequest()
 
 /**
  * @description: 获取selectInfo
  * @return {SelectInfo} 返回本地gid、pf和时间
  */
-const getSelectInfo = (): SelectInfo => {
-  let gid = getLocalInfo('selectInfo', 'gid') as string
-  let pf = getLocalInfo('selectInfo', 'pf') as string[]
+const getSelectInfo = (): SelectInfo | null => {
+  let gid = getLocalInfo('selectInfo', 'gid') as string | null
+  let pf = getLocalInfo('selectInfo', 'pf') as string[] | null
 
-  gid = gid ? gid : defaultGid
-  pf = pf ? [pf[0]] : defaultPf
+  gid = gid ? gid : null
+  pf = pf ? [pf[0]] : null
+  if (!gid || !pf) return null
 
   return { pf, gid }
 }
@@ -48,10 +53,26 @@ const getSelectInfo = (): SelectInfo => {
  * @description: 获取多选的pf
  * @return {{ tempPf: string[] }} 多选pf
  */
-const getMultipleChoice = (): { tempPf: string[] } => {
-  let tempPf = getLocalInfo('tempMultipleChoice', 'pf') as string[]
-  tempPf = tempPf ? tempPf : defaultPf
-  return { tempPf }
+const getMultipleChoice = (): string[] | null => {
+  let tempPf = getLocalInfo('tempMultipleChoice', 'pf') as string[] | null
+  tempPf = tempPf ? tempPf : null
+  return tempPf
+}
+
+const updateGameList = async () => {
+  const response = (await axiosInstance.post(AllApi.pidToGidList, {
+    active: false
+  })) as ResponseInfo
+  if (!response || response.code !== 0) {
+    console.log('获取游戏列表失败')
+    return null
+  }
+  const data = response.data as Array<PlatformInfo>
+  return {
+    gid: data[0].gidList[0].gid,
+    pf: defaultPf,
+    tempPf: defaultPf
+  }
 }
 
 /**
@@ -59,13 +80,28 @@ const getMultipleChoice = (): { tempPf: string[] } => {
  * @param {SelectInfo} selectInfo 单选的选择器
  * @param {SelectInfo} tempMultipleChoice 多选的选择器
  */
-const initSelect = (selectInfo: SelectInfo, tempMultipleChoice: MultipleChoice) => {
-  const { gid, pf } = getSelectInfo()
-  const { tempPf } = getMultipleChoice()
-  Object.assign(selectInfo, { gid, pf })
-  Object.assign(tempMultipleChoice, { gid, pf: tempPf })
-  saveLocalInfo('selectInfo', selectInfo)
-  saveLocalInfo('tempMultipleChoice', tempMultipleChoice)
+export const initSelect = async () => {
+  let gid: string = '',
+    pf: Array<string>,
+    multiPf: Array<string>
+
+  const localSelectInfo = getSelectInfo()
+  const localMultiPf = getMultipleChoice()
+  if (!localSelectInfo || !localMultiPf) {
+    const res = await updateGameList()
+    if (!res) {
+      throw new Error('获取游戏列表失败')
+    }
+    gid = res.gid
+    pf = res.pf
+    multiPf = res.pf
+  } else {
+    gid = localSelectInfo.gid
+    pf = localSelectInfo.pf
+    multiPf = localMultiPf
+  }
+
+  return { gid, pf, multiPf }
 }
 
 export const useCommonStore = defineStore('commonStore', () => {
@@ -81,7 +117,7 @@ export const useCommonStore = defineStore('commonStore', () => {
     pf: defaultPf
   })
 
-  initSelect(selectInfo, multipleChoice)
+  // initSelect(selectInfo, multipleChoice)
 
   /**
    * @description: 保存现有的selectInfo
@@ -97,14 +133,29 @@ export const useCommonStore = defineStore('commonStore', () => {
     localStorage.setItem('tempMultipleChoice', JSON.stringify(multipleChoice))
   }
 
+  /**
+   * @description: 更新selectInfo和multipleChoice
+   * @param newSelectInfo 新的selectInfo
+   * @param multipleChoice 新的multipleChoice
+   */
+  const updateSelectInfo = (newSelectInfo: SelectInfo, multipleChoice: MultipleChoice) => {
+    Object.assign(selectInfo, newSelectInfo)
+    Object.assign(multipleChoice, newSelectInfo)
+
+    saveLocalInfo('selectInfo', selectInfo)
+    saveLocalInfo('tempMultipleChoice', multipleChoice)
+  }
+
   const gameInfoList = reactive<Array<PlatformInfo>>([])
   const allGameInfo = reactive<Array<GameInfo>>([])
   return {
     gameInfoList,
     selectInfo,
     allGameInfo,
+    updateSelectInfo,
     tempMultipleChoice: multipleChoice,
     saveSelectInfo,
+
     saveTempMultipleChoice: saveTempMultipleChoice
   }
 })

+ 4 - 1
src/utils/auth/auth.ts

@@ -15,7 +15,8 @@ import {
   clearUserInfo,
   getLoginState,
   getUserInfo,
-  setLoginState
+  setLoginState,
+  clearAllSelection
 } from '../localStorage/localStorage.ts'
 
 /**
@@ -28,9 +29,11 @@ export const clearClientInfo = (msg: string = '请先登录') => {
     message: msg,
     duration: 1500
   })
+
   removeAllToken()
   setLoginState(false)
   clearUserInfo()
+  clearAllSelection()
 }
 
 export const authLogin = (): boolean => {

+ 10 - 1
src/utils/localStorage/localStorage.ts

@@ -82,6 +82,14 @@ const getUserInfo = (): UserInfo | null => {
   return null
 }
 
+/**
+ * @description: 清除所有选择
+ */
+const clearAllSelection = () => {
+  localStorage.removeItem('selectInfo')
+  localStorage.removeItem('tempMultipleChoice')
+}
+
 export {
   getLocalInfo,
   saveLocalInfo,
@@ -89,5 +97,6 @@ export {
   getLoginState,
   setUserInfo,
   getUserInfo,
-  clearUserInfo
+  clearUserInfo,
+  clearAllSelection
 }

+ 5 - 1
src/views/Home/AdvertisingData/AdvertisingList.vue

@@ -282,7 +282,10 @@ const isRadioPf = ref(false)
  * @param pf  新pf
  * @param  gid 新gid
  */
-const updateAllReq = (pf: string[], gid: string) => {
+const updateAllReq = () => {
+  const gid = selectInfo.gid
+  const pf = tempMultipleChoice.pf
+
   queryFormData.value.gid = gid
   queryFormData.value.pf = pf
   updateChartData()
@@ -301,6 +304,7 @@ const changeDate = (date: Array<Date>) => {
   })
   const timeRange = getRangeTimestamps(date).map((item) => item.toString())
   queryFormData.value.createTime = [timeRange[0], timeRange[1]]
+  updateAllReq()
   updateChartData()
 }
 

+ 2 - 0
src/views/Home/Overview/OverView.vue

@@ -270,6 +270,8 @@ const monthInfo = reactive<TemporalTrendInfo>({
  */
 const updateAllReq = (pf: string, gid: string) => {
   pf = isSinglePf ? pf[0] : pf
+  console.log(pf, gid)
+  console.log('执行了')
   updateReqConfig(overViewDataReqConfig, { pf, gid })
   updateReqConfig(periodInfo.dataReqConfig, { pf, gid })
   updateReqConfig(monthInfo.dataReqConfig, { pf, gid })

+ 42 - 67
src/views/IndexView.vue

@@ -3,8 +3,8 @@
  * @Date: 2024-08-20 14:06:49
  * @LastEditors: fxs bjnsfxs@163.com
  * @LastEditTime: 2025-06-03
- * @Description: 
- * 
+ * @Description:
+ *
 -->
 <script setup lang="ts">
 import { useRequest } from '@/hooks/useRequest.ts'
@@ -19,7 +19,7 @@ import { computed, onMounted, reactive, ref, watch } from 'vue'
 import { ElMessage } from 'element-plus'
 import { getAllGameInfo } from '@/utils/table/table'
 
-import { useCommonStore } from '@/stores/useCommon'
+import { initSelect, useCommonStore } from '@/stores/useCommon'
 import { initLoadResource } from '@/utils/resource'
 import { getUserInfo } from '@/utils/localStorage/localStorage'
 
@@ -47,7 +47,7 @@ import router from '@/router'
 // }
 
 const route = useRoute()
-const { selectInfo, gameInfoList, saveSelectInfo } = useCommonStore()
+const { selectInfo, gameInfoList, saveSelectInfo, updateSelectInfo } = useCommonStore()
 const { AllApi } = useRequest()
 const { updateUserInfo } = useUser()
 const userInfo = getUserInfo()
@@ -221,26 +221,20 @@ watch(
  * 获取所有游戏列表
  */
 const updateGameInfo = () => {
-  getAllGameInfo()
-    .then((data) => {
-      if (data) {
-        // allGameInfo.splice(0, allGameInfo.length)
-        //
-        // data.map((item) => {
-        //   allGameInfo.push({
-        //     gid: item.gid,
-        //     gameName: item.gameName
-        //   })
-        // })
-
-        loadingState.value = true
-      } else {
-        throw new Error('游戏信息获取失败')
-      }
-    })
-    .catch((err) => {
-      console.log(err)
-    })
+  return new Promise((resolve, reject) => {
+    getAllGameInfo()
+      .then((data) => {
+        if (data) {
+          resolve(data)
+        } else {
+          throw new Error('游戏信息获取失败')
+        }
+      })
+      .catch((err) => {
+        console.log(err)
+        reject(err)
+      })
+  })
 }
 
 /**
@@ -256,34 +250,6 @@ const setNavbarGameSelect = (optionsList: Array<PlatformInfo>) => {
   }
   gameSelectInfo.optionsList.splice(0, gameSelectInfo.optionsList.length, ...optionsList)
   backupOptionsList.splice(0, backupOptionsList.length, ...optionsList)
-  // optionsList.forEach((item) => {
-  //   if (!gameSelectInfo.optionsList.has(item.gameName)) {
-  //     gameSelectInfo.optionsList.set(item.gameName, [
-  //       {
-  //         value: item.gid,
-  //         label: item.gameName
-  //       }
-  //     ])
-  //   } else {
-  //     gameSelectInfo.optionsList.get(item.gameName)?.push({
-  //       value: item.gid,
-  //       label: item.gameName
-  //     })
-  //   }
-  // })
-
-  console.log('更新后')
-  console.log(gameSelectInfo.optionsList)
-  // optionsList.forEach((item) => {
-  //   gameSelectInfo.optionsList.push({
-  //     value: item.gid,
-  //     label: item.gameName
-  //   })
-  // })
-  // 这个主要是用在初始化
-  // if (selectInfo.gid) {
-  //   selectedGame.value = selectInfo.gid
-  // }
 }
 
 /**
@@ -345,16 +311,7 @@ let watchGameListChange: () => void = () => {}
 const watchLoadingState = watch(
   () => loadingState,
   (newVal) => {
-    if (newVal) {
-      // 用来监听游戏列表的变化
-      // watchGameListChange = watch(
-      //   () => allGameInfo,
-      //   () => {
-      //     updateNavbarGameSelect('', true)
-      //   },
-      //   { deep: true }
-      // )
-
+    if (newVal.value) {
       watchGameListChange = watch(
         () => gameInfoList,
         () => {
@@ -372,21 +329,39 @@ const watchLoadingState = watch(
   }
 )
 
-updateGameInfo()
-updateNavbarGameSelect('', true)
-onMounted(() => {
-  // 去加载所有需要的资源
+onMounted(async () => {
+  // // 去加载所有需要的资源
+  // // await updateNavbarGameSelect('', true)
+  // // await updateGameInfo()
+  const { gid, pf, multiPf } = await initSelect()
+  updateSelectInfo(
+    {
+      pf,
+      gid
+    },
+    {
+      gid,
+      pf: multiPf
+    }
+  )
+  console.log(selectInfo)
+
+  await updateGameInfo()
   initLoadResource(resourceInfo).then((data) => {
     Object.assign(blobUrlInfo, data)
   })
-  console.log(selectInfo)
+  // console.log(selectInfo)
+  // const gid = gameSelectInfo.optionsList[0].gidList[0].gid
   selectedGame.value = selectInfo.gid
+  // selectInfo.gid =  gameInfoList[0].gidList[0].gid
 
   if (userInfo) {
     updateUserInfo({
       ...userInfo
     })
   }
+  console.log('gaowan l')
+  loadingState.value = true
 })
 </script>