ljc 1 ماه پیش
والد
کامیت
e0b6711457
5فایلهای تغییر یافته به همراه23 افزوده شده و 10 حذف شده
  1. 17 4
      components/cwg-system.vue
  2. 1 1
      pages/login/components/LoginHeaderGroup.vue
  3. 2 2
      pages/login/index.vue
  4. 2 2
      pages/login/regist.vue
  5. 1 1
      windows/top-window.vue

+ 17 - 4
components/cwg-system.vue

@@ -14,6 +14,7 @@ import { computed, ref, onMounted,onUnmounted } from 'vue'
 import { useI18n } from 'vue-i18n'
 import Config from '@/config/index'
 import { customApi } from '@/service/custom'
+import { userToken } from "@/composables/config";
 
 const props = defineProps({
   iconColor: {
@@ -23,6 +24,11 @@ const props = defineProps({
   textColor: {
     type: String,
     default: '#141d22'
+  },
+  // 事件来源标识,用于区分不同组件的事件监听
+  eventSource: {
+    type: String,
+    default: ''
   }
 })
 
@@ -87,7 +93,11 @@ const applySystemList = (data: any[]) => {
 
 async function getSystemList(type = false) {
   const cached = getCache()
-  console.log(1,type)
+  console.log('system',type,props.form)
+  // top-window组件中,没有token不去请求接口
+  if (props.eventSource === 'top') {
+    if (!userToken.value) return
+  }
   if (!type){
     if (cached && cached.timestamp && Date.now() - cached.timestamp < CACHE_DURATION) {
       applySystemList(cached.data || [])
@@ -165,10 +175,13 @@ const isInit = ref(false)
 onMounted(() => {
   if (isInit.value) return
   isInit.value = true
-  console.log('注册')
-  // getSystemList()
+  
+  getSystemList()
 
-  uni.$on('updateSystemList', () => {
+  uni.$on('updateSystemList', (source) => {
+    console.log(source)
+    // 如果指定了事件来源,只处理来自该来源的事件
+    if (props.eventSource && source !== props.eventSource) return
     getSystemList(true)
   })
 })

+ 1 - 1
pages/login/components/LoginHeaderGroup.vue

@@ -1,7 +1,7 @@
 <template>
   <view class="login-header-group">
     <view class="header-item">
-      <cwg-system :text-color="textColor" :icon-color="iconColor" />
+      <cwg-system :text-color="textColor" :icon-color="iconColor" event-source="login"/>
     </view>
     <view class="divider" :style="{ backgroundColor: dividerColor }"></view>
     <view class="header-item" style="margin-right: 10rpx">

+ 2 - 2
pages/login/index.vue

@@ -94,7 +94,7 @@ async function getCustomLoginInfo() {
   try {
     const res = await userApi.getUserInfo()
     userStore.saveUserInfo(res.data)
-    uni.$emit('updateSystemList')
+    uni.$emit('updateSystemList', 'login')
     if (res.code === 200) {
       switch (modeStore.value) {
         case 'customer':
@@ -165,7 +165,7 @@ onMounted(() => {
   console.log('kaiaaa')
   if (init.value)return
   init.value = true
-  uni.$emit('updateSystemList')
+  uni.$emit('updateSystemList','login')
   const accountInfo = userStore.accountInfo
   if (accountInfo?.rememberPassword) {
     form.value.loginName = accountInfo?.loginName || ''

+ 2 - 2
pages/login/regist.vue

@@ -560,7 +560,7 @@ const getLoginInfo = async () => {
     let res = await userApi.getUserInfo()
     if (res.code == 200) { // Code.StatusOK
       userStore.saveUserInfo(res.data)
-      uni.$emit('updateSystemList')
+      uni.$emit('updateSystemList',login)
       showToast(t('Msg.LoginSuccess'))
       setTimeout(() => {
         uni.reLaunch({
@@ -578,7 +578,7 @@ const getLoginInfo = async () => {
 
 
 onMounted(() => {
-  uni.$emit('updateSystemList')
+  uni.$emit('updateSystemList',login)
   getCountry()
   getCountryMsg()
 

+ 1 - 1
windows/top-window.vue

@@ -5,7 +5,7 @@
     </div>
     <div class="right" v-if="visible">
       <cwg-payment />
-      <cwg-system />
+      <cwg-system event-source="top"/>
       <cwg-language />
       <cwg-notice />
       <cwg-right-drawer />