UNPKG

micro-ui-y

Version:

128 lines (115 loc) 4.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectAll = exports.selectItem = exports.selectFlag = exports.gridRows = undefined; var _index = require("../constants/index"); var actionTypes = _interopRequireWildcard(_index); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } //渲染的条数 [] 删除后仍然占位 0 var gridRows = function gridRows() { var gridRows = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { "default": [] }; var action = arguments[1]; switch (action.type) { case actionTypes.add_rows: gridRows = Object.assign({}, gridRows); if (!gridRows[action.gridType]) { gridRows[action.gridType] = []; } gridRows[action.gridType].push(new Date().getTime()); return gridRows; case actionTypes.del_rows: gridRows = Object.assign({}, gridRows); var _selectItem = action.selectItem; for (var i = 0; i < gridRows[action.gridType].length; i++) { if (_selectItem.includes(gridRows[action.gridType][i])) { gridRows[action.gridType].splice(i, 1, 0); } } return gridRows; case actionTypes.copy_rows: gridRows = Object.assign({}, gridRows); gridRows[action.gridType] = action.newGetTimeValue; return gridRows; case actionTypes.edit_rows: gridRows = Object.assign({}, gridRows); gridRows[action.gridType] = action.editRowsGetTimeValue; return gridRows; default: return gridRows; } }; //是否有复选框 true false var selectFlag = function selectFlag() { var selectFlag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { "default": true }; var action = arguments[1]; switch (action.type) { case actionTypes.set_select_flag: selectFlag = Object.assign({}, selectFlag); selectFlag[action.gridType] = action.flag; return selectFlag; default: return selectFlag; } }; //复选后的值 [] var selectItem = function selectItem() { var selectItem = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { "default": [] }; var action = arguments[1]; switch (action.type) { case actionTypes.getTime_value: selectItem = Object.assign({}, selectItem); if (!selectItem[action.gridType]) { selectItem[action.gridType] = []; } if (selectItem[action.gridType].includes(action.getTimeValue)) { var index = selectItem[action.gridType].indexOf(action.getTimeValue); if (index > -1) { selectItem[action.gridType].splice(index, 1); } } else { selectItem[action.gridType].push(action.getTimeValue); } selectItem[action.gridType].sort(); return selectItem; case actionTypes.getTime_all: selectItem = Object.assign({}, selectItem); var getTimeValue = [].concat(action.getTimeValue); if (!selectItem[action.gridType]) { selectItem[action.gridType] = []; } if (action.flag == "all") { selectItem[action.gridType] = getTimeValue; // gridRows } else { selectItem[action.gridType] = []; // gridRows } selectItem[action.gridType].sort(); return selectItem; case actionTypes.getTime_del: selectItem = Object.assign({}, selectItem); selectItem[action.gridType] = []; return selectItem; default: return selectItem; } }; //是否全选 true false var selectAll = function selectAll() { var selectAll = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { "default": false }; var action = arguments[1]; switch (action.type) { case actionTypes.set_select_all: selectAll = Object.assign({}, selectAll); selectAll[action.gridType] = action.flag == "all" ? true : false; return selectAll; default: return selectAll; } }; exports.gridRows = gridRows; exports.selectFlag = selectFlag; exports.selectItem = selectItem; exports.selectAll = selectAll; //# sourceMappingURL=grid.js.map