vue2-client 1.3.25 → 1.4.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.
@@ -1,167 +1,168 @@
1
- <template>
2
- <div>
3
- <a-upload-dragger
4
- v-if="model.type === 'file'"
5
- :accept="model.accept.join('')"
6
- :customRequest="uploadFiles"
7
- :file-list="uploadedFileList"
8
- :multiple="true"
9
- :remove="deleteFileItem"
10
- name="file">
11
- <p class="ant-upload-drag-icon">
12
- <a-icon type="inbox"/>
13
- </p>
14
- <p class="ant-upload-text">
15
- 点击或拖动文件到该区域上传
16
- </p>
17
- <p class="ant-upload-hint">
18
- 支持单个或多个文件
19
- </p>
20
- </a-upload-dragger>
21
- <a-upload
22
- v-if=" model.type === 'image'"
23
- :accept="model.accept.join('')"
24
- :customRequest="uploadFiles"
25
- :file-list="uploadedFileList"
26
- :remove="deleteFileItem"
27
- list-type="picture-card">
28
- <a-icon type="plus"/>
29
- <div class="ant-upload-text">
30
- Upload
31
- </div>
32
- </a-upload>
33
- </div>
34
- </template>
35
-
36
- <script>
37
-
38
- import { post } from '@vue2-client/services/api'
39
- import { mapState } from 'vuex'
40
-
41
- export default {
42
- name: 'uploads',
43
- data () {
44
- return {
45
- uploadedFileList: [],
46
- }
47
- },
48
- props: {
49
- // 表单属性
50
- model: {
51
- type: Object,
52
- default: () => {
53
- return {}
54
- }
55
- },
56
- files: {
57
- type: Array,
58
- default: () => {
59
- return []
60
- }
61
- },
62
- images: {
63
- type: Array,
64
- default: () => {
65
- return []
66
- }
67
- },
68
- serviceName: {
69
- type: String,
70
- default: 'af-system'
71
- }
72
- },
73
- computed: {
74
- ...mapState('account', { currUser: 'user' })
75
- },
76
- created () {
77
- const list = this.model.type === 'file' ? [...this.files] : [...this.images]
78
- if (this.model.useType) {
79
- this.uploadedFileList = list.filter(item => item.f_use_type === this.model.useType)
80
- } else {
81
- this.uploadedFileList = list
82
- }
83
- this.$emit('setFiles', this.uploadedFileList.filter(item => item.status === 'done').map(item => item.id))
84
- },
85
- methods: {
86
- uploadFiles (info) {
87
- if (this.uploadedFileList.length >= this.model.acceptCount) {
88
- this.$message.error(`当前表单限制仅可上传 ${this.model.acceptCount} 个文件`)
89
- return
90
- }
91
- // 初始化文件信息
92
- const fileInfo = {
93
- uid: info.file.uid,
94
- name: info.file.name,
95
- status: 'uploading',
96
- response: '',
97
- url: '',
98
- }
99
- // 放入上传列表中,以便于显示上传进度
100
- this.uploadedFileList.push(fileInfo)
101
- // 组装上传数据
102
- const headers = {
103
- 'Content-Type': 'multipart/form-data',
104
- }
105
- const formData = new FormData()
106
- formData.append('avatar', info.file)
107
- formData.append('resUploadMode', this.model.resUploadMode ?? 'server')
108
- if (this.model.pathKey) {
109
- formData.append('pathKey', this.model.pathKey ?? 'Default')
110
- }
111
- // formData.append('stockAlias', this.model.stockAlias)
112
- formData.append('formType', this.model.type)
113
- formData.append('useType', this.model.useType ?? 'Default')
114
- formData.append('resUploadStock', this.model.resUploadStock)
115
- formData.append('filename', info.file.name)
116
- formData.append('filesize', (info.file.size / 1024 / 1024).toFixed(4))
117
- formData.append('f_operator', this.currUser ? this.currUser.username : '')
118
-
119
- // const url = '/api/af-system/resource'
120
- // if (process.env.NODE_ENV === 'production') {
121
- // url = `/${this.model.stockAlias}/af-system/resource`
122
- // }
123
- post('/api/' + this.serviceName + '/resource/upload', formData, { headers, timeout: 60 * 1000 }).then(res => {
124
- // 根据服务端返回的结果判断成功与否,设置文件条目的状态
125
- if (res.success) {
126
- fileInfo.status = 'done'
127
- let dataObj
128
- if (typeof res.data === 'string') {
129
- dataObj = JSON.parse(res.data)
130
- } else {
131
- dataObj = res.data
132
- }
133
- fileInfo.response = dataObj
134
- fileInfo.id = dataObj.id
135
- fileInfo.url = dataObj.f_downloadpath
136
- this.$emit('setFiles', this.uploadedFileList.filter(item => item.status === 'done').map(item => item.id))
137
- this.$message.success('上传成功!')
138
- } else {
139
- fileInfo.status = 'error'
140
- fileInfo.response = res.data
141
- this.$message.error('上传失败!')
142
- }
143
- }).catch((e) => {
144
- fileInfo.status = 'error'
145
- fileInfo.response = e
146
- this.$message.error(`请求失败!${e}`)
147
- })
148
- },
149
- // 删除文件
150
- deleteFileItem (file) {
151
- if (file.id) {
152
- post('/api/' + this.serviceName + '/entity/t_files', { id: file.id, f_state: '删除' }).then(res => {
153
- }).catch(e => { })
154
- }
155
- // 找到当前文件所在列表的索引
156
- const index = this.uploadedFileList.indexOf(file)
157
- // 从列表中移除该文件
158
- this.uploadedFileList.splice(index, 1)
159
- this.$emit('setFiles', this.uploadedFileList.filter(item => item.status === 'done').map(item => item.id))
160
- return true
161
- }
162
- }
163
- }
164
- </script>
165
- <style lang="less" scoped>
166
-
167
- </style>
1
+ <template>
2
+ <div>
3
+ <a-upload-dragger
4
+ v-if="model.type === 'file'"
5
+ :accept="model.accept.join('')"
6
+ :customRequest="uploadFiles"
7
+ :file-list="uploadedFileList"
8
+ :multiple="true"
9
+ :remove="deleteFileItem"
10
+ name="file">
11
+ <p class="ant-upload-drag-icon">
12
+ <a-icon type="inbox"/>
13
+ </p>
14
+ <p class="ant-upload-text">
15
+ 点击或拖动文件到该区域上传
16
+ </p>
17
+ <p class="ant-upload-hint">
18
+ 支持单个或多个文件
19
+ </p>
20
+ </a-upload-dragger>
21
+ <a-upload
22
+ v-if=" model.type === 'image'"
23
+ :accept="model.accept.join('')"
24
+ :customRequest="uploadFiles"
25
+ :file-list="uploadedFileList"
26
+ :remove="deleteFileItem"
27
+ list-type="picture-card">
28
+ <a-icon type="plus"/>
29
+ <div class="ant-upload-text">
30
+ Upload
31
+ </div>
32
+ </a-upload>
33
+ </div>
34
+ </template>
35
+
36
+ <script>
37
+
38
+ import { post } from '@vue2-client/services/api'
39
+ import { mapState } from 'vuex'
40
+ import { upload } from '@vue2-client/services/api/common'
41
+
42
+ export default {
43
+ name: 'uploads',
44
+ data () {
45
+ return {
46
+ uploadedFileList: [],
47
+ }
48
+ },
49
+ props: {
50
+ // 表单属性
51
+ model: {
52
+ type: Object,
53
+ default: () => {
54
+ return {}
55
+ }
56
+ },
57
+ files: {
58
+ type: Array,
59
+ default: () => {
60
+ return []
61
+ }
62
+ },
63
+ images: {
64
+ type: Array,
65
+ default: () => {
66
+ return []
67
+ }
68
+ },
69
+ serviceName: {
70
+ type: String,
71
+ default: 'af-system'
72
+ }
73
+ },
74
+ computed: {
75
+ ...mapState('account', { currUser: 'user' })
76
+ },
77
+ created () {
78
+ const list = this.model.type === 'file' ? [...this.files] : [...this.images]
79
+ if (this.model.useType) {
80
+ this.uploadedFileList = list.filter(item => item.f_use_type === this.model.useType)
81
+ } else {
82
+ this.uploadedFileList = list
83
+ }
84
+ this.$emit('setFiles', this.uploadedFileList.filter(item => item.status === 'done').map(item => item.id))
85
+ },
86
+ methods: {
87
+ uploadFiles (info) {
88
+ if (this.uploadedFileList.length >= this.model.acceptCount) {
89
+ this.$message.error(`当前表单限制仅可上传 ${this.model.acceptCount} 个文件`)
90
+ return
91
+ }
92
+ // 初始化文件信息
93
+ const fileInfo = {
94
+ uid: info.file.uid,
95
+ name: info.file.name,
96
+ status: 'uploading',
97
+ response: '',
98
+ url: '',
99
+ }
100
+ // 放入上传列表中,以便于显示上传进度
101
+ this.uploadedFileList.push(fileInfo)
102
+ // 组装上传数据
103
+ const headers = {
104
+ 'Content-Type': 'multipart/form-data',
105
+ }
106
+ const formData = new FormData()
107
+ formData.append('avatar', info.file)
108
+ formData.append('resUploadMode', this.model.resUploadMode ?? 'server')
109
+ if (this.model.pathKey) {
110
+ formData.append('pathKey', this.model.pathKey ?? 'Default')
111
+ }
112
+ // formData.append('stockAlias', this.model.stockAlias)
113
+ formData.append('formType', this.model.type)
114
+ formData.append('useType', this.model.useType ?? 'Default')
115
+ formData.append('resUploadStock', this.model.resUploadStock)
116
+ formData.append('filename', info.file.name)
117
+ formData.append('filesize', (info.file.size / 1024 / 1024).toFixed(4))
118
+ formData.append('f_operator', this.currUser ? this.currUser.username : '')
119
+
120
+ // const url = '/api/af-system/resource'
121
+ // if (process.env.NODE_ENV === 'production') {
122
+ // url = `/${this.model.stockAlias}/af-system/resource`
123
+ // }
124
+ upload(formData, this.serviceName, { headers, timeout: 60 * 1000 }).then(res => {
125
+ // 根据服务端返回的结果判断成功与否,设置文件条目的状态
126
+ if (res.success) {
127
+ fileInfo.status = 'done'
128
+ let dataObj
129
+ if (typeof res.data === 'string') {
130
+ dataObj = JSON.parse(res.data)
131
+ } else {
132
+ dataObj = res.data
133
+ }
134
+ fileInfo.response = dataObj
135
+ fileInfo.id = dataObj.id
136
+ fileInfo.url = dataObj.f_downloadpath
137
+ this.$emit('setFiles', this.uploadedFileList.filter(item => item.status === 'done').map(item => item.id))
138
+ this.$message.success('上传成功!')
139
+ } else {
140
+ fileInfo.status = 'error'
141
+ fileInfo.response = res.data
142
+ this.$message.error('上传失败!')
143
+ }
144
+ }).catch((e) => {
145
+ fileInfo.status = 'error'
146
+ fileInfo.response = e
147
+ this.$message.error(`请求失败!${e}`)
148
+ })
149
+ },
150
+ // 删除文件
151
+ deleteFileItem (file) {
152
+ if (file.id) {
153
+ post('/api/' + this.serviceName + '/entity/t_files', { id: file.id, f_state: '删除' }).then(res => {
154
+ }).catch(e => { })
155
+ }
156
+ // 找到当前文件所在列表的索引
157
+ const index = this.uploadedFileList.indexOf(file)
158
+ // 从列表中移除该文件
159
+ this.uploadedFileList.splice(index, 1)
160
+ this.$emit('setFiles', this.uploadedFileList.filter(item => item.status === 'done').map(item => item.id))
161
+ return true
162
+ }
163
+ }
164
+ }
165
+ </script>
166
+ <style lang="less" scoped>
167
+
168
+ </style>
@@ -49,31 +49,53 @@
49
49
  <a-button v-if="!buttonState || buttonState.delete" :disabled="!isDelete" type="danger" @click="deleteItem">
