Files
lingji-work-fe/src/views/components/management/person/index.vue

127 lines
4.3 KiB
Vue
Raw Normal View History

<template>
2025-09-11 18:16:05 +08:00
<div class="bg-#fff rounded-16px w-100% p-36px person-wrap">
2025-09-10 14:29:18 +08:00
<p class="title mb-32px">个人信息</p>
2025-09-11 18:16:05 +08:00
<div class="flex items-center">
2025-09-12 15:07:29 +08:00
<Upload
action="/"
:showUploadList="false"
accept="image/*"
v-if="dataSource"
:customRequest="handleUpload"
class="mr-60px relative cursor-pointer"
>
<Avatar :src="dataSource.head_image" :size="100" v-if="dataSource.head_image" />
<div v-else class="w-100 h-100 rounded-50% bg-#6D4CFE flex items-center justify-center">
<span class="color-#FFF text-46px font-400">{{ dataSource.mobile?.slice(-3) }}</span>
</div>
2025-09-11 18:16:05 +08:00
<img :src="icon1" width="20" height="20" class="absolute right-5px bottom-4px" />
2025-09-12 15:07:29 +08:00
</Upload>
2025-09-11 18:16:05 +08:00
<div class="flex-1 flex h-68px">
<div class="flex flex-1">
<span class="cts mr-4p">昵称</span>
<span class="cts !color-#211F24 bold !font-500 mr-12px">{{ dataSource.name || '-' }}</span>
<Button type="text" size="small" class="!p-0 !h-22px m-0" @click="openChangeNameModal">编辑</Button>
</div>
<div class="flex-1">
<div class="flex items-center mb-24px">
<span class="cts mr-4px w-56px">手机号</span>
2025-09-12 15:07:29 +08:00
<span class="cts !color-#211F24 bold !font-500 mr-12px">{{ mobileLabel }}</span>
2025-09-11 18:16:05 +08:00
<Button type="text" size="small" class="!p-0 !h-22px m-0" @click="openChangeMobileModal">更改</Button>
2025-09-04 18:05:16 +08:00
</div>
2025-09-11 18:16:05 +08:00
<div class="flex items-center">
<span class="cts mr-4px w-56px">密码</span>
<span
class="!bg-#211F24 bold !font-500 w-6px h-6px rounded-50% mr-2px"
v-for="(item, index) in new Array(10).fill(0)"
:key="index"
></span>
2025-09-12 12:00:26 +08:00
<Button type="text" size="small" class="!p-0 !h-22px ml-10px" @click="openChangePasswordModal">更改</Button>
2025-09-11 18:16:05 +08:00
</div>
</div>
</div>
</div>
2025-09-12 12:00:26 +08:00
<ChangePasswordModal ref="changePasswordModalRef" />
2025-09-11 18:16:05 +08:00
<ChangeNameModal ref="changeNameModalRef" />
<ChangeMobileModal ref="changeMobileModalRef" />
2025-07-01 17:28:18 +08:00
</div>
</template>
<script setup lang="ts">
2025-09-12 15:07:29 +08:00
import { Avatar, Button, Upload, message } from 'ant-design-vue';
2025-09-12 12:00:26 +08:00
import ChangePasswordModal from './components/change-password-modal/index.vue';
2025-09-11 18:16:05 +08:00
import ChangeNameModal from './components/change-name-modal/index.vue';
import ChangeMobileModal from './components/change-mobile-modal/index.vue';
import { reactive, ref } from 'vue';
import axios from 'axios';
2025-09-12 15:07:29 +08:00
import { fetchImageUploadFile, updateMyInfo } from '@/api/all';
import { useUserStore } from '@/stores';
2025-09-11 18:16:05 +08:00
import icon1 from './img/icon1.png';
const store = useUserStore();
2025-09-12 12:00:26 +08:00
const changePasswordModalRef = ref(null);
2025-09-11 18:16:05 +08:00
const changeNameModalRef = ref(null);
const changeMobileModalRef = ref(null);
const formRef = ref();
const dataSource = computed(() => {
2025-09-11 18:16:05 +08:00
return store.userInfo;
});
2025-09-12 15:07:29 +08:00
const mobileLabel = computed(() => {
2025-09-11 18:16:05 +08:00
const _mobile = dataSource.value.mobile;
if (!_mobile) return '-';
return _mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
});
2025-09-12 15:07:29 +08:00
// const form = reactive({
// mobile: '',
// captcha: '',
// });
2025-09-11 18:16:05 +08:00
const openChangeNameModal = () => {
changeNameModalRef.value.open(dataSource.name);
};
const openChangeMobileModal = () => {
changeMobileModalRef.value.open();
};
2025-09-12 12:00:26 +08:00
const openChangePasswordModal = () => {
changePasswordModalRef.value.open(dataSource.value.mobile);
};
2025-09-12 15:07:29 +08:00
const getFileExtension: string = (filename: string) => {
const match = filename.match(/\.([^.]+)$/);
return match ? match[1].toLowerCase() : '';
};
2025-09-12 15:07:29 +08:00
const handleUpload = async (option) => {
const { file } = option;
try {
2025-09-12 15:07:29 +08:00
if (file) {
const fileExtension = getFileExtension(file.name);
const { data } = await fetchImageUploadFile({
suffix: fileExtension,
});
const { upload_url, file_url } = data;
const blob = new Blob([file], { type: file.type });
await axios.put(upload_url, blob, {
headers: { 'Content-Type': file.type },
});
const { code } = await updateMyInfo({ head_image: file_url });
if (code === 200) {
message.success('修改成功');
store.userInfo.head_image = file_url;
}
}
} catch (error) {
2025-09-12 15:07:29 +08:00
message.error('上传失败');
}
2025-09-12 15:07:29 +08:00
};
</script>
2025-09-12 15:07:29 +08:00
2025-07-01 17:28:18 +08:00
<style scoped lang="scss">
2025-09-11 18:16:05 +08:00
@import './style.scss';
</style>