t20-common-lib 0.15.9 → 0.15.11

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": "t20-common-lib",
3
- "version": "0.15.9",
3
+ "version": "0.15.11",
4
4
  "description": "T20",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 电子档案 / 附件相关接口(与 Demo DynamicForm 一致)
3
+ */
4
+ import service from '../../../src/utils/request'
5
+
6
+ export function getByBussValue(data = {}) {
7
+ return service.post(`/api/neams/eamsattachfile/getByBussValue`, data)
8
+ }
9
+
10
+ export function getUploadedFile(data = {}) {
11
+ return service.post(`/api/neams/eamsbaserecord/queryList`, data)
12
+ }
@@ -0,0 +1,241 @@
1
+ import axios from 'axios'
2
+ import { getByBussValue, getUploadedFile } from '../api/fileApi'
3
+
4
+ function randomString(num) {
5
+ num = num || 32
6
+ const t = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
7
+ const a = t.length
8
+ let n = ''
9
+ for (let i = 0; i < num; i++) n += t.charAt(Math.floor(Math.random() * a))
10
+ return n
11
+ }
12
+
13
+ function getBearerToken() {
14
+ return sessionStorage.getItem('token') || ''
15
+ }
16
+
17
+ export const fileUploadTableMixin = {
18
+ data() {
19
+ return {
20
+ fileUploadTableData: [],
21
+ fileAction: () => {},
22
+ seeTypes: /\.(jpg|png|gif|svg|pdf|swf|xlsx|xls|docx|doc)$/i,
23
+ dataPorp: {
24
+ fileAccept: '.rar,.zip,.doc,.docx,.pdf,image/*,.xls,.xlsx',
25
+ typeOptions: [],
26
+ multiple: false
27
+ },
28
+ mapdata: {}
29
+ }
30
+ },
31
+ methods: {
32
+ addRow() {
33
+ this.fileUploadTableData.splice(0, 0, {
34
+ id: 'n' + Math.random(),
35
+ type: '',
36
+ name: '',
37
+ time: '',
38
+ user: '',
39
+ _fileData: {}
40
+ })
41
+ },
42
+ downRows(rows) {
43
+ if (!rows || rows.length === 0) return this.$message.error('请选择数据')
44
+ const token = getBearerToken()
45
+ rows.map(item => {
46
+ axios({
47
+ method: 'POST',
48
+ url: '/api/neams/eamsbaserecord/downloadFile',
49
+ responseType: 'blob',
50
+ headers: {
51
+ charset: 'utf-8',
52
+ Authorization: `Bearer ${token}`,
53
+ 'Content-Type': 'application/json',
54
+ timestamp: Date.now(),
55
+ OperationDesc: 'yYarJp',
56
+ requestKey: randomString(16)
57
+ },
58
+ data: { beid: item.beid }
59
+ })
60
+ .then(response => {
61
+ const resp = response.data
62
+ if (resp.type === 'application/octet-stream') {
63
+ if (window.navigator && window.navigator.msSaveOrOpenBlob) {
64
+ const blob = new Blob([resp], { type: 'application/zip' })
65
+ window.navigator.msSaveOrOpenBlob(blob, item.name)
66
+ } else {
67
+ const blob = new Blob([resp], { type: 'application/zip' })
68
+ const url = window.URL.createObjectURL(blob)
69
+ const link = document.createElement('a')
70
+ link.href = url
71
+ link.download = item.name
72
+ link.click()
73
+ URL.revokeObjectURL(url)
74
+ }
75
+ } else {
76
+ this.$message.error((this.$t && this.$t('common_w_0094')) || '下载失败' + '!')
77
+ }
78
+ })
79
+ .catch(error => this.$message.error(error))
80
+ })
81
+ },
82
+ deleteRows(rows) {
83
+ rows.forEach(row => {
84
+ const index = this.fileUploadTableData.findIndex(r => r.id === row.id)
85
+ if (index > -1 && !row.notBeDelete) {
86
+ this.fileUploadTableData.splice(index, 1)
87
+ this.$message.success('删除成功')
88
+ }
89
+ })
90
+ },
91
+ uploadRequest(options, row) {
92
+ const token = getBearerToken()
93
+ const { file } = options
94
+ const data = new FormData()
95
+ data.append('file', file)
96
+ data.append(
97
+ 'data',
98
+ JSON.stringify({
99
+ syscode: this.uploadParam.syscode,
100
+ appno: this.uploadParam.appno,
101
+ bussValue: this.mapdata[row.type],
102
+ attno: row.type,
103
+ bussId: this.uploadParam?.paymentTemplate === 'REQUEST_PAYOUT' ? '' : this.uploadParam.bussId,
104
+ cltno: JSON.parse(sessionStorage.getItem('userInfo') || '{}').cltNo,
105
+ memo: file.name,
106
+ recordname: file.name,
107
+ fileSize: file.size
108
+ })
109
+ )
110
+ data.append('date', '2022-01-01 00:00:00' + ',2099-12-31 23:59:59')
111
+ return new Promise((resolve, reject) => {
112
+ axios
113
+ .post(`/api/neams/eamsbaserecord/batchSavejson`, data, {
114
+ headers: {
115
+ 'Content-Type': 'multipart/form-data',
116
+ charset: 'utf-8',
117
+ timestamp: Date.now(),
118
+ Authorization: `Bearer ${token}`,
119
+ requestKey: randomString(16),
120
+ OperationDesc: 'yYarJp'
121
+ },
122
+ loading: false,
123
+ noMsg: true
124
+ })
125
+ .then(({ data: res }) => resolve(res))
126
+ .catch(err => reject(err))
127
+ })
128
+ },
129
+ getByBussValueFn() {
130
+ this.mapdata = {}
131
+ if (!this.uploadParam || !this.uploadParam.bussValue) return
132
+ if (this.uploadParam.bussValue.split(',').length > 1) {
133
+ this.dataPorp.typeOptions = []
134
+ this.uploadParam.bussValue.split(',').map(item => {
135
+ getByBussValue({
136
+ bussValue: item
137
+ }).then(res => {
138
+ res &&
139
+ res.map(t => {
140
+ this.dataPorp.typeOptions.push({
141
+ ...t,
142
+ type: t.attno,
143
+ label: t.attname
144
+ })
145
+ this.mapdata[t.attno] = item
146
+ })
147
+ })
148
+ })
149
+ return
150
+ }
151
+ getByBussValue({
152
+ bussValue: this.uploadParam.bussValue
153
+ }).then(res => {
154
+ this.dataPorp.typeOptions = (res.data || []).map(item => {
155
+ item.type = item.attno
156
+ item.label = item.attname
157
+ this.mapdata[item.attno] = this.uploadParam.bussValue
158
+ return item
159
+ })
160
+ })
161
+ },
162
+ getUploadedFiles() {
163
+ if (!this.uploadParam) return
164
+ if (this.uploadParam.bussValue && this.uploadParam.bussValue.includes(',')) {
165
+ this.uploadParam.bussValue.split(',').map(async t => {
166
+ const rr = await getUploadedFile({
167
+ bussId: this.uploadParam?.bussId,
168
+ bussValue: t
169
+ })
170
+ const data = rr && rr.data != null ? rr.data : rr
171
+ this.fileUploadTableData = this.fileUploadTableData.concat(
172
+ (data || []).map(item => ({
173
+ id: item.beid,
174
+ beid: item.beid,
175
+ type: item.attno,
176
+ name: item.recordname,
177
+ time: item.updatetime,
178
+ user: item.creator,
179
+ url: item.filepath
180
+ }))
181
+ )
182
+ })
183
+ return
184
+ }
185
+ getUploadedFile({
186
+ bussValue: this.uploadParam.bussValue,
187
+ bussId: this.uploadParam.bussId
188
+ }).then(res => {
189
+ const list = res && res.data != null ? res.data : res
190
+ this.fileUploadTableData =
191
+ (list || []).map(item => {
192
+ item.type = item.attno
193
+ item.name = item.memo || item.recordname
194
+ item.time = item.uploadtime
195
+ item.user = item.creator
196
+ item.url = `/api/neams/eamsbaserecord/download/${item.beid}`
197
+ item._name = item.memo
198
+ return item
199
+ }) || []
200
+ })
201
+ },
202
+ onSuccess(file, row) {
203
+ const _fileData = file.response
204
+ this.$set(row, 'id', _fileData.data)
205
+ this.$set(row, 'bussValue', this.mapdata[row.type])
206
+ let userName = ''
207
+ try {
208
+ const raw = sessionStorage.getItem('User_Info') || sessionStorage.getItem('userInfo')
209
+ if (raw) userName = JSON.parse(raw).userName || ''
210
+ } catch (e) {
211
+ userName = ''
212
+ }
213
+ this.$set(row, 'user', userName)
214
+ this.$set(row, 'archiveId', _fileData.data)
215
+ this.$set(row, 'beid', _fileData.data)
216
+ },
217
+ onRemove(file) {
218
+ if (file.status === 'success') {
219
+ const { beid } = file.response
220
+ const i = this.fileUploadTableData.findIndex(d => d.id === beid)
221
+ if (i !== -1) this.fileUploadTableData.splice(i, 1)
222
+ }
223
+ }
224
+ },
225
+ watch: {
226
+ uploadParam: {
227
+ immediate: true,
228
+ deep: true,
229
+ handler() {
230
+ if (!this.needFile) return
231
+ if (!this.uploadParam) return
232
+ if (this.uploadParam.bussValue) {
233
+ this.getByBussValueFn()
234
+ }
235
+ if (this.uploadParam.bussId) {
236
+ this.getUploadedFiles()
237
+ }
238
+ }
239
+ }
240
+ }
241
+ }
@@ -52,6 +52,29 @@
52
52
  </template>
