Sfoglia il codice sorgente

系统配置基本完成

Huanyi 2 settimane fa
parent
commit
a02e3edee8

+ 2 - 2
.env.development

@@ -1,6 +1,6 @@
 # 页面标题
-VITE_APP_TITLE = 商户后台
-VITE_APP_LOGO_TITLE = 商户后台
+VITE_APP_TITLE = ''
+VITE_APP_LOGO_TITLE = ''
 
 # 开发环境配置
 VITE_APP_ENV = 'development'

+ 2 - 2
.env.production

@@ -1,6 +1,6 @@
 # 页面标题
-VITE_APP_TITLE = 商户后台
-VITE_APP_LOGO_TITLE = 商户后台
+VITE_APP_TITLE = ''
+VITE_APP_LOGO_TITLE = ''
 
 # 生产环境配置
 VITE_APP_ENV = 'production'

+ 1 - 1
index.html

@@ -7,7 +7,7 @@
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
 <!--    <link rel="icon" href="/favicon.ico" />-->
     <link rel="icon" href="/?" />
-    <title>%VITE_APP_TITLE%</title>
+    <title></title>
     <!--[if lt IE 11
       ]><script>
         window.location.href = '/html/ie.html';

+ 14 - 0
src/api/system/websiteSetting/index.ts

@@ -0,0 +1,14 @@
+import request from '@/utils/request';
+import { WebsiteSettingVO } from './types';
+
+/**
+ * 获取网站设置详情
+ * @param id 网站设置 ID
+ * @returns 网站设置详情
+ */
+export function getWebsiteSetting(id: number | string) {
+  return request<WebsiteSettingVO>({
+    url: `/system/websiteSetting/${id}`,
+    method: 'get'
+  });
+}

+ 26 - 0
src/api/system/websiteSetting/types.ts

@@ -0,0 +1,26 @@
+/** 
+ * 网站设置相关的接口类型定义
+ */
+
+export interface WebsiteSettingVO {
+  /** 主键 ID */
+  id: number;
+  /** 网站图标 ID */
+  icon: number;
+  /** 网站图标 URL */
+  iconUrl: string;
+  /** 网站标题 */
+  title: string;
+  /** 登录页标题 */
+  loginTitle: string;
+  /** 登录页背景 ID */
+  loginBackground: number;
+  /** 登录页背景 URL */
+  loginBackgroundUrl: string;
+  /** 侧边栏菜单标题 */
+  menuTitle: string;
+}
+
+export interface WebsiteSettingQuery extends PageQuery {
+  // 可以根据需要添加查询参数
+}

+ 1 - 1
src/components/CustomerDetailDrawer/index.vue

@@ -126,7 +126,7 @@ import { listAllChangeLog } from '@/api/archieves/changeLog';
 import { listAreaStation } from '@/api/system/areaStation';
 import { listSubOrderOnCustomer } from '@/api/order/subOrder/index';
 import { listAllService } from '@/api/service/list/index';
