HtViewer.vue
7.48 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<template>
<div>
<div
class="pic-card"
:body-style="{ padding: '0px', margin: '10px', cursor: 'pointer' }"
>
<div class="image">
<van-image v-if="showPicture && value" :src="picture" :style="style" />
<van-empty v-else :image="noImg" description="暂无签名" />
</div>
<div slot="header" class="buttoms">
<!-- <el-tooltip
class="item"
effect="dark"
content="图片格式:png 图片尺寸:250*70px"
placement="bottom"
> -->
<el-upload
v-if="isIndexPic"
accept=".png,.PNG"
class="upload-demo"
:action="actionUrl"
:headers="header"
name="files"
:show-file-list="false"
:on-success="success"
:on-progress="progress"
:before-upload="beforeAvatarUpload"
:multiple="false"
:limit="10"
:on-exceed="handleExceed"
>
<div>
<i class="icons icon-my-todo-upload"></i>
<span>上传签名</span>
</div>
<!-- <el-button circle icon="el-icon-upload2" title="上传"></el-button> -->
</el-upload>
<!-- </el-tooltip> -->
<el-upload
v-if="!isIndexPic"
accept=".png,.PNG"
class="upload-demo"
:action="actionUrl"
name="files"
:headers="header"
:show-file-list="false"
:on-success="success"
:on-progress="progress"
:before-upload="beforeAvatarUpload"
:multiple="false"
:limit="10"
:on-exceed="handleExceed"
>
<div>
<i class="icons icon-my-todo-upload"></i>
<span>上传签名</span>
</div>
<!-- <el-button circle icon="el-icon-upload2" title="上传"></el-button> -->
</el-upload>
<div @click="remove()">
<i class="icon icon-trash"></i>
<span>删除</span>
</div>
<!-- <el-button
icon="el-icon-delete"
circle
style="margin-left: 10px"
title="移除"
@click="remove()"
></el-button> -->
<!-- </el-row> -->
</div>
<!-- <el-collapse-transition> -->
<!-- </el-collapse-transition> -->
</div>
</div>
</template>
<script>
import req from '@/utils/request'
import { mapState } from 'vuex'
import { Loading } from 'element-ui'
import { Notify, Dialog } from 'vant'
export default {
name: 'HtViewer',
props: ['value', 'imgHeight', 'imgWidth', 'isIndexPic'],
data() {
return {
noImg: require('../assets/images/noImage.png'),
httpsFile: { fileName: '', url: '' },
dialogFormVisible: false,
showPicture: false,
openPicture: false,
style: {
width: '265px',
height: '180px',
borderRadius: '3px',
padding: '1px',
margin: '1px',
cursor: 'pointer',
},
imgArr: [],
options: {
inline: false,
button: true,
navbar: true,
title: false,
toolbar: true,
tooltip: true,
movable: true,
zoomable: true,
rotatable: true,
scalable: true,
transition: true,
fullscreen: true,
keyboard: true,
url: 'data-source',
},
picture: '',
}
},
computed: mapState({
header: (state) => {
return { Authorization: `Bearer ${state.login.currentUser.token}` }
},
actionUrl: function () {
return window.context.portal + '/system/file/v1/fileUpload'
},
}),
mounted() {
if (this.imgHeight > 0 && this.imgWidth > 0) {
this.style = {
height: this.imgHeight + 'px',
width: this.imgWidth + 'px',
}
}
this.$store.dispatch('menu/downloadImg', this.value).then((res) => {
if (res != '') {
this.picture = res
this.showPicture = true
}
})
},
created() {
this.$validator = this.$root.$validator
},
methods: {
handleExceed(files, fileList) {
// this.$message.warning(`上传图片前,先删除原有图片`);
},
progress() {
Loading.service('文件上传中')
},
//文件上传成功时
success(response, file, fileList) {
let loadingInstance = Loading.service('文件上传中')
const this_ = this
this.$store
.dispatch('menu/downloadImg', response.fileId)
.then((res) => {
if (res != '') {
this.picture = res
}
})
setTimeout(function () {
this_.$emit('input', response.fileId)
this_.showPicture = true
// 以服务的方式调用的 Loading 需要异步关闭
loadingInstance.close()
}, 1000)
},
beforeAvatarUpload(file) {
var FileExt = file.name.replace(/.+\./, '')
if (['png'].indexOf(FileExt.toLowerCase()) === -1) {
Notify({ type: 'warning', message: '请上传后缀名为png类型的图片!' })
return false
}
},
remove() {
if (!this.value) {
return
}
Dialog.confirm({
title: '提示',
message: '确定要删除吗?',
type: 'warning',
})
.then(() => {
this.$emit('input', '')
//签章附件不能删除,会导致已签章表单无法找到旧的签章附件
// if (this.value) {
// req
// .post(
// req.getContext().portal +
// "/system/file/v1/remove" ,
// this.value
// )
// .then((r) => {
// this.$emit("input", "");
// });
// }
})
.catch(() => {})
},
},
}
</script>
<style lang="scss" scoped>
ul {
display: flex;
flex-wrap: wrap;
}
ul li {
list-style: none;
}
.upload-demo {
display: inline-block;
}
.pic-card ::v-deep .el-card__header {
padding-top: 5px;
padding-bottom: 5px;
}
.pic-card {
padding: 16px;
}
.image {
// margin: 16px 16px 50px;
border: 1px solid #e6e6e6;
border-radius: 8px 8px 8px 8px;
height: 140px;
::v-deep .van-image {
width: 100% !important;
height: 100% !important;
padding: 0;
margin: 0 !important;
}
.van-image,
.van-empty {
width: 100%;
height: 100%;
}
::v-deep {
.van-empty__image {
width: 72px;
height: 52px;
}
.van-empty__description {
padding: 0;
margin: 0;
}
}
}
.buttoms {
margin-top: 13px;
display: flex;
align-items: center;
& > div {
display: flex;
justify-content: flex-start;
align-items: normal;
height: 22px !important;
line-height: 22px;
}
.icon {
font-size: 22px;
color: #409eff;
}
.icons {
margin: 3px;
font-size: 16px;
vertical-align: middle;
color: #409eff;
margin-right: 3px;
}
.icon + span,
.icons + span {
color: #409eff;
font-weight: 400;
font-size: 14px;
margin-left: 4px;
vertical-align: middle;
}
.upload-demo {
margin-right: 24px;
margin-bottom: 3px;
::v-deep .el-upload {
height: 22px;
line-height: 22px;
}
}
}
</style>