@zgfe/business-lib 1.1.29-visual.6 → 1.1.29-visual.7

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.
@@ -7,5 +7,6 @@ declare const Apis: {
7
7
  queryPanelGroup: string;
8
8
  queryDatasetList: string;
9
9
  queryDatasetDetail: string;
10
+ getSocketToken: string;
10
11
  };
11
12
  export default Apis;
@@ -6,6 +6,7 @@ var Apis = {
6
6
  updatePanelTarget: '/apppanel/updateElemet.jsp',
7
7
  queryPanelGroup: '/apppanel/panels.jsp',
8
8
  queryDatasetList: '/zg/web/cdp/inner/dataset/list',
9
- queryDatasetDetail: '/zg/web/cdp/inner/dataset/detail'
9
+ queryDatasetDetail: '/zg/web/cdp/inner/dataset/detail',
10
+ getSocketToken: '/zg/web/v2/tracking/view/websocket/token'
10
11
  };
11
12
  export default Apis;
@@ -1,7 +1,8 @@
1
1
  import React, { ReactNode } from 'react';
2
+ import { AppInfoProps } from '../context';
2
3
  declare const DemoContent: React.FC<{
3
4
  children?: ReactNode;
4
5
  needMeta?: boolean;
5
- currentApp?: number;
6
+ currentApp?: AppInfoProps;
6
7
  }>;
7
8
  export default DemoContent;