-import changeLogMap from '@/enums/changeLog.json';
+import changeLogMap from '@/json/changeLog.json';
 
 const props = defineProps({
   visible: {

+ 1 - 1
src/components/PetDetailDrawer/index.vue

@@ -122,7 +122,7 @@ import { listAllChangeLog } from '@/api/archieves/changeLog'
 import { listSubOrderOnPet } from '@/api/order/subOrder/index'
 import { listAllService } from '@/api/service/list/index'
 import { ElMessage } from 'element-plus'
-import changeLogMap from '@/enums/changeLog.json'
+import changeLogMap from '@/json/changeLog.json'
 
 const props = defineProps({
   visible: {

+ 0 - 0
src/enums/changeLog.json → src/json/changeLog.json


+ 1 - 1
src/enums/fulfiller.json → src/json/fulfiller.json

@@ -89,4 +89,4 @@
       "tagType": "info"
     }
   }
-}
+}

+ 6 - 2
src/layout/components/Sidebar/Logo.vue

@@ -23,9 +23,12 @@
 
 <script setup lang="ts">
 import variables from '@/assets/styles/variables.module.scss';
-import logo from '@/assets/logo/logo.png';
+import defaultLogo from '@/assets/logo/logo.png';
 import { useSettingsStore } from '@/store/modules/settings';
+import { useWebsiteStore } from '@/store/modules/website';
+
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
+const websiteStore = useWebsiteStore();
 
 defineProps({
   collapse: {
@@ -34,7 +37,8 @@ defineProps({
   }
 });
 
-const title = import.meta.env.VITE_APP_LOGO_TITLE;
+const title = computed(() => websiteStore.websiteConfig.menuTitle || import.meta.env.VITE_APP_LOGO_TITLE);
+const logo = computed(() => websiteStore.websiteConfig.iconUrl || defaultLogo);
 const settingsStore = useSettingsStore();
 const sideTheme = computed(() => settingsStore.sideTheme);
 </script>

+ 12 - 3
src/main.ts

@@ -57,7 +57,16 @@ app.use(plugins);
 // 自定义指令
 directive(app);
 
-app.mount('#app');
+// 在挂载前获取网站配置数据,确保一开始就按库渲染
+import { useWebsiteStore } from '@/store/modules/website';
+const websiteStore = useWebsiteStore();
 
-// 初始化开发者工具保护(仅生产环境)
-initDevToolsProtection();
+// 提前执行获取配置任务
+const initWebsite = async () => {
+    await websiteStore.getWebsiteConfig();
+    app.mount('#app');
+    // 初始化开发者工具保护(仅生产环境)
+    initDevToolsProtection();
+};
+
+initWebsite();

+ 59 - 0
src/store/modules/website.ts

@@ -0,0 +1,59 @@
+import { defineStore } from 'pinia';
+import { getWebsiteSetting } from '@/api/system/websiteSetting';
+import { WebsiteSettingVO } from '@/api/system/websiteSetting/types';
+
+/**
+ * 网站全局配置设置
+ */
+export const useWebsiteStore = defineStore('website', () => {
+  const websiteConfig = ref<WebsiteSettingVO>({
+    id: 0,
+    icon: 0,
+    iconUrl: '',
+    title: '',
+    loginTitle: '',
+    loginBackground: 0,
+    loginBackgroundUrl: '',
+    menuTitle: ''
+  });
+
+  /**
+   * 获取网站设置详情
+   */
+  const getWebsiteConfig = async () => {
+    try {
+      const res = await getWebsiteSetting(2);
+      if (res && res.data) {
+        websiteConfig.value = res.data;
+        // 更新网站标题和图标
+        updatePageBranding();
+      }
+    } catch (error) {
+      console.error('获取网站设置失败:', error);
+    }
+  };
+
+  /**
+   * 更新页面的标题和 favicon 图标
+   */
+  const updatePageBranding = () => {
+    if (websiteConfig.value.title) {
+      document.title = websiteConfig.value.title;
+    }
+    if (websiteConfig.value.iconUrl) {
+      let iconLink = document.querySelector('link[rel~="icon"]') as HTMLLinkElement;
+      if (!iconLink) {
+        iconLink = document.createElement('link');
+        iconLink.rel = 'icon';
+        document.getElementsByTagName('head')[0].appendChild(iconLink);
+      }
+      iconLink.href = websiteConfig.value.iconUrl;
+    }
+  };
+
+  return {
+    websiteConfig,
+    getWebsiteConfig,
+    updatePageBranding
+  };
+});

+ 5 - 2
src/utils/dynamicTitle.ts

@@ -1,14 +1,17 @@
 import defaultSettings from '@/settings';
 import { useSettingsStore } from '@/store/modules/settings';
+import { useWebsiteStore } from '@/store/modules/website';
 
 /**
  * 动态修改标题
  */
 export const useDynamicTitle = () => {
   const settingsStore = useSettingsStore();
+  const websiteStore = useWebsiteStore();
+  const systemTitle = websiteStore.websiteConfig.title || import.meta.env.VITE_APP_TITLE;
   if (settingsStore.dynamicTitle) {
-    document.title = settingsStore.title + ' - ' + import.meta.env.VITE_APP_TITLE;
+    document.title = settingsStore.title + ' - ' + systemTitle;
   } else {
-    document.title = defaultSettings.title as string;
+    document.title = systemTitle;
   }
 };

+ 15 - 2
src/views/login.vue

@@ -1,5 +1,5 @@
 <template>
-  <div class="login">
+  <div class="login" :style="loginBackgroundStyle">
     <el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">
       <div class="title-box">
         <h3 class="title">{{ title }}</h3>
@@ -82,6 +82,7 @@
 import { getCodeImg, getTenantList } from '@/api/login';
 import { authRouterUrl } from '@/api/system/social/auth';
 import { useUserStore } from '@/store/modules/user';
+import { useWebsiteStore } from '@/store/modules/website';
 import { LoginData, TenantVO } from '@/api/types';
 import { to } from 'await-to-js';
 import { HttpStatus } from '@/enums/RespEnum';
@@ -89,11 +90,23 @@ import { useI18n } from 'vue-i18n';
 
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 
-const title = import.meta.env.VITE_APP_TITLE;
+const websiteStore = useWebsiteStore();
+const title = computed(() => websiteStore.websiteConfig.loginTitle || import.meta.env.VITE_APP_TITLE);
 const userStore = useUserStore();
 const router = useRouter();
 const { t } = useI18n();
 
+const loginBackgroundStyle = computed(() => {
+  const url = websiteStore.websiteConfig.loginBackgroundUrl;
+  if (url) {
+    return {
+      backgroundImage: `url(${url})`,
+      backgroundSize: 'cover'
+    };
+  }
+  return {};
+});
+
 const loginForm = ref<LoginData>({
   platformId: 1,
   tenantId: '000000',

+ 2 - 2
vite.config.ts

@@ -24,8 +24,8 @@ export default defineConfig(({ mode, command }) => {
       // open: true,
       proxy: {
         [env.VITE_APP_BASE_API]: {
-          // target: 'http://127.0.0.1:8080',
-          target: 'http://www.hoomeng.pet/api',
+          target: 'http://127.0.0.1:8080',
+          // target: 'http://www.hoomeng.pet/api',
           changeOrigin: true,
           ws: true,
           rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')