agilebuilder-ui 1.0.73 → 1.0.74-tmp2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agilebuilder-ui",
3
- "version": "1.0.73",
3
+ "version": "1.0.74-tmp2",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./lib/super-ui.js",
@@ -12,7 +12,6 @@
12
12
  "@tinymce/tinymce-vue": "4.0.4",
13
13
  "@zxing/library": "^0.20.0",
14
14
  "async-validator": "^4.2.5",
15
- "compressorjs": "1.2.1",
16
15
  "font-awesome": "^4.7.0",
17
16
  "js-base64": "^3.7.7",
18
17
  "js-cookie": "^3.0.5",
@@ -20,6 +19,7 @@
20
19
  "path-to-regexp": "6.2.1",
21
20
  "sortablejs": "^1.15.0",
22
21
  "tinymce": "5.8.2",
22
+ "compressorjs": "1.2.1",
23
23
  "uuid": "^9.0.1"
24
24
  },
25
25
  "devDependencies": {
@@ -1,249 +1,410 @@
1
1
  <template>
2
2
  <div>
3
- <FileUploadComponent
4
- ref="fileUploadRef"
5
- :disabled="disabled"
6
- :systemCode="systemCode"
7
- :accept="accept"
3
+ <q-uploader
4
+ :url="defaultAction"
5
+ label="Upload"
6
+ field-name="file"
7
+ :with-credentials="true"
8
8
  :multiple="multiple"
9
- :limitFileSize="limitFileSize"
10
- :fileList="fileListResult"
11
- :beforeRemove="beforeRemove"
12
- :onRemove="onRemove"
13
- :beforeDownload="beforeDownload"
14
- :baseURL="baseURLVal"
15
- @chooseFile="pickBrowserFiles"
16
- @remove="removeFile"
17
- />
9
+ >
10
+ <template v-slot:header>
11
+ <div class="row no-wrap items-center q-pa-sm q-gutter-xs">
12
+ <q-btn
13
+ v-if="newFiles.length > 0"
14
+ icon="clear_all"
15
+ round
16
+ dense
17
+ flat
18
+ />
19
+ <q-btn
20
+ v-if="fileList.length > 0"
21
+ icon="done_all"
22
+ round
23
+ dense
24
+ flat
25
+ />
26
+ <q-spinner
27
+ v-if="isUploading && !disable"
28
+ class="q-uploader__spinner"
29
+ />
30
+ <q-btn
31
+ v-if="!disable"
32
+ type="a"
33
+ icon="add_box"
34
+ round
35
+ dense
36
+ flat
37
+ @click="pickFiles"
38
+ />
39
+ <q-btn
40
+ v-if="!disable"
41
+ icon="cloud_upload"
42
+ round
43
+ dense
44
+ flat
45
+ @click="uploadFiles"
46
+ />
47
+ <q-btn
48
+ v-if="showClose"
49
+ icon="close"
50
+ round
51
+ dense
52
+ flat
53
+ @click="$emit('close')"
54
+ >
55
+ <q-tooltip>Close</q-tooltip>
56
+ </q-btn>
57
+ </div>
58
+ </template>
59
+ <template v-slot:list>
60
+ <q-list separator>
61
+ <q-item
62
+ v-for="(tempFile,index) in newFiles"
63
+ :key="index"
64
+ active
65
+ active-class="bg-teal-1 text-grey-8"
66
+ >
67
+ <q-item-section>
68
+ <q-item-label class="full-width ellipsis">
69
+ {{ tempFile.name }}
70
+ </q-item-label>
71
+ </q-item-section>
72
+
73
+ <q-item-section
74
+ v-if="isImg(tempFile)"
75
+ thumbnail
76
+ >
77
+ <img :src="tempFile.base64Path">
78
+ </q-item-section>
79
+
80
+ <q-item-section
81
+ v-if="!disable"
82
+ side
83
+ >
84
+ <q-btn
85
+ size="12px"
86
+ color="red"
87
+ flat
88
+ dense
89
+ round
90
+ icon="delete"
91
+ @click.native="removeFile(index,true,tempFile.name)"
92
+ />
93
+ </q-item-section>
94
+ </q-item>
95
+ </q-list>
96
+ <q-list separator>
97
+ <q-item
98
+ v-for="(myFile,index) in fileList"
99
+ :key="myFile.serverPath"
100
+ >
101
+ <q-item-section>
102
+ <q-item-label class="full-width ellipsis">
103
+ {{ myFile.name }}
104
+ </q-item-label>
105
+ </q-item-section>
106
+
107
+ <q-item-section
108
+ v-if="isImg(myFile)"
109
+ thumbnail
110
+ >
111
+ <img :src="imgSrc+'&showName='+ encodeURI(myFile.name) + '&serverPath=' + myFile.serverPath">
112
+ </q-item-section>
113
+
114
+ <q-item-section
115
+ top
116
+ side
117
+ >
118
+ <div
119
+ class="q-col-gutter-xs row items-start"
120
+ >
121
+ <div class="col">
122
+ <q-btn
123
+ size="12px"
124
+ flat
125
+ dense
126
+ round
127
+ icon="download"
128
+ @click.native="downloadFile(myFile)"
129
+ />
130
+ </div>
131
+ <div
132
+ v-if="!disable"
133
+ class="col"
134
+ >
135
+ <q-btn
136
+ size="12px"
137
+ color="red"
138
+ flat
139
+ dense
140
+ round
141
+ icon="delete"
142
+ @click.native="removeFile(index,false,myFile.name)"
143
+ />
144
+ </div>
145
+ </div>
146
+ </q-item-section>
147
+ </q-item>
148
+ </q-list>
149
+ </template>
150
+ </q-uploader>
18
151
  </div>
19
152
  </template>
20
- <script lang="ts" setup>
21
- import { ref, defineEmits } from 'vue'
22
- import { getToken, getCookieCache } from '../../../../src/utils/auth.js' // 获得token
23
- import Compressor from 'compressorjs'
24
- import { ElMessage } from 'element-plus'
25
- import { useI18n } from 'vue-i18n'
26
- import FileUploadComponent from './file-upload-component.vue'
27
- const props = defineProps({
28
- openFsUpload: {
29
- type: Object,
30
- default: true
31
- },
32
- entity: {
33
- type: Object,
34
- default: () => {
35
- return null
153
+
154
+ <script>
155
+ import Vue from 'vue'
156
+ import {
157
+ getToken
158
+ } from '../../../src/utils/auth.js' // 获得token
159
+ export default {
160
+ name: 'FileUploadApp',
161
+ props: {
162
+ systemCode: {
163
+ type: String,
164
+ default: null
165
+ },
166
+ multiple: {
167
+ type: Boolean,
168
+ default: false
169
+ },
170
+ // 已上传文件列表
171
+ fileResult: {
172
+ type: Array,
173
+ default: null
174
+ },
175
+ showClose: {
176
+ type: Boolean,
177
+ default: true
178
+ },
179
+ // 是否禁止编辑,为true只能下载,不能删除和上传
180
+ disable: {
181
+ type: Boolean,
182
+ default: false
183
+ },
184
+ // 文件大小限制,单位是M
185
+ limitFileSize: {
186
+ type: Number,
187
+ default: null
188
+ },
189
+ beforeUpload: {
190
+ type: Function,
191
+ default: null
192
+ },
193
+ beforeRemove: {
194
+ type: Function,
195
+ default: null
196
+ },
197
+ // 组件id,在表单或列表中应该唯一,一般传字段名即可
198
+ componentId: {
199
+ type: String,
200
+ default: function () {
201
+ return 'file-upload'
202
+ }
203
+ },
204
+ // 组件名称,一般是字段label
205
+ componentName: {
206
+ type: String,
207
+ default: function () {
208
+ return 'file-upload'
209
+ }
210
+ },
211
+ options: {
212
+ type: Object,
213
+ default: null
214
+ },
215
+ // 列表编码。选择文件后,回填列表文件集合使用。
216
+ listCode: {
217
+ type: String,
218
+ default: null
36
219
  }
37
220
  },
38
- fileInfo: {
39
- type: Object,
40
- default: () => ({})
41
- },
42
- systemCode: {
43
- type: String,
44
- default: ''
45
- },
46
- displayType: {
47
- type: String,
48
- default: 'input'
49
- },
50
- // 是否禁止编辑,为true只能下载,不能删除和上传
51
- disabled: {
52
- type: Boolean,
53
- default: false
54
- },
55
- accept: {
56
- type: String,
57
- default: ''
58
- },
59
- multiple: {
60
- type: Boolean,
61
- default: false
62
- },
63
- limit: {
64
- type: Number,
65
- default: 1
66
- },
67
- // 文件大小限制,单位是M,默认是30M
68
- limitFileSize: {
69
- type: Number,
70
- default: 30
71
- },
72
- placeholder: {
73
- type: String,
74
- default: '拖拽文件 或 点击上传'
75
- },
76
- action: {
77
- type: String,
78
- default: ''
79
- },
80
- headers: {
81
- type: Object,
82
- default: () => ({ Authorization: null })
83
- },
84
- // 已上传文件列表
85
- fileList: {
86
- type: Array,
87
- default: () => []
88
- },
89
- onSuccess: {
90
- type: Function,
91
- default: () => {}
92
- },
93
- beforeRemove: {
94
- type: Function,
95
- default: () => {}
96
- },
97
- onRemove: {
98
- type: Function,
99
- default: () => {}
100
- },
101
- beforeDownload: {
102
- type: Function,
103
- default: () => {}
104
- },
105
- pageContext: {
106
- type: Object,
107
- default: () => ({})
108
- },
109
- configure: {
110
- type: Object,
111
- default: () => ({})
112
- },
113
- // 组件id,在表单或列表中应该唯一,一般传字段名即可
114
- componentId: {
115
- type: String,
116
- default: function () {
117
- return 'file-upload'
221
+ data () {
222
+ let fileList = []
223
+ if (this.fileResult) {
224
+ fileList = JSON.parse(JSON.stringify(this.fileResult))
118
225
  }
119
- },
120
- // 组件名称,一般是字段label
121
- componentName: {
122
- type: String,
123
- default: function () {
124
- return 'file-upload'
226
+ const defaultAction = Vue.prototype.baseAPI + '/component/super-form/uploads'
227
+ const token = getToken()
228
+ let baseURL
229
+ if (this.options) {
230
+ baseURL = this.options.backendUrl
231
+ }
232
+ if (!baseURL) {
233
+ baseURL = Vue.prototype.baseURL
234
+ }
235
+ const imgSrc = baseURL + '/common/super-form/downloads?jwt=' + token
236
+ return {
237
+ defaultAction,
238
+ fileList,
239
+ imgSrc,
240
+ newFiles: [],
241
+ isUploading: false, // 是否正在上传
242
+ baseURL
125
243
  }
126
244
  },
127
- options: {
128
- type: Object,
129
- default: null
130
- },
131
- // 列表编码
132
- listCode: {
133
- type: String,
134
- default: null
135
- },
136
- // 打开相机和相册选项,默认是都可以打开
137
- openCameraOrChoosePhoto: {
138
- type: String,
139
- default: 'openCameraAndChoosePhoto'
245
+ watch: {
246
+ fileResult (val) {
247
+ this.fileList = JSON.parse(JSON.stringify(val))
248
+ }
140
249
  },
141
- beforeUpload: {
142
- type: Function,
143
- default: () => {}
144
- }
145
- })
146
-
147
- const fileListResult = ref(props.fileList)
148
- let baseURL = window.$vueApp.config.globalProperties.baseURL
149
- if (props.options) {
150
- baseURL = props.options.backendUrl
151
- }
152
- if (!baseURL) {
153
- baseURL = window.$vueApp.config.globalProperties.baseURL
154
- }
155
- const baseURLVal = ref(baseURL)
156
-
157
- const baseAPI = window.$vueApp.config.globalProperties.baseAPI
158
- const fileUploadRef = ref(null)
159
- const emits = defineEmits(['remove', 'uploadend'])
160
-
161
- // 表示点击了选择文件按钮
162
- function pickBrowserFiles() {
163
- // console.log('---点击了选择文件按钮---')
164
- const message = {
165
- type: 'pickFiles',
166
- multiple: props.multiple,
167
- componentId: props.componentId,
168
- componentName: props.componentName,
169
- systemCode: props.systemCode,
170
- token: getToken(),
171
- listCode: props.listCode
172
- }
173
- window.parent.postMessage(JSON.stringify(message), '*')
174
- }
175
-
176
- function pickFileDone(data) {
177
- appFileDone(data)
178
- }
179
- function uploadFileDone(data) {
180
- // 表示文件上传到服务器成功
181
- appFileDone(data)
182
- }
183
- function appFileDone(data) {
184
- const files = data.files
185
- let myFiles = files
186
- if (files && typeof files === 'string') {
187
- myFiles = JSON.parse(files)
188
- }
189
- if (myFiles && !Array.isArray(myFiles)) {
190
- myFiles = [myFiles]
191
- }
192
- uploadFileSuccess(myFiles)
193
- }
194
- function uploadFileSuccess(files) {
195
- // this.isUploading = true
196
- let isCanUpload = true
197
- if (props.beforeUpload && typeof props.beforeUpload === 'function') {
198
- for (let i = 0; i < files.length; i++) {
199
- const file = files[i]
200
- const isMobile = true
201
- // eslint-disable-next-line no-useless-call
202
- isCanUpload = props.beforeUpload({
203
- fileObj: file,
204
- files: files,
205
- isMobile,
206
- pageContext: props.pageContext,
207
- configureObj: props.configure
208
- })
209
- if (isCanUpload !== undefined && isCanUpload === false) {
210
- break
250
+ methods: {
251
+ addFile (files) {
252
+ if (this.multiple) {
253
+ this.newFiles = this.newFiles.concat(files)
254
+ } else {
255
+ if (files && files.length > 0) {
256
+ this.newFiles = files
257
+ } else {
258
+ this.newFiles = []
259
+ }
211
260
  }
261
+ this.$emit('pickup-file', this.newFiles)
262
+ },
263
+ isImg (file) {
264
+ const fileName = file.name
265
+ if (fileName) {
266
+ return fileName.indexOf('jpg') !== -1 || fileName.indexOf('JPG') !== -1 || fileName.indexOf('png') !== -1 || fileName.indexOf('PNG') !== -1
267
+ }
268
+ return false
269
+ },
270
+ removeFile (index, isTemp, fileName) {
271
+ if (!isTemp) {
272
+ // 表示是已经上传了的文件
273
+ const rmFile = JSON.parse(JSON.stringify(this.fileList[index]))
274
+ this.fileList.splice(index, 1)
275
+ this.$emit('remove', { rmFiles: [rmFile], serverFiles: this.fileList })
276
+ } else {
277
+ // 表示是新添加,还未上传的文件
278
+ const rmFile = JSON.parse(JSON.stringify(this.newFiles[index]))
279
+ this.newFiles.splice(index, 1)
280
+ this.$emit('remove', { rmFiles: [rmFile], serverFiles: this.fileList, newFiles: this.newFiles })
281
+ // console.log('---点击了删除文件按钮,发送postmessage给手机端---')
282
+ const message = {
283
+ type: 'removeFiles',
284
+ files: [fileName],
285
+ componentId: this.componentId,
286
+ componentName: this.componentName
287
+ }
288
+ window.parent.postMessage(JSON.stringify(message), '*')
289
+ }
290
+ },
291
+ downloadFile (file) {
292
+ this.$emit('download', file)
293
+ },
294
+ // 表示点击了选择文件按钮
295
+ pickFiles () {
296
+ // console.log('---点击了选择文件按钮---')
297
+ const message = {
298
+ type: 'pickFiles',
299
+ multiple: this.multiple,
300
+ componentId: this.componentId,
301
+ componentName: this.componentName,
302
+ systemCode: this.systemCode,
303
+ token: getToken(),
304
+ listCode: this.listCode
305
+ }
306
+ window.parent.postMessage(JSON.stringify(message), '*')
307
+ },
308
+ // 表示点击了上传按钮
309
+ uploadFiles () {
310
+ // console.log('---点击了上传按钮---this.newFiles=', this.newFiles)
311
+ if (this.newFiles && this.newFiles.length > 0) {
312
+ this.isUploading = true
313
+ // const message = {
314
+ // type: 'uploadFiles',
315
+ // systemCode: this.systemCode,
316
+ // token: getToken(),
317
+ // limitFileSize: this.limitFileSize,
318
+ // componentId: this.componentId,
319
+ // componentName: this.componentName
320
+ // }
321
+ let isCanUpload = true
322
+ if (this.beforeUpload && typeof (this.beforeUpload) === 'function') {
323
+ for (let i = 0; i < this.newFiles.length; i++) {
324
+ const file = this.newFiles[i]
325
+ const isMobile = true
326
+ // eslint-disable-next-line no-useless-call
327
+ isCanUpload = this.beforeUpload.call(this, file, isMobile)
328
+ if (isCanUpload !== undefined && isCanUpload === false) {
329
+ break
330
+ }
331
+ }
332
+ }
333
+ if (!isCanUpload) {
334
+ // 不能提交文件
335
+ return
336
+ }
337
+ // window.parent.postMessage(JSON.stringify(message), '*')
338
+ this.uploadFileSuccess(this.newFiles)
339
+ } else {
340
+ this.$emit('uploadend', this.fileList)
341
+ }
342
+ },
343
+ cleareQueuedFiles () {
344
+ // console.log('---cleareQueuedFiles---')
345
+ this.newFiles = []
346
+ // console.log('---点击了清空临时文件按钮,发送postmessage给手机端---')
347
+ const message = {
348
+ type: 'clearFiles',
349
+ componentId: this.componentId,
350
+ componentName: this.componentName
351
+ }
352
+ window.parent.postMessage(JSON.stringify(message), '*')
353
+ },
354
+ clearUploadedFiles () {
355
+ // console.log('---clearUploadedFiles---')
356
+ this.fileList = []
357
+ },
358
+ pickFileDone (data) {
359
+ this.appFileDone(data)
360
+ },
361
+ uploadFileDone (data) {
362
+ // 表示文件上传到服务器成功
363
+ this.appFileDone(data)
364
+ },
365
+ appFileDone (data) {
366
+ const files = data.files
367
+ let myFiles = files
368
+ if (files && typeof files === 'string') {
369
+ myFiles = JSON.parse(files)
370
+ }
371
+ if (myFiles && !Array.isArray(myFiles)) {
372
+ myFiles = [myFiles]
373
+ }
374
+ if (data.type === 'pickFileDone') {
375
+ // 选择文件完成
376
+ console.log('appFileDone11111----myFiles=', JSON.stringify(myFiles))
377
+ this.addFile(myFiles)
378
+ } else {
379
+ // 表示文件上传到服务器成功
380
+ console.log('appFileDone22222----myFiles=', JSON.stringify(myFiles))
381
+ this.uploadFileSuccess(myFiles)
382
+ }
383
+ },
384
+ uploadFileSuccess (files) {
385
+ this.isUploading = false
386
+ // 表示文件上传到服务器成功
387
+ if (files) {
388
+ // files:[{name:'',serverPath:''},{name:'',serverPath:''}]
389
+ if (this.multiple) {
390
+ this.$set(this, 'fileList', this.fileList.concat(files))
391
+ } else {
392
+ // 单选时将已选文件移除,然后再替换为新上传的文件
393
+ const rmFiles = JSON.parse(JSON.stringify(this.fileList))
394
+ this.fileResult[0] = files
395
+ this.$set(this, 'fileList', files)
396
+ this.$emit('remove', { rmFiles, serverFiles: this.fileList })
397
+ }
398
+ }
399
+ console.log('uploadFileSuccess111111----this.fileList=', JSON.stringify(this.fileList))
400
+ this.$set(this, 'newFiles', [])
401
+ this.$set(this, 'isUploading', false)
402
+ this.$emit('uploadend', this.fileList)
212
403
  }
213
404
  }
214
- if (isCanUpload !== undefined && !isCanUpload) {
215
- // 不能提交文件
216
- return
217
- }
218
- // this.isUploading = false
219
- // 表示文件上传到服务器成功
220
- if (files) {
221
- // files:[{name:'',serverPath:''},{name:'',serverPath:''}]
222
- if (props.multiple) {
223
- files.forEach((file) => {
224
- fileListResult.value.push(file)
225
- })
226
- } else {
227
- // 单选时将已选文件移除,然后再替换为新上传的文件
228
- const rmFiles = JSON.parse(JSON.stringify(fileListResult.value))
229
- fileListResult.value = files
230
- emits('remove', { rmFiles, serverFiles: fileListResult.value })
231
- }
232
- }
233
- console.log('uploadFileSuccess111111----fileListResult.value=', JSON.stringify(fileListResult.value))
234
-
235
- fileUploadRef.value.changeFileList(fileListResult.value)
236
- // this.isUploading = false
237
- emits('uploadend', fileListResult.value)
238
- }
239
-
240
- function removeFile(param) {
241
- console.log('removeFile----param=', param)
242
- const file = param.file
243
- if (file) {
244
- emits('remove', { rmFiles: [file], serverFiles: fileListResult.value, index: param.index })
245
- }
246
405
  }
247
406
  </script>
248
407
 
249
- <style lang="scss" scoped></style>
408
+ <style lang="scss" scoped>
409
+
410
+ </style>