@@ -82,10 +82,16 @@ var DemoContent = function DemoContent(_ref3) {
82
82
  setStore = _useState18[1];
83
83
  useEffect(function () {
84
84
  if (!needMeta || !currentApp) return;
85
- loadUserProps();
86
- loadEvents();
87
- loadEnvList();
88
- loadUserGroup();
85
+ if (currentApp.appsHasData && currentApp.appsHasData.length) {
86
+ loadUserProps();
87
+ loadEvents();
88
+ loadEnvList();
89
+ loadUserGroup();
90
+ } else {
91
+ setLoadEnv(false);
92
+ setLoadEvent(false);
93
+ setLoadUsers(false);
94
+ }
89
95
  }, [currentApp, needMeta]);
90
96
  useEffect(function () {
91
97
  if (loadEnv || loadEvent || loadUsers || loadUserGroups) return;
@@ -157,10 +163,7 @@ var DemoContent = function DemoContent(_ref3) {
157
163
  }
158
164
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BizGlobalDataContext.Provider, {
159
165
  value: {
160
- currentApp: {
161
- appId: currentApp,
162
- platform: 0
163
- },
166
+ currentApp: currentApp,
164
167
  eventGroupList: store === null || store === void 0 ? void 0 : store.eventGroupList,
165
168
  userPropList: store === null || store === void 0 ? void 0 : store.userPropList,
166
169
  eventEnvList: store === null || store === void 0 ? void 0 : store.envPropList,
@@ -1,8 +1,9 @@
1
- import React from 'react';
2
- import { DemoWrapper } from '@zgfe/business-lib';
1
+ import React, { useContext } from 'react';
2
+ import { DemoWrapper, BizGlobalDataContext } from '@zgfe/business-lib';
3
3
  export default (function () {
4
+ var ctx = useContext(BizGlobalDataContext);
4
5
  return /*#__PURE__*/React.createElement(DemoWrapper, {
5
- defaultApp: 3,
6
+ defaultApp: 332,
6
7
  needMeta: true
7
- }, "xxx");
8
+ }, JSON.stringify(ctx || {}));
8
9
  });
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
+ import { AppInfoProps } from '../context';
2
3
  declare const DemoHeader: React.FC<{
3
4
  defaultApp?: number;
4
- onChangeApp?: (appId: number) => void;
5
+ onChangeApp?: (app: AppInfoProps) => void;
6
+ onLoading?: (loading: boolean) => void;
5
7
  }>;
6
8
  export default DemoHeader;
@@ -9,7 +9,8 @@ import React, { useEffect, useState } from 'react';
9
9
  import request from '../utils/ajax';
10
10
  var DemoHeader = function DemoHeader(_ref) {
11
11
  var defaultApp = _ref.defaultApp,
12
- onChangeApp = _ref.onChangeApp;
12
+ onChangeApp = _ref.onChangeApp,
13
+ onLoading = _ref.onLoading;
13
14
  var _useState = useState([]),
14
15
  _useState2 = _slicedToArray(_useState, 2),
15
16
  appList = _useState2[0],
@@ -21,17 +22,25 @@ var DemoHeader = function DemoHeader(_ref) {
21
22
  useEffect(function () {
22
23
  queryAppList();
23
24
  }, []);
25
+ useEffect(function () {
26
+ if (onLoading) onLoading(loading);
27
+ }, [loading, appList]);
24
28
  function queryAppList() {
25
29
  setLoading(true);
26
30
  request('/analysis/api/common/proxy/data/v2ajaxGetDataByApp.jsp').then(function (res) {
27
31
  setAppList(res.applist);
28
- if (!defaultApp && res.applist.length) onChange(res.applist[0].id);
32
+ if (defaultApp) {
33
+ _onChange(res.applist.find(function (item) {
34
+ return item.id === defaultApp;
35
+ }));
36
+ }
37
+ if (!defaultApp && res.applist.length) _onChange(res.applist[0]);
29
38
  }).finally(function () {
30
39
  setLoading(false);
31
40
  });
32
41
  }
33
- function onChange(id) {
34
- if (onChangeApp) onChangeApp(id);
42
+ function _onChange(item) {
43
+ if (onChangeApp) onChangeApp(item);
35
44
  }
36
45
  if (loading) return /*#__PURE__*/React.createElement(Skeleton.Input, null);
37
46
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Select, {
@@ -41,7 +50,10 @@ var DemoHeader = function DemoHeader(_ref) {
41
50
  label: 'appName',
42
51
  value: 'id'
43
52
  },
44
- onChange: onChange,
53
+ onChange: function onChange(_id, app) {
54
+ console.log('默认应用', app);
55
+ _onChange(app);
56
+ },
45
57
  style: {
46
58
  width: '200px'
47
59
  }
@@ -20,14 +20,18 @@ var DemoWrapper = function DemoWrapper(_ref) {
20
20
  _useState2 = _slicedToArray(_useState, 2),
21
21
  loading = _useState2[0],
22
22
  setLoading = _useState2[1];
23
- var _useState3 = useState(false),
23
+ var _useState3 = useState(true),
24
24
  _useState4 = _slicedToArray(_useState3, 2),
25
- notLogin = _useState4[0],
26
- setNotLogin = _useState4[1];
27
- var _useState5 = useState(defaultApp),
25
+ appListLoading = _useState4[0],
26
+ setAppListLoading = _useState4[1];
27
+ var _useState5 = useState(false),
28
28
  _useState6 = _slicedToArray(_useState5, 2),
29
- appId = _useState6[0],
30
- setAppId = _useState6[1];
29
+ notLogin = _useState6[0],
30
+ setNotLogin = _useState6[1];
31
+ var _useState7 = useState(),
32
+ _useState8 = _slicedToArray(_useState7, 2),
33
+ app = _useState8[0],
34
+ setApp = _useState8[1];
31
35
  useEffect(function () {
32
36
  getCurrentUser();
33
37
  }, []);
@@ -53,15 +57,19 @@ var DemoWrapper = function DemoWrapper(_ref) {
53
57
  return /*#__PURE__*/React.createElement(Card, {
54
58
  title: /*#__PURE__*/React.createElement(DemoHeader, {
55
59
  defaultApp: defaultApp,
56
- onChangeApp: setAppId
60
+ onChangeApp: setApp,
61
+ onLoading: setAppListLoading
57
62
  }),
58
63
  className: className,
59
64
  bodyStyle: {
60
65
  background: '#FAFAFB'
61
66
  }
62
- }, /*#__PURE__*/React.createElement(DemoContent, {
63
- currentApp: appId,
64
- needMeta: needMeta
67
+ }, appListLoading ? /*#__PURE__*/React.createElement(Spin, {
68
+ tip: "\u5E94\u7528\u4FE1\u606F\u521D\u59CB\u5316\u4E2D"
69
+ }) : /*#__PURE__*/React.createElement(DemoContent, {
70
+ currentApp: app,
71
+ needMeta: needMeta,
72
+ key: app === null || app === void 0 ? void 0 : app.appId
65
73
  }, children));
66
74
  };
67
75
  export default DemoWrapper;
@@ -8,10 +8,11 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
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
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
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- import React, { useEffect, useRef, useState } from 'react';
11
+ import React, { useContext, useEffect, useRef, useState } from 'react';
12
12
  import { SocketClient } from '@zgfe/business-lib';
13
13
  import { Button, Card, Form, Input, notification } from 'antd';
14
14
  import styles from './index.less';
15
+ import { DemoWrapper, BizGlobalDataContext } from '@zgfe/business-lib';
15
16
  var ChatPanel = function ChatPanel(_ref) {
16
17
  var name = _ref.name,
17
18
  param = _ref.param;
@@ -29,8 +30,10 @@ var ChatPanel = function ChatPanel(_ref) {
29
30
  setOnline = _useState6[1];
30
31
  var formRef = useRef();
31
32
  var historyRef = useRef();
33
+ var _useContext = useContext(BizGlobalDataContext),
34
+ currentApp = _useContext.currentApp;
32
35
  useEffect(function () {
33
- setClient(new SocketClient('wss://rt2.zhugeio.com/eventtracking/ws', param));
36
+ setClient(new SocketClient('wss://rt2.zhugeio.com/eventtracking/ws', currentApp === null || currentApp === void 0 ? void 0 : currentApp.appKey, param));
34
37
  }, []);
35
38
  useEffect(function () {
36
39
  var _historyRef$current;
@@ -41,7 +44,6 @@ var ChatPanel = function ChatPanel(_ref) {
41
44
  client.openLog(true);
42
45
  client.onConnected(onConnected);
43
46
  client.onError(onError);
44
- client.onLogin(onLogin);
45
47
  client.on('offline', function () {
46
48
  setHistory(function (list) {
47
49
  return [].concat(_toConsumableArray(list), [{
@@ -67,17 +69,10 @@ var ChatPanel = function ChatPanel(_ref) {
67
69
  message: '连接成功'
68
70
  });
69
71
  }
70
- function onError() {
72
+ function onError(err) {
71
73
  notification.error({
72
- message: '连接失败'
73
- });
74
- }
75
- function onLogin() {
76
- setHistory(function (list) {
77
- return [].concat(_toConsumableArray(list), [{
78
- type: 'he',
79
- message: '登录成功'
80
- }]);
74
+ message: '连接失败',
75
+ description: err.message
81
76
  });
82
77
  }
83
78
  return /*#__PURE__*/React.createElement(Card, {
@@ -124,32 +119,21 @@ var ChatPanel = function ChatPanel(_ref) {
124
119
  }, online ? '下线' : '上线')))));
125
120
  };
126
121
  export default (function () {
127
- return /*#__PURE__*/React.createElement("div", {
122
+ var ctx = useContext(BizGlobalDataContext);
123
+ var currentApp = ctx.currentApp;
124
+ return /*#__PURE__*/React.createElement(DemoWrapper, null, /*#__PURE__*/React.createElement("div", {
128
125
  className: styles.container
129
126
  }, /*#__PURE__*/React.createElement(ChatPanel, {
130
127
  name: "\u5F20\u4E09",
131
128
  param: {
132
- id: 'eti8-4ilv-876r-1wr5',
133
- origin: 1,
134
- appId: '146',
135
- programId: 'zgej-3det-9edb-dje3',
136
- type: 3,
137
- payload: {
138
- unionid: 'hjadfhdskji884bdfd',
139
- username: 'zhangsan'
140
- }
129
+ appId: currentApp === null || currentApp === void 0 ? void 0 : currentApp.appId,
130
+ origin: 3
141
131
  }
142
132
  }), /*#__PURE__*/React.createElement(ChatPanel, {
143
133
  name: "\u674E\u56DB",
144
134
  param: {
145
- id: 'ueks-d8d2-njka-8742-2mdd',
146
- origin: 3,
147
- appId: '146',
148
- type: 3,
149
- payload: {
150
- unionid: 'web-unionid2132',
151
- username: 'zhangsan'
152
- }
135
+ appId: currentApp === null || currentApp === void 0 ? void 0 : currentApp.appId,
136
+ origin: 5
153
137
  }
154
- }));
138
+ })));
155
139
  });
@@ -7,13 +7,13 @@ declare class SocketClient {
7
7
  private catch;
8
8
  private showLog;
9
9
  private pingTimer?;
10
- constructor(url: string, params?: Record<string, any>);
10
+ private appkey?;
11
+ constructor(url: string, appkey: string, params?: Record<string, any>);
11
12
  emit(event: string, payload: SocketClientTypes.Message['data']['payload']): void;
12
13
  on(type: SocketClientTypes.EventType | string, handle: SocketClientTypes.Handler): void;
13
14
  onConnected(handle: SocketClientTypes.Handler): void;
14
15
  onDisconnected(handle: SocketClientTypes.Handler): void;
15
16
  onError(handle: SocketClientTypes.Handler): void;
16
- onLogin(handle: SocketClientTypes.Handler): void;
17
17
  private _onError;
18
18
  private _onClose;
19
19
  private _onOpen;
@@ -21,7 +21,7 @@ declare class SocketClient {
21
21
  private ping;
22
22
  removeAllListeners(): void;
23
23
  removeListener(event: string, handle?: SocketClientTypes.Handler): void;
24
- private login;
24
+ private getToken;
25
25
  open(url?: string, params?: Record<string, any>): void;
26
26
  close(): void;
27
27
  destroy(): void;
@@ -1,7 +1,7 @@
1
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; }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
5
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
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
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); }
@@ -14,9 +14,12 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
14
14
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
15
15
  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); }
16
16
  import { notification } from 'antd';
17
+ import _ from 'lodash';
18
+ import request from 'umi-request';
19
+ import Apis from '../constants/apis';
17
20
  import SocketClientTypes from './types';
18
21
  var SocketClient = /*#__PURE__*/function () {
19
- function SocketClient(url, params) {
22
+ function SocketClient(url, appkey, params) {
20
23
  _classCallCheck(this, SocketClient);
21
24
  this.client = void 0;
22
25
  this.url = void 0;
@@ -25,6 +28,8 @@ var SocketClient = /*#__PURE__*/function () {
25
28
  this.catch = [];
26
29
  this.showLog = false;
27
30
  this.pingTimer = void 0;
31
+ this.appkey = void 0;
32
+ this.appkey = appkey;
28
33
  this.url = url;
29
34
  this.params = params;
30
35
  this.open();
@@ -84,18 +89,13 @@ var SocketClient = /*#__PURE__*/function () {
84
89
  value: function onError(handle) {
85
90
  this.on(SocketClientTypes.EventType.error, handle);
86
91
  }
87
- }, {
88
- key: "onLogin",
89
- value: function onLogin(handle) {
90
- this.on(SocketClientTypes.EventType.login, handle);
91
- }
92
92
  }, {
93
93
  key: "_onError",
94
- value: function _onError(_event) {
94
+ value: function _onError(error) {
95
95
  var _this$listeners$error;
96
- this.log('error', 'socket连接异常');
96
+ this.log('error', 'socket连接异常', error);
97
97
  (_this$listeners$error = this.listeners['error']) === null || _this$listeners$error === void 0 ? void 0 : _this$listeners$error.forEach(function (handle) {
98
- handle.call(undefined);
98
+ handle.call(undefined, error);
99
99
  });
100
100
  }
101
101
  }, {
@@ -114,7 +114,6 @@ var SocketClient = /*#__PURE__*/function () {
114
114
  var _this$listeners$conne,
115
115
  _this = this;
116
116
  this.log('info', 'socket连接成功', event);
117
- this.login();
118
117
  (_this$listeners$conne = this.listeners['connected']) === null || _this$listeners$conne === void 0 ? void 0 : _this$listeners$conne.forEach(function (handle) {
119
118
  handle.call(undefined);
120
119
  });
@@ -130,38 +129,30 @@ var SocketClient = /*#__PURE__*/function () {
130
129
  }, {
131
130
  key: "onMessage",
132
131
  value: function onMessage(event) {
133
- var res_ = JSON.parse(event.data);
134
- if (res_.code) {
135
- var data = res_.data;
136
- if (res_.code === SocketClientTypes.ResponseCode.offline) {
137
- var _this$listeners$Socke;
138
- (_this$listeners$Socke = this.listeners[SocketClientTypes.EventType.offline]) === null || _this$listeners$Socke === void 0 ? void 0 : _this$listeners$Socke.forEach(function (handle) {
139
- handle.call(undefined, res_);
140
- });
141
- return;
132
+ var _this$listeners$Socke, _this$listeners$Socke2;
133
+ var res = JSON.parse(event.data);
134
+ if (res.code) {
135
+ switch (Number(res.code)) {
136
+ case SocketClientTypes.ResponseCode.offline:
137
+ (_this$listeners$Socke = this.listeners[SocketClientTypes.EventType.offline]) === null || _this$listeners$Socke === void 0 ? void 0 : _this$listeners$Socke.forEach(function (handle) {
138
+ handle.call(undefined, res);
139
+ });
140
+ break;
141
+ case SocketClientTypes.ResponseCode.exist:
142
+ (_this$listeners$Socke2 = this.listeners[SocketClientTypes.EventType.exist]) === null || _this$listeners$Socke2 === void 0 ? void 0 : _this$listeners$Socke2.forEach(function (handle) {
143
+ handle.call(undefined, res);
144
+ });
145
+ break;
146
+ case SocketClientTypes.ResponseCode.paramError:
147
+ this._onError(new Error('参数缺失或错误'));
142
148
  }
143
- if (res_.code === SocketClientTypes.ResponseCode.exist) {
144
- var _this$listeners$Socke2;
145
- (_this$listeners$Socke2 = this.listeners[SocketClientTypes.EventType.exist]) === null || _this$listeners$Socke2 === void 0 ? void 0 : _this$listeners$Socke2.forEach(function (handle) {
146
- handle.call(undefined, res_);
147
- });
148
- return;
149
- }
150
- if (data.type === SocketClientTypes.RequestType.login) {
151
- var _this$listeners$Socke3;
152
- this.log('info', '登录成功');
153
- (_this$listeners$Socke3 = this.listeners[SocketClientTypes.EventType.login]) === null || _this$listeners$Socke3 === void 0 ? void 0 : _this$listeners$Socke3.forEach(function (handle) {
154
- handle.call(undefined, res_);
155
- });
156
- return;
157
- }
158
- } else if (res_.type === SocketClientTypes.RequestType.pong) {
149
+ } else if (res.type === SocketClientTypes.RequestType.pong) {
159
150
  return;
160
151
  } else {
161
- var _data = res_.data;
162
- if (this.listeners[_data.event]) {
163
- this.listeners[_data.event].forEach(function (handle) {
164
- handle.call(undefined, _data.payload);
152
+ var data = res.data;
153
+ if (this.listeners[data.event]) {
154
+ this.listeners[data.event].forEach(function (handle) {
155
+ handle.call(undefined, data.payload);
165
156
  });
166
157
  }
167
158
  }
@@ -197,31 +188,70 @@ var SocketClient = /*#__PURE__*/function () {
197
188
  }
198
189
  }
199
190
  }, {
200
- key: "login",
201
- value: function login() {
202
- var _this$client3;
203
- this.log('info', '开始登录', this.params);
204
- (_this$client3 = this.client) === null || _this$client3 === void 0 ? void 0 : _this$client3.send(JSON.stringify(_objectSpread({
205
- type: SocketClientTypes.RequestType.normal
206
- }, this.params)));
207
- }
191
+ key: "getToken",
192
+ value: function () {
193
+ var _getToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
194
+ var res;
195
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
196
+ while (1) switch (_context.prev = _context.next) {
197
+ case 0:
198
+ _context.next = 2;
199
+ return request(Apis.getSocketToken, {
200
+ method: 'get',
201
+ params: {
202
+ appKey: this.appkey
203
+ }
204
+ });
205
+ case 2:
206
+ res = _context.sent;
207
+ return _context.abrupt("return", res);
208
+ case 4:
209
+ case "end":
210
+ return _context.stop();
211
+ }
212
+ }, _callee, this);
213
+ }));
214
+ function getToken() {
215
+ return _getToken.apply(this, arguments);
216
+ }
217
+ return getToken;
218
+ }()
208
219
  }, {
209
220
  key: "open",
210
221
  value: function open(url, params) {
211
- this.params = params || this.params;
212
- if (this.client) this.close();
213
- var client = new WebSocket(url || this.url);
214
- this.client = client;
215
- client.onmessage = this.onMessage.bind(this);
216
- client.onerror = this._onError.bind(this);
217
- client.onclose = this._onClose.bind(this);
218
- client.onopen = this._onOpen.bind(this);
222
+ var _this4 = this;
223
+ this.getToken().then(function (res) {
224
+ if (!res) {
225
+ throw new Error('获取socket授权失败');
226
+ }
227
+ _this4.params = params || _this4.params;
228
+ if (_this4.client) _this4.close();
229
+ var paramUrl = [];
230
+ if (_this4.params) {
231
+ Object.keys(_this4.params || {}).forEach(function (key) {
232
+ if (_.isObject(_this4.params[key]) || _.isArray(_this4.params[key])) {
233
+ paramUrl.push("".concat(key, "=").concat(JSON.stringify(_this4.params[key])));
234
+ } else {
235
+ paramUrl.push("".concat(key, "=").concat(_this4.params[key]));
236
+ }
237
+ });
238
+ }
239
+ var client = new WebSocket("".concat(url || _this4.url, "?").concat(paramUrl.join('&')));
240
+ _this4.client = client;
241
+ client.onmessage = _this4.onMessage.bind(_this4);
242
+ client.onerror = _this4._onError.bind(_this4);
243
+ client.onclose = _this4._onClose.bind(_this4);
244
+ client.onopen = _this4._onOpen.bind(_this4);
245
+ }).catch(function (err) {
246
+ _this4.log('error', 'socket获取token信息异常');
247
+ _this4._onError(err);
248
+ });
219
249
  }
220
250
  }, {
221
251
  key: "close",
222
252
  value: function close() {
223
- var _this$client4;
224
- (_this$client4 = this.client) === null || _this$client4 === void 0 ? void 0 : _this$client4.close();
253
+ var _this$client3;
254
+ (_this$client3 = this.client) === null || _this$client3 === void 0 ? void 0 : _this$client3.close();
225
255
  this.log('info', '关闭socket连接');
226
256
  }
227
257
  }, {
@@ -3,7 +3,6 @@ declare namespace SocketClientTypes {
3
3
  connected = "connected",
4
4
  disconnected = "disconnected",
5
5
  error = "error",
6
- login = "login",
7
6
  offline = "offline",
8
7
  exist = "exist"
9
8
  }
@@ -11,13 +10,13 @@ declare namespace SocketClientTypes {
11
10
  common = 0,
12
11
  ping = 1,
13
12
  pong = 2,
14
- login = 3,
15
13
  normal = 5,
16
14
  img = 6
17
15
  }
18
16
  enum ResponseCode {
19
- offline = "109001",
20
- exist = "109002"
17
+ offline = 109001,
18
+ exist = 109002,
19
+ paramError = 109005
21
20
  }
22
21
  type Message = {
23
22
  type: RequestType;
@@ -5,7 +5,6 @@ var SocketClientTypes;
5
5
  EventType["connected"] = "connected";
6
6
  EventType["disconnected"] = "disconnected";
7
7
  EventType["error"] = "error";
8
- EventType["login"] = "login";
9
8
  EventType["offline"] = "offline";
10
9
  EventType["exist"] = "exist";
11
10
  })(EventType = SocketClientTypes.EventType || (SocketClientTypes.EventType = {}));
@@ -14,14 +13,14 @@ var SocketClientTypes;
14
13
  RequestType[RequestType["common"] = 0] = "common";
15
14
  RequestType[RequestType["ping"] = 1] = "ping";
16
15
  RequestType[RequestType["pong"] = 2] = "pong";
17
- RequestType[RequestType["login"] = 3] = "login";
18
16
  RequestType[RequestType["normal"] = 5] = "normal";
19
17
  RequestType[RequestType["img"] = 6] = "img";
20
18
  })(RequestType = SocketClientTypes.RequestType || (SocketClientTypes.RequestType = {}));
21
19
  var ResponseCode;
22
20
  (function (ResponseCode) {
23
- ResponseCode["offline"] = "109001";
24
- ResponseCode["exist"] = "109002";
21
+ ResponseCode[ResponseCode["offline"] = 109001] = "offline";
22
+ ResponseCode[ResponseCode["exist"] = 109002] = "exist";
23
+ ResponseCode[ResponseCode["paramError"] = 109005] = "paramError";
25
24
  })(ResponseCode = SocketClientTypes.ResponseCode || (SocketClientTypes.ResponseCode = {}));
26
25
  })(SocketClientTypes || (SocketClientTypes = {}));
27
26
  export default SocketClientTypes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgfe/business-lib",
3
- "version": "1.1.29-visual.6",
3
+ "version": "1.1.29-visual.7",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -59,5 +59,5 @@
59
59
  "react": "^16.12.0 || ^17.0.0",
60
60
  "yorkie": "^2.0.0"
61
61
  },
62
- "gitHead": "afdafe3bb289a223ac879876d120c9493a83fe3f"
62
+ "gitHead": "0d22608428c02690fec4f51be172d62b7b979cb6"
63
63
  }