From e81a9725b7305e5c9e96cc9cc394a2a51c289fc4 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Fri, 4 Aug 2023 12:05:48 +0800 Subject: [PATCH] feat: customized site title --- src/i18n/lang/en/router.ts | 1 + src/i18n/lang/en/views/index.ts | 2 + src/i18n/lang/en/views/system.ts | 6 ++ src/i18n/lang/zh/router.ts | 1 + src/i18n/lang/zh/views/index.ts | 2 + src/i18n/lang/zh/views/system.ts | 6 ++ src/interfaces/i18n/router.d.ts | 1 + src/interfaces/i18n/views/index.d.ts | 1 + src/interfaces/i18n/views/system.d.ts | 4 ++ src/interfaces/models/setting.d.ts | 2 +- src/interfaces/store/index.d.ts | 1 + src/interfaces/store/modules/system.d.ts | 25 ++++++++ src/layouts/components/Sidebar.vue | 43 ++++++++++---- src/router/index.ts | 6 +- src/router/system.ts | 11 ++++ src/store/index.ts | 2 + src/store/modules/layout.ts | 1 + src/store/modules/system.ts | 30 ++++++++++ src/views/system/detail/SystemDetail.vue | 76 ++++++++++++++++++++++++ 19 files changed, 207 insertions(+), 14 deletions(-) create mode 100644 src/i18n/lang/en/views/system.ts create mode 100644 src/i18n/lang/zh/views/system.ts create mode 100644 src/interfaces/i18n/views/system.d.ts create mode 100644 src/interfaces/store/modules/system.d.ts create mode 100644 src/router/system.ts create mode 100644 src/store/modules/system.ts create mode 100644 src/views/system/detail/SystemDetail.vue diff --git a/src/i18n/lang/en/router.ts b/src/i18n/lang/en/router.ts index 665b287e7a526..07f151634b1b0 100644 --- a/src/i18n/lang/en/router.ts +++ b/src/i18n/lang/en/router.ts @@ -21,6 +21,7 @@ const router: LRouter = { }, notification: 'Notification', environment: 'Environment', + system: 'System Settings', misc: { disclaimer: 'Disclaimer', mySettings: 'My Settings', diff --git a/src/i18n/lang/en/views/index.ts b/src/i18n/lang/en/views/index.ts index 2e23e4e9de9f4..33471f0404ff2 100644 --- a/src/i18n/lang/en/views/index.ts +++ b/src/i18n/lang/en/views/index.ts @@ -12,6 +12,7 @@ import tokens from './tokens'; import env from './env'; import notification from './notification'; import environment from './environment'; +import system from './system'; import plugins from './plugins'; import misc from './misc'; @@ -31,6 +32,7 @@ const views: LViews = { notification, environment, plugins, + system, misc, }; export default views; diff --git a/src/i18n/lang/en/views/system.ts b/src/i18n/lang/en/views/system.ts new file mode 100644 index 0000000000000..a68faf3867d80 --- /dev/null +++ b/src/i18n/lang/en/views/system.ts @@ -0,0 +1,6 @@ +const system: LViewsSystem = { + customizeSiteTitle: 'Customize Site Title', + siteTitle: 'Site Title', +}; + +export default system; diff --git a/src/i18n/lang/zh/router.ts b/src/i18n/lang/zh/router.ts index e4d80ff2ecc21..f6651ee51b196 100644 --- a/src/i18n/lang/zh/router.ts +++ b/src/i18n/lang/zh/router.ts @@ -21,6 +21,7 @@ const router: LRouter = { }, notification: '消息通知', environment: '环境变量', + system: '系统设置', misc: { disclaimer: '免责声明', mySettings: '我的设置', diff --git a/src/i18n/lang/zh/views/index.ts b/src/i18n/lang/zh/views/index.ts index 2e23e4e9de9f4..33471f0404ff2 100644 --- a/src/i18n/lang/zh/views/index.ts +++ b/src/i18n/lang/zh/views/index.ts @@ -12,6 +12,7 @@ import tokens from './tokens'; import env from './env'; import notification from './notification'; import environment from './environment'; +import system from './system'; import plugins from './plugins'; import misc from './misc'; @@ -31,6 +32,7 @@ const views: LViews = { notification, environment, plugins, + system, misc, }; export default views; diff --git a/src/i18n/lang/zh/views/system.ts b/src/i18n/lang/zh/views/system.ts new file mode 100644 index 0000000000000..4bd1113089606 --- /dev/null +++ b/src/i18n/lang/zh/views/system.ts @@ -0,0 +1,6 @@ +const system: LViewsSystem = { + customizeSiteTitle: '是否自定义网站标题', + siteTitle: '网站标题', +}; + +export default system; diff --git a/src/interfaces/i18n/router.d.ts b/src/interfaces/i18n/router.d.ts index 7f2520bf945f3..7fe7b1cfd72b7 100644 --- a/src/interfaces/i18n/router.d.ts +++ b/src/interfaces/i18n/router.d.ts @@ -22,6 +22,7 @@ export declare global { }; notification: string; environment: string; + system: string; misc: { disclaimer: string; mySettings: string; diff --git a/src/interfaces/i18n/views/index.d.ts b/src/interfaces/i18n/views/index.d.ts index 70863c71c467c..9553d82f5f504 100644 --- a/src/interfaces/i18n/views/index.d.ts +++ b/src/interfaces/i18n/views/index.d.ts @@ -16,5 +16,6 @@ export declare global { misc: LViewsMisc; ds: LViewsDataSource; environment: LViewsEnvironments; + system: LViewsSystem; } } diff --git a/src/interfaces/i18n/views/system.d.ts b/src/interfaces/i18n/views/system.d.ts new file mode 100644 index 0000000000000..23c91e298be8e --- /dev/null +++ b/src/interfaces/i18n/views/system.d.ts @@ -0,0 +1,4 @@ +interface LViewsSystem { + customizeSiteTitle: string; + siteTitle: string; +} diff --git a/src/interfaces/models/setting.d.ts b/src/interfaces/models/setting.d.ts index 66d0a76a72105..e7a205fe84070 100644 --- a/src/interfaces/models/setting.d.ts +++ b/src/interfaces/models/setting.d.ts @@ -1,6 +1,6 @@ export declare global { interface Setting extends BaseModel { key: string; - value: { [key: string]: string }; + value: { [key: string]: any }; } } diff --git a/src/interfaces/store/index.d.ts b/src/interfaces/store/index.d.ts index 44319d014e621..fe1b25f680ca3 100644 --- a/src/interfaces/store/index.d.ts +++ b/src/interfaces/store/index.d.ts @@ -19,6 +19,7 @@ export declare global { notification: NotificationStoreState; ds: DataSourceStoreState; environment: EnvironmentStoreState; + system: SystemStoreState; } type StoreGetter = (state: S, getters: GetterTree, rootState: R, rootGetters: any) => T; diff --git a/src/interfaces/store/modules/system.d.ts b/src/interfaces/store/modules/system.d.ts new file mode 100644 index 0000000000000..915c3ccc7a9ce --- /dev/null +++ b/src/interfaces/store/modules/system.d.ts @@ -0,0 +1,25 @@ +import {GetterTree, Module, MutationTree} from 'vuex'; + +declare global { + interface SystemStoreModule extends Module { + getters: SystemStoreGetters; + mutations: SystemStoreMutations; + actions: SystemStoreActions; + } + + interface SystemStoreState { + siteTitle: Setting; + } + + interface SystemStoreGetters extends GetterTree { + } + + interface SystemStoreMutations extends MutationTree { + setSiteTitle: StoreMutation; + } + + interface SystemStoreActions extends BaseStoreActions { + getSiteTitle: StoreAction; + saveSiteTitle: StoreAction; + } +} diff --git a/src/layouts/components/Sidebar.vue b/src/layouts/components/Sidebar.vue index c621bb7d48927..0a9f0b71d6ed8 100644 --- a/src/layouts/components/Sidebar.vue +++ b/src/layouts/components/Sidebar.vue @@ -14,22 +14,38 @@ +
+ + + +
@@ -74,6 +91,7 @@ export default defineComponent({ const { common: commonState, layout: layoutState, + system: systemState, } = store.state as RootStoreState; const storeNamespace = 'layout'; @@ -137,6 +155,8 @@ export default defineComponent({ const systemInfo = computed(() => commonState.systemInfo || {}); + const siteTitle = computed(() => systemState.siteTitle); + return { sidebarCollapsed, toggleIcon, @@ -148,6 +168,7 @@ export default defineComponent({ onMenuItemClick, toggleSidebar, systemInfo, + siteTitle, t, }; }, @@ -194,7 +215,7 @@ export default defineComponent({ .logo-title { font-family: BlinkMacSystemFont, -apple-system, segoe ui, roboto, oxygen, ubuntu, cantarell, fira sans, droid sans, helvetica neue, helvetica, arial, sans-serif; - font-size: 28px; + font-size: 20px; font-weight: 600; margin-left: 12px; color: #ffffff; diff --git a/src/router/index.ts b/src/router/index.ts index c597776629f16..fd16e16f3b4cb 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -12,9 +12,10 @@ import token from '@/router/token'; import env from '@/router/env'; import notification from '@/router/notification'; import plugin from '@/router/plugin'; -import misc from '@/router/misc'; import ds from '@/router/ds'; import environment from '@/router/environment'; +import system from '@/router/system'; +import misc from '@/router/misc'; import {initRouterAuth} from '@/router/hooks/auth'; import {initRouterStats} from '@/router/hooks/stats'; import {ROUTER_ROOT_NAME_ROOT} from '@/constants/router'; @@ -43,6 +44,7 @@ export function getDefaultRoutes(): Array { ...misc, ...ds, ...environment, + ...system, ], }, ]; @@ -72,7 +74,7 @@ export function getDefaultSidebarMenuItems(): MenuItem[] { }, {path: '/notifications', title: 'router.menuItems.notification', icon: ['fa', 'envelope']}, {path: '/environments', title: 'router.menuItems.environment', icon: ['fa', 'percent']}, - // {path: '/plugins', title: 'router.menuItems.plugins', icon: ['fa', 'plug']}, + {path: '/system', title: 'router.menuItems.system', icon: ['fa', 'cogs']}, ]; } diff --git a/src/router/system.ts b/src/router/system.ts new file mode 100644 index 0000000000000..aecbb5373386a --- /dev/null +++ b/src/router/system.ts @@ -0,0 +1,11 @@ +import {RouteRecordRaw} from 'vue-router'; + +const endpoint = 'system'; + +export default [ + { + name: 'SystemDetail', + path: endpoint, + component: () => import('@/views/system/detail/SystemDetail.vue'), + }, +] as Array; diff --git a/src/store/index.ts b/src/store/index.ts index 566364bce6a7f..9d7a29ccefb65 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -16,6 +16,7 @@ import git from '@/store/modules/git'; import notification from '@/store/modules/notification'; import ds from '@/store/modules/ds'; import environment from '@/store/modules/environment'; +import system from '@/store/modules/system'; let _store: Store; @@ -39,6 +40,7 @@ export const createStore = (): Store => { notification, ds, environment, + system, }, }); }; diff --git a/src/store/modules/layout.ts b/src/store/modules/layout.ts index 1b25291475f47..225b561ee0ea7 100644 --- a/src/store/modules/layout.ts +++ b/src/store/modules/layout.ts @@ -52,6 +52,7 @@ export default { if ([ '/notifications', '/environments', + '/system', ].includes(d.path) && rootState.common.systemInfo?.edition !== 'global.edition.pro') { return false; } diff --git a/src/store/modules/system.ts b/src/store/modules/system.ts new file mode 100644 index 0000000000000..d52abdf78f049 --- /dev/null +++ b/src/store/modules/system.ts @@ -0,0 +1,30 @@ +import useRequest from "@/services/request"; + +const { + get, + put, +} = useRequest(); + +export default { + namespaced: true, + state: { + siteTitle: {}, + }, + getters: {}, + mutations: { + setSiteTitle(state, siteTitle) { + state.siteTitle = {...siteTitle}; + } + }, + actions: { + getSiteTitle: async ({state}: StoreActionContext) => { + const res = await get('/settings/site_title'); + state.siteTitle = res.data; + console.debug(state.siteTitle); + }, + saveSiteTitle: async ({state}: StoreActionContext) => { + console.debug(state.siteTitle); + await put('/settings/site_title', state.siteTitle); + }, + } +} as SystemStoreModule; diff --git a/src/views/system/detail/SystemDetail.vue b/src/views/system/detail/SystemDetail.vue new file mode 100644 index 0000000000000..f0225fcafd56a --- /dev/null +++ b/src/views/system/detail/SystemDetail.vue @@ -0,0 +1,76 @@ + + + + +