UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

447 lines (446 loc) 22.9 kB
"use strict"; 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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); 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 __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TitleIcon = void 0; var react_1 = __importDefault(require("react")); var mobx_react_1 = require("mobx-react"); var mobx_1 = require("mobx"); var lodash_1 = require("lodash"); var pandora_app_component_1 = require("@qn-pandora/pandora-app-component"); var login_1 = require("@qn-pandora/app-sdk/es/apis/login"); var app_sdk_1 = require("@qn-pandora/app-sdk"); var pandora_component_1 = require("@qn-pandora/pandora-component"); var errorBoundary_1 = __importDefault(require("../../../../../hocs/errorBoundary")); var BasicComponent_1 = __importDefault(require("../../../../Base/BasicComponent")); var Common_1 = require("../../../../Common"); var metric_panel_style_1 = require("../../../../../constants/metric-panel-style"); var bind_1 = __importDefault(require("../../../../../utils/bind")); var language_1 = require("../../../../../services/language"); var conatsnts_1 = require("../conatsnts"); var toaster_1 = __importDefault(require("../../../../../services/base/toaster")); var type_1 = require("../../../../../constants/language/other/type"); var style = __importStar(require("./style.mless")); var Item = Common_1.Form.Item; var Delete = pandora_app_component_1.RowManager.Delete, Add = pandora_app_component_1.RowManager.Add; var TitleIcon = /** @class */ (function (_super) { __extends(TitleIcon, _super); function TitleIcon() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.name = ''; return _this; } Object.defineProperty(TitleIcon.prototype, "fieldsSelectOptions", { get: function () { return this.props.dataset.fields.map(function (e) { return e.key; }); }, enumerable: false, configurable: true }); Object.defineProperty(TitleIcon.prototype, "fields", { get: function () { var currentBuckets = this.props.chartStyleService.currentBuckets; var _a = this.props.dataset, fields = _a.fields, rows = _a.rows; var bucketIndexs = currentBuckets.map(function (b) { return lodash_1.findIndex(fields, function (f) { return f.key === b; }); }); if (bucketIndexs.length === 0) { return []; } var bucketIndex = bucketIndexs[0]; var result = []; rows.forEach(function (row) { var value = row[bucketIndex][0]; result.push({ value: value, text: value }); }); return result; }, enumerable: false, configurable: true }); Object.defineProperty(TitleIcon.prototype, "colorType", { get: function () { var chartStyleService = this.props.chartStyleService; var color = chartStyleService.titleIcon.color; return lodash_1.get(color, 'type'); }, enumerable: false, configurable: true }); Object.defineProperty(TitleIcon.prototype, "width", { get: function () { var chartStyleService = this.props.chartStyleService; var width = chartStyleService.titleIcon.width; return width; }, enumerable: false, configurable: true }); Object.defineProperty(TitleIcon.prototype, "field", { get: function () { var chartStyleService = this.props.chartStyleService; var color = chartStyleService.titleIcon.color; return lodash_1.get(color, 'field'); }, enumerable: false, configurable: true }); Object.defineProperty(TitleIcon.prototype, "icon", { get: function () { var chartStyleService = this.props.chartStyleService; var icon = chartStyleService.titleIcon.icon; return icon; }, enumerable: false, configurable: true }); Object.defineProperty(TitleIcon.prototype, "open", { get: function () { var chartStyleService = this.props.chartStyleService; var open = chartStyleService.titleIcon.open; return open; }, enumerable: false, configurable: true }); Object.defineProperty(TitleIcon.prototype, "titles", { get: function () { var chartStyleService = this.props.chartStyleService; var titles = chartStyleService.titleIcon.titles; return titles || []; }, enumerable: false, configurable: true }); Object.defineProperty(TitleIcon.prototype, "placeholder", { get: function () { return this.colorType === metric_panel_style_1.ETitleIconColor.Field ? language_1.formatString(type_1.OtherLocale.metric.title_icon.color.placeholder_field) : language_1.formatString(type_1.OtherLocale.metric.title_icon.color.placeholder_system); }, enumerable: false, configurable: true }); Object.defineProperty(TitleIcon.prototype, "colorOptions", { get: function () { return conatsnts_1.colorOptions.map(function (option) { return { value: option.value, text: (react_1.default.createElement("div", { className: style.option }, react_1.default.createElement(pandora_app_component_1.ColorBlock, { colors: conatsnts_1.colorMap[option.value].slice(0, 6), className: style.colorBlock }), react_1.default.createElement("span", { className: style.text }, language_1.formatString(option.text)))) }; }); }, enumerable: false, configurable: true }); TitleIcon.prototype.setName = function (name) { this.name = name; }; TitleIcon.prototype.handleColorChange = function (key, value) { var titleIcon = this.props.chartStyleService.titleIcon; this.handleTitleIconChange('color', key === 'type' ? __assign(__assign({}, titleIcon.color), { type: value, field: '' }) : __assign(__assign({}, titleIcon.color), { field: value })); }; TitleIcon.prototype.handleTitleIconChange = function (key, value) { var _a; var _b = this.props.chartStyleService, setTitleColor = _b.setTitleColor, titleIcon = _b.titleIcon; setTitleColor(__assign(__assign({}, titleIcon), (_a = {}, _a[key] = value, _a))); }; TitleIcon.prototype.getUseName = function () { return __awaiter(this, void 0, void 0, function () { var username; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, login_1.getUserInfo()]; case 1: username = (_a.sent()).username; this.setName(username); return [2 /*return*/]; } }); }); }; TitleIcon.prototype.handleTitleChange = function (title, index) { var _a = this.props.chartStyleService.titleIcon.titles, titles = _a === void 0 ? [] : _a; var data = __spread((titles || [])); data[index] = title; this.handleTitleIconChange('titles', data); }; TitleIcon.prototype.handleAddTitle = function () { var _a = this.props.chartStyleService.titleIcon.titles, titles = _a === void 0 ? [] : _a; var colors = this.field ? conatsnts_1.colorMap[this.field] : []; this.handleTitleIconChange('titles', __spread(titles, [ { field: '', color: colors[titles.length % colors.length] || '' } ])); }; TitleIcon.prototype.handleDeleteTitle = function (index) { var _a = this.props.chartStyleService.titleIcon.titles, titles = _a === void 0 ? [] : _a; var data = __spread(titles); data.splice(index, 1); this.handleTitleIconChange('titles', data); }; TitleIcon.prototype.componentDidMount = function () { this.getUseName(); }; TitleIcon.prototype.render = function () { var _this = this; return (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement(Item, __assign({ label: language_1.formatString(type_1.OtherLocale.metric.title_icon.label) }, conatsnts_1.formItemLayout), react_1.default.createElement(Common_1.SolidRadioGroup, { options: conatsnts_1.OpenOptions, value: this.open, onChange: function (value) { _this.handleTitleIconChange('open', value); } })), this.open && (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement(Item, __assign({ label: language_1.formatString(type_1.OtherLocale.metric.title_icon.color.label) }, conatsnts_1.formItemLayout), react_1.default.createElement("div", { className: style.color }, react_1.default.createElement(Common_1.Selector, { placeholder: language_1.formatString(type_1.OtherLocale.metric.title_icon.color.type), value: this.colorType, onChange: function (value) { _this.handleColorChange('type', value); }, className: style.colorType, options: conatsnts_1.ColorTypes }), this.colorType === metric_panel_style_1.ETitleIconColor.Field ? (react_1.default.createElement(Common_1.Selector, { placeholder: this.placeholder, value: this.field, onChange: function (value) { _this.handleColorChange('field', value); }, options: this.fieldsSelectOptions, showSearch: true })) : (react_1.default.createElement(Common_1.Selector, { value: this.field, onChange: function (value) { _this.handleColorChange('field', value); }, options: this.colorOptions })))), react_1.default.createElement(Item, __assign({}, conatsnts_1.formItemLayout, { label: language_1.formatString(type_1.OtherLocale.metric.title_icon.icon) }), react_1.default.createElement(pandora_app_component_1.UploaderImage, { action: app_sdk_1.appEnv.getApiPrefix() + "/setting/image", width: "70px", height: "70px", hideUploadText: true, hideNote: true, value: this.icon, imagePrefix: this.name + "_metric_panel_chart", onChange: function (icon) { _this.handleTitleIconChange('icon', icon); }, hideAddIcon: true })), react_1.default.createElement(Item, __assign({}, conatsnts_1.formItemLayout, { label: language_1.formatString(type_1.OtherLocale.metric.title_icon.width) }), react_1.default.createElement(pandora_component_1.InputNumber, { value: this.width, onChange: function (width) { _this.handleTitleIconChange('width', width); } })), this.open && this.colorType === metric_panel_style_1.ETitleIconColor.System && (react_1.default.createElement(Item, __assign({}, conatsnts_1.formItemLayout, { label: language_1.formatString(type_1.OtherLocale.metric.title_icon.title) }), this.titles.map(function (title, index) { return (react_1.default.createElement(react_1.default.Fragment, null, react_1.default.createElement("div", { className: style.addonAfter }, react_1.default.createElement(pandora_component_1.AutoComplete, { value: title.field, onChange: function (field) { _this.handleTitleChange(__assign(__assign({}, title), { field: field }), index); }, dataSource: _this.fields, getPopupContainer: _this.props.getPopupContainer }), react_1.default.createElement(pandora_app_component_1.ColorPicker, { presetColors: _this.field ? conatsnts_1.colorMap[_this.field] : [], value: title.color, onChange: function (color) { _this.handleTitleChange(__assign(__assign({}, title), { color: color }), index); } }), react_1.default.createElement(pandora_app_component_1.UploaderImage, { action: app_sdk_1.appEnv.getApiPrefix() + "/setting/image", width: "32px", height: "32px", hideUploadText: true, hideNote: true, value: title.icon, imagePrefix: _this.name + "_metric_panel_chart", hideAddIcon: true, onChange: function (icon) { _this.handleTitleChange(__assign(__assign({}, title), { icon: icon }), index); } }), react_1.default.createElement(Delete, { onClick: function () { _this.handleDeleteTitle(index); } })))); }), react_1.default.createElement(Add, { text: language_1.formatString(type_1.OtherLocale.metric.title_icon.add), className: style.add, onClick: this.handleAddTitle }))))))); }; __decorate([ mobx_1.observable, __metadata("design:type", String) ], TitleIcon.prototype, "name", void 0); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "fieldsSelectOptions", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "fields", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "colorType", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "width", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "field", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "icon", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "open", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "titles", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "placeholder", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "colorOptions", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "setName", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "handleColorChange", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "handleTitleIconChange", null); __decorate([ bind_1.default, toaster_1.default.handle(''), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], TitleIcon.prototype, "getUseName", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Number]), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "handleTitleChange", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "handleAddTitle", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "handleDeleteTitle", null); TitleIcon = __decorate([ mobx_react_1.observer ], TitleIcon); return TitleIcon; }(BasicComponent_1.default)); exports.TitleIcon = TitleIcon; exports.default = errorBoundary_1.default(TitleIcon);