Repository navigation
Expand file tree
/
Copy pathadminSet.vue
More file actions
128 lines (124 loc) · 3.58 KB
/
Copy pathadminSet.vue
File metadata and controls
128 lines (124 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<template>
<div class="fillcontain">
<head-top></head-top>
<header class="admin_title">管理员信息</header>
<div class="admin_set">
<ul>
<li>
<span>姓名:</span><span>{{adminInfo.user_name}}</span>
</li>
<li>
<span>注册时间:</span><span>{{adminInfo.create_time}}</span>
</li>
<li>
<span>管理员权限:</span><span>{{adminInfo.admin}}</span>
</li>
<li>
<span>管理员 ID:</span><span>{{adminInfo.id}}</span>
</li>
<li>
<span>更换头像:</span>
<el-upload
class="avatar-uploader"
:action="baseUrl + '/admin/update/avatar/' + adminInfo.id"
:show-file-list="false"
:on-success="uploadImg"
:before-upload="beforeImgUpload">
<img v-if="adminInfo.avatar" :src="baseImgPath + adminInfo.avatar" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</li>
</ul>
</div>
</div>
</template>
<script>
import headTop from '../components/headTop'
import {mapState} from 'vuex'
import {baseUrl, baseImgPath} from '@/config/env'
export default {
data(){
return {
baseUrl,
baseImgPath,
}
},
components: {
headTop,
},
computed: {
...mapState(['adminInfo']),
},
methods: {
uploadImg(res, file) {
if (res.status == 1) {
this.adminInfo.avatar = res.image_path;
}else{
this.$message.error('上传图片失败!');
}
},
beforeImgUpload(file) {
const isRightType = (file.type === 'image/jpeg') || (file.type === 'image/png');
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isRightType) {
this.$message.error('上传头像图片只能是 JPG 格式!');
}
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 2MB!');
}
return isRightType && isLt2M;
},
},
}
</script>
<style lang="less">
@import '../style/mixin';
.explain_text{
margin-top: 20px;
text-align: center;
font-size: 20px;
color: #333;
}
.admin_set{
width: 60%;
background-color: #F9FAFC;
min-height: 400px;
margin: 20px auto 0;
border-radius: 10px;
ul > li{
padding: 20px;
span{
color: #666;
}
}
}
.admin_title{
margin-top: 20px;
.sc(24px, #666);
text-align: center;
}
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
margin-top: 10px;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #20a0ff;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 120px;
height: 120px;
line-height: 120px;
text-align: center;
}
.avatar {
width: 120px;
height: 120px;
display: block;
}
</style>