¶Ô±ÈÐÂÎļþ |
| | |
| | | <!-- |
| | | * @Author: lzhe lzhe@example.com |
| | | * @Date: 2024-09-06 14:09:39 |
| | | * @LastEditors: lzhe lzhe@example.com |
| | | * @LastEditTime: 2024-10-09 11:30:37 |
| | | * @FilePath: /smart-web/src/views/usercenter.vue |
| | | * @Description: è¿æ¯é»è®¤è®¾ç½®,请设置`customMade`, æå¼koroFileHeaderæ¥çé
ç½® è¿è¡è®¾ç½®: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE |
| | | --> |
| | | <template> |
| | | <div class="user-main"> |
| | | <div class="user-title marB12">åºç¡ä¿¡æ¯</div> |
| | | <el-upload |
| | | :headers="authorization" |
| | | class="avatar-uploader" |
| | | action="/api/blade-resource/oss/endpoint/put-file" |
| | | :show-file-list="false" |
| | | :on-success="handleAvatarSuccess" |
| | | :before-upload="beforeAvatarUpload"> |
| | | <div v-if="baseData.avatar" style="position: relative;"> |
| | | <img :src="baseData.avatar" class="avatar"> |
| | | <div class="el-icon-editDom"> |
| | | <span class="el-icon-edit">ç¼è¾</span> |
| | | <span class="el-icon-del" @click.stop="avatarDel">å é¤</span> |
| | | </div> |
| | | </div> |
| | | <el-icon v-else class="el-icon-plus avatar-uploader-icon"><Picture /></el-icon> |
| | | </el-upload> |
| | | <div class="marB12" style="margin-top: 12px;"><span class="user-title">è´¦å·</span><span class="user-content">{{baseData.account}}</span></div> |
| | | <div class="marB12"> |
| | | <span class="user-title">è´¦å·æµç§°</span><span class="user-content">{{baseData.realName}}</span> |
| | | <el-icon v-if="isEditRealName" class="password-icon" @click="editRealName"><EditPen /></el-icon> |
| | | <div class="realNameRepeat" v-if="!isEditRealName"> |
| | | <el-input v-model="realNameRepeat" style="width: 240px" placeholder="请è¾å
¥" /> |
| | | <el-icon @click="realNameSub"><Check /></el-icon> |
| | | <el-icon @click="realNameClose"><Close /></el-icon> |
| | | </div> |
| | | </div> |
| | | <div class="marB12"><span class="user-title">ç»å½å¯ç </span><span class="user-content editPassword" @click="editPasswordModel = true">ç¹å»ä¿®æ¹</span></div> |
| | | </div> |
| | | <el-dialog title="ä¿®æ¹å¯ç " v-model="editPasswordModel" :width="800" destroy-on-close @closed="closeModel"> |
| | | <el-form :model="passwordForm" :rules="passwordRules" ref="dialogForm" label-width="120px" label-position="center"> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="åå¯ç " prop="oldPassword"> |
| | | <el-input placeholder="请è¾å
¥å¯ç " clearable v-model="passwordForm.oldPassword" show-password></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="æ°å¯ç " prop="newPassword"> |
| | | <el-input placeholder="请è¾å
¥å¯ç " clearable v-model="passwordForm.newPassword" show-password></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="确认å¯ç " prop="newPassword1"> |
| | | <el-input placeholder="请è¾å
¥å¯ç " clearable v-model="passwordForm.newPassword1" show-password></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | </el-form> |
| | | <template #footer> |
| | | <el-button @click="editPasswordModel=false" >å æ¶</el-button> |
| | | <el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="passwordSubmit">ç¡® å®</el-button> |
| | | </template> |
| | | </el-dialog> |
| | | </template> |
| | | |
| | | <script> |
| | | import * as ElementPlusIconsVue from '@element-plus/icons-vue' |
| | | let icons = [] |
| | | for (const [key, component] of Object.entries(ElementPlusIconsVue)) { |
| | | icons.push(key) |
| | | } |
| | | export default { |
| | | name: 'usercenter', |
| | | components: { |
| | | ...ElementPlusIconsVue |
| | | }, |
| | | data() { |
| | | return { |
| | | isEditRealName: true, |
| | | realNameRepeat: "", |
| | | baseData: {}, |
| | | //è¡¨åæ°æ® |
| | | passwordForm: { |
| | | oldPassword: "", |
| | | newPassword: "", |
| | | newPassword1: "" |
| | | }, |
| | | //éªè¯è§å |
| | | passwordRules: { |
| | | oldPassword: [{required: true, message: '请è¾å
¥åå¯ç '}], |
| | | newPassword: [{required: true, message: '请è¾å
¥æ°å¯ç '}], |
| | | newPassword1: [{required: true, message: '请è¾å
¥ç¡®è®¤å¯ç '}] |
| | | }, |
| | | authorization: {}, |
| | | titleMap: "ä¿®æ¹å¯ç ", |
| | | editPasswordModel: false |
| | | } |
| | | }, |
| | | mounted() { |
| | | this.getInfo(); |
| | | }, |
| | | methods: { |
| | | realNameSub() { |
| | | var obj = {...this.baseData}; |
| | | obj.realName = this.realNameRepeat; |
| | | this.updateData(); |
| | | }, |
| | | realNameClose() { |
| | | this.realNameRepeat = this.baseData.realName; |
| | | this.isEditRealName = !this.isEditRealName; |
| | | }, |
| | | editRealName() { |
| | | this.realNameRepeat = this.baseData.realName; |
| | | this.isEditRealName = !this.isEditRealName; |
| | | }, |
| | | getInfo() { |
| | | this.$HTTP.get(`/api/blade-user/info`).then(res=> { |
| | | if(res.code == 200) { |
| | | this.baseData = res.data; |
| | | this.realNameRepeat = res.data.realName; |
| | | }else { |
| | | this.$alert(res.message, "æç¤º", {type: 'error'}); |
| | | } |
| | | }) |
| | | }, |
| | | passwordSubmit() { |
| | | this.$refs.dialogForm.validate(async (valid) => { |
| | | if (valid) { |
| | | this.$HTTP.post(`/api/blade-user/update-password?oldPassword=${this.passwordForm.oldPassword}&newPassword=${this.passwordForm.newPassword}&newPassword1=${this.passwordForm.newPassword1}`).then(res=> { |
| | | if(res.code == 200) { |
| | | this.editPasswordModel = false; |
| | | this.$message.success("æä½æå"); |
| | | }else { |
| | | this.$alert(res.message, "æç¤º", {type: 'error'}); |
| | | } |
| | | }) |
| | | }else{ |
| | | return false; |
| | | } |
| | | }) |
| | | }, |
| | | closeModel(flag) { |
| | | console.log(flag); |
| | | this.passwordForm = { |
| | | oldPassword: "", |
| | | newPassword: "", |
| | | newPassword1: "" |
| | | } |
| | | }, |
| | | avatarDel() { |
| | | this.baseData.avatar = ""; |
| | | this.updateData(); |
| | | }, |
| | | updateData() { |
| | | this.$HTTP.post(`/api/blade-user/update-info`,this.baseData).then(res=> { |
| | | if(res.code == 200) { |
| | | this.getInfo(); |
| | | this.isEditRealName = true; |
| | | }else { |
| | | this.$alert(res.message, "æç¤º", {type: 'error'}); |
| | | } |
| | | }) |
| | | }, |
| | | handleAvatarSuccess(file) { |
| | | this.baseData.avatar = file.data.link; |
| | | this.updateData(); |
| | | }, |
| | | beforeAvatarUpload(file) { |
| | | var isJPG = (file.type === 'image/jpeg' || file.type === 'image/png'); |
| | | if (!isJPG) { |
| | | this.$message.error('请ä¸ä¼ å¾çï¼'); |
| | | } |
| | | var TOKEN = this.$TOOL.cookie.get("TOKEN") |
| | | this.authorization = {Authorization: 'Basic c2FiZXI6c2FiZXJfc2VjcmV0','Blade-Auth': TOKEN} |
| | | return isJPG; |
| | | }, |
| | | } |
| | | } |
| | | </script> |
| | | <style scoped> |
| | | .user-main { |
| | | background-color: #f9fafb; |
| | | border: 1px solid #dcdfe6; |
| | | box-shadow: 0 2px 4px 0 rgba(0,0,0,.12), 0 0 6px 0 rgba(0,0,0,.04); |
| | | margin: 8px; |
| | | padding: 16px 20px; |
| | | background-color: #fff; |
| | | } |
| | | .user-title { |
| | | font-weight: 700; |
| | | font-size: 16px; |
| | | margin-right: 12px; |
| | | } |
| | | .marB12 { |
| | | margin-bottom: 12px; |
| | | } |
| | | .user-content { |
| | | color: #303133; |
| | | font-size: 16px; |
| | | } |
| | | .editPassword { |
| | | color: #409eff; |
| | | cursor: pointer; |
| | | margin-right: 6px; |
| | | } |
| | | .realNameRepeat { |
| | | display: inline-block; |
| | | margin-left: 12px; |
| | | } |
| | | .realNameRepeat i { |
| | | font-size: 16px; |
| | | vertical-align: middle; |
| | | margin-left: 8px; |
| | | cursor: pointer; |
| | | color: #409eff; |
| | | } |
| | | .password-icon { |
| | | font-size: 14px; |
| | | vertical-align: text-top; |
| | | cursor: pointer; |
| | | margin-left: 6px; |
| | | } |
| | | .avatar-uploader .el-upload { |
| | | border: 1px dashed #d9d9d9; |
| | | border-radius: 6px; |
| | | cursor: pointer; |
| | | position: relative; |
| | | overflow: hidden; |
| | | } |
| | | .avatar-uploader .el-upload:hover { |
| | | border-color: #409EFF; |
| | | } |
| | | .avatar-uploader-icon { |
| | | font-size: 28px; |
| | | color: #8c939d; |
| | | width: 80px; |
| | | height: 80px; |
| | | line-height: 80px; |
| | | text-align: center; |
| | | background-color: #c0c4cc; |
| | | } |
| | | .el-icon-editDom { |
| | | position: absolute; |
| | | left: 4px; |
| | | top: 56px; |
| | | font-weight: 700; |
| | | color: #409eff; |
| | | } |
| | | .el-icon-editDom span { |
| | | margin: 0; |
| | | padding: 0; |
| | | font-size: 12px; |
| | | line-height: 18px; |
| | | border: 1px solid #409eff; |
| | | background: #fff; |
| | | padding-left: 2px; |
| | | padding-right: 2px; |
| | | cursor: pointer; |
| | | } |
| | | .el-icon-editDom .el-icon-edit { |
| | | margin-right: 4px; |
| | | } |
| | | .el-icon-editDom .el-icon-del { |
| | | |
| | | } |
| | | .avatar { |
| | | width: 80px; |
| | | height: 80px; |
| | | display: block; |
| | | } |
| | | </style> |