centaline-data-driven-v3 0.0.91 → 0.0.92

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,158 +1,214 @@
1
1
  import common from './common';
2
2
  import Enum from './Enum';
3
3
  import request from './request';
4
- import Form from '../loader/src/Form';
5
4
  const formData = {
6
- install(app) {
7
- app.config.globalProperties.$formData = formData;
8
- },
9
5
  form: null,
10
- formTable: null,
11
- excuteData: null,//fields
12
- fieldsDic: null,//fieldsDic
13
- _excuteListData: undefined,
14
-
15
- enableRelationFields(FlagRelation) {
6
+ formTable: null,
7
+ excuteData: null,//fields
8
+ fieldsDic: null,//fieldsDic
9
+ source:null,
10
+ _excuteListData: undefined,
11
+ enableRelationFields(FlagRelation) {
16
12
  this.form.enableRelationFields = FlagRelation
17
- },
18
- //获取code1
19
- getCode1ByField1(id) {
13
+ },
14
+ //获取code1
15
+ getCode1ByField1(id) {
20
16
  var rtn1 = this.fieldsDic[id];
21
17
  if (rtn1) {
22
- return rtn1.code1;
18
+ return rtn1.code1;
23
19
  }
24
- },
25
- //获取code2
26
- getCode2ByField1(id) {
20
+ },
21
+
22
+ //获取code2
23
+ getCode2ByField1(id) {
27
24
  var rtn1 = this.fieldsDic[id];
28
25
  if (rtn1) {
29
- return rtn1.code2;
26
+ return rtn1.code2;
27
+ }
28
+ },
29
+ setActionRouter(id, attrKey, attrValue) {
30
+ var router = this.form.actionRouters.find((v1) => {
31
+ return v1.key === id;
32
+ });
33
+ if (router) {
34
+ router[attrKey] = attrValue;
30
35
  }
31
- },
32
- //获取Field的属性attrKey的值
33
- getValueByFieldName(id, attrKey) {
36
+ },
37
+ //获取Field的属性attrKey的值
38
+ getValueByFieldName(id, attrKey) {
34
39
  attrKey = common.initialsToLowerCase(attrKey);
35
40
  var rtn1 = this.fieldsDic[id];
36
41
  if (rtn1) {
37
- return rtn1[attrKey];
42
+ return rtn1[attrKey];
38
43
  }
39
- },
40
- //设置Field的属性attrKey的值
41
- setValueByFieldName(id, attrKey, attrValue) {
44
+ },
45
+ getValueByFieldNameFromParent(id, attrKey) {
46
+ if (this.form && this.form.parentModelForm) {
47
+ return this.form.parentModelForm.getValueByFieldName(id, attrKey);
48
+ }
49
+ return null;
50
+ },
51
+ //设置Field的属性attrKey的值
52
+ setValueByFieldName(id, attrKey, attrValue) {
42
53
  attrKey = common.initialsToLowerCase(attrKey);
43
54
  var rtn1 = this.fieldsDic[id];
44
55
  if (rtn1) {
45
- if (attrKey == 'code1' && rtn1.controlType === Enum.ControlType.NumericTextBox
46
- && attrValue != undefined && attrValue != null && attrValue != '') {
47
- if (rtn1.decimals1 != undefined && rtn1.decimals1 != null && rtn1.decimals1 > -1) {
48
- attrValue = Number(attrValue).toFixed(rtn1.decimals1)
49
- }
56
+ if (attrKey == 'code1' && rtn1.controlType === Enum.ControlType.NumericTextBox
57
+ && attrValue != undefined && attrValue != null && attrValue != '') {
58
+ if (rtn1.decimals1 != undefined && rtn1.decimals1 != null && rtn1.decimals1 > -1) {
59
+ attrValue = Number(attrValue).toFixed(rtn1.decimals1)
60
+ }
61
+ }
62
+ else if (attrKey == 'code1' && (rtn1.controlType === Enum.ControlType.File
63
+ || rtn1.controlType === Enum.ControlType.SliceUpload || rtn1.controlType === Enum.ControlType.PhotoSelect)
64
+ && attrValue != undefined && attrValue != null && attrValue != '') {
65
+ rtn1.jsSetFile(attrValue, rtn1);
66
+ }
67
+ rtn1[attrKey] = attrValue;
68
+ if (rtn1.controlType === Enum.ControlType.Tags) {
69
+ rtn1["value"] = JSON.parse(attrValue);
70
+ }
71
+ if (rtn1.controlType === Enum.ControlType.SearchListBox
72
+ || rtn1.controlType === Enum.ControlType.ComboBox
73
+ || rtn1.controlType === Enum.ControlType.MultiSelectWithSearch
74
+ || rtn1.controlType === Enum.ControlType.MultiSelectNoSearch
75
+ ) {
76
+ if (rtn1["options"].length == 0) {
77
+ rtn1["options"] = [{ value: '', label: '' }];
50
78
  }
51
- rtn1[attrKey] = attrValue;
52
- Form.hiddenHandle(rtn1, this.form);
53
- Form.requiredHandle(rtn1, this.form);
79
+ if (attrKey == 'code1') {
80
+ rtn1["value"] = attrValue;
81
+ rtn1["options"][0]["value"] = attrValue
82
+ }
83
+ if (attrKey == 'name1') {
84
+ rtn1["options"][0]["label"] = attrValue
85
+ }
86
+ if (rtn1.itemKey) rtn1.itemKey = Math.random()
87
+ }
88
+ if (rtn1.is == 'ct-button') {
89
+ if (common.flagApp() && this.form.$vue.loaded) {
90
+ this.form.$vue.loaded(this.form)
91
+ }
92
+ }
93
+ this.source.hiddenHandle(rtn1, this.form);
94
+ if(this.source.requiredHandle){
95
+ this.source.requiredHandle(rtn1, this.form);
96
+ }
54
97
  }
55
- },
56
- //设置Field的v1、v2的值
57
- setV1AndV2ByField1(id, code1, code2) {
98
+ },
99
+ setValueByFieldNameFromParent(id, attrKey, attrValue) {
100
+ if (this.form && this.form.parentModelForm) {
101
+ return this.form.parentModelForm.setValueByFieldName(id, attrKey, attrValue);
102
+ }
103
+ return null;
104
+ },
105
+ //设置Field的v1、v2的值
106
+ setV1AndV2ByField1(id, code1, code2) {
58
107
  var rtn1 = this.fieldsDic[id];
59
108
  if (rtn1) {
60
- if (typeof rtn1.code1 !== 'undefined') {
61
- rtn1.code1 = code1;
62
- Form.hiddenHandle(rtn1);//隐藏关联的
63
- }
64
- if (typeof rtn1.code2 !== 'undefined') {
65
- rtn1.code2 = code2;
66
- }
109
+ if (typeof rtn1.code1 !== 'undefined') {
110
+ rtn1.code1 = code1;
111
+ this.source.hiddenHandle(rtn1);//隐藏关联的
112
+ }
113
+ if (typeof rtn1.code2 !== 'undefined') {
114
+ rtn1.code2 = code2;
115
+ }
67
116
  }
68
- },
69
- setTabsSelect(id) {
117
+ },
118
+ clearMedia(id) {
119
+ var rtn1 = this.fieldsDic[id];
120
+ for (let i = 0; i < rtn1.fileSourceList.length; i++) {
121
+ rtn1.fileSourceList[i].flagDeleted = true;
122
+ }
123
+ rtn1.fileList = [];
124
+ },
125
+ setTabsSelect(id) {
70
126
  if (this.form && this.form.$vue) {
71
- var f = this.fieldsDic[id];
72
- if (this.form.isHorizontalLayout) {
73
- this.form.$vue.activeName = f.collapseName.toString() === '-1' ? this.form.$vue.activeName : f.collapseName.toString();
74
- }
127
+ var f = this.fieldsDic[id];
128
+ if (this.form.isHorizontalLayout) {
129
+ this.form.$vue.activeName = f.collapseName.toString() === '-1' ? this.form.$vue.activeName : f.collapseName.toString();
130
+ }
75
131
  }
76
- },
77
- //路由提交
78
- submit(id) {
132
+ },
133
+ //路由提交
134
+ submit(fieldName1) {
79
135
  if (this.form && this.form.$vue) {
80
- this.form.$vue.fieldClickHandler({ id: id });
136
+ this.form.$vue.fieldClickHandler({ fieldName1: fieldName1 });
81
137
  }
82
- },
138
+ },
83
139
 
84
- //获取列表数据
85
- get excuteListData() {
140
+ //获取列表数据
141
+ get excuteListData() {
86
142
  if (this._excuteListData) {
87
- return this._excuteListData;
143
+ return this._excuteListData;
88
144
  }
89
145
  else {
90
- if (this.excuteData !== null) {
91
- this._excuteListData = this.excuteData.filter((v) => {
92
- return typeof v.is !== undefined && (v.is === 'ct-formlist' || v.is === 'ct-repeat');
93
- });
94
- }
146
+ if (this.excuteData !== null) {
147
+ this._excuteListData = this.excuteData.filter((v) => {
148
+ return typeof v.is !== undefined && (v.is === 'ct-formlist' || v.is === 'ct-repeat');
149
+ });
150
+ }
95
151
  }
96
152
  return this._excuteListData;
97
- },
98
- setExcuteListData(fields) {
153
+ },
154
+ setExcuteListData(fields) {
99
155
  this._excuteListData = null;
100
156
  if (fields !== null) {
101
- this.excuteData = fields;
102
- this._excuteListData = fields.filter((v) => {
103
- return typeof v.is !== undefined && (v.is === 'ct-formlist' || v.is === 'ct-repeat');
104
- });
157
+ this.excuteData = fields;
158
+ this._excuteListData = fields.filter((v) => {
159
+ return typeof v.is !== undefined && (v.is === 'ct-formlist' || v.is === 'ct-repeat');
160
+ });
105
161
  }
106
- },
107
- //获取列表的Field
108
- getListField(tableName, rowNum, fiedlId) {
162
+ },
163
+ //获取列表的Field
164
+ getListField(tableName, rowNum, fiedlId) {
109
165
  let listData = this.excuteListData.find((v) => {
110
- return v.name === tableName;
166
+ return v.name === tableName;
111
167
  });
112
168
  if (listData) {
113
- let field = null;
114
- //正在编辑的Field
115
- if (rowNum === null && (fiedlId === null || listData.currentEventField.fieldName1 === fiedlId)) {
116
- field = listData.currentEventField;
169
+ let field = null;
170
+ //正在编辑的Field
171
+ if (rowNum === null && (fiedlId === null || listData.currentEventField.fieldName1 === fiedlId)) {
172
+ field = listData.currentEventField;
173
+ }
174
+ //正在编辑的行
175
+ else if (rowNum === null && listData.currentRowIndex === 0) {
176
+ let fields = listData.currentRow.data;
177
+ field = fields[fiedlId];
178
+ }
179
+ //源数据
180
+ else {
181
+ if (rowNum === null && listData.currentRowIndex) {
182
+ rowNum = listData.currentRowIndex;
117
183
  }
118
- //正在编辑的行
119
- else if (rowNum === null && listData.currentRowIndex === 0) {
120
- let fields = listData.currentRow.data;
121
- field = fields[fiedlId];
122
- }
123
- //源数据
124
- else {
125
- if (rowNum === null && listData.currentRowIndex) {
126
- rowNum = listData.currentRowIndex;
127
- }
128
184
 
129
- if (rowNum === 0 || (rowNum && fiedlId)) {
130
- try {
131
- let fields = listData.rows[rowNum].field;
132
- field = fields.find((v) => {
133
- return v.fieldName1 === fiedlId;
134
- });
135
- } catch (e) {
136
- if (listData.rows.length <= rowNum) {
137
- common.message('获取列表行索引超出界限', 'error')
138
- }
139
- }
185
+ if (rowNum === 0 || (rowNum && fiedlId)) {
186
+ try {
187
+ let fields = listData.rows[rowNum].field;
188
+ field = fields.find((v) => {
189
+ return v.fieldName1 === fiedlId;
190
+ });
191
+ } catch (e) {
192
+ if (listData.rows.length <= rowNum) {
193
+ common.message('获取列表行索引超出界限', 'error')
140
194
  }
195
+ }
141
196
  }
197
+ }
142
198
 
143
- return { listData: listData, field: field };
199
+ return { listData: listData, field: field };
144
200
  }
145
- },
146
- //获取列表的行数(注意 这里包括列头)
147
- getListCount(tableName) {
201
+ },
202
+ //获取列表的行数(注意 这里包括列头)
203
+ getListCount(tableName) {
148
204
  tableName = tableName ? tableName : this.form.scripts.$fd;
149
205
  let data = this.getListField(tableName, null, null);
150
206
  if (data) {
151
- return data.listData.rows.length;
207
+ return data.listData.rows.length;
152
208
  }
153
- },
154
- //获取表格某行某列的值
155
- getListFieldValue(tableName, rowNum, fiedlId, attrName, defaultValue) {
209
+ },
210
+ //获取表格某行某列的值
211
+ getListFieldValue(tableName, rowNum, fiedlId, attrName, defaultValue) {
156
212
  tableName = tableName ? tableName : this.form.scripts.$fd;
157
213
  let data = this.getListField(tableName, rowNum, fiedlId);
158
214
 
@@ -160,27 +216,27 @@ const formData = {
160
216
  attrName = attrName ? attrName : 'code1';
161
217
 
162
218
  if (!fiedlId) {
163
- fiedlId = data.listData.currentEventField.fieldName1;
219
+ fiedlId = data.listData.currentEventField.fieldName1;
164
220
  }
165
221
  if (fiedlId && rowNum === null && fiedlId === data.listData.currentEventField.fieldName1) {
166
- data.field = data.listData.currentEventField;
222
+ data.field = data.listData.currentEventField;
167
223
  }
168
224
  rowNum = rowNum !== null ? rowNum : data.listData.currentRowIndex;
169
225
 
170
226
  //若该行正在编辑,则取编辑状态的。
171
227
  if (data && data.listData && data.listData.currentRow.data && data.listData.currentRow.data[fiedlId]
172
- && data.listData.currentRow.data.$sourceIndex === rowNum && data.listData.currentRow.isSet) {
173
- return data.listData.currentRow.data[fiedlId][attrName];
228
+ && data.listData.currentRow.data.$sourceIndex === rowNum && data.listData.currentRow.isSet) {
229
+ return data.listData.currentRow.data[fiedlId][attrName];
174
230
  }
175
231
  else if (data && data.field) {
176
- if (typeof defaultValue !== 'undefined' && data.listData.rows[rowNum].deleted) {//若该行被删除时,则直接返回默认值
177
- return defaultValue;
178
- }
179
- return data.field[attrName];
232
+ if (typeof defaultValue !== 'undefined' && data.listData.rows[rowNum].deleted) {//若该行被删除时,则直接返回默认值
233
+ return defaultValue;
234
+ }
235
+ return data.field[attrName];
180
236
  }
181
- },
182
- //设置表格某行某列的值
183
- setListFieldValue(value, tableName, rowNum, fiedlId, attrName) {
237
+ },
238
+ //设置表格某行某列的值
239
+ setListFieldValue(value, tableName, rowNum, fiedlId, attrName, flagTemplate) {
184
240
  value = value == undefined ? "" : value.toString();
185
241
  tableName = tableName ? tableName : this.form.scripts.$fd;
186
242
  let data = this.getListField(tableName, rowNum, fiedlId);
@@ -189,70 +245,119 @@ const formData = {
189
245
  attrName = attrName ? attrName : 'code1';
190
246
 
191
247
  if (!fiedlId) {
192
- fiedlId = data.listData.currentEventField.id;
248
+ fiedlId = data.listData.currentEventField.id;
193
249
  }
194
250
 
195
251
  rowNum = rowNum ? rowNum : data.listData.currentRowIndex;
196
252
 
197
253
  if (data) {
198
- //正在编辑的行
199
- if (data.listData.currentRow.data && data.listData.currentRow.data[fiedlId] && rowNum > -1
200
- && data.listData.currentRow.data.$sourceIndex === data.listData.source.rows[rowNum].$sourceIndex) {
201
- let currentField = data.listData.currentRow.data[fiedlId];
202
- currentField[attrName] = value;
203
- //校验自己
204
- if (currentField.validExcute) {
205
- currentField.validExcute();
206
- }
207
- if (data.field) {
208
- data.field[attrName] = value;
209
- }
254
+ //正在编辑的行
255
+ if (data.listData.currentRow.data && data.listData.currentRow.data[fiedlId] && rowNum > -1
256
+ && data.listData.currentRow.data.$sourceIndex === data.listData.source.rows[rowNum].$sourceIndex) {
257
+ let currentField = data.listData.currentRow.data[fiedlId];
258
+ currentField[attrName] = value;
259
+ //校验自己
260
+ if (currentField.validExcute) {
261
+ currentField.validExcute();
210
262
  }
211
- else if (data.field) {
212
- data.field.source[attrName] = value;
263
+ if (data.field) {
264
+ data.field[attrName] = value;
213
265
  }
214
-
215
- //如果有汇总列,触发重新计算汇总
216
- if (data.listData.showSummary) {
217
- data.listData.tableData.push({});
218
- data.listData.tableData.pop();
266
+ }
267
+ else if (data.field) {
268
+ if (data.field) {
269
+ data.field[attrName] = value;
270
+ }
271
+ if (data.field.source) {
272
+ data.field.source[attrName] = value;
273
+ }
274
+ if (flagTemplate) {
275
+ data.field[attrName] = value;
276
+ }
277
+ if (data.listData.flagTemplate && data.listData.$vue) {
278
+ data.listData.$vue.itemKey = Math.random()
219
279
  }
280
+ }
220
281
 
221
- return true;
282
+ //如果有汇总列,触发重新计算汇总
283
+ if (data.listData.showSummary) {
284
+ data.listData.tableData.push({});
285
+ data.listData.tableData.pop();
286
+ }
287
+
288
+ return true;
222
289
  }
223
290
  return false;
224
- },
225
- //设置表格属性值
226
- setListAttr(tableId, attrName, attrValue) {
291
+ },
292
+ //设置表格选择路由
293
+ setListSelectRouter(tableId, attrKey, attrValue) {
227
294
  let listData = this.excuteListData.find((v) => {
228
- return v.name === tableId;
295
+ return v.fieldName1 === tableId;
229
296
  });
230
- listData[attrName] = attrValue
231
- },
232
- //新增表格数据
233
- insertRow(tableId, rows) {
297
+ if (listData) {
298
+ var router = listData.selectRouter;
299
+ if (router) {
300
+ router[attrKey] = attrValue;
301
+ }
302
+ }
303
+ },
304
+ //设置表格属性值
305
+ setListAttr(tableId, attrName, attrValue) {
234
306
  let listData = this.excuteListData.find((v) => {
235
- return v.name === tableId;
307
+ return v.fieldName1 === tableId;
236
308
  });
237
- listData.insertRow(rows);
238
- },
239
- //新增或替换表格数据
240
- insertOrUpdateRow(tableId, row) {
309
+ if (listData) {
310
+ listData[attrName] = attrValue
311
+ }
312
+ },
313
+ //新增表格数据
314
+ insertRow(tableId, rows) {
241
315
  let listData = this.excuteListData.find((v) => {
242
- return v.name === tableId;
316
+ return v.fieldName1 === tableId;
243
317
  });
244
- listData.insertOrUpdateRow(row);
245
- },
246
- //清空表格数据
247
- clear(tableId) {
318
+ if (listData) {
319
+ listData.$vue.insertRow(rows);
320
+ }
321
+ },
322
+ //添加单选表格数据
323
+ insertSingleRow(tableId, row) {
248
324
  let listData = this.excuteListData.find((v) => {
249
- return v.name === tableId;
325
+ return v.fieldName1 === tableId;
250
326
  });
251
- listData.deleteAll();
252
- },
327
+ if (listData) {
328
+ listData.$vue.insertSingleRow(row);
329
+ }
330
+ },
331
+ //新增或替换表格数据
332
+ insertOrUpdateRow(tableId, row) {
333
+ let listData = this.excuteListData.find((v) => {
334
+ return v.fieldName1 === tableId;
335
+ });
336
+ if (listData) {
337
+ listData.$vue.insertOrUpdateRow(row);
338
+ }
339
+ },
340
+ //删除表格数据
341
+ deleteRow(tableId, row) {
342
+ let listData = this.excuteListData.find((v) => {
343
+ return v.id === tableId;
344
+ });
345
+ if (listData) {
346
+ listData.$vue.delRow(row);
347
+ }
348
+ },
349
+ //清空表格数据
350
+ clear(tableId) {
351
+ let listData = this.excuteListData.find((v) => {
352
+ return v.fieldName1 === tableId;
353
+ });
354
+ if (listData) {
355
+ listData.$vue.deleteAll();
356
+ }
357
+ },
253
358
 
254
- //获取后台数据,并返回脚本。
255
- execServerScript(action, object, successCallback) {
359
+ //获取后台数据,并返回脚本。
360
+ execServerScript(action, object, successCallback) {
256
361
  let formData = this;//作用域保存
257
362
 
258
363
  //是否是行内触发的
@@ -260,33 +365,33 @@ const formData = {
260
365
  object.editMode = data ? 1 : 0;
261
366
 
262
367
  request.postHandler(common.globalUri(), { action: action, para: object }).then(
263
- function (response) {
264
- if (response.rtnCode === Enum.ReturnCode.Successful) {
265
- var data = response.content;
266
- if (response.clientActionType === Enum.ClientActionType.ExcuteScript && data) {
267
- common.excute.call(formData.form.scripts, data);
268
- }
269
- else
270
- if (response.clientActionType === Enum.ClientActionType.None && data && successCallback) {
271
- //因为要传参,并直接执行方法,故successCallback回调里要使用formData的话,要加this
272
- //若不能接受this,也可修改common.excute方法
273
- //successCallback.call(formData.form.scripts, data);
368
+ function (response) {
369
+ if (response.rtnCode === Enum.ReturnCode.Successful) {
370
+ var data = response.content;
371
+ if (response.clientActionType === Enum.ClientActionType.ExcuteScript && data) {
372
+ common.excute.call(formData.form.scripts, data);
373
+ }
374
+ else
375
+ if (response.clientActionType === Enum.ClientActionType.None && data && successCallback) {
376
+ //因为要传参,并直接执行方法,故successCallback回调里要使用formData的话,要加this
377
+ //若不能接受this,也可修改common.excute方法
378
+ //successCallback.call(formData.form.scripts, data);
274
379
 
275
- //优化,不需要加this
276
- common.excuteFun.call(formData.form.scripts, successCallback, data);
277
- }
380
+ //优化,不需要加this
381
+ common.excuteFun.call(formData.form.scripts, successCallback, data);
278
382
  }
279
383
  }
384
+ }
280
385
  );
281
- },
282
- execRouter(routerKey) {
386
+ },
387
+ execRouter(routerKey) {
283
388
  let field = { fieldName1: routerKey };
284
389
  this.form.$vue.fieldClickHandler(field);
285
- },
286
- //消息提示 type主题:success/warning/info/error。 duration 显示时间, 毫秒。设为 0 则不会自动关闭。 showClose 是否显示关闭按钮。
287
- message(message, type, center, duration, showClose, dangerouslyUseHTMLString) {
390
+ },
391
+ //消息提示 type主题:success/warning/info/error。 duration 显示时间, 毫秒。设为 0 则不会自动关闭。 showClose 是否显示关闭按钮。
392
+ message(message, type, center, duration, showClose, dangerouslyUseHTMLString) {
288
393
  common.message(message, type, center, duration, showClose, dangerouslyUseHTMLString)
289
- },
394
+ },
290
395
  };
291
396
 
292
397
  export default formData;