1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | 1× 3× 1× 1× 1× 1× 1× 1× 1× 3× 3× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 2× 2× 2× 2× 2× 2× 2× 2× 2× 2× 2× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 22× 22× 22× 22× 20× 20× 20× 22× 1× 20× 20× 20× 20× 20× 5× 5× 5× 9× 5× 15× 1× 3× 3× 3× 3× 3× 2× 3× 3× 3× 3× 1× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 2× 2× 1× 1× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 3× 1× 3× 3× 3× 3× 1× 1× | 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _cloneDeep = require('lodash/cloneDeep'); var _cloneDeep2 = _interopRequireDefault(_cloneDeep); var _uxcoreConst = require('uxcore-const'); var _uxcoreConst2 = _interopRequireDefault(_uxcoreConst); var _util = require('./util'); var _util2 = _interopRequireDefault(_util); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _toConsumableArray(arr) { Eif (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } function addEmptyRow(cb) { this.insertRecords({}, false, cb); } function addEmptyRowFromTop(cb) { this.insertRecords({}, true, cb); } function addRow(rowData, cb) { this.insertRecords(rowData, false, cb); } function addRowFromTop(rowData, cb) { this.insertRecords(rowData, true, cb); } function resetRow(rowData, cb) { var _this = this; var me = this; var updateData = {}; var data = me.data.datas || me.data.data; for (var i = 0; i < data.length; i++) { Eif (data[i].jsxid === rowData.jsxid) { updateData = (0, _cloneDeep2['default'])(data[i]); break; } } this.updateRecord(updateData, function () { _this.doValidate(); Eif (cb) { cb(updateData); } }); } function resetAllRow(cb) { var _this2 = this; var me = this; var copyData = (0, _cloneDeep2['default'])(me.data); var stateData = me.state.data.data || me.state.data.datas; Eif (copyData.data || copyData.datas) { var data = copyData.data || copyData.datas; var _loop = function _loop(i) { var item = data[i]; stateData.forEach(function (stateItem) { Eif (item.jsxid === stateItem.jsxid) { item.__mode__ = stateItem.__mode__; } }); }; for (var i = 0; i < data.length; i++) { _loop(i); } this.setState({ data: copyData }, function () { _this2.doValidate(); Eif (cb) { cb(); } }); } } function delRow(rowData, cb) { this.removeRecords(rowData, cb); } function editRow(rowData, cb) { var newRowData = (0, _cloneDeep2['default'])(rowData); newRowData.__mode__ = _uxcoreConst2['default'].MODE.EDIT; this.updateRecord(newRowData, cb); } function viewRow(rowData, cb) { var newRowData = (0, _cloneDeep2['default'])(rowData); newRowData.__mode__ = _uxcoreConst2['default'].MODE.VIEW; this.updateRecord(newRowData, cb); } function viewAllRow(cb) { var me = this; var data = (0, _cloneDeep2['default'])(me.state.data.data || me.state.data.datas); for (var i = 0; i < data.length; i++) { var _item = data[i]; _item.__mode__ = _uxcoreConst2['default'].MODE.VIEW; } this.updateRecord(data, cb); } function resetAndViewAllRow(cb) { var me = this; var data = (0, _cloneDeep2['default'])(me.data.data || me.data.datas); for (var i = 0; i < data.length; i++) { var _item2 = data[i]; _item2.__mode__ = _uxcoreConst2['default'].MODE.VIEW; } this.updateRecord(data, cb); } function saveRow(rowData, cb) { var newRowData = (0, _cloneDeep2['default'])(rowData); newRowData.__mode__ = _uxcoreConst2['default'].MODE.VIEW; newRowData.__edited__ = true; this.syncRecord(newRowData, cb); } function saveAllRow(cb) { var me = this; var data = (0, _cloneDeep2['default'])(me.state.data.data || me.state.data.datas); for (var i = 0; i < data.length; i++) { var _item3 = data[i]; _item3.__mode__ = _uxcoreConst2['default'].MODE.VIEW; _item3.__edited__ = true; } this.syncRecord(data, cb); } function editAllRow(cb) { var me = this; var data = (0, _cloneDeep2['default'])(me.data.data || me.data.datas); for (var i = 0; i < data.length; i++) { var _item4 = data[i]; _item4.__mode__ = _uxcoreConst2['default'].MODE.EDIT; } this.updateRecord(data, cb); } function toggleSubComp(rowData, cb) { var content = (0, _cloneDeep2['default'])(this.state.data); var data = content.data || content.datas; var rows = Array.isArray(rowData) ? rowData : [rowData]; Eif (data) { rows.forEach(function (row) { for (var i = 0; i < data.length; i++) { var _item5 = data[i]; Eif (_item5.jsxid === row.jsxid) { _item5.showSubComp = !_item5.showSubComp; break; } } }); this.syncRecord(data, cb); } } function moveRowUp(rowData, cb) { var content = (0, _cloneDeep2['default'])(this.state.data); var data = content.data || content.datas; Eif (data) { var treeIdArr = rowData.__treeId__.split('-'); var rows = data; for (var i = 0; i < treeIdArr.length - 1; i++) { var rowIndex = treeIdArr[i]; rows = rows[rowIndex].data; } var lastIndex = treeIdArr.pop(); Eif (lastIndex > 0) { rows.splice(lastIndex, 1); rows.splice(lastIndex - 1, 0, _extends({}, rowData, { __treeId__: treeIdArr.concat([lastIndex - 1]).join('-') })); this.data = content; this.setState({ data: content }, function () { Eif (cb) { cb(); } }); } this.updateTreeId(data); } } function moveRowDown(rowData, cb) { var content = (0, _cloneDeep2['default'])(this.state.data); var data = content.data || content.datas; Eif (data) { var treeIdArr = rowData.__treeId__.split('-').map(function (item) { return parseInt(item, 10); }); var rows = data; for (var i = 0; i < treeIdArr.length - 1; i++) { var rowIndex = treeIdArr[i]; rows = rows[rowIndex].data; } var lastIndex = treeIdArr.pop(); Eif (lastIndex < rows.length - 1) { rows.splice(lastIndex, 1); rows.splice(lastIndex + 1, 0, _extends({}, rowData, { __treeId__: treeIdArr.concat([lastIndex + 1]).join('-') })); this.data = content; this.setState({ data: content }, function () { Eif (cb) { cb(); } }); } this.updateTreeId(data); } } function doValidate() { var pass = true; var me = this; var fieldKeys = Object.keys(me.fields); fieldKeys.forEach(function (name) { var fieldPass = me.fields[name](); // if one field fails to pass, the table fails to pass Eif (pass) { pass = fieldPass; } }); return pass; } function getData(validate) { var me = this; var pass = true; Eif (validate !== false) { pass = this.doValidate(); } if (me.props.getSavedData) { // 滤除可能为空的元素 var data = (0, _cloneDeep2['default'])(me.data); Eif (data && data.data instanceof Array) { data.data = data.data.filter(function (item) { return item !== undefined; }); } return { data: data, pass: pass }; } return { data: me.state.data, pass: pass }; } function changeTreeExpandState(_ref) { var tableData = _ref.tableData, rowData = _ref.rowData; var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {}; var expandedKeys = (0, _cloneDeep2['default'])(this.state.expandedKeys); _util2['default'].toggleItemInArr(rowData.jsxid, expandedKeys); var filteredTreeLoadingIds = this.state.treeLoadingIds.filter(function (id) { return id !== rowData.__treeId__; }); Eif (tableData) { this.data = tableData; this.setState({ treeLoadingIds: filteredTreeLoadingIds, expandedKeys: expandedKeys, data: tableData }, function () { cb(); }); } else { this.setState({ treeLoadingIds: filteredTreeLoadingIds, expandedKeys: expandedKeys }, function () { cb(); }); } } function toggleTreeExpanded(rowData, cb) { var _this3 = this; var loadTreeData = this.props.loadTreeData; var treeLoadingIds = this.state.treeLoadingIds; Eif (Array.isArray(rowData.data) && !rowData.data.length && loadTreeData) { var newTreeLoadingIds = [].concat(_toConsumableArray(treeLoadingIds)); newTreeLoadingIds.push(rowData.__treeId__); this.setState({ treeLoadingIds: newTreeLoadingIds }); var loadedResult = loadTreeData(rowData); var loadedAction = function loadedAction(content) { var _addDataToSelectedRow = _this3.addDataToSelectedRow(content, rowData), tableData = _addDataToSelectedRow.tableData, newRowData = _addDataToSelectedRow.newRowData; _this3.changeTreeExpandState({ tableData: tableData, rowData: newRowData }, cb); }; if ((typeof loadedResult === 'undefined' ? 'undefined' : _typeof(loadedResult)) === 'object' && loadedResult.then) { loadedResult.then(function (content) { loadedAction(content); }); } else { loadedAction(loadedResult); } } else { this.changeTreeExpandState({ rowData: rowData }, cb); } } function addDataInRow(table, treeId, newData) { var tableData = (0, _cloneDeep2['default'])(table.data); var rowPositionArr = treeId.split('-'); var temp = tableData; var index = void 0; var newRowData = void 0; for (var i = 0; i < rowPositionArr.length; i++) { index = rowPositionArr[i]; Eif (i === rowPositionArr.length - 1) { newRowData = temp[index]; newRowData.data = newData; } else { temp = temp[index].data; } } return { tableData: tableData, newRowData: newRowData }; } function addDataToSelectedRow(content, rowData) { var me = this; var _addDataInRow = this.addDataInRow(me.state.data, rowData.__treeId__, content.data), tableData = _addDataInRow.tableData, newRowData = _addDataInRow.newRowData; var processedData = me.addValuesInData({ data: tableData }, 'reset') || {}; return { tableData: processedData, newRowData: newRowData }; } exports['default'] = { addEmptyRow: addEmptyRow, addEmptyRowFromTop: addEmptyRowFromTop, addRow: addRow, addRowFromTop: addRowFromTop, resetRow: resetRow, resetAllRow: resetAllRow, delRow: delRow, editRow: editRow, editAllRow: editAllRow, viewRow: viewRow, viewAllRow: viewAllRow, resetAndViewAllRow: resetAndViewAllRow, saveRow: saveRow, saveAllRow: saveAllRow, toggleSubComp: toggleSubComp, addDataInRow: addDataInRow, addDataToSelectedRow: addDataToSelectedRow, changeTreeExpandState: changeTreeExpandState, toggleTreeExpanded: toggleTreeExpanded, doValidate: doValidate, getData: getData, moveRowUp: moveRowUp, moveRowDown: moveRowDown }; module.exports = exports['default']; |