init
This commit is contained in:
@@ -0,0 +1,328 @@
|
||||
<template>
|
||||
<s-pages title="设置">
|
||||
<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 { baseUrl } from '@/sheep/config';
|
||||
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: '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.chooseImage({
|
||||
count: 1, //默认9
|
||||
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
|
||||
success: function (res) {
|
||||
const tempFilePaths = res.tempFilePaths;
|
||||
const tempFiles = res.tempFiles;
|
||||
let resSize = tempFiles[0].size;
|
||||
if (resSize > 1048576) {
|
||||
uni.showToast({
|
||||
title: '上传图片大小不能超过1MB',
|
||||
icon: 'error',
|
||||
});
|
||||
return;
|
||||
}
|
||||
const token = uni.getStorageSync('token') ? uni.getStorageSync('token') : undefined;
|
||||
let tenant_id = uni.getStorageSync('tenant-id');
|
||||
uni.uploadFile({
|
||||
url: baseUrl + '/app-api/infra/file/upload', //仅为示例,非真实的接口地址
|
||||
filePath: tempFilePaths[0],
|
||||
name: 'file',
|
||||
formData: {
|
||||
directory: 'head',
|
||||
'tenant-id': tenant_id,
|
||||
token: token,
|
||||
},
|
||||
header: {},
|
||||
success: (uploadFileRes) => {
|
||||
let url = JSON.parse(uploadFileRes.data).data;
|
||||
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>
|
||||
Reference in New Issue
Block a user