UNPKG

tplus-pos

Version:

pos module

409 lines (348 loc) 12.8 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _Button3 = require('tinper-bee/dist/Button'); var _Button4 = _interopRequireDefault(_Button3); var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); var _extends2 = require('babel-runtime/helpers/extends'); var _extends3 = _interopRequireDefault(_extends2); var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); var _inherits2 = require('babel-runtime/helpers/inherits'); var _inherits3 = _interopRequireDefault(_inherits2); var _class; require('tinper-bee/dist/Button/index.css'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _mutantsMicrofx = require('mutants-microfx'); require('../textBox/style.less'); var _tplusComponentsTouch = require('tplus-components-touch'); var _pageStores = require('../../../pageStores'); var _beeTable = require('bee-table'); var _beeTable2 = _interopRequireDefault(_beeTable); require('./style.less'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var QuickKey = (0, _mutantsMicrofx.observer)(_class = function (_Component) { (0, _inherits3.default)(QuickKey, _Component); function QuickKey(props, context) { (0, _classCallCheck3.default)(this, QuickKey); console.log("初始化QuickKey"); var _this = (0, _possibleConstructorReturn3.default)(this, (QuickKey.__proto__ || (0, _getPrototypeOf2.default)(QuickKey)).call(this, props, context)); _this.cancel = function () { _pageStores.QuickKeyStore.hide(); _tplusComponentsTouch.Keyboard.close(); }; _this.ok = function () { _pageStores.QuickKeyStore.hide(); _tplusComponentsTouch.Keyboard.close(); }; _this.addTitleForClassificatiion = function (hotKeyConfigList) { if (!hotKeyConfigList || hotKeyConfigList.length == 0) return []; var configList = []; var isHaveUpKey = false; var isHaveDownKey = false; hotKeyConfigList.forEach(function (config, index) { if (config.isdisplay) { config.transKeyValue = undefined; config.transDefaultKeyValue = undefined; var classificationTitle = _tplusComponentsTouch.hotKey.classificationList[config.classification - 1] || ""; var commonIndex = configList.findIndex(function (obj) { return obj.classificationTitle == classificationTitle; }); console.log(commonIndex); //删除多余的上下行 if (config.keyValue === 'up' && !isHaveUpKey || config.keyValue === 'down' && !isHaveDownKey || config.keyValue !== 'down' && config.keyValue !== 'up') { if (config.keyValue === 'up') isHaveUpKey = true; if (config.keyValue === 'down') isHaveDownKey = true; // 替换上下左右键 _tplusComponentsTouch.hotKey.keyReplaceStringList.forEach(function (_ref) { var key = _ref.key, value = _ref.value; if (config.keyValue.indexOf(key.toLocaleLowerCase()) !== -1 || config.DefaultValue.indexOf(key.toLocaleLowerCase()) !== -1) { var newRe = new RegExp(key.toLocaleLowerCase(), "g"); // 替换当前快捷键值 if (config.keyValue !== "pagedown" && config.keyValue !== "pageup") { config.transKeyValue = typeof config.transKeyValue !== "undefined" ? config.transKeyValue.replace(newRe, value) : config.keyValue.replace(newRe, value); } else { config.transKeyValue = config.keyValue; } // 替换默认快捷键值 if (config.DefaultValue !== "pagedown" && config.DefaultValue !== "pageup") { config.transDefaultKeyValue = typeof config.transDefaultKeyValue !== "undefined" ? config.transDefaultKeyValue.replace(newRe, value) : config.DefaultValue.replace(newRe, value); } else { config.transDefaultKeyValue = config.DefaultValue; } } if (config.keyValue === 'up') { config.describe = "上一行"; } if (config.keyValue === 'down') { config.describe = "下一行"; } }); if (typeof config.transKeyValue === "undefined") { config.transKeyValue = config.keyValue; } if (typeof config.transDefaultKeyValue === "undefined") { config.transDefaultKeyValue = config.DefaultValue; } //查找到header位置 if (commonIndex !== -1) { //header位置 + 子节点数量 插入 configList[commonIndex].childrenNumber += 1; configList.splice(configList[commonIndex].childrenNumber + commonIndex, 0, (0, _extends3.default)({}, config, { classificationTitle: classificationTitle, isHeader: false })); } else { configList.push({ classificationTitle: classificationTitle, isHeader: true, describe: '', operation: [''], enableEdit: false, id: new Date().getTime(), childrenNumber: 1 }); configList.push((0, _extends3.default)({ classificationTitle: classificationTitle, isHeader: false }, config)); } } } }); var sortResult = _this.recursionSortHotKeyList(configList); return _this.addOperationTypeByConfigList(sortResult); }; _this.recursionSortHotKeyList = function (configList) { if (configList && configList.length > 0) { // 定义空数组用于接收整理好的数据 var newList = []; // copy var newConfigList = [].concat((0, _toConsumableArray3.default)(configList)); // 获取所有页面Header集合 var headerList = newConfigList.filter(function (config) { return config.isHeader; }); // 按Header拆分 headerList.forEach(function (headerConfig, hndex) { var classByHeaderList = []; newConfigList.forEach(function (config, index) { if (!config.isHeader && config.classificationTitle == headerConfig.classificationTitle) classByHeaderList.push(config); }); var sortedList = _this.newArraySort(classByHeaderList, function (configA, configB) { if (configA.operationType > configB.operationType) return 1; if (configA.TabIndex > configB.TabIndex) return 1; return -1; }); newList = [].concat((0, _toConsumableArray3.default)(newList), [headerConfig], (0, _toConsumableArray3.default)(sortedList)); }); return newList; } return []; }; _this.newArraySort = function (array, fn) { var t = void 0; fn = fn || function (x, y) { return x - y; }; for (var i = 0; i < array.length; i++) { for (var j = i; j < array.length; j++) { if (fn(array[i], array[j]) > 0) { t = array[i]; array[i] = array[j]; array[j] = t; } } } return array; }; _this.addOperationTypeByConfigList = function (configList) { var newList = []; configList.forEach(function (config, index) { var isHeader = config.isHeader, operationType = config.operationType; // 即不是第一个也不是最后一个 if (index != 0 && index != configList.length - 1 && operationType != undefined) { var previous = configList[index - 1]; // 当前所属页面编号与上一个不同则认为当前为所属页面开头 if (!isHeader && previous.operationType != undefined && previous.operationType != operationType || previous.isHeader) { newList.push({ isOperationType: true, OperationTypeName: _tplusComponentsTouch.hotKey.operationTypeName[operationType - 1], isHeader: false, describe: '', operation: [''], enableEdit: false, id: new Date().getTime(), childrenNumber: 1 }); newList.push((0, _extends3.default)({ isHeader: false, isOperationType: false }, config)); } else { newList.push((0, _extends3.default)({ isHeader: false, isOperationType: false }, config)); } } else { newList.push(config); } }); return newList; }; _this.onRowClass = function (record) { var isHeader = record.isHeader, isOperationType = record.isOperationType; if (isHeader) { return 't_set_table_header_back'; } if (isOperationType) { return 't_set_table_operation_header_back'; } return 't_set_table'; }; _this.state = { focus: false }; return _this; } (0, _createClass3.default)(QuickKey, [{ key: 'componentDidMount', // 弹出快捷键说明 value: function componentDidMount() { _pageStores.QuickKeyStore.onShow(function () { var isReaded = localStorage.getItem("QUICK_KEY_UPDATED_READING"); if (isReaded == null) { _tplusComponentsTouch.ModalWraper.info({ className: 'tplus-confirm-quickkey', title: "温馨提示", content: '本次升级可能导致您原来设置的快捷键被修改,请检查并重新设置!', cancelable: false, onOk: function onOk() {} }); localStorage.setItem("QUICK_KEY_UPDATED_READING", 1); } }); } }, { key: 'render', value: function render() { var _this2 = this; var visible = _pageStores.QuickKeyStore.visible; if (!visible) return null; var ds = this.addTitleForClassificatiion(window.defineHotKeyConfigList); var columns = [{ title: '功能类别', dataIndex: 'classification', key: 'classification', width: "18%", render: function render(text, record) { var _ref2 = record || {}, classificationTitle = _ref2.classificationTitle, isHeader = _ref2.isHeader; return isHeader ? _react2.default.createElement( 'span', { className: "quick-key-edit-header" }, classificationTitle || "" ) : ""; } }, { title: '所属页面', dataIndex: 'isOperationType', width: "25%", render: function render(text, record) { var _ref3 = record || {}, OperationTypeName = _ref3.OperationTypeName, isHeader = _ref3.isHeader, isOperationType = _ref3.isOperationType; return !isHeader && isOperationType ? _react2.default.createElement( 'span', { className: "quick-key-edit-header" }, OperationTypeName || "" ) : ""; } }, { title: '功能键名称', dataIndex: 'describe', key: 'describe', width: "26%", render: function render(text, record) { var _ref4 = record || {}, describe = _ref4.describe, isHeader = _ref4.isHeader, isOperationType = _ref4.isOperationType; return isHeader || isOperationType ? "" : describe || ""; } }, { title: '快捷键', dataIndex: 'keyValue', key: 'keyValue', width: "26%", render: function render(text, record) { var _ref5 = record || {}, transKeyValue = _ref5.transKeyValue, isHeader = _ref5.isHeader, isOperationType = _ref5.isOperationType; return isHeader || isOperationType ? "" : transKeyValue.toLocaleUpperCase() || ""; } }]; return _react2.default.createElement( _tplusComponentsTouch.ModalWraper, { show: visible, animation: true, className: 'quickKey-modal', width: 800, title: "快捷键", onHide: this.cancel, footer: _react2.default.createElement( 'div', null, _react2.default.createElement( _Button4.default, { type: 'cancel', onClick: this.cancel }, '\u53D6\u6D88' ), _react2.default.createElement( _Button4.default, { type: 'success', onClick: this.ok }, '\u786E\u5B9A' ) ) }, _react2.default.createElement( 'div', { className: 'tab tab2', ref: function ref(dom) { return _this2.tab2Dom = dom; } }, _react2.default.createElement( 'div', { className: 'table' }, _react2.default.createElement(_beeTable2.default, { rowKey: function rowKey(record) { return record.id; }, columns: columns, data: ds, className: '', rowClassName: function rowClassName(record) { return _this2.onRowClass(record); } }) ) ) ); } }]); return QuickKey; }(_react.Component)) || _class; exports.default = QuickKey; //# sourceMappingURL=index.js.map