50
50
  <a-icon :style="iconStyle" type="delete"/>删除
51
51
  </a-button>
52
+ <a-button v-if="!buttonState || buttonState.import" type="dashed" @click="$refs.importExcel.importExcelHandleOpen()">
53
+ <a-icon :style="iconStyle" type="import" />导入
54
+ </a-button>
55
+ <a-dropdown v-if="!buttonState || buttonState.export">
56
+ <a-menu slot="overlay">
57
+ <a-menu-item :disabled="selectedRowKeys.length === 0" key="1" @click="handleExport(true)"><a-icon :style="iconStyle" type="ordered-list" />导出选中数据</a-menu-item>
58
+ <a-menu-item key="2" @click="handleExport"><a-icon :style="iconStyle" type="snippets" />导出本页数据</a-menu-item>
59
+ <a-menu-item key="3" @click="handleExportByQuery"><a-icon :style="iconStyle" type="download" />导出所有符合条件的数据</a-menu-item>
60
+ </a-menu>
61
+ <a-button>导出 <a-icon type="down" /> </a-button>
62
+ </a-dropdown>
52
63
  <slot :selectedRowKeys="selectedRowKeys" name="button"></slot>
53
64
  </a-space>
54
65
  <slot name="expand"></slot>
55
66
  </template>
