h5环境配置

This commit is contained in:
zjf committed 2026-09-28 17:25:10 +08:00
1 parent 487082cc80
commit 71ba22bedc
2 files changed
+36 -19

No files matched your search

+34 -18
View File
@@ -152,15 +152,20 @@ export const useTabbarStore = defineStore("tabbar", {
if (!this._getNativeTabbarPath()) {
return
}
if (typeof uni.setTabBarItem !== "function") return
this.allTabbarList.forEach((item, index) => {
const visible = this.visibleTabbarList.some((current) => current.pagePath === item.pagePath)
uni.setTabBarItem({
index,
text: this.resolveTabText(item),
iconPath: item.iconPath,
selectedIconPath: item.selectedIconPath,
visible,
})
try {
uni.setTabBarItem({
index,
text: this.resolveTabText(item),
iconPath: item.iconPath,
selectedIconPath: item.selectedIconPath,
visible,
})
} catch (err) {
console.log("setTabBarItem error:", err)
}
})
},
reset() {
@@ -284,24 +289,31 @@ export const useTabbarStore = defineStore("tabbar", {
if (!targetPath || this.isTabbarPage(targetPath)) return
this.hideTabbar(currentPath)
},
// 原生 tabbar 相关 API 只能在 tabbar 页面执行,这里统一做保护。
// 原生 tabbar 相关 API 只能在 tabbar 页面执行;H5 部分环境未实现,需先探测再调用,避免打断路由。
_applyNativeTabbarVisibility(path = "") {
const nativeTabbarPath = this._getNativeTabbarPath(path)
if (!nativeTabbarPath) return
const action = this.tabbarVisible ? "showTabBar" : "hideTabBar"
uni[action]({
animation: true,
success: (res) => {
console.log(`${action}:`, res)
},
fail: (err) => {
console.log(`${action} fail:`, err)
},
})
const api = (uni as any)[action]
if (typeof api !== "function") return
try {
api({
animation: true,
success: (res: any) => {
console.log(`${action}:`, res)
},
fail: (err: any) => {
console.log(`${action} fail:`, err)
},
})
} catch (err) {
console.log(`${action} error:`, err)
}
},
// 原生 tabbar 不能动态增删项,只能按索引逐项控制可见性。
_applyNativeTabbarItems() {
if (!this._getNativeTabbarPath()) return
if (typeof uni.setTabBarItem !== "function") return
this.allTabbarList.forEach((item, index) => {
const visible = this.visibleTabbarList.some((current) => current.pagePath === item.pagePath)
const options: any = {
@@ -311,7 +323,11 @@ export const useTabbarStore = defineStore("tabbar", {
selectedIconPath: item.selectedIconPath,
visible,
}
uni.setTabBarItem(options)
try {
uni.setTabBarItem(options)
} catch (err) {
console.log("setTabBarItem error:", err)
}
})
},
// 统一监听全局路由跳转,避免每个页面都手动调用 show/hideTabBar。
+2 -1
View File
@@ -29,7 +29,8 @@ export default defineConfig(({ mode }) => {
throw new Error("生产环境必须使用 HTTPS 协议!请检查 VITE_APP_PROD_SERVICE 配置")
}
return {
base: "/h5/",
// H5 部署子路径只在 manifest.json → h5.router.base 配置;
// 勿在此处写死 /h5/,否则 App(iOS/Android) 打包也会带上错误前缀。
build: {
target: "es6",
sourcemap: false,