Kaynağa Gözat

feat:获取门户logo

liuyuedi 2 yıl önce
ebeveyn
işleme
01bcd4e22f

+ 8 - 2
src/api/portal/portal.js

@@ -5,8 +5,8 @@ const baseURL = process.env.VUE_APP_BASE_API;
 
 // 获取portal配置
 export async function getSsoInfo() {
-  let res = await axios({ method: 'get', url: baseURL + '/portal/cfg/cfg' });
-  let cfg =
+  const res = await axios({ method: 'get', url: baseURL + '/portal/cfg/cfg' });
+  const cfg =
     res.status === 200 &&
     res.data &&
     res.data.code === '000000' &&
@@ -21,3 +21,9 @@ export function fetchSSOConfigInfo() {
     method: 'get'
   });
 }
+export function getPortalImg() {
+  return request({
+    url: '/portalprod-api/system/theme/info',
+    method: 'get'
+  });
+}

+ 7 - 4
src/layout/components/Sidebar/Logo.vue

@@ -51,6 +51,7 @@
 <script>
 import logoImg from '@/assets/images/logo.png';
 import variables from '@/assets/styles/variables.scss';
+import { mapState } from 'vuex';
 
 export default {
   name: 'SidebarLogo',
@@ -61,6 +62,11 @@ export default {
     }
   },
   computed: {
+    ...mapState({
+      logo: function (state) {
+        return this.formatImg(state.settings.logo) || logoImg;
+      }
+    }),
     variables() {
       return variables;
     },
@@ -72,10 +78,7 @@ export default {
     }
   },
   data() {
-    return {
-      // title: '水价改革管理系统',
-      logo: logoImg
-    };
+    return {};
   }
 };
 </script>

+ 1 - 0
src/permission.js

@@ -26,6 +26,7 @@ router.beforeEach(async (to, from, next) => {
   }
 
   if (token) {
+    store.dispatch('settings/getPortalSystemInfo');
     to.meta.title && store.dispatch('settings/setTitle', to.meta.title);
     /* has token*/
     if (to.path === '/login') {

+ 14 - 0
src/store/modules/settings.js

@@ -1,4 +1,5 @@
 import defaultSettings from '@/settings';
+import { getPortalImg } from '@/api/portal/portal';
 
 const {
   sideTheme,
@@ -14,6 +15,7 @@ const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || '';
 const state = {
   title: '',
   theme: storageSetting.theme || '#14A478',
+  logo: '',
   sideTheme: storageSetting.sideTheme || sideTheme,
   showSettings: showSettings,
   topNav: storageSetting.topNav === undefined ? topNav : storageSetting.topNav,
@@ -48,6 +50,18 @@ const actions = {
   // 设置网页标题
   setTitle({ commit }, title) {
     state.title = title;
+    getPortalSystemInfo(context) {
+      const { commit, state } = context;
+      if (state.logo) {
+        return Promise.resolve(state.logo);
+      }
+  
+      return getPortalImg().then((res) => {
+        commit('CHANGE_SETTING', { key: 'logo', value: res.data.logoUrl });
+  
+        return res.data;
+      });
+    }
   }
 };
 

+ 7 - 1
src/utils/request.js

@@ -6,7 +6,7 @@ import errorCode from '@/utils/errorCode';
 import { tansParams, blobValidate } from '@/utils/ruoyi';
 import cache from '@/plugins/cache';
 import { saveAs } from 'file-saver';
-
+const whitePrefixUrlList = ['/iot', '/portalprod-api'];
 let downloadLoadingInstance;
 // 是否显示重新登录
 export const isRelogin = { show: false };
@@ -23,6 +23,12 @@ const service = axios.create({
 // request拦截器
 service.interceptors.request.use(
   (config) => {
+    const isHideBaseUrl =
+      whitePrefixUrlList.findIndex((item) => config.url.includes(item)) > -1;
+
+    if (isHideBaseUrl) {
+      config.baseURL = '';
+    }
     if (config.url.includes('/iot')) {
       config.baseURL = '';
     }

+ 9 - 1
vue.config.js

@@ -62,7 +62,15 @@ module.exports = {
         pathRewrite: {
           // ['^' + process.env.VUE_APP_BASE_API]: ''
         }
-      }
+      },
+      ['/portalprod-api']: {
+        // target: `http://192.168.1.95:7000`,
+        target: `http://192.168.1.221:7000`,
+        // target: `http://114.55.0.7:7000`,
+        changeOrigin: true,
+        pathRewrite: {
+          // ['^' + process.env.VUE_APP_BASE_API]: ''
+        }
     },
     disableHostCheck: true
   },