Files
im/pages/user/selfInfo/index.vue
T

195 lines
4.9 KiB
Vue
Raw Normal View History

2025-11-07 09:56:20 +08:00
<template>
2025-11-25 05:36:02 +08:00
<view class="page_container">
<custom-nav-bar title="个人资料" />
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
<view class="info_wrap">
<info-item :loading="loadingState.faceURL" @click="updateAvatar" title="头像">
<my-avatar :src="selfInfo.faceURL" :desc="selfInfo.nickname" size="30" slot="value" />
</info-item>
<info-item @click="updateNickname" title="姓名" :content="selfInfo.nickname" />
<info-item :loading="loadingState.gender" @click="updateGender" title="性别" :content="getGender" />
<info-item :loading="loadingState.birth" @click="() => (showDatePicker = true)" title="生日"
:content="getBirth" />
</view>
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
<view class="info_wrap">
<info-item :showArrow="false" title="手机号码" :content="selfInfo.mobile || '-'" />
<info-item :showArrow="false" title="邮箱" :content="selfInfo.email || '-'" />
</view>
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
<u-datetime-picker :minDate="0" :maxDate="nowDate" :show="showDatePicker" @confirm="confirmDate"
@cancel="() => (showDatePicker = false)" v-model="selfInfo.birth" mode="date" />
2026-02-09 07:29:02 +08:00
<c-cut-avatar ref="cutAvatar" @save="saveAvatar" />
2025-11-25 05:36:02 +08:00
</view>
2025-11-07 09:56:20 +08:00
</template>
<script>
2026-02-09 07:29:02 +08:00
import {businessInfoUpdate,upload} from "@/api/login";
2025-11-25 05:36:02 +08:00
import IMSDK from "openim-uniapp-polyfill";
import CustomNavBar from "@/components/CustomNavBar/index.vue";
import MyAvatar from "@/components/MyAvatar/index.vue";
import dayjs from "dayjs";
import InfoItem from "./InfoItem.vue";
2025-11-27 07:40:32 +08:00
import util from "@/util";
2026-01-01 04:15:30 +08:00
import {getPurePath} from "@/util/common";
2025-11-25 05:36:02 +08:00
export default {
components: {
CustomNavBar,
MyAvatar,
InfoItem,
},
data() {
return {
showDatePicker: false,
loadingState: {
faceURL: false,
gender: false,
birth: false,
},
nowDate: Date.now(),
};
},
computed: {
selfInfo() {
return this.$store.getters.storeSelfInfo;
},
getGender() {
2026-01-09 09:15:59 +08:00
if (this.selfInfo.sex == 0) {
2025-11-25 05:36:02 +08:00
return "保密";
}
2026-01-09 09:15:59 +08:00
if (this.selfInfo.sex == 1) {
2025-11-25 05:36:02 +08:00
return "男";
}
return "女";
},
getBirth() {
const birth = this.selfInfo.birthday ?? 0;
return dayjs(birth).format("YYYY-MM-DD");
},
},
methods: {
2025-11-27 07:40:32 +08:00
...util,
2025-11-25 05:36:02 +08:00
updateNickname() {
2026-01-01 04:15:30 +08:00
const s = util.aesencode(this.selfInfo);
2025-11-25 05:36:02 +08:00
uni.navigateTo({
2026-01-01 04:15:30 +08:00
url: `/pages/common/markOrIDPage/index?isSelfNickname=true&sourceInfo=${s}`,
2025-11-25 05:36:02 +08:00
});
},
updateGender() {
uni.showActionSheet({
itemList: ['保密',"男", "女"],
success: async ({
tapIndex
}) => {
this.loadingState.gender = true;
await this.updateSelfInfo({gender: tapIndex,},"gender",);
},
});
},
2026-02-09 07:29:02 +08:00
saveAvatar(e){
this.tempFilePath = e.path;
upload(e.path,{
'url':"/user/avatar",
savePath: "avatar"
}).then((res) => {
console.log("上传成功",res);
this.$store.commit("user/SET_SELF_INFO",{
...this.$store.getters.storeSelfInfo,
faceURL: res.data.avatar,
});
}).catch((res1) => {
console.log("上传失败",res1);
});
},
2025-11-25 05:36:02 +08:00
updateAvatar() {
uni.chooseImage({
count: 1,
2026-02-09 07:29:02 +08:00
sizeType: ["original"],
2025-11-25 05:36:02 +08:00
success: async ({
tempFilePaths
}) => {
const path = tempFilePaths[0];
2026-02-09 07:29:02 +08:00
this.$refs.cutAvatar.enterEditor(path);
return ;
2025-11-25 05:36:02 +08:00
const nameIdx = path.lastIndexOf("/") + 1;
const typeIdx = path.lastIndexOf(".") + 1;
const fileName = path.slice(nameIdx);
const fileType = path.slice(typeIdx);
this.loadingState.faceURL = true;
2026-01-01 04:15:30 +08:00
try{
const res = await IMSDK.asyncApi(IMSDK.IMMethods.UploadFile, IMSDK.uuid(), {
filepath: getPurePath(tempFilePaths[0]),
name: fileName,
contentType: fileType,
uuid: IMSDK.uuid(),
});
console.log(res);
this.updateSelfInfo({
faceURL: res.data.url,
},
"faceURL",
);
this.loadingState.faceURL = false;
}catch(e){
console.log(e);
}
2025-11-25 05:36:02 +08:00
},
});
},
toQrCode() {
uni.navigateTo({
2025-11-27 07:40:32 +08:00
url: `/pages/common/userOrGroupQrCode`,
2025-11-25 05:36:02 +08:00
});
},
copyID() {
uni.setClipboardData({
data: this.selfInfo.userID,
success: () => {
uni.hideToast();
this.$nextTick(() => {
uni.$u.toast("复制成功");
});
},
});
},
async updateSelfInfo(data, key) {
try {
await businessInfoUpdate({
userID: this.selfInfo.userID,
...data,
});
await this.$store.dispatch("user/updateBusinessInfo");
uni.$u.toast("修改成功");
} catch (e) {
console.log(e);
uni.$u.toast("修改失败");
}
this.loadingState[key] = false;
},
confirmDate({value}) {
this.loadingState.birth = true;
2026-01-09 09:15:59 +08:00
console.log(this.$store.getters.storeSelfInfo.faceURL);
2025-11-25 05:36:02 +08:00
this.updateSelfInfo({birth: value,},"birth",);
this.showDatePicker = false;
},
},
};
2025-11-07 09:56:20 +08:00
</script>
<style lang="scss" scoped>
2025-11-25 05:36:02 +08:00
.page_container {
background-color: #f8f8f8;
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.info_wrap {
margin: 24rpx 24rpx 0 24rpx;
background: #fff;
border-radius: 6px;
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.qr_icon {
width: 22px;
height: 23px;
}
}
}
</style>