You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
3.9 KiB
173 lines
3.9 KiB
<template>
|
|
<view class="page">
|
|
<u-navbar back-text="服务器地址">
|
|
<view slot="right" style="margin-right: 16px">
|
|
<u-icon name="plus" size="50" color="#4E73DF" @click=" showModal = true " />
|
|
</view>
|
|
</u-navbar>
|
|
<u-swipe-action
|
|
v-for="(item, index) in serverList"
|
|
class="list"
|
|
:class="item.title===serverConfig ? 'blue' : ''"
|
|
:show="item.show"
|
|
:index="index"
|
|
:key="item.title"
|
|
:options="options"
|
|
@content-click="select(item.title)"
|
|
@click="click"
|
|
>
|
|
<view class="list-text">
|
|
{{item.title}}
|
|
<u-icon v-if="item.title===serverConfig" name="checkmark-circle" />
|
|
</view>
|
|
</u-swipe-action>
|
|
<u-popup v-model="showModal" mode="center" border-radius="14" @close="reset">
|
|
<view class="title">请输入服务器地址</view>
|
|
<u-field
|
|
v-model="value"
|
|
label-width="0"
|
|
placeholder="协议+IP地址+端口号"
|
|
:border-bottom="false"
|
|
:clearable="false"
|
|
:error-message="errorMessage"
|
|
/>
|
|
<view class="popupBottom">
|
|
<u-button size="medium" type="primary" shape="circle" plain @click=" showModal = false ">取消</u-button>
|
|
<u-button size="medium" type="primary" shape="circle" @click="add">确定</u-button>
|
|
</view>
|
|
</u-popup>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
showModal: false,
|
|
index: "",
|
|
value: "",
|
|
errorMessage: "",
|
|
serverConfig: uni.getStorageSync("serverConfig"),
|
|
serverList: uni.getStorageSync("serverList").map((item) => {
|
|
return { show: false, title: item };
|
|
}),
|
|
options: [
|
|
{
|
|
text: "修改",
|
|
style: {
|
|
backgroundColor: "#4E73DF",
|
|
},
|
|
},
|
|
{
|
|
text: "删除",
|
|
style: {
|
|
backgroundColor: "#EC6A56",
|
|
},
|
|
},
|
|
],
|
|
};
|
|
},
|
|
watch: {
|
|
serverList() {
|
|
uni.setStorageSync(
|
|
"serverList",
|
|
this.serverList.map((item) => item.title)
|
|
);
|
|
},
|
|
},
|
|
created() {},
|
|
mounted() {},
|
|
methods: {
|
|
add() {
|
|
|
|
if (!this.value) {
|
|
this.errorMessage = "服务器地址不能为空";
|
|
} else if (uni.getStorageSync("serverList").includes(this.value)) {
|
|
this.errorMessage = "服务器地址重复";
|
|
} else {
|
|
if (this.index !== "") {
|
|
if (this.serverList[this.index].title === this.serverConfig) {
|
|
this.serverConfig = this.value;
|
|
uni.setStorageSync("serverConfig", this.value);
|
|
}
|
|
this.$set(this.serverList, this.index, {
|
|
show: false,
|
|
title: this.value,
|
|
});
|
|
} else {
|
|
this.serverList.push({
|
|
show: false,
|
|
title: this.value,
|
|
});
|
|
}
|
|
this.showModal = false;
|
|
}
|
|
},
|
|
reset() {
|
|
this.index = "";
|
|
this.value = "";
|
|
this.errorMessage = "";
|
|
},
|
|
select(item) {
|
|
this.$set(this, "serverConfig", item);
|
|
uni.setStorageSync("serverConfig", item);
|
|
uni.navigateBack({
|
|
delta: 1,
|
|
});
|
|
},
|
|
click(index, handle) {
|
|
if (handle == 0) {
|
|
this.index = index;
|
|
this.value = this.serverList[index].title;
|
|
this.showModal = true;
|
|
} else {
|
|
this.serverList.splice(index, 1);
|
|
}
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style scoped>
|
|
.page {
|
|
height: 100vh;
|
|
background-color: #eef3ff;
|
|
}
|
|
|
|
.list {
|
|
border-bottom: 1px solid #f8faff;
|
|
}
|
|
.list-text {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
|
|
padding: 15px;
|
|
font-size: 18px;
|
|
}
|
|
|
|
.blue >>> .u-swipe-content {
|
|
color: #007aff;
|
|
}
|
|
|
|
.title {
|
|
padding-top: 10px;
|
|
padding-left: 20px;
|
|
|
|
font-weight: bolder;
|
|
}
|
|
|
|
.u-field {
|
|
padding: 0 15px;
|
|
}
|
|
.u-field >>> .u-flex {
|
|
margin: 10px 0 !important;
|
|
padding: 5px 10px;
|
|
border: 1px solid #c1c3cf;
|
|
border-radius: 20px;
|
|
}
|
|
|
|
.popupBottom {
|
|
display: flex;
|
|
margin-bottom: 10px;
|
|
}
|
|
</style>
|
|
|