|
@@ -0,0 +1,149 @@
|
|
1
|
+<template>
|
|
2
|
+ <el-dialog
|
|
3
|
+ :visible.sync="dialogVisible"
|
|
4
|
+ :before-close="handleCancel"
|
|
5
|
+ class="selectImg-dialog"
|
|
6
|
+ :title="title"
|
|
7
|
+ width="550px"
|
|
8
|
+ :close-on-click-modal="false"
|
|
9
|
+ append-to-body
|
|
10
|
+ >
|
|
11
|
+ <div class="content-wrap" v-loading="loading">
|
|
12
|
+ <el-upload
|
|
13
|
+ ref="upload"
|
|
14
|
+ class="upload-demo"
|
|
15
|
+ :action="URL.BASEURL + URL.media_upload"
|
|
16
|
+ :before-upload="beforeAvatarUpload"
|
|
17
|
+ :on-success="uploadSuccess"
|
|
18
|
+ :on-progress='beforeUploadUpload'
|
|
19
|
+ :on-error='uploadFail'
|
|
20
|
+ :on-exceed="handleExceed"
|
|
21
|
+ :file-list="fileList"
|
|
22
|
+ accept=".jpg,.jpeg,.png"
|
|
23
|
+ name="file"
|
|
24
|
+ :data="fileData"
|
|
25
|
+ :show-file-list="true"
|
|
26
|
+ list-type="picture"
|
|
27
|
+ :multiple="false"
|
|
28
|
+ :limit="1"
|
|
29
|
+ drag
|
|
30
|
+ >
|
|
31
|
+ <div>
|
|
32
|
+ <i class="el-icon-upload"></i>
|
|
33
|
+ <div class="el-upload__text">将图片拖到此处,或<em>点击上传</em></div>
|
|
34
|
+ <div slot="tip" class="el-upload__tip">*图片仅支持png或jpg格式,且文件大小不得超过10M。</div>
|
|
35
|
+ </div>
|
|
36
|
+ </el-upload>
|
|
37
|
+ </div>
|
|
38
|
+ <div slot="footer" class="dialog-footer">
|
|
39
|
+ <el-button size="mini" @click="handleCancel">关 闭</el-button>
|
|
40
|
+ <el-button size="mini" type="primary" @click="handleConfirm">确 定</el-button>
|
|
41
|
+ </div>
|
|
42
|
+ </el-dialog>
|
|
43
|
+</template>
|
|
44
|
+
|
|
45
|
+<script>
|
|
46
|
+export default {
|
|
47
|
+ props: {
|
|
48
|
+ // 控制弹框是否显示
|
|
49
|
+ dialogVisible: {
|
|
50
|
+ type: Boolean,
|
|
51
|
+ default: () => false
|
|
52
|
+ },
|
|
53
|
+ },
|
|
54
|
+ data() {
|
|
55
|
+ return {
|
|
56
|
+ loading: false,
|
|
57
|
+ fileList: [],
|
|
58
|
+ fileData: {
|
|
59
|
+ admin_id: this.$cookie.getCookie('admin_id'),
|
|
60
|
+ ttl: this.$cookie.getCookie('ttl'),
|
|
61
|
+ sign: this.$cookie.getCookie('sign'),
|
|
62
|
+ corpid: this.$localSelfStore.getLocal('defaultCorp') && this.$localSelfStore.getLocal('defaultCorp') != 'undefined' ? JSON.parse(this.$localSelfStore.getLocal('defaultCorp')).corpid : '',
|
|
63
|
+ type: 1,//素材类型。1图片 2语音 3视频
|
|
64
|
+ },
|
|
65
|
+
|
|
66
|
+ }
|
|
67
|
+ },
|
|
68
|
+ computed: {
|
|
69
|
+ title() {
|
|
70
|
+ return `更换图片`
|
|
71
|
+ },
|
|
72
|
+ },
|
|
73
|
+ watch: {
|
|
74
|
+ dialogVisible(isShow) {
|
|
75
|
+ if (isShow) {
|
|
76
|
+ // this.$refs.upload.clearFiles()
|
|
77
|
+ } else {
|
|
78
|
+ this.$refs.upload.clearFiles()
|
|
79
|
+ }
|
|
80
|
+ },
|
|
81
|
+ },
|
|
82
|
+ methods: {
|
|
83
|
+ // 限制上传一个文件,重新选择文件替换原来的文件
|
|
84
|
+ handleExceed(files, fileList) {
|
|
85
|
+ this.$message.error('最多只能上传一张图片')
|
|
86
|
+ },
|
|
87
|
+ beforeAvatarUpload(file) {
|
|
88
|
+ const isLt10M = file.size / 1024 / 1024 < 10;
|
|
89
|
+ if (!isLt10M) {
|
|
90
|
+ this.$message.error('上传头像图片大小不能超过 10MB!');
|
|
91
|
+ }
|
|
92
|
+ return isLt10M;
|
|
93
|
+ },
|
|
94
|
+ // 上传成功
|
|
95
|
+ uploadSuccess (res, file) {
|
|
96
|
+ this.$loading(this.$loadingConfig).close();
|
|
97
|
+ if (res.errno == 0) {
|
|
98
|
+ this.$message({
|
|
99
|
+ message: '上传成功',
|
|
100
|
+ type: 'success'
|
|
101
|
+ })
|
|
102
|
+ } else {
|
|
103
|
+ this.$message({
|
|
104
|
+ message: res.err,
|
|
105
|
+ type: 'warning'
|
|
106
|
+ })
|
|
107
|
+ }
|
|
108
|
+ },
|
|
109
|
+ beforeUploadUpload (file) {
|
|
110
|
+ this.$loading(this.$loadingConfig);
|
|
111
|
+ },
|
|
112
|
+ // 上传失败
|
|
113
|
+ uploadFail (file) {
|
|
114
|
+ this.$loading(this.$loadingConfig).close();
|
|
115
|
+ this.$message({
|
|
116
|
+ message: '上传失败',
|
|
117
|
+ type: 'fail'
|
|
118
|
+ })
|
|
119
|
+ let idx = this.$refs.upload.uploadFiles.findIndex(item => item.uid === file.uid)
|
|
120
|
+ this.$refs.upload.uploadFiles.splice(idx, 1)
|
|
121
|
+ },
|
|
122
|
+ handleCancel() {
|
|
123
|
+ this.$emit('cancel')
|
|
124
|
+ },
|
|
125
|
+ handleConfirm() {
|
|
126
|
+ console.log('this.$refs.upload.uploadFiles => ', this.$refs.upload.uploadFiles)
|
|
127
|
+ console.log('fileList => ', this.fileList)
|
|
128
|
+ const { uploadFiles } = this.$refs.upload
|
|
129
|
+ if (!uploadFiles || !uploadFiles.length) {
|
|
130
|
+ return this.$message.warning('请上传更换图片')
|
|
131
|
+ }
|
|
132
|
+ this.$emit('confirm', uploadFiles[0].response.rst.url)
|
|
133
|
+ },
|
|
134
|
+ },
|
|
135
|
+};
|
|
136
|
+</script>
|
|
137
|
+
|
|
138
|
+<style lang="scss" scoped>
|
|
139
|
+.selectImg-dialog {
|
|
140
|
+ .content-wrap {
|
|
141
|
+ display: flex;
|
|
142
|
+ align-items: center;
|
|
143
|
+ justify-content: center;
|
|
144
|
+ }
|
|
145
|
+ .dialog-footer {
|
|
146
|
+ text-align: center;
|
|
147
|
+ }
|
|
148
|
+}
|
|
149
|
+</style>
|