UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

330 lines (329 loc) 14 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; import { computed, reaction } from 'mobx'; import { get, isNil, isNumber, isUndefined, findIndex, toString } from 'lodash'; import bind from '../../../utils/bind'; import BaseChartStore from '../stores/base'; var BaseTableStore = /** @class */ (function (_super) { __extends(BaseTableStore, _super); function BaseTableStore(getProps) { var _this = _super.call(this, getProps) || this; /** * 表格数据显示、样式form表单都依赖于dataset, 特加此reaction。 * 渲染了数据后设置column和DataSource到chartStyleService */ _this.addDisposer(reaction(function () { return _this.dataset; }, function (dataset) { var _a = _this.getInitTableData(dataset), columns = _a.columns, dataSource = _a.dataSource; var _b = _this.chartStyleService, setColumns = _b.setColumns, setDataSource = _b.setDataSource; setColumns(columns); setDataSource(dataSource); }, { fireImmediately: true })); return _this; } Object.defineProperty(BaseTableStore.prototype, "filters", { get: function () { return this.chartStyleService.filterColumns .filter(function (item) { return item.checked && item.filters; }) .map(function (item) { return ({ key: item.dataIndex, value: item.filters }); }); }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "baseDataSource", { get: function () { return this.chartStyleService.dataSource; }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "tableData", { get: function () { var _this = this; if (!this.filters.length) { return this.baseDataSource; } var newData = []; this.baseDataSource.forEach(function (item) { var e_1, _a; var isAdd = true; var _loop_1 = function (filter) { if (filter.value.length > 0) { var index = findIndex(filter.value, function (value) { return toString(value) === toString(item[filter.key].current); }); if (index === -1) { isAdd = false; return "break"; } } }; try { for (var _b = __values(_this.filters), _c = _b.next(); !_c.done; _c = _b.next()) { var filter = _c.value; var state_1 = _loop_1(filter); if (state_1 === "break") break; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } if (isAdd) { newData.push(item); } }); return newData; }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "renderColumns", { get: function () { var _a; // 下钻后,新的数据需要全部checked // 非下钻数据变更的时候,如果有配置项,按照配置项的,无配置项则为全部选中 var isInDrillDown = (_a = this.chartActionService) === null || _a === void 0 ? void 0 : _a.drillDownActionService.isInDrillDown; var _b = this.chartStyleService, filterColumns = _b.filterColumns, hasColumnsConfig = _b.hasColumnsConfig; var checked = isInDrillDown ? true : !hasColumnsConfig; var renderColumns = []; filterColumns.forEach(function (item) { var realChecked = isNil(item.checked) ? checked : item.checked; if (realChecked) { renderColumns.push(__assign(__assign({}, item), { checked: true })); } }); return renderColumns; }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "chartDataset", { get: function () { return this.dataset; }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "showPagination", { get: function () { return this.chartStyleService.pagination; }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "pagination", { get: function () { var total = this.tableData.length; var _a = this.chartStyleService, tablePageSize = _a.tablePageSize, pagination = _a.pagination; var pageSize = pagination ? tablePageSize : total; return { size: 'default', total: total, pageSize: pageSize, simple: true }; }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "bordered", { get: function () { var border = this.chartStyleService.bordered; return isUndefined(border) ? get(this.themeOption, ['table', 'border', 'show']) : border; }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "tableTitleFont", { get: function () { return this.chartStyleService.tableTitleFont; }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "tableTitleBgColor", { get: function () { return this.chartStyleService.tableTitleBgColor; }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "pageScroll", { get: function () { return this.chartStyleService.scroll; }, enumerable: false, configurable: true }); Object.defineProperty(BaseTableStore.prototype, "autoplaySpeed", { get: function () { return this.chartStyleService.autoplaySpeed; }, enumerable: false, configurable: true }); BaseTableStore.prototype.getSortFunction = function (key) { return { ascend: function (a, b) { return (get(a, [key, 'current']) || 0) - (get(b, [key, 'current']) || 0); }, descend: function (a, b) { return (get(b, [key, 'current']) || 0) - (get(a, [key, 'current']) || 0); } }; }; BaseTableStore.prototype.onSettingChange = function (fields) { var _a; var _b = this.chartStyleService, filterColumns = _b.filterColumns, setFilterColumns = _b.setFilterColumns, hasColumnsConfig = _b.hasColumnsConfig; var isInDrillDown = (_a = this.chartActionService) === null || _a === void 0 ? void 0 : _a.drillDownActionService.isInDrillDown; var checked = isInDrillDown ? true : !hasColumnsConfig; setFilterColumns(filterColumns.map(function (col) { var _a; var realChecked = isNil(col.checked) ? checked : col.checked; var width = ((_a = fields.find(function (item) { return item.field === col.dataIndex; })) === null || _a === void 0 ? void 0 : _a.width) || col.width; return __assign(__assign({}, col), { width: isNumber(width) && width < 120 ? 120 : width, checked: realChecked }); })); }; BaseTableStore.prototype.onColumnsFiltersChange = function (filters) { var _a; var _b = this.chartStyleService, filterColumns = _b.filterColumns, setFilterColumns = _b.setFilterColumns, hasColumnsConfig = _b.hasColumnsConfig; var isInDrillDown = (_a = this.chartActionService) === null || _a === void 0 ? void 0 : _a.drillDownActionService.isInDrillDown; var checked = isInDrillDown ? true : !hasColumnsConfig; setFilterColumns(filterColumns.map(function (col) { var realChecked = isNil(col.checked) ? checked : col.checked; var index = filters.findIndex(function (filterValue) { return filterValue.key === col.dataIndex; }); if (index !== -1) { return __assign(__assign({}, col), { checked: realChecked, filters: filters[index].value }); } return __assign(__assign({}, col), { checked: realChecked, filters: [] }); })); }; __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "filters", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "baseDataSource", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "tableData", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "renderColumns", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "chartDataset", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "showPagination", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "pagination", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "bordered", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "tableTitleFont", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "tableTitleBgColor", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "pageScroll", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], BaseTableStore.prototype, "autoplaySpeed", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], BaseTableStore.prototype, "getSortFunction", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], BaseTableStore.prototype, "onSettingChange", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], BaseTableStore.prototype, "onColumnsFiltersChange", null); return BaseTableStore; }(BaseChartStore)); export default BaseTableStore;