serveConfigSelect.vue 5.3 KB

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