Browse Source

BUG修复/部分配置文件修改

fanghuisheng 2 years ago
parent
commit
a74804f1e5

+ 11 - 3
src/App.vue

@@ -3,7 +3,7 @@ import config from "./config";
 import store from "@/store";
 import { getToken } from "@/utils/auth";
 
-import { defineComponent, getCurrentInstance, inject, onMounted } from "vue";
+import { defineComponent, getCurrentInstance, inject, onMounted, watchEffect } from "vue";
 import { onLoad, onShow, onHide, onLaunch } from "@dcloudio/uni-app";
 
 let tab = inject("$tab");
@@ -24,10 +24,18 @@ function initConfig() {
 
 function checkLogin() {
   if (!getToken()) {
-    // proxy.$tab.reLaunch("/pages/login");
+    proxy.$tab.reLaunch("/pages/login");
   }
 }
 
+watchEffect(() => {
+  //#ifdef APP-PLUS
+  if (uni.getStorageSync("serveUrl")) {
+    config.baseUrl = "http://" + uni.getStorageSync("serveUrl") + "/prod-api";
+  }
+  //#endif
+});
+
 onShow(() => {
   console.log("App Show");
 });
@@ -39,7 +47,7 @@ onHide(() => {
 onLaunch(() => {
   console.log("App Launch");
   // #ifdef APP-PLUS
-  plus.screen.lockOrientation("portrait-primary");//设置不可横屏
+  plus.screen.lockOrientation("portrait-primary"); //设置不可横屏
   // #endif
   initApp();
 });

+ 16 - 27
src/pages.json

@@ -1,20 +1,5 @@
 {
   "pages": [
-    {
-      "path": "pages/login",
-      "style": {
-        "navigationBarTitleText": "登录",
-        "navigationStyle": "custom",
-        "navigationBarTextStyle": "black" // 仅支持 black/white
-      }
-    },
-    {
-      "path": "pages/serveConfig",
-      "style": {
-        "navigationBarTitleText": "服务器配置",
-        "navigationStyle": "custom"
-      }
-    },
     {
       "path": "pages/index",
       "style": {
@@ -42,6 +27,21 @@
         }
       }
     },
+    {
+      "path": "pages/login",
+      "style": {
+        "navigationBarTitleText": "登录",
+        "navigationStyle": "custom",
+        "navigationBarTextStyle": "black" // 仅支持 black/white
+      }
+    },
+    {
+      "path": "pages/serveConfig",
+      "style": {
+        "navigationBarTitleText": "服务器配置",
+        "navigationStyle": "custom"
+      }
+    },
     {
       "path": "pages/mine/index",
       "style": {
@@ -137,9 +137,7 @@
       }
     },
     //消防督察单模块 开始
-
     //消防督察单模块 结束
-
     //巡检模块 开始
     {
       "path": "pages/business/mhxf/xunJian/xunJian",
@@ -240,7 +238,6 @@
       }
     },
     //巡检模块 结束
-
     //信息查询 开始
     {
       "path": "pages/business/mhxf/informationSelect/index",
@@ -257,7 +254,6 @@
       }
     },
     //信息查询 结束
-
     //设备管理 开始
     {
       "path": "pages/business/mhxf/deviceManage/index",
@@ -267,7 +263,6 @@
       }
     },
     //设备管理 结束
-
     //协同作战地图 开始
     {
       "path": "pages/business/mhxf/coordination/index",
@@ -277,7 +272,6 @@
       }
     },
     //协同作战地图 结束
-
     //单位信息采集 开始
     {
       "path": "pages/business/mhxf/unitInfoCollection/index",
@@ -287,7 +281,6 @@
       }
     },
     //单位信息采集 结束
-
     //消防报告 开始
     {
       "path": "pages/business/mhxf/fireReport/index",
@@ -311,7 +304,6 @@
       }
     },
     //消防报告 结束
-
     //待办事项 开始
     {
       "path": "pages/business/mhxf/needMatter/index",
@@ -321,7 +313,6 @@
       }
     },
     //待办事项 结束
-
     //消息 开始
     {
       "path": "pages/info/info",
@@ -352,7 +343,6 @@
       }
     },
     //消息 结束
-
     //分析 开始
     {
       "path": "pages/analyse/analyse",
@@ -361,7 +351,6 @@
       }
     },
     //分析 结束
-
     //设置 开始
     {
       "path": "pages/setting/setting",
@@ -450,4 +439,4 @@
       }
     ]
   }
-}
+}

