swordpass-ui 1.0.9 → 1.1.1

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.
@@ -98,370 +98,374 @@
98
98
  </div>
99
99
  </template>
100
100
  <script>
101
- import utils from '@/utils.js'
102
- import permission from '@/mixins/permission.js'
103
- import inputName from '@/mixins/inputName.js'
104
- import form from '@/mixins/form.js'
105
- import ClFieldTail from '../../FieldTail/index'
106
- import FileUpload from '../../FileUpload/index'
107
- import Locale from '@/mixins/locale'
108
- import FileTable from './FileTable'
109
- import FileList from './FileList'
110
- import FileCard from './FileCard.vue'
111
- import mobileMode from '@/mixins/mobileMode.js'
112
- import _ from 'lodash'
113
- const { saveAs } = require('file-saver')
101
+ import utils from '@/utils.js'
102
+ import permission from '@/mixins/permission.js'
103
+ import inputName from '@/mixins/inputName.js'
104
+ import form from '@/mixins/form.js'
105
+ import ClFieldTail from '../../FieldTail/index'
106
+ import FileUpload from '../../FileUpload/index'
107
+ import Locale from '@/mixins/locale'
108
+ import FileTable from './FileTable'
109
+ import FileList from './FileList'
110
+ import FileCard from './FileCard.vue'
111
+ import mobileMode from '@/mixins/mobileMode.js'
112
+ import _ from 'lodash'
113
+ const { saveAs } = require('file-saver')
114
114
 
