设置网页title为固定值

This commit is contained in:
rucky 2025-03-14 18:00:32 +08:00
parent ad7b421eff
commit 8588aabf1c
3 changed files with 39 additions and 39 deletions

View File

@ -1,8 +1,8 @@
import { useNavigationBarTitleStore } from '@/stores/navigationBarTitle' import { useNavigationBarTitleStore } from "@/stores/navigationBarTitle";
export default { export default {
onShow() { onShow() {
const navigationBarTitleStore = useNavigationBarTitleStore() const navigationBarTitleStore = useNavigationBarTitleStore();
navigationBarTitleStore.setTitle() navigationBarTitleStore.setTitle();
} },
} };

View File

@ -336,7 +336,7 @@
{ {
"path": "pages/create/create", "path": "pages/create/create",
"style": { "style": {
"navigationBarTitleText": "创作" "navigationBarTitleText": "信广龙AI智能体"
}, },
"meta": { "meta": {
"auth": true, "auth": true,

View File

@ -1,38 +1,38 @@
import { defineStore } from 'pinia' import { defineStore } from "pinia";
import router from '@/router' import router from "@/router";
interface routeObject { interface routeObject {
path: string path: string;
title: string title: string;
} }
interface NavigationBarTitleState { interface NavigationBarTitleState {
pathToTitleMap: Map<string, string | undefined> pathToTitleMap: Map<string, string | undefined>;
} }
export const useNavigationBarTitleStore = defineStore({ export const useNavigationBarTitleStore = defineStore({
id: 'navigationBarTitleStore', id: "navigationBarTitleStore",
state: (): NavigationBarTitleState => ({ state: (): NavigationBarTitleState => ({
pathToTitleMap: new Map() pathToTitleMap: new Map(),
}), }),
getters: { getters: {
getTitle(): string | undefined { getTitle(): string | undefined {
try { try {
const realRoute = router.resolve(router.currentRoute.value.path) const realRoute = router.resolve(router.currentRoute.value.path);
return this.pathToTitleMap.get(realRoute?.path!) return this.pathToTitleMap.get(realRoute?.path!);
} catch (error) { } catch (error) {
console.log('getTitle Error => ', error) console.log("getTitle Error => ", error);
}
} }
}, },
},
actions: { actions: {
add({ path, title }: routeObject) { add({ path, title }: routeObject) {
this.pathToTitleMap.set(path, title) this.pathToTitleMap.set(path, title);
}, },
setTitle() { setTitle() {
const title = this.getTitle const title = this.getTitle;
if (title) { if (title) {
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
title title: "信广龙AI智能体", // title
}) });
} }
} },
} },
}) });