123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <template>
- <view id="serveConfigSelect-container">
- <view class="top-area">
- <u-icon name="arrow-left" size="17px" color="#000" :bold="true" @click="navigateTo()"></u-icon>
- </view>
- <view class="content-area">
- <text class="content-area-title">选择服务器地址</text>
- <u-icon class="content-area-icons" name="scan" color="#2a98ff" size="22" @tap="serveClick(1)"></u-icon>
- <text class="content-area-setting" @click="serveClick(2)"> 添加 </text>
- </view>
- <view class="bottom-area">
- <div class="serveList">
- <u-radio-group v-model="radiovalue" placement="column" @change="handleRadio">
- <div class="serveList-item" v-for="(item, index) in radiolist" :key="index">
- <u-radio :customStyle="{ margin: 'auto 0' }" :value="item.id" :name="item.id"></u-radio>
- <div class="serveList-item-center" @click="handleRadio(item.id)">
- <div class="serveList-item-center-title">{{ item.linkUrl }}</div>
- <div class="serveList-item-center-content">备注:{{ item.content }}</div>
- </div>
- <div v-if="item.id != radiovalue" class="serveList-item-icon" @click="deleteRadio(index)">
- <u-icon name="close" color="#a0a4af" size="14"></u-icon>
- </div>
- <div v-if="item.id == radiovalue" class="serveList-item-icon" @click="editRadio(index)">
- <u-icon name="arrow-right" color="#a0a4af" size="14"></u-icon>
- </div>
- </div>
- </u-radio-group>
- </div>
- <u-button
- v-if="radiolist.length > 0"
- type="primary"
- :customStyle="{
- display: 'block',
- width: '100%',
- height: '45px',
- lineHeight: '45px',
- fontSize: '17px',
- }"
- @click="handleSubmit()"
- shape="circle"
- >
- 保 存</u-button
- >
- </view>
- </view>
- </template>
- <script setup>
- import config from "@/config";
- import { onLoad, onShow, onHide, onLaunch } from "@dcloudio/uni-app";
- import { ref, onMounted, inject, shallowRef, reactive, toRefs, getCurrentInstance, watchEffect } from "vue";
- import { getToken, setToken, removeToken } from "@/utils/auth";
- import { useStores, commonStores } from "@/store/modules/index";
- const commonStore = commonStores();
- const { proxy } = getCurrentInstance();
- const dataList = reactive({
- radiolist: [],
- radiovalue: "",
- });
- const uForm = ref(null);
- const { radiolist, radiovalue } = toRefs(dataList);
- /**
- * @切换单选
- * @按钮点击事件
- */
- function handleRadio(id) {
- radiovalue.value = id;
- let serveList = uni.getStorageSync("serveList");
- serveList[0].radiovalue = radiovalue.value;
- uni.setStorageSync("serveList", serveList);
- }
- /**
- * @删除
- * @按钮点击事件
- */
- function deleteRadio(index) {
- let serveList = uni.getStorageSync("serveList");
- serveList[0].radiolist.splice(index, 1);
- uni.setStorageSync("serveList", serveList);
- init();
- proxy.$tab.redirectTo("/pages/serveConfigSelect"); //重载当前页
- }
- /**
- * @编辑
- * @按钮点击事件
- */
- function editRadio(index) {
- proxy.$tab.navigateTo("/pages/serveConfig?index=" + index);
- }
- /**
- * @扫一扫
- * @按钮点击事件
- */
- function serveClick(type) {
- if (type == 1) {
- uni.scanCode({
- autoZoom: false,
- success: async (e) => {
- uni.showToast({
- title: "扫码成功",
- icon: "none",
- });
- commonStore.setServeList(e.result, "");
- init();
- proxy.$tab.redirectTo("/pages/serveConfigSelect"); //重载当前页
- },
- fail: (err) => {
- uni.showToast({
- title: "扫码失败",
- icon: "none",
- });
- console.log("扫码失败", err);
- },
- complete: () => {
- // uni.showToast({
- // title: "扫码结束",
- // icon: "none",
- // });
- console.log("扫码结束");
- },
- });
- } else if (type == 2) {
- proxy.$tab.navigateTo("/pages/serveConfig");
- }
- }
- /**
- * @保存
- * @按钮点击事件
- */
- function handleSubmit() {
- let serveList = uni.getStorageSync("serveList");
- if (serveList.length > 0) {
- serveList[0].radiolist.forEach((el) => {
- if (el.id == serveList[0].radiovalue) {
- uni.setStorageSync("serveUrl", el.linkUrl);
- config.baseUrl = "http://" + uni.getStorageSync("serveUrl") + "/prod-api";
- navigateTo();
- }
- });
- }
- }
- /**
- * @跳转登录
- */
- function navigateTo() {
- proxy.$tab.navigateBack(1);
- }
- /**
- * @初始化
- */
- function init() {
- let serveList = uni.getStorageSync("serveList");
- if (serveList.length > 0) {
- radiolist.value = serveList[0].radiolist;
- radiovalue.value = serveList[0].radiovalue;
- }
- }
- onShow(() => {
- init();
- });
- onLoad((options) => {});
- </script>
- <style lang="scss" scoped>
- #serveConfigSelect-container {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 1;
- width: 100%;
- height: 100vh;
- margin: auto;
- padding: 0 30px;
- padding-top: 20%;
- //#ifdef MP-WEIXIN
- padding-top: 30%;
- //#endif
- background-color: #ffffff;
- .top-area {
- }
- .content-area {
- display: flex;
- margin: 30px 0;
- &-title {
- margin: auto auto auto 0;
- color: #000;
- font-size: 18px;
- }
- &-icons {
- margin: auto 5px auto 0;
- }
- &-setting {
- color: #2a98ff;
- margin: auto 0;
- }
- }
- .bottom-area {
- .serveList {
- max-height: calc(59px * 6);
- overflow: auto;
- &-item {
- display: flex;
- background-color: #f5f6fa !important;
- margin-bottom: 15px;
- padding: 10px;
- border-radius: 8px;
- &-center {
- margin: auto 0 auto 0;
- width: 100%;
- &-title {
- margin-bottom: 5px;
- font-weight: 600;
- }
- &-content {
- color: #a0a4af;
- font-size: 12px;
- }
- }
- &-icon {
- margin: auto 0 auto 0;
- height: 100%;
- }
- }
- }
- }
- }
- </style>
|