Browse Source

项目名动态配置

wangwei 3 years ago
parent
commit
dfee3ea757

+ 2 - 2
.env

@@ -2,7 +2,7 @@
 VITE_PORT = 3200
 
 # spa-title
-VITE_GLOB_APP_TITLE = admin
+VITE_GLOB_APP_TITLE = pyadmin
 
 # spa shortname
-VITE_GLOB_APP_SHORT_NAME = vue_vben_admin_2x
+VITE_GLOB_APP_SHORT_NAME = pyadmin

+ 3 - 1
src/App.vue

@@ -10,7 +10,7 @@
   import { defineComponent } from 'vue';
   import { ConfigProvider } from 'ant-design-vue';
   import { AppProvider } from '/@/components/Application';
-
+  import { useAppStore } from '/@/store/modules/app';
   import { useTitle } from '/@/hooks/web/useTitle';
   import { useLocale } from '/@/locales/useLocale';
 
@@ -18,7 +18,9 @@
     name: 'App',
     components: { ConfigProvider, AppProvider },
     setup() {
+      const appStore = useAppStore();
       useTitle();
+      appStore.setAppInfoAction();
 
       // support Multi-language
       const { getAntdLocale } = useLocale();

+ 7 - 1
src/api/sys/model/generalModel.ts

@@ -2,7 +2,13 @@
  * @description: Get common information return value
  */
 export interface CommonRowModel {
-  rows: object[];
+  row: {
+    basic: any;
+    dictionary: object;
+    email: object;
+    example: object;
+    user: object;
+  };
 }
 
 /**

+ 1 - 1
src/api/sys/upload.ts

@@ -3,7 +3,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { UploadFileParams } from '/@/utils/http/axios/types';
 import { useGlobSetting } from '/@/hooks/setting';
 
-const { uploadUrl = '', urlPrefix } = useGlobSetting();
+const { /*uploadUrl = '', */ urlPrefix } = useGlobSetting();
 
 enum Api {
   uploadUrl = '/general/file',

+ 8 - 3
src/components/Application/src/AppLogo.vue

@@ -12,11 +12,12 @@
 </template>
 <script lang="ts">
   import { defineComponent, computed, unref } from 'vue';
-  import { useGlobSetting } from '/@/hooks/setting';
+  // import { useGlobSetting } from '/@/hooks/setting';
   import { useGo } from '/@/hooks/web/usePage';
   import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
   import { useDesign } from '/@/hooks/web/useDesign';
   import { PageEnum } from '/@/enums/pageEnum';
+  import { useAppStore } from '/@/store/modules/app';
 
   const props = {
     /**
@@ -37,10 +38,13 @@
     name: 'AppLogo',
     props: props,
     setup(props) {
+      const appStore = useAppStore();
       const { prefixCls } = useDesign('app-logo');
       const { getCollapsedShowTitle } = useMenuSetting();
-      const { title } = useGlobSetting();
+      // const { title } = useGlobSetting();
       const go = useGo();
+      const title = computed(() => appStore.getAppTitle);
+      const getAppLogo = computed(() => appStore.getAppLogo);
 
       const getAppLogoClass = computed(() => [
         prefixCls,
@@ -56,10 +60,11 @@
       ]);
 
       function goHome() {
-        go(PageEnum.BASE_HOME);
+        go(PageEnum.BASE_HOME); // 初始化加载页面
       }
 
       return {
+        getAppLogo,
         getAppLogoClass,
         getTitleClass,
         getCollapsedShowTitle,

+ 1 - 1
src/enums/pageEnum.ts

@@ -2,7 +2,7 @@ export enum PageEnum {
   // basic login path
   BASE_LOGIN = '/login',
   // basic home path
-  BASE_HOME = '/dashboard',
+  BASE_HOME = '/admin',
   // error page path
   ERROR_PAGE = '/exception',
   // error log page path

+ 7 - 3
src/hooks/web/useTitle.ts

@@ -1,13 +1,17 @@
 import { watch, unref } from 'vue';
 import { useI18n } from '/@/hooks/web/useI18n';
 import { useTitle as usePageTitle } from '@vueuse/core';
-import { useGlobSetting } from '/@/hooks/setting';
+// import { useGlobSetting } from '/@/hooks/setting';
+import { useAppStore } from '/@/store/modules/app';
 import { useRouter } from 'vue-router';
+import { computed } from 'vue';
 
 import { REDIRECT_NAME } from '/@/router/constant';
 
 export function useTitle() {
-  const { title } = useGlobSetting();
+  const appStore = useAppStore();
+  const title = computed(() => appStore.getAppTitle);
+  // const { title } = useGlobSetting();
   const { t } = useI18n();
   const { currentRoute } = useRouter();
 
@@ -22,7 +26,7 @@ export function useTitle() {
       }
 
       const tTitle = t(route?.meta?.title as string);
-      pageTitle.value = tTitle ? ` ${tTitle} - ${title} ` : `${title}`;
+      pageTitle.value = tTitle ? ` ${tTitle} - ${title.value} ` : `${title.value}`;
     },
     { immediate: true }
   );

+ 5 - 2
src/layouts/default/sider/MixSider.vue

@@ -92,10 +92,11 @@
 
   import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
   import { useDragLine } from './useLayoutSider';
-  import { useGlobSetting } from '/@/hooks/setting';
+  // import { useGlobSetting } from '/@/hooks/setting';
   import { useDesign } from '/@/hooks/web/useDesign';
   import { useI18n } from '/@/hooks/web/useI18n';
   import { useGo } from '/@/hooks/web/usePage';
+  import { useAppStore } from '/@/store/modules/app';
 
   import { SIDE_BAR_SHOW_TIT_MINI_WIDTH, SIDE_BAR_MINI_WIDTH } from '/@/enums/appEnum';
 
@@ -143,7 +144,9 @@
         getCollapsed,
       } = useMenuSetting();
 
-      const { title } = useGlobSetting();
+      //const { title } = useGlobSetting();
+      const appStore = useAppStore();
+      const title = computed(() => appStore.getAppTitle);
 
       useDragLine(sideRef, dragBarRef, true);
 

+ 23 - 0
src/store/modules/app.ts

@@ -10,6 +10,7 @@ import { Persistent } from '/@/utils/cache/persistent';
 import { darkMode } from '/@/settings/designSetting';
 import { resetRouter } from '/@/router';
 import { deepMerge } from '/@/utils';
+import { getConfigInfo } from '/@/api/sys/general';
 
 interface AppState {
   darkMode?: ThemeEnum;
@@ -19,6 +20,8 @@ interface AppState {
   projectConfig: ProjectConfig | null;
   // When the window shrinks, remember some states, and restore these states when the window is restored
   beforeMiniInfo: BeforeMiniState;
+  appTitle: string;
+  appLogo: string;
 }
 let timeId: TimeoutHandle;
 export const useAppStore = defineStore({
@@ -28,11 +31,19 @@ export const useAppStore = defineStore({
     pageLoading: false,
     projectConfig: Persistent.getLocal(PROJ_CFG_KEY),
     beforeMiniInfo: {},
+    appTitle: 'admin',
+    appLogo: '',
   }),
   getters: {
     getPageLoading() {
       return this.pageLoading;
     },
+    getAppTitle() {
+      return this.appTitle;
+    },
+    getAppLogo() {
+      return this.appLogo;
+    },
     getDarkMode(): 'light' | 'dark' | string {
       return this.darkMode || localStorage.getItem(APP_DARK_MODE_KEY_) || darkMode;
     },
@@ -62,6 +73,12 @@ export const useAppStore = defineStore({
     setPageLoading(loading: boolean): void {
       this.pageLoading = loading;
     },
+    setAppTitle(appTitle: string) {
+      this.appTitle = appTitle;
+    },
+    setAppLogo(appLogo: string) {
+      this.appLogo = appLogo;
+    },
 
     setDarkMode(mode: ThemeEnum): void {
       this.darkMode = mode;
@@ -93,6 +110,12 @@ export const useAppStore = defineStore({
         clearTimeout(timeId);
       }
     },
+    async setAppInfoAction() {
+      const res = await getConfigInfo();
+      const config = res.row.basic.list;
+      this.setAppTitle(config[0].value);
+      this.setAppLogo(config[1].value);
+    },
   },
 });
 

+ 1 - 31
src/store/modules/permission.ts

@@ -121,37 +121,7 @@ export const usePermissionStore = defineStore({
         try {
           // this.changePermissionCode();
           routeList = await getMenuList(); //请求后端路由菜单数组
-          // 默认路由
-          // const dashboard = {
-          //   path: '/dashboard',
-          //   name: 'Dashboard',
-          //   component: 'LAYOUT',
-          //   redirect: '/dashboard/analysis',
-          //   meta: {
-          //     icon: 'ion:grid-outline',
-          //     title: 'routes.dashboard.dashboard',
-          //   },
-          //   children: [
-          //     {
-          //       path: 'analysis',
-          //       name: 'Analysis',
-          //       component: '/dashboard/analysis/index',
-          //       meta: {
-          //         affix: true,
-          //         title: 'routes.dashboard.analysis',
-          //       },
-          //     },
-          //     {
-          //       path: 'workbench',
-          //       name: 'Workbench',
-          //       component: '/dashboard/workbench/index',
-          //       meta: {
-          //         title: 'routes.dashboard.workbench',
-          //       },
-          //     },
-          //   ],
-          // };
-          // routeList.unshift(dashboard);
+          //可添加默认路由
         } catch (error) {
           console.error(error);
         }

+ 1 - 1
src/utils/http/axios/index.ts

@@ -155,7 +155,7 @@ const transform: AxiosTransform = {
           content: t('sys.api.networkExceptionMsg'),
         });
       }
-    } catch (error) {
+    } catch (error: any) {
       throw new Error(error);
     }
     checkStatus(error?.response?.status, msg);

+ 0 - 2
src/views/general/config/data.ts

@@ -147,9 +147,7 @@ export const columns: BasicColumn[] = [
           const onArrayChange = (val) => {
             console.log(`父组件获取到的参数 =======》`, val);
             record.value = val;
-            record.value.b = 123456;
           };
-          console.log('-----------return ??????------------');
           return h(ArrayCom, {
             value: record.value,
             // options: record.content,

+ 3 - 2
src/views/general/config/index.vue

@@ -53,6 +53,7 @@
   import { useI18n } from '/@/hooks/web/useI18n';
   import { adapt } from '/@/utils/adapt';
   import { validateType } from '/@/utils/validTools';
+  import { useAppStore } from '/@/store/modules/app';
   import {
     BasicTable,
     useTable,
@@ -76,6 +77,7 @@
     setup() {
       const { t } = useI18n();
       const { createMessage } = useMessage();
+      const appStore = useAppStore();
       const { success /*, error */ } = createMessage;
       const tableHeight = adapt().tableHeight;
       const state = reactive({
@@ -127,6 +129,7 @@
       // 处理请求数据
       function afterFetch(result) {
         result = result[state.group].list;
+        appStore.setAppTitle(result[0].value);
         return result;
       }
       getGroupList();
@@ -147,7 +150,6 @@
         state.tableShow = true;
         state.formShow = false;
         state.current_index = i;
-        console.log(`state.current_index`, state.current_index);
         await nextTick();
         getTableAction().reload();
         state.group = group.toLowerCase();
@@ -163,7 +165,6 @@
       }
 
       async function handleTableSubmit() {
-        console.log('==========handleTableSubmit=========');
         const data = getTableAction().getDataSource();
         let flag = true;
         data.map((item) => {

+ 1 - 0
src/views/home/user/index.vue

@@ -45,6 +45,7 @@
   import { useMessage } from '/@/hooks/web/useMessage';
   import { getMyInfo, editMyInfo } from '/@/api/sys/user';
   import { useUserStore } from '/@/store/modules/user';
+
   export default defineComponent({
     name: 'User',
     components: {},

+ 1 - 1
src/views/sys/login/LoginForm.vue

@@ -159,7 +159,7 @@
               duration: 3,
             });
           }
-        } catch (error) {
+        } catch (error: any) {
           createErrorModal({
             title: t('sys.api.errorTip'),
             content: error.message || t('sys.api.networkExceptionMsg'),