@yysports/tools 1.0.7 → 2.0.0
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/dist/Track/core/auth.d.ts +16 -0
- package/dist/Track/core/auth.js +83 -0
- package/dist/Track/core/constants.d.ts +14 -0
- package/dist/Track/core/constants.js +25 -0
- package/dist/Track/core/envelope.d.ts +9 -0
- package/dist/Track/core/envelope.js +54 -0
- package/dist/Track/core/instance.d.ts +108 -0
- package/dist/Track/core/instance.js +365 -0
- package/dist/Track/core/lifecycle.d.ts +18 -0
- package/dist/Track/core/lifecycle.js +59 -0
- package/dist/Track/core/profile.d.ts +5 -0
- package/dist/Track/core/profile.js +30 -0
- package/dist/Track/core/queue.d.ts +13 -0
- package/dist/Track/core/queue.js +36 -0
- package/dist/Track/core/replay.d.ts +17 -0
- package/dist/Track/core/replay.js +117 -0
- package/dist/Track/core/router.d.ts +6 -0
- package/dist/Track/core/router.js +15 -0
- package/dist/Track/core/system.d.ts +14 -0
- package/dist/Track/core/system.js +36 -0
- package/dist/Track/core/transport.d.ts +18 -0
- package/dist/Track/core/transport.js +151 -0
- package/dist/Track/index.d.ts +31 -28
- package/dist/Track/index.js +212 -392
- package/dist/Utils/common.js +5 -6
- package/dist/Utils/route.js +1 -6
- package/dist/Utils/url.js +1 -3
- package/dist/Utils/wx.js +2 -7
- package/dist/interfaces/track.interface.d.ts +14 -4
- package/lib/Track/core/auth.d.ts +16 -0
- package/lib/Track/core/auth.js +67 -0
- package/lib/Track/core/constants.d.ts +14 -0
- package/lib/Track/core/constants.js +56 -0
- package/lib/Track/core/envelope.d.ts +9 -0
- package/lib/Track/core/envelope.js +61 -0
- package/lib/Track/core/instance.d.ts +108 -0
- package/lib/Track/core/instance.js +257 -0
- package/lib/Track/core/lifecycle.d.ts +18 -0
- package/lib/Track/core/lifecycle.js +74 -0
- package/lib/Track/core/profile.d.ts +5 -0
- package/lib/Track/core/profile.js +47 -0
- package/lib/Track/core/queue.d.ts +13 -0
- package/lib/Track/core/queue.js +49 -0
- package/lib/Track/core/replay.d.ts +17 -0
- package/lib/Track/core/replay.js +131 -0
- package/lib/Track/core/router.d.ts +6 -0
- package/lib/Track/core/router.js +39 -0
- package/lib/Track/core/system.d.ts +14 -0
- package/lib/Track/core/system.js +53 -0
- package/lib/Track/core/transport.d.ts +18 -0
- package/lib/Track/core/transport.js +115 -0
- package/lib/Track/index.d.ts +31 -28
- package/lib/Track/index.js +126 -312
- package/lib/Utils/common.js +4 -6
- package/lib/interfaces/track.interface.d.ts +14 -4
- package/package.json +11 -10
package/dist/Track/index.js
CHANGED
|
@@ -1,433 +1,253 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!config) {
|
|
40
|
-
throw new Error('请配置Track');
|
|
41
|
-
}
|
|
42
|
-
if (!config.domain) {
|
|
43
|
-
throw new Error('请设置信息采集中心域名');
|
|
44
|
-
}
|
|
45
|
-
if (!config.appId) {
|
|
46
|
-
throw new Error('请设置appId');
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
5
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
6
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
7
|
+
/**
|
|
8
|
+
* 新版多实例埋点入口
|
|
9
|
+
* 提供统一 createTracker(config, { lazy }) API
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { TrackerInstance } from "./core/instance";
|
|
13
|
+
|
|
14
|
+
// ---------------- 多实例工厂 ----------------
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 创建埋点实例
|
|
18
|
+
* @param config TrackConfig
|
|
19
|
+
* @param options { lazy } 是否延迟 init(默认 false)
|
|
20
|
+
* - lazy=false: 返回 Promise<TrackerInstance>(已完成 init)
|
|
21
|
+
* - lazy=true: 返回未初始化实例 (TrackerInstance),需外部手动调用 init()
|
|
22
|
+
*/
|
|
23
|
+
export function createTracker(config, options) {
|
|
24
|
+
var _ref = options || {},
|
|
25
|
+
lazy = _ref.lazy;
|
|
26
|
+
var ins = new TrackerInstance(config);
|
|
27
|
+
if (lazy) return ins;
|
|
28
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
29
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
30
|
+
while (1) switch (_context.prev = _context.next) {
|
|
31
|
+
case 0:
|
|
32
|
+
_context.next = 2;
|
|
33
|
+
return ins.init();
|
|
34
|
+
case 2:
|
|
35
|
+
return _context.abrupt("return", ins);
|
|
36
|
+
case 3:
|
|
37
|
+
case "end":
|
|
38
|
+
return _context.stop();
|
|
47
39
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
40
|
+
}, _callee);
|
|
41
|
+
}))();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ---------------- 静态外观(兼容方便使用) ----------------
|
|
45
|
+
var TrackFacade = /*#__PURE__*/function () {
|
|
46
|
+
function TrackFacade() {
|
|
47
|
+
_classCallCheck(this, TrackFacade);
|
|
48
|
+
}
|
|
49
|
+
_createClass(TrackFacade, null, [{
|
|
50
|
+
key: "init",
|
|
51
|
+
value: ( /** 初始化(必须先调用一次)。重复调用直接返回已存在实例 */function () {
|
|
52
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(config) {
|
|
53
|
+
var _this = this;
|
|
54
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
55
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
59
56
|
case 0:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (data.length) {
|
|
64
|
-
debug && console.debug('[track:debug] push data', data);
|
|
65
|
-
navigator.sendBeacon("".concat(this.config.domain, "/pousheng-guard/api/analysis/track"), compressed);
|
|
57
|
+
if (!this._instance) {
|
|
58
|
+
_context3.next = 2;
|
|
59
|
+
break;
|
|
66
60
|
}
|
|
61
|
+
return _context3.abrupt("return", this._instance);
|
|
62
|
+
case 2:
|
|
63
|
+
if (!this._initPromise) {
|
|
64
|
+
this._initPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
65
|
+
var ins;
|
|
66
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
67
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
68
|
+
case 0:
|
|
69
|
+
ins = new TrackerInstance(config);
|
|
70
|
+
_context2.next = 3;
|
|
71
|
+
return ins.init();
|
|
72
|
+
case 3:
|
|
73
|
+
_this._instance = ins;
|
|
74
|
+
// 回放预队列
|
|
75
|
+
_this._queue.forEach(function (_ref4) {
|
|
76
|
+
var _ref5;
|
|
77
|
+
var method = _ref4.method,
|
|
78
|
+
args = _ref4.args;
|
|
79
|
+
return (_ref5 = ins)[method].apply(_ref5, _toConsumableArray(args));
|
|
80
|
+
});
|
|
81
|
+
_this._queue.length = 0;
|
|
82
|
+
return _context2.abrupt("return", ins);
|
|
83
|
+
case 7:
|
|
84
|
+
case "end":
|
|
85
|
+
return _context2.stop();
|
|
86
|
+
}
|
|
87
|
+
}, _callee2);
|
|
88
|
+
}))();
|
|
89
|
+
}
|
|
90
|
+
return _context3.abrupt("return", this._initPromise);
|
|
67
91
|
case 4:
|
|
68
92
|
case "end":
|
|
69
|
-
return
|
|
93
|
+
return _context3.stop();
|
|
70
94
|
}
|
|
71
|
-
},
|
|
95
|
+
}, _callee3, this);
|
|
72
96
|
}));
|
|
73
|
-
function
|
|
74
|
-
return
|
|
97
|
+
function init(_x) {
|
|
98
|
+
return _init.apply(this, arguments);
|
|
75
99
|
}
|
|
76
|
-
return
|
|
77
|
-
}()
|
|
100
|
+
return init;
|
|
101
|
+
}() /** 是否已就绪 */)
|
|
78
102
|
}, {
|
|
79
|
-
key: "
|
|
80
|
-
value: function
|
|
81
|
-
|
|
82
|
-
var autoReportError = this.config.autoReportError;
|
|
83
|
-
if (autoReportError) {
|
|
84
|
-
addEventListener('error', function (event) {
|
|
85
|
-
var message = event.message,
|
|
86
|
-
filename = event.filename;
|
|
87
|
-
var errorInfo = {
|
|
88
|
-
message: message,
|
|
89
|
-
fileName: filename
|
|
90
|
-
};
|
|
91
|
-
_this.errorLog(errorInfo);
|
|
92
|
-
console.error('[track:error] catch error', event);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
//关闭页面时,发送剩余的埋点数据
|
|
97
|
-
addEventListener('visibilitychange', function () {
|
|
98
|
-
if (document.visibilityState === 'hidden') {
|
|
99
|
-
_this.send();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
103
|
+
key: "isReady",
|
|
104
|
+
value: function isReady() {
|
|
105
|
+
return !!this._instance;
|
|
102
106
|
}
|
|
103
107
|
|
|
104
|
-
|
|
108
|
+
/** 获取内部实例(未初始化时抛错) */
|
|
105
109
|
}, {
|
|
106
|
-
key: "
|
|
107
|
-
value: function
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
localStorage.setItem('__IMEI__', generateRandomString(16));
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
innerHeight: innerHeight,
|
|
114
|
-
innerWidth: innerWidth,
|
|
115
|
-
href: location.href,
|
|
116
|
-
systemTime: new Date(),
|
|
117
|
-
IMEI: localStorage.getItem('__IMEI__')
|
|
118
|
-
};
|
|
110
|
+
key: "getInstance",
|
|
111
|
+
value: function getInstance() {
|
|
112
|
+
if (!this._instance) throw new Error('Track 未初始化,请先调用 Track.init(config)');
|
|
113
|
+
return this._instance;
|
|
119
114
|
}
|
|
120
115
|
|
|
121
|
-
|
|
116
|
+
/** 延迟调用帮助:未 init 时先入队 */
|
|
122
117
|
}, {
|
|
123
|
-
key: "
|
|
124
|
-
value: function
|
|
125
|
-
var
|
|
126
|
-
|
|
127
|
-
userProfile.userId = '';
|
|
118
|
+
key: "invoke",
|
|
119
|
+
value: function invoke(method) {
|
|
120
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
121
|
+
args[_key - 1] = arguments[_key];
|
|
128
122
|
}
|
|
129
|
-
if (
|
|
130
|
-
|
|
123
|
+
if (this._instance) {
|
|
124
|
+
var _ref6;
|
|
125
|
+
(_ref6 = this._instance)[method].apply(_ref6, args);
|
|
126
|
+
} else if (this._initPromise) {
|
|
127
|
+
// 初始化进行中,进入队列
|
|
128
|
+
this._queue.push({
|
|
129
|
+
method: method,
|
|
130
|
+
args: args
|
|
131
|
+
});
|
|
132
|
+
} else {
|
|
133
|
+
// 尚未开始 init,仍入队,提示一次
|
|
134
|
+
this._queue.push({
|
|
135
|
+
method: method,
|
|
136
|
+
args: args
|
|
137
|
+
});
|
|
138
|
+
if (!this._warned) {
|
|
139
|
+
console.warn('[track] 在 Track.init 前调用了日志方法,已暂存至初始化后回放');
|
|
140
|
+
this._warned = true;
|
|
141
|
+
}
|
|
131
142
|
}
|
|
132
|
-
return userProfile;
|
|
133
143
|
}
|
|
134
144
|
|
|
135
|
-
|
|
145
|
+
/**
|
|
146
|
+
* 发送事件日志(通用事件)
|
|
147
|
+
* - 若未初始化:自动排队等待 init 完成后回放
|
|
148
|
+
*/
|
|
136
149
|
}, {
|
|
137
|
-
key: "
|
|
138
|
-
value: function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
// 初始化权限中心数据
|
|
143
|
-
}, {
|
|
144
|
-
key: "initAuthCenterData",
|
|
145
|
-
value: function () {
|
|
146
|
-
var _initAuthCenterData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
|
|
147
|
-
var getAuth, menuBuild, getDataScopeZonePermissions, menuNameMap, routes, authCenterApi, _yield$Promise$all, _yield$Promise$all2, _yield$Promise$all2$, authInfo, _yield$Promise$all2$2, menuData, dataScopeZonePermissions, _ref2, _ref2$user, user, _ref2$roles, roles, dataScopeRoles, restUser, isAdmin, accessPage, routesMap, authCenterUserProfile;
|
|
148
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
149
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
150
|
-
case 0:
|
|
151
|
-
getAuth = _ref.getAuth, menuBuild = _ref.menuBuild, getDataScopeZonePermissions = _ref.getDataScopeZonePermissions, menuNameMap = _ref.menuNameMap, routes = _ref.routes;
|
|
152
|
-
authCenterApi = []; // 获取用户权限
|
|
153
|
-
if (getAuth) {
|
|
154
|
-
authCenterApi.push(getAuth);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// 获取权限中心配置的菜单及按钮
|
|
158
|
-
if (menuBuild) {
|
|
159
|
-
authCenterApi.push(menuBuild);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// 获取权限中心配置的区部数据权限
|
|
163
|
-
if (getDataScopeZonePermissions) {
|
|
164
|
-
authCenterApi.push(getDataScopeZonePermissions);
|
|
165
|
-
}
|
|
166
|
-
_context2.next = 7;
|
|
167
|
-
return Promise.all(authCenterApi.map(function (v) {
|
|
168
|
-
if (v) {
|
|
169
|
-
return v();
|
|
170
|
-
} else {
|
|
171
|
-
return Promise.resolve();
|
|
172
|
-
}
|
|
173
|
-
}));
|
|
174
|
-
case 7:
|
|
175
|
-
_yield$Promise$all = _context2.sent;
|
|
176
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
|
|
177
|
-
_yield$Promise$all2$ = _yield$Promise$all2[0];
|
|
178
|
-
authInfo = _yield$Promise$all2$ === void 0 ? {} : _yield$Promise$all2$;
|
|
179
|
-
_yield$Promise$all2$2 = _yield$Promise$all2[1];
|
|
180
|
-
menuData = _yield$Promise$all2$2 === void 0 ? [] : _yield$Promise$all2$2;
|
|
181
|
-
dataScopeZonePermissions = _yield$Promise$all2[2];
|
|
182
|
-
_ref2 = authInfo || {}, _ref2$user = _ref2.user, user = _ref2$user === void 0 ? {} : _ref2$user, _ref2$roles = _ref2.roles, roles = _ref2$roles === void 0 ? [] : _ref2$roles;
|
|
183
|
-
dataScopeRoles = user.roles, restUser = _objectWithoutProperties(user, _excluded); // 权限中心的用户信息
|
|
184
|
-
isAdmin = roles.includes('admin'); // 当前用户所拥有的所有页面权限
|
|
185
|
-
accessPage = []; // 获取本地菜单信息映射
|
|
186
|
-
if (routes) {
|
|
187
|
-
routesMap = getRoutesMap(routes, menuNameMap);
|
|
188
|
-
routesMap.forEach(function (value) {
|
|
189
|
-
var access = value.access;
|
|
190
|
-
if (access.length === 0) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (isAdmin) {
|
|
194
|
-
accessPage.push.apply(accessPage, _toConsumableArray(access));
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
access.forEach(function (key) {
|
|
198
|
-
if (roles.includes(key)) {
|
|
199
|
-
accessPage.push(key);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
this.routesMap = routesMap;
|
|
204
|
-
}
|
|
205
|
-
this.authMap = getAuthMapByAuthCenter(menuData);
|
|
206
|
-
authCenterUserProfile = _objectSpread(_objectSpread({}, restUser), {}, {
|
|
207
|
-
dataScopeRoles: dataScopeRoles,
|
|
208
|
-
roles: roles,
|
|
209
|
-
accessPage: accessPage
|
|
210
|
-
});
|
|
211
|
-
if (dataScopeZonePermissions) {
|
|
212
|
-
Object.assign(authCenterUserProfile, {
|
|
213
|
-
dataScopeZonePermissions: dataScopeZonePermissions
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
this.authCenterUserProfile = authCenterUserProfile;
|
|
217
|
-
return _context2.abrupt("return", authCenterUserProfile);
|
|
218
|
-
case 24:
|
|
219
|
-
case "end":
|
|
220
|
-
return _context2.stop();
|
|
221
|
-
}
|
|
222
|
-
}, _callee2, this);
|
|
223
|
-
}));
|
|
224
|
-
function initAuthCenterData(_x) {
|
|
225
|
-
return _initAuthCenterData.apply(this, arguments);
|
|
150
|
+
key: "eventLog",
|
|
151
|
+
value: function eventLog() {
|
|
152
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
153
|
+
args[_key2] = arguments[_key2];
|
|
226
154
|
}
|
|
227
|
-
|
|
228
|
-
}
|
|
155
|
+
this.invoke.apply(this, ['eventLog'].concat(args));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 发送访问/页面曝光日志
|
|
159
|
+
* - 用于记录页面 / 场景进入等行为
|
|
160
|
+
*/
|
|
229
161
|
}, {
|
|
230
|
-
key: "
|
|
231
|
-
value: function () {
|
|
232
|
-
var
|
|
233
|
-
|
|
234
|
-
var userProfile, menuNameMap, routes, getAuth, menuBuild, getDataScopeZonePermissions, restConfig, currentUserProfile, _this$authCenterUserP;
|
|
235
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
236
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
237
|
-
case 0:
|
|
238
|
-
userProfile = _ref3.userProfile, menuNameMap = _ref3.menuNameMap, routes = _ref3.routes, getAuth = _ref3.getAuth, menuBuild = _ref3.menuBuild, getDataScopeZonePermissions = _ref3.getDataScopeZonePermissions, restConfig = _objectWithoutProperties(_ref3, _excluded2);
|
|
239
|
-
this.checkConfig(restConfig);
|
|
240
|
-
this.config = restConfig;
|
|
241
|
-
_context3.next = 5;
|
|
242
|
-
return this.initAuthCenterData({
|
|
243
|
-
getAuth: getAuth,
|
|
244
|
-
menuBuild: menuBuild,
|
|
245
|
-
getDataScopeZonePermissions: getDataScopeZonePermissions,
|
|
246
|
-
menuNameMap: menuNameMap,
|
|
247
|
-
routes: routes
|
|
248
|
-
});
|
|
249
|
-
case 5:
|
|
250
|
-
currentUserProfile = {}; // 如果对接了权限中心,取权限中心的用户信息
|
|
251
|
-
if (this.authCenterUserProfile.userName) {
|
|
252
|
-
Object.assign(currentUserProfile, {
|
|
253
|
-
userId: this.authCenterUserProfile.userName,
|
|
254
|
-
userName: this.authCenterUserProfile.nickName,
|
|
255
|
-
orgCode: this.authCenterUserProfile.orgCode,
|
|
256
|
-
orgTitle: this.authCenterUserProfile.orgTitle,
|
|
257
|
-
dataScopeRoles: (_this$authCenterUserP = this.authCenterUserProfile.dataScopeRoles) === null || _this$authCenterUserP === void 0 ? void 0 : _this$authCenterUserP.map(function (role) {
|
|
258
|
-
return role.name;
|
|
259
|
-
}).join(',')
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// 传入区部数据权限接口时,设置区部权限数据
|
|
264
|
-
if (this.authCenterUserProfile.dataScopeZonePermissions && ((_this$authCenterUserP2 = this.authCenterUserProfile.dataScopeZonePermissions) === null || _this$authCenterUserP2 === void 0 || (_this$authCenterUserP2 = _this$authCenterUserP2.list) === null || _this$authCenterUserP2 === void 0 ? void 0 : _this$authCenterUserP2.length) > 0) {
|
|
265
|
-
// 提取出所有 zoneId
|
|
266
|
-
Object.assign(currentUserProfile, {
|
|
267
|
-
dataScopeZonePermissions: this.authCenterUserProfile.dataScopeZonePermissions.list.map(function (item) {
|
|
268
|
-
return item.list.map(function (zone) {
|
|
269
|
-
return zone.zoneId;
|
|
270
|
-
}).join(',');
|
|
271
|
-
}).join(',')
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
if (userProfile) {
|
|
275
|
-
Object.assign(currentUserProfile, userProfile);
|
|
276
|
-
}
|
|
277
|
-
this.setUserProfile(currentUserProfile);
|
|
278
|
-
this.mountAutoTask();
|
|
279
|
-
|
|
280
|
-
// 注册应用版本
|
|
281
|
-
this.registerAppInfo();
|
|
282
|
-
return _context3.abrupt("return", this.authCenterUserProfile);
|
|
283
|
-
case 13:
|
|
284
|
-
case "end":
|
|
285
|
-
return _context3.stop();
|
|
286
|
-
}
|
|
287
|
-
}, _callee3, this);
|
|
288
|
-
}));
|
|
289
|
-
function init(_x2) {
|
|
290
|
-
return _init.apply(this, arguments);
|
|
162
|
+
key: "visitLog",
|
|
163
|
+
value: function visitLog() {
|
|
164
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
165
|
+
args[_key3] = arguments[_key3];
|
|
291
166
|
}
|
|
292
|
-
|
|
293
|
-
}() // 注册更新应用信息
|
|
294
|
-
}, {
|
|
295
|
-
key: "registerAppInfo",
|
|
296
|
-
value: function registerAppInfo() {
|
|
297
|
-
var appId = this.config.appId;
|
|
298
|
-
navigator.sendBeacon("".concat(this.config.domain, "/pousheng-guard/api/conf/updateAppVersion"), pako.deflate(JSON.stringify({
|
|
299
|
-
appId: appId,
|
|
300
|
-
version: version
|
|
301
|
-
})));
|
|
167
|
+
this.invoke.apply(this, ['visitLog'].concat(args));
|
|
302
168
|
}
|
|
303
|
-
|
|
304
|
-
|
|
169
|
+
/**
|
|
170
|
+
* 发送错误日志
|
|
171
|
+
* - 适用于运行时异常、资源加载失败、接口异常包装等
|
|
172
|
+
*/
|
|
305
173
|
}, {
|
|
306
|
-
key: "
|
|
307
|
-
value: function
|
|
308
|
-
var
|
|
309
|
-
|
|
310
|
-
var config = this.config;
|
|
311
|
-
this.checkConfig(config);
|
|
312
|
-
var reqData = _objectSpread(_objectSpread(_objectSpread({}, this.getSystemProfile()), this.getUserProfile()), {}, {
|
|
313
|
-
type: type,
|
|
314
|
-
appId: config.appId,
|
|
315
|
-
log: JSON.stringify(log)
|
|
316
|
-
});
|
|
317
|
-
this.trackQueue.push(reqData);
|
|
318
|
-
if (this.trackQueue.length > 4) {
|
|
319
|
-
this.send();
|
|
174
|
+
key: "errorLog",
|
|
175
|
+
value: function errorLog() {
|
|
176
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
177
|
+
args[_key4] = arguments[_key4];
|
|
320
178
|
}
|
|
179
|
+
this.invoke.apply(this, ['errorLog'].concat(args));
|
|
321
180
|
}
|
|
322
|
-
|
|
323
|
-
|
|
181
|
+
/**
|
|
182
|
+
* 发送接口调用相关日志
|
|
183
|
+
* - 记录接口耗时 / 结果状态
|
|
184
|
+
*/
|
|
324
185
|
}, {
|
|
325
|
-
key: "
|
|
326
|
-
value: function
|
|
327
|
-
var
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
return pathname.replace(base, '/');
|
|
186
|
+
key: "apiLog",
|
|
187
|
+
value: function apiLog() {
|
|
188
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
189
|
+
args[_key5] = arguments[_key5];
|
|
190
|
+
}
|
|
191
|
+
this.invoke.apply(this, ['apiLog'].concat(args));
|
|
332
192
|
}
|
|
333
|
-
|
|
334
|
-
|
|
193
|
+
/**
|
|
194
|
+
* 强制立即 flush 已缓冲的日志(若实例策略存在缓冲)
|
|
195
|
+
*/
|
|
335
196
|
}, {
|
|
336
|
-
key: "
|
|
337
|
-
value: function
|
|
338
|
-
|
|
339
|
-
|
|
197
|
+
key: "flush",
|
|
198
|
+
value: function flush() {
|
|
199
|
+
if (!this._instance) return;
|
|
200
|
+
this._instance.flush();
|
|
340
201
|
}
|
|
341
|
-
|
|
342
|
-
|
|
202
|
+
/**
|
|
203
|
+
* 销毁当前单例实例
|
|
204
|
+
* - 停止上报 / 释放资源
|
|
205
|
+
* - 再次使用需重新 init
|
|
206
|
+
*/
|
|
343
207
|
}, {
|
|
344
|
-
key: "
|
|
345
|
-
value: function
|
|
346
|
-
this.
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
208
|
+
key: "destroy",
|
|
209
|
+
value: function destroy() {
|
|
210
|
+
if (!this._instance) return;
|
|
211
|
+
this._instance.destroy();
|
|
212
|
+
this._instance = null;
|
|
213
|
+
this._initPromise = null;
|
|
350
214
|
}
|
|
351
|
-
|
|
352
|
-
|
|
215
|
+
/**
|
|
216
|
+
* 设置用户画像 / 用户基础属性
|
|
217
|
+
* - 若在 init 前调用:会延迟到实例 ready 后再真正执行
|
|
218
|
+
*/
|
|
353
219
|
}, {
|
|
354
|
-
key: "
|
|
355
|
-
value: function
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
220
|
+
key: "setUserProfile",
|
|
221
|
+
value: function setUserProfile(profile) {
|
|
222
|
+
if (!this._instance) {
|
|
223
|
+
// 允许提前设置,将其转换为 eventLog 之前的一个补丁:加入队列尾部一个函数式调用
|
|
224
|
+
this._queue.push({
|
|
225
|
+
method: 'eventLog',
|
|
226
|
+
args: []
|
|
227
|
+
}); // 占位避免丢失顺序
|
|
228
|
+
// 等 init 后再真正 set(用回放后 hook)
|
|
229
|
+
var prevInit = this._initPromise;
|
|
230
|
+
if (prevInit) {
|
|
231
|
+
prevInit.then(function (ins) {
|
|
232
|
+
return ins.setUserProfile(profile);
|
|
233
|
+
});
|
|
366
234
|
}
|
|
367
|
-
} else {
|
|
368
|
-
Object.assign(copyEventLog, _eventLog);
|
|
369
|
-
}
|
|
370
|
-
if (!copyEventLog.module) {
|
|
371
|
-
var routeNames = this.getPageModuleName();
|
|
372
|
-
copyEventLog.module = (routeNames === null || routeNames === void 0 ? void 0 : routeNames.join('-')) || '-';
|
|
373
|
-
}
|
|
374
|
-
this.pushQueue({
|
|
375
|
-
log: copyEventLog,
|
|
376
|
-
type: 'event'
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// 推送页面访问日志
|
|
381
|
-
}, {
|
|
382
|
-
key: "visitLog",
|
|
383
|
-
value: function visitLog(_visitLog) {
|
|
384
|
-
// 检测当前路由是否为重定向路由,如果是则不记录
|
|
385
|
-
var routeInfo = this.routesMap.get(this.getFormatBasePath());
|
|
386
|
-
if (routeInfo !== null && routeInfo !== void 0 && routeInfo.isRedirect) {
|
|
387
235
|
return;
|
|
388
236
|
}
|
|
389
|
-
|
|
390
|
-
_visitLog = {
|
|
391
|
-
module: '',
|
|
392
|
-
content: ''
|
|
393
|
-
};
|
|
394
|
-
var routeNames = this.getPageModuleName();
|
|
395
|
-
Object.assign(_visitLog, {
|
|
396
|
-
module: routeNames.join('-'),
|
|
397
|
-
content: "\u8BBF\u95EE\u9875\u9762: ".concat(_toConsumableArray(routeNames).pop())
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
this.pushQueue({
|
|
401
|
-
log: _visitLog,
|
|
402
|
-
type: 'visit'
|
|
403
|
-
});
|
|
237
|
+
this._instance.setUserProfile(profile);
|
|
404
238
|
}
|
|
405
|
-
|
|
406
|
-
// 推送接口访问日志
|
|
239
|
+
/** 获取当前配置(未初始化时返回 undefined) */
|
|
407
240
|
}, {
|
|
408
|
-
key: "
|
|
409
|
-
value: function
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
navigator.sendBeacon("".concat(this.config.domain, "/pousheng-guard/api/analysis/track"), pako.deflate(JSON.stringify([_objectSpread(_objectSpread({
|
|
413
|
-
appId: config.appId,
|
|
414
|
-
log: _apiLog,
|
|
415
|
-
type: 'api'
|
|
416
|
-
}, this.getSystemProfile()), this.getUserProfile())])));
|
|
241
|
+
key: "getConfig",
|
|
242
|
+
value: function getConfig() {
|
|
243
|
+
var _this$_instance;
|
|
244
|
+
return (_this$_instance = this._instance) === null || _this$_instance === void 0 ? void 0 : _this$_instance.getConfig();
|
|
417
245
|
}
|
|
418
246
|
}]);
|
|
419
|
-
return
|
|
420
|
-
}();
|
|
421
|
-
|
|
422
|
-
_defineProperty(
|
|
423
|
-
|
|
424
|
-
_defineProperty(
|
|
425
|
-
|
|
426
|
-
_defineProperty(Track, "authCenterUserProfile", {});
|
|
427
|
-
// 路径信息映射
|
|
428
|
-
_defineProperty(Track, "routesMap", new Map());
|
|
429
|
-
// 权限信息映射
|
|
430
|
-
_defineProperty(Track, "authMap", new Map());
|
|
431
|
-
// 埋点队列
|
|
432
|
-
_defineProperty(Track, "trackQueue", []);
|
|
433
|
-
export default Track;
|
|
247
|
+
return TrackFacade;
|
|
248
|
+
}(); // 默认导出静态外观,满足 import Track 后直接 Track.eventLog()
|
|
249
|
+
_defineProperty(TrackFacade, "_instance", null);
|
|
250
|
+
_defineProperty(TrackFacade, "_initPromise", null);
|
|
251
|
+
_defineProperty(TrackFacade, "_queue", []);
|
|
252
|
+
_defineProperty(TrackFacade, "_warned", false);
|
|
253
|
+
export default TrackFacade;
|