Pārlūkot izejas kodu

Merge branch 'hotfix/修复云机授权' of Software/android-cloud-H5 into develop

zengzhixiang 2 gadi atpakaļ
vecāks
revīzija
6053add615

+ 2 - 2
pages/phone/_id.vue

@@ -37,12 +37,12 @@ export default {
       }/WXtrialInterface.html${qs.stringify(
         {
           userCardId,
-          username: userName,
+          username: $auth.user.username,
           token,
           rm: room,
           mealType: buyVipType,
           sourceType,
-          authPhone,
+          authPhone: authPhone ? 'huo' : 'none',
           validTime,
         },
         {

+ 52 - 1
schemes/password.js

@@ -4,7 +4,22 @@ import { LocalScheme } from '~auth/runtime';
 // const { createHash } = await import('node:crypto');
 let publicKey;
 const encrypt = new JSEncrypt();
-
+function getProp(holder, propName) {
+  if (!propName || !holder || typeof holder !== 'object') {
+    return holder;
+  }
+  if (propName in holder) {
+    return holder[propName];
+  }
+  const propParts = Array.isArray(propName)
+    ? propName
+    : (propName + '').split('.');
+  let result = holder;
+  while (propParts.length && result) {
+    result = result[propParts.shift()];
+  }
+  return result;
+}
 export default class CustomScheme extends LocalScheme {
   async login(data, { reset = true } = {}) {
     const endpoint = { data: Object.assign({}, data) };
@@ -53,6 +68,8 @@ export default class CustomScheme extends LocalScheme {
       this.options.endpoints.login,
     );
     this.updateTokens(response);
+    localStorage.setItem('auth.username', response.data.data.username);
+
     if (!this.requestHandler.interceptor) {
       this.initializeRequestInterceptor();
     }
@@ -61,4 +78,38 @@ export default class CustomScheme extends LocalScheme {
     }
     return response;
   }
+
+  fetchUser(endpoint) {
+    console.log(
+      '🚀 ~ file: password.js ~ line 83 ~ CustomScheme ~ fetchUser ~ endpoint',
+      endpoint,
+    );
+    if (!this.check().valid) {
+      return Promise.resolve();
+    }
+    if (!this.options.endpoints.user) {
+      this.$auth.setUser({});
+      return Promise.resolve();
+    }
+    return this.$auth
+      .requestWith(this.name, endpoint, this.options.endpoints.user)
+      .then((response) => {
+        const userData = getProp(response.data, this.options.user.property);
+
+        userData.username = localStorage.getItem('auth.username');
+
+        if (!userData) {
+          const error = new Error(
+            `User Data response does not contain field ${this.options.user.property}`,
+          );
+          return Promise.reject(error);
+        }
+        this.$auth.setUser(userData);
+        return response;
+      })
+      .catch((error) => {
+        this.$auth.callOnError(error, { method: 'fetchUser' });
+        return Promise.reject(error);
+      });
+  }
 }

+ 1 - 1
static/screenAndroid/WXdraw.js

@@ -148,7 +148,7 @@ function doConnectDirectives() {
           // 不同账号
 
           // 当前是获取方
-          if (isControl && isAuth === 'huo') {
+          if (isAuth === 'huo') {
             $.confirm(
               '授权方已收回控制权,您进入观看屏幕模式',
               function () {

+ 1 - 1
static/screenIos/WXdraw.js

@@ -157,7 +157,7 @@ function doConnectDirectives() {
           // 不同账号
 
           // 当前是获取方
-          if (isControl && isAuth === 'huo') {
+          if (isAuth === 'huo') {
             $.confirm(
               '授权方已收回控制权,您进入观看屏幕模式',
               function () {