133 lines
3.1 KiB
Plaintext
133 lines
3.1 KiB
Plaintext
<template>
|
|
<view class="page">
|
|
<scroll-view direction="vertical" :show-scrollbar="false" style="flex:1;">
|
|
<view class="tip-bar">
|
|
<uni-icons type="locked" size="20" color="#34C759"></uni-icons>
|
|
<text class="tip-text">以下设置仅对你生效,管理他人查看你的方式</text>
|
|
</view>
|
|
|
|
<view class="list-container">
|
|
<view class="list-item" v-for="(item, idx) in items" :key="idx">
|
|
<view class="item-left">
|
|
<text class="item-title">{{ item.title }}</text>
|
|
<text class="item-sub">{{ item.sub }}</text>
|
|
</view>
|
|
<switch :checked="item.value == 1" color="#34C759" @change="() => onToggle(item)" />
|
|
</view>
|
|
</view>
|
|
</scroll-view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup lang="uts">
|
|
import Api from '@/common/api-service.uts'
|
|
|
|
type SettingItem = {
|
|
key : string
|
|
title : string
|
|
sub : string
|
|
value : number
|
|
}
|
|
|
|
const items = reactive<SettingItem[]>([
|
|
{ key: 'hide_age', title: '隐藏年龄', sub: '他人将无法看到你的真实年龄', value: 0 },
|
|
{ key: 'hide_online', title: '隐藏在线状态', sub: '他人看不到你是否在线', value: 0 },
|
|
{ key: 'hide_distance', title: '隐藏距离', sub: '同城/附近不再显示与你的距离', value: 0 },
|
|
{ key: 'hide_album', title: '隐藏相册', sub: '他人访问你的资料时看不到相册', value: 0 },
|
|
{ key: 'danmaku_global', title: '弹幕总开关', sub: '关闭后全站不显示互动弹幕', value: 1 },
|
|
])
|
|
|
|
function loadPrivacy() {
|
|
Api.user.privacy()
|
|
.then((res : UTSJSONObject) => {
|
|
items.forEach((it : SettingItem) => {
|
|
const v = res.get(it.key)
|
|
if (v != null) {
|
|
it.value = (v as number) == 1 ? 1 : 0
|
|
}
|
|
})
|
|
})
|
|
.catch(() => {
|
|
uni.showToast({ title: '加载失败', icon: 'none' })
|
|
})
|
|
}
|
|
|
|
function onToggle(item : SettingItem) {
|
|
const next = item.value == 1 ? 0 : 1
|
|
item.value = next
|
|
Api.user.updatePrivacy({ [item.key]: next })
|
|
.then(() => {
|
|
uni.showToast({ title: '已更新', icon: 'success', duration: 1000 })
|
|
})
|
|
.catch((err : any) => {
|
|
item.value = item.value == 1 ? 0 : 1
|
|
uni.showToast({ title: (err && err.message) ? err.message : '更新失败', icon: 'none' })
|
|
})
|
|
}
|
|
|
|
onMounted(() => { loadPrivacy() })
|
|
onShow(() => { loadPrivacy() })
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.page {
|
|
flex: 1;
|
|
background-color: #f7f7f7;
|
|
}
|
|
|
|
.tip-bar {
|
|
display: flex;
|
|
flex-flow: row nowrap;
|
|
align-items: center;
|
|
margin: 24rpx 30rpx;
|
|
padding: 20rpx 24rpx;
|
|
background-color: rgba(52, 199, 89, 0.1);
|
|
border-radius: 16rpx;
|
|
}
|
|
|
|
.tip-text {
|
|
font-size: 24rpx;
|
|
color: #34C759;
|
|
margin-left: 12rpx;
|
|
flex: 1;
|
|
}
|
|
|
|
.list-container {
|
|
margin: 0 30rpx;
|
|
background-color: #fff;
|
|
border-radius: 20rpx;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.list-item {
|
|
display: flex;
|
|
flex-flow: row nowrap;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 30rpx;
|
|
border-bottom: 1rpx solid #f0f0f0;
|
|
}
|
|
|
|
.list-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.item-left {
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex: 1;
|
|
margin-right: 20rpx;
|
|
}
|
|
|
|
.item-title {
|
|
font-size: 30rpx;
|
|
color: #333;
|
|
}
|
|
|
|
.item-sub {
|
|
font-size: 24rpx;
|
|
color: #999;
|
|
margin-top: 6rpx;
|
|
}
|
|
</style>
|