@zgfe/business-lib 1.1.66 → 1.1.67-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/es/assets/iconfont/demo_index.html +118 -3
  2. package/es/assets/iconfont/iconfont.css +23 -3
  3. package/es/assets/iconfont/iconfont.js +1 -1
  4. package/es/assets/iconfont/iconfont.json +35 -0
  5. package/es/assets/iconfont/iconfont.ttf +0 -0
  6. package/es/assets/iconfont/iconfont.woff +0 -0
  7. package/es/assets/iconfont/iconfont.woff2 +0 -0
  8. package/es/assets/styles/chunks.less +18 -0
  9. package/es/assets/styles/variable.less +1 -0
  10. package/es/attrCondition/group.d.ts +2 -2
  11. package/es/attrCondition/group.js +10 -6
  12. package/es/attrCondition/index.js +43 -7
  13. package/es/attrCondition/styles/index.less +23 -7
  14. package/es/attrCondition/useAttrCondition.d.ts +3 -1
  15. package/es/attrCondition/useAttrCondition.js +2 -1
  16. package/es/attrCondition/useConditionGroup.js +14 -3
  17. package/es/attrConditions/components/stringList.d.ts +1 -0
  18. package/es/attrConditions/components/stringList.js +1 -0
  19. package/es/attrConditions/components/valuesList.d.ts +1 -0
  20. package/es/attrConditions/components/valuesList.js +6 -1
  21. package/es/attrConditions/index.js +4 -2
  22. package/es/attrConditions/types.d.ts +1 -0
  23. package/es/attributeSelector/demo/disable.js +6 -1
  24. package/es/attributeSelector/index.js +8 -13
  25. package/es/attributeSelector/styles/index.less +8 -19
  26. package/es/attributeSelector/types.d.ts +2 -1
  27. package/es/context/index.d.ts +4 -0
  28. package/es/context/index.js +2 -1
  29. package/es/eventSelector/index.js +0 -1
  30. package/es/eventSelector/listPanel.d.ts +10 -0
  31. package/es/eventSelector/listPanel.js +9 -9
  32. package/es/eventSelector/option.js +5 -2
  33. package/es/formulaTarget/components/formula/data.d.ts +16 -0
  34. package/es/formulaTarget/components/formula/data.js +40 -0
  35. package/es/formulaTarget/components/formula/demo.d.ts +2 -0
  36. package/es/formulaTarget/components/formula/demo.js +76 -0
  37. package/es/formulaTarget/components/formula/index.d.ts +6 -0
  38. package/es/formulaTarget/components/formula/index.js +132 -0
  39. package/es/formulaTarget/components/formula/index.less +68 -0
  40. package/es/formulaTarget/components/formula/types.d.ts +24 -0
  41. package/es/formulaTarget/components/formula/types.js +1 -0
  42. package/es/formulaTarget/components/formula/util.d.ts +28 -0
  43. package/es/formulaTarget/components/formula/util.js +245 -0
  44. package/es/formulaTarget/components/formulaItem/data.d.ts +2 -0
  45. package/es/formulaTarget/components/formulaItem/data.js +4 -0
  46. package/es/formulaTarget/components/formulaItem/index.d.ts +4 -0
  47. package/es/formulaTarget/components/formulaItem/index.js +190 -0
  48. package/es/formulaTarget/components/formulaItem/types.d.ts +10 -0
  49. package/es/formulaTarget/components/formulaItem/types.js +1 -0
  50. package/es/formulaTarget/components/panel/data.d.ts +8 -0
  51. package/es/formulaTarget/components/panel/data.js +32 -0
  52. package/es/formulaTarget/components/panel/demo.d.ts +2 -0
  53. package/es/formulaTarget/components/panel/demo.js +59 -0
  54. package/es/formulaTarget/components/panel/index.d.ts +6 -0
  55. package/es/formulaTarget/components/panel/index.js +162 -0
  56. package/es/formulaTarget/components/panel/index.less +131 -0
  57. package/es/formulaTarget/components/panel/item.d.ts +5 -0
  58. package/es/formulaTarget/components/panel/item.js +76 -0
  59. package/es/formulaTarget/components/panel/types.d.ts +13 -0
  60. package/es/formulaTarget/components/panel/types.js +1 -0
  61. package/es/formulaTarget/components/symbol/index.d.ts +7 -0
  62. package/es/formulaTarget/components/symbol/index.js +48 -0
  63. package/es/formulaTarget/components/symbol/index.less +48 -0
  64. package/es/formulaTarget/demo/group.d.ts +2 -0
  65. package/es/formulaTarget/demo/group.js +92 -0
  66. package/es/formulaTarget/demo/index.d.ts +2 -0
  67. package/es/formulaTarget/demo/index.js +21 -0
  68. package/es/formulaTarget/index.d.ts +5 -0
  69. package/es/formulaTarget/index.js +196 -0
  70. package/es/formulaTarget/styles/index.less +66 -0
  71. package/es/formulaTarget/types.d.ts +17 -0
  72. package/es/formulaTarget/types.js +1 -0
  73. package/es/index.d.ts +2 -1
  74. package/es/index.js +2 -1
  75. package/es/select/handle.js +9 -2
  76. package/es/select/styles/handle.less +1 -0
  77. package/es/select/types.d.ts +1 -0
  78. package/es/targetConditionGroup/components/targetDimension.js +0 -2
  79. package/es/targetConditionGroup/demo/index.js +1 -0
  80. package/es/targetConditionGroup/index.js +15 -7
  81. package/es/targetConditionGroup/styles/index.less +31 -6
  82. package/es/targetSelector/index.js +11 -69
  83. package/es/targetSelector/optionIcon.js +3 -0
  84. package/es/targetSelector/styles/index.less +27 -13
  85. package/es/userGroup/index.js +5 -9
  86. package/es/userGroup/styles/index.less +9 -10
  87. package/package.json +2 -2
