UNPKG

@cainiaofe/cn-ui-charts

Version:
210 lines (208 loc) 7.25 kB
import _extends from "@babel/runtime/helpers/extends"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; var _window; import React from 'react'; var _ref = ((_window = window) === null || _window === void 0 ? void 0 : _window.VisualEngineUtils) || {}, SelectControl = _ref.SelectControl; import "./index.scss"; import { getDataSourceList } from "../../util/util"; var DataSourceSetter = /*#__PURE__*/function (_React$Component) { _inheritsLoose(DataSourceSetter, _React$Component); function DataSourceSetter() { var _this; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this; // // 组件属性 // static defaultProps = { // initBind:false, // }; _this.state = { dataSourceList: [] }; // // select = (value) => { // const { prop } = this.props; // prop.getNode().setPropValue(prop.getName(), { // type: "JSExpression", // value: `this.dataSource.getDataSource('${value}')` // }); // }; // getDsName = () => { // const { prop } = this.props; // const origin = prop.getNode().getPropValue(prop.getName()) || this.props.value; // let value = ""; // const variable = origin && (origin.value || origin.variable); // if (origin && variable) { // value = variable.slice(variable.indexOf("'") + 1, variable.lastIndexOf("'")); // } // return value; // }; // // // 获取默认的Form/TableQueryForm数据源 // getFormDefaultDataSource = () => { // const { prop } = this.props; // const selected = prop.getNode(); // const { dataSourceList } = this.state; // // const selectedNodeId = selected.id; // const dataSourceManager = Engine.context.getManager("EpochDataSource") as DataSourceManager; // // const { dataSourceName /* uuid, componentName */ } = dataSourceManager.getDataSourceInfoByNode(selected); // let defaultFormDataSourceName = null; // const initBind = this.isInitBindDataSource(prop); // if (initBind) { // dataSourceList.forEach((item) => { // if (item.value === dataSourceName) { // defaultFormDataSourceName = item.value; // } // }); // } // if (defaultFormDataSourceName) { // this.select(defaultFormDataSourceName); // } // return defaultFormDataSourceName; // }; // // isInitBindDataSource(prop: any = {}) { // // const selected = prop.getNode(); // if ( // selected.componentName === "Form" || // selected.componentName === "TableQueryForm" || // selected.componentName === "OMSTableQueryForm" || // selected.componentName === "OMSFormDialog" || // selected.componentName === "OMSFormEmbed" || // selected.componentName === "DetailBlock" || // selected.componentName === "DetailContainer" || // selected.componentName === 'EpochTableQueryForm' || // selected.componentName === "OMSDetail" // ) { // return true; // } // // const initBind = prop?._config?.setter?.props?.initBind; // // if(initBind) { // return true; // } // // return false; // } _this.select = function (value) { var prop = _this.props.prop; try { prop.getNode().setPropValue(prop.getName(), { type: 'variable', variable: "state." + value }); // prop.setVariableValue({ // type: "variable", // variable: `state.${value}`, // }) // prop.setHotValue({ // type: "variable", // variable: `state.${value}`, // }) } catch (e) {} }; _this.getDsName = function () { var value = ''; var prop = _this.props.prop; try { // const dsExpr = prop.getNode().getPropValue(prop.getName()) var dsExpr = prop.getHotValue(); var variableStr = prop.getVariableValue(); if (dsExpr && dsExpr.type === 'variable' && dsExpr.variable) { value = dsExpr.variable.slice(dsExpr.variable.lastIndexOf('.') + 1); } else if (variableStr) { value = variableStr.slice(variableStr.lastIndexOf('.') + 1); } } catch (e) { console.log('error'); } return value; }; return _this; } var _proto = DataSourceSetter.prototype; _proto.componentDidMount = function componentDidMount() {} // createDataSource = (dataSourceList) =>{ // // Engine.Pages.currentPage.ctx.managerMap.dataPool.addItem({description: "", // // dpType: "VALUE", // // id: "", // // initialData: "", // // isGlobal: false, // // name: "dp33", // // protocal: "VALUE"}) // const { initBind, prop, selected = {} } = this.props; // const { componentName } = selected // if(initBind && componentName && dataSourceList.length > 0) { // const first = dataSourceList.find(item=>item.value === `${componentName}`); // let index = ''; // if(first) { // index = this.generateIndex(dataSourceList,componentName); // } // const componentPrototype = Trunk?.getPrototype(componentName); // const dataSource = Engine?.context?.getManager('dataPool'); // const ds = dataSource?.addItem({ // description: `${componentPrototype?.options?.title || componentName}${index}的数据源`, // dpType: "VALUE", // id: "", // initialData: "", // isGlobal: false, // name: `${componentName}${index}`, // protocal: "VALUE", // }) // if(ds && ds.name) { // this.select(ds.name); // } // return ds.name; // } // } ; _proto.componentWillMount = function componentWillMount() { var _this2 = this; var prop = this.props.prop; // 监听 this.willDetach = prop.onValueChange(function () { return _this2.forceUpdate(); }); }; _proto.componentWillUnmount = function componentWillUnmount() { // 卸载监听 this.willDetach && this.willDetach(); }; _proto.render = function render() { var _this$props = this.props, prop = _this$props.prop, selected = _this$props.selected; // let dsName = prop.value; var dataSourceList = []; var dsName = this.getDsName(); if (!dsName) { // dataSourceList = this.getDataSourceList(); // dsName = this.createDataSource(dataSourceList) } dataSourceList = getDataSourceList({ typeList: ['VALUE'] }); if (Array.isArray(dataSourceList)) { dataSourceList = dataSourceList.map(function (item) { var newLabel = item.label + " (" + item.value + ")"; return _extends({}, item, { label: newLabel, text: newLabel }); }); } return /*#__PURE__*/React.createElement(SelectControl, { readOnly: true, options: dataSourceList, value: dsName, onChange: this.select }); }; return DataSourceSetter; }(React.Component); export default DataSourceSetter;