Przeglądaj źródła

优化自动刷新token

“shengjie.huang” 1 rok temu
rodzic
commit
464e71f97b

+ 4 - 0
src/App.vue

@@ -4,6 +4,10 @@ import { useUserStore } from '@/store'
 
 onLaunch(() => {
   console.log('App Launch')
+  // 已经有登录过token的情况下, 更新token
+  if (useUserStore().isLogined) {
+    useUserStore().wxLogin().then((token) => { })
+  }
 })
 onShow(() => {
   console.log('App Show')

+ 7 - 4
src/pages/assistant/detail.vue

@@ -151,11 +151,11 @@ function handleSubmit() {
 onLoad((option) => {
   // 通过分享传参
   type.value = option.type || "add"
-  if (type.value == 'add' && option.hostname && option.asname) {
-    formData.value.hostname = option.hostname
-    formData.value.asname = option.asname
+  if (type.value == 'add' && option.scene) {
+    formData.value.hostname = option.scene
+    formData.value.asname = option.scene
     message.confirm({
-      msg: `是否添加设备"${option.asname}"到我的打印助手`,
+      msg: `是否添加设备"${option.scene}"到我的打印助手`,
       closeOnClickModal: false,
     }).then(() => {
       handleSubmit()
@@ -176,4 +176,7 @@ onLoad((option) => {
 :deep(.wd-cell__value) {
   text-align: left !important;
 }
+:deep(.wd-message-box__content) {
+  word-break: break-all;
+}
 </style>

+ 1 - 1
src/pages/assistant/index.vue

@@ -280,7 +280,7 @@ onReachBottom(() => {
 onShareAppMessage(() => {
   return {
     title: "分享设备:给你分享了一个打印助手,可点击添加",
-    path: `pages/assistant/detail?type=add&hostname=${currentData.value.hostname}&asname=${currentData.value.asname}`,
+    path: `pages/assistant/detail?scene=${currentData.value.hostname}`,
     imageUrl: deviceImgSrc.value,
   }
 })

+ 3 - 3
src/pages/print/index.vue

@@ -264,15 +264,16 @@ function updateShowName() {
 
 // 获取打印机 (兼容远程+局域网, 打印机均可选择, 只是选择局域网打印机的处理逻辑不同)
 function getPrinterList() {
-  let params = { id: "" }
+  let params = {}
   getUserHubPrints(params)
     .then((res: any) => {
       if (res.code === 0 && res.body) {
-        // printerList.value = res.body && res.body.length > 0 ? res.body.filter(i => i['printer-type'] == 'normal' ) : []
         printerList.value = res.body || []
         printerList.value.forEach(item => {
           item.showName = `${item.name} (${item.userHubName})`
         })
+        // 检查局域网打印
+        checkUserHub()
       }
     })
     .catch((e) => {})
@@ -834,7 +835,6 @@ onLoad((option) => {
     }
   }
   getPrinterList()
-  checkUserHub()
 })
 </script>
 

+ 2 - 2
src/store/user.ts

@@ -39,8 +39,8 @@ export const useUserStore = defineStore(
       return new Promise<void>((resolve, reject) => {
         loginByCode({ code })
           .then((res: any) => {
-            if (res.code === 0) {
-              const accessToken = res.body.token || ''
+            if (res.code === 0 && res.body.token) {
+              const accessToken = res.body.token
               setToken(accessToken)
               initUserInfo()
               resolve(accessToken)