|
|
1
|
+<template>
|
|
|
2
|
+ <div>
|
|
|
3
|
+ <Modal
|
|
|
4
|
+ width="800"
|
|
|
5
|
+ v-model="showModal"
|
|
|
6
|
+ title="图片"
|
|
|
7
|
+ @on-ok="insertImage"
|
|
|
8
|
+ ok-text="保存"
|
|
|
9
|
+ class="multi-image">
|
|
|
10
|
+ <Row :gutter="16">
|
|
|
11
|
+ <Col span="10">
|
|
|
12
|
+ <Input v-model="file" placeholder="请输入地址" @on-enter="addFile"/>
|
|
|
13
|
+
|
|
|
14
|
+ </Col>
|
|
|
15
|
+ <Col span="8">
|
|
|
16
|
+ <Button type="primary" @click="addFile">确定</Button>
|
|
|
17
|
+ </Col>
|
|
|
18
|
+ </Row>
|
|
|
19
|
+ <br />
|
|
|
20
|
+ <Upload
|
|
|
21
|
+ ref="upload"
|
|
|
22
|
+ multiple
|
|
|
23
|
+ type="drag"
|
|
|
24
|
+ :data="{bucket: 'goodsimg'}"
|
|
|
25
|
+ :max-size="2048"
|
|
|
26
|
+ :format="['jpg','jpeg','png']"
|
|
|
27
|
+ :show-upload-list="false"
|
|
|
28
|
+ :on-format-error="handleFormatError"
|
|
|
29
|
+ :on-exceeded-size="handleMaxSize"
|
|
|
30
|
+ :on-success="handleSuccess"
|
|
|
31
|
+ :on-error="handleError"
|
|
|
32
|
+ action="/Api/upload/image">
|
|
|
33
|
+ <div style="padding: 20px 0">
|
|
|
34
|
+ <Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
|
|
|
35
|
+ <p>点击或将文件拖拽到这里上传</p>
|
|
|
36
|
+ </div>
|
|
|
37
|
+ </Upload>
|
|
|
38
|
+ <div class="upload-list" v-for="item in fileList">
|
|
|
39
|
+ <template v-if="item.status === 'finished'">
|
|
|
40
|
+ <img :src="item.url">
|
|
|
41
|
+ <div class="upload-list-cover">
|
|
|
42
|
+ <Icon type="ios-eye-outline" @click.native="handleView(item)"></Icon>
|
|
|
43
|
+ <Icon type="ios-trash-outline" @click.native="handleRemove(item)"></Icon>
|
|
|
44
|
+ </div>
|
|
|
45
|
+ </template>
|
|
|
46
|
+ <template v-else>
|
|
|
47
|
+ <Progress v-if="item.showProgress" :percent="item.percentage" hide-info></Progress>
|
|
|
48
|
+ </template>
|
|
|
49
|
+ </div>
|
|
|
50
|
+ </Modal>
|
|
|
51
|
+ <Modal title="查看图片" v-model="visible">
|
|
|
52
|
+ <img :src="imgUrl" v-if="visible" style="width: 100%">
|
|
|
53
|
+ </Modal>
|
|
|
54
|
+ </div>
|
|
|
55
|
+</template>
|
|
|
56
|
+
|
|
|
57
|
+<script>
|
|
|
58
|
+import _ from 'lodash';
|
|
|
59
|
+export default {
|
|
|
60
|
+ name: 'MultiImage',
|
|
|
61
|
+ created() {
|
|
|
62
|
+ this.$watch('$parent.dashboard', () => {
|
|
|
63
|
+ this.$parent.dashboard === 'dashboard-multi-image' && (this.showModal = true);
|
|
|
64
|
+ });
|
|
|
65
|
+ },
|
|
|
66
|
+ data() {
|
|
|
67
|
+ return {
|
|
|
68
|
+ showModal: true,
|
|
|
69
|
+ fileList: [],
|
|
|
70
|
+ imgUrl: '',
|
|
|
71
|
+ file: '',
|
|
|
72
|
+ visible: false
|
|
|
73
|
+ };
|
|
|
74
|
+ },
|
|
|
75
|
+ methods: {
|
|
|
76
|
+ handleView(item) {
|
|
|
77
|
+ this.imgUrl = item.url;
|
|
|
78
|
+ this.visible = true;
|
|
|
79
|
+ },
|
|
|
80
|
+ handleRemove(file) {
|
|
|
81
|
+ // 从 upload 实例删除数据
|
|
|
82
|
+ let fileList = this.$refs.upload.fileList;
|
|
|
83
|
+
|
|
|
84
|
+ this.$refs.upload.fileList.splice(fileList.indexOf(file), 1);
|
|
|
85
|
+ },
|
|
|
86
|
+ handleFormatError(file) {
|
|
|
87
|
+ this.$Notice.warning({
|
|
|
88
|
+ title: '文件格式不正确',
|
|
|
89
|
+ desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
|
|
|
90
|
+ });
|
|
|
91
|
+ },
|
|
|
92
|
+ handleMaxSize(file) {
|
|
|
93
|
+ this.$Notice.warning({
|
|
|
94
|
+ title: '超出文件大小限制',
|
|
|
95
|
+ desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
|
|
|
96
|
+ });
|
|
|
97
|
+ },
|
|
|
98
|
+ handleSuccess(response, file) {
|
|
|
99
|
+ let url = _.get(response, 'data.imagesList[0]');
|
|
|
100
|
+
|
|
|
101
|
+ if (url) {
|
|
|
102
|
+ file.url = url;
|
|
|
103
|
+ }
|
|
|
104
|
+ },
|
|
|
105
|
+ handleError(error) {
|
|
|
106
|
+ this.$Notice.error(error);
|
|
|
107
|
+ },
|
|
|
108
|
+ insertImage() {
|
|
|
109
|
+ _.each(this.fileList, file => {
|
|
|
110
|
+ this.$parent.execCommand('insertImage', file.url);
|
|
|
111
|
+ });
|
|
|
112
|
+ },
|
|
|
113
|
+ addFile() {
|
|
|
114
|
+ if (this.file) {
|
|
|
115
|
+ this.fileList.push({
|
|
|
116
|
+ name: '',
|
|
|
117
|
+ status: 'finished',
|
|
|
118
|
+ url: this.file,
|
|
|
119
|
+ uid: ''
|
|
|
120
|
+ });
|
|
|
121
|
+ this.file = '';
|
|
|
122
|
+ }
|
|
|
123
|
+ }
|
|
|
124
|
+ },
|
|
|
125
|
+ watch: {
|
|
|
126
|
+ showModal(val) {
|
|
|
127
|
+ if (!val) {
|
|
|
128
|
+ this.fileList = this.$refs.upload.fileList = [];
|
|
|
129
|
+ this.$parent.dashboard = null;
|
|
|
130
|
+ }
|
|
|
131
|
+ }
|
|
|
132
|
+ },
|
|
|
133
|
+ mounted() {
|
|
|
134
|
+ this.fileList = this.$refs.upload.fileList;
|
|
|
135
|
+ }
|
|
|
136
|
+};
|
|
|
137
|
+</script>
|
|
|
138
|
+<style lang="scss">
|
|
|
139
|
+.multi-image {
|
|
|
140
|
+ .upload-list {
|
|
|
141
|
+ margin-top: 20px;
|
|
|
142
|
+ display: inline-block;
|
|
|
143
|
+ width: 60px;
|
|
|
144
|
+ height: 60px;
|
|
|
145
|
+ text-align: center;
|
|
|
146
|
+ line-height: 60px;
|
|
|
147
|
+ border: 1px solid transparent;
|
|
|
148
|
+ border-radius: 4px;
|
|
|
149
|
+ overflow: hidden;
|
|
|
150
|
+ background: #fff;
|
|
|
151
|
+ position: relative;
|
|
|
152
|
+ box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
|
|
|
153
|
+ margin-right: 4px;
|
|
|
154
|
+ }
|
|
|
155
|
+
|
|
|
156
|
+ .upload-list img {
|
|
|
157
|
+ width: 100%;
|
|
|
158
|
+ height: 100%;
|
|
|
159
|
+ }
|
|
|
160
|
+
|
|
|
161
|
+ .upload-list-cover {
|
|
|
162
|
+ display: none;
|
|
|
163
|
+ position: absolute;
|
|
|
164
|
+ top: 0;
|
|
|
165
|
+ bottom: 0;
|
|
|
166
|
+ left: 0;
|
|
|
167
|
+ right: 0;
|
|
|
168
|
+ background: rgba(0, 0, 0, 0.6);
|
|
|
169
|
+ }
|
|
|
170
|
+
|
|
|
171
|
+ .upload-list:hover .upload-list-cover {
|
|
|
172
|
+ display: block;
|
|
|
173
|
+ }
|
|
|
174
|
+
|
|
|
175
|
+ .upload-list-cover i {
|
|
|
176
|
+ color: #fff;
|
|
|
177
|
+ font-size: 20px;
|
|
|
178
|
+ cursor: pointer;
|
|
|
179
|
+ margin: 0 2px;
|
|
|
180
|
+ }
|
|
|
181
|
+}
|
|
|
182
|
+
|
|
|
183
|
+</style> |