Przeglądaj źródła

新增扫码识别服务器配置功能

fanghuisheng 2 lat temu
rodzic
commit
874de12489

+ 0 - 20
src/components/export.vue

@@ -1,20 +0,0 @@
-<template>
-	<view>
-		
-	</view>
-</template>
-
-<script>
-	export default {
-		name:"export",
-		data() {
-			return {
-				
-			};
-		}
-	}
-</script>
-
-<style>
-
-</style>

+ 38 - 0
src/components/pages-harder/index.vue

@@ -0,0 +1,38 @@
+<template>
+  <view :style="{ paddingTop: statusBarHeight + 'px' }"></view>
+  <view v-if="navbarShow" style="margin-bottom: 44px">
+    <u-navbar leftText="返回" :title="navbar_title" :safeAreaInsetTop="true">
+      <template #left>
+        <view class="u-nav-slot" style="display: flex">
+          <u-icon name="arrow-left" size="19"></u-icon>
+          <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
+          <u-icon name="home" size="20"></u-icon>
+        </view>
+      </template>
+    </u-navbar>
+  </view>
+</template>
+<script setup>
+import { onReady, onLoad, onShow, onNavigationBarButtonTap } from "@dcloudio/uni-app";
+import { ref, onMounted, inject, shallowRef, reactive, getCurrentInstance } from "vue";
+
+const props = defineProps({
+  navbarShow: {
+    type: Boolean,
+    default: false,
+  },
+  navbarTitle: {
+    type: String,
+    default: "",
+  },
+});
+
+const navbar_title = ref(props.navbarTitle);
+const navbar_show = ref(props.navbarShow);
+const statusBarHeight = ref(0);
+
+onLoad((option) => {
+  let systemInfo = uni.getSystemInfoSync();
+  statusBarHeight.value = systemInfo.statusBarHeight; //获取刘海屏高度
+});
+</script>

+ 9 - 1
src/config.js

@@ -1,7 +1,15 @@
 // 应用全局配置
 export default {
   // baseUrl: 'https://vue.ruoyi.vip/prod-api',
-   baseUrl: import.meta.env.MODE=== "production" ? "http://mobile.usky.cn:8099/prod-api" : "http://172.16.120.165:13200/prod-api",
+
+  //#ifdef H5
+  baseUrl: import.meta.env.MODE === "production" ? "http://mobile.usky.cn:8099/prod-api" : "http://172.16.120.165:13200/prod-api",
+  //#endif
+
+  //#ifdef APP-PLUS
+  baseUrl: "http://" + uni.getStorageSync("serveUrl") + "/prod-api",
+  //#endif
+
   // baseUrl: "http://mobile.usky.cn:8099/prod-api",
   websiteUrl: "https://qhome.usky.cn",
   // NODE_ENV=devlopment

+ 26 - 24
src/pages/index.vue

@@ -1,8 +1,10 @@
 <template>
   <!-- <u-sticky bgColor="#fff"> </u-sticky> -->
 
+  <!-- <pagesHarder></pagesHarder> -->
+
   <scroll-view scroll-x>
-    <view>
+    <view style="margin-bottom:50px">
       <!-- 下拉选择 -->
       <!-- <view class="searchSelect shadow" v-if="flag">
         <view class="cu-bar search bg-white">
@@ -124,7 +126,7 @@
             <!-- <view class="cu-tag badge" v-if="item.badge != 0">
               <block v-if="item.badge != 0">{{ item.badge > 99 ? "99+" : item.badge }}</block>
             </view> -->
-            <text style="font-size: 13px">{{ item.meta.title }}</text>
+            <text style="font-size: 12px">{{ item.meta.title }}</text>
           </view>
         </view>
       </view>
@@ -139,7 +141,7 @@
             <!-- <view class="cu-tag badge" v-if="item.badge != 0">
               <block v-if="item.badge != 0">{{ item.badge > 99 ? "99+" : item.badge }}</block>
             </view> -->
-            <text style="font-size: 13px">{{ item.meta.title }}</text>
+            <text style="font-size: 12px">{{ item.meta.title }}</text>
           </view>
         </view>
       </view>
@@ -150,13 +152,13 @@
 
 <script setup>
 import searchSelect from "@/components/searchSelect/searchSelect.vue";
+import pagesHarder from "@/components/pages-harder/index.vue";
 
 import json from "@/static/js/json.js"; //引入api请求封装方法
 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, setToken, removeToken } from "@/utils/auth";
 import useStores from "@/store/modules/user.js";
 import publicStore from "@/store/modules/public";
 
