浏览代码

feat(router): 配置H5路由模式为history

- 在manifest配置中新增H5端router配置,设置mode为history
- 在manifest.json同步更新router模式为history
- 优化useTabbar,移除tabbar图标的引用,保持图标为空字符串
- 改进sys store中获取accessId方法,从hash方式改为path方式
- 添加tenantCode判断,tenantCode存在时跳过第三方主题色请求
zhangtao 3 天之前
父节点
当前提交
244208d405
共有 13 个文件被更改,包括 20 次插入14 次删除
  1. 3 0
      manifest.config.ts
  2. 3 7
      src/composables/useTabbar.ts
  3. 3 0
      src/manifest.json
  4. 二进制
      src/static/tab/cart1.png
  5. 二进制
      src/static/tab/cart2.png
  6. 二进制
      src/static/tab/class-tab0.png
  7. 二进制
      src/static/tab/class-tab1.png
  8. 二进制
      src/static/tab/index.png
  9. 二进制
      src/static/tab/index1.png
  10. 二进制
      src/static/tab/index2.png
  11. 二进制
      src/static/tab/my1.png
  12. 二进制
      src/static/tab/my2.png
  13. 11 7
      src/store/sys.ts

+ 3 - 0
manifest.config.ts

@@ -88,6 +88,9 @@ export default defineManifestConfig({
   'h5': {
     // darkmode: true,
     // themeLocation: 'theme.json',
+    router: {
+      mode: 'history',
+    },
     sdkConfigs: {
       maps: {
         qqmap: {

+ 3 - 7
src/composables/useTabbar.ts

@@ -1,7 +1,3 @@
-import icon4 from '@/static/tab/cart2.png'
-import icon6 from '@/static/tab/my2.png'
-import class2 from '@/static/tab/class-tab1.png'
-
 export interface TabbarItem {
   name: string
   value: number | null
@@ -13,9 +9,9 @@ export interface TabbarItem {
 
 const tabbarItems = ref<TabbarItem[]>([
   { name: 'smqjh-home', value: null, active: true, title: '首页', icon1: '', icon2: '' },
-  { name: 'smqjh-classfiy', value: null, active: false, title: '分类', icon1: '', icon2: class2 },
-  { name: 'smqjh-cart', value: null, active: false, title: '购物车', icon1: '', icon2: icon4 },
-  { name: 'smqjh-my', value: null, active: false, title: '我的', icon1: '', icon2: icon6 },
+  { name: 'smqjh-classfiy', value: null, active: false, title: '分类', icon1: '', icon2: '' },
+  { name: 'smqjh-cart', value: null, active: false, title: '购物车', icon1: '', icon2: '' },
+  { name: 'smqjh-my', value: null, active: false, title: '我的', icon1: '', icon2: '' },
 ])
 
 export function useTabbar() {

+ 3 - 0
src/manifest.json

@@ -84,6 +84,9 @@
   },
   "vueVersion": "3",
   "h5": {
+    "router": {
+      "mode": "history"
+    },
     "sdkConfigs": {
       "maps": {
         "qqmap": {

二进制
src/static/tab/cart1.png


二进制
src/static/tab/cart2.png


二进制
src/static/tab/class-tab0.png


二进制
src/static/tab/class-tab1.png


二进制
src/static/tab/index.png


二进制
src/static/tab/index1.png


二进制
src/static/tab/index2.png


二进制
src/static/tab/my1.png


二进制
src/static/tab/my2.png


+ 11 - 7
src/store/sys.ts

@@ -117,7 +117,9 @@ export const useSysStore = defineStore('system', {
      * 获取第三方主题色
      */
     async getThirdPartyThemeColor() {
-      const accessId = this.getAccessIdFromHash() || 'ch_002'
+      if (this.tenantCode)
+        return
+      const accessId = this.getAccessIdFromPath()
       try {
         const res = await Apis.sys.appAccess({ pathParams: { accessId } })
         this.thirdPartyName = res.data.accessName
@@ -130,12 +132,14 @@ export const useSysStore = defineStore('system', {
       }
     },
 
-    getAccessIdFromHash() {
-      // 仅在 H5 下从地址栏 hash 路由中提取第一个路径段作为 accessId
-      const hash = window.location.hash || ''
-      const path = hash.replace(/^#\/?/, '').split('?')[0]
-      const [accessId] = path.split('/').filter(Boolean)
-      return accessId
+    getAccessIdFromPath() {
+      // 仅在 H5 下从地址路径中提取第一个路径段作为 accessId
+      // #ifdef H5
+      const path = window.location.pathname || ''
+      const cleanPath = path.split('?')[0].replace(/^\//, '')
+      const [accessId] = cleanPath.split('/').filter(Boolean)
+      return accessId || ''
+      // #endif
     },
 
   },