swordpass-ui 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/swordpass-ui.common.js +161 -91
- package/lib/swordpass-ui.css +1 -1
- package/lib/swordpass-ui.umd.js +161 -91
- package/lib/swordpass-ui.umd.min.js +2 -2
- package/package.json +1 -1
- package/packages/File/src/main.vue +91 -17
- package/packages/FileUpload/src/main.vue +177 -167
package/package.json
CHANGED
|
@@ -350,39 +350,113 @@ export default {
|
|
|
350
350
|
return item
|
|
351
351
|
},
|
|
352
352
|
// 对附件对象的操作,包括:添加、更新、删除、清空、调整顺序
|
|
353
|
+
// valueOpration(item, opType = 'update', direct) {
|
|
354
|
+
// if (opType == 'clear') {
|
|
355
|
+
// this.$emit('input', '')
|
|
356
|
+
// this.refreshFileUploadDebounce()
|
|
357
|
+
// return
|
|
358
|
+
// }
|
|
359
|
+
// let ary = utils.isEmpty(this.value) ? [] : JSON.parse(this.value)
|
|
360
|
+
// const index = ary.findIndex((m) => m.uid == item.uid)
|
|
361
|
+
// switch (opType) {
|
|
362
|
+
// case 'update': {
|
|
363
|
+
// if (index > -1) {
|
|
364
|
+
// ary[index] = item
|
|
365
|
+
// } else {
|
|
366
|
+
// ary.push(item)
|
|
367
|
+
// }
|
|
368
|
+
// break
|
|
369
|
+
// }
|
|
370
|
+
// case 'remove':
|
|
371
|
+
// ary.splice(index, 1)
|
|
372
|
+
// break
|
|
373
|
+
// case 'move': {
|
|
374
|
+
// const realItem = ary.find((m) => m.uid == item.uid)
|
|
375
|
+
// ary = utils.arrayMove(ary, realItem, direct)
|
|
376
|
+
// break
|
|
377
|
+
// }
|
|
378
|
+
// }
|
|
379
|
+
// this.$emit('input', ary.length > 0 ? JSON.stringify(ary) : '')
|
|
380
|
+
// this.refreshFileUploadDebounce()
|
|
381
|
+
// },
|
|
353
382
|
valueOpration(item, opType = 'update', direct) {
|
|
354
|
-
|
|
383
|
+
// 清空操作
|
|
384
|
+
if (opType === 'clear') {
|
|
355
385
|
this.$emit('input', '')
|
|
356
386
|
this.refreshFileUploadDebounce()
|
|
357
387
|
return
|
|
358
388
|
}
|
|
359
|
-
|
|
360
|
-
|
|
389
|
+
|
|
390
|
+
// 参数验证
|
|
391
|
+
if (!item || !item.uid) {
|
|
392
|
+
console.warn('item 或 item.uid 不能为空')
|
|
393
|
+
return
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// 获取当前附件数组
|
|
397
|
+
let ary = this.value ? JSON.parse(this.value) : []
|
|
398
|
+
|
|
399
|
+
// 根据操作类型执行相应逻辑
|
|
361
400
|
switch (opType) {
|
|
362
|
-
case 'update':
|
|
363
|
-
|
|
364
|
-
ary[index] = item
|
|
365
|
-
} else {
|
|
366
|
-
ary.push(item)
|
|
367
|
-
}
|
|
401
|
+
case 'update':
|
|
402
|
+
this.handleUpdate(ary, item)
|
|
368
403
|
break
|
|
369
|
-
}
|
|
370
404
|
case 'remove':
|
|
371
|
-
|
|
405
|
+
this.handleRemove(ary, item)
|
|
372
406
|
break
|
|
373
|
-
case 'move':
|
|
374
|
-
|
|
375
|
-
ary = utils.arrayMove(ary, realItem, direct)
|
|
407
|
+
case 'move':
|
|
408
|
+
this.handleMove(ary, item, direct)
|
|
376
409
|
break
|
|
377
|
-
|
|
410
|
+
default:
|
|
411
|
+
console.warn(`不支持的操作类型: ${opType}`)
|
|
412
|
+
return
|
|
378
413
|
}
|
|
414
|
+
|
|
415
|
+
// 更新组件值并刷新上传组件
|
|
379
416
|
this.$emit('input', ary.length > 0 ? JSON.stringify(ary) : '')
|
|
380
|
-
|
|
417
|
+
this.refreshFileUploadDebounce()
|
|
418
|
+
},
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* 处理附件更新操作
|
|
422
|
+
*/
|
|
423
|
+
handleUpdate(ary, item) {
|
|
424
|
+
const index = ary.findIndex((m) => m.uid === item.uid)
|
|
425
|
+
if (index > -1) {
|
|
426
|
+
// 存在则更新
|
|
427
|
+
ary[index] = { ...ary[index], ...item }
|
|
428
|
+
} else {
|
|
429
|
+
// 不存在则添加
|
|
430
|
+
ary.push(item)
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* 处理附件删除操作
|
|
436
|
+
*/
|
|
437
|
+
handleRemove(ary, item) {
|
|
438
|
+
const index = ary.findIndex((m) => m.uid === item.uid)
|
|
439
|
+
if (index > -1) {
|
|
440
|
+
ary.splice(index, 1)
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* 处理附件移动操作
|
|
446
|
+
*/
|
|
447
|
+
handleMove(ary, item, direct) {
|
|
448
|
+
const index = ary.findIndex((m) => m.uid === item.uid)
|
|
449
|
+
if (index > -1) {
|
|
450
|
+
const realItem = ary[index]
|
|
451
|
+
ary = utils.arrayMove(ary, realItem, direct)
|
|
452
|
+
}
|
|
381
453
|
},
|
|
382
454
|
// 同步附件数据到上传组件
|
|
383
455
|
refreshFileUpload() {
|
|
384
456
|
this.$nextTick(() => {
|
|
385
|
-
this.$refs.fileUpload
|
|
457
|
+
if (this.$refs.fileUpload) {
|
|
458
|
+
this.$refs.fileUpload.reload(this.inputVal)
|
|
459
|
+
}
|
|
386
460
|
})
|
|
387
461
|
},
|
|
388
462
|
handleError(err, file) {
|
|
@@ -30,8 +30,18 @@
|
|
|
30
30
|
</el-button>
|
|
31
31
|
</el-tooltip>
|
|
32
32
|
</el-upload>
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
<el-popconfirm title="确定要清空吗?" @confirm="handleClear">
|
|
34
|
+
<el-button
|
|
35
|
+
v-if="!readonly && files.length > 0"
|
|
36
|
+
slot="reference"
|
|
37
|
+
size="mini"
|
|
38
|
+
round
|
|
39
|
+
icon="el-icon-delete"
|
|
40
|
+
>
|
|
41
|
+
清空
|
|
42
|
+
</el-button>
|
|
43
|
+
</el-popconfirm>
|
|
44
|
+
<!-- <el-button
|
|
35
45
|
v-if="!readonly && files.length > 0"
|
|
36
46
|
v-popconfirm="{ content: '确定要清空吗?', confirm: handleClear }"
|
|
37
47
|
size="mini"
|
|
@@ -39,184 +49,184 @@
|
|
|
39
49
|
icon="el-icon-delete"
|
|
40
50
|
>
|
|
41
51
|
清空
|
|
42
|
-
</el-button>
|
|
52
|
+
</el-button> -->
|
|
43
53
|
|
|
44
54
|
<slot name="append"></slot>
|
|
45
55
|
</div>
|
|
46
56
|
</template>
|
|
47
57
|
<script>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
value: {
|
|
56
|
-
type: Array,
|
|
57
|
-
required: true,
|
|
58
|
-
},
|
|
59
|
-
actionUrl: {
|
|
60
|
-
type: String,
|
|
61
|
-
required: true,
|
|
62
|
-
},
|
|
63
|
-
listType: {
|
|
64
|
-
type: String,
|
|
65
|
-
},
|
|
66
|
-
multiple: {
|
|
67
|
-
type: Boolean,
|
|
68
|
-
},
|
|
69
|
-
accept: {
|
|
70
|
-
type: String,
|
|
71
|
-
},
|
|
72
|
-
limit: {
|
|
73
|
-
type: Number,
|
|
74
|
-
default: 5,
|
|
75
|
-
},
|
|
76
|
-
header: {
|
|
77
|
-
type: Object,
|
|
78
|
-
},
|
|
79
|
-
size: {
|
|
80
|
-
type: Number,
|
|
81
|
-
default: 50,
|
|
82
|
-
},
|
|
83
|
-
readonly: {
|
|
84
|
-
type: Boolean,
|
|
85
|
-
default: false,
|
|
86
|
-
},
|
|
87
|
-
beforeUpload: {
|
|
88
|
-
type: Function,
|
|
89
|
-
},
|
|
90
|
-
onSuccess: {
|
|
91
|
-
type: Function,
|
|
92
|
-
},
|
|
93
|
-
onError: {
|
|
94
|
-
type: Function,
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
data() {
|
|
98
|
-
return {
|
|
99
|
-
files: [],
|
|
100
|
-
}
|
|
58
|
+
export default {
|
|
59
|
+
name: 'ClFileUpload',
|
|
60
|
+
props: {
|
|
61
|
+
withCredentials: {
|
|
62
|
+
type: Boolean,
|
|
63
|
+
default: false,
|
|
101
64
|
},
|
|
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
|
-
|
|
65
|
+
value: {
|
|
66
|
+
type: Array,
|
|
67
|
+
required: true,
|
|
68
|
+
},
|
|
69
|
+
actionUrl: {
|
|
70
|
+
type: String,
|
|
71
|
+
required: true,
|
|
72
|
+
},
|
|
73
|
+
listType: {
|
|
74
|
+
type: String,
|
|
75
|
+
},
|
|
76
|
+
multiple: {
|
|
77
|
+
type: Boolean,
|
|
78
|
+
},
|
|
79
|
+
accept: {
|
|
80
|
+
type: String,
|
|
81
|
+
},
|
|
82
|
+
limit: {
|
|
83
|
+
type: Number,
|
|
84
|
+
default: 5,
|
|
85
|
+
},
|
|
86
|
+
header: {
|
|
87
|
+
type: Object,
|
|
88
|
+
},
|
|
89
|
+
size: {
|
|
90
|
+
type: Number,
|
|
91
|
+
default: 50,
|
|
92
|
+
},
|
|
93
|
+
readonly: {
|
|
94
|
+
type: Boolean,
|
|
95
|
+
default: false,
|
|
96
|
+
},
|
|
97
|
+
beforeUpload: {
|
|
98
|
+
type: Function,
|
|
99
|
+
},
|
|
100
|
+
onSuccess: {
|
|
101
|
+
type: Function,
|
|
102
|
+
},
|
|
103
|
+
onError: {
|
|
104
|
+
type: Function,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
data() {
|
|
108
|
+
return {
|
|
109
|
+
files: [],
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
computed: {
|
|
113
|
+
acceptLabel: function () {
|
|
114
|
+
return this.accept ? this.accept : '所有格式'
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
created() {
|
|
118
|
+
this.files = this.value || []
|
|
119
|
+
},
|
|
120
|
+
methods: {
|
|
121
|
+
reload(files) {
|
|
122
|
+
this.files = files
|
|
123
|
+
},
|
|
124
|
+
// 附件是否超过最大尺寸
|
|
125
|
+
exceedFileSize(file) {
|
|
126
|
+
return file.size > this.size * 1024 * 1024
|
|
127
|
+
},
|
|
128
|
+
handleBeforeUpload(file) {
|
|
129
|
+
let resultVal = false
|
|
130
|
+
if (this.exceedFileSize(file)) {
|
|
131
|
+
let computerSize = this.$options.filters['computerSize'](file.size)
|
|
151
132
|
this.$message({
|
|
152
|
-
message:
|
|
133
|
+
message: `附件的大小为${computerSize},超过了允许的最大尺寸${this.size}MB.`,
|
|
153
134
|
type: 'warning',
|
|
154
135
|
})
|
|
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
|
-
this.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
136
|
+
resultVal = false
|
|
137
|
+
} else {
|
|
138
|
+
resultVal = true
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (
|
|
142
|
+
this.beforeUpload &&
|
|
143
|
+
this.beforeUpload.constructor == Function &&
|
|
144
|
+
resultVal
|
|
145
|
+
) {
|
|
146
|
+
resultVal = this.beforeUpload(file)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (resultVal) {
|
|
150
|
+
this.files.push(file)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return resultVal
|
|
154
|
+
},
|
|
155
|
+
handleProgress(event, file, fileList) {
|
|
156
|
+
const index = this.files.findIndex((m) => m === file)
|
|
157
|
+
index > -1 && this.$set(this.files, index, file)
|
|
158
|
+
this.$emit('on-progress', event, file, fileList)
|
|
159
|
+
},
|
|
160
|
+
handleExceed() {
|
|
161
|
+
this.$message({
|
|
162
|
+
message: `最多允许上传${this.limit}个附件.`,
|
|
163
|
+
type: 'warning',
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
handleSuccess(response, file, fileList) {
|
|
167
|
+
if (this.onSuccess && this.onSuccess.constructor == Function) {
|
|
168
|
+
this.onSuccess(response, file, fileList)
|
|
169
|
+
}
|
|
170
|
+
const index = this.files.findIndex((m) => m === file)
|
|
171
|
+
file.state = 'success'
|
|
172
|
+
index > -1 && this.$set(this.files, index, file)
|
|
173
|
+
},
|
|
174
|
+
handleError(err, file, fileList) {
|
|
175
|
+
if (this.onError && this.onError.constructor == Function) {
|
|
176
|
+
this.onError(err, file, fileList)
|
|
177
|
+
}
|
|
178
|
+
this.$emit('handle-error', err, file, fileList)
|
|
179
|
+
const index = this.files.findIndex((m) => m === file)
|
|
180
|
+
file.state = 'exception'
|
|
181
|
+
index > -1 && this.$set(this.files, index, file)
|
|
182
|
+
this.$message({
|
|
183
|
+
message: `附件${file.name}上传失败.`,
|
|
184
|
+
type: 'error',
|
|
185
|
+
onClose: () => {
|
|
186
|
+
this.files.remove(file)
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
},
|
|
190
|
+
handleClear() {
|
|
191
|
+
this.files.forEach((m) => {
|
|
192
|
+
this.abort(m)
|
|
193
|
+
})
|
|
194
|
+
this.$refs.elUploadEl.clearFiles()
|
|
195
|
+
this.files = []
|
|
196
|
+
this.$emit('clear')
|
|
197
|
+
},
|
|
198
|
+
abort(file) {
|
|
199
|
+
// 附件还在上传中,则中止上传。
|
|
200
|
+
if (file && file.status === 'uploading') {
|
|
201
|
+
this.$refs.elUploadEl.abort(file)
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
remove(file) {
|
|
205
|
+
this.abort(file)
|
|
206
|
+
this.files.remove(file)
|
|
207
|
+
for (var i = 0; i < this.files.length; i++) {
|
|
208
|
+
if (this.files[i].uid == file.uid) {
|
|
209
|
+
this.files.splice(i, 1) //删除数组某一项
|
|
201
210
|
}
|
|
202
|
-
}
|
|
211
|
+
}
|
|
203
212
|
},
|
|
204
|
-
}
|
|
213
|
+
},
|
|
214
|
+
}
|
|
205
215
|
</script>
|
|
206
216
|
<style lang="scss" scoped>
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
217
|
+
.el-upload {
|
|
218
|
+
display: inline;
|
|
219
|
+
text-align: center;
|
|
220
|
+
cursor: pointer;
|
|
221
|
+
outline: none;
|
|
222
|
+
}
|
|
213
223
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
224
|
+
.file-upload-container {
|
|
225
|
+
margin-bottom: 10px;
|
|
226
|
+
}
|
|
217
227
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
228
|
+
div.file-upload-container > div {
|
|
229
|
+
display: inline-block;
|
|
230
|
+
margin-right: 10px;
|
|
231
|
+
}
|
|
222
232
|
</style>
|