serveConfig.vue 4.6 KB

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