UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

422 lines (421 loc) 20.7 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 __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; }; import React from 'react'; import { observer } from 'mobx-react'; import { action, computed, observable } from 'mobx'; import { findIndex, get } from 'lodash'; import { ColorPicker, UploaderImage, RowManager, ColorBlock } from '@qn-pandora/pandora-app-component'; import { getUserInfo } from '@qn-pandora/app-sdk/es/apis/login'; import { appEnv } from '@qn-pandora/app-sdk'; import { AutoComplete, InputNumber } from '@qn-pandora/pandora-component'; import errorBoundary from '../../../../../hocs/errorBoundary'; import BasicComponent from '../../../../Base/BasicComponent'; import { Form, Selector, SolidRadioGroup } from '../../../../Common'; import { ETitleIconColor } from '../../../../../constants/metric-panel-style'; import bind from '../../../../../utils/bind'; import { formatString } from '../../../../../services/language'; import { OpenOptions, colorOptions, colorMap, ColorTypes, formItemLayout } from '../conatsnts'; import toaster from '../../../../../services/base/toaster'; import { OtherLocale } from '../../../../../constants/language/other/type'; import * as style from './style.mless'; var Item = Form.Item; var Delete = RowManager.Delete, Add = 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 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 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 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 === ETitleIconColor.Field ? formatString(OtherLocale.metric.title_icon.color.placeholder_field) : formatString(OtherLocale.metric.title_icon.color.placeholder_system); }, enumerable: false, configurable: true }); Object.defineProperty(TitleIcon.prototype, "colorOptions", { get: function () { return colorOptions.map(function (option) { return { value: option.value, text: (React.createElement("div", { className: style.option }, React.createElement(ColorBlock, { colors: colorMap[option.value].slice(0, 6), className: style.colorBlock }), React.createElement("span", { className: style.text }, 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*/, 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 ? 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.createElement(React.Fragment, null, React.createElement(Item, __assign({ label: formatString(OtherLocale.metric.title_icon.label) }, formItemLayout), React.createElement(SolidRadioGroup, { options: OpenOptions, value: this.open, onChange: function (value) { _this.handleTitleIconChange('open', value); } })), this.open && (React.createElement(React.Fragment, null, React.createElement(Item, __assign({ label: formatString(OtherLocale.metric.title_icon.color.label) }, formItemLayout), React.createElement("div", { className: style.color }, React.createElement(Selector, { placeholder: formatString(OtherLocale.metric.title_icon.color.type), value: this.colorType, onChange: function (value) { _this.handleColorChange('type', value); }, className: style.colorType, options: ColorTypes }), this.colorType === ETitleIconColor.Field ? (React.createElement(Selector, { placeholder: this.placeholder, value: this.field, onChange: function (value) { _this.handleColorChange('field', value); }, options: this.fieldsSelectOptions, showSearch: true })) : (React.createElement(Selector, { value: this.field, onChange: function (value) { _this.handleColorChange('field', value); }, options: this.colorOptions })))), React.createElement(Item, __assign({}, formItemLayout, { label: formatString(OtherLocale.metric.title_icon.icon) }), React.createElement(UploaderImage, { action: 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.createElement(Item, __assign({}, formItemLayout, { label: formatString(OtherLocale.metric.title_icon.width) }), React.createElement(InputNumber, { value: this.width, onChange: function (width) { _this.handleTitleIconChange('width', width); } })), this.open && this.colorType === ETitleIconColor.System && (React.createElement(Item, __assign({}, formItemLayout, { label: formatString(OtherLocale.metric.title_icon.title) }), this.titles.map(function (title, index) { return (React.createElement(React.Fragment, null, React.createElement("div", { className: style.addonAfter }, React.createElement(AutoComplete, { value: title.field, onChange: function (field) { _this.handleTitleChange(__assign(__assign({}, title), { field: field }), index); }, dataSource: _this.fields, getPopupContainer: _this.props.getPopupContainer }), React.createElement(ColorPicker, { presetColors: _this.field ? colorMap[_this.field] : [], value: title.color, onChange: function (color) { _this.handleTitleChange(__assign(__assign({}, title), { color: color }), index); } }), React.createElement(UploaderImage, { action: 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.createElement(Delete, { onClick: function () { _this.handleDeleteTitle(index); } })))); }), React.createElement(Add, { text: formatString(OtherLocale.metric.title_icon.add), className: style.add, onClick: this.handleAddTitle }))))))); }; __decorate([ observable, __metadata("design:type", String) ], TitleIcon.prototype, "name", void 0); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "fieldsSelectOptions", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "fields", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "colorType", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "width", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "field", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "icon", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "open", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "titles", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "placeholder", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TitleIcon.prototype, "colorOptions", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "setName", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "handleColorChange", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "handleTitleIconChange", null); __decorate([ bind, toaster.handle(''), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], TitleIcon.prototype, "getUseName", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Number]), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "handleTitleChange", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "handleAddTitle", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], TitleIcon.prototype, "handleDeleteTitle", null); TitleIcon = __decorate([ observer ], TitleIcon); return TitleIcon; }(BasicComponent)); export { TitleIcon }; export default errorBoundary(TitleIcon);