56
67
  </x-table>
68
+ <!-- 上传文件 -->
69
+ <x-import-excel
70
+ ref="importExcel"
71
+ @ok="refreshTable"
72
+ :title="title"
73
+ :service-name="serviceName"
74
+ :query-params-name="queryParamsName"
75
+ />
57
76
  </template>
58
77
  </a-skeleton>
59
78
  </template>
60
79
  <script>
61
- import XForm from '@vue2-client/base-client/components/common/XForm/XForm'
62
- import XAddForm from '@vue2-client/base-client/components/common/XAddForm/XAddForm'
63
- import XTable from '@vue2-client/base-client/components/common/XTable/XTable'
64
- import { query, commonApi, addOrModify, remove, queryWithResource } from '@vue2-client/services/api/common'
80
+ import XForm from '@vue2-client/base-client/components/common/XForm'
81
+ import XAddForm from '@vue2-client/base-client/components/common/XAddForm'
82
+ import XTable from '@vue2-client/base-client/components/common/XTable'
83
+ import XImportExcel from '@vue2-client/base-client/components/common/XImportExcel'
84
+ import { query, download, commonApi, addOrModify, remove, queryWithResource } from '@vue2-client/services/api/common'
65
85
  import { indexedDB } from '@vue2-client/utils/indexedDB'
