three-trees-ui 1.0.73 → 1.0.74

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": "three-trees-ui",
3
- "version": "1.0.73",
3
+ "version": "1.0.74",
4
4
  "publicPath": "/ui",
5
5
  "author": "hotent",
6
6
  "private": false,
@@ -5,7 +5,6 @@
5
5
  <script>
6
6
  import utils from '@/utils.js'
7
7
  import CustomQuery from '@/services/CustomQuery.js'
8
- import _ from 'lodash'
9
8
 
10
9
  export default {
11
10
  name: 'HtGlobalQuery',
@@ -48,7 +47,7 @@
48
47
  //主表
49
48
  _this.formInst.$watch(
50
49
  item.triggerField,
51
- _.debounce(function (newVal, oldVal) {
50
+ function(newVal, oldVal) {
52
51
  if (
53
52
  (newVal != '' || oldVal != undefined) &&
54
53
  newVal !== oldVal
@@ -60,7 +59,8 @@
60
59
  null
61
60
  )
62
61
  }
63
- }, 500)
62
+ }
63
+ // { immediate: true }
64
64
  )
65
65
  } else {
66
66
  //子表
@@ -83,7 +83,7 @@
83
83
 
84
84
  _this.formInst.$watch(
85
85
  'data.' + item.subPath,
86
- _.debounce(function (newVal) {
86
+ function(newVal) {
87
87
  let myOldVal = _this.subOldValueMap[item.subPath]
88
88
  _this.subQueryConfig
89
89
  .filter((i) => {
@@ -151,7 +151,7 @@
151
151
  )
152
152
  }
153
153
  })
154
- }, 500),
154
+ },
155
155
  { deep: true }
156
156
  )
157
157
  }
@@ -35,6 +35,16 @@
35
35
  type: String,
36
36
  default: '子表数据',
37
37
  },
38
+ exportMaxRow: {
39
+ type: [String, Number],
40
+ },
41
+ exportField: {
42
+ // 禁止导出的字段集合
43
+ type: String,
44
+ },
45
+ exportFieldTransformData: {
46
+ type: String,
47
+ },
38
48
  },
39
49
  computed: {
40
50
  columns: function() {
@@ -47,6 +57,46 @@
47
57
  }
48
58
  },
