Jelajahi Sumber

feat: 优化tabbar,精简tabbar

菲鸽 1 tahun lalu
induk
melakukan
a9d3eccad5

+ 1 - 1
pages.config.ts

@@ -35,7 +35,7 @@ export default defineUniPages({
         iconType: 'wot',
         iconType: 'wot',
       },
       },
       {
       {
-        pagePath: 'pages/index/about',
+        pagePath: 'pages/about/about',
         text: '关于',
         text: '关于',
         icon: 'i-carbon-code',
         icon: 'i-carbon-code',
         iconType: 'unocss',
         iconType: 'unocss',

+ 1 - 1
src/components/fg-tabbar/fg-tabbar.vue

@@ -40,7 +40,7 @@
 import { tabBar } from '@/pages.json'
 import { tabBar } from '@/pages.json'
 import { tabbarStore } from './tabbar'
 import { tabbarStore } from './tabbar'
 
 
-/** tabbarList 里面的 path 必须和 pages.config.ts 的页面路径一致 */
+/** tabbarList 里面的 path 从 pages.config.ts 得到 */
 const tabbarList = tabBar.list.map((item) => ({ ...item, path: `/${item.pagePath}` }))
 const tabbarList = tabBar.list.map((item) => ({ ...item, path: `/${item.pagePath}` }))
 
 
 function selectTabBar({ value: index }: { value: number }) {
 function selectTabBar({ value: index }: { value: number }) {

+ 1 - 15
src/components/fg-tabbar/tabbar.ts

@@ -1,20 +1,6 @@
-export const tabbarList = [
-  {
-    path: '/pages/index/about',
-    icon: 'home',
-    isWotIcon: true,
-    title: '首页',
-  },
-  {
-    path: '/pages/index/index',
-    icon: 'i-carbon-user-avatar',
-    isWotIcon: false,
-    title: '我的',
-  },
-]
-
 /**
 /**
  * tabbar 状态,增加 storageSync 保证刷新浏览器时在正确的 tabbar 页面
  * tabbar 状态,增加 storageSync 保证刷新浏览器时在正确的 tabbar 页面
+ * 使用reactive简单状态,而不是 pinia 全局状态
  */
  */
 export const tabbarStore = reactive({
 export const tabbarStore = reactive({
   curIdx: uni.getStorageSync('app-tabbar-index') || 0,
   curIdx: uni.getStorageSync('app-tabbar-index') || 0,

+ 17 - 2
src/layouts/tabbar.vue

@@ -1,4 +1,19 @@
 <template>
 <template>
-  <slot />
-  <fg-tabbar />
+  <wd-config-provider :themeVars="themeVars">
+    <slot />
+    <!-- 注意下面,多了一个自定义tabbar -->
+    <fg-tabbar />
+    <wd-toast />
+    <wd-message-box />
+  </wd-config-provider>
 </template>
 </template>
+
+<script lang="ts" setup>
+import type { ConfigProviderThemeVars } from 'wot-design-uni'
+
+const themeVars: ConfigProviderThemeVars = {
+  // colorTheme: 'red',
+  // buttonPrimaryBgColor: '#07c160',
+  // buttonPrimaryColor: '#07c160',
+}
+</script>

+ 2 - 8
src/pages.json

@@ -31,7 +31,7 @@
         "iconType": "wot"
         "iconType": "wot"
       },
       },
       {
       {
-        "pagePath": "pages/index/about",
+        "pagePath": "pages/about/about",
         "text": "关于",
         "text": "关于",
         "icon": "i-carbon-code",
         "icon": "i-carbon-code",
         "iconType": "unocss"
         "iconType": "unocss"
@@ -57,13 +57,7 @@
     {
     {
       "path": "pages/about/about",
       "path": "pages/about/about",
       "type": "page",
       "type": "page",
-      "style": {
-        "navigationBarTitleText": "关于"
-      }
-    },
-    {
-      "path": "pages/index/about",
-      "type": "page",
+      "layout": "tabbar",
       "style": {
       "style": {
         "navigationBarTitleText": "关于"
         "navigationBarTitleText": "关于"
       }
       }

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

@@ -1,5 +1,6 @@
 <route lang="json5">
 <route lang="json5">
 {
 {
+  layout: 'tabbar',
   style: {
   style: {
     navigationBarTitleText: '关于',
     navigationBarTitleText: '关于',
   },
   },

+ 0 - 60
src/pages/index/about.vue

@@ -1,60 +0,0 @@
-<route lang="json5">
-{
-  style: {
-    navigationBarTitleText: '关于',
-  },
-}
-</route>
-
-<template>
-  <view
-    class="bg-white overflow-hidden pt-2 px-4"
-    :style="{ marginTop: safeAreaInsets?.top + 'px' }"
-  >
-    <view class="text-center text-3xl mt-4 test-css">关于页面</view>
-    <view class="text-center text-3xl mt-8">
-      鸽友们好,我是
-      <text class="text-red-500">菲鸽</text>
-    </view>
-    <view class="text-center mt-8 text-#fff">
-      <wd-button type="primary" @click="gotoPage('request')">去请求页</wd-button>
-      <wd-button type="primary" @click="gotoPage('request2')" custom-class="ml-2">
-        去请求页2 (状态一体)
-      </wd-button>
-    </view>
-
-    <view class="text-center mt-8 text-#fff">
-      <wd-button type="primary" @click="gotoPage('upload')">上传demo</wd-button>
-      <wd-button type="primary" @click="gotoPage('upload2')" custom-class="ml-2">
-        上传demo2(状态一体)
-      </wd-button>
-    </view>
-    <view class="text-center mt-8">
-      <text class="mr-2">iconfont:</text>
-      <view class="inline-flex gap-2 text-red">
-        <view class="iconfont icon-my" />
-        <view class="iconfont icon-chat" />
-        <view class="iconfont icon-package" />
-      </view>
-    </view>
-  </view>
-  <fg-tabbar />
-</template>
-
-<script lang="ts" setup>
-// 获取屏幕边界到安全区域距离
-const { safeAreaInsets } = uni.getSystemInfoSync()
-
-const gotoPage = (page: string) => {
-  uni.navigateTo({
-    url: `/pages/index/${page}`,
-  })
-}
-</script>
-
-<style lang="scss" scoped>
-.test-css {
-  // mt-4=>1rem=>16px;
-  margin-top: 16px;
-}
-</style>

+ 1 - 2
src/types/uni-pages.d.ts

@@ -6,13 +6,12 @@
 interface NavigateToOptions {
 interface NavigateToOptions {
   url: "/pages/index/index" |
   url: "/pages/index/index" |
        "/pages/about/about" |
        "/pages/about/about" |
-       "/pages/index/about" |
        "/pages/my/index";
        "/pages/my/index";
 }
 }
 interface RedirectToOptions extends NavigateToOptions {}
 interface RedirectToOptions extends NavigateToOptions {}
 
 
 interface SwitchTabOptions {
 interface SwitchTabOptions {
-  url: "/pages/index/index" | "/pages/index/about" | "/pages/my/index"
+  url: "/pages/index/index" | "/pages/about/about" | "/pages/my/index"
 }
 }
 
 
 type ReLaunchOptions = NavigateToOptions | SwitchTabOptions;
 type ReLaunchOptions = NavigateToOptions | SwitchTabOptions;