53
53
  </N20-anchor-item>
54
54
  </el-form>
55
+ <N20-anchor-item
56
+ v-if="needFile"
57
+ key="fileuploadtable"
58
+ id="fileuploadtable"
59
+ :title="$lc('附件信息')"
60
+ >
61
+ <N20-file-upload-table
62
+ v-if="!needFileDIY"
63
+ :action="fileAction"
64
+ :table-data="fileUploadTableData"
65
+ :see-types="seeTypes"
66
+ :show-batch-upload="false"
67
+ :data-porp="dataPorp"
68
+ :upload-http-request="uploadRequest"
69
+ :readonly="uploadReadOnly"
70
+ @on-success="onSuccess"
71
+ @on-remove="onRemove"
72
+ @add-row="addRow"
73
+ @down-rows="downRows"
74
+ @delete-rows="deleteRows"
75
+ />
76
+ <slot v-else name="fileUploadTable"></slot>
77
+ </N20-anchor-item>
55
78
  </N20-anchor>
56
79
  <div slot="footer">
57
80
  <el-button type="primary" @click="submit('submit')">{{ $lc('提交') }}</el-button>
@@ -68,7 +91,10 @@
68
91
  * 3. A 控制 B 可编辑 — setFieldEditable
69
92
  * 4. A 控制 B 值/名称回显或下拉项 — setFieldValue、setFieldLabelValue、setFieldOptions
