t20-common-lib 0.15.10 → 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.10",
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>
@@ -71,6 +94,7 @@
71
94
  *
72
95
  * fieldControlList:与 dynamicData 同时传入,仅在收到模版时按 fieldNo 与 elements[].prop 合并一次 isShow、showName→label、isRequired;之后渲染均以合并后的 mergedTemplateBase 为唯一数据源。
73
96
  */
97
+ import { fileUploadTableMixin } from '../mixins/fileUpload'
74
98
  // 复用 Demo 中的字段组件,按模板的 elementType 动态渲染
75
99
  const context = require.context('./components/', true, /\.vue$/)
76
100
  const demoComponents = {}
@@ -84,6 +108,7 @@ export default {
84
108
  components: {
85
109
  ...demoComponents
86
110
  },
111
+ mixins: [fileUploadTableMixin],
87
112
  props: {
88
113
  title: {
89
114
  type: String,
@@ -107,6 +132,31 @@ export default {
107
132
  fieldControlList: {
108
133
  type: Array,
109
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
110
160
  }
111
161
  },
112
162
  data() {
@@ -440,9 +490,11 @@ export default {
440
490
  async submit() {
441
491
  const valid = await this.$refs.dynamicForms.validate()
442
492
  if (!valid) return
443
- this.$emit('submit', {
444
- formData: this.formData
445
- })
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)
446
498
  }
447
499
  }
448
500
  }