115
- export default {
116
- name: 'ClFile',
117
- components: { ClFieldTail, FileUpload, FileTable, FileList, FileCard },
118
- mixins: [Locale, permission, inputName, form, mobileMode],
119
- props: {
120
- type: {
121
- type: String,
122
- default: 'table',
123
- validator: function(value) {
124
- return ['table', 'list', 'card'].indexOf(value) !== -1
125
- },
126
- },
127
- isSimple: {
128
- type: Boolean,
129
- default: false,
130
- },
131
- simplicity: {
132
- type: Boolean,
133
- default: false,
134
- },
135
- withCredentials: {
136
- type: Boolean,
137
- default: false,
138
- },
139
- actionUrl: {
140
- type: String,
141
- default: null,
142
- },
143
- value: {
144
- type: String,
145
- },
146
- multiple: {
147
- type: Boolean,
148
- default: false,
149
- },
150
- accept: {
151
- type: String,
152
- },
153
- limit: {
154
- type: Number,
155
- },
156
- pictureWall: {
157
- type: Boolean,
158
- default: false,
159
- },
160
- header: {
161
- type: Object,
162
- },
163
- size: {
164
- type: Number,
165
- },
166
- sizeType: {
167
- type: String,
168
- },
169
- previewable: {
170
- type: Boolean,
171
- default: true,
172
- },
173
- allowPreview: {
174
- type: Boolean,
175
- default: true,
176
- },
177
- downloadable: {
178
- type: Boolean,
179
- default: true,
180
- },
181
- allowDownload: {
182
- type: Boolean,
183
- default: true,
184
- },
185
- sortable: {
186
- type: Boolean,
187
- default: true,
188
- },
189
- propConf: [Array, String],
190
- beforeUpload: {
191
- type: Function,
192
- },
193
- onSuccess: {
194
- type: Function,
195
- },
196
- onError: {
197
- type: Function,
198
- },
199
- columnShow: {
200
- type: Object,
201
- default() {
202
- return {}
203
- },
204
- },
205
- cardBadge: {
206
- type: Boolean,
207
- default: true,
208
- },
209
- thumbnail: {
210
- type: Function,
211
- },
212
- flowData: {
213
- type: Object,
214
- default: () => {
215
- return {}
216
- },
115
+ export default {
116
+ name: 'ClFile',
117
+ components: { ClFieldTail, FileUpload, FileTable, FileList, FileCard },
118
+ mixins: [Locale, permission, inputName, form, mobileMode],
119
+ props: {
120
+ type: {
121
+ type: String,
122
+ default: 'table',
123
+ validator: function (value) {
124
+ return ['table', 'list', 'card'].indexOf(value) !== -1
217
125
  },
218
126
  },
219
- data() {
220
- return {
221
- writeable: true,
222
- temp: null,
223
- refreshFileUploadDebounce: _.debounce(this.refreshFileUpload, 200),
224
- inputVal: [],
225
- }
127
+ isSimple: {
128
+ type: Boolean,
129
+ default: false,
226
130
  },
227
- computed: {
228
- typeVal: function() {
229
- return this.isSimple || this.simplicity ? 'list' : this.type
230
- },
231
- inputsContainerWidth() {
232
- return this.typeVal !== 'list' && this.formInputsDisplay !== 'block'
233
- ? { width: 'auto' }
234
- : {}
131
+ simplicity: {
132
+ type: Boolean,
133
+ default: false,
134
+ },
135
+ withCredentials: {
136
+ type: Boolean,
137
+ default: false,
138
+ },
139
+ actionUrl: {
140
+ type: String,
141
+ default: null,
142
+ },
143
+ value: {
144
+ type: String,
145
+ },
146
+ multiple: {
147
+ type: Boolean,
148
+ default: false,
149
+ },
150
+ accept: {
151
+ type: String,
152
+ },
153
+ limit: {
154
+ type: Number,
155
+ },
156
+ pictureWall: {
157
+ type: Boolean,
158
+ default: false,
159
+ },
160
+ header: {
161
+ type: Object,
162
+ },
163
+ size: {
164
+ type: Number,
165
+ },
166
+ sizeType: {
167
+ type: String,
168
+ },
169
+ previewable: {
170
+ type: Boolean,
171
+ default: true,
172
+ },
173
+ allowPreview: {
174
+ type: Boolean,
175
+ default: true,
176
+ },
177
+ downloadable: {
178
+ type: Boolean,
179
+ default: true,
180
+ },
181
+ allowDownload: {
182
+ type: Boolean,
183
+ default: true,
184
+ },
185
+ sortable: {
186
+ type: Boolean,
187
+ default: true,
188
+ },
189
+ propConf: [Array, String],
190
+ beforeUpload: {
191
+ type: Function,
192
+ },
193
+ onSuccess: {
194
+ type: Function,
195
+ },
196
+ onError: {
197
+ type: Function,
198
+ },
199
+ columnShow: {
200
+ type: Object,
201
+ default() {
202
+ return {}
235
203
  },
236
- actionUrlVal: function() {
237
- return this.actionUrl
238
- ? this.actionUrl
239
- : this.$requestConfig.uploadUrl
240
- ? this.handlerUploadUrl
241
- : 'https://jsonplaceholder.typicode.com/posts/'
204
+ },
205
+ cardBadge: {
206
+ type: Boolean,
207
+ default: true,
208
+ },
209
+ thumbnail: {
210
+ type: Function,
211
+ },
212
+ flowData: {
213
+ type: Object,
214
+ default: () => {
215
+ return {}
242
216
  },
243
- handlerUploadUrl() {
244
- const baseUrl = this.$requestConfig.uploadUrl
245
- if (!this.flowData.defId) {
246
- return baseUrl
247
- }
248
- const indexOfMark = baseUrl.indexOf('?')
249
- if (indexOfMark == -1) {
250
- return `${baseUrl}?defId=${this.flowData.defId}`
251
- }
252
- if (indexOfMark > -1 && indexOfMark == baseUrl.length - 1) {
253
- return `${baseUrl}defId=${this.flowData.defId}`
254
- }
255
- if (indexOfMark > -1 && indexOfMark < baseUrl.length - 1) {
256
- return `${baseUrl}&defId=${this.flowData.defId}`
257
- }
217
+ },
218
+ },
219
+ data() {
220
+ return {
221
+ writeable: true,
222
+ temp: null,
223
+ refreshFileUploadDebounce: _.debounce(this.refreshFileUpload, 1000),
224
+ inputVal: [],
225
+ }
226
+ },
227
+ computed: {
228
+ typeVal: function () {
229
+ return this.isSimple || this.simplicity ? 'list' : this.type
230
+ },
231
+ inputsContainerWidth() {
232
+ return this.typeVal !== 'list' && this.formInputsDisplay !== 'block'
233
+ ? { width: 'auto' }
234
+ : {}
235
+ },
236
+ actionUrlVal: function () {
237
+ return this.actionUrl
238
+ ? this.actionUrl
239
+ : this.$requestConfig.uploadUrl
240
+ ? this.handlerUploadUrl
241
+ : 'https://jsonplaceholder.typicode.com/posts/'
242
+ },
243
+ handlerUploadUrl() {
244
+ const baseUrl = this.$requestConfig.uploadUrl
245
+ if (!this.flowData.defId) {
258
246
  return baseUrl
259
- },
260
- headerVal: function() {
261
- return this.header
262
- ? this.header
263
- : this.$requestConfig.header
264
- ? this.$requestConfig.header()
265
- : null
266
- },
267
- acceptType: function() {
268
- if (this.accept) {
269
- const ary = []
270
- this.accept.split(',').forEach((m) => {
271
- if (m.startsWith('.')) {
272
- ary.push(m)
273
- } else {
274
- ary.push(`.${m}`)
275
- }
276
- })
277
- return ary.join(',')
278
- }
279
- return null
280
- },
281
- previewableVal: function() {
282
- return (
283
- (this.inputWriteable && this.previewable) ||
284
- (this.permission_sub === 'r' && this.allowPreview)
285
- )
286
- },
287
- downloadableVal: function() {
288
- return (
289
- (this.inputWriteable && this.downloadable) ||
290
- (this.permission_sub === 'r' && this.allowDownload)
291
- )
292
- },
247
+ }
248
+ const indexOfMark = baseUrl.indexOf('?')
249
+ if (indexOfMark == -1) {
250
+ return `${baseUrl}?defId=${this.flowData.defId}`
251
+ }
252
+ if (indexOfMark > -1 && indexOfMark == baseUrl.length - 1) {
253
+ return `${baseUrl}defId=${this.flowData.defId}`
254
+ }
255
+ if (indexOfMark > -1 && indexOfMark < baseUrl.length - 1) {
256
+ return `${baseUrl}&defId=${this.flowData.defId}`
257
+ }
258
+ return baseUrl
293
259
  },
294
- watch: {
295
- value(val) {
296
- if (utils.isEmpty(val)) {
297
- this.inputVal = []
298
- }
299
- if (val.constructor == String) {
260
+ headerVal: function () {
261
+ return this.header
262
+ ? this.header
263
+ : this.$requestConfig.header
264
+ ? this.$requestConfig.header()
265
+ : null
266
+ },
267
+ acceptType: function () {
268
+ if (this.accept) {
269
+ const ary = []
270
+ this.accept.split(',').forEach((m) => {
271
+ if (m.startsWith('.')) {
272
+ ary.push(m)
273
+ } else {
274
+ ary.push(`.${m}`)
275
+ }
276
+ })
277
+ return ary.join(',')
278
+ }
279
+ return null
280
+ },
281
+ previewableVal: function () {
282
+ return (
283
+ (this.inputWriteable && this.previewable) ||
284
+ (this.permission_sub === 'r' && this.allowPreview)
285
+ )
286
+ },
287
+ downloadableVal: function () {
288
+ return (
289
+ (this.inputWriteable && this.downloadable) ||
290
+ (this.permission_sub === 'r' && this.allowDownload)
291
+ )
292
+ },
293
+ },
294
+ watch: {
295
+ value(val) {
296
+ if (utils.isEmpty(val)) {
297
+ this.inputVal = []
298
+ }
299
+ if (val.constructor == String) {
300
+ if (val) {
300
301
  this.inputVal = [...JSON.parse(val)]
302
+ } else {
303
+ this.inputVal = []
301
304
  }
305
+ }
306
+ },
307
+ inputVal: {
308
+ handler(val) {
309
+ this.$emit('input', JSON.stringify(val))
302
310
  },
303
- inputVal: {
304
- handler(val) {
305
- this.$emit('input', JSON.stringify(val))
306
- },
307
- deep: true,
308
- },
311
+ deep: true,
309
312
  },
310
- created() {
311
- if (this.value) {
312
- this.inputVal = JSON.parse(this.value)
313
+ },
314
+ created() {
315
+ if (this.value) {
316
+ this.inputVal = JSON.parse(this.value)
317
+ }
318
+ },
319
+ methods: {
320
+ //获取指定字符串点最后一个字符
321
+ substringType(str) {
322
+ let valueArr = str.split('.')
323
+ return valueArr[valueArr.length - 1]
324
+ },
325
+ // 将文件对象转换为附件对象
326
+ convertFile2Item(file) {
327
+ const item = {
328
+ name: file.name,
329
+ size: file.size,
330
+ percentage: file.percentage,
331
+ status: file.status,
332
+ state: file.status,
333
+ type:
334
+ file.name && file.name.split('.')
335
+ ? this.substringType(file.name)
336
+ : file.type,
337
+ uid: file.uid,
338
+ prop1: '',
339
+ prop2: '',
340
+ prop3: '',
341
+ prop4: '',
342
+ prop5: '',
343
+ prop6: '',
344
+ }
345
+ if (file.response) {
346
+ item.response = { ...file.response }
347
+ item.username = file.response.username || ''
313
348
  }
349
+ return item
314
350
  },
315
- methods: {
316
- //获取指定字符串点最后一个字符
317
- substringType(str) {
318
- let valueArr = str.split('.')
319
- return valueArr[valueArr.length - 1]
320
- },
321
- // 将文件对象转换为附件对象
322
- convertFile2Item(file) {
323
- const item = {
324
- name: file.name,
325
- size: file.size,
326
- percentage: file.percentage,
327
- status: file.status,
328
- state: file.status,
329
- type:
330
- file.name && file.name.split('.')
331
- ? this.substringType(file.name)
332
- : file.type,
333
- uid: file.uid,
334
- prop1: '',
335
- prop2: '',
336
- prop3: '',
337
- prop4: '',
338
- prop5: '',
339
- prop6: '',
340
- }
341
- if (file.response) {
342
- item.response = { ...file.response }
343
- item.username = file.response.username || ''
344
- }
345
- return item
346
- },
347
- // 对附件对象的操作,包括:添加、更新、删除、清空、调整顺序
348
- valueOpration(item, opType = 'update', direct) {
349
- if (opType == 'clear') {
350
- this.$emit('input', '')
351
- this.refreshFileUploadDebounce()
352
- return
353
- }
354
- let ary = utils.isEmpty(this.value) ? [] : JSON.parse(this.value)
355
- const index = ary.findIndex((m) => m.uid == item.uid)
356
- switch (opType) {
357
- case 'update': {
358
- if (index > -1) {
359
- ary[index] = item
360
- } else {
361
- ary.push(item)
362
- }
363
- break
364
- }
365
- case 'remove':
366
- ary.splice(index, 1)
367
- break
368
- case 'move': {
369
- const realItem = ary.find((m) => m.uid == item.uid)
370
- ary = utils.arrayMove(ary, realItem, direct)
371
- break
372
- }
373
- }
374
- this.$emit('input', ary.length > 0 ? JSON.stringify(ary) : '')
351
+ // 对附件对象的操作,包括:添加、更新、删除、清空、调整顺序
352
+ valueOpration(item, opType = 'update', direct) {
353
+ if (opType == 'clear') {
354
+ this.$emit('input', '')
375
355
  this.refreshFileUploadDebounce()
376
- },
377
- // 同步附件数据到上传组件
378
- refreshFileUpload() {
379
- this.$nextTick(() => {
380
- this.$refs.fileUpload.reload(this.inputVal)
381
- })
382
- },
383
- handleError(err, file) {
384
- this.valueOpration(this.convertFile2Item(file))
385
- //上传失败的附件在3秒后自动移除
386
- setTimeout(() => {
387
- this.valueOpration(this.convertFile2Item(file), 'remove')
388
- }, 3000)
389
- },
390
- handleProgress(event, file) {
391
- this.valueOpration(this.convertFile2Item(file))
392
- },
393
- handleClear() {
394
- this.valueOpration(null, 'clear')
395
- },
396
- move(item, direct) {
397
- this.valueOpration(item, 'move', direct)
398
- },
399
- uploadSuccess(response, file, fileList) {
400
- this.valueOpration(this.convertFile2Item(file))
401
- this.$emit('onSuccess', response, file, fileList)
402
- },
403
- removeFile(file) {
404
- this.$refs.fileUpload.abort(file)
405
- this.valueOpration(this.convertFile2Item(file), 'remove')
406
- this.$emit('remove', file, this.inputVal)
407
- },
408
- download(file) {
409
- // 组件单独绑定了download事件
410
- if (this.$options._parentListeners.download) {
411
- this.$emit('download', file, this.inputVal)
412
- }
413
- // 未绑定时触发全局download事件处理函数
414
- else if (this.$requestConfig.download) {
415
- this.$requestConfig
416
- .download(file.response.fileId)
417
- .then(({ data, headers }) => {
418
- if (data && headers) {
419
- // 附件下载
420
- const fileName = decodeURIComponent(
421
- headers['content-disposition']
422
- .split(';')[1]
423
- .split('filename=')[1]
424
- )
425
- const blob = new Blob([data])
426
- saveAs(blob, fileName)
427
- }
428
- })
429
- .catch((err) => {
430
- this.$message.error(`附件下载失败:${err}`)
431
- })
432
- }
433
- },
434
- preview(file) {
435
- if (file.status !== 'success') {
436
- this.$message.warning(this.t('cl.file.forbiddenPreview'))
437
- return
438
- }
439
- if (this.previewableVal) {
440
- // 当前组件未添加preview事件监听 并且 设置了全局预览方法
441
- if (!this._events.preview && this.$preview) {
442
- this.$preview(file)
356
+ return
357
+ }
358
+ let ary = utils.isEmpty(this.value) ? [] : JSON.parse(this.value)
359
+ const index = ary.findIndex((m) => m.uid == item.uid)
360
+ switch (opType) {
361
+ case 'update': {
362
+ if (index > -1) {
363
+ ary[index] = item
443
364
  } else {
444
- this.$emit('preview', file, this.inputVal)
365
+ ary.push(item)
445
366
  }
367
+ break
368
+ }
369
+ case 'remove':
370
+ ary.splice(index, 1)
371
+ break
372
+ case 'move': {
373
+ const realItem = ary.find((m) => m.uid == item.uid)
374
+ ary = utils.arrayMove(ary, realItem, direct)
375
+ break
376
+ }
377
+ }
378
+ this.$emit('input', ary.length > 0 ? JSON.stringify(ary) : '')
379
+ this.refreshFileUploadDebounce()
380
+ },
381
+ // 同步附件数据到上传组件
382
+ refreshFileUpload() {
383
+ this.$nextTick(() => {
384
+ this.$refs.fileUpload.reload(this.inputVal)
385
+ })
386
+ },
387
+ handleError(err, file) {
388
+ this.valueOpration(this.convertFile2Item(file))
389
+ //上传失败的附件在3秒后自动移除
390
+ setTimeout(() => {
391
+ this.valueOpration(this.convertFile2Item(file), 'remove')
392
+ }, 3000)
393
+ },
394
+ handleProgress(event, file) {
395
+ this.valueOpration(this.convertFile2Item(file))
396
+ },
397
+ handleClear() {
398
+ this.valueOpration(null, 'clear')
399
+ },
400
+ move(item, direct) {
401
+ this.valueOpration(item, 'move', direct)
402
+ },
403
+ uploadSuccess(response, file, fileList) {
404
+ this.valueOpration(this.convertFile2Item(file))
405
+ this.$emit('onSuccess', response, file, fileList)
406
+ },
407
+ removeFile(file) {
408
+ this.$refs.fileUpload.abort(file)
409
+ this.valueOpration(this.convertFile2Item(file), 'remove')
410
+ this.$emit('remove', file, this.inputVal)
411
+ },
412
+ download(file) {
413
+ // 组件单独绑定了download事件
414
+ if (this.$options._parentListeners.download) {
415
+ this.$emit('download', file, this.inputVal)
416
+ }
417
+ // 未绑定时触发全局download事件处理函数
418
+ else if (this.$requestConfig.download) {
419
+ this.$requestConfig
420
+ .download(file.response.fileId)
421
+ .then(({ data, headers }) => {
422
+ if (data && headers) {
423
+ // 附件下载
424
+ const fileName = decodeURIComponent(
425
+ headers['content-disposition']
426
+ .split(';')[1]
427
+ .split('filename=')[1]
428
+ )
429
+ const blob = new Blob([data])
430
+ saveAs(blob, fileName)
431
+ }
432
+ })
433
+ .catch((err) => {
434
+ this.$message.error(`附件下载失败:${err}`)
435
+ })
436
+ }
437
+ },
438
+ preview(file) {
439
+ if (file.status !== 'success') {
440
+ this.$message.warning(this.t('cl.file.forbiddenPreview'))
441
+ return
442
+ }
443
+ if (this.previewableVal) {
444
+ // 当前组件未添加preview事件监听 并且 设置了全局预览方法
445
+ if (!this._events.preview && this.$preview) {
446
+ this.$preview(file)
446
447
  } else {
447
- let msg = this.t('cl.file.nopreview')
448
- this.$message.warning(msg)
448
+ this.$emit('preview', file, this.inputVal)
449
449
  }
450
- },
451
- handleSort(data) {
452
- this.$emit('input', JSON.stringify(data))
453
- this.refreshFileUploadDebounce()
454
- },
450
+ } else {
451
+ let msg = this.t('cl.file.nopreview')
452
+ this.$message.warning(msg)
453
+ }
454
+ },
455
+ handleSort(data) {
456
+ this.$emit('input', JSON.stringify(data))
457
+ this.refreshFileUploadDebounce()
455
458
  },
456
- }
459
+ },
460
+ }
457
461
  </script>
458
462
  <style lang="scss" scoped>
459
- input[type='hidden'][aria-invalid='true'] + .file-upload-container {
460
- outline: 1px solid #f56c6c;
461
- }
462
- .upload-tooltip {
463
- font-size: 11px;
464
- color: #999999;
465
- line-height: 14px;
466
- }
463
+ input[type='hidden'][aria-invalid='true'] + .file-upload-container {
464
+ outline: 1px solid #f56c6c;
465
+ }
466
+ .upload-tooltip {
467
+ font-size: 11px;
468
+ color: #999999;
469
+ line-height: 14px;
470
+ }
467
471
  </style>