@zgfe/business-lib 1.1.34-alpha.2 → 1.1.34-alpha.21
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.
- package/es/addToPanel/index.js +7 -1
- package/es/addToScene/index.js +1 -1
- package/es/assets/colorIcon/demo.css +539 -0
- package/es/assets/colorIcon/demo_index.html +741 -0
- package/es/assets/colorIcon/iconfont.css +112 -0
- package/es/assets/colorIcon/iconfont.js +43 -0
- package/es/assets/colorIcon/iconfont.json +177 -0
- package/es/assets/colorIcon/iconfont.svg +67 -0
- package/es/assets/colorIcon/iconfont.ttf +0 -0
- package/es/assets/colorIcon/iconfont.woff +0 -0
- package/es/assets/colorIcon/iconfont.woff2 +0 -0
- package/es/assets/iconfont/demo_index.html +95 -3
- package/es/assets/iconfont/iconfont.css +19 -3
- package/es/assets/iconfont/iconfont.js +1 -1
- package/es/assets/iconfont/iconfont.json +28 -0
- package/es/assets/iconfont/iconfont.ttf +0 -0
- package/es/assets/iconfont/iconfont.woff +0 -0
- package/es/assets/iconfont/iconfont.woff2 +0 -0
- package/es/assets/theme.js +1 -2
- package/es/attrConditions/components/stringList.js +0 -1
- package/es/attrConditions/components/valuesList.js +1 -0
- package/es/attrConditions/demo/group.js +3 -2
- package/es/attrConditions/demo/index.js +1 -11
- package/es/attrConditions/index.d.ts +3 -1
- package/es/attrConditions/index.js +24 -19
- package/es/attrConditions/types.d.ts +1 -1
- package/es/attributeSelector/index.js +10 -8
- package/es/attributeSelector/types.d.ts +4 -0
- package/es/attributeSelector/util.js +5 -1
- package/es/chart/util/formatOption.js +1 -1
- package/es/colorIcon/demo/index.d.ts +3 -0
- package/es/colorIcon/demo/index.js +10 -0
- package/es/colorIcon/index.d.ts +9 -0
- package/es/colorIcon/index.js +19 -0
- package/es/constants/apis.d.ts +6 -0
- package/es/constants/apis.js +7 -1
- package/es/constants/common.d.ts +11 -0
- package/es/constants/common.js +35 -0
- package/es/context/index.d.ts +4 -1
- package/es/cycleTime/month.js +17 -15
- package/es/datePicker/index.d.ts +1 -1
- package/es/datePicker/index.js +1 -1
- package/es/datePicker/styles/index.less +1 -1
- package/es/demoWrapper/content.d.ts +2 -1
- package/es/demoWrapper/content.js +25 -12
- package/es/demoWrapper/demo/index.js +5 -3
- package/es/demoWrapper/head.d.ts +3 -1
- package/es/demoWrapper/head.js +17 -5
- package/es/demoWrapper/index.js +18 -10
- package/es/dialog/index.js +1 -1
- package/es/eventSelector/demo/index.js +1 -0
- package/es/eventSelector/index.js +15 -10
- package/es/eventSelector/listPanel.js +33 -7
- package/es/eventSelector/types.d.ts +2 -0
- package/es/index.d.ts +3 -1
- package/es/index.js +3 -1
- package/es/select/handle.js +6 -2
- package/es/select/index.js +13 -11
- package/es/socket/demo/demo.d.ts +2 -0
- package/es/socket/demo/demo.js +145 -0
- package/es/socket/demo/index.less +27 -0
- package/es/socket/index.d.ts +33 -0
- package/es/socket/index.js +304 -0
- package/es/socket/types.d.ts +38 -0
- package/es/socket/types.js +28 -0
- package/es/targetConditionGroup/components/targetDimension.js +29 -27
- package/es/targetConditionGroup/data/operates.js +0 -3
- package/es/targetConditionGroup/demo/index.js +2 -1
- package/es/targetConditionGroup/index.js +65 -34
- package/es/targetConditionGroup/types.d.ts +1 -0
- package/es/targetSelector/index.js +9 -7
- package/es/userCondition/conditionTypeList.js +11 -8
- package/es/userCondition/conditions/business/operatorCondition.d.ts +11 -0
- package/es/userCondition/conditions/business/operatorCondition.js +181 -0
- package/es/userCondition/conditions/business/paramsCondition.d.ts +9 -0
- package/es/userCondition/conditions/business/paramsCondition.js +79 -0
- package/es/userCondition/conditions/businessCondition.d.ts +2 -8
- package/es/userCondition/conditions/businessCondition.js +37 -203
- package/es/userCondition/conditions/cdpCondition.js +1 -1
- package/es/userCondition/conditions/dataAttribute.js +78 -274
- package/es/userCondition/conditions/eventCondition.js +7 -4
- package/es/userCondition/conditions/order/runPeriodCondition.d.ts +11 -0
- package/es/userCondition/conditions/order/runPeriodCondition.js +142 -0
- package/es/userCondition/conditions/order/runTimesCondition.d.ts +11 -0
- package/es/userCondition/conditions/order/runTimesCondition.js +112 -0
- package/es/userCondition/conditions/textDesc.d.ts +1 -1
- package/es/userCondition/conditions/textDesc.js +160 -2
- package/es/userCondition/conditions/timeDimension.d.ts +1 -0
- package/es/userCondition/conditions/timeDimension.js +26 -76
- package/es/userCondition/demo/business.d.ts +3 -0
- package/es/userCondition/demo/business.js +71 -0
- package/es/userCondition/index.js +14 -2
- package/es/userCondition/orConditions.js +9 -4
- package/es/userCondition/types.d.ts +42 -8
- package/es/userCondition/types.js +8 -1
- package/es/userCondition/util.d.ts +1 -1
- package/es/userCondition/util.js +7 -4
- package/es/userTagsSelector/index.js +5 -3
- package/es/utils/ajax.js +0 -1
- package/package.json +60 -60
|
@@ -10,6 +10,7 @@ import SelectHandle from '../select/handle';
|
|
|
10
10
|
import BizGlobalDataContext from '../context';
|
|
11
11
|
import EventListPanel from './listPanel';
|
|
12
12
|
import './styles/index.less';
|
|
13
|
+
import { BuiltinIndicators } from '../constants/common';
|
|
13
14
|
export var classPrefix = 'biz-event-select';
|
|
14
15
|
var BizEventSelector = function BizEventSelector(props) {
|
|
15
16
|
var alias = props.alias,
|
|
@@ -42,13 +43,14 @@ var BizEventSelector = function BizEventSelector(props) {
|
|
|
42
43
|
var getValue = function getValue(param) {
|
|
43
44
|
var _param$group, _param$event;
|
|
44
45
|
var res = {};
|
|
46
|
+
var allEvents = props.showBuiltInTarget ? eventGroupList === null || eventGroupList === void 0 ? void 0 : eventGroupList.concat(BuiltinIndicators) : eventGroupList;
|
|
45
47
|
if (!((_param$group = param.group) === null || _param$group === void 0 ? void 0 : _param$group.id)) {
|
|
46
48
|
res.group = {
|
|
47
49
|
id: 0,
|
|
48
50
|
name: '所有分组',
|
|
49
51
|
eventList: function () {
|
|
50
52
|
var list = [];
|
|
51
|
-
|
|
53
|
+
allEvents === null || allEvents === void 0 ? void 0 : allEvents.forEach(function (group) {
|
|
52
54
|
list = list.concat(group.eventList);
|
|
53
55
|
});
|
|
54
56
|
return list;
|
|
@@ -62,7 +64,7 @@ var BizEventSelector = function BizEventSelector(props) {
|
|
|
62
64
|
attrList: []
|
|
63
65
|
};
|
|
64
66
|
}
|
|
65
|
-
|
|
67
|
+
allEvents === null || allEvents === void 0 ? void 0 : allEvents.forEach(function (group) {
|
|
66
68
|
var _param$group2;
|
|
67
69
|
if (group.id === ((_param$group2 = param.group) === null || _param$group2 === void 0 ? void 0 : _param$group2.id)) res.group = group;
|
|
68
70
|
group.eventList.forEach(function (event) {
|
|
@@ -100,19 +102,22 @@ var BizEventSelector = function BizEventSelector(props) {
|
|
|
100
102
|
return /*#__PURE__*/React.createElement("div", {
|
|
101
103
|
className: [classPrefix, border ? 'border' : ''].join(' ')
|
|
102
104
|
}, /*#__PURE__*/React.createElement(Dropdown, {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
dropdownRender: function dropdownRender() {
|
|
106
|
+
return /*#__PURE__*/React.createElement(EventListPanel, {
|
|
107
|
+
value: currentValue,
|
|
108
|
+
onChange: onChange,
|
|
109
|
+
showOverview: showAllEvent,
|
|
110
|
+
showBuiltInTarget: props.showBuiltInTarget,
|
|
111
|
+
defaultSelectAble: defaultSelectAble
|
|
112
|
+
});
|
|
113
|
+
},
|
|
109
114
|
trigger: ['click'],
|
|
110
115
|
overlayStyle: {
|
|
111
116
|
minWidth: 0,
|
|
112
117
|
paddingLeft: 8
|
|
113
118
|
},
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
open: visible,
|
|
120
|
+
onOpenChange: onVisibleChange,
|
|
116
121
|
getPopupContainer: props.popupContainer ? function () {
|
|
117
122
|
return document.getElementById(selectId);
|
|
118
123
|
} : undefined,
|
|
@@ -15,6 +15,7 @@ import InfiniteScroll from 'react-infinite-scroll-component';
|
|
|
15
15
|
import { classPrefix } from '.';
|
|
16
16
|
import { BizGlobalDataContext } from '..';
|
|
17
17
|
import { ShowStatus } from '../attributeSelector/types';
|
|
18
|
+
import { BuiltinIndicators } from '../constants/common';
|
|
18
19
|
import BizSearchInput from '../searchInput';
|
|
19
20
|
import EventListOption from './option';
|
|
20
21
|
var EventListPanel = function EventListPanel(props) {
|
|
@@ -68,15 +69,33 @@ var EventListPanel = function EventListPanel(props) {
|
|
|
68
69
|
}
|
|
69
70
|
});
|
|
70
71
|
});
|
|
71
|
-
list = [].concat(markList, _toConsumableArray(list));
|
|
72
|
+
list = props.showBuiltInTarget ? [].concat(_toConsumableArray(BuiltinIndicators.eventList), markList, _toConsumableArray(list)) : [].concat(markList, _toConsumableArray(list));
|
|
72
73
|
return list;
|
|
73
74
|
}(),
|
|
74
75
|
name: '所有分组'
|
|
75
76
|
};
|
|
76
77
|
setGroupList(function (list) {
|
|
77
|
-
return [group].concat(_toConsumableArray(list));
|
|
78
|
+
return props.showBuiltInTarget ? [group, BuiltinIndicators].concat(_toConsumableArray(list)) : [group].concat(_toConsumableArray(list));
|
|
79
|
+
});
|
|
80
|
+
setCurrentGroup(function () {
|
|
81
|
+
var _props$value;
|
|
82
|
+
if (props.defaultSelectAble && ((_props$value = props.value) === null || _props$value === void 0 ? void 0 : _props$value.group)) {
|
|
83
|
+
if (props.showBuiltInTarget && props.value.group.id === -2) {
|
|
84
|
+
return BuiltinIndicators;
|
|
85
|
+
} else {
|
|
86
|
+
var _currentGroup = group;
|
|
87
|
+
eventGroupList === null || eventGroupList === void 0 ? void 0 : eventGroupList.forEach(function (eGroup) {
|
|
88
|
+
var _props$value2, _props$value2$group;
|
|
89
|
+
if (eGroup.id === ((_props$value2 = props.value) === null || _props$value2 === void 0 ? void 0 : (_props$value2$group = _props$value2.group) === null || _props$value2$group === void 0 ? void 0 : _props$value2$group.id)) {
|
|
90
|
+
_currentGroup = eGroup;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return _currentGroup;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return group;
|
|
78
98
|
});
|
|
79
|
-
setCurrentGroup(group);
|
|
80
99
|
}, []);
|
|
81
100
|
useEffect(function () {
|
|
82
101
|
setCurrentValue(props.value);
|
|
@@ -166,18 +185,26 @@ var InfiniteScrollList = function InfiniteScrollList(_ref) {
|
|
|
166
185
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
167
186
|
showList = _useState12[0],
|
|
168
187
|
setShowList = _useState12[1];
|
|
188
|
+
var _useState13 = useState([]),
|
|
189
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
190
|
+
canShowList = _useState14[0],
|
|
191
|
+
setCanShowList = _useState14[1];
|
|
169
192
|
useEffect(function () {
|
|
170
|
-
|
|
193
|
+
var data = searchEventList.filter(function (item) {
|
|
194
|
+
return item.eventHidden !== ShowStatus.hidden;
|
|
195
|
+
});
|
|
196
|
+
setCanShowList(data);
|
|
197
|
+
setShowList(data.slice(0, 10));
|
|
171
198
|
}, [searchEventList]);
|
|
172
199
|
var loadMoreData = function loadMoreData() {
|
|
173
|
-
var moreData =
|
|
200
|
+
var moreData = canShowList.slice(showList.length, showList.length + 10);
|
|
174
201
|
setShowList(function (list) {
|
|
175
202
|
return [].concat(_toConsumableArray(list), _toConsumableArray(moreData));
|
|
176
203
|
});
|
|
177
204
|
};
|
|
178
205
|
return /*#__PURE__*/React.createElement(InfiniteScroll, {
|
|
179
206
|
dataLength: showList.length,
|
|
180
|
-
hasMore: showList.length <
|
|
207
|
+
hasMore: showList.length < canShowList.length,
|
|
181
208
|
loader: /*#__PURE__*/React.createElement(Skeleton, {
|
|
182
209
|
paragraph: {
|
|
183
210
|
rows: 1
|
|
@@ -190,7 +217,6 @@ var InfiniteScrollList = function InfiniteScrollList(_ref) {
|
|
|
190
217
|
key: Math.random()
|
|
191
218
|
}, showList.map(function (e) {
|
|
192
219
|
var _currentValue$event2;
|
|
193
|
-
if (e.eventHidden === ShowStatus.hidden) return null;
|
|
194
220
|
return /*#__PURE__*/React.createElement(EventListOption, {
|
|
195
221
|
label: e.alias || e.name,
|
|
196
222
|
key: "".concat(currentGroup === null || currentGroup === void 0 ? void 0 : currentGroup.id, "-").concat(e.id),
|
|
@@ -23,6 +23,7 @@ export declare namespace EventSelectTypes {
|
|
|
23
23
|
showAllEvent?: boolean;
|
|
24
24
|
defaultSelectAble?: boolean;
|
|
25
25
|
popupContainer?: boolean;
|
|
26
|
+
showBuiltInTarget?: boolean;
|
|
26
27
|
onVisibleChange?: (visible: boolean) => void;
|
|
27
28
|
border?: boolean;
|
|
28
29
|
theme?: string;
|
|
@@ -33,6 +34,7 @@ export declare namespace EventSelectTypes {
|
|
|
33
34
|
interface DropdownProps {
|
|
34
35
|
value?: Value;
|
|
35
36
|
showOverview?: boolean;
|
|
37
|
+
showBuiltInTarget?: boolean;
|
|
36
38
|
defaultSelectAble?: boolean;
|
|
37
39
|
onChange?: (value: Value, isOverview?: boolean) => void;
|
|
38
40
|
}
|
package/es/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import BizDialog from './dialog';
|
|
|
13
13
|
import BizChart from './chart';
|
|
14
14
|
import BizTable from './table';
|
|
15
15
|
import IconFont from './icon/iconFont';
|
|
16
|
+
import ColorIcon from './colorIcon';
|
|
16
17
|
import { util, ajax } from './utils';
|
|
17
18
|
import theme from './assets/theme.js';
|
|
18
19
|
import convertAttributeData from './attributeSelector/util';
|
|
@@ -28,7 +29,8 @@ import BizDnd from './dnd';
|
|
|
28
29
|
import BizDetailLayout from './layout/detail';
|
|
29
30
|
import BizLoginForm from './loginForm';
|
|
30
31
|
import DemoWrapper from './demoWrapper';
|
|
31
|
-
|
|
32
|
+
import SocketClient from './socket';
|
|
33
|
+
export { BizSearchInput, BizSelect, BizDialog, BizChart, BizTable, BizAnalysisLayout, BizDetailLayout, BizUserGroup, IconFont, ColorIcon, BizTargetSelector, BizEventSelector, BizAttributeSelector, BizGlobalDataContext, BizTargetCondition, BizDatePicker, BizConditionItem, BizConditionGroup, BizUserCondition, BizAddToScene, BizAddToPanel, BizCycleTime, BizDnd, BizLoginForm, DemoWrapper, SocketClient, ajax, util, theme, convertAttributeData, BizUserTagsSelect, setGlobalConfig, };
|
|
32
34
|
export type { UserGroupTypes } from './userGroup/types';
|
|
33
35
|
export type { BizSelectTypes } from './select/types';
|
|
34
36
|
export type { AttributeSelect } from './attributeSelector/types';
|
package/es/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import BizDialog from './dialog';
|
|
|
12
12
|
import BizChart from './chart';
|
|
13
13
|
import BizTable from './table';
|
|
14
14
|
import IconFont from './icon/iconFont';
|
|
15
|
+
import ColorIcon from './colorIcon';
|
|
15
16
|
import { util, ajax } from './utils';
|
|
16
17
|
import theme from './assets/theme.js';
|
|
17
18
|
import convertAttributeData from './attributeSelector/util';
|
|
@@ -27,4 +28,5 @@ import BizDnd from './dnd';
|
|
|
27
28
|
import BizDetailLayout from './layout/detail';
|
|
28
29
|
import BizLoginForm from './loginForm';
|
|
29
30
|
import DemoWrapper from './demoWrapper';
|
|
30
|
-
|
|
31
|
+
import SocketClient from './socket';
|
|
32
|
+
export { BizSearchInput, BizSelect, BizDialog, BizChart, BizTable, BizAnalysisLayout, BizDetailLayout, BizUserGroup, IconFont, ColorIcon, BizTargetSelector, BizEventSelector, BizAttributeSelector, BizGlobalDataContext, BizTargetCondition, BizDatePicker, BizConditionItem, BizConditionGroup, BizUserCondition, BizAddToScene, BizAddToPanel, BizCycleTime, BizDnd, BizLoginForm, DemoWrapper, SocketClient, ajax, util, theme, convertAttributeData, BizUserTagsSelect, setGlobalConfig };
|
package/es/select/handle.js
CHANGED
|
@@ -67,7 +67,11 @@ var SelectHandle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
67
67
|
}
|
|
68
68
|
}, [focus]);
|
|
69
69
|
var searchInputWidth = useMemo(function () {
|
|
70
|
-
|
|
70
|
+
if (textRef.current && searchValue) {
|
|
71
|
+
textRef.current.innerText = searchValue;
|
|
72
|
+
return textRef.current.offsetWidth;
|
|
73
|
+
}
|
|
74
|
+
return 3;
|
|
71
75
|
}, [searchValue]);
|
|
72
76
|
var onDelete = function onDelete(data) {
|
|
73
77
|
if (props.onDelete) props.onDelete(data);
|
|
@@ -122,7 +126,7 @@ var SelectHandle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
122
126
|
}), /*#__PURE__*/React.createElement("span", {
|
|
123
127
|
className: "".concat(classPrefix, "-temp"),
|
|
124
128
|
ref: textRef
|
|
125
|
-
}
|
|
129
|
+
}));
|
|
126
130
|
}
|
|
127
131
|
return /*#__PURE__*/React.createElement("div", {
|
|
128
132
|
ref: handleRef,
|
package/es/select/index.js
CHANGED
|
@@ -146,15 +146,17 @@ var BizSelect = function BizSelect(props) {
|
|
|
146
146
|
setVisible(true);
|
|
147
147
|
};
|
|
148
148
|
return /*#__PURE__*/React.createElement(Dropdown, {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
149
|
+
dropdownRender: function dropdownRender() {
|
|
150
|
+
return /*#__PURE__*/React.createElement(SelectOverlay, _objectSpread(_objectSpread({}, res), {}, {
|
|
151
|
+
value: current,
|
|
152
|
+
labelField: labelField,
|
|
153
|
+
keyField: keyField,
|
|
154
|
+
searchValue: searchValue,
|
|
155
|
+
onChange: onChange,
|
|
156
|
+
ref: overlayRef,
|
|
157
|
+
searchPlaceholder: props.searchPlaceholder
|
|
158
|
+
}));
|
|
159
|
+
},
|
|
158
160
|
disabled: props.disable,
|
|
159
161
|
destroyPopupOnHide: props.destroyPopupOnHide,
|
|
160
162
|
overlayStyle: {
|
|
@@ -165,8 +167,8 @@ var BizSelect = function BizSelect(props) {
|
|
|
165
167
|
getPopupContainer: props.popupContainer ? function () {
|
|
166
168
|
return document.getElementById(selectId);
|
|
167
169
|
} : undefined,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
+
open: visible,
|
|
171
|
+
onOpenChange: onVisibleChange
|
|
170
172
|
}, /*#__PURE__*/React.createElement("div", {
|
|
171
173
|
className: "".concat(classPrefix, "-handle ").concat(props.className ? props.className : ''),
|
|
172
174
|
ref: selectRef,
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
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."); }
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
9
|
+
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; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
12
|
+
import { SocketClient } from '@zgfe/business-lib';
|
|
13
|
+
import { Button, Card, Form, Input, notification } from 'antd';
|
|
14
|
+
import styles from './index.less';
|
|
15
|
+
import { DemoWrapper, BizGlobalDataContext } from '@zgfe/business-lib';
|
|
16
|
+
var ChatPanel = function ChatPanel(_ref) {
|
|
17
|
+
var name = _ref.name,
|
|
18
|
+
param = _ref.param;
|
|
19
|
+
var _useState = useState(),
|
|
20
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
+
client = _useState2[0],
|
|
22
|
+
setClient = _useState2[1];
|
|
23
|
+
var _useState3 = useState([]),
|
|
24
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
25
|
+
history = _useState4[0],
|
|
26
|
+
setHistory = _useState4[1];
|
|
27
|
+
var _useState5 = useState(true),
|
|
28
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
29
|
+
online = _useState6[0],
|
|
30
|
+
setOnline = _useState6[1];
|
|
31
|
+
var formRef = useRef();
|
|
32
|
+
var historyRef = useRef();
|
|
33
|
+
var _useContext = useContext(BizGlobalDataContext),
|
|
34
|
+
currentApp = _useContext.currentApp;
|
|
35
|
+
useEffect(function () {
|
|
36
|
+
var socket = new SocketClient('wss://rt2.zhugeio.com/eventtracking/ws', currentApp === null || currentApp === void 0 ? void 0 : currentApp.appKey, param);
|
|
37
|
+
setClient(socket);
|
|
38
|
+
return function () {
|
|
39
|
+
console.log('销毁chat', param);
|
|
40
|
+
if (!client) return;
|
|
41
|
+
client.destroy();
|
|
42
|
+
setClient(undefined);
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
useEffect(function () {
|
|
46
|
+
var _historyRef$current;
|
|
47
|
+
if (historyRef.current) historyRef.current.scrollTop = (_historyRef$current = historyRef.current) === null || _historyRef$current === void 0 ? void 0 : _historyRef$current.scrollHeight;
|
|
48
|
+
}, [history]);
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
if (!client) return;
|
|
51
|
+
client.openLog(true);
|
|
52
|
+
client.onConnected(onConnected);
|
|
53
|
+
client.onError(onError);
|
|
54
|
+
client.on('offline', function () {
|
|
55
|
+
setHistory(function (list) {
|
|
56
|
+
return [].concat(_toConsumableArray(list), [{
|
|
57
|
+
type: 'he',
|
|
58
|
+
message: '对方已下线'
|
|
59
|
+
}]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
client.on('exist', function () {
|
|
63
|
+
console.log('连接已存在');
|
|
64
|
+
});
|
|
65
|
+
client.on('message', function (message) {
|
|
66
|
+
setHistory(function (list) {
|
|
67
|
+
return [].concat(_toConsumableArray(list), [{
|
|
68
|
+
type: 'he',
|
|
69
|
+
message: message
|
|
70
|
+
}]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}, [client]);
|
|
74
|
+
function onConnected() {
|
|
75
|
+
notification.success({
|
|
76
|
+
message: '连接成功'
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function onError(err) {
|
|
80
|
+
notification.error({
|
|
81
|
+
message: '连接失败',
|
|
82
|
+
description: err.message
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return /*#__PURE__*/React.createElement(Card, {
|
|
86
|
+
title: name
|
|
87
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
88
|
+
className: styles.history,
|
|
89
|
+
ref: historyRef
|
|
90
|
+
}, history.map(function (item, i) {
|
|
91
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
92
|
+
className: styles[item.type],
|
|
93
|
+
key: i
|
|
94
|
+
}, item.type, ": ", item.message);
|
|
95
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
96
|
+
className: styles.footer
|
|
97
|
+
}, /*#__PURE__*/React.createElement(Form, {
|
|
98
|
+
ref: formRef,
|
|
99
|
+
autoComplete: "off",
|
|
100
|
+
onFinish: function onFinish(_ref2) {
|
|
101
|
+
var _formRef$current;
|
|
102
|
+
var message = _ref2.message;
|
|
103
|
+
client.emit('message', message);
|
|
104
|
+
setHistory(function (list) {
|
|
105
|
+
return [].concat(_toConsumableArray(list), [{
|
|
106
|
+
type: 'me',
|
|
107
|
+
message: message
|
|
108
|
+
}]);
|
|
109
|
+
});
|
|
110
|
+
(_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.resetFields();
|
|
111
|
+
}
|
|
112
|
+
}, /*#__PURE__*/React.createElement(Form.Item, {
|
|
113
|
+
name: "message"
|
|
114
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
115
|
+
placeholder: "\u56DE\u8F66\u53D1\u9001\u4FE1\u606F",
|
|
116
|
+
autoFocus: true
|
|
117
|
+
})), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
|
|
118
|
+
onClick: function onClick() {
|
|
119
|
+
if (online) {
|
|
120
|
+
client.close();
|
|
121
|
+
} else {
|
|
122
|
+
client.open();
|
|
123
|
+
}
|
|
124
|
+
setOnline(!online);
|
|
125
|
+
}
|
|
126
|
+
}, online ? '下线' : '上线')))));
|
|
127
|
+
};
|
|
128
|
+
export default (function () {
|
|
129
|
+
return /*#__PURE__*/React.createElement(DemoWrapper, {
|
|
130
|
+
defaultApp: 334
|
|
131
|
+
}, /*#__PURE__*/React.createElement(BizGlobalDataContext.Consumer, null, function (_ref3) {
|
|
132
|
+
var currentApp = _ref3.currentApp;
|
|
133
|
+
console.log('当前应用', currentApp.id);
|
|
134
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
135
|
+
className: styles.container,
|
|
136
|
+
key: currentApp.id
|
|
137
|
+
}, /*#__PURE__*/React.createElement(ChatPanel, {
|
|
138
|
+
name: "\u5F20\u4E09",
|
|
139
|
+
param: {
|
|
140
|
+
appId: currentApp === null || currentApp === void 0 ? void 0 : currentApp.id,
|
|
141
|
+
origin: 3
|
|
142
|
+
}
|
|
143
|
+
}));
|
|
144
|
+
}));
|
|
145
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@import '../../assets/styles/inner.less';
|
|
2
|
+
.container {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: row;
|
|
5
|
+
border: 1px solid red;
|
|
6
|
+
& > :global(.ant-card) {
|
|
7
|
+
flex: 1;
|
|
8
|
+
margin: @margin-md;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
.history {
|
|
12
|
+
height: 400px;
|
|
13
|
+
overflow: auto;
|
|
14
|
+
}
|
|
15
|
+
.he,
|
|
16
|
+
.me {
|
|
17
|
+
margin-bottom: @margin-sm;
|
|
18
|
+
padding: @padding-sm;
|
|
19
|
+
line-height: 24px;
|
|
20
|
+
background: @background-color-base;
|
|
21
|
+
}
|
|
22
|
+
.he {
|
|
23
|
+
text-align: left;
|
|
24
|
+
}
|
|
25
|
+
.me {
|
|
26
|
+
text-align: right;
|
|
27
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import SocketClientTypes from './types';
|
|
2
|
+
declare class SocketClient {
|
|
3
|
+
private client?;
|
|
4
|
+
private url;
|
|
5
|
+
private params?;
|
|
6
|
+
private listeners;
|
|
7
|
+
private catch;
|
|
8
|
+
private showLog;
|
|
9
|
+
private pingTimer?;
|
|
10
|
+
private appkey?;
|
|
11
|
+
private token?;
|
|
12
|
+
constructor(url: string, appkey: string, params?: Record<string, any>);
|
|
13
|
+
emit(event: string, payload?: SocketClientTypes.Message['data']['payload']): void;
|
|
14
|
+
on<T>(type: SocketClientTypes.EventType | string, handle: (data?: T) => void): void;
|
|
15
|
+
onConnected(handle: (data?: any) => void): void;
|
|
16
|
+
onDisconnected(handle: (data?: any) => void): void;
|
|
17
|
+
onError(handle: (data?: Error) => void): void;
|
|
18
|
+
private _onError;
|
|
19
|
+
private _onClose;
|
|
20
|
+
private _onOpen;
|
|
21
|
+
private onMessage;
|
|
22
|
+
private ping;
|
|
23
|
+
removeAllListeners(): void;
|
|
24
|
+
removeListener(event: string, handle?: (data?: any) => void): void;
|
|
25
|
+
private _getToken;
|
|
26
|
+
open(url?: string, params?: Record<string, any>): void;
|
|
27
|
+
close(): void;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
private log;
|
|
30
|
+
openLog(open: boolean): void;
|
|
31
|
+
getToken(): string | undefined;
|
|
32
|
+
}
|
|
33
|
+
export default SocketClient;
|