Ver Fonte

refactor: 优化用户状态管理和HTTP请求头设置,移除冗余代码

EvilDragon há 3 meses atrás
pai
commit
8c8c5a275c

+ 1 - 1
packages/app/src/main.ts

@@ -1,6 +1,6 @@
 import { createSSRApp } from 'vue'
 import App from './App.vue'
-import store, { useUserStore } from './store'
+import store from './store'
 import { routeInterceptor, requestInterceptor, prototypeInterceptor } from './interceptors'
 import 'virtual:uno.css'
 import '@/style/index.scss'

+ 5 - 9
packages/app/src/utils/http.ts

@@ -3,17 +3,13 @@ import { CustomRequestOptions } from '../interceptors/request'
 import { useUserStore } from '../store'
 import dayjs from 'dayjs'
 
-const userStore = useUserStore()
-// console.log(userStore.userInfo)
-const Authorization = userStore.userInfo?.token
-// console.log(Authorization)
-const header: { 'tenant-id': number; Authorization?: string } = {
-  'tenant-id': 1,
-  Authorization,
-}
-// Authorization && (header.Authorization = `Bearer ${Authorization}`)
 export const http = async <T>(options: CustomRequestOptions) => {
   const userStore = useUserStore()
+  const Authorization = userStore.userInfo?.token
+  const header: { 'tenant-id': number; Authorization?: string } = {
+    'tenant-id': 1,
+    Authorization,
+  }
   // console.log(dayjs(userStore.userInfo.expiresTime).format('YYYY-MM-DD HH:mm:ss'))
   const diff = dayjs(userStore.userInfo.expiresTime).diff(dayjs(), 'minutes')
   // console.log(diff)

+ 8 - 10
packages/merchant/.eslintrc-auto-import.json

@@ -3,11 +3,14 @@
     "Component": true,
     "ComponentPublicInstance": true,
     "ComputedRef": true,
+    "DirectiveBinding": true,
     "EffectScope": true,
     "ExtractDefaultPropTypes": true,
     "ExtractPropTypes": true,
     "ExtractPublicPropTypes": true,
     "InjectionKey": true,
+    "MaybeRef": true,
+    "MaybeRefOrGetter": true,
     "PropType": true,
     "Ref": true,
     "VNode": true,
@@ -20,7 +23,6 @@
     "effectScope": true,
     "getCurrentInstance": true,
     "getCurrentScope": true,
-    "h": true,
     "inject": true,
     "isProxy": true,
     "isReactive": true,
@@ -65,6 +67,7 @@
     "onUnload": true,
     "onUnmounted": true,
     "onUpdated": true,
+    "onWatcherCleanup": true,
     "provide": true,
     "reactive": true,
     "readonly": true,
@@ -82,20 +85,15 @@
     "useAttrs": true,
     "useCssModule": true,
     "useCssVars": true,
+    "useId": true,
+    "useModel": true,
     "useRequest": true,
     "useSlots": true,
+    "useTemplateRef": true,
     "useUpload": true,
-    "useUpload2": true,
     "watch": true,
     "watchEffect": true,
     "watchPostEffect": true,
-    "watchSyncEffect": true,
-    "onWatcherCleanup": true,
-    "useId": true,
-    "useModel": true,
-    "useTemplateRef": true,
-    "DirectiveBinding": true,
-    "MaybeRef": true,
-    "MaybeRefOrGetter": true
+    "watchSyncEffect": true
   }
 }

+ 1 - 1
packages/merchant/src/pages/home/index.vue

@@ -137,7 +137,7 @@ onShow(async () => {})
 onLoad(() => {
   console.log(isLogined.value)
   if (!isLogined.value) {
-    uni.reLaunch({ url: '/pages/login/index' })
+    // uni.reLaunch({ url: '/pages/login/index' })
   }
 })
 onShareAppMessage(() => ({}))

+ 2 - 1
packages/merchant/src/pages/login/index.vue

@@ -37,6 +37,7 @@ onLoad(() => {
     uni.reLaunch({ url: '/pages/home/index' })
   }
 })
+onShareAppMessage(async () => ({}))
 </script>
 <template>
   <div class="flex-grow flex flex-col items-center justify-start px-7.5 bg-[#ffffff] pt-[100px]">
@@ -62,7 +63,7 @@ onLoad(() => {
           <wd-img :src="loginPswIcon" mode="widthFix" width="19" />
           <wd-input
             no-border
-            type="number"
+            show-password
             placeholder="请输入密码"
             v-model="formData.password"
             custom-class="flex-1 bg-transparent!"

+ 0 - 3
packages/merchant/src/types/auto-import.d.ts

@@ -14,7 +14,6 @@ declare global {
   const effectScope: typeof import('vue')['effectScope']
   const getCurrentInstance: typeof import('vue')['getCurrentInstance']
   const getCurrentScope: typeof import('vue')['getCurrentScope']
-  const h: typeof import('vue')['h']
   const inject: typeof import('vue')['inject']
   const isProxy: typeof import('vue')['isProxy']
   const isReactive: typeof import('vue')['isReactive']
@@ -79,12 +78,10 @@ declare global {
   const useCssVars: typeof import('vue')['useCssVars']
   const useId: typeof import('vue')['useId']
   const useModel: typeof import('vue')['useModel']
-  const useNavbarWeixin: (typeof import('../hooks/useNavbarWeixin'))['default']
   const useRequest: typeof import('../hooks/useRequest')['default']
   const useSlots: typeof import('vue')['useSlots']
   const useTemplateRef: typeof import('vue')['useTemplateRef']
   const useUpload: typeof import('../hooks/useUpload')['default']
-  const useUpload2: typeof import('../hooks/useUpload2')['default']
   const watch: typeof import('vue')['watch']
   const watchEffect: typeof import('vue')['watchEffect']
   const watchPostEffect: typeof import('vue')['watchPostEffect']

+ 5 - 9
packages/merchant/src/utils/http.ts

@@ -3,17 +3,13 @@ import { CustomRequestOptions } from '../interceptors/request'
 import { useUserStore } from '../store'
 import dayjs from 'dayjs'
 
-const userStore = useUserStore()
-// console.log(userStore.userInfo)
-const Authorization = userStore.userInfo?.token
-// console.log(Authorization)
-const header: { 'tenant-id': number; Authorization?: string } = {
-  'tenant-id': 1,
-  Authorization,
-}
-// Authorization && (header.Authorization = `Bearer ${Authorization}`)
 export const http = async <T>(options: CustomRequestOptions) => {
   const userStore = useUserStore()
+  const Authorization = userStore.userInfo?.token
+  const header: { 'tenant-id': number; Authorization?: string } = {
+    'tenant-id': 1,
+    Authorization,
+  }
   // console.log(dayjs(userStore.userInfo.expiresTime).format('YYYY-MM-DD HH:mm:ss'))
   const diff = dayjs(userStore.userInfo.expiresTime).diff(dayjs(), 'minutes')
   // console.log(diff)