| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503 |
- <template>
- <div class="page-content user">
- <div class="content">
- <div class="left-wrap">
- <div class="user-wrap box-style">
- <img class="bg" src="@imgs/user/bg.webp" />
- <el-upload
- :file-list="[]"
- class="upload-demo"
- name="avatar"
- accept="jpg,jpeg,png,webp"
- :show-file-list="false"
- :action="uploadServer"
- :headers="{Authorization: useUserStore().accessToken}"
- :on-success="handleSuccess"
- >
- <img class="avatar" :src="userInfo.avatar || 'https://img.lewaimai.com/zqcrm/avatar/20250926/9PLsci1dwXLcb8Iw.jpg'" title="点击上传"/>
- <template #tip>
- <div class="el-upload__tip">
- 点击头像上传
- </div>
- </template>
- </el-upload>
- <h2 class="name">{{ userInfo.username }}</h2>
- <!-- <p class="des">逐趣CRM 是一款漂亮的后台管理系统模版.</p>-->
- <div class="outer-info">
- <div>
- <i class="iconfont-sys"></i>
- <span>{{ form.sex ? '女' : '男' }}</span>
- </div>
- <div>
- <i class="iconfont-sys"></i>
- <span>{{ form.phone }}</span>
- </div>
- <div>
- <i class="iconfont-sys"></i>
- <span>{{ form.email }}</span>
- </div>
- <div>
- <i class="iconfont-sys"></i>
- <span>{{ form.descr}}</span>
- </div>
- </div>
- <!-- <div class="lables">
- <h3>标签</h3>
- <div>
- <div v-for="item in lableList" :key="item">
- {{ item }}
- </div>
- </div>
- </div>-->
- </div>
- <!-- <el-carousel class="gallery" height="160px"
- :interval="5000"
- indicator-position="none"
- >
- <el-carousel-item class="item" v-for="item in galleryList" :key="item">
- <img :src="item"/>
- </el-carousel-item>
- </el-carousel> -->
- </div>
- <div class="right-wrap">
- <div class="info box-style">
- <h1 class="title">基本设置</h1>
- <ElForm
- :model="form"
- class="form"
- ref="ruleFormRef"
- :rules="rules"
- label-width="86px"
- label-position="top"
- >
- <ElRow>
- <ElFormItem label="用户名" prop="realName">
- <el-input v-model="form.username" :disabled="!isEdit" />
- </ElFormItem>
- <ElFormItem label="性别" prop="sex" class="right-input">
- <ElSelect v-model="form.sex" placeholder="Select" :disabled="!isEdit">
- <ElOption
- v-for="item in options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </ElSelect>
- </ElFormItem>
- </ElRow>
- <ElRow>
- <ElFormItem label="手机" prop="phone">
- <ElInput v-model="form.phone" :disabled="!isEdit" />
- </ElFormItem>
- <ElFormItem label="邮箱" prop="email" class="right-input">
- <ElInput v-model="form.email" :disabled="!isEdit" />
- </ElFormItem>
- </ElRow>
- <ElFormItem label="个人介绍" prop="des">
- <ElInput type="text" v-model="form.descr" :disabled="!isEdit" />
- </ElFormItem>
- <div class="el-form-item-right">
- <ElButton type="primary" style="width: 90px" v-ripple @click="edit">
- {{ isEdit ? '保存' : '编辑' }}
- </ElButton>
- </div>
- </ElForm>
- </div>
- <div class="info box-style" style="margin-top: 20px">
- <h1 class="title">更改密码</h1>
- <ElForm ref="pwdFormRef" :model="pwdForm" :rules="pwdRules" class="form" label-width="86px" label-position="top">
- <ElFormItem label="当前密码" prop="password">
- <ElInput
- v-model="pwdForm.password"
- type="password"
- :disabled="!isEditPwd"
- show-password
- />
- </ElFormItem>
- <ElFormItem label="新密码" prop="newPassword">
- <ElInput
- v-model="pwdForm.newPassword"
- type="password"
- :disabled="!isEditPwd"
- show-password
- />
- </ElFormItem>
- <ElFormItem label="确认新密码" prop="confirmPassword">
- <ElInput
- v-model="pwdForm.confirmPassword"
- type="password"
- :disabled="!isEditPwd"
- show-password
- />
- </ElFormItem>
- <div class="el-form-item-right">
- <ElButton type="primary" style="width: 90px" v-ripple @click="editPwd">
- {{ isEditPwd ? '保存' : '编辑' }}
- </ElButton>
- </div>
- </ElForm>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import { useUserStore } from '@/store/modules/user'
- import {ElForm, ElMessage, FormInstance, FormRules, UploadProps} from 'element-plus'
- import {commonApi} from "@/api/commonApi";
- import {UserService} from "@/api/usersApi";
- import {computed} from "vue";
- defineOptions({ name: 'UserCenter' })
- const uploadServer = computed(() => import.meta.env.VITE_API_URL + import.meta.env.VITE_UPLOAD_URL)
- const userStore = useUserStore()
- const userInfo = computed(() => userStore.getUserInfo)
- const isEdit = ref(false)
- const isEditPwd = ref(false)
- const date = ref('')
- const form = reactive<Form.User>({
- username: userInfo.value.username || '',
- email: userInfo.value.email || '',
- phone: userInfo.value.phone || '',
- sex: userInfo.value.sex || 0,
- descr: userInfo.value.descr || '',
- })
- const handleSuccess: UploadProps['onSuccess'] = (response, uploadFile) => {
- if (response.code === 200) {
- ElMessage.success('上传成功!')
- userInfo.value.avatar = response.data.url
- } else {
- ElMessage.error(response.msg)
- }
- }
- const pwdForm = reactive<Form.ChangePassword>({
- password: '',
- newPassword: '',
- confirmPassword: ''
- })
- const ruleFormRef = ref<FormInstance>()
- const pwdFormRef = ref<FormInstance>()
- const pwdRules = reactive<FormRules>({
- password: [
- {required: true, message: '请输入密码', trigger: 'blur'},
- {min: 1, max: 12, message: '长度在 1 到 12 个字符', trigger: 'blur'}
- ],
- newPassword: [
- {required: true, message: '请输入新密码', trigger: 'blur'},
- {min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur'}
- ],
- confirmPassword: [{required: true, message: '请确认新密码', trigger: 'blur'}],
- })
- const rules = reactive<FormRules>({
- username: [
- { required: true, message: '请输入用户名', trigger: 'blur' },
- { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
- ],
- descr: [
- { max: 20, message: '长度最多20个字符', trigger: 'blur' }
- ],
- phone: [{ required: true, message: '请输入手机号码', trigger: 'blur' }],
- email: [{ type: 'email', message: '请输入正确邮箱', trigger: 'blur' }],
- })
- const options = [
- {
- value: 0,
- label: '男'
- },
- {
- value: 1,
- label: '女'
- }
- ]
- const lableList: Array<string> = ['专注设计', '很有想法', '辣~', '大长腿', '川妹子', '海纳百川']
- onMounted(() => {
- getDate()
- })
- const getDate = () => {
- const d = new Date()
- const h = d.getHours()
- let text = ''
- if (h >= 6 && h < 9) {
- text = '早上好'
- } else if (h >= 9 && h < 11) {
- text = '上午好'
- } else if (h >= 11 && h < 13) {
- text = '中午好'
- } else if (h >= 13 && h < 18) {
- text = '下午好'
- } else if (h >= 18 && h < 24) {
- text = '晚上好'
- } else if (h >= 0 && h < 6) {
- text = '很晚了,早点睡'
- }
- date.value = text
- }
- const edit = async () => {
- isEdit.value = !isEdit.value
- if (!isEdit.value) {
- if (!ruleFormRef.value) return
- await ruleFormRef.value.validate((valid) => {
- if (valid) {
- commonApi.editUSer(form)
- .then(() => {
- ElMessage.success('修改成功')
- userStore.setUserForm(form)
- })
- .catch(() => {
- ElMessage.error('操作失败')
- })
- }
- })
- }
- }
- const editPwd = async () => {
- isEditPwd.value = !isEditPwd.value
- if (!isEditPwd.value) {
- if (!pwdFormRef.value) return
- // 保存密码
- await pwdFormRef.value.validate((valid) => {
- if (valid) {
- commonApi.changePassword(pwdForm)
- .then(() => {
- ElMessage.success('密码修改成功')
- })
- .catch(() => {
- ElMessage.error('操作失败')
- })
- }
- })
- }
- }
- </script>
- <style lang="scss">
- .user {
- .icon {
- width: 1.4em;
- height: 1.4em;
- overflow: hidden;
- vertical-align: -0.15em;
- fill: currentcolor;
- }
- }
- </style>
- <style lang="scss" scoped>
- .page-content {
- width: 100%;
- height: 100%;
- padding: 0 !important;
- background: transparent !important;
- border: none !important;
- box-shadow: none !important;
- $box-radius: calc(var(--custom-radius) + 4px);
- .box-style {
- border: 1px solid var(--art-border-color);
- }
- .content {
- position: relative;
- display: flex;
- justify-content: space-between;
- margin-top: 10px;
- .left-wrap {
- width: 450px;
- margin-right: 25px;
- .user-wrap {
- position: relative;
- height: 600px;
- padding: 35px 40px;
- overflow: hidden;
- text-align: center;
- background: var(--art-main-bg-color);
- border-radius: $box-radius;
- .bg {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 200px;
- object-fit: cover;
- }
- .avatar {
- position: relative;
- z-index: 10;
- width: 80px;
- height: 80px;
- margin-top: 120px;
- object-fit: cover;
- border: 2px solid #fff;
- border-radius: 50%;
- }
- .name {
- margin-top: 20px;
- font-size: 22px;
- font-weight: 400;
- }
- .des {
- margin-top: 20px;
- font-size: 14px;
- }
- .outer-info {
- width: 300px;
- margin: auto;
- margin-top: 30px;
- text-align: left;
- > div {
- margin-top: 10px;
- span {
- margin-left: 8px;
- font-size: 14px;
- }
- }
- }
- .lables {
- margin-top: 40px;
- h3 {
- font-size: 15px;
- font-weight: 500;
- }
- > div {
- display: flex;
- flex-wrap: wrap;
- justify-content: center;
- margin-top: 15px;
- > div {
- padding: 3px 6px;
- margin: 0 10px 10px 0;
- font-size: 12px;
- background: var(--art-main-bg-color);
- border: 1px solid var(--art-border-color);
- border-radius: 2px;
- }
- }
- }
- }
- .gallery {
- margin-top: 25px;
- border-radius: 10px;
- .item {
- img {
- width: 100%;
- height: 100%;
- object-fit: cover;
- }
- }
- }
- }
- .right-wrap {
- flex: 1;
- overflow: hidden;
- border-radius: $box-radius;
- .info {
- background: var(--art-main-bg-color);
- border-radius: $box-radius;
- .title {
- padding: 15px 25px;
- font-size: 20px;
- font-weight: 400;
- color: var(--art-text-gray-800);
- border-bottom: 1px solid var(--art-border-color);
- }
- .form {
- box-sizing: border-box;
- padding: 30px 25px;
- > .el-row {
- .el-form-item {
- width: calc(50% - 10px);
- }
- .el-input,
- .el-select {
- width: 100%;
- }
- }
- .right-input {
- margin-left: 20px;
- }
- .el-form-item-right {
- display: flex;
- align-items: center;
- justify-content: end;
- .el-button {
- width: 110px !important;
- }
- }
- }
- }
- }
- }
- }
- @media only screen and (max-width: $device-ipad-vertical) {
- .page-content {
- .content {
- display: block;
- margin-top: 5px;
- .left-wrap {
- width: 100%;
- }
- .right-wrap {
- width: 100%;
- margin-top: 15px;
- }
- }
- }
- }
- </style>
|