49
59
  methods: {
60
+ async sqlChange(config, value = '') {
61
+ return new Promise((resolve) => {
62
+ let sqlStr = config.relevancyValue
63
+ ? config.relevancyValue.replace(/{val}/g, value)
64
+ : ''
65
+ sqlStr = sqlStr ? sqlStr.replace(/\n/g, '') : ''
66
+ let params = {
67
+ dsName: config.dataSource,
68
+ sql: sqlStr,
69
+ }
70
+ this.$requestConfig.getValueBySql(params).then((res) => {
71
+ resolve(res)
72
+ })
73
+ })
74
+ },
75
+ transformFieldData(data) {
76
+ return new Promise(async (resolve) => {
77
+ let fieldTransformData = JSON.parse(
78
+ decode(this.exportFieldTransformData)
79
+ )
80
+ for (let i = 0; i < data.length; i++) {
81
+ for (let j = 0; j < fieldTransformData.length; j++) {
82
+ if (fieldTransformData[j].relevancyType == 'value') {
83
+ data[i][fieldTransformData[j].field] =
84
+ fieldTransformData[j].relevancyValue
85
+ } else {
86
+ // 动态时 请求接口修改数据
87
+ let result = await this.sqlChange(
88
+ fieldTransformData[j],
89
+ data[i][fieldTransformData[j].field]
90
+ )
91
+ if (result) {
92
+ data[i][fieldTransformData[j].field] = result
93
+ }
94
+ }
95
+ }
96
+ }
97
+ resolve(data)
98
+ })
99
+ },
50
100
  // 配置的数据字典 导出时翻译为汉字
51
101
  changeDictionary(data) {
52
102
  return new Promise(async (resolve, reject) => {
@@ -76,10 +126,18 @@
76
126
  },
77
127
  changeRowKey(rows) {
78
128
  var exportData = []
129
+ let exportFieldArr = null
130
+ if (this.exportField) {
131
+ exportFieldArr = this.exportField.split(',')
132
+ }
79
133
  rows.forEach((row) => {
80
134
  var exportRow = {}
81
135
  this.columns.forEach((col) => {
82
- if (col.ctrlType != 'suntable') {
136
+ if (
137
+ col.ctrlType != 'suntable' &&
138
+ (!exportFieldArr ||
139
+ (exportFieldArr && !exportFieldArr.includes(col.name)))
140
+ ) {
83
141
  exportRow[col.desc] = row[col.name]
84
142
  }
85
143
  })
@@ -87,6 +145,25 @@
87
145
  })
88
146
  return exportData
89
147
  },
148
+ getConfirmValue(rows, count) {
149
+ return new Promise((resolve) => {
150
+ this.$confirm(
151
+ `导出数据量超出导出限制【${count}】,将导出${count}条,是否继续?`,
152
+ '提示',
153
+ {
154
+ confirmButtonText: '确定',
155
+ cancelButtonText: '取消',
156
+ type: 'warning',
157
+ }
158
+ )
159
+ .then(() => {
160
+ resolve(rows.slice(0, count))
161
+ })
162
+ .catch(() => {
163
+ resolve(false)
164
+ })
165
+ })
166
+ },
90
167
  handleCommand(type) {
91
168
  const pInst = utils.getOnlineFormInstance(this)
92
169
  SubPagination.exportData(
@@ -97,6 +174,20 @@
97
174
  )
98
175
  .then(async (data) => {
99
176
  data = JSON.parse(JSON.stringify(data))
177
+ if (this.exportMaxRow && Number(this.exportMaxRow) < data.length) {
178
+ let result = await this.getConfirmValue(
179
+ data,
180
+ Number(this.exportMaxRow)
181
+ )
182
+ if (result === false) {
183
+ return
184
+ }
185
+ data = result
186
+ }
187
+
188
+ if (this.exportFieldTransformData) {
189
+ data = await this.transformFieldData(data)
190
+ }
100
191
  // 导出时 字典转换
101
192
  await this.changeDictionary(data)
102
193
  let exportData = this.changeRowKey(data)
@@ -102,6 +102,45 @@
102
102
  type: String,
103
103
  required: true,
104
104
  },
105
+ importMaxRow: {
106
+ type: [String, Number],
107
+ default: null,
108
+ },
109
+ templateType: {
110
+ // 导入模板类型 default 系统默认 custom 自定义
111
+ type: String,
112
+ default: 'default',
113
+ },
114
+ customTemplate: {
115
+ // 自定义的导入模板文件
116
+ type: String,
117
+ default: '',
118
+ },
119
+ importTransform: {
120
+ // 是否有转换字段
121
+ type: String,
122
+ default: '0',
123
+ },
124
+ importModes: {
125
+ // 导入模式选项显示
126
+ type: String,
127
+ default: 'append,override,merge',
128
+ },
129
+ fieldTransformData: {
130
+ // 转换字段配置
131
+ type: String,
132
+ default: '',
133
+ },
134
+ conditionRule: {
135
+ // 条件模式配置
136
+ type: String,
137
+ default: '',
138
+ },
139
+ conditionType: {
140
+ // 条件模式配置
141
+ type: String,
142
+ default: 'cover',
143
+ },
105
144
  },
106
145
  data() {
107
146
  return {
@@ -110,11 +149,6 @@
110
149
  showRowData: false,
111
150
  mergeFunc: null,
112
151
  mode: 'append',
113
- modeOptions: [
114
- { mode: 'append', desc: '追加导入' },
115
- { mode: 'override', desc: '覆盖导入' },
116
- { mode: 'merge', desc: '合并导入', disabled: true },
117
- ],
118
152
  cacheDicData: {}, // 缓存字典数据
119
153
  }
120
154
  },
@@ -122,6 +156,30 @@
122
156
  columns: function() {
123
157
  return eval(decode(this.dataColumns))
124
158
  },
159
+ modeOptions() {
160
+ let options = [
161
+ { mode: 'append', desc: '追加导入' },
162
+ { mode: 'override', desc: '覆盖导入' },
163
+ { mode: 'merge', desc: '合并导入' },
164
+ { mode: 'condition', desc: '条件导入' },
165
+ ]
166
+ return options.filter((k) => {
167
+ return this.importModes.includes(k.mode)
168
+ })
169
+ },
170
+ conditionConfig() {
171
+ let config = {}
172
+ if (this.conditionRule) {
173
+ config = JSON.parse(decode(this.conditionRule))
174
+ config.conditionArr.forEach((k) => {
175
+ k.exportField = this.getNameByDesc(k.exportField)
176
+ })
177
+ }
178
+ return {
179
+ conditionType: this.conditionType,
180
+ ...config,
181
+ }
182
+ },
125
183
  },
126
184
  watch: {
127
185
  dialogVisible: {
@@ -139,7 +197,7 @@
139
197
  handler: function(newVal) {
140
198
  if (newVal) {
141
199
  // 如果有导入合并的代码,则允许选择合并导入模式
142
- this.$set(this.modeOptions[2], 'disabled', false)
200
+ // this.$set(this.modeOptions[2], 'disabled', false)
143
201
  // 并设置默认为 合并导入
144
202
  this.mode = 'merge'
145
203
  // 解码合并的代码
@@ -156,6 +214,9 @@
156
214
  }
157
215
  },
158
216
  mounted() {
217
+ if (this.importModes) {
218
+ this.mode = this.importModes.split(',')[0]
219
+ }
159
220
  // 初始化导入时需要的参数
160
221
  const pInst = utils.getOnlineFormInstance(this)
161
222
  let formUid = pInst && pInst._uid ? pInst._uid : ''
@@ -170,10 +231,52 @@
170
231
  SubPagination._map.set(instKey, pInst)
171
232
  }
172
233
  },
173
- // destroyed() {
174
- // SubPagination.clear(this.dataSubname, this)
175
- // },
234
+ destroyed() {
235
+ SubPagination.clear(this.dataSubname, this)
236
+ },
176
237
  methods: {
238
+ transformFieldData(data) {
239
+ return new Promise(async (resolve) => {
240
+ if (this.importTransform === '0') {
241
+ resolve(data)
242
+ return
243
+ }
244
+ let fieldTransformData = JSON.parse(decode(this.fieldTransformData))
245
+ for (let i = 0; i < data.length; i++) {
246
+ for (let j = 0; j < fieldTransformData.length; j++) {
247
+ if (fieldTransformData[j].relevancyType == 'value') {
248
+ data[i][fieldTransformData[j].field] =
249
+ fieldTransformData[j].relevancyValue
250
+ } else {
251
+ // 动态时 请求接口修改数据
252
+ let result = await this.sqlChange(
253
+ fieldTransformData[j],
254
+ data[i][fieldTransformData[j].field]
255
+ )
256
+ if (result) {
257
+ data[i][fieldTransformData[j].field] = result
258
+ }
259
+ }
260
+ }
261
+ }
262
+ resolve(data)
263
+ })
264
+ },
265
+ async sqlChange(config, value = '') {
266
+ return new Promise((resolve) => {
267
+ let sqlStr = config.relevancyValue
268
+ ? config.relevancyValue.replace(/{val}/g, value)
269
+ : ''
270
+ sqlStr = sqlStr ? sqlStr.replace(/\n/g, '') : ''
271
+ let params = {
272
+ dsName: config.dataSource,
273
+ sql: sqlStr,
274
+ }
275
+ this.$requestConfig.getValueBySql(params).then((res) => {
276
+ resolve(res)
277
+ })
278
+ })
279
+ },
177
280
  changeDictionary(data) {
178
281
  return new Promise(async (resolve) => {
179
282
  for (let i = 0; i < data.length; i++) {
@@ -214,6 +317,28 @@
214
317
  },
215
318
  //子表模板导出
216
319
  exportFormSub() {
320
+ // 如果是自定义模板
321
+ if (this.templateType == 'custom' && this.customTemplate) {
322
+ let file = JSON.parse(decode(this.customTemplate))[0]
323
+ this.$requestConfig
324
+ .download(file.response.fileId)
325
+ .then(({ data, headers }) => {
326
+ if (data && headers) {
327
+ // 附件下载
328
+ const fileName = decodeURIComponent(
329
+ headers['content-disposition']
330
+ .split(';')[1]
331
+ .split('filename=')[1]
332
+ )
333
+ const blob = new Blob([data])
334
+ saveAs(blob, fileName)
335
+ }
336
+ })
337
+ .catch((err) => {
338
+ this.$message.error(`附件下载失败:${err}`)
339
+ })
340
+ return
341
+ }
217
342
  let columns = this.columns.filter((item) => {
218
343
  return !(
219
344
  item.ctrlType &&
@@ -263,6 +388,7 @@
263
388
  let count = this.importRows.length
264
389
  if (count > maxRowInt && maxRowInt != 0) {
265
390
  this.$message.error('子表数据已超过最大行数【' + maxRowInt + '】')
391
+ this.$refs.selectFile.value = ''
266
392
  return
267
393
  }
268
394
  } else if (this.mode == 'append') {
@@ -290,13 +416,16 @@
290
416
  }
291
417
  }
292
418
  }
293
- let importRows = await this.changeDictionary(this.importRows)
294
419
  const pInst = utils.getOnlineFormInstance(this.$parent.$parent)
420
+ let importRows = await this.changeDictionary(this.importRows)
421
+ // 导入如果有数据转换的此处做转换
422
+ importRows = await this.transformFieldData(importRows)
295
423
  SubPagination.importData(
296
424
  this.dataSubname,
297
425
  importRows,
298
426
  this.mode,
299
427
  this.mergeFunc,
428
+ this.conditionConfig,
300
429
  pInst
301
430
  )
302
431
  .then(() => {
@@ -304,6 +433,7 @@
304
433
  this.dialogVisible = false
305
434
  })
306
435
  .catch((err) => {
436
+ this.$refs.selectFile.value = ''
307
437
  this.$message.error(`数据导入失败:${err}`)
308
438
  })
309
439
  },
@@ -312,10 +442,43 @@
312
442
  return
313
443
  }
314
444
  this.importRows = []
315
- this.readWorkbookFromLocalFile(m.target.files[0], (rows) => {
445
+ this.readWorkbookFromLocalFile(m.target.files[0], async (rows) => {
446
+ if (this.importMaxRow) {
447
+ let count = rows.length
448
+ if (count > parseInt(this.importMaxRow)) {
449
+ let result = await this.getConfirmValue(
450
+ rows,
451
+ parseInt(this.importMaxRow)
452
+ )
453
+ if (result === false) {
454
+ this.$refs.selectFile.value = ''
455
+ return
456
+ }
457
+ rows = result
458
+ }
459
+ }
316
460
  this.importRows = this.changeRowKey(rows)
317
461
  })
318
462
  },
463
+ getConfirmValue(rows, count) {
464
+ return new Promise((resolve) => {
465
+ this.$confirm(
466
+ `导入数据量已超过最大限制,将默认导入前【${count}】条,是否继续?`,
467
+ '提示',
468
+ {
469
+ confirmButtonText: '确定',
470
+ cancelButtonText: '取消',
471
+ type: 'warning',
472
+ }
473
+ )
474
+ .then(() => {
475
+ resolve(rows.slice(0, count))
476
+ })
477
+ .catch(() => {
478
+ resolve(false)
479
+ })
480
+ })
481
+ },
319
482
  // 读取本地excel文件
320
483
  readWorkbookFromLocalFile(file, callback) {
321
484
  const reader = new FileReader()
@@ -106,9 +106,9 @@
106
106
  mounted() {
107
107
  this.paginationChange()
108
108
  },
109
- // destroyed() {
110
- // SubPagination.clear(this.dataSubname, this)
111
- // },
109
+ destroyed() {
110
+ SubPagination.clear(this.dataSubname, this)
111
+ },
112
112
  methods: {
113
113
  paginationChange() {
114
114
  // 分页变化时,以dataPath为key设置到公共的js对象中
@@ -845,5 +845,5 @@ const Formulas = {
845
845
  Formulas.install = (Vue) => {
846
846
  Vue.prototype.$Formulas = Formulas
847
847
  }
848
-
848
+ window.FormMath = Formulas
849
849
  export { formula, Formulas }