li.shaoyi 2 anos atrás
pai
commit
d85d07c9d2

+ 3 - 2
public/manifest.json

@@ -7,7 +7,7 @@
     "version" : {
         "name" : "1.1.0",
         /*应用版本名称*/
-        "code" : 100010
+        "code" : 100100
     },
     "description" : "",
     /*应用描述信息*/
@@ -143,7 +143,8 @@
                 "permissions" : [],
                 "abiFilters" : [ "armeabi-v7a", "arm64-v8a" ],
                 "autoSdkPermissions" : false,
-                "minSdkVersion" : 30
+                "minSdkVersion" : 29,
+                "targetSdkVersion" : ""
             },
             /*使用Native.js调用原生安卓API需要使用到的系统权限*/
             "orientation" : [ "portrait-primary" ],

+ 5 - 5
src/hooks/navigation/index.ts

@@ -12,8 +12,8 @@ export function useNavigation() {
 
     // 是否有历史页面
     const hasHistory = () => {
-        const { state } = animateRouter
-        return state.history.length > 1
+        const state = animateRouter.getState()
+        return state.historyRoutes.length > 1
     }
 
     // 获取全局Url参数(只能获取一次)
@@ -70,15 +70,15 @@ export function useNavigation() {
 
     // 返回主页
     const backHome = () => {
-        const { state } = animateRouter
-        const delta = state.history.length - 1
+        const state = animateRouter.getState()
+        const delta = state.historyRoutes.length - 1
         const params = { tabIndex: 0 }
 
         if (delta) {
             setGlobalUrlParams(params)
             router.go(-delta)
         } else {
-            const page = state.history[0]
+            const page = state.historyRoutes[0]
             if (page?.name !== 'home-index') {
                 setGlobalUrlParams(params)
                 router.replace({ name: 'home-index' })

+ 0 - 1
src/packages/mobile/components/base/router-transition/index.less

@@ -2,7 +2,6 @@
 @transition-duration: 220ms;
 
 /* 无过渡效果 */
-.delay-enter-active,
 .delay-leave-active {
     transition-duration: @transition-duration;
 }

+ 3 - 3
src/packages/mobile/components/layouts/page/index.vue

@@ -1,8 +1,8 @@
 <template>
   <router-view class="app-page" v-slot="{ Component, route }">
-    <RouterTransition :transition-name="state.transitionName" @leave="onLeave" @after-enter="onAfterEnter">
+    <RouterTransition :transition-name="transitionName" @leave="onLeave" @after-enter="onAfterEnter">
       <!-- 缓存组件,前进刷新,后退缓存 -->
-      <keep-alive :exclude="state.excludeViews">
+      <keep-alive :exclude="excludeViews">
         <component :is="handleComponent(Component, route)" :key="getRouteKey(route)" />
       </keep-alive>
     </RouterTransition>
@@ -15,7 +15,7 @@ import animateRouter from '@mobile/router/animateRouter'
 import RouterTransition from '@mobile/components/base/router-transition/index.vue'
 import http from '@/services/http'
 
-const { state } = animateRouter
+const { transitionName, excludeViews } = animateRouter.getStateRef()
 
 // 手动给组件添加 name 属性,处理缓存 exclude 无效的问题
 const handleComponent = (component: Record<'type', { name: RouteRecordName | undefined }>, route: RouteRecordNormalized) => {

+ 92 - 60
src/packages/mobile/router/animateRouter.ts

@@ -1,34 +1,47 @@
-import { ref, toRefs, readonly } from 'vue'
+import { ref, toRefs } from 'vue'
 import { createRouter, RouterOptions, RouteRecordRaw, RouteLocationNormalized } from 'vue-router'
 
+interface historyRoute {
+    name: string;
+    fullPath: string;
+}
+
 interface HistoryState {
-    history: RouteLocationNormalized[]; // 已访问的路由列表
-    excludeViews: string[]; // 不缓存的页面
+    historyRoutes: historyRoute[]; // 历史路由列表
+    excludeViews: string[]; // 不缓存的视图
     actionName: '' | 'push' | 'replace' | 'forward' | 'back'; // 当前路由动作
     transitionName: '' | 'route-out' | 'route-in'; // 前进后退动画
     goStep: number; // 前进后退步数
 }
 
 export default new (class {
-    private storageKey = 'history_mobile';
+    private storageKey = 'history_mobile'
 
-    private _state = ref<HistoryState>({
-        history: [],
+    private state = ref<HistoryState>({
+        historyRoutes: [],
         excludeViews: [],
         actionName: '',
         transitionName: '',
-        goStep: 0,
+        goStep: 0
     })
 
-    /** 只读状态 */
-    state;
-
     constructor() {
-        const state = sessionStorage.getItem(this.storageKey);
+        const state = sessionStorage.getItem(this.storageKey)
         if (state) {
-            this._state.value = JSON.parse(state);
+            // 合并赋值,防止 sessionStorage 获取的值有问题
+            this.state.value = {
+                ...this.state.value,
+                ...JSON.parse(state)
+            }
         }
-        this.state = readonly(toRefs(this._state.value));
+    }
+
+    getState() {
+        return this.state.value
+    }
+
+    getStateRef() {
+        return toRefs(this.state.value)
     }
 
     /**
@@ -37,56 +50,55 @@ export default new (class {
      * @returns 
      */
     create = (options: RouterOptions) => {
-        const router = createRouter(options);
-        const { push, replace, go, forward, back } = router;
-        const { actionName, goStep } = toRefs(this._state.value);
+        const router = createRouter(options)
+        const { push, replace, go, forward, back } = router
+        const { excludeViews, actionName, goStep } = this.getStateRef()
 
         // 添加
         router.push = (to: RouteRecordRaw) => {
-            actionName.value = 'push';
-            return push(to);
+            actionName.value = 'push'
+            return push(to)
         }
 
         // 替换
         router.replace = (to: RouteRecordRaw) => {
-            actionName.value = 'replace';
-            return replace(to);
+            actionName.value = 'replace'
+            return replace(to)
         }
 
         // 前进后退
         router.go = (delta: number) => {
-            goStep.value = delta;
+            goStep.value = delta
             if (delta > 0) {
-                actionName.value = 'forward';
+                actionName.value = 'forward'
             }
             if (delta < 0) {
-                actionName.value = 'back';
+                actionName.value = 'back'
             }
-            go(delta);
+            go(delta)
         }
 
         // 前进
         router.forward = () => {
-            actionName.value = 'forward';
-            forward();
+            actionName.value = 'forward'
+            forward()
         }
 
         // 后退
         router.back = () => {
-            actionName.value = 'back';
-            back();
+            actionName.value = 'back'
+            back()
         }
 
         router.beforeResolve((to) => {
-            this.addHistory(to);
+            this.addHistory(to)
         })
 
         router.afterEach(() => {
-            const { excludeViews } = toRefs(this._state.value);
-            excludeViews.value = [];
+            excludeViews.value = []
         })
 
-        return router;
+        return router
     }
 
     /**
@@ -94,66 +106,86 @@ export default new (class {
      * @param route 
      */
     private addHistory = (route: RouteLocationNormalized) => {
-        const { history, excludeViews, actionName, transitionName, goStep } = toRefs(this._state.value);
+        const { historyRoutes, excludeViews, actionName, transitionName, goStep } = this.getStateRef()
+        const newRoute = {
+            name: route.name as string,
+            fullPath: route.fullPath
+        }
 
         // 如果是替换动作,必定是前进
         if (actionName.value === 'replace') {
-            const lastIndex = history.value.length - 1;
-            const lastView = history.value[lastIndex];
+            const lastIndex = historyRoutes.value.length - 1
+            const lastView = historyRoutes.value[lastIndex]
 
             if (lastView) {
-                excludeViews.value.push(lastView.name as string);
-                history.value[lastIndex] = route; // 更新最后一条记录
+                excludeViews.value.push(lastView.name as string)
+                historyRoutes.value[lastIndex] = newRoute // 更新最后一条记录
             } else {
-                history.value.push(route);
+                historyRoutes.value.push(newRoute)
             }
-            transitionName.value = 'route-in'; // 前进动画
+
+            transitionName.value = 'route-in' // 前进动画
         } else {
             // 倒序查找路由所在的位置
             const index = (() => {
-                for (let i = history.value.length - 1; i >= 0; i--) {
-                    if (history.value[i].fullPath === route.fullPath) {
-                        return i;
+                for (let i = historyRoutes.value.length - 1; i >= 0; i--) {
+                    if (historyRoutes.value[i].fullPath === route.fullPath) {
+                        return i
                     }
                 }
-                return -1;
-            })();
+                return -1
+            })()
 
             if (index > -1) {
                 if (actionName.value === 'push') {
-                    history.value.push(route);
-                    transitionName.value = 'route-in'; //前进动画
+                    historyRoutes.value.push(newRoute)
+                    transitionName.value = 'route-in' //前进动画
                 } else {
-                    if (history.value.length > 1) {
-                        const i = index + 1;
-                        const n = history.value.length - i;
+                    if (historyRoutes.value.length > 1) {
+                        const i = index + 1
+                        const n = historyRoutes.value.length - i
 
-                        excludeViews.value = history.value.map((e) => e.name).slice(-n) as string[]; // 返回数组最后位置开始的n个元素
-                        history.value.splice(i, n); // 从i位置开始删除后面所有元素(包括i)
+                        excludeViews.value = historyRoutes.value.map((e) => e.name).slice(-n) // 返回数组最后位置开始的n个元素
+                        historyRoutes.value.splice(i, n) // 从i位置开始删除后面所有元素(包括i)
                     }
-                    transitionName.value = 'route-out'; //后退动画
+                    transitionName.value = 'route-out' //后退动画
                 }
             } else {
                 if (goStep.value < 0) {
-                    const start = history.value.length + goStep.value
+                    const start = historyRoutes.value.length + goStep.value
                     if (start) {
-                        history.value.splice(start)
+                        historyRoutes.value.splice(start)
                     }
                 }
                 // 忽略重定向的页面
                 if (route.redirectedFrom) {
-                    transitionName.value = 'route-in'; // 前进动画
+                    transitionName.value = 'route-in' // 前进动画
                 } else {
-                    history.value.push(route);
-                    if (history.value.length > 1) {
-                        transitionName.value = 'route-in'; // 前进动画
+                    historyRoutes.value.push(newRoute)
+                    if (historyRoutes.value.length > 1) {
+                        transitionName.value = 'route-in' // 前进动画
                     }
                 }
             }
         }
 
-        actionName.value = '';
+        actionName.value = ''
         goStep.value = 0
-        sessionStorage.setItem(this.storageKey, JSON.stringify(this._state.value));
+
+        // 处理对象循环引用
+        // const getCircularReplacer = () => {
+        //     const seen = new WeakSet()
+        //     return (key: string, value: unknown) => {
+        //         if (typeof value === 'object' && value !== null) {
+        //             if (seen.has(value)) {
+        //                 return
+        //             }
+        //             seen.add(value)
+        //         }
+        //         return value
+        //     }
+        // }
+
+        sessionStorage.setItem(this.storageKey, JSON.stringify(this.state.value))
     }
 })

+ 1 - 3
src/packages/mobile/views/user/register/index.vue

@@ -19,7 +19,7 @@
         <Field v-model="formData.loginpwd" name="loginpwd" type="password" label="登录密码" placeholder="必填"
           autocomplete="off" :rules="formRules.loginpwd" />
         <Field v-model="formData.refernum" name="refernum" label="注册编码" placeholder="必填" autocomplete="off"
-          :rules="formRules.refernum">
+          :rules="formRules.refernum" v-if="false">
           <!-- <template #button>
             <app-qrcode-scan @success="onScanSuccess">
               <Button size="small" type="primary">扫码</Button>
@@ -84,12 +84,10 @@ const formData = reactive<Model.RegisterReq>({
   mobilephone: '',
   loginpwd: '',
   vcode: '',
-  refernum: '',
   isaudit: 1,
   userinfotype: 1,
   usertype: 5,
   openmode: 5,
-  lsitAgreementID: []
 })
 
 // 表单验证规则

+ 1 - 1
src/types/model/common.d.ts

@@ -34,7 +34,7 @@ declare global {
             mobilephone: string; // 手机号
             loginpwd: string; // 登录密码
             vcode: string; // 验证码
-            refernum: string; // 推荐码: refernum(推荐码不为空,则取推荐人的所属用户为本用户的所属,推荐码为空,取系统参数003为本用户的所属)
+            refernum?: string; // 推荐码: refernum(推荐码不为空,则取推荐人的所属用户为本用户的所属,推荐码为空,取系统参数003为本用户的所属)
             isaudit: number; // 是否审核: isaudit 0 - 否,1 - 是
             userinfotype: number; // 客户类型: userinfotype 1-个人,2-企业
             usertype: number;