@@ -458,31 +460,31 @@ onNavigationBarButtonTap((e) => {
 .static-tabs {
   border-radius: 50rpx;
   border: 1rpx solid #4074e7;
-}
 
-.static-tabs > view {
-  color: #4074e7;
-  font-size: 30rpx;
-}
+  > view {
+    color: #4074e7;
+    font-size: 30rpx;
+  }
 
-.static-tabs > view.active {
-  color: #fff;
-  background: #4074e7;
-}
+  > view.active {
+    color: #fff;
+    background: #4074e7;
+  }
 
-.static-tabs > view:first-child {
-  border-top-left-radius: 50rpx;
-  border-bottom-left-radius: 50rpx;
-}
+  > view:first-child {
+    border-top-left-radius: 50rpx;
+    border-bottom-left-radius: 50rpx;
+  }
 
-.static-tabs > view:nth-child(2) {
-  border-left: 1px solid #4074e7;
-  border-right: 1px solid #4074e7;
-}
+  > view:nth-child(2) {
+    border-left: 1px solid #4074e7;
+    border-right: 1px solid #4074e7;
+  }
 
-.static-tabs > view:last-child {
-  border-top-right-radius: 50rpx;
-  border-bottom-right-radius: 50rpx;
+  > view:last-child {
+    border-top-right-radius: 50rpx;
+    border-bottom-right-radius: 50rpx;
+  }
 }
 
 /* 检测时间 */

+ 19 - 11
src/pages/login.vue

@@ -19,7 +19,7 @@
         <text class="title">请登录</text>
 
         <!-- #ifdef APP-PLUS -->
-        <view id="okay">首次账号登录请先配置服务器</view>
+        <view id="okay" v-if="!linkUrl">首次账号登录请先配置服务器</view>
         <!-- <u-icon class="icons" name="scan" color="gray" size="22"></u-icon> -->
         <view class="setting" @tap="goSeverConfig"> 配置服务器 </view>
         <!--#endif-->
@@ -62,7 +62,7 @@
 
 <script setup>
 import { onLoad, onShow, onHide, onLaunch } from "@dcloudio/uni-app";
-import { reactive, getCurrentInstance, toRefs, inject } from "vue";
+import { reactive, getCurrentInstance, toRefs, inject, watchEffect } from "vue";
 import { getToken, setToken, removeToken } from "@/utils/auth";
 import { Lock, User, Cellphone } from "@element-plus/icons-vue";
 import { getCodeImg, getMobileTenantConfig } from "@/api/login";
@@ -90,11 +90,13 @@ const data = reactive({
   username: undefined,
   password: undefined,
   inputIconBool: true,
+  /** 服务器配置数据 */
+  linkUrl: uni.getStorageSync("serveUrl"),
 
   // VerificationCodeOne
 });
 
-const { title, bg, bottomTitle, logo, phone, verify, codeTime, switchText, username, password, tenantId, inputIconBool } = toRefs(data);
+const { title, bg, bottomTitle, logo, phone, verify, codeTime, switchText, username, password, tenantId, inputIconBool, linkUrl } = toRefs(data);
 
 function goSeverConfig() {
   uni.navigateTo({
@@ -158,22 +160,18 @@ function env() {
   // }
 
   //#ifdef H5
-  var linkUrl = window.location.host;
+  linkUrl.value = window.location.host;
   // var linkUrl='ces.cn';
   // var linkUrl='172.16.120.165:13203'
   //#endif
 
-  //#ifdef APP-PLUS
-  var linkUrl = newPublicStore.serveUrl;
-  //#endif
+  getMobileTenantConfigApi({ url: linkUrl.value });
 
   //  uni.showToast({
   //   title: '服务器链接地址为'+linkUrl,
   //   icon: "none",
   // })
 
-  getMobileTenantConfigApi({ url: linkUrl });
-
   //  let port = uni.getSystemInfoSync().platform;
   // switch (port) {
   //   case "android":
@@ -196,8 +194,7 @@ function env() {
 /** 点击提交按钮 */
 async function submitRes() {
   //#ifdef APP-PLUS
-  var linkUrl = newPublicStore.serveUrl;
-  if (!newPublicStore.serveUrl) {
+  if (!uni.getStorageSync("serveUrl")) {
     proxy.$modal.msg("首次登录请先进行服务器配置");
     return;
   }
@@ -271,6 +268,15 @@ async function getMobileTenantConfigApi(params) {
   });
 }
 
+watchEffect(() => {
+  //#ifdef APP-PLUS
+  if (uni.getStorageSync("serveUrl")) {
+    linkUrl.value = uni.getStorageSync("serveUrl");
+    getMobileTenantConfigApi({ url: linkUrl.value });
+  }
+  //#endif
+});
+
 /**
  * @onLoad
  */
@@ -383,6 +389,8 @@ page {
 
       :deep(uni-image) {
         height: 40px;
+        // width:40px;
+        width: auto;
       }
       .logo {
         margin-right: 10px;

+ 51 - 9
src/pages/serveConfig.vue

@@ -6,12 +6,14 @@
 
     <view class="content">
       <text class="title">设置服务器地址</text>
-      <!-- <u-icon class="icons" name="scan" color="#2a98ff" size="22"></u-icon>
-      <text class="setting" @tap="goSeverConfig"> 扫码添加 </text> -->
+      <u-icon class="icons" name="scan" color="#2a98ff" size="22"></u-icon>
+      <text class="setting" @tap="scanClick"> 扫码添加 </text>
     </view>
 
     <view class="bottom">
-      <u-input v-model="linkUrl" placeholder="服务器地址(必填)" border="none" clearable> </u-input>
+      <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-button type="primary" style="width: 100%; height: 45px; font-size: 17px; margin-top: 20px" @click="handleSubmit()" shape="circle"> 保 存</u-button>
     </view>
@@ -21,6 +23,7 @@
 <script setup>
 import { onLoad, onShow, onHide, onLaunch } from "@dcloudio/uni-app";
 import { ref, onMounted, inject, shallowRef, reactive, toRefs, getCurrentInstance } from "vue";
+import { getToken, setToken, removeToken } from "@/utils/auth";
 import publicStore from "@/store/modules/public.js";
 const newPublicStore = publicStore();
 
@@ -28,10 +31,44 @@ const { proxy } = getCurrentInstance();
 
 const dataList = reactive({
   linkUrl: "", //链接地址
+  port: "",
 });
 
 const uForm = ref(null);
-const { linkUrl } = toRefs(dataList);
+const { linkUrl, port } = toRefs(dataList);
+
+/**
+ * @扫一扫
+ * @按钮点击事件
+ */
+function scanClick() {
+  uni.scanCode({
+    success: async (e) => {
+      uni.showToast({
+        title: "扫码成功",
+        icon: "none",
+      });
+
+      linkUrl.value = e.result.split(":")[0];
+
+      port.value = e.result.split(":")[1];
+    },
+    fail: (err) => {
+      uni.showToast({
+        title: "扫码失败",
+        icon: "none",
+      });
+      console.log("扫码失败", err);
+    },
+    complete: () => {
+      // uni.showToast({
+      //   title: "扫码结束",
+      //   icon: "none",
+      // });
+      console.log("扫码结束");
+    },
+  });
+}
 
 /**
  * @提交
@@ -43,19 +80,23 @@ function handleSubmit() {
     return;
   }
 
-  if (!/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/.test(linkUrl.value)) {
+  if (!/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z0-9]{2,})+$/.test(linkUrl.value)) {
     proxy.$modal.msg("请输入正确的链接地址");
     return;
   }
 
-  newPublicStore.serveUrl = linkUrl.value;
+  if (!port.value) {
+    proxy.$modal.msg("请输入端口号");
+    return;
+  }
+
+  uni.setStorageSync("serveUrl", linkUrl.value + ":" + port.value);
   navigateTo();
 }
 
 /**
  * @跳转登录
  */
-
 function navigateTo() {
   uni.navigateTo({
     url: "/pages/login",
@@ -63,8 +104,9 @@ function navigateTo() {
 }
 
 onLoad((options) => {
-  if (newPublicStore.serveUrl) {
-    linkUrl.value = newPublicStore.serveUrl;
+  if (uni.getStorageSync("serveUrl")) {
+    linkUrl.value = uni.getStorageSync("serveUrl").split(":")[0];
+    port.value = uni.getStorageSync("serveUrl").split(":")[1];
   }
 });
 </script>

+ 12 - 10
src/store/modules/public.js

@@ -4,7 +4,7 @@ const publicStore = defineStore("public", {
   state: () => ({
     leftBtn: true, //左侧收起按钮
     rightBtn: true, //右侧收起按钮
-    serveUrl:null,//链接地址
+    serveUrl: null, //链接地址
 
     mapBool: 1, //1.高德 2.测绘院
     streetTownList: [
@@ -130,15 +130,17 @@ const publicStore = defineStore("public", {
   }),
   persist: {
     // 自定义数据持久化方式
-    // key: 'store-key', //指定key进行存储,此时非key的值不会持久化,刷新就会丢失
-    storage: window ? window.localStorage : uni.setStorageSync(), // 指定换成地址
-    // paths: ['nested.data'],// 指定需要持久化的state的路径名称
-    beforeRestore: (context) => {
-      console.log("Before" + context);
-    },
-    afterRestore: (context) => {
-      console.log("After" + context);
-    },
+    enabled: true,
+    // key: 'public-key', //指定key进行存储,此时非key的值不会持久化,刷新就会丢失
+    strategies: [
+      // 指定存储的位置以及存储的变量都有哪些,该属性可以不写,
+      //在不写的情况下,默认存储到 sessionStorage 里面,默认存储 state 里面的所有数据。
+      {
+        storage: window ? window.localStorage : uni.setStorageSync(),
+        // paths: ["count"]
+      },
+      // paths 是一个数组,如果写了 就会只存储 count 变量,当然也可以写多个。
+    ],
   },
   actions: {
     getDate() {

+ 9 - 0
src/utils/request.js

@@ -50,6 +50,15 @@ const request = (config) => {
           });
           modal.closeLoading();
           reject("无效的会话,或者会话已过期,请重新登录。");
+        } else if (code === 404 || res.statusCode === 404) {
+          if (res.data.msg.indexOf(":") !== -1) {
+            modal.msg(res.data.msg.split(":")[1]);
+            reject(res.data.msg.split(":")[1]);
+          } else {
+            modal.msg(res.data.msg);
+            reject(res.data.msg);
+          }
+          modal.closeLoading();
         } else if (code === 500 || res.statusCode === 500) {
           if (res.data.msg.indexOf(":") !== -1) {
             modal.msg(res.data.msg.split(":")[1]);