SignatureManage.vue
7.25 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
<template>
<div class="signature-manage">
<el-form
ref="form"
:model="form"
label-width="100px"
class="signature-manage-form"
:rules="rules"
>
<el-form-item label="签章:" class="signature-manage_uploadForm">
<el-upload
ref="signatureUpload"
:action="action"
class="signature-manage_upload"
:class="{ uoloadSty: showBtnDealImg, disUoloadSty: noneBtnImg }"
list-type="picture-card"
:on-remove="handleDealImgRemove"
:on-change="dealImgChange"
accept=".jpeg,.jpg,.gif,.png"
:limit="limitCountImg"
:file-list="fileList"
:http-request="httpRequest"
>
<i class="el-icon-plus"></i>
</el-upload>
<template v-if="noneBtnImg">
<el-button type="text" style="padding: 0;" @click="reloadImg">重新上传</el-button>
<el-button type="text" style="padding: 0;" @click="deleteImg">删除</el-button>
</template>
</el-form-item>
<el-form-item label="登录密码:" prop="oldPassWord">
<el-input
v-model.trim="form.oldPassWord"
placeholder="请输入登录密码"
show-password
clearable
></el-input>
</el-form-item>
<el-form-item label="设置密码:" prop="password">
<el-input
v-model.trim="form.password"
placeholder="请设置签章密码"
show-password
clearable
></el-input>
</el-form-item>
<el-form-item label="确认密码:" prop="confirmPwd">
<el-input
v-model.trim="form.confirmPwd"
placeholder="请再次输入密码"
show-password
clearable
></el-input>
</el-form-item>
</el-form>
<div class="signature-manage-save">
<el-button type="primary" class="save-btn" @click="handleClick">
保存
</el-button>
</div>
</div>
</template>
<script>
import { getSealByCurrentUserId } from '@/api/uc.js'
import req from '@/utils/request.js'
import { fileUrl } from '@/api/portal'
export default {
data() {
return {
form: {
fileId: '',
id: '',
isUse: 0,
password: '',
pkVal: '',
userId: '',
confirmPwd: '',
createTime: '',
oldPassWord: '',
},
rules: {
oldPassWord: [
{ required: true, message: '不能为空', trigger: 'blur' },
],
password: [
{ required: true, message: '不能为空', trigger: 'blur' },
{
pattern: '^[a-zA-Z][a-zA-Z0-9_]*$',
message: '只能输入字母、数字、下划线,且以字母开头',
},
],
confirmPwd: [
{ required: true, message: '不能为空', trigger: 'blur' },
{
pattern: '^[a-zA-Z][a-zA-Z0-9_]*$',
message: '只能输入字母、数字、下划线,且以字母开头',
},
],
},
limitCountImg: 1,
showBtnDealImg: true,
noneBtnImg: false,
fileList: [],
action: '',
}
},
async created() {
// 上传路径拼接
this.action = `${window.context.portal}/system/file/v1/upload`
// 获取签章信息
let res = await getSealByCurrentUserId()
if (res.fileId) {
this.fileList.push({
url: fileUrl(res.fileId),
...res,
})
this.noneBtnImg = true
this.form.fileId = res.fileId
}
this.form.id = res.id || '' // 有id为更新 没id为新增
this.form.pkVal = res.pkVal || ''
this.form.userId = res.userId
},
methods: {
reloadImg() {
this.$refs.signatureUpload.clearFiles()
this.deleteImg()
this.$refs.signatureUpload.$children[1].$refs.input.click()
},
deleteImg() {
this.fileList = []
this.handleDealImgRemove('', this.fileList)
},
// 自定义上传
async httpRequest(val) {
const formData = new FormData()
formData.append('files', val.file)
let response = await req.post(
window.context.portal + '/system/file/v1/fileUpload',
formData
)
if (response.success) {
this.$message.success('上传成功')
this.form.fileId = response.fileId
this.form.userId = this.$store.state.user.userInfo.user.userId
}
},
// 保存
async handleClick() {
if (
this.form.password === '' ||
this.form.confirmPwd === '' ||
this.form.oldPassWord === ''
) {
this.$message.warning('请输入密码后保存')
return
}
if (this.form.password !== this.form.confirmPwd) {
this.$message.error('两次密码输入不一致')
return
}
this.$refs.form.validate((res) => {
if (res) {
this.form.createTime = new Date()
.toLocaleString('en-ZA')
.replaceAll('/', '-')
.replaceAll(',', '')
req
.post(window.context.uc + '/uc/electronicSeal/v1/save', this.form)
.then((res) => {
if (res.state) {
this.$message.success(res.message)
this.form.oldPassWord = ''
this.form.password = ''
this.form.confirmPwd = ''
} else {
this.$message.error(res.message)
}
})
}
})
},
// 改变
dealImgChange(file, fileList) {
this.noneBtnImg = fileList.length >= this.limitCountImg
},
// 删除
handleDealImgRemove(file, fileList) {
this.noneBtnImg = fileList.length >= this.limitCountImg
this.fileList = []
this.form.fileId = ''
// 删除签章
// req.delete(
// window.context.portal + `/uc/electronicSeal/v2/${this.form.id}`
// )
},
},
}
</script>
<style lang="scss" scoped>
.signature-manage {
width: 50%;
height: 400px;
margin: 88px auto;
::v-deep {
.el-input {
width: 80%;
}
.el-form-item__label {
padding: 0 30px 0 0;
}
.el-upload--picture-card {
width: 208px;
height: 108px;
display: flex;
justify-content: center;
align-items: center;
background-color: #f9f9f9;
}
}
.signature-manage-save {
width: 100%;
text-align: center;
margin-top: 60px;
.save-btn {
padding: 8px 30px;
}
}
.uoloadSty .el-upload--picture-card {
width: 110px;
height: 110px;
line-height: 110px;
}
::v-deep .disUoloadSty .el-upload--picture-card {
width: 0; /* 上传按钮隐藏 */
height: 0;
opacity: 0;
}
::v-deep .el-upload-list--picture-card .el-upload-list__item {
width: 208px;
height: 108px;
}
::v-deep .signature-manage_uploadForm{
.el-form-item__content{
line-height: 0;
}
}
::v-deep .signature-manage_upload {
.el-upload-list__item-status-label, .el-upload-list__item-actions {
display: none;
}
}
}
</style>