Canvas.vue
12.7 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<template>
<div style="position: relative; width: 100%; height: 100%">
<NavBar>
<template slot="title">签章管理</template>
</NavBar>
<div class="esign-div">
<van-tabs
v-model="active"
color="#409EFF"
title-active-color="#409EFF"
title-inactive-color="#262626"
>
<van-tab title="手写签名">
<div class="esign-div_content" @click="showPop = true">
<van-image
v-if="electronicSealFileUrl"
:src="electronicSealFileUrl"
/>
<van-empty v-else :image="noImg" description="暂无签名" />
</div>
</van-tab>
<van-tab title="上传签名">
<ht-viewer v-model="electronicSeal.fileId" ref="htViewer" />
</van-tab>
</van-tabs>
</div>
<div class="password_all">
<div>
<van-form ref="Form">
<van-field
v-model="electronicSeal.oldPassWord"
:type="electronicSealOldPassWord ? 'text' : 'password'"
autocomplete="off"
label="登录密码"
placeholder="请输入登录密码"
input-align="right"
@click-right-icon="clickPassword('electronicSealOldPassWord')"
>
<template #right-icon>
<i
:class="
!electronicSealOldPassWord ? 'icon-yincang' : 'icon-xianshi'
"
></i>
</template>
</van-field>
<van-field
v-model="electronicSeal.password"
:type="electronicSealPassword ? 'text' : 'password'"
autocomplete="off"
label="签章密码"
:error="false"
placeholder="请输入签章密码"
input-align="right"
:rules="[
{
validator,
message: '只能输入字母、数字、下划线,且以字母开头',
},
]"
@click-right-icon="clickPassword('electronicSealPassword')"
>
<template #right-icon>
<i
:class="
!electronicSealPassword ? 'icon-yincang' : 'icon-xianshi'
"
></i>
</template>
</van-field>
<van-field
v-model="electronicSeal.confirmPwd"
:type="electronicSealConfirmPwd ? 'text' : 'password'"
autocomplete="off"
label="确认密码"
placeholder="请输入确认密码"
input-align="right"
:error="false"
:rules="[
{
validator: validators,
message: '两次输入的值必须相同',
},
]"
@click-right-icon="clickPassword('electronicSealConfirmPwd')"
>
<template #right-icon>
<i
:class="
!electronicSealConfirmPwd ? 'icon-yincang' : 'icon-xianshi'
"
></i>
</template>
</van-field>
</van-form>
</div>
</div>
<div class="button_group">
<van-button type="default" @click="handleReset">清空</van-button>
<van-button
type="info"
:loading="loading"
loading-text="保存中..."
@click="handleGenerate"
>
保存
</van-button>
</div>
<van-popup
v-model="showPop"
:close-on-click-overlay="false"
round
position="bottom"
style="min-height: 40%"
>
<van-nav-bar
title="手写签章"
left-text="取消"
right-text="确定"
class="popup_header_fixed"
@click-left="clickLeft"
@click-right="onSave()"
/>
<div class="content popup_header_margin">
<vue-esign
ref="esign"
:is-crop="isCrop"
:line-width="lineWidth"
:line-color="lineColor"
:width="800"
:height="600"
/>
</div>
</van-popup>
</div>
</template>
<script>
import vueEsign from 'vue-esign'
import NavBar from '@/components/NavBar.vue'
import req from '@/utils/request'
import { Notify } from 'vant'
import HtViewer from './HtViewer.vue'
export default {
components: {
NavBar,
vueEsign,
HtViewer,
},
data() {
return {
noImg: require('../assets/images/noImage.png'),
showPop: false,
lineWidth: 4,
lineColor: '#000000',
bgColor: '#ffffff',
resultImg: '',
isCrop: true,
electronicSealFileUrl: '',
electronicSeal: {
fileId: '',
password: '',
},
active: 0,
loading: false,
electronicSealConfirmPwd: false,
electronicSealPassword: false,
electronicSealOldPassWord: false,
}
},
mounted() {
this.getElectronicSeal()
},
methods: {
validators(val) {
if (val === this.electronicSeal.password) {
return true
}
return false
},
validator(val) {
return /^[a-zA-Z][a-zA-Z0-9_]*$/.test(val)
},
clickPassword(da) {
this[da] = !this[da]
},
clickLeft() {
this.$refs.esign.reset()
this.showPop = false
},
onSave() {
this.$refs.esign.generate().then((res) => {
this.electronicSealFileUrl = res
this.clickLeft()
})
},
handleReset() {
this.electronicSeal.oldPassWord = ''
this.electronicSeal.confirmPwd = ''
this.electronicSeal.password = ''
this.electronicSealFileUrl = ''
this.electronicSeal.fileId = ''
// this.$refs.htViewer.remove()
},
getElectronicSeal() {
// 获取当前登录用户的签章图片
req
.get(
window.context.uc + '/uc/electronicSeal/v1/getSealByCurrentUserId'
)
.then((response) => {
if (response) {
this.electronicSeal = response
this.$store
.dispatch('menu/downloadImg', response.fileId)
.then((res) => {
if (res != '') {
this.electronicSealFileUrl = res
}
})
}
})
.then(() => {})
},
handleGenerate() {
// if (this.active == 0 && !this.electronicSealFileUrl) {
// Notify({ type: 'warning', message: '请先手写签名!' })
// return
// } else if (this.active == 1 && !this.electronicSeal.fileId) {
// Notify({ type: 'warning', message: '请先上传签名图片!' })
// return
// }
if (!this.electronicSeal.oldPassWord) {
Notify({ type: 'warning', message: '请输入登录密码!' })
return
}
if (!this.electronicSeal.password) {
Notify({ type: 'warning', message: '请输入签章密码!' })
return
}
if (!this.electronicSeal.confirmPwd) {
Notify({ type: 'warning', message: '请输入确认密码!' })
return
}
if (this.electronicSeal.password != this.electronicSeal.confirmPwd) {
Notify({ type: 'warning', message: '签章密码与确认密码不一致!' })
return
}
this.$refs.Form.validate()
.then(() => {
let electronicSealClone = _.cloneDeep(this.electronicSeal)
delete electronicSealClone.confirmPwd
// 验证通过
if (this.active == 0) {
this.loading = true
let formData = new FormData()
if (this.electronicSealFileUrl) {
let file = this.base64ToFile(
this.electronicSealFileUrl,
this.getuuid()
)
formData.append('files', file)
req
.post(
window.context.portal + '/system/file/v1/fileUpload',
formData
)
.then((resp) => {
const { fileId } = resp
electronicSealClone.fileId = fileId
return fileId
})
.then(() => {
return req.post(
window.context.uc + '/uc/electronicSeal/v1/userSave',
electronicSealClone
)
})
.then((resp) => {
if (resp.state) {
Notify({ type: 'success', message: resp.message })
this.getElectronicSeal()
this.$router.push('personal')
} else {
Notify({ type: 'warning', message: resp.message })
}
})
.catch((message) => {
Notify({ type: 'warning', message })
})
.finally(() => (this.loading = false))
} else {
electronicSealClone.fileId = ''
req
.post(
window.context.uc + '/uc/electronicSeal/v1/userSave',
electronicSealClone
)
.then((resp) => {
if (resp.state) {
Notify({ type: 'success', message: resp.message })
this.getElectronicSeal()
this.$router.push('personal')
} else {
Notify({ type: 'warning', message: resp.message })
}
})
.catch((message) => {
Notify({ type: 'warning', message })
})
.finally(() => (this.loading = false))
}
} else {
this.loading = true
req
.post(
window.context.uc + '/uc/electronicSeal/v1/userSave',
electronicSealClone
)
.then((resp) => {
if (resp.state) {
Notify({ type: 'success', message: resp.message })
this.getElectronicSeal()
this.$router.push('personal')
} else {
Notify({ type: 'warning', message: resp.message })
}
})
.finally(() => (this.loading = false))
}
})
.catch(() => {
//验证失败
})
},
base64ToFile(urlData, fileName) {
let arr = urlData.split(',')
let mime = arr[0].match(/:(.*?);/)[1]
let bytes = atob(arr[1]) // 解码base64
let n = bytes.length
let ia = new Uint8Array(n)
while (n--) {
ia[n] = bytes.charCodeAt(n)
}
return new File([ia], fileName, { type: mime })
},
getuuid() {
// 随机获取值 当作文件名称
var s = []
var hexDigits = '0123456789abcdef'
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
}
s[14] = '4'
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1)
s[8] = s[13] = s[18] = s[23] = '-'
this.uuidA = s.join('')
return this.uuidA
},
},
}
</script>
<style lang="scss" scoped>
@import '@/styles/matterButton.scss';
.esign-div {
background-color: #ffffff;
height: 246px;
&_content {
margin: 16px 16px 50px;
border: 1px solid #e6e6e6;
border-radius: 8px 8px 8px 8px;
height: 140px;
overflow: hidden;
.van-image,
.van-empty {
width: 100%;
height: 100%;
}
::v-deep {
.van-empty__image {
width: 72px;
height: 52px;
}
.van-empty__description {
padding: 0;
margin: 0;
}
}
}
}
.button_group {
display: flex;
align-items: center;
justify-content: space-between;
position: absolute;
margin: 0 16px;
bottom: 10px;
width: calc(100% - 32px);
.van-button {
width: 163px;
height: 42px;
border: 1px solid #e6e6e6;
border-radius: 8px 8px 8px 8px;
}
}
::v-deep {
.van-field__label {
font-size: 14px;
width: 70px;
}
.van-tab--active {
.van-tab__text {
color: #409eff;
}
}
.popup_header_fixed {
border-bottom: 0.02667rem solid #e6e6e6;
}
.van-field__right-icon {
font-size: 16px;
}
}
.password_all {
margin: 12px 0px;
background: #ffffff;
& > div {
padding: 12px 0px;
}
}
.content {
width: 100%;
height: calc(100% - 44px);
}
</style>