Files
kangyuan-mobile/pages/public/setting.vue
T
2026-06-15 10:24:15 +08:00

311 lines
7.2 KiB
Vue

<template>
<s-pages title="设置" :purple_bg="true">
<view class="setPage">
<view class="card1">
<card_list :arr="listArr">
<template v-slot:footer-1>
<view @click="upImg" class="headImg">
<image v-if="userInfo?.avatar" :src="userInfo?.avatar" mode="scaleToFill" />
<image v-else :src="`${$url}home/head.png`" mode="scaleToFill" />
</view>
</template>
<template v-slot:footer-2>
<input
type="text"
placeholder="请输入昵称"
v-model="userInfo.nickname"
style="text-align: right"
@blur="upData"
/>
</template>
</card_list>
</view>
<view class="bg24 submit-btn" @click="btn">登录其他账号</view>
</view>
</s-pages>
</template>
<script setup>
import sheep from '@/sheep';
import { ref, computed, reactive, onMounted } from 'vue';
import AuthUtil from '@/sheep/api/member/auth';
import card_list from '@/components/card_list/card_list.vue';
import UserApi from '@/sheep/api/member/user';
const appInfo = computed(() => sheep.$store('app').info);
const isLogin = computed(() => sheep.$store('user').isLogin);
const userInfo = ref({});
const storageSize = uni.getStorageInfoSync().currentSize + 'Kb';
const state = reactive({
showModal: false,
});
const listArr = ref([
{
id: '1',
title: '头像',
disabled: false,
url: '',
},
{
id: '2',
title: '昵称',
rightText: '',
},
{
id: '9',
title: '用户ID',
rightText: '',
},
{
id: '10',
title: '手机号',
rightText: '',
},
// {
// id: '3',
// title: '手机号码',
// rightText: '',
// clickable: true,
// link: 'navigateTo',
// to: '/pages/home/phone',
// },
{
id: '4',
title: '修改密码',
clickable: true,
link: 'navigateTo',
to: '/pages/home/pass',
},
{
id: '12',
title: '银行卡',
clickable: true,
link: 'navigateTo',
to: '/pages/home/bankCard',
},
{
id: '5',
title: '隐私政策',
clickable: true,
link: 'navigateTo',
to: '/pages/home/agreement?type=1',
},
{
id: '6',
title: '用户协议',
clickable: true,
link: 'navigateTo',
to: '/pages/home/agreement?type=2',
},
// {
// id: '8',
// title: '计算',
// clickable: true,
// link: 'navigateTo',
// to: '/pages/home/calculate',
// },
{
id: '7',
title: '关于app',
clickable: true,
link: 'navigateTo',
to: '/pages/public/versions/versions',
// link: 'navigateTo',
rightText: uni.getSystemInfoSync().appWgtVersion,
},
{
id: '11',
title: '账号注销',
clickable: true,
link: 'navigateTo',
to: '/pages/public/logoff',
},
// {
// id: '12',
// title: '测试',
// clickable: true,
// link: 'navigateTo',
// to: '/pages/public/test',
// },
]);
function onCheckUpdate() {
sheep.$platform.checkUpdate();
// 小程序初始化时已检查更新
// H5实时更新无需检查
// App 1.跳转应用市场更新 2.手动热更新 3.整包更新
}
// 注销账号
function onLogoff() {
uni.showModal({
title: '提示',
content: '确认注销账号?',
confirmColor: '#FA7E31',
success: async function (res) {
if (!res.confirm) {
return;
}
const { code } = await AuthUtil.deactivate();
if (code !== 0) {
return;
}
sheep.$store('user').logout();
sheep.$router.go('/pages/index/user');
},
});
}
// 退出账号
function onLogout() {
uni.showModal({
title: '提示',
content: '确认退出账号?',
confirmColor: '#FA7E31',
success: async function (res) {
if (!res.confirm) {
return;
}
const { code } = await AuthUtil.logout();
if (code !== 0) {
return;
}
sheep.$store('user').logout();
sheep.$router.go('/pages/index/user');
},
});
}
const upImg = () => {
uni.navigateTo({
url: '/pages/public/avatarCrop',
success: (res) => {
const eventChannel = res?.eventChannel;
if (!eventChannel) return;
eventChannel.on('success', ({ url }) => {
if (!url) return;
upData({ avatar: url });
});
},
});
};
const getData = async (obj) => {
let res = await UserApi.getUserInfo();
if (res.code != 0) return;
userInfo.value = res.data;
listArr.value.forEach((item) => {
if (item.id == 2) {
item.rightText = userInfo.value.nickname;
}
if (item.id == 3) {
item.rightText = userInfo.value.mobile;
}
if (item.id == 9) {
item.rightText = userInfo.value.id + '';
}
if (item.id == 10) {
item.rightText = userInfo.value.mobile;
}
});
console.log(listArr.value);
};
const upData = async (obj) => {
let res = await UserApi.updateUser({
...userInfo.value,
...obj,
});
if (res.code != 0) return;
getData();
};
const btn = () => {
uni.showModal({
title: '提示',
content: '确认退出账号?',
confirmColor: '#FA7E31',
success: async function (res) {
if (!res.confirm) {
return;
}
const { code } = await AuthUtil.logout();
if (code !== 0) {
return;
}
sheep.$store('user').logout();
// sheep.$router.go('/pages/public/login');
uni.reLaunch({
url: '/pages/public/login',
});
},
});
};
onMounted(() => {
// listArr.value.forEach(item=>{
// if(item.id == 7){
// let localVersion = '';
// // #ifdef APP-PLUS
// localVersion = plus.runtime.versionCode;
// // #endif
// // #ifndef APP-PLUS
// localVersion = uni.getStorageSync('localVersion') || '1.0.0';
// // #endif
// item.rightText = localVersion;
// }
// })
getData();
});
const logout = () => {
uni.showModal({
title: '注销账号',
content: '注销账号后,将数据清空,并无法登录该账号,请谨慎操作',
confirmColor: '#FA7E31',
success: async function (res) {
if (!res.confirm) {
return;
}
const { code } = await AuthUtil.logout();
if (code !== 0) {
return;
}
sheep.$store('user').logout();
sheep.$router.go('/pages/index/user');
},
});
};
</script>
<style lang="scss" scoped>
.setPage {
padding: 30rpx 40rpx;
box-sizing: border-box;
.card1 {
background-color: var(--color24);
border-radius: 8rpx;
overflow: hidden;
}
}
.headImg {
width: 72rpx;
height: 72rpx;
border-radius: 8rpx;
overflow: hidden;
image {
width: 100%;
height: 100%;
}
}
input {
font-size: 28rpx;
color: #666666;
}
.submit-btn {
color: var(--color34);
background: var(--color1);
margin-top: 100rpx;
}
</style>