Permalink
Browse files

fix: u-meta定义可以对应主子表情况下对应特定行

  • Loading branch information...
1 parent c63bf10 commit f6aca86948329e5514b65b45c316a82493d355bf liuyk committed Nov 14, 2016
Showing with 383 additions and 102 deletions.
  1. +108 −24 dist/js/kero-adapter.js
  2. +55 −3 dist/js/kero.js
  3. +5 −6 dist/js/sparrow.js
  4. +2 −2 dist/js/sparrow.min.js
  5. +122 −24 dist/js/u.js
  6. +13 −13 dist/js/u.min.js
  7. +78 −30 js/core/valueMixin.js
@@ -1791,6 +1791,7 @@
DataTable.prototype.getData = _getData.getData;
DataTable.prototype.getDataByRule = _getData.getDataByRule;
DataTable.prototype.getRow = _getData.getRow;
+ DataTable.prototype.getChildRow = _getData.getChildRow;
DataTable.prototype.getRowByRowId = _getData.getRowByRowId;
DataTable.prototype.getRowIndex = _getData.getRowIndex;
DataTable.prototype.getRowsByField = _getData.getRowsByField;
@@ -2438,6 +2439,35 @@
return this.rows.peek()[index];
};
+ var getChildRow = function getChildRow(obj) {
+ var fullField = obj.fullField,
+ index = obj.index,
+ row = null;
+ if (parseInt(index) > -1) {
+ if ((index + '').indexOf('.') > 0) {
+ var fieldArr = fullField.split('.');
+ var indexArr = index.split('.');
+ var nowDatatable = this;
+ var nowRow = null;
+ for (var i = 0; i < indexArr.length; i++) {
+ nowRow = nowDatatable.getRow(indexArr[i]);
+ if (i < indexArr.length - 1) {
+ if (nowRow) {
+ nowDatatable = nowRow.getValue(fieldArr[i]);
+ } else {
+ nowRow = null;
+ break;
+ }
+ }
+ }
+ row = nowRow;
+ } else {
+ row = this.getRow(index);
+ }
+ }
+ return row;
+ };
+
/**
* 根据rowid取row对象
* @param rowid
@@ -2578,6 +2608,7 @@
exports.getData = getData;
exports.getDataByRule = getDataByRule;
exports.getRow = getRow;
+ exports.getChildRow = getChildRow;
exports.getRowByRowId = getRowByRowId;
exports.getRowIndex = getRowIndex;
exports.getRowsByField = getRowsByField;
@@ -3182,15 +3213,22 @@
};
var refByRow = function refByRow(obj) {
- var fieldName = obj.fieldName;
+ var fieldName = obj.fieldName,
+ fullField = obj.fullField;
this.createField(fieldName);
if (!this.valueChange[fieldName]) this.valueChange[fieldName] = ko.observable(1);
return ko.pureComputed({
read: function read() {
this.valueChange[fieldName]();
this.currentRowChange();
- var row;
- if (obj.index > -1) row = this.getRow(obj.index);
+ var row,
+ index = obj.index + '';
+ var childRowObj = {
+ fullField: fullField,
+ index: index
+ };
+ row = this.getChildRow(childRowObj);
+
if (row) {
return row.getChildValue(fieldName);
} else return '';
@@ -4974,7 +5012,7 @@
/* 78 */
/***/ function(module, exports) {
- "use strict";
+ 'use strict';
exports.__esModule = true;
/**
@@ -4988,22 +5026,28 @@
var self = this;
// 如果存在行对象则处理数据都针对此行进行处理
- if (this.options.rowIndex > -1) {
- // 添加监听,判断当前field并且为当前行的情况下才修改值
- this.dataModel.on(DataTable.ON_VALUE_CHANGE, function (obj) {
- if (self.field == obj.field) {
- var rowId = obj.rowId;
- var row = self.dataModel.getRowByRowId(rowId);
- var index = self.dataModel.getRowIndex(row);
- if (index == self.options.rowIndex) {
- self.modelValueChange(obj.newValue);
- }
+ if (parseInt(this.options.rowIndex) > -1) {
+ if ((this.options.rowIndex + '').indexOf('.') > 0) {
+ // 主子表的情况
+ var childObj = this.getChildVariable();
+ var lastRow = childObj.lastRow;
+ var lastField = childObj.lastField;
+ this.dataModel.refByRow({ fieldName: lastField, index: this.options.rowIndex, fullField: this.field }).subscribe(function (value) {
+ self.modelValueChange(value);
+ });
+
+ if (lastRow) {
+ this.modelValueChange(lastRow.getValue(lastField));
}
- });
+ } else {
+ this.dataModel.refByRow({ fieldName: this.field, index: this.options.rowIndex }).subscribe(function (value) {
+ self.modelValueChange(value);
+ });
- var rowObj = this.dataModel.getRow(this.options.rowIndex);
- if (rowObj) {
- this.modelValueChange(rowObj.getValue(this.field));
+ var rowObj = this.dataModel.getRow(this.options.rowIndex);
+ if (rowObj) {
+ this.modelValueChange(rowObj.getValue(this.field));
+ }
}
} else {
this.dataModel.ref(this.field).subscribe(function (value) {
@@ -5014,6 +5058,32 @@
},
methods: {
/**
+ * 获取与子表相关的变量
+ * @param {Object} value
+ */
+ getChildVariable: function getChildVariable() {
+ var indexArr = this.options.rowIndex.split('.');
+ var lastIndex = indexArr[indexArr.length - 1];
+ var fieldArr = this.options.field.split('.');
+ var lastField = fieldArr[fieldArr.length - 1];
+ var lastDataTable = this.dataModel;
+ var lastRow = null;
+
+ for (var i = 0; i < fieldArr.length; i++) {
+ lastRow = lastDataTable.getRow(indexArr[i]);
+ if (!lastRow) break;
+ if (i < fieldArr.length - 1) {
+ lastDataTable = lastRow.getValue(fieldArr[i]);
+ }
+ }
+ return {
+ lastField: lastField,
+ lastIndex: lastIndex,
+ lastDataTable: lastDataTable,
+ lastRow: lastRow
+ };
+ },
+ /**
* 模型数据改变
* @param {Object} value
*/
@@ -5047,9 +5117,16 @@
this.showValue = this.masker ? this.masker.format(this.trueValue).value : this.trueValue;
this.setShowValue(this.showValue);
this.slice = true;
- if (this.options.rowIndex > -1) {
- var rowObj = this.dataModel.getRow(this.options.rowIndex);
- if (rowObj) rowObj.setValue(this.field, this.trueValue);
+ if (parseInt(this.options.rowIndex) > -1) {
+ if ((this.options.rowIndex + '').indexOf('.') > 0) {
+ var childObj = this.getChildVariable();
+ var lastRow = childObj.lastRow;
+ var lastField = childObj.lastField;
+ if (lastRow) lastRow.setValue(lastField, this.trueValue);
+ } else {
+ var rowObj = this.dataModel.getRow(this.options.rowIndex);
+ if (rowObj) rowObj.setValue(this.field, this.trueValue);
+ }
} else {
this.dataModel.setValue(this.field, this.trueValue);
}
@@ -5071,9 +5148,16 @@
},
setModelValue: function setModelValue(value) {
if (!this.dataModel) return;
- if (this.options.rowIndex > -1) {
- var rowObj = this.dataModel.getRow(this.options.rowIndex);
- if (rowObj) rowObj.setValue(this.field, value);
+ if (parseInt(this.options.rowIndex) > -1) {
+ if ((this.options.rowIndex + '').indexOf('.') > 0) {
+ var childObj = this.getChildVariable();
+ var lastRow = childObj.lastRow;
+ var lastField = childObj.lastField;
+ if (lastRow) lastRow.setValue(lastField, this.trueValue);
+ } else {
+ var rowObj = this.dataModel.getRow(this.options.rowIndex);
+ if (rowObj) rowObj.setValue(this.field, value);
+ }
} else {
this.dataModel.setValue(this.field, value);
}
View
@@ -3111,6 +3111,7 @@
DataTable.prototype.getData = _getData.getData;
DataTable.prototype.getDataByRule = _getData.getDataByRule;
DataTable.prototype.getRow = _getData.getRow;
+ DataTable.prototype.getChildRow = _getData.getChildRow;
DataTable.prototype.getRowByRowId = _getData.getRowByRowId;
DataTable.prototype.getRowIndex = _getData.getRowIndex;
DataTable.prototype.getRowsByField = _getData.getRowsByField;
@@ -3758,6 +3759,35 @@
return this.rows.peek()[index];
};
+ var getChildRow = function getChildRow(obj) {
+ var fullField = obj.fullField,
+ index = obj.index,
+ row = null;
+ if (parseInt(index) > -1) {
+ if ((index + '').indexOf('.') > 0) {
+ var fieldArr = fullField.split('.');
+ var indexArr = index.split('.');
+ var nowDatatable = this;
+ var nowRow = null;
+ for (var i = 0; i < indexArr.length; i++) {
+ nowRow = nowDatatable.getRow(indexArr[i]);
+ if (i < indexArr.length - 1) {
+ if (nowRow) {
+ nowDatatable = nowRow.getValue(fieldArr[i]);
+ } else {
+ nowRow = null;
+ break;
+ }
+ }
+ }
+ row = nowRow;
+ } else {
+ row = this.getRow(index);
+ }
+ }
+ return row;
+ };
+
/**
* 根据rowid取row对象
* @param rowid
@@ -3898,6 +3928,7 @@
exports.getData = getData;
exports.getDataByRule = getDataByRule;
exports.getRow = getRow;
+ exports.getChildRow = getChildRow;
exports.getRowByRowId = getRowByRowId;
exports.getRowIndex = getRowIndex;
exports.getRowsByField = getRowsByField;
@@ -4502,15 +4533,22 @@
};
var refByRow = function refByRow(obj) {
- var fieldName = obj.fieldName;
+ var fieldName = obj.fieldName,
+ fullField = obj.fullField;
this.createField(fieldName);
if (!this.valueChange[fieldName]) this.valueChange[fieldName] = ko.observable(1);
return ko.pureComputed({
read: function read() {
this.valueChange[fieldName]();
this.currentRowChange();
- var row;
- if (obj.index > -1) row = this.getRow(obj.index);
+ var row,
+ index = obj.index + '';
+ var childRowObj = {
+ fullField: fullField,
+ index: index
+ };
+ row = this.getChildRow(childRowObj);
+
if (row) {
return row.getChildValue(fieldName);
} else return '';
@@ -5984,6 +6022,14 @@
rowObj.parent.trigger(DataTable.ON_VALUE_CHANGE, event);
rowObj.parent.trigger(fieldName + "." + DataTable.ON_VALUE_CHANGE, event);
if (rowObj == rowObj.parent.getCurrentRow()) rowObj.parent.trigger(fieldName + "." + DataTable.ON_CURRENT_VALUE_CHANGE, event);
+
+ // 对于多级字表需要触发顶层div的valuechange事件
+ if (rowObj.parent.ns) {
+ event.fullField = fName;
+ event.ns = rowObj.parent.ns;
+ rowObj.parent.root.trigger(DataTable.ON_VALUE_CHANGE, event);
+ rowObj.parent.root.trigger(fName + "." + DataTable.ON_VALUE_CHANGE, event);
+ }
};
/**
@@ -6009,6 +6055,12 @@
var tempField = rowObj.data;
for (var i = 0; i < fnames.length; i++) {
tempField = tempField[fnames[i]];
+ if (tempField.value instanceof DataTable) {
+ var row = tempField.value.getCurrentRow();
+ if (row) {
+ tempField = row.data;
+ }
+ }
if (!tempField) {
break;
}
View
@@ -1,5 +1,5 @@
/*!
- * tinper-sparrow v0.1.1
+ * tinper-sparrow v3.1.3
* sparrow.js
* author : Yonyou FED
* homepage : https://github.com/iuap-design/tinper-sparrow#readme
@@ -2886,17 +2886,16 @@
};
PhoneNumberMasker.prototype.formatArgument = function (obj) {
- return obj;
+ var numberObj = {};
+ numberObj.value = obj;
+ return numberObj;
};
PhoneNumberMasker.prototype.innerFormat = function (obj) {
if (!obj) {
return;
}
- var val = obj;
- return {
- value: val
- };
+ return obj;
};
NumberMasker.DefaultFormatMeta = {
Oops, something went wrong.
Oops, something went wrong.

0 comments on commit f6aca86

Please sign in to comment.