serveConfigSelect.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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" @tap="serveClick(1)"></u-icon>
  9. <text class="setting" @click="serveClick(2)"> 添加 </text>
  10. </view>
  11. <view class="bottom">
  12. <div class="serveList">
  13. <u-radio-group v-model="radiovalue" placement="column" @change="handleRadio">
  14. <div style="display: flex; background-color: #f5f6fa !important; margin-bottom: 15px; padding: 10px; border-radius: 8px" v-for="(item, index) in radiolist" :key="index">
  15. <u-radio :customStyle="{ margin: 'auto 0' }" :value="item.id" :name="item.id"></u-radio>
  16. <div style="margin: auto 0 auto 0; width: 100%" @click="handleRadio(item.id)">
  17. <div style="margin-bottom: 5px; font-weight: 600">{{ item.linkUrl }}</div>
  18. <div style="color: #a0a4af; font-size: 12px">备注:{{ item.content }}</div>
  19. </div>
  20. <div v-if="item.id != radiovalue" style="margin: auto 0 auto 0; height: 100%" @click="deleteRadio(index)">
  21. <u-icon name="close" color="#a0a4af" size="14"></u-icon>
  22. </div>
  23. </div>
  24. </u-radio-group>
  25. </div>
  26. <u-button v-if="radiolist.length > 0" type="primary" style="width: 100%; height: 45px; font-size: 17px; margin-top: 20px" @click="handleSubmit()" shape="circle"> 保 存</u-button>
  27. </view>
  28. </view>
  29. </template>
  30. <script setup>
  31. import config from "@/config";
  32. import { onLoad, onShow, onHide, onLaunch } from "@dcloudio/uni-app";
  33. import { ref, onMounted, inject, shallowRef, reactive, toRefs, getCurrentInstance, watchEffect } from "vue";
  34. import { getToken, setToken, removeToken } from "@/utils/auth";
  35. import { publicStores, useStores } from "@/store/modules/index";
  36. const publicStore = publicStores();
  37. const { proxy } = getCurrentInstance();
  38. const dataList = reactive({
  39. radiolist: [],
  40. radiovalue: "",
  41. });
  42. const uForm = ref(null);
  43. const { radiolist, radiovalue } = toRefs(dataList);
  44. /**
  45. * @切换单选
  46. * @按钮点击事件
  47. */
  48. function handleRadio(id) {
  49. radiovalue.value = id;
  50. let serveList = uni.getStorageSync("serveList");
  51. serveList[0].radiovalue = radiovalue.value;
  52. uni.setStorageSync("serveList", serveList);
  53. }
  54. /**
  55. * @删除
  56. * @按钮点击事件
  57. */
  58. function deleteRadio(index) {
  59. let serveList = uni.getStorageSync("serveList");
  60. serveList[0].radiolist.splice(index, 1);
  61. uni.setStorageSync("serveList", serveList);
  62. init();
  63. proxy.$tab.redirectTo("/pages/serveConfigSelect"); //重载当前页
  64. }
  65. /**
  66. * @扫一扫
  67. * @按钮点击事件
  68. */
  69. function serveClick(type) {
  70. if (type == 1) {
  71. uni.scanCode({
  72. success: async (e) => {
  73. uni.showToast({
  74. title: "扫码成功",
  75. icon: "none",
  76. });
  77. publicStore.getServeList(e.result, "");
  78. init();
  79. proxy.$tab.redirectTo("/pages/serveConfigSelect"); //重载当前页
  80. },
  81. fail: (err) => {
  82. uni.showToast({
  83. title: "扫码失败",
  84. icon: "none",
  85. });
  86. console.log("扫码失败", err);
  87. },
  88. complete: () => {
  89. // uni.showToast({
  90. // title: "扫码结束",
  91. // icon: "none",
  92. // });
  93. console.log("扫码结束");
  94. },
  95. });
  96. } else if (type == 2) {
  97. proxy.$tab.navigateTo("/pages/serveConfig");
  98. }
  99. }
  100. /**
  101. * @保存
  102. * @按钮点击事件
  103. */
  104. function handleSubmit() {
  105. let serveList = uni.getStorageSync("serveList");
  106. if (serveList.length > 0) {
  107. serveList[0].radiolist.forEach((el) => {
  108. if (el.id == serveList[0].radiovalue) {
  109. uni.setStorageSync("serveUrl", el.linkUrl);
  110. config.baseUrl = "http://" + uni.getStorageSync("serveUrl") + "/prod-api";
  111. navigateTo();
  112. }
  113. });
  114. }
  115. }
  116. /**
  117. * @跳转登录
  118. */
  119. function navigateTo() {
  120. proxy.$tab.navigateBack(1);
  121. }
  122. /**
  123. * @初始化
  124. */
  125. function init() {
  126. let serveList = uni.getStorageSync("serveList");
  127. if (serveList.length > 0) {
  128. radiolist.value = serveList[0].radiolist;
  129. radiovalue.value = serveList[0].radiovalue;
  130. }
  131. }
  132. onShow(() => {
  133. init();
  134. });
  135. onLoad((options) => {});
  136. </script>
  137. <style lang="scss" scoped>
  138. #serveConfig {
  139. position: fixed;
  140. top: 0;
  141. left: 0;
  142. right: 0;
  143. bottom: 0;
  144. z-index: 1;
  145. width: 100%;
  146. height: 100vh;
  147. padding: 0 40px;
  148. margin: auto;
  149. padding-top: 20%;
  150. background-color: #ffffff;
  151. .top {
  152. }
  153. .content {
  154. display: flex;
  155. margin: 30px 0;
  156. .title {
  157. margin: auto auto auto 0;
  158. color: #000;
  159. font-size: 18px;
  160. }
  161. .icons {
  162. margin: auto 5px auto 0;
  163. }
  164. .setting {
  165. color: #2a98ff;
  166. margin: auto 0;
  167. }
  168. }
  169. .bottom {
  170. .serveList {
  171. max-height: calc(59px * 6);
  172. overflow: auto;
  173. }
  174. // .u-radio {
  175. // :deep(.u-radio__icon-wrap) {
  176. // background-color: transparent !important;
  177. // }
  178. // :deep(.u-icon) {
  179. // width: 8px;
  180. // height: 8px;
  181. // background-color: rgb(41, 121, 255);
  182. // border-radius: 100%;
  183. // }
  184. // :deep(.u-icon__icon) {
  185. // display: none;
  186. // }
  187. // }
  188. }
  189. }
  190. </style>