@@ -0,0 +1,40 @@
1
+ export var formulaList = ['+', '-', '*', '/'];
2
+ export var formulaList2 = [{
3
+ name: 'tianjia3',
4
+ value: '+'
5
+ }, {
6
+ name: 'jian',
7
+ value: '-'
8
+ }, {
9
+ name: 'qingchu',
10
+ value: '*'
11
+ }, {
12
+ name: 'chu',
13
+ value: '/'
14
+ }];
15
+ export var formulaObj = {
16
+ '+': 'tianjia3',
17
+ '-': 'jian',
18
+ '*': 'qingchu',
19
+ '/': 'chu'
20
+ };
21
+ export var formulaDimensions = [{
22
+ type: 'number',
23
+ label: '人数'
24
+ }, {
25
+ type: 'times',
26
+ label: '次数'
27
+ }];
28
+ export var resultFormatList = [{
29
+ label: '原始数据',
30
+ value: 'scale:5'
31
+ }, {
32
+ label: '保留两位小数',
33
+ value: 'scale:2'
34
+ }, {
35
+ label: '保留整数',
36
+ value: 'scale:0'
37
+ }, {
38
+ label: '乘以100%',
39
+ value: 'percent:2'
40
+ }];
@@ -0,0 +1,2 @@
1
+ declare const _default: () => JSX.Element;
2
+ export default _default;
@@ -0,0 +1,76 @@
1
+ import React from 'react';
2
+ import FormulaContainer from '.';
3
+ import { BizGlobalDataContext, convertAttributeData } from '../../..';
4
+ import eventData from '../../../mock/event';
5
+ import envData from '../../../mock/env';
6
+ import userData from '../../../mock/user';
7
+ import { OperateTypes } from '../../../attrConditions/types';
8
+ var defaultValue = [{
9
+ filters: {
10
+ relation: 'and',
11
+ conditions: [{
12
+ attrId: 0,
13
+ propCategory: 'userProp',
14
+ type: 1,
15
+ operator: OperateTypes.Equal,
16
+ values: ['实名'],
17
+ dimensionSub: 'is_anonymous',
18
+ label: '实名/匿名',
19
+ attrName: 'is_anonymous',
20
+ category: 'fixed'
21
+ }]
22
+ },
23
+ analysisDimension: {
24
+ analysisIndex: 'number'
25
+ },
26
+ type: 'add',
27
+ alias: '新增用户',
28
+ eventGroupId: 0,
29
+ eventName: '新增用户',
30
+ eventId: -201,
31
+ isBuiltIn: true
32
+ }, {
33
+ filters: {
34
+ relation: 'and',
35
+ conditions: [{
36
+ attrId: 30601363,
37
+ propCategory: 'eventProp',
38
+ type: 1,
39
+ operator: OperateTypes.Equal,
40
+ values: ['3.0'],
41
+ dimensionSub: 'event_attr',
42
+ label: '版本',
43
+ attrName: '版本'
44
+ }]
45
+ },
46
+ analysisDimension: {
47
+ analysisIndex: 'number'
48
+ },
49
+ type: 'event',
50
+ alias: '底部导航栏曝光',
51
+ eventGroupId: 0,
52
+ eventName: '底部导航栏曝光',
53
+ eventId: 24288499,
54
+ isBuiltIn: false
55
+ }];
56
+ export default (function () {
57
+ var store = convertAttributeData({
58
+ eventList: eventData,
59
+ userPropList: userData,
60
+ envPropList: envData
61
+ });
62
+ var onChange = function onChange(data, result) {
63
+ console.log('公式change:', data, result);
64
+ };
65
+ return /*#__PURE__*/React.createElement(BizGlobalDataContext.Provider, {
66
+ value: {
67
+ eventGroupList: store.eventGroupList,
68
+ userPropList: store.userPropList,
69
+ eventEnvList: store.envPropList
70
+ }
71
+ }, ' ', /*#__PURE__*/React.createElement(FormulaContainer, {
72
+ value: defaultValue,
73
+ formula: "$0/(30+$1)*2",
74
+ onChange: onChange
75
+ }));
76
+ });
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { FormulaContainerTypes } from './types';
3
+ import './index.less';
4
+ export declare const classPrefix = "formula-container";
5
+ declare const FormulaContainer: React.ForwardRefExoticComponent<FormulaContainerTypes.Props & React.RefAttributes<any>>;
6
+ export default FormulaContainer;
@@ -0,0 +1,132 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import React, { useEffect, useImperativeHandle, useState } from 'react';
8
+ import { formatTarget, getBrackets, targetsFormat } from './util';
9
+ import './index.less';
10
+ import FormulaSymbol from '../symbol';
11
+ import FormulaItem from '../formulaItem';
12
+ import _ from 'lodash';
13
+ import { BizSelect, IconFont, util } from '../../..';
14
+ import { formulaList, resultFormatList } from './data';
15
+ export var classPrefix = 'formula-container';
16
+ var FormulaContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
17
+ var _useState = useState([]),
18
+ _useState2 = _slicedToArray(_useState, 2),
19
+ targetList = _useState2[0],
20
+ setTargetList = _useState2[1];
21
+ var _useState3 = useState([null, null]),
22
+ _useState4 = _slicedToArray(_useState3, 2),
23
+ brackets = _useState4[0],
24
+ setBrackets = _useState4[1];
25
+ var _useState5 = useState(resultFormatList[0]),
26
+ _useState6 = _slicedToArray(_useState5, 2),
27
+ resultFormat = _useState6[0],
28
+ setResultFormat = _useState6[1];
29
+ useEffect(function () {
30
+ init();
31
+ }, []);
32
+ useEffect(function () {
33
+ setBrackets(getBrackets(targetList));
34
+ var item = formatTarget(targetList);
35
+ props.onChange && props.onChange(item.formulaList, item.formula, resultFormat.value);
36
+ }, [targetList, resultFormat]);
37
+ useImperativeHandle(ref, function () {
38
+ return {
39
+ reset: init
40
+ };
41
+ });
42
+ var init = function init() {
43
+ setResultFormat(function () {
44
+ return props.resultFormat ? resultFormatList.filter(function (item) {
45
+ return item.value === props.resultFormat;
46
+ })[0] : resultFormatList[0];
47
+ });
48
+ setTargetList(targetsFormat(props.formula, props.value));
49
+ };
50
+ var _onChange = function onChange(index, data) {
51
+ setTargetList(function (list) {
52
+ var newList = _.cloneDeep(list);
53
+ newList[index].value = _.cloneDeep(data);
54
+ return newList;
55
+ });
56
+ };
57
+ var onAdd = function onAdd() {
58
+ setTargetList(function (list) {
59
+ var newList = _.cloneDeep(list);
60
+ if (list.length) {
61
+ newList.push({
62
+ id: util.guid(),
63
+ type: 'symbol',
64
+ value: formulaList[2]
65
+ });
66
+ }
67
+ newList.push({
68
+ id: util.guid(),
69
+ type: 'item',
70
+ value: null
71
+ });
72
+ return newList;
73
+ });
74
+ };
75
+ var _onDelete = function onDelete(id) {
76
+ setTargetList(function (list) {
77
+ var newList = _.cloneDeep(list);
78
+ newList.forEach(function (item, i) {
79
+ if (item.id === id) {
80
+ newList.splice(i, 1);
81
+ if (i > 0) {
82
+ newList.splice(i - 1, 1);
83
+ } else {
84
+ newList.splice(i, 1);
85
+ }
86
+ }
87
+ });
88
+ return newList;
89
+ });
90
+ };
91
+ var onChangeFormat = function onChangeFormat(data) {
92
+ setResultFormat(data);
93
+ };
94
+ return /*#__PURE__*/React.createElement("div", {
95
+ className: classPrefix
96
+ }, targetList.map(function (target, index) {
97
+ if (target.type === 'symbol') {
98
+ return /*#__PURE__*/React.createElement(FormulaSymbol, {
99
+ key: target.id,
100
+ value: target.value,
101
+ onChange: function onChange(data) {
102
+ return _onChange(index, data);
103
+ }
104
+ });
105
+ }
106
+ return /*#__PURE__*/React.createElement(FormulaItem, {
107
+ key: target.id,
108
+ id: target.id,
109
+ index: index,
110
+ value: target.value,
111
+ brackets: brackets,
112
+ onChange: function onChange(data) {
113
+ return _onChange(index, data);
114
+ },
115
+ onDelete: function onDelete() {
116
+ return _onDelete(target.id);
117
+ }
118
+ });
119
+ }), targetList.length < 9 ? /*#__PURE__*/React.createElement(IconFont, {
120
+ type: "tianjia",
121
+ className: "".concat(classPrefix, "-add"),
122
+ onClick: onAdd
123
+ }) : null, /*#__PURE__*/React.createElement("div", {
124
+ className: "".concat(classPrefix, "-format")
125
+ }, /*#__PURE__*/React.createElement("span", null, "\u8BA1\u7B97\u7ED3\u679C"), /*#__PURE__*/React.createElement(BizSelect, {
126
+ value: resultFormat,
127
+ options: resultFormatList,
128
+ keyField: 'value',
129
+ onChange: onChangeFormat
130
+ })));
131
+ });
132
+ export default FormulaContainer;
@@ -0,0 +1,68 @@
1
+ @import '../../../assets/styles/inner.less';
2
+
3
+ .formula-container {
4
+ display: flex;
5
+ align-items: center;
6
+ &-target {
7
+ display: flex;
8
+ &:hover {
9
+ .formula-container-option:not(.active) {
10
+ display: flex;
11
+ color: #b9ceff;
12
+ }
13
+ }
14
+ &-handle {
15
+ min-width: 88px;
16
+ &-icon {
17
+ margin-left: 4px;
18
+ color: @text-color-middle;
19
+ }
20
+ &-name {
21
+ margin-left: 4px;
22
+ }
23
+ }
24
+ }
25
+
26
+ &-format {
27
+ display: flex;
28
+ align-items: center;
29
+ margin-left: 40px;
30
+ & > span {
31
+ margin-right: 12px;
32
+ }
33
+
34
+ .biz-select-handle {
35
+ min-width: 136px;
36
+ }
37
+ }
38
+ &-add {
39
+ margin-left: 8px;
40
+ color: @primary-color;
41
+ font-size: 18px !important;
42
+ cursor: pointer;
43
+ }
44
+ &-option {
45
+ display: flex;
46
+ align-items: center;
47
+ color: transparent;
48
+ cursor: pointer;
49
+ &.active {
50
+ display: flex;
51
+ color: #354354;
52
+ }
53
+ &.disabled {
54
+ cursor: not-allowed;
55
+ }
56
+
57
+ &:first-child {
58
+ margin-right: 4px;
59
+ }
60
+ &:last-child {
61
+ margin-left: 4px;
62
+ }
63
+ }
64
+
65
+ &-symbol {
66
+ margin: 0 12px;
67
+ }
68
+ }
@@ -0,0 +1,24 @@
1
+ import { TargetConditionTypes } from '../../..';
2
+ export declare namespace FormulaContainerTypes {
3
+ interface Props {
4
+ value?: TargetConditionTypes.Value[];
5
+ formula?: string;
6
+ resultFormat?: string;
7
+ onChange?: (formulaList: TargetConditionTypes.Value[], formula: string, result?: string) => void;
8
+ }
9
+ type Value = null | string | TargetConditionTypes.Value;
10
+ interface FormulaItemValue {
11
+ id: string;
12
+ type: 'item' | 'symbol';
13
+ value: null | string | Item;
14
+ }
15
+ interface Item {
16
+ left: boolean;
17
+ right: boolean;
18
+ condition?: Value;
19
+ }
20
+ interface Bracket {
21
+ id: string;
22
+ index: number;
23
+ }
24
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { AttrConditionTypes, TargetConditionTypes } from '../../..';
2
+ import { EventGroup } from '../../../attributeSelector/types';
3
+ import { FormulaContainerTypes } from './types';
4
+ import { BizFormulaTargetTypes } from '../../types';
5
+ export declare const newItem: FormulaContainerTypes.FormulaItemValue;
6
+ export declare const newSymbol: FormulaContainerTypes.FormulaItemValue;
7
+ export declare const targetsFormat: (targetFormula?: string, targets?: TargetConditionTypes.Value[]) => FormulaContainerTypes.FormulaItemValue[];
8
+ export declare const formatTarget: (targetList: FormulaContainerTypes.FormulaItemValue[]) => {
9
+ formula: string;
10
+ formulaList: TargetConditionTypes.Value[];
11
+ };
12
+ export declare const getBrackets: (formula: FormulaContainerTypes.FormulaItemValue[]) => any[];
13
+ export declare const dimensionLabel: (condition: any) => any;
14
+ export declare const isDisable: (id: string, currentIndex: number, brackets: any[], type: string) => boolean;
15
+ export declare const validator: (type: string, condition?: TargetConditionTypes.Value | string | null) => {
16
+ isOk: boolean;
17
+ msg: string;
18
+ };
19
+ export declare const getDimension: (data: TargetConditionTypes.DimensionValue, eId?: number, eventGroupList?: EventGroup[]) => string;
20
+ export declare const judgeHaveFilter: (filter?: AttrConditionTypes.GroupValue) => boolean;
21
+ export declare const getFilters: (filters?: AttrConditionTypes.GroupValue) => {
22
+ conditions: AttrConditionTypes.ItemValue[];
23
+ relation?: "and" | "or" | undefined;
24
+ } | undefined;
25
+ export declare const validatorFormula: (params: BizFormulaTargetTypes.Value) => {
26
+ isOk: boolean;
27
+ msg: string;
28
+ };
@@ -0,0 +1,245 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ import _ from 'lodash';
8
+ import { normalOptions } from '../../../targetConditionGroup/data/operates';
9
+ import { util } from '../../../utils';
10
+ import { formulaDimensions, formulaList } from './data';
11
+ export var newItem = {
12
+ id: util.guid(),
13
+ type: 'item',
14
+ value: null
15
+ };
16
+ export var newSymbol = {
17
+ id: util.guid(),
18
+ type: 'symbol',
19
+ value: formulaList[2]
20
+ };
21
+ export var targetsFormat = function targetsFormat(targetFormula, targets) {
22
+ if (!targetFormula || !(targets === null || targets === void 0 ? void 0 : targets.length)) return [{
23
+ id: util.guid(),
24
+ type: 'item',
25
+ value: null
26
+ }];
27
+ var symbolReg = new RegExp("[".concat(formulaList.join('\\'), "]"), 'g');
28
+ var symbolList = targetFormula === null || targetFormula === void 0 ? void 0 : targetFormula.match(symbolReg);
29
+ var formulaItems = [];
30
+ targetFormula.split(symbolReg).forEach(function (formula, i) {
31
+ var item = {
32
+ id: util.guid(),
33
+ type: 'item',
34
+ value: {
35
+ left: /\(/.test(formula),
36
+ right: /\)/.test(formula),
37
+ condition: null
38
+ }
39
+ };
40
+ if (/\$/.test(formula)) {
41
+ var num = formula.match(/\d+/);
42
+ item.value.condition = num ? targets[Number(num[0])] : null;
43
+ } else {
44
+ item.value.condition = formula.replace(/\(|\)/g, '');
45
+ }
46
+ formulaItems.push(item);
47
+ if (symbolList && symbolList[i]) {
48
+ formulaItems.push({
49
+ id: util.guid(),
50
+ type: 'symbol',
51
+ value: symbolList[i]
52
+ });
53
+ }
54
+ });
55
+ return formulaItems;
56
+ };
57
+ export var formatTarget = function formatTarget(targetList) {
58
+ var formulaList = [];
59
+ var formula = '';
60
+ var i = 0;
61
+ targetList.forEach(function (item) {
62
+ if (!item.value) {
63
+ formula += item.value;
64
+ return;
65
+ }
66
+ if (item.type === 'item') {
67
+ var _data$condition;
68
+ var data = _.cloneDeep(item.value);
69
+ var code = "$".concat(i);
70
+ if ((_data$condition = data.condition) === null || _data$condition === void 0 ? void 0 : _data$condition.eventId) {
71
+ formulaList.push(data.condition);
72
+ i++;
73
+ } else {
74
+ code = data.condition;
75
+ }
76
+ formula += "".concat(data.left ? '(' : '').concat(code).concat(data.right ? ')' : '');
77
+ } else if (item.type === 'symbol') {
78
+ formula += item.value;
79
+ }
80
+ });
81
+ return {
82
+ formula: formula,
83
+ formulaList: formulaList
84
+ };
85
+ };
86
+ export var getBrackets = function getBrackets(formula) {
87
+ var brackets = new Array(2);
88
+ formula.forEach(function (item, i) {
89
+ var flag1 = item.value && item.value.left;
90
+ var flag2 = item.value && item.value.right;
91
+ if (flag1) {
92
+ brackets[0] = {
93
+ id: item.id,
94
+ index: i
95
+ };
96
+ }
97
+ if (flag2) {
98
+ brackets[1] = {
99
+ id: item.id,
100
+ index: i
101
+ };
102
+ }
103
+ });
104
+ return brackets;
105
+ };
106
+ export var dimensionLabel = function dimensionLabel(condition) {
107
+ if (util.isString(condition)) return '';
108
+ if (condition && ['add', 'pv', 'active'].includes(condition.type)) return '';
109
+ if (condition && condition.dimension) {
110
+ if (/:sum$/.test(condition.dimension)) {
111
+ return condition.dimension.replace(/:sum$/, ':总和');
112
+ }
113
+ var dimension = formulaDimensions.find(function (item) {
114
+ return item.type === condition.dimension;
115
+ });
116
+ if (dimension) return dimension.label;
117
+ }
118
+ return '';
119
+ };
120
+ export var isDisable = function isDisable(id, currentIndex, brackets, type) {
121
+ var disable = false;
122
+ var index = type === 'left' ? 0 : 1;
123
+ var flag = type === 'left' ? brackets[1] && brackets[1].index < currentIndex : brackets[0] && brackets[0].index > currentIndex;
124
+ if (brackets[index] && brackets[index].id !== id || flag) {
125
+ disable = true;
126
+ }
127
+ return disable;
128
+ };
129
+ export var validator = function validator(type, condition) {
130
+ var isOk = true;
131
+ var msg = '';
132
+ if (type === 'constant') {
133
+ if (condition !== '0' && !condition) {
134
+ isOk = false;
135
+ msg = '常数不可为空';
136
+ } else {
137
+ isOk = !/[^0-9.]/g.test(condition);
138
+ if (Number(condition) === 0) {
139
+ isOk = false;
140
+ msg = '常数不可为0';
141
+ } else if (!isOk) {
142
+ isOk = false;
143
+ msg = '常数中只能输入大于0的数字';
144
+ }
145
+ }
146
+ } else {
147
+ var _condition$filters;
148
+ if (condition && (condition === null || condition === void 0 ? void 0 : condition.filters) && (condition === null || condition === void 0 ? void 0 : (_condition$filters = condition.filters) === null || _condition$filters === void 0 ? void 0 : _condition$filters.conditions)) {
149
+ var _condition$filters2;
150
+ condition === null || condition === void 0 ? void 0 : (_condition$filters2 = condition.filters) === null || _condition$filters2 === void 0 ? void 0 : _condition$filters2.conditions.forEach(function (item) {
151
+ if (!isOk) return;
152
+ if (item.propCategory === 'eventProp' && !item.attrId || item.propCategory !== 'eventProp' && !item.attrName) {
153
+ isOk = false;
154
+ msg = '属性不可为空';
155
+ } else if (!item.values || !item.values.length) {
156
+ if (item.operator !== 'is null' && item.operator !== 'is not null') {
157
+ isOk = false;
158
+ msg = '属性值不能为空';
159
+ }
160
+ }
161
+ });
162
+ }
163
+ }
164
+ return {
165
+ isOk: isOk,
166
+ msg: msg
167
+ };
168
+ };
169
+ export var getDimension = function getDimension(data, eId, eventGroupList) {
170
+ var name = '';
171
+ normalOptions.forEach(function (item) {
172
+ if (item.value === data.analysisIndex) {
173
+ name = item.label;
174
+ }
175
+ });
176
+ if (data.analysisAttr) {
177
+ eventGroupList === null || eventGroupList === void 0 ? void 0 : eventGroupList.forEach(function (group) {
178
+ group.eventList.forEach(function (event) {
179
+ if (event.id === eId) {
180
+ event.attrList.forEach(function (attr) {
181
+ if (String(attr.id) === data.analysisAttr) {
182
+ name += attr.alias || attr.label;
183
+ }
184
+ });
185
+ return;
186
+ }
187
+ });
188
+ });
189
+ }
190
+ return name;
191
+ };
192
+ export var judgeHaveFilter = function judgeHaveFilter(filter) {
193
+ var flag = false;
194
+ filter === null || filter === void 0 ? void 0 : filter.conditions.forEach(function (item) {
195
+ if (item.attrId) {
196
+ if (item.values && item.values.length || ['is null', 'is not null'].includes(item.operator)) {
197
+ flag = true;
198
+ return;
199
+ }
200
+ }
201
+ });
202
+ return flag;
203
+ };
204
+ export var getFilters = function getFilters(filters) {
205
+ if (!filters) return;
206
+ var conditions = filters.conditions;
207
+ if (conditions && conditions.length) {
208
+ conditions = conditions.filter(function (item) {
209
+ return item.attrId && (item.values && item.values.length || ['is null', 'is not null'].includes(item.operator));
210
+ });
211
+ }
212
+ return _objectSpread(_objectSpread({}, filters), {}, {
213
+ conditions: conditions
214
+ });
215
+ };
216
+ export var validatorFormula = function validatorFormula(params) {
217
+ var isOk = true;
218
+ var msg = '';
219
+ var formula = params.formula;
220
+ var customCondition = params.customCondition || [];
221
+ var reg = RegExp(/null|undefined/);
222
+ if (!customCondition.length || !formula || !/\$/.test(formula)) {
223
+ isOk = false;
224
+ msg = '公式不合法,请添加整体指标或事件指标';
225
+ } else if (/\(|\)/.test(formula) && !/\(\S*?\)/.test(formula) || formula.match(reg)) {
226
+ isOk = false;
227
+ msg = '公式不合法';
228
+ }
229
+ if (isOk) {
230
+ customCondition.forEach(function (condition) {
231
+ if (!isOk) return;
232
+ var type = condition.type || 'constant';
233
+ var validatorData = validator(type, condition);
234
+ if (!validatorData.isOk) {
235
+ isOk = false;
236
+ msg = '公式不合法';
237
+ return;
238
+ }
239
+ });
240
+ }
241
+ return {
242
+ isOk: isOk,
243
+ msg: msg
244
+ };
245
+ };
@@ -0,0 +1,2 @@
1
+ import { FormulaContainerTypes } from '../formula/types';
2
+ export declare const itemDefaultData: FormulaContainerTypes.Item;
@@ -0,0 +1,4 @@
1
+ export var itemDefaultData = {
2
+ left: false,
3
+ right: false
4
+ };
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { FormulaItemProps } from './types';
3
+ declare const FormulaItem: React.FC<FormulaItemProps>;
4
+ export default FormulaItem;