Commit c1dfa424e23ad1180fead8860c9a26b606219bd3
1 parent
89ab0203
添加页面
Showing
2 changed files
with
208 additions
and
0 deletions
src/assets/images/meun/专项行动处理.png
0 → 100644
1.6 KB
src/views/homePage/components/UserInfoPage.vue
0 → 100644
| 1 | +<template> | |
| 2 | + <el-dialog | |
| 3 | + title="修改信息" | |
| 4 | + :close-on-click-modal="false" | |
| 5 | + :visible.sync="visible" | |
| 6 | + class="NCC-dialog NCC-dialog_center userInfo" | |
| 7 | + lock-scroll | |
| 8 | + width="600px" | |
| 9 | + v-loading="loading" | |
| 10 | + > | |
| 11 | + <el-row class="infoContent"> | |
| 12 | + <div class="head"> | |
| 13 | + <el-upload | |
| 14 | + class="avatar-uploader" | |
| 15 | + :action="define.comUploadUrl + '/userAvatar'" | |
| 16 | + :headers="uploadHeaders" | |
| 17 | + :on-success="handleSuccess" | |
| 18 | + :show-file-list="false" | |
| 19 | + accept="image/*" | |
| 20 | + > | |
| 21 | + <div class="avatar-box"> | |
| 22 | + <el-avatar :size="80" :src="avatar" class="avatar" v-if="avatar"/> | |
| 23 | + <div class="avatar-hover">更换头像</div> | |
| 24 | + </div> | |
| 25 | + </el-upload> | |
| 26 | + <!-- <span class="username">{{ user.realName }}</span> --> | |
| 27 | + </div> | |
| 28 | + <el-form class="infoForm" ref="form" :model="user" :rules="rules" label-width="80px"> | |
| 29 | + <el-form-item label="用户名" prop="realName"> | |
| 30 | + <el-input | |
| 31 | + v-model="user.realName" | |
| 32 | + placeholder="请输入用户名" | |
| 33 | + /> | |
| 34 | + </el-form-item> | |
| 35 | + </el-form> | |
| 36 | + </el-row> | |
| 37 | + | |
| 38 | + <span slot="footer" class="dialog-footer"> | |
| 39 | + <el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">保存</el-button> | |
| 40 | + <el-button type="danger" @click="visible = false">关闭</el-button> | |
| 41 | + </span> | |
| 42 | + </el-dialog> | |
| 43 | +</template> | |
| 44 | +<script> | |
| 45 | +import { | |
| 46 | + UserSettingInfo, | |
| 47 | + UpdateAvatar, | |
| 48 | +} from "@/api/permission/userSetting"; | |
| 49 | +import request from "@/utils/request"; | |
| 50 | +import define from "@/utils/define"; | |
| 51 | +export default { | |
| 52 | + components: {}, | |
| 53 | + props: [], | |
| 54 | + data() { | |
| 55 | + return { | |
| 56 | + loading: false, | |
| 57 | + visible: false, | |
| 58 | + btnLoading: false, | |
| 59 | + user: { | |
| 60 | + realName: '', | |
| 61 | + }, | |
| 62 | + uploadHeaders: { Authorization: this.$store.getters.token }, | |
| 63 | + rules: { | |
| 64 | + realName: [ | |
| 65 | + { required: true, message: "用户名不能为空", trigger: "blur" }, | |
| 66 | + ], | |
| 67 | + } | |
| 68 | + }; | |
| 69 | + }, | |
| 70 | + computed: { | |
| 71 | + avatar() { | |
| 72 | + return define.comUrl + this.$store.state.user.avatar; | |
| 73 | + } | |
| 74 | + }, | |
| 75 | + watch: {}, | |
| 76 | + created() {}, | |
| 77 | + mounted() {}, | |
| 78 | + methods: { | |
| 79 | + goBack() { | |
| 80 | + this.$emit("refresh"); | |
| 81 | + }, | |
| 82 | + init() { | |
| 83 | + this.visible = true; | |
| 84 | + this.loading = true; | |
| 85 | + this.getInfo(); | |
| 86 | + }, | |
| 87 | + getInfo() { | |
| 88 | + UserSettingInfo().then((res) => { | |
| 89 | + this.user = res.data; | |
| 90 | + this.loading = false; | |
| 91 | + }).catch(() => this.loading = false); | |
| 92 | + }, | |
| 93 | + // 头像 | |
| 94 | + handleSuccess(res, file) { | |
| 95 | + if (res.code == 200) { | |
| 96 | + this.updateAvatar(res.data); | |
| 97 | + } else { | |
| 98 | + this.$message({ | |
| 99 | + message: "上传失败", | |
| 100 | + type: "error", | |
| 101 | + duration: 1000, | |
| 102 | + }); | |
| 103 | + } | |
| 104 | + }, | |
| 105 | + updateAvatar(data) { | |
| 106 | + UpdateAvatar(data.name).then((res) => { | |
| 107 | + this.user.avatar = data.url; | |
| 108 | + this.$store.commit("SET_AVATAR", data.url); | |
| 109 | + this.$message({ | |
| 110 | + message: res.msg, | |
| 111 | + type: "success", | |
| 112 | + duration: 1000, | |
| 113 | + }); | |
| 114 | + }); | |
| 115 | + }, | |
| 116 | + dataFormSubmit() { | |
| 117 | + this.btnLoading = true; | |
| 118 | + this.$refs["form"].validate(async (valid) => { | |
| 119 | + if(valid) { | |
| 120 | + request({ | |
| 121 | + url: `/permission/users/${this.user.id}`, | |
| 122 | + method: 'PUT', | |
| 123 | + data: { realName: this.user.realName } | |
| 124 | + }).then((res) => { | |
| 125 | + this.$store.commit("SET_NAME", this.user.realName); | |
| 126 | + this.$message({ | |
| 127 | + message: res.msg, | |
| 128 | + type: "success", | |
| 129 | + duration: 1000, | |
| 130 | + }); | |
| 131 | + this.visible = false; | |
| 132 | + this.$emit("refresh"); | |
| 133 | + }).catch(() => this.btnLoading = false) | |
| 134 | + } | |
| 135 | + }) | |
| 136 | + | |
| 137 | + }, | |
| 138 | + }, | |
| 139 | +}; | |
| 140 | +</script> | |
| 141 | +<style lang="scss" scoped> | |
| 142 | +.userInfo { | |
| 143 | + .infoContent { | |
| 144 | + display: flex; | |
| 145 | + flex-direction: row; | |
| 146 | + align-items: center; | |
| 147 | + justify-content: flex-start; | |
| 148 | + height: 100px; | |
| 149 | + margin-bottom: 20px; | |
| 150 | + .infoForm { | |
| 151 | + flex: 1; | |
| 152 | + margin-top: 30px; | |
| 153 | + } | |
| 154 | + } | |
| 155 | + .head { | |
| 156 | + position: relative; | |
| 157 | + left: 10px; | |
| 158 | + top: 10px; | |
| 159 | + height: 90px; | |
| 160 | + width: 100px; | |
| 161 | + padding-top: 10px; | |
| 162 | + .avatar-uploader { | |
| 163 | + display: inline-block; | |
| 164 | + vertical-align: top; | |
| 165 | + .avatar-hover { | |
| 166 | + position: absolute; | |
| 167 | + left: 0; | |
| 168 | + top: 0; | |
| 169 | + font-size: 12px; | |
| 170 | + display: none; | |
| 171 | + overflow: hidden; | |
| 172 | + width: 80px; | |
| 173 | + height: 80px; | |
| 174 | + text-align: center; | |
| 175 | + border-radius: 50%; | |
| 176 | + line-height: 80px; | |
| 177 | + color: #fff; | |
| 178 | + cursor: pointer; | |
| 179 | + background: rgba(0, 0, 0, 0.5); | |
| 180 | + } | |
| 181 | + &:hover { | |
| 182 | + & .avatar-hover { | |
| 183 | + display: block; | |
| 184 | + } | |
| 185 | + } | |
| 186 | + } | |
| 187 | + .avatar-box { | |
| 188 | + position: relative; | |
| 189 | + } | |
| 190 | + .avatar { | |
| 191 | + display: inline-block; | |
| 192 | + width: 80px; | |
| 193 | + height: 80px; | |
| 194 | + overflow: hidden; | |
| 195 | + border-radius: 50%; | |
| 196 | + vertical-align: top; | |
| 197 | + margin-right: 10px; | |
| 198 | + } | |
| 199 | + .el-avatar>img { | |
| 200 | + width: 100%; | |
| 201 | + } | |
| 202 | + .username { | |
| 203 | + line-height: 80px; | |
| 204 | + font-size: 20px; | |
| 205 | + } | |
| 206 | + } | |
| 207 | +} | |
| 208 | +</style> | ... | ... |