70
93
  * 5. A 控制 B 渲染哪种组件 — setFieldElementType(须为 elementTypeChange 中已配置的枚举)
94
+ *
95
+ * fieldControlList:与 dynamicData 同时传入,仅在收到模版时按 fieldNo 与 elements[].prop 合并一次 isShow、showName→label、isRequired;之后渲染均以合并后的 mergedTemplateBase 为唯一数据源。
71
96
  */
97
+ import { fileUploadTableMixin } from '../mixins/fileUpload'
72
98
  // 复用 Demo 中的字段组件,按模板的 elementType 动态渲染
73
99
  const context = require.context('./components/', true, /\.vue$/)
74
100
  const demoComponents = {}
@@ -82,6 +108,7 @@ export default {
82
108
  components: {
83
109
  ...demoComponents
84
110
  },
111
+ mixins: [fileUploadTableMixin],
85
112
  props: {
86
113
  title: {
87
114
  type: String,
@@ -100,6 +127,36 @@ export default {
100
127
  linkageMethod: {
101
128
  type: Function,
102
129
  default: null
130
+ },
131
+ /** 字段控制配置,与 dynamicData 一并传入;仅整合一次 */
132
+ fieldControlList: {
133
+ type: Array,
134
+ default: () => []
135
+ },
136
+ /** 是否展示附件锚点(默认关闭,不影响现有用法) */
137
+ needFile: {
138
+ type: Boolean,
139
+ default: false
140
+ },
141
+ /** true 时使用 fileUploadTable 插槽自定义附件区 */
142
+ needFileDIY: {
143
+ type: Boolean,
144
+ default: true
145
+ },
146
+ /** 电子档案 / 上传参数,与 Demo DynamicForm uploadParam 一致 */
147
+ uploadParam: {
148
+ type: Object,
149
+ default: () => ({
150
+ syscode: '060000000',
151
+ appno: '060500000',
152
+ bussValue: 'invest_041001001',
153
+ attno: 'invest_002',
154
+ bussId: null
155
+ })
156
+ },
157
+ uploadReadOnly: {
158
+ type: Boolean,
159
+ default: false
103
160
  }
104
161
  },
105
162
  data() {
@@ -109,9 +166,11 @@ export default {
109
166
  // 右侧锚点当前定位项
110
167
  action: '',
111
168
  formAttrs: {},
169
+ // dynamicData + fieldControlList 合并后的模版快照;applyFieldStates 均从此克隆,不再直接用原始 dynamicData
170
+ mergedTemplateBase: null,
112
171
  // 运行时模板(动态表单渲染与联动状态都基于它)
113
172
  runtimeTemplate: { units: [] },
114
- // 联动写入的 options / elementType:每次从 dynamicData 克隆模板后会合并回来,避免被重置清空
173
+ // 联动写入的 options / elementType:每次从 mergedTemplateBase 克隆后会合并回来,避免被重置清空
115
174
  linkageFieldOverrides: {},
116
175
  // 避免联动写值导致 watch 循环触发
117
176
  isApplyingLinkage: false,
@@ -205,10 +264,40 @@ export default {
205
264
  this.$emit('input', { ...this.formData })
206
265
  }
207
266
  },
267
+ /**
268
+ * 将 fieldControlList 合并进模版克隆(fieldNo 对应 elements[].prop)
269
+ */
270
+ mergeFieldControlIntoTemplate(templateClone) {
271
+ const list = this.fieldControlList
272
+ if (!templateClone?.units || !Array.isArray(list) || list.length === 0) return templateClone
273
+ const byFieldNo = Object.create(null)
274
+ list.forEach(row => {
275
+ if (row && row.fieldNo != null && row.fieldNo !== '') byFieldNo[row.fieldNo] = row
276
+ })
277
+ ;(templateClone.units || []).forEach(group => {
278
+ ;(group.elements || []).forEach(item => {
279
+ if (!item.prop) return
280
+ const cfg = byFieldNo[item.prop]
281
+ if (!cfg) return
282
+ if (cfg.isShow !== undefined && cfg.isShow !== null) {
283
+ item.isShow = this.templateShowOrEditable(cfg.isShow)
284
+ }
285
+ if (cfg.showName != null && String(cfg.showName).trim() !== '') {
286
+ item.label = cfg.showName
287
+ }
288
+ if (cfg.isRequired !== undefined && cfg.isRequired !== null) {
289
+ item.isRequired = this.templateRequired(cfg.isRequired)
290
+ }
291
+ })
292
+ })
293
+ return templateClone
294
+ },
208
295
  // 基于模板初始化:分组锚点、默认值、必填规则
209
296
  initializeFromTemplate() {
210
297
  this.linkageFieldOverrides = {}
211
- this.runtimeTemplate = JSON.parse(JSON.stringify(this.dynamicData || { units: [] }))
298
+ const raw = JSON.parse(JSON.stringify(this.dynamicData || { units: [] }))
299
+ this.mergedTemplateBase = this.mergeFieldControlIntoTemplate(raw)
300
+ this.runtimeTemplate = JSON.parse(JSON.stringify(this.mergedTemplateBase))
212
301
  this.action = this.formGroups.length > 0 ? this.formGroups[0].prop : ''
213
302
  this.ensureFormDataShape()
214
303
  this.formGroups.forEach(group => {
@@ -328,7 +417,7 @@ export default {
328
417
  const prev = this.linkageFieldOverrides[groupProp][fieldProp] || {}
329
418
  this.$set(this.linkageFieldOverrides[groupProp], fieldProp, { ...prev, ...patch })
330
419
  },
331
- /** 模板每次从 dynamicData 克隆后,把联动里改过的 options / elementType 写回对应字段 */
420
+ /** 模板每次从 mergedTemplateBase 克隆后,把联动里改过的 options / elementType 写回对应字段 */
332
421
  applyLinkageOverrides() {
333
422
  Object.keys(this.linkageFieldOverrides || {}).forEach(groupProp => {
334
423
  const fields = this.linkageFieldOverrides[groupProp]
@@ -369,9 +458,9 @@ export default {
369
458
  this.$emit('linkage', linkageApi)
370
459
  },
371
460
  applyFieldStates() {
372
- if (!this.dynamicData?.units) return
461
+ if (!this.mergedTemplateBase?.units) return
373
462
  this.isApplyingLinkage = true
374
- const nextTemplate = JSON.parse(JSON.stringify(this.dynamicData))
463
+ const nextTemplate = JSON.parse(JSON.stringify(this.mergedTemplateBase))
375
464
  this.rules = {}
376
465
  ;(nextTemplate.units || []).forEach(group => {
377
466
  group.isShow = this.templateShowOrEditable(group.isShow)
@@ -401,9 +490,11 @@ export default {
401
490
  async submit() {
402
491
  const valid = await this.$refs.dynamicForms.validate()
403
492
  if (!valid) return
404
- this.$emit('submit', {
405
- formData: this.formData
406
- })
493
+ const payload = { formData: this.formData }
494
+ if (this.needFile) {
495
+ payload.fileUploadTableData = (this.fileUploadTableData || []).filter(t => t.beid)
496
+ }
497
+ this.$emit('submit', payload)
407
498
  }
408
499
  }
409
500
  }