Quellcode durchsuchen

feat(login): wip 登录系统

feige996 vor 8 Monaten
Ursprung
Commit
6aa4bc3472
5 geänderte Dateien mit 19 neuen und 10 gelöschten Zeilen
  1. 0 5
      src/App.vue
  2. 9 0
      src/pages/about/about.vue
  3. 7 2
      src/router/interceptor.ts
  4. 1 1
      src/tabbar/config.ts
  5. 2 2
      src/tabbar/store.ts

+ 0 - 5
src/App.vue

@@ -1,8 +1,6 @@
 <script setup lang="ts">
 import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
 import { navigateToInterceptor } from '@/router/interceptor'
-
-import { tabbarStore } from './tabbar/store'
 import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
 
 onLaunch((options) => {
@@ -12,9 +10,6 @@ onLaunch((options) => {
   const gotoPath = options?.path || ''
 
   navigateToInterceptor.invoke({ url: gotoPath })
-
-  // 处理直接进入路由非首页时,tabbarIndex 不正确的问题
-  tabbarStore.setAutoCurIdx(gotoPath)
 })
 onShow((options) => {
   console.log('App Show', options)

+ 9 - 0
src/pages/about/about.vue

@@ -17,6 +17,12 @@ import RequestComp from './components/request.vue'
 // testOxlint('oxlint')
 console.log('about')
 
+function toLogin() {
+  uni.navigateTo({
+    url: `/pages/login/login?redirect=${encodeURIComponent('/pages/about/about')}`,
+  })
+}
+
 function gotoAlova() {
   uni.navigateTo({
     url: '/pages/about/alova',
@@ -51,6 +57,9 @@ onReady(() => {
     <view class="my-2 text-center">
       <image src="/static/images/avatar.jpg" class="h-100px w-100px" />
     </view>
+    <button class="mt-4 w-40 text-center" @click="toLogin">
+      点击去登录页
+    </button>
     <RequestComp />
     <view class="mb-6 h-1px bg-#eee" />
     <view class="text-center">

+ 7 - 2
src/router/interceptor.ts

@@ -5,6 +5,7 @@
  * 我这里应为大部分都可以随便进入,所以使用黑名单
  */
 import { useUserStore } from '@/store'
+import { tabbarStore } from '@/tabbar/store'
 import { getLastPage } from '@/utils'
 import { EXCLUDE_LIST, LOGIN_PAGE_LIST } from '../login/config'
 
@@ -14,6 +15,9 @@ export const navigateToInterceptor = {
   // 增加对相对路径的处理,BY 网友 @ideal
   invoke({ url }: { url: string }) {
     console.log(url) // /pages/route-interceptor/index?name=feige&age=30
+    if (url === undefined) {
+      return
+    }
     let path = url.split('?')[0]
 
     // 处理相对路径
@@ -24,6 +28,9 @@ export const navigateToInterceptor = {
       path = `${baseDir}/${path}`
     }
 
+    // 处理直接进入路由非首页时,tabbarIndex 不正确的问题
+    tabbarStore.setAutoCurIdx(path)
+
     if (LOGIN_PAGE_LIST.includes(path)) {
       console.log('000')
       return
@@ -34,8 +41,6 @@ export const navigateToInterceptor = {
       return
     }
 
-    // tabbarStore.restorePrevIdx()
-
     console.log('拦截器中得到的 path:', path, userStore.hasLogin)
 
     if ([...EXCLUDE_LIST, ...LOGIN_PAGE_LIST].includes(path)) {

+ 1 - 1
src/tabbar/config.ts

@@ -20,7 +20,7 @@ export const TABBAR_STRATEGY_MAP = {
 // 如果是使用 NO_TABBAR(0),nativeTabbarList 和 customTabbarList 都不生效(里面的配置不用管)
 // 如果是使用 NATIVE_TABBAR(1),只需要配置 nativeTabbarList,customTabbarList 不生效
 // 如果是使用 CUSTOM_TABBAR(2,3),只需要配置 customTabbarList,nativeTabbarList 不生效
-export const selectedTabbarStrategy = TABBAR_STRATEGY_MAP.NATIVE_TABBAR
+export const selectedTabbarStrategy = TABBAR_STRATEGY_MAP.CUSTOM_TABBAR_WITH_CACHE
 
 type NativeTabBarItem = TabBar['list'][0]
 // TODO: 2/3. 使用 NATIVE_TABBAR 时,更新下面的 tabbar 配置

+ 2 - 2
src/tabbar/store.ts

@@ -33,8 +33,8 @@ export const tabbarStore = reactive({
     uni.setStorageSync('app-tabbar-index', idx)
   },
   setAutoCurIdx(path: string) {
-    const index = tabbarList.findIndex(item => item.pagePath === path)
-    // console.log('index:', index, path)
+    const index = tabbarList.findIndex(item => item.path === path)
+    console.log('index:', index, path)
     // console.log('tabbarList:', tabbarList)
     if (index === -1) {
       this.setCurIdx(0)