Skip to content

Commit e7debc3

Browse files
committed
added avatar modal
1 parent 545b103 commit e7debc3

File tree

2 files changed

+116
-3
lines changed

2 files changed

+116
-3
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<template>
2+
<a-modal :visible="visible" title="修改头像" :maskClosable="false" :confirmLoading="confirmLoading" :width="800">
3+
<a-row>
4+
<a-col :span="12" :style="{height: '350px'}">
5+
<vue-cropper
6+
ref="cropper"
7+
:img="options.img"
8+
:info="true"
9+
:autoCrop="options.autoCrop"
10+
:autoCropWidth="options.autoCropWidth"
11+
:autoCropHeight="options.autoCropHeight"
12+
:fixedBox="options.fixedBox"
13+
@realTime="realTime"
14+
>
15+
</vue-cropper>
16+
</a-col>
17+
<a-col :span="12" :style="{height: '350px'}">
18+
<div class="avatar-upload-preview">
19+
<img :src="previews.url" :style="previews.img"/>
20+
</div>
21+
</a-col>
22+
</a-row>
23+
24+
<template slot="footer">
25+
<a-button key="back" @click="cancelHandel">取消</a-button>
26+
<a-button key="submit" type="primary" :loading="confirmLoading" @click="okHandel">保存</a-button>
27+
</template>
28+
</a-modal>
29+
</template>
30+
<script>
31+
import VueCropper from 'vue-cropper'
32+
33+
export default {
34+
components: {
35+
VueCropper
36+
},
37+
data() {
38+
return {
39+
visible: false,
40+
id: null,
41+
confirmLoading: false,
42+
43+
options: {
44+
img: 'http://ofyaji162.bkt.clouddn.com/bg1.jpg',
45+
autoCrop: true,
46+
autoCropWidth: 200,
47+
autoCropHeight: 200,
48+
fixedBox: true
49+
},
50+
previews: {},
51+
};
52+
},
53+
watch: {
54+
55+
},
56+
methods: {
57+
edit(id) {
58+
this.visible = true;
59+
this.id = id;
60+
/* 获取原始头像 */
61+
62+
},
63+
close() {
64+
this.id = null;
65+
this.visible = false;
66+
},
67+
cancelHandel() {
68+
this.close();
69+
},
70+
okHandel() {
71+
const vm = this
72+
73+
vm.confirmLoading = true
74+
setTimeout(() => {
75+
vm.confirmLoading = false
76+
vm.close()
77+
vm.$message.success('上传头像成功');
78+
}, 2000)
79+
80+
},
81+
82+
realTime(data) {
83+
this.previews = data
84+
}
85+
}
86+
};
87+
</script>
88+
89+
<style lang="scss" scoped>
90+
91+
.avatar-upload-preview {
92+
position: absolute;
93+
top: 50%;
94+
transform: translate(50%, -50%);
95+
width: 180px;
96+
height: 180px;
97+
border-radius: 50%;
98+
box-shadow: 0 0 4px #ccc;
99+
overflow: hidden;
100+
101+
img {
102+
width: 100%;
103+
height: 100%;
104+
}
105+
}
106+
</style>

src/views/account/settings/BaseSetting.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
</a-col>
5454
<a-col :md="24" :lg="8" :style="{ minHeight: '180px' }">
55-
<div class="ant-upload-preview" >
55+
<div class="ant-upload-preview" @click="$refs.modal.edit(1)" >
5656
<a-icon type="cloud-upload-o" class="upload-icon"/>
5757
<div class="mask">
5858
<a-icon type="plus" />
@@ -62,15 +62,19 @@
6262
</a-col>
6363

6464
</a-row>
65+
66+
<avatar-modal ref="modal">
67+
68+
</avatar-modal>
6569
</div>
6670
</template>
6771

6872
<script>
69-
import VueCropper from "vue-cropper/example/src/vue-cropper/vue-cropper"
73+
import AvatarModal from './AvatarModal'
7074
7175
export default {
7276
components: {
73-
VueCropper
77+
AvatarModal
7478
},
7579
data () {
7680
return {
@@ -92,6 +96,9 @@
9296
fixedNumber: [1, 1]
9397
}
9498
}
99+
},
100+
methods: {
101+
95102
}
96103
}
97104
</script>

0 commit comments

Comments
 (0)