serveConfig.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view id="serveConfig">
  3. <view class="top">
  4. <u-icon name="arrow-left" size="17px" color="#000" :bold="true" @click="navigateTo"></u-icon>
  5. </view>
  6. <view class="content">
  7. <text class="title">设置服务器地址</text>
  8. <u-icon class="icons" name="scan" color="#2a98ff" size="22"></u-icon>
  9. <text class="setting" @tap="scanClick"> 扫码添加 </text>
  10. </view>
  11. <view class="bottom">
  12. <u-input style="margin-bottom: 15px" v-model="linkUrl" placeholder="服务器地址(必填)" border="none" clearable> </u-input>
  13. <!-- <u-input v-model="port" type="number" placeholder="端口号(必填)" border="none" maxlength="5" clearable> </u-input> -->
  14. <u-input style="margin-bottom: 15px" v-model="port" type="number" placeholder="端口号(非必填)" border="none" maxlength="5" clearable> </u-input>
  15. <u-input v-model="content" placeholder="备注(非必填)" border="none" maxlength="20" clearable> </u-input>
  16. <u-button type="primary" style="width: 100%; height: 45px; font-size: 17px; margin-top: 20px" @click="handleSubmit()" shape="circle"> 保 存</u-button>
  17. </view>
  18. </view>
  19. </template>
  20. <script setup>
  21. import config from "@/config";
  22. import { onLoad, onShow, onHide, onLaunch } from "@dcloudio/uni-app";
  23. import { ref, onMounted, inject, shallowRef, reactive, toRefs, getCurrentInstance } from "vue";
  24. import { getToken, setToken, removeToken } from "@/utils/auth";
  25. import publicStore from "@/store/modules/public.js";
  26. const publicStores = publicStore();
  27. const { proxy } = getCurrentInstance();
  28. const dataList = reactive({
  29. linkUrl: "", //链接地址
  30. port: "",
  31. content: "",
  32. });
  33. const uForm = ref(null);
  34. const { linkUrl, port, content } = toRefs(dataList);
  35. /**
  36. * @扫一扫
  37. * @按钮点击事件
  38. */
  39. function scanClick() {
  40. uni.scanCode({
  41. success: async (e) => {
  42. uni.showToast({
  43. title: "扫码成功",
  44. icon: "none",
  45. });
  46. linkUrl.value = e.result.split(":")[0];
  47. port.value = e.result.split(":")[1];
  48. },
  49. fail: (err) => {
  50. uni.showToast({
  51. title: "扫码失败",
  52. icon: "none",
  53. });
  54. console.log("扫码失败", err);
  55. },
  56. complete: () => {
  57. // uni.showToast({
  58. // title: "扫码结束",
  59. // icon: "none",
  60. // });
  61. console.log("扫码结束");
  62. },
  63. });
  64. }
  65. /**
  66. * @保存
  67. * @按钮点击事件
  68. */
  69. function handleSubmit() {
  70. if (!linkUrl.value) {
  71. proxy.$modal.msg("请输入链接地址");
  72. return;
  73. }
  74. if (!/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}(?:\.[a-zA-Z0-9]{2,})+$/.test(linkUrl.value)) {
  75. proxy.$modal.msg("请输入正确的链接地址");
  76. return;
  77. }
  78. // if (!port.value) {
  79. // proxy.$modal.msg("请输入端口号");
  80. // return;
  81. // }
  82. if (!port.value) {
  83. uni.setStorageSync("serveUrl", linkUrl.value);
  84. publicStores.getServeList(linkUrl.value, content.value);
  85. } else {
  86. uni.setStorageSync("serveUrl", linkUrl.value + ":" + port.value);
  87. publicStores.getServeList(linkUrl.value + ":" + port.value, content.value);
  88. }
  89. config.baseUrl = "http://" + uni.getStorageSync("serveUrl") + "/prod-api";
  90. navigateTo();
  91. }
  92. /**
  93. * @跳转登录
  94. */
  95. function navigateTo() {
  96. proxy.$tab.redirectTo("/pages/serveConfigSelect");
  97. }
  98. onLoad((options) => {});
  99. </script>
  100. <style>
  101. page {
  102. background-color: #ffffff;
  103. }
  104. </style>
  105. <style lang="scss" scoped>
  106. #serveConfig {
  107. position: relative;
  108. z-index: 1;
  109. width: 100%;
  110. padding: 0 40px;
  111. margin: auto;
  112. padding-top: 20%;
  113. .top {
  114. }
  115. .content {
  116. display: flex;
  117. margin: 30px 0;
  118. .title {
  119. margin: auto auto auto 0;
  120. color: #000;
  121. font-size: 18px;
  122. }
  123. .icons {
  124. margin: auto 5px auto 0;
  125. }
  126. .setting {
  127. color: #2a98ff;
  128. margin: auto 0;
  129. }
  130. }
  131. .bottom {
  132. :deep(.u-input) {
  133. height: 45px;
  134. border-radius: 8px;
  135. padding: 5px 12px !important;
  136. border: 0 !important;
  137. // border-color: #000 !important;
  138. // border-color: gray !important;
  139. // background-color: rgba(255, 255, 255, 0.1) !important;
  140. background-color: #f5f6fa !important;
  141. }
  142. :deep(.input-placeholder) {
  143. color: #a0a4af;
  144. }
  145. :deep(.uni-input-wrapper) {
  146. font-size: 16px;
  147. }
  148. :deep(.u-input__content__field-wrapper__field) {
  149. height: 30px;
  150. line-height: 30px;
  151. }
  152. :deep(.uni-input-input) {
  153. // padding:8px
  154. }
  155. :deep(.u-line) {
  156. display: none !important;
  157. }
  158. }
  159. }
  160. </style>