66
86
  import { mapState } from 'vuex'
67
87
  import { Modal } from 'ant-design-vue'
68
88
  import { post } from '@vue2-client/services/api/restTools'
69
89
  import { CommonTempTable } from '@vue2-client/services/api/commonTempTable'
90
+ import { exportJson } from '@vue2-client/utils/excel/Export2Excel'
70
91
 
71
92
  export default {
72
93
  name: 'XFormTable',
73
94
  components: {
74
95
  XTable,
75
96
  XForm,
76
- XAddForm
97
+ XAddForm,
98
+ XImportExcel
77
99
  },
78
100
  data () {
79
101
  return {
@@ -117,11 +139,7 @@ export default {
117
139
  // 被修改数据加载状态
118
140
  editDataLoading: false,
119
141
  // 是否为临时表
120
- isTableTemp: false,
121
- // 自定义新增修改接口
122
- customAoM: undefined,
123
- // 自定义查询接口
124
- customQuery: undefined
142
+ isTableTemp: false
125
143
  }
126
144
  },
127
145
  computed: {
@@ -177,11 +195,6 @@ export default {
177
195
  return false
178
196
  }
179
197
  },
180
- // 动态创建子表需要的定义
181
- tempTableData: {
182
- type: Object,
183
- default: null
184
- },
185
198
  // 数据只有一页时是否展示分页,true:展示,auto:隐藏
186
199
  showPagination: {
187
200
  type: Boolean,
@@ -227,18 +240,18 @@ export default {
227
240
  this.formItems = res.formJson
228
241
  this.buttonState = res.buttonState
229
242
  this.serviceName = res.serviceName
230
- this.customAoM = res.customAoM
231
- this.customQuery = res.customQuery
232
243
  this.mainLoading = false
233
244
  this.loaded = true
234
245
  },
235
246
  getColumnsJson () {
247
+ this.form = {}
236
248
  this.mainLoading = true
237
249
  indexedDB.getByWeb(this.queryParamsName, commonApi.getColumnsJson, { str: this.queryParamsName }, (ret) => {
238
250
  this.setParams(ret)
239
251
  })
240
252
  },
241
253
  getColumnsJsonBySource () {
254
+ this.form = {}
242
255
  this.mainLoading = true
243
256
  post(commonApi.getColumnsJson, { queryObject: this.queryParamsJson }).then(res => {
244
257
  this.queryParams = res
@@ -267,7 +280,7 @@ export default {
267
280
  // 新增/修改数据表单提交
268
281
  onAddOrModify (res) {
269
282
  if (this.viewMode) {
270
- this.$message.info('预览模式禁止新增')
283
+ this.$message.info('预览模式禁止新增和修改')
271
284
  return false
272
285
  }
273
286
  // 如果是临时表
@@ -276,39 +289,35 @@ export default {
276
289
  return
277
290
  }
278
291
  if (res.valid) {
279
- this.loading = true
280
- const requestParameters = {
281
- queryParamsName: this.queryParamsName,
282
- form: {}
283
- }
284
- if (this.businessType === '修改') {
285
- const rowKeyValue = this.selectedRowKeys[0]
286
- const key = this.tableColumns[0].dataIndex
287
- const realKey = key.substring(key.indexOf('_') + 1)
288
- requestParameters.form[realKey] = rowKeyValue
289
- }
290
- for (const key of Object.keys(res.form)) {
291
- const realKey = key.substring(key.indexOf('_') + 1)
292
- requestParameters.form[realKey] = res.form[key]
293
- }
294
- if (!this.customAoM || this.customAoM?.length === 0) {
295
- this.customAoM = undefined
296
- }
297
- addOrModify(requestParameters, this.customAoM, this.serviceName).then(res => {
298
- this.$message.success(this.businessType + '成功!')
299
- this.loading = false
300
- this.modelVisible = false
301
- this.$refs.xTable.refresh(true)
302
- // commit
303
- this.$emit('afterSubmit', { type: this.businessType, id: res.id, form: requestParameters.form })
304
- }).catch(e => {
305
- this.loading = false
306
- this.modelVisible = false
307
- this.$message.error(this.businessType + '失败!')
308
- })
309
- } else {
310
292
  return false
311
293
  }
294
+ this.loading = true
295
+ const requestParameters = {
296
+ queryParamsName: this.queryParamsName,
297
+ form: {}
298
+ }
299
+ if (this.businessType === '修改') {
300
+ // 将更新需要的主键值加入到表单中
301
+ const key = this.tableColumns[0].dataIndex
302
+ const realKey = this.getRealKey(key)
303
+ requestParameters.form[realKey] = this.selectedRowKeys[0]
304
+ }
305
+ for (const key of Object.keys(res.form)) {
306
+ const realKey = this.getRealKey(key)
307
+ requestParameters.form[realKey] = res.form[key]
308
+ }
309
+ addOrModify(requestParameters, this.serviceName).then(res => {
310
+ this.$message.success(this.businessType + '成功!')
311
+ this.loading = false
312
+ this.modelVisible = false
313
+ this.$refs.xTable.refresh(true)
314
+ // commit
315
+ this.$emit('afterSubmit', { type: this.businessType, id: res.id, form: requestParameters.form })
316
+ }).catch(e => {
317
+ this.loading = false
318
+ this.modelVisible = false
319
+ this.$message.error(this.businessType + '失败!')
320
+ })
312
321
  },
313
322
  // 刷新加载表格数据
314
323
  loadData (requestParameters, callback) {
@@ -320,7 +329,7 @@ export default {
320
329
  }
321
330
  }
322
331
  if (!this.isTableTemp) {
323
- result = query(requestParameters, undefined, this.serviceName)
332
+ result = query(requestParameters, this.serviceName)
324
333
  }
325
334
  this.$emit('afterQuery', result)
326
335
  callback(result)
@@ -329,6 +338,10 @@ export default {
329
338
  action (record, id) {
330
339
  this.$emit('action', record, id)
331
340
  },
341
+ // 获取数据字段实际值
342
+ getRealKey (key) {
343
+ return key.substring(key.indexOf('_') + 1)
344
+ },
332
345
  // 新增业务
333
346
  addItem () {
334
347
  this.businessType = '新增'
@@ -338,32 +351,24 @@ export default {
338
351
  // 修改业务
339
352
  editItem () {
340
353
  this.businessType = '修改'
341
- if (!this.viewMode) {
342
- const requestParameters = {
343
- queryParamsName: this.queryParamsName,
344
- conditionParams: {},
345
- pageNo: 1,
346
- pageSize: 1
347
- }
348
- requestParameters.conditionParams[this.tableColumns[0].dataIndex] = this.selectedRowKeys[0]
349
- requestParameters.f_businessid = this.selectedRowKeys[0]
350
- if (this.isTableTemp) {
351
- this.$emit('tempTableEdit', requestParameters)
352
- return
353
- }
354
- this.editDataLoading = true
355
- if (!this.customQuery || this.customQuery?.length === 0) {
356
- this.customQuery = undefined
357
- }
358
- queryWithResource(requestParameters, this.customQuery, this.serviceName).then(res => {
359
- this.modifyModelData = { data: res.data[0], images: res.images, files: res.files }
360
- this.modelVisible = true
361
- this.editDataLoading = false
362
- console.warn(this.modifyModelData)
363
- })
364
- } else {
365
- this.$message.info('预览模式禁止修改')
354
+ const requestParameters = {
355
+ queryParamsName: this.queryParamsName,
356
+ conditionParams: {},
357
+ pageNo: 1,
358
+ pageSize: 1
366
359
  }
360
+ requestParameters.conditionParams[this.tableColumns[0].dataIndex] = this.selectedRowKeys[0]
361
+ requestParameters.f_businessid = this.selectedRowKeys[0]
362
+ if (this.isTableTemp) {
363
+ this.$emit('tempTableEdit', requestParameters)
364
+ return
365
+ }
366
+ this.editDataLoading = true
367
+ queryWithResource(requestParameters, this.serviceName).then(res => {
368
+ this.modifyModelData = { data: res.data[0], images: res.images, files: res.files }
369
+ this.modelVisible = true
370
+ this.editDataLoading = false
371
+ })
367
372
  },
368
373
  // 删除业务
369
374
  deleteItem () {
@@ -382,7 +387,7 @@ export default {
382
387
  queryParamsName: this.queryParamsName,
383
388
  idList: this.selectedRowKeys
384
389
  }
385
- remove(requestParameters, undefined, this.serviceName).then(res => {
390
+ remove(requestParameters, this.serviceName).then(res => {
386
391
  this.loading = false
387
392
  this.$message.success('删除成功!')
388
393
  this.$refs.xTable.clearRowKeys()
@@ -397,6 +402,38 @@ export default {
397
402
  onCancel () {}
398
403
  })
399
404
  },
405
+ // 导出选中或本页数据
406
+ handleExport (isSelected) {
407
+ const tHeader = this.tableColumns.filter(res => res.slotType !== 'action').map(res => res.title)
408
+ const filterVal = this.tableColumns.map(res => res.dataIndex)
409
+ let exportData
410
+ if (isSelected) {
411
+ exportData = this.$refs.xTable.selectedRows
412
+ } else {
413
+ exportData = this.$refs.xTable.dataSource
414
+ }
415
+ const data = this.formatJson(filterVal, exportData)
416
+ exportJson(tHeader, data, this.title + `数据_${new Date().toLocaleString()}`)
417
+ },
418
+ formatJson (filterVal, jsonData) {
419
+ return jsonData.map(v => filterVal.map(j => v[j]))
420
+ },
421
+ // 导出符合条件的数据
422
+ handleExportByQuery () {
423
+ const that = this
424
+ this.$confirm({
425
+ title: '是否确认导出?',
426
+ content: '此操作将导出当前条件下所有数据而非选中数据',
427
+ onOk () {
428
+ download({
429
+ queryParamsName: that.queryParamsName,
430
+ form: that.form,
431
+ type: 'exportData'
432
+ }, that.title + `数据_${new Date().toLocaleString()}.xlsx`, that.serviceName)
433
+ },
434
+ onCancel () {}
435
+ })
436
+ },
400
437
  // 查询表单部分显示/隐藏切换
401
438
  toggleIsFormShow () {
402
439
  this.isFormShow = !this.isFormShow