serveConfig.vue 4.6 KB

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