+ 1 - 1
src/pages/common/webview/index.vue

@@ -1,6 +1,6 @@
 <template>
   <view v-if="params.url">
-    <web-view :webview-styles="webviewStyles" :src="`${params.url}`"></web-view>
+    <web-view :webview-styles="webviewStyles" :src="`${params.url}`" allow></web-view>
   </view>
 </template>
 

+ 9 - 4
src/pages/index.vue

@@ -171,6 +171,7 @@ import * as jwx from "@/utils/jssdk.js"; //引入js sdk的封装
 
 import { onReady, onLoad, onShow, onNavigationBarButtonTap } from "@dcloudio/uni-app";
 import { ref, onMounted, inject, shallowRef, reactive, getCurrentInstance } from "vue";
+import { getToken } from "@/utils/auth";
 import useStores from "@/store/modules/user.js";
 import publicStore from "@/store/modules/public";
 
@@ -232,7 +233,7 @@ function swiperChange(e) {
  * @轮播图点击事件
  */
 function swiperClick(list) {
-  if (list instanceof Object) {
+  if (typeof list == "object") {
     let linkType = arrayList.swiperList[arrayList.swiperIndex].linkType;
     let url = arrayList.swiperList[arrayList.swiperIndex].link;
 
@@ -274,9 +275,9 @@ function getMobileBannerApi() {
 
 onLoad((option) => {
   //获取首页标题
-  if (uni.getStorageSync("homeTitle")) {
+  if (useStore.$state.loginTitle) {
     uni.setNavigationBarTitle({
-      title: uni.getStorageSync("homeTitle"),
+      title: useStore.$state.loginTitle,
     });
   } else {
     uni.setNavigationBarTitle({
@@ -284,6 +285,10 @@ onLoad((option) => {
     });
   }
 
+  console.log(useStore.$state.tenantId)
+
+  console.log(useStore.$state.name)
+
   if (uni.getStorageSync(useStore.$state.name)) {
     arrayList.recentlyUsed = uni.getStorageSync(useStore.$state.name);
   }
@@ -324,7 +329,7 @@ function scanCode() {
       qrCodeSend({
         qrCode: list.uid,
         tenantId: useStore.$state.tenantId,
-        userName: useStore.$state.userName,
+        userName: useStore.$state.name,
       }).then((res) => {});
     },
     fail: (err) => {

+ 28 - 66
src/pages/login.vue

@@ -3,15 +3,15 @@
     <!-- <u-loading-page :loading="true" loading-text="loading..."  loading-mode="spinner"></u-loading-page> -->
 
     <view class="bg">
-      <image class="bgImage" :src="bg" v-if="bg" />
+      <image class="bgImage" :src="useStore.$state.loginBg" v-if="useStore.$state.loginBg" />
       <!-- <image class="bgImage" src="@/static/images/wt/bg.png" v-else /> -->
     </view>
 
     <view class="middle">
       <view class="top">
-        <image class="logo" mode="heightFix" :src="logo" v-if="logo" />
+        <image class="logo" mode="heightFix" :src="useStore.$state.loginLogo" v-if="useStore.$state.loginLogo" />
         <image class="logo" mode="heightFix" src="@/static/logo200.png" v-else />
-        <text class="title" v-if="title">{{ title }}</text>
+        <text class="title" v-if="useStore.$state.loginTitle">{{ useStore.$state.loginTitle }}</text>
         <text class="title" v-else>移动端登录</text>
       </view>
 
@@ -67,16 +67,16 @@
       <!--#endif-->
     </view>
     <view class="bottom">
-      <div class="title">{{ bottomTitle }}</div>
+      <div class="title">{{ useStore.$state.loginBottomTitle }}</div>
     </view>
   </view>
 </template>
 
 <script setup>
 import { onLoad, onShow, onHide, onLaunch, onReady } from "@dcloudio/uni-app";
-import { reactive, getCurrentInstance, toRefs, inject, watchEffect } from "vue";
+import { reactive, getCurrentInstance, toRefs, inject } from "vue";
 import { getToken, setToken, removeToken } from "@/utils/auth";
-import { getCodeImg, getMobileTenantConfig } from "@/api/login";
+import { getCodeImg } from "@/api/login";
 
 import publicStore from "@/store/modules/public.js";
 
@@ -87,17 +87,11 @@ const newPublicStore = publicStore();
 const { proxy } = getCurrentInstance();
 
 const data = reactive({
-  /** saas数据 */
-  bg: "",
-  logo: "",
-  title: "",
-  bottomTitle: "",
   /** login数据 */
   phone: undefined,
   verify: undefined,
   codeTime: 0,
   switchText: "验证码登录",
-  tenantId: undefined,
   username: undefined,
   password: undefined,
   inputIconBool: true,
@@ -109,7 +103,7 @@ const data = reactive({
   // VerificationCodeOne
 });
 
-const { title, bg, bottomTitle, logo, phone, verify, codeTime, switchText, username, password, tenantId, inputIconBool, linkUrl, userChecked } = toRefs(data);
+const { phone, verify, codeTime, switchText, username, password, inputIconBool, linkUrl, userChecked } = toRefs(data);
 
 function goSeverConfig() {
   proxy.$tab.navigateTo("/pages/serveConfig");
@@ -174,6 +168,14 @@ function getVerifyCode() {
  * 判断运行环境
  */
 function env() {
+  useStore.SET_LOGINMOBILELIST({
+    loginTitle: "",
+    loginBottomTitle: "",
+    loginBg: "",
+    loginLogo: "",
+    tenantId: "",
+  });
+
   // const u = navigator.userAgent
   // //https://blog.csdn.net/weixin_42659644/article/details/126294231
   // if(u.indexOf('saas')>-1){ //指定app内 获取app识别号
@@ -182,16 +184,8 @@ function env() {
 
   //  let port = uni.getSystemInfoSync().platform;
   // switch (port) {
-  //   case "android":
-  //     getMobileTenantConfigApi({ url: window.location.host });
-  //     console.log("Android"); //android
-  //     break;
-  //   case "ios":
-  //     console.log("iOS"); //ios
-  //     getMobileTenantConfigApi({ url: window.location.host });
-  //     break;
   //   case "windows":
-  //     getMobileTenantConfigApi({ url: window.location.host });
+  //     useStore.GetMobileTenantConfig({ url: window.location.host });
   //     break;
   //   default: //devtools
   //     console.log("小程序");
@@ -199,17 +193,19 @@ function env() {
   // }
 
   //#ifdef H5
-  linkUrl.value = window.location.host;
-  // linkUrl.value = window.location.host;
-  // linkUrl.value='ces.cn';
-  // linkUrl.value='172.16.120.165:13203'
-  getMobileTenantConfigApi({ url: linkUrl.value });
+  if (window.location.host) {
+    linkUrl.value = window.location.host;
+    // linkUrl.value = window.location.host;
+    // linkUrl.value='ces.cn';
+    // linkUrl.value='172.16.120.165:13203'
+    useStore.GetMobileTenantConfig({ url: linkUrl.value });
+  }
   //#endif
 
   //#ifdef APP-PLUS
   if (uni.getStorageSync("serveUrl")) {
     linkUrl.value = uni.getStorageSync("serveUrl");
-    getMobileTenantConfigApi({ url: linkUrl.value });
+    useStore.GetMobileTenantConfig({ url: linkUrl.value });
   }
   //#endif
 }
@@ -246,7 +242,7 @@ function submitRes() {
     login({
       phone: phone.value,
       verify: verify.value,
-      tenantId: tenantId.value,
+      tenantId: useStore.$state.tenantId,
     });
   } else {
     if (!username.value) {
@@ -261,7 +257,7 @@ function submitRes() {
     login({
       username: username.value,
       password: password.value,
-      tenantId: tenantId.value,
+      tenantId: useStore.$state.tenantId,
     });
   }
 }
@@ -279,23 +275,6 @@ function login(data) {
   });
 }
 
-/** 获取登录页数据 */
-function getMobileTenantConfigApi(params) {
-  getMobileTenantConfig(params).then((res) => {
-    if (res.data.length > 0) {
-      let data = res.data[0];
-      title.value = data.loginTitle;
-      bottomTitle.value = data.loginFooter;
-      tenantId.value = data.tenantId;
-      bg.value = data.loginBackUrl;
-      logo.value = data.loginLogo;
-      uni.setStorageSync("homeTitle", data.loginTitle);
-
-      useStore.$state.tenantId = data.tenantId;
-    }
-  });
-}
-
 // 用户协议
 function handleUserAgrement() {
   let site = getApp().globalData.config.appInfo.agreements[0];
@@ -307,28 +286,11 @@ function handlePrivacy() {
   proxy.$tab.navigateTo(`/pages/common/textview/index1?title=${site.title}&content=${site.content}`);
 }
 
-watchEffect(() => {
-  //#ifdef APP-PLUS
-  if (uni.getStorageSync("serveUrl")) {
-    linkUrl.value = uni.getStorageSync("serveUrl");
-    getMobileTenantConfigApi({ url: linkUrl.value });
-  }
-  //#endif
-});
-
 /**
  * @onLoad
  */
 onLoad(() => {
   env();
-
-  const token = getToken();
-  //需要登录
-  if (token) {
-    uni.switchTab({
-      url: "/pages/index",
-    });
-  }
 });
 
 // onReady(() => {
@@ -536,12 +498,12 @@ page {
   }
 
   .bottom {
-    position: absolute;
+    position: fixed;
     width: 100%;
     bottom: 10px;
     .title {
       text-align: center;
-      color: #000;
+      color: #96a6b5;
       font-size: 14px;
     }
   }

+ 11 - 4
src/pages/serveConfig.vue

@@ -13,7 +13,9 @@
     <view class="bottom">
       <u-input style="margin-bottom: 15px" v-model="linkUrl" placeholder="服务器地址(必填)" border="none" clearable> </u-input>
 
-      <u-input v-model="port" type="number" placeholder="端口号(必填)" border="none" maxlength="5" clearable> </u-input>
+      <!-- <u-input v-model="port" type="number" placeholder="端口号(必填)" border="none" maxlength="5" clearable> </u-input> -->
+
+      <u-input v-model="port" type="number" placeholder="端口号(非必填)" border="none" maxlength="5" clearable> </u-input>
 
       <u-button type="primary" style="width: 100%; height: 45px; font-size: 17px; margin-top: 20px" @click="handleSubmit()" shape="circle"> 保 存</u-button>
     </view>
@@ -86,12 +88,17 @@ function handleSubmit() {
     return;
   }
 
+  // if (!port.value) {
+  //   proxy.$modal.msg("请输入端口号");
+  //   return;
+  // }
+
   if (!port.value) {
-    proxy.$modal.msg("请输入端口号");
-    return;
+    uni.setStorageSync("serveUrl", linkUrl.value);
+  } else {
+    uni.setStorageSync("serveUrl", linkUrl.value + ":" + port.value);
   }
 
-  uni.setStorageSync("serveUrl", linkUrl.value + ":" + port.value);
   config.baseUrl = "http://" + uni.getStorageSync("serveUrl") + "/prod-api";
   navigateTo();
 }

+ 1 - 1
src/pages/setting/setting.vue

@@ -3,7 +3,7 @@
     <view class="top-banner justify-center align-center text-center">
       <view>
         <image width="130" src="@/static/images/setting/personal-head.png"></image>
-        <view class="userName">{{ useStores.$state.userName }}</view>
+        <view class="userName">{{ useStores.$state.name }}</view>
         <!-- <view>上海永天科技股份有限公司</view> -->
       </view>
     </view>

+ 1 - 1
src/permission.js

@@ -34,4 +34,4 @@ list.forEach((item) => {
       console.log(err);
     },
   });
-});
+});

+ 51 - 9
src/store/modules/user.js

@@ -1,6 +1,6 @@
 import storage from "@/utils/storage";
 import constant from "@/utils/constant";
-import { login, logout, getInfo } from "@/api/login";
+import { login, logout, getInfo, getMobileTenantConfig } from "@/api/login";
 import { getToken, setToken, removeToken } from "@/utils/auth";
 import { defineStore } from "pinia";
 import modal from "@/plugins/modal.js";
@@ -8,12 +8,16 @@ import modal from "@/plugins/modal.js";
 const useStores = defineStore("useStores", {
   state: () => ({
     token: getToken(),
-    name: storage.get(constant.name),
+    name: storage.get(constant.name),//用户名称
     avatar: storage.get(constant.avatar),
     roles: storage.get(constant.roles),
     permissions: storage.get(constant.permissions),
-    userName: "",
-    tenantId:"",
+
+    loginTitle: storage.get(constant.loginTitle),
+    loginBottomTitle: storage.get(constant.loginFooter),
+    loginBg: storage.get(constant.loginBackUrl),
+    loginLogo: storage.get(constant.loginLogo),
+    tenantId: storage.get(constant.tenantId),
   }),
   persist: {
     // 自定义数据持久化方式
@@ -34,8 +38,8 @@ const useStores = defineStore("useStores", {
       return new Promise((resolve, reject) => {
         login(data)
           .then((res) => {
+            this.SET_TOKEN(res.data.access_token)
             setToken(res.data.access_token);
-            this.token = res.data.access_token;
             resolve();
           })
           .catch((error) => {
@@ -46,16 +50,29 @@ const useStores = defineStore("useStores", {
       });
     },
 
+    //获取登录页数据
+    GetMobileTenantConfig(params) {
+      getMobileTenantConfig(params).then((res) => {
+        if (res.data.length > 0) {
+          let data = res.data[0];
+          this.SET_LOGINMOBILELIST({
+            loginTitle: data.loginTitle,
+            loginBottomTitle: data.loginFooter,
+            loginBg: data.loginBackUrl,
+            loginLogo: data.loginLogo,
+            tenantId: data.tenantId,
+          })
+        }
+      });
+    },
+
     // 获取用户信息
     GetInfo() {
       return new Promise((resolve, reject) => {
         getInfo()
           .then((res) => {
-            console.log(res.data);
             var data = res.data;
 
-            this.userName = data.user.userName;
-
             if (data.roles && data.roles.length > 0) {
               this.SET_ROLES(data.roles);
               this.SET_PERMISSIONS(data.permissions);
@@ -79,9 +96,16 @@ const useStores = defineStore("useStores", {
       return new Promise((resolve, reject) => {
         logout()
           .then(() => {
-            this.SET_TOKEN("");
+            this.SET_TOKEN("");//清空token
             this.SET_ROLES([]);
             this.SET_PERMISSIONS([]);
+            this.SET_LOGINMOBILELIST({
+              loginTitle: "",
+              loginBottomTitle: "",
+              loginBg: "",
+              loginLogo: "",
+              tenantId: "",
+            });//清空登录页数据
             removeToken();
             storage.clean();
             resolve();
@@ -112,6 +136,24 @@ const useStores = defineStore("useStores", {
       this.permissions = permissions;
       storage.set(constant.permissions, permissions);
     },
+
+    SET_LOGINMOBILELIST(loginMobileList) {
+      //title
+      this.loginTitle = loginMobileList.loginTitle
+      storage.set(constant.loginTitle, loginMobileList.loginTitle);
+      //bottomTitle
+      this.loginBottomTitle = loginMobileList.loginBottomTitle
+      storage.set(constant.loginBottomTitle, loginMobileList.loginBottomTitle);
+      //bg
+      this.loginBg = loginMobileList.loginBg
+      storage.set(constant.loginBg, loginMobileList.loginBg);
+      //logo
+      this.loginLogo = loginMobileList.loginLogo
+      storage.set(constant.loginLogo, loginMobileList.loginLogo);
+      //tenantId
+      this.tenantId = loginMobileList.tenantId
+      storage.set(constant.tenantId, loginMobileList.tenantId);
+    }
   },
 });
 

+ 12 - 6
src/utils/constant.js

@@ -1,8 +1,14 @@
 const constant = {
-   avatar: 'vuex_avatar',
-   name: 'vuex_name',
-   roles: 'vuex_roles',
-   permissions: 'vuex_permissions'
- }
+  avatar: 'vuex_avatar',
+  name: 'vuex_name',
+  roles: 'vuex_roles',
+  permissions: 'vuex_permissions',
 
- export default constant
+  loginTitle: 'vuex_loginTitle',
+  loginBottomTitle: 'vuex_loginBottomTitle',
+  loginBg: 'vuex_loginBg',
+  loginLogo: 'vuex_loginLogo',
+  tenantId: 'vuex_tenantId', 
+}
+
+export default constant

+ 5 - 5
src/utils/storage.js

@@ -4,13 +4,13 @@ import constant from './constant'
 let storageKey = 'storage_data'
 
 // 存储节点变量名
-let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions]
+let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions, constant.loginTitle, constant.loginBottomTitle, constant.loginBg, constant.loginLogo, constant.tenantId]
 
 // 存储的数据
 let storageData = uni.getStorageSync(storageKey) || {}
 
 const storage = {
-  set: function(key, value) {
+  set: function (key, value) {
     if (storageNodeKeys.indexOf(key) != -1) {
       let tmp = uni.getStorageSync(storageKey)
       tmp = tmp ? tmp : {}
@@ -18,14 +18,14 @@ const storage = {
       uni.setStorageSync(storageKey, tmp)
     }
   },
-  get: function(key) {
+  get: function (key) {
     return storageData[key] || ""
   },
-  remove: function(key) {
+  remove: function (key) {
     delete storageData[key]
     uni.setStorageSync(storageKey, storageData)
   },
-  clean: function() {
+  clean: function () {
     uni.removeStorageSync(storageKey)
   }
 }