350 lines
9.1 KiB
Vue
350 lines
9.1 KiB
Vue
<template>
|
|
<view class="content">
|
|
<TopSafe></TopSafe>
|
|
<Header title="设置" />
|
|
<view class="setting-view">
|
|
<view class="item-list mt-24">
|
|
<view class="flex-r-lr item-box" @click="onHead(index)" v-for="(item, index) in headList" :key="index"
|
|
:style="{ borderWidth: index == headList.length - 1 ? '0' : '2rpx' }">
|
|
<text class="text-gray text-32">{{ item.text }}</text>
|
|
<view class="flex-r-e" style="align-items: center;">
|
|
<image v-if="item.type == 'img'" :src="item.value" class="ava-img"></image>
|
|
<text class="text-zu text-32" v-if="item.type == 'text'">{{ item.value }}</text>
|
|
<u-icon size="16" name="arrow-right" color="#666" style="margin-left:12rpx"></u-icon>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="item-list mt-24">
|
|
<view class="flex-r-lr item-box" @click="onBottom(index)" v-for="(item, index) in bottomList"
|
|
:key="index" :style="{ borderWidth: index == bottomList.length - 1 ? '0' : '2rpx' }">
|
|
<text class="text-gray text-32">{{ item.text }}</text>
|
|
<view class="flex-r-e" style="align-items: center;">
|
|
<u-icon size="16" name="arrow-right" color="#666" style="margin-left:12rpx"></u-icon>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<MyBtn class="mt-48" @ok="onOutLogin" text="退出登录"></MyBtn>
|
|
</view>
|
|
<up-toast ref="uToastRef"></up-toast>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { getUserInfo, uploadAvatar } from '@/api/auth.js';
|
|
import { uploadImage, uploadImg } from '@/api/common.js';
|
|
import { IMG_TYPE } from '@/utils/enumUtils.js';
|
|
import { BASE_URL, Authorization } from '@/utils/config.js';
|
|
import { getStorageFun, TOKEN_NAME, clear } from '@/utils/auth.js';
|
|
import Header from '@/components/common/header.vue';
|
|
import TopSafe from '@/components/common/top-safe.nvue'
|
|
import MyBtn from '@/components/common/my-btn.vue'
|
|
import func from '@/utils/func.js';
|
|
|
|
export default {
|
|
components: { Header, TopSafe, MyBtn },
|
|
data() {
|
|
return {
|
|
type: false,
|
|
userInfo: null,
|
|
headList: [
|
|
{ text: '头像', type: 'img', value: '' },
|
|
{ text: '用户名称', type: 'text', value: '' },
|
|
],
|
|
bottomList: [
|
|
{ text: '账号与安全' },
|
|
{ text: '我的合同' },
|
|
{ text: '资质照片' },
|
|
{ text: '用户协议' },
|
|
{ text: '隐私协议' },
|
|
{ text: '售后保障协议' },
|
|
{ text: '关于我们' },
|
|
]
|
|
};
|
|
},
|
|
onShow() {
|
|
this.init();
|
|
},
|
|
onLoad() {
|
|
// this.userinfo();
|
|
},
|
|
methods: {
|
|
init() {
|
|
this.userinfo()
|
|
},
|
|
onHead(index) {
|
|
console.log('index', index)
|
|
let that = this;
|
|
if (index == 0) {
|
|
uni.chooseImage({
|
|
count: 1, // 默认9,设置图片的数量
|
|
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
|
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
|
success: function (res) {
|
|
// 成功选择图片后
|
|
const filePath = res.tempFilePaths[0]; // 获取文件路径
|
|
that.uploadFile(filePath);
|
|
}
|
|
});
|
|
} else if (index == 1) {
|
|
uni.navigateTo({
|
|
url: '/pages/rwa_package/setName/setName'
|
|
})
|
|
}
|
|
},
|
|
uploadFile(url) {
|
|
uni.showLoading({
|
|
title: '图片上传中...',
|
|
})
|
|
const that = this;
|
|
const token = getStorageFun(TOKEN_NAME); // 获取token, 根据实际情况调整获取方式
|
|
// 成功则返回文件的本地临时文件路径
|
|
uni.uploadFile({
|
|
url: BASE_URL + uploadImg, // 替换为你的上传接口URL
|
|
filePath: url,
|
|
name: 'file',
|
|
formData: {
|
|
'type': IMG_TYPE.COMMON,
|
|
},
|
|
header: {
|
|
"Authorization": Authorization,
|
|
'HSM-AUTH': token ? token : '',
|
|
},
|
|
success: (uploadFileRes) => {
|
|
const data = JSON.parse(uploadFileRes.data);
|
|
if (data.bizcode === 100) {
|
|
const accessUrl = data.data.accessUrl;
|
|
// // #ifdef MP-WEIXIN
|
|
// that.handleWxMediaCheck(accessUrl);
|
|
// // #endif
|
|
// // #ifndef MP-WEIXIN
|
|
// that.setUploadAvatar(accessUrl);
|
|
// // #endif
|
|
that.setUploadAvatar(accessUrl);
|
|
} else {
|
|
uni.showToast({
|
|
title: '图片上传失败',
|
|
icon: 'none',
|
|
mask: true,
|
|
duration: 3000,
|
|
})
|
|
}
|
|
},
|
|
fail: (uploadFileErr) => {
|
|
uni.showToast({
|
|
title: '图片上传失败',
|
|
icon: 'none',
|
|
mask: true,
|
|
duration: 3000,
|
|
})
|
|
},
|
|
complete: (res) => {
|
|
// 请求完成以后做一些事情
|
|
uni.hideLoading();
|
|
}
|
|
});
|
|
},
|
|
// #ifdef MP-WEIXIN
|
|
async handleWxMediaCheck(imgUrl) {
|
|
uni.showLoading({
|
|
title: '安全检测中...',
|
|
});
|
|
try {
|
|
const [token, openid] = await Promise.all([
|
|
this.getWxAccessToken(),
|
|
this.getWxOpenId()
|
|
]);
|
|
uni.request({
|
|
url: `https://api.weixin.qq.com/wxa/media_check_async?access_token=${token}`,
|
|
method: 'POST',
|
|
data: {
|
|
media_url: imgUrl,
|
|
media_type: 2,
|
|
version: 2,
|
|
scene: 1,
|
|
openid: openid
|
|
},
|
|
success: (res) => {
|
|
uni.hideLoading();
|
|
if (res.data && res.data.errcode === 0) {
|
|
this.setUploadAvatar(imgUrl);
|
|
} else {
|
|
uni.showToast({
|
|
title: (res.data && res.data.errmsg) || '图片检测未通过',
|
|
icon: 'none',
|
|
duration: 3000
|
|
});
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
uni.hideLoading();
|
|
uni.showToast({
|
|
title: '安全检测失败',
|
|
icon: 'none',
|
|
duration: 3000
|
|
});
|
|
}
|
|
});
|
|
} catch (err) {
|
|
uni.hideLoading();
|
|
uni.showToast({
|
|
title: '获取微信凭证或OpenID失败',
|
|
icon: 'none',
|
|
duration: 3000
|
|
});
|
|
}
|
|
},
|
|
getWxAccessToken() {
|
|
const appid = 'wx376a16a88befe265';
|
|
const secret = '0e8fcbf770d72d41b84ea5ebdc427d10';
|
|
return new Promise((resolve, reject) => {
|
|
uni.request({
|
|
url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appid}&secret=${secret}`,
|
|
method: 'GET',
|
|
success: (res) => {
|
|
if (res.data && res.data.access_token) {
|
|
resolve(res.data.access_token);
|
|
} else {
|
|
reject(res.data);
|
|
}
|
|
},
|
|
fail: (err) => reject(err)
|
|
});
|
|
});
|
|
},
|
|
getWxOpenId() {
|
|
const appid = 'wx376a16a88befe265';
|
|
const secret = '0e8fcbf770d72d41b84ea5ebdc427d10';
|
|
return new Promise((resolve, reject) => {
|
|
uni.login({
|
|
provider: 'weixin',
|
|
success: (loginRes) => {
|
|
if (loginRes.code) {
|
|
uni.request({
|
|
url: `https://api.weixin.qq.com/sns/jscode2session?appid=${appid}&secret=${secret}&js_code=${loginRes.code}&grant_type=authorization_code`,
|
|
method: 'GET',
|
|
success: (res) => {
|
|
if (res.data && res.data.openid) {
|
|
resolve(res.data.openid);
|
|
} else {
|
|
reject(res.data);
|
|
}
|
|
},
|
|
fail: (err) => reject(err)
|
|
});
|
|
} else {
|
|
reject(loginRes);
|
|
}
|
|
},
|
|
fail: (err) => reject(err)
|
|
});
|
|
});
|
|
},
|
|
// #endif
|
|
setUploadAvatar(img) {
|
|
let params = {
|
|
imgUrl: img
|
|
}
|
|
console.log("---", params)
|
|
uploadAvatar(params).then(res => {
|
|
if (res.bizcode === 100) {
|
|
this.$refs.uToastRef.show({
|
|
type: 'success',
|
|
message: "头像设置成功",
|
|
});
|
|
this.init();
|
|
} else {
|
|
this.$refs.uToastRef.show({
|
|
type: 'error',
|
|
message: "头像设置失败",
|
|
});
|
|
}
|
|
})
|
|
},
|
|
onOutLogin() {
|
|
clear();
|
|
uni.navigateTo({
|
|
url: '/pages/login_package/login/login'
|
|
})
|
|
},
|
|
onBottom(index) {
|
|
let url = '';
|
|
switch (index) {
|
|
case 0:
|
|
url = '/pages/rwa_package/accountSafe/accountSafe'
|
|
break;
|
|
case 1:
|
|
url = '/pages/rwa_package/insights/index'
|
|
break;
|
|
case 2:
|
|
url = '/pages/rwa_package/store-photo/store-photo'
|
|
break;
|
|
case 3:
|
|
url = '/pages/mine_package/mine_user_agreement/mine_user_agreement'
|
|
break;
|
|
case 4:
|
|
url = '/pages/mine_package/mine_privacy_agreement/mine_privacy_agreement'
|
|
break;
|
|
case 5:
|
|
url = '/pages/mine_package/mine_product_agreement/mine_product_agreement'
|
|
break;
|
|
case 6:
|
|
url = '/pages/mine_package/mine_about_us/mine_about_us'
|
|
break;
|
|
}
|
|
if (url) {
|
|
uni.navigateTo({
|
|
url: url
|
|
})
|
|
}
|
|
},
|
|
userinfo() {
|
|
getUserInfo().then(res => {
|
|
if (res.bizcode == 100) {
|
|
this.userInfo = res.data;
|
|
this.userInfo.avatarUrl = this.userInfo.avatarUrl ? this.userInfo.avatarUrl : 'https://static.tbmall.xin/static/default-avatar.png';
|
|
this.headList[0].value = this.userInfo.avatarUrl;
|
|
this.userInfo.nickname = this.userInfo.nickname ? this.userInfo.nickname : '暂未设置';
|
|
this.headList[1].value = this.userInfo.nickname;
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.setting-view {
|
|
width: 100%;
|
|
height: calc(100% - 88rpx - var(--status-bar-height));
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
overflow-y: auto;
|
|
padding: 0 32rpx;
|
|
box-sizing: border-box;
|
|
|
|
.item-list {
|
|
width: 100%;
|
|
border-radius: 16rpx;
|
|
display: flex;
|
|
flex-direction: column;
|
|
background-color: #fff;
|
|
|
|
.item-box {
|
|
min-height: 108rpx;
|
|
padding: 0 32rpx;
|
|
box-sizing: border-box;
|
|
align-items: center;
|
|
border-bottom: solid #EAEAEA;
|
|
|
|
.ava-img {
|
|
width: 60rpx;
|
|
height: 60rpx;
|
|
border-radius: 30rpx;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</style>
|