centaline-data-driven 1.2.73 → 1.2.76

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.
@@ -4,7 +4,7 @@ import Enum from './lib/Enum';
4
4
  import Router from './Router';
5
5
  import valid from '../../../validate/index';
6
6
  import common from '../../../common';
7
- import formData from '../../../formData';
7
+ import Axios from 'axios';
8
8
  import Vue from 'vue';
9
9
 
10
10
  const Form = function (source, callBack, apiParam, failCallBack, isFormList) {
@@ -163,8 +163,297 @@ const Form = function (source, callBack, apiParam, failCallBack, isFormList) {
163
163
  get onload() {
164
164
  return source.onload;
165
165
  },
166
- get formData() {
167
- return formData;
166
+ formData:{
167
+ common: common,
168
+ Axios: Axios,
169
+ form: null,
170
+ formTable:null,
171
+ excuteData: null,//fields
172
+ fieldsDic: null,//fieldsDic
173
+ _excuteListData: undefined,
174
+
175
+ //获取code1
176
+ getCode1ByField1(id) {
177
+ var rtn1 = this.fieldsDic[id];
178
+ if (rtn1) {
179
+ return rtn1.value;
180
+ }
181
+ },
182
+ //获取code2
183
+ getCode2ByField1(id) {
184
+ var rtn1 = this.fieldsDic[id];
185
+ if (rtn1) {
186
+ return rtn1.value1;
187
+ }
188
+ },
189
+ //获取Field的属性attrKey的值
190
+ getValueByFieldName(id, attrKey) {
191
+ attrKey = this.common.initialsToUpperCase(attrKey);
192
+ var rtn1 = this.fieldsDic[id];
193
+ if (rtn1) {
194
+ return rtn1.source[attrKey];
195
+ }
196
+ },
197
+ //设置Field的属性attrKey的值
198
+ setValueByFieldName(id, attrKey, attrValue) {
199
+ attrKey = this.common.initialsToUpperCase(attrKey);
200
+ var rtn1 = this.fieldsDic[id];
201
+ if (rtn1) {
202
+ rtn1.source[attrKey] = attrValue;
203
+ this.form.hatchHandle(id, attrKey, attrValue, rtn1);
204
+ //this.form.hiddenHandle(rtn1);//隐藏关联的
205
+
206
+ //用于处理源数据改动,强制更新视图数据 todo
207
+ if (rtn1.self.$forceUpdate) {
208
+ rtn1.self.$forceUpdate();
209
+ }
210
+ }
211
+ },
212
+ //设置Field的v1、v2的值
213
+ setV1AndV2ByField1(id, code1, code2) {
214
+ var rtn1 = this.fieldsDic[id];
215
+ if (rtn1) {
216
+ if (typeof rtn1.value !== 'undefined') {
217
+ rtn1.value = code1;
218
+
219
+ this.form.validMrf(rtn1);//验证必填关联组件
220
+ this.form.hiddenHandle(rtn1, true);//隐藏关联的
221
+ }
222
+ if (typeof rtn1.value1 !== 'undefined') {
223
+ rtn1.value1 = code2;
224
+ }
225
+
226
+ if (rtn1.self.$forceUpdate) {
227
+ rtn1.self.$forceUpdate();
228
+ }
229
+ }
230
+ },
231
+
232
+ //获取列表数据
233
+ get excuteListData() {
234
+ if (this._excuteListData) {
235
+ return this._excuteListData;
236
+ }
237
+ else {
238
+ if (this.excuteData !== null) {
239
+ this._excuteListData = this.excuteData.filter((v) => {
240
+ return typeof v.is !== undefined && v.is === 'ct-form-list-table';
241
+ });
242
+ }
243
+ }
244
+ return this._excuteListData;
245
+ },
246
+ setExcuteListData(fields) {
247
+ this._excuteListData=null;
248
+ if (fields !== null) {
249
+ this.excuteData=fields;
250
+ this._excuteListData = fields.filter((v) => {
251
+ return typeof v.is !== undefined && v.is === 'ct-form-list-table';
252
+ });
253
+ }
254
+ },
255
+ //获取列表的Field
256
+ getListField(tableName, rowNum, fiedlId) {
257
+ let listData = this.excuteListData.find((v) => {
258
+ return v.id === tableName;
259
+ });
260
+ if (listData) {
261
+ let field = null;
262
+ //正在编辑的Field
263
+ if (rowNum === null && (fiedlId === null || listData.currentEventField.id === fiedlId)) {
264
+ field = listData.currentEventField;
265
+ }
266
+ //正在编辑的行
267
+ else if (rowNum === null && listData.currentRowIndex === 0) {
268
+ let fields = listData.currentRow.data;
269
+ field = fields[fiedlId];
270
+ }
271
+ //源数据
272
+ else {
273
+ if (rowNum === null && listData.currentRowIndex) {
274
+ rowNum = listData.currentRowIndex;
275
+ }
276
+
277
+ if (rowNum === 0 || (rowNum && fiedlId)) {
278
+ try {
279
+ let fields = listData.rows[rowNum].field;
280
+ field = fields.find((v) => {
281
+ return v.id === fiedlId;
282
+ });
283
+ } catch (e) {
284
+ if (listData.rows.length <= rowNum) {
285
+ var checkMsg = "获取列表行索引超出界限";
286
+ this.message(checkMsg);
287
+ }
288
+ }
289
+ }
290
+ }
291
+
292
+ return { listData: listData, field: field };
293
+ }
294
+ },
295
+ //获取列表的行数(注意 这里包括列头)
296
+ getListCount(tableName) {
297
+ tableName = tableName ? tableName : this.form.scripts.$fd;
298
+ let data = this.getListField(tableName, null, null);
299
+ if (data) {
300
+ return data.listData.rows.length;
301
+ }
302
+ },
303
+ //获取表格某行某列的值
304
+ getListFieldValue(tableName, rowNum, fiedlId, attrName, defaultValue) {
305
+ tableName = tableName ? tableName : this.form.scripts.$fd;
306
+
307
+ let data = this.getListField(tableName, rowNum, fiedlId);
308
+
309
+ attrName = this.common.initialsToUpperCase(attrName);
310
+ attrName = attrName ? attrName : 'code1';
311
+
312
+ if (!fiedlId) {
313
+ fiedlId = data.listData.currentEventField.id;
314
+ }
315
+ if (fiedlId && rowNum === null && fiedlId === data.listData.currentEventField.id) {
316
+ data.field = data.listData.currentEventField;
317
+ }
318
+ rowNum = rowNum !== null ? rowNum : data.listData.currentRowIndex;
319
+
320
+ //若该行正在编辑,则取编辑状态的。
321
+ if (data && data.listData && data.listData.currentRow.data && data.listData.currentRow.data[fiedlId]
322
+ && data.listData.currentRow.data.$sourceIndex === rowNum && data.listData.currentRow.isSet) {
323
+ return data.listData.currentRow.data[fiedlId].source[attrName];
324
+ }
325
+ else if (data && data.field) {
326
+ if (typeof defaultValue !== 'undefined' && data.listData.rows[rowNum].deleted) {//若该行被删除时,则直接返回默认值
327
+ return defaultValue;
328
+ }
329
+ return data.field.source[attrName];
330
+ }
331
+ },
332
+ //设置表格某行某列的值
333
+ setListFieldValue(value, tableName, rowNum, fiedlId, attrName) {
334
+ value = value==undefined?"":value.toString();
335
+ tableName = tableName ? tableName : this.form.scripts.$fd;
336
+ let data = this.getListField(tableName, rowNum, fiedlId);
337
+
338
+ attrName = this.common.initialsToUpperCase(attrName);
339
+ attrName = attrName ? attrName : 'code1';
340
+
341
+ if (!fiedlId) {
342
+ fiedlId = data.listData.currentEventField.id;
343
+ }
344
+ if (fiedlId && !rowNum && fiedlId === data.listData.currentEventField.id) {
345
+ //data.field = data.listData.currentEventField;
346
+ }
347
+ rowNum = rowNum ? rowNum : data.listData.currentRowIndex;
348
+
349
+ if (data) {
350
+ if (data.field) {
351
+ data.field.source[attrName] = value;
352
+ data.listData.updateListField(data.listData.refFieldsLabel, rowNum, fiedlId);
353
+ }
354
+ //data.field.self.$forceUpdate();
355
+
356
+ //正在编辑的行
357
+ if (data.listData.currentRow.data && data.listData.currentRow.data[fiedlId] && data.listData.currentRow.data.$sourceIndex === rowNum) {
358
+ let currentField = data.listData.currentRow.data[fiedlId];
359
+ currentField.source[attrName] = value;
360
+ //校验自己
361
+ if (currentField.self && currentField.self.validExcute) {
362
+ currentField.self.validExcute();
363
+ }
364
+ if (typeof currentField.self.$forceUpdate === "function") {
365
+ currentField.self.$forceUpdate();
366
+ }
367
+ }
368
+
369
+ //如果有汇总列,触发重新计算汇总
370
+ if (data.listData.showSummary) {
371
+ data.listData.tableData.push({});
372
+ data.listData.tableData.pop();
373
+ }
374
+
375
+ return true;
376
+ }
377
+ return false;
378
+ },
379
+ //设置表格属性值
380
+ setListAttr(tableId, attrName, attrValue) {
381
+ let listData = this.excuteListData.find((v) => {
382
+ return v.id === tableId;
383
+ });
384
+ listData[attrName] = attrValue
385
+ },
386
+ //新增表格数据
387
+ insertRow(tableId,rows) {
388
+ let listData = this.excuteListData.find((v) => {
389
+ return v.id === tableId;
390
+ });
391
+ listData.insertRow(rows);
392
+ },
393
+ //新增或替换表格数据
394
+ insertOrUpdateRow(tableId,row) {
395
+ let listData = this.excuteListData.find((v) => {
396
+ return v.id === tableId;
397
+ });
398
+ listData.insertOrUpdateRow(row);
399
+ },
400
+ //清空表格数据
401
+ clear(tableId) {
402
+ let listData = this.excuteListData.find((v) => {
403
+ return v.id === tableId;
404
+ });
405
+ listData.deleteAll();
406
+ },
407
+
408
+ //获取后台数据,并返回脚本。
409
+ execServerScript(action, object, successCallback) {
410
+ let formData = this;//作用域保存
411
+
412
+ //是否是行内触发的
413
+ let data = this.getListField(this.form.scripts.$fd, null, null);
414
+ object.editMode = data ? 1 : 0;
415
+
416
+ Vue.prototype.$api.postHandler(this.common.globalUri(), { action: action, para: object }).then(
417
+ function (response) {
418
+ if (response.rtnCode === Enum.ReturnCode.Successful) {
419
+ var data = response.content;
420
+ if (response.clientActionType === Enum.ClientActionType.ExcuteScript && data) {
421
+ formData.common.excute.call(formData.form.scripts, data);
422
+ }
423
+ else
424
+ if (response.clientActionType === Enum.ClientActionType.None && data && successCallback) {
425
+ //因为要传参,并直接执行方法,故successCallback回调里要使用formData的话,要加this
426
+ //若不能接受this,也可修改common.excute方法
427
+ //successCallback.call(formData.form.scripts, data);
428
+
429
+ //优化,不需要加this
430
+ formData.common.excuteFun.call(formData.form.scripts, successCallback, data);
431
+ }
432
+ }
433
+ }
434
+ );
435
+ },
436
+ //消息提示 type主题:success/warning/info/error。 duration 显示时间, 毫秒。设为 0 则不会自动关闭。 showClose 是否显示关闭按钮。
437
+ message(message, type, center, duration, showClose, dangerouslyUseHTMLString) {
438
+ if (typeof center === 'undefined') {
439
+ center = true;
440
+ }
441
+ if (typeof duration === 'undefined') {
442
+ duration = 1500;
443
+ }
444
+ if (typeof showClose === 'undefined') {
445
+ showClose = false;
446
+ }
447
+
448
+ Vue.prototype.$message({
449
+ message: message,//消息文字
450
+ dangerouslyUseHTMLString: dangerouslyUseHTMLString || false,
451
+ type: type || 'error',//主题:success/warning/info/error
452
+ center: center,//是否居中
453
+ duration: duration, //显示时间, 毫秒。设为 0 则不会自动关闭
454
+ showClose: showClose,//是否显示关闭按钮
455
+ });
456
+ },
168
457
  },
169
458
  getFormObj() {
170
459
  var rtnFormObj = {};
@@ -108,8 +108,7 @@ const FormList = function (source, master) {
108
108
  }
109
109
  },
110
110
  _rows:null,
111
- get rows() {
112
-
111
+ get rows() {
113
112
  if (this._rows) {
114
113
  return this._rows;
115
114
  }
@@ -119,6 +118,7 @@ const FormList = function (source, master) {
119
118
  source.rows.forEach((r) => {
120
119
  var row = rtn.initRow(r);
121
120
  this._rows.push(row);
121
+ rtn._rows[rtn._rows.length - 1].$sourceIndex = rtn._rows.length - 1;
122
122
  });
123
123
  return this._rows;
124
124
  }
@@ -285,13 +285,17 @@ const FormList = function (source, master) {
285
285
  cancelButtonText: "取消",
286
286
  //type: 'warning'
287
287
  }).then(() => {
288
- if (rtn.rows[index].isNewFlag) {
289
- rtn.rows.splice(index, 1);
290
- source.rows.splice(index, 1);
291
- }
292
- else {
293
- rtn.rows[index].deleted = true;
294
- }
288
+ rtn.rows.forEach((row,i) => {
289
+ if(row.$sourceIndex===index){
290
+ if (row.isNewFlag) {
291
+ rtn.rows.splice(i, 1);
292
+ source.rows.splice(i, 1);
293
+ }
294
+ else {
295
+ rtn.rows[i].deleted = true;
296
+ }
297
+ }
298
+ });
295
299
  callback();
296
300
  }).catch(() => {
297
301
  });
@@ -349,7 +353,6 @@ const FormList = function (source, master) {
349
353
  common.openDialog(dialogOption);
350
354
  },
351
355
  addSourceRow(row) {
352
- //let sourceRow = JSON.parse(JSON.stringify(source.Rows[0]));
353
356
  let sourceRow = JSON.parse(JSON.stringify(source.rows[0]));
354
357
  for (let k in sourceRow.columns) {
355
358
  //sourceRow.Row[k] = row.field[k].source;
@@ -360,6 +363,7 @@ const FormList = function (source, master) {
360
363
  let iRow = this.initRow(sourceRow);
361
364
  iRow.isNewFlag = true;
362
365
  rtn._rows.push(iRow);
366
+ rtn._rows[rtn._rows.length - 1].$sourceIndex = rtn._rows.length - 1;
363
367
  Vue.set(row, 'edit', iRow.edit);
364
368
  Vue.set(row, 'delete', iRow.delete);
365
369
  row.$sourceIndex = rtn._rows.length - 1;
@@ -403,6 +407,7 @@ const FormList = function (source, master) {
403
407
  if (!isRepeat) {
404
408
  source.rows.push(row);
405
409
  rtn.rows.push(rowItem);
410
+ rtn._rows[rtn._rows.length - 1].$sourceIndex = rtn._rows.length - 1;
406
411
 
407
412
  rowData.$sourceIndex = source.rows.length - 1;
408
413
 
@@ -418,7 +423,63 @@ const FormList = function (source, master) {
418
423
  }]
419
424
  };
420
425
  common.openDialog(dialogOption);
421
- }
426
+ },
427
+ deleteAll() {
428
+ if(rtn._rows && rtn._rows.length>1){
429
+ let index=0;
430
+ var newRows=[]
431
+ rtn._rows.forEach((r) => {
432
+ if(index>0){
433
+ if (!r.isNewFlag) {
434
+ r.deleted = true;
435
+ newRows.push(r);
436
+ }
437
+ }
438
+ else{
439
+ index++;
440
+ }
441
+ });
442
+ rtn._tableData.splice(0,rtn._tableData.length);
443
+ source.rows.splice(1, source.rows.length-1,newRows);
444
+ rtn._rows.splice(1, rtn._rows.length-1,newRows);
445
+ }
446
+ },
447
+ insertRow(rows) {
448
+ if(rows && rows.length>0){
449
+ rows.forEach((r) => {
450
+ source.rows.push(r);
451
+ let iRow = this.initRow(r);
452
+ iRow.isNewFlag = true;
453
+ rtn._rows.push(iRow);
454
+ Vue.set(r, 'edit', iRow.edit);
455
+ Vue.set(r, 'delete', iRow.delete);
456
+ rtn._rows[rtn._rows.length - 1].$sourceIndex = rtn._rows.length - 1;
457
+
458
+ let rowData = rtn.rowsItemToTableData(iRow)
459
+ rowData.$sourceIndex = rtn._rows.length - 1;
460
+ rowData.edit = iRow.edit;
461
+ rowData.delete = iRow.delete;
462
+ rtn._tableData.push(rowData);
463
+ });
464
+ }
465
+ },
466
+ insertOrUpdateRow(row) {
467
+ if(row){
468
+ source.rows.push(r);
469
+ let iRow = this.initRow(r);
470
+ iRow.isNewFlag = true;
471
+ rtn._rows.push(iRow);
472
+ Vue.set(r, 'edit', iRow.edit);
473
+ Vue.set(r, 'delete', iRow.delete);
474
+ r.$sourceIndex = rtn._rows.length - 1;
475
+
476
+ let rowData = rtn.rowsItemToTableData(iRow)
477
+ rowData.$sourceIndex = rtn._rows.length - 1;
478
+ rowData.edit = iRow.edit;
479
+ rowData.delete = iRow.delete;
480
+ rtn._tableData.push(rowData);
481
+ }
482
+ },
422
483
  };
423
484
  return rtn;
424
485
  };