| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 | <template>  <view id="serveConfig">    <view class="top">      <u-icon name="arrow-left" size="17px" color="#000" :bold="true" @click="navigateTo"></u-icon>    </view>    <view class="content">      <text class="title">设置服务器地址</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 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 style="margin-bottom: 15px" v-model="port" type="number" placeholder="端口号(非必填)" border="none" maxlength="5" clearable> </u-input>      <u-input v-model="content" placeholder="备注(非必填)" border="none" maxlength="20" 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>  </view></template><script setup>import config from "@/config";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 publicStores = publicStore();const { proxy } = getCurrentInstance();const dataList = reactive({  linkUrl: "", //链接地址  port: "",  content: "",});const uForm = ref(null);const { linkUrl, port, content } = 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("扫码结束");    },  });}/** * @保存 * @按钮点击事件 */function handleSubmit() {  if (!linkUrl.value) {    proxy.$modal.msg("请输入链接地址");    return;  }  if (!/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}(?:\.[a-zA-Z0-9]{2,})+$/.test(linkUrl.value)) {    proxy.$modal.msg("请输入正确的链接地址");    return;  }  // if (!port.value) {  //   proxy.$modal.msg("请输入端口号");  //   return;  // }  if (!port.value) {    uni.setStorageSync("serveUrl", linkUrl.value);    publicStores.getServeList(linkUrl.value, content.value);  } else {    uni.setStorageSync("serveUrl", linkUrl.value + ":" + port.value);    publicStores.getServeList(linkUrl.value + ":" + port.value, content.value);  }  config.baseUrl = "http://" + uni.getStorageSync("serveUrl") + "/prod-api";  navigateTo();}/** * @跳转登录 */function navigateTo() {  proxy.$tab.redirectTo("/pages/serveConfigSelect");}onLoad((options) => {});</script><style>page {  background-color: #ffffff;}</style><style lang="scss" scoped>#serveConfig {  position: relative;  z-index: 1;  width: 100%;  padding: 0 40px;  margin: auto;  padding-top: 20%;  .top {  }  .content {    display: flex;    margin: 30px 0;    .title {      margin: auto auto auto 0;      color: #000;      font-size: 18px;    }    .icons {      margin: auto 5px auto 0;    }    .setting {      color: #2a98ff;      margin: auto 0;    }  }  .bottom {    :deep(.u-input) {      height: 45px;      border-radius: 8px;      padding: 5px 12px !important;      border: 0 !important;      //   border-color: #000 !important;      //   border-color: gray !important;      //   background-color: rgba(255, 255, 255, 0.1) !important;      background-color: #f5f6fa !important;    }    :deep(.input-placeholder) {      color: #a0a4af;    }    :deep(.uni-input-wrapper) {      font-size: 16px;    }    :deep(.u-input__content__field-wrapper__field) {      height: 30px;      line-height: 30px;    }    :deep(.uni-input-input) {      // padding:8px    }    :deep(.u-line) {      display: none !important;    }  }}</style>
 |