@yysports/tools 0.0.1
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/LICENSE +21 -0
- package/README.md +40 -0
- package/dist/CurrentUser/index.d.ts +35 -0
- package/dist/CurrentUser/index.js +168 -0
- package/dist/Track/index.d.ts +24 -0
- package/dist/Track/index.js +275 -0
- package/dist/Utils/common.d.ts +20 -0
- package/dist/Utils/common.js +55 -0
- package/dist/Utils/file.d.ts +10 -0
- package/dist/Utils/file.js +30 -0
- package/dist/Utils/index.d.ts +4 -0
- package/dist/Utils/index.js +4 -0
- package/dist/Utils/url.d.ts +1 -0
- package/dist/Utils/url.js +29 -0
- package/dist/Utils/wx.d.ts +11 -0
- package/dist/Utils/wx.js +25 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/interfaces/currentUser.interface.d.ts +21 -0
- package/dist/interfaces/currentUser.interface.js +1 -0
- package/dist/interfaces/track.interface.d.ts +35 -0
- package/dist/interfaces/track.interface.js +16 -0
- package/lib/CurrentUser/index.d.ts +35 -0
- package/lib/CurrentUser/index.js +130 -0
- package/lib/Track/index.d.ts +24 -0
- package/lib/Track/index.js +209 -0
- package/lib/Utils/common.d.ts +20 -0
- package/lib/Utils/common.js +66 -0
- package/lib/Utils/file.d.ts +10 -0
- package/lib/Utils/file.js +50 -0
- package/lib/Utils/index.d.ts +4 -0
- package/lib/Utils/index.js +29 -0
- package/lib/Utils/url.d.ts +1 -0
- package/lib/Utils/url.js +45 -0
- package/lib/Utils/wx.d.ts +11 -0
- package/lib/Utils/wx.js +46 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +50 -0
- package/lib/interfaces/currentUser.interface.d.ts +21 -0
- package/lib/interfaces/currentUser.interface.js +17 -0
- package/lib/interfaces/track.interface.d.ts +35 -0
- package/lib/interfaces/track.interface.js +35 -0
- package/package.json +99 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// 将无固定参数个数的回掉函数以Promise形式执行
|
|
2
|
+
export var promisify = function promisify(fn) {
|
|
3
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
4
|
+
args[_key - 1] = arguments[_key];
|
|
5
|
+
}
|
|
6
|
+
return new Promise(function (resolve) {
|
|
7
|
+
if (args.length > 0) {
|
|
8
|
+
fn.apply(void 0, args.concat([resolve]));
|
|
9
|
+
} else {
|
|
10
|
+
fn(resolve);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 将数组内某个字段的值转换为对象组
|
|
17
|
+
* @param array
|
|
18
|
+
* @param key
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export function arrayToObj(array, key) {
|
|
22
|
+
return array.reduce(function (obj, item) {
|
|
23
|
+
obj[item[key]] = item;
|
|
24
|
+
return obj;
|
|
25
|
+
}, {});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 检测当前浏览器内核版本是否大于等于指定的Chrome内核版本
|
|
30
|
+
* @param minVersion 指定的Chrome内核版本
|
|
31
|
+
* @returns 是否大于等于指定版本
|
|
32
|
+
*/
|
|
33
|
+
export function checkChromeVersion(minVersion) {
|
|
34
|
+
var ua = navigator.userAgent.toLowerCase();
|
|
35
|
+
var chromeVersion = ua.match(/chrom(e|ium)\/([0-9]+)\./);
|
|
36
|
+
if (chromeVersion && chromeVersion[2]) {
|
|
37
|
+
return parseInt(chromeVersion[2], 10) >= minVersion;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 生成随机字符串
|
|
44
|
+
* @param length 字符串长度
|
|
45
|
+
* @returns 随机字符串
|
|
46
|
+
*/
|
|
47
|
+
export function generateRandomString(length) {
|
|
48
|
+
var result = '';
|
|
49
|
+
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
50
|
+
var charactersLength = characters.length;
|
|
51
|
+
for (var i = 0; i < length; i++) {
|
|
52
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { compressAccuratelyConfig } from 'image-conversion';
|
|
2
|
+
export declare const downloadFile: (href: string, fileName?: string) => void;
|
|
3
|
+
export declare const compressImg: (file: Blob, config?: number | compressAccuratelyConfig | undefined) => Promise<Blob>;
|
|
4
|
+
/**
|
|
5
|
+
* 检查文件类型
|
|
6
|
+
* @param file File 文件对象
|
|
7
|
+
* @param accept string 文件类型,使用“,”分割,如:image/png,image/jpeg
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare const checkFileType: (file: File, accept: string) => boolean;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { compressAccurately } from 'image-conversion';
|
|
2
|
+
export var downloadFile = function downloadFile(href, fileName) {
|
|
3
|
+
var aEle = document.createElement('a');
|
|
4
|
+
aEle.target = '_blank';
|
|
5
|
+
aEle.href = href;
|
|
6
|
+
aEle.download = fileName || '';
|
|
7
|
+
aEle.click();
|
|
8
|
+
aEle.remove();
|
|
9
|
+
};
|
|
10
|
+
export var compressImg = function compressImg(file, config) {
|
|
11
|
+
return compressAccurately(file, config);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 检查文件类型
|
|
16
|
+
* @param file File 文件对象
|
|
17
|
+
* @param accept string 文件类型,使用“,”分割,如:image/png,image/jpeg
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export var checkFileType = function checkFileType(file, accept) {
|
|
21
|
+
if (accept) {
|
|
22
|
+
// 整理文件类型
|
|
23
|
+
var acceptList = accept.split(',').map(function (item) {
|
|
24
|
+
return item.trim().toLowerCase();
|
|
25
|
+
});
|
|
26
|
+
var fileType = file.type.toLowerCase();
|
|
27
|
+
return acceptList.includes(fileType);
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getUrlParams: (str?: string) => any;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
export var getUrlParams = function getUrlParams(str) {
|
|
5
|
+
var paramsStr = location.search;
|
|
6
|
+
if (typeof str === 'string') {
|
|
7
|
+
if (str.startsWith('http')) {
|
|
8
|
+
var url = new URL(str);
|
|
9
|
+
paramsStr = url.search;
|
|
10
|
+
} else {
|
|
11
|
+
paramsStr = str;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
var searchParams = new URLSearchParams(paramsStr);
|
|
15
|
+
var params = {};
|
|
16
|
+
var _iterator = _createForOfIteratorHelper(searchParams.entries()),
|
|
17
|
+
_step;
|
|
18
|
+
try {
|
|
19
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
20
|
+
var v = _step.value;
|
|
21
|
+
params[v[0]] = v[1];
|
|
22
|
+
}
|
|
23
|
+
} catch (err) {
|
|
24
|
+
_iterator.e(err);
|
|
25
|
+
} finally {
|
|
26
|
+
_iterator.f();
|
|
27
|
+
}
|
|
28
|
+
return params;
|
|
29
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const isWechat: boolean;
|
|
2
|
+
export interface WxSDKOption {
|
|
3
|
+
debug?: boolean;
|
|
4
|
+
appId: string;
|
|
5
|
+
timestamp: string;
|
|
6
|
+
nonceStr: string;
|
|
7
|
+
signature: string;
|
|
8
|
+
jsApiList: string[];
|
|
9
|
+
openTagList?: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare const wxSDK: (option: WxSDKOption) => Promise<unknown>;
|
package/dist/Utils/wx.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
|
|
8
|
+
export var isWechat = navigator.userAgent.toLowerCase().includes('micromessenger');
|
|
9
|
+
export var wxSDK = function wxSDK(option) {
|
|
10
|
+
return new Promise(function (resolve, reject) {
|
|
11
|
+
var configOption = Object.assign({}, (_objectDestructuringEmpty(option), option));
|
|
12
|
+
wx.config(_objectSpread({}, configOption));
|
|
13
|
+
wx.ready(function () {
|
|
14
|
+
resolve({
|
|
15
|
+
success: true
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
wx.error(function (res) {
|
|
19
|
+
reject({
|
|
20
|
+
success: false,
|
|
21
|
+
message: res
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as CurrentUser } from "./CurrentUser";
|
|
2
|
+
export { default as Track } from "./Track";
|
|
3
|
+
import * as _Utils from "./Utils";
|
|
4
|
+
export { _Utils as Utils };
|
|
5
|
+
export * from "./interfaces/currentUser.interface";
|
|
6
|
+
export * from "./interfaces/track.interface";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type LocalRouteItemType = {
|
|
2
|
+
access?: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
parentPath?: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
routes?: LocalRouteItemType[];
|
|
7
|
+
};
|
|
8
|
+
export type AuthMenuItemType = {
|
|
9
|
+
logAction: any;
|
|
10
|
+
name: string;
|
|
11
|
+
meta?: {
|
|
12
|
+
title: string;
|
|
13
|
+
};
|
|
14
|
+
permission?: string;
|
|
15
|
+
children?: AuthMenuItemType[];
|
|
16
|
+
path?: string;
|
|
17
|
+
builtIn?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type MenuNameMapType = {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface TrackConfig {
|
|
2
|
+
appId: string;
|
|
3
|
+
serverUrl?: string;
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
autoReportError?: boolean;
|
|
6
|
+
userProfile?: UserProfile;
|
|
7
|
+
base?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare enum TrackTypeEnum {
|
|
10
|
+
error = "\u9519\u8BEF\u4FE1\u606F",
|
|
11
|
+
visit = "\u9875\u9762\u8BBF\u95EE",
|
|
12
|
+
event = "\u7528\u6237\u89E6\u53D1",
|
|
13
|
+
api = "\u63A5\u53E3\u89E6\u53D1"
|
|
14
|
+
}
|
|
15
|
+
export type TrackType = keyof typeof TrackTypeEnum;
|
|
16
|
+
export interface UserProfile {
|
|
17
|
+
userId: string;
|
|
18
|
+
userName: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SystemProfile {
|
|
21
|
+
IMEI: string;
|
|
22
|
+
innerHeight: number;
|
|
23
|
+
innerWidth: number;
|
|
24
|
+
href: string;
|
|
25
|
+
systemTime: Date;
|
|
26
|
+
}
|
|
27
|
+
export interface CustomizeProfile {
|
|
28
|
+
content: string;
|
|
29
|
+
module: string;
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}
|
|
32
|
+
export interface ErrorProfile {
|
|
33
|
+
fileName: string;
|
|
34
|
+
message: string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// 埋点信息类型
|
|
2
|
+
export var TrackTypeEnum = /*#__PURE__*/function (TrackTypeEnum) {
|
|
3
|
+
TrackTypeEnum["error"] = "\u9519\u8BEF\u4FE1\u606F";
|
|
4
|
+
TrackTypeEnum["visit"] = "\u9875\u9762\u8BBF\u95EE";
|
|
5
|
+
TrackTypeEnum["event"] = "\u7528\u6237\u89E6\u53D1";
|
|
6
|
+
TrackTypeEnum["api"] = "\u63A5\u53E3\u89E6\u53D1";
|
|
7
|
+
return TrackTypeEnum;
|
|
8
|
+
}({});
|
|
9
|
+
|
|
10
|
+
// 用户信息
|
|
11
|
+
|
|
12
|
+
// 系统信息
|
|
13
|
+
|
|
14
|
+
// 自定义埋点信息
|
|
15
|
+
|
|
16
|
+
// 错误信息
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AuthMenuItemType, LocalRouteItemType, MenuNameMapType } from '../interfaces/currentUser.interface';
|
|
2
|
+
export interface CurrentUserConfig {
|
|
3
|
+
getAuth?: () => Promise<any>;
|
|
4
|
+
menuBuild?: () => Promise<AuthMenuItemType[]>;
|
|
5
|
+
menuNameMap: MenuNameMapType;
|
|
6
|
+
routes: LocalRouteItemType[];
|
|
7
|
+
}
|
|
8
|
+
export interface CurrentUserInfo {
|
|
9
|
+
name?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
nickName?: string;
|
|
12
|
+
roles: string[];
|
|
13
|
+
isAdmin: boolean;
|
|
14
|
+
accessPage: string[];
|
|
15
|
+
}
|
|
16
|
+
type PathMapItemType = {
|
|
17
|
+
module?: string[];
|
|
18
|
+
access?: string;
|
|
19
|
+
hasAccess?: boolean;
|
|
20
|
+
options: {
|
|
21
|
+
[key: string]: {
|
|
22
|
+
logAction: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export default class CurrentUser {
|
|
27
|
+
static profile: CurrentUserInfo | null;
|
|
28
|
+
static pathMap: {
|
|
29
|
+
[key: string]: PathMapItemType;
|
|
30
|
+
};
|
|
31
|
+
static formatAuthMenu(authMenuData: AuthMenuItemType[]): void;
|
|
32
|
+
static formatLocalMenu(routes: LocalRouteItemType[], menuNameMap: MenuNameMapType): void;
|
|
33
|
+
static init({ getAuth, menuBuild, menuNameMap, routes, }: CurrentUserConfig): Promise<CurrentUserInfo>;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/CurrentUser/index.tsx
|
|
20
|
+
var CurrentUser_exports = {};
|
|
21
|
+
__export(CurrentUser_exports, {
|
|
22
|
+
default: () => CurrentUser
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(CurrentUser_exports);
|
|
25
|
+
var CurrentUser = class {
|
|
26
|
+
// 格式化权限中心菜单、按钮数据
|
|
27
|
+
static formatAuthMenu(authMenuData) {
|
|
28
|
+
const ergodicAuthMenu = (amd, pathArr = []) => {
|
|
29
|
+
amd.forEach((menu) => {
|
|
30
|
+
const { path, permission, name, logAction, children } = menu;
|
|
31
|
+
const currPathArr = [...pathArr];
|
|
32
|
+
if (path) {
|
|
33
|
+
currPathArr.push(path == null ? void 0 : path.replaceAll("/", ""));
|
|
34
|
+
}
|
|
35
|
+
const currPathObj = this.pathMap[`/${currPathArr.join("/")}`];
|
|
36
|
+
if (currPathObj) {
|
|
37
|
+
currPathObj.hasAccess = true;
|
|
38
|
+
}
|
|
39
|
+
if (path === void 0 && currPathObj) {
|
|
40
|
+
currPathObj.options[permission] = {
|
|
41
|
+
logAction: logAction || name
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
45
|
+
ergodicAuthMenu(children, [...currPathArr]);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
ergodicAuthMenu(authMenuData);
|
|
50
|
+
}
|
|
51
|
+
// 格式化本地菜单权限数据
|
|
52
|
+
static formatLocalMenu(routes, menuNameMap) {
|
|
53
|
+
const ergodicLocalMenu = (rs, parentMenu) => {
|
|
54
|
+
rs.forEach((route) => {
|
|
55
|
+
const { path, access, name, routes: routes2 } = route;
|
|
56
|
+
const nameArr = [...(parentMenu == null ? void 0 : parentMenu.name) || []];
|
|
57
|
+
const moduleArr = [...(parentMenu == null ? void 0 : parentMenu.module) || []];
|
|
58
|
+
if (name) {
|
|
59
|
+
nameArr.push(name);
|
|
60
|
+
const menuKey = ["menu", ...nameArr].join(".");
|
|
61
|
+
moduleArr.push(menuNameMap[menuKey]);
|
|
62
|
+
}
|
|
63
|
+
if (path) {
|
|
64
|
+
this.pathMap[path] = {
|
|
65
|
+
module: [...moduleArr],
|
|
66
|
+
access,
|
|
67
|
+
options: {}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (routes2) {
|
|
71
|
+
ergodicLocalMenu(routes2, {
|
|
72
|
+
path,
|
|
73
|
+
name: nameArr,
|
|
74
|
+
module: moduleArr
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
ergodicLocalMenu(routes);
|
|
80
|
+
}
|
|
81
|
+
static async init({
|
|
82
|
+
getAuth,
|
|
83
|
+
menuBuild,
|
|
84
|
+
menuNameMap,
|
|
85
|
+
routes
|
|
86
|
+
}) {
|
|
87
|
+
const [authInfo = {}, menuData = []] = await Promise.all(
|
|
88
|
+
[
|
|
89
|
+
getAuth,
|
|
90
|
+
// 获取用户权限
|
|
91
|
+
menuBuild
|
|
92
|
+
// 获取权限中心配置的菜单及按钮
|
|
93
|
+
].map((v) => {
|
|
94
|
+
if (v) {
|
|
95
|
+
return v();
|
|
96
|
+
} else {
|
|
97
|
+
return Promise.resolve();
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
const { user = {}, roles = [] } = authInfo || {};
|
|
102
|
+
const isAdmin = roles.includes("admin");
|
|
103
|
+
this.formatLocalMenu(routes, menuNameMap);
|
|
104
|
+
this.formatAuthMenu(menuData);
|
|
105
|
+
const accessPage = [];
|
|
106
|
+
Object.keys(this.pathMap).forEach((path) => {
|
|
107
|
+
const currObj = this.pathMap[path];
|
|
108
|
+
if (currObj.access) {
|
|
109
|
+
if (isAdmin) {
|
|
110
|
+
accessPage.push(currObj.access);
|
|
111
|
+
} else {
|
|
112
|
+
currObj.hasAccess && accessPage.push(currObj.access);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
this.profile = {
|
|
117
|
+
name: user.userName || "system",
|
|
118
|
+
email: user.email || "system",
|
|
119
|
+
nickName: user.nickName || "system",
|
|
120
|
+
roles,
|
|
121
|
+
isAdmin,
|
|
122
|
+
accessPage
|
|
123
|
+
};
|
|
124
|
+
return this.profile;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
// 当前用户信息
|
|
128
|
+
CurrentUser.profile = null;
|
|
129
|
+
// 路径信息映射
|
|
130
|
+
CurrentUser.pathMap = {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CustomizeProfile, ErrorProfile, SystemProfile, TrackConfig, TrackType, UserProfile } from '../interfaces/track.interface';
|
|
2
|
+
declare class Track {
|
|
3
|
+
static config: TrackConfig;
|
|
4
|
+
static userProfile: UserProfile;
|
|
5
|
+
static trackQueue: any[];
|
|
6
|
+
static checkConfig(config?: TrackConfig): void;
|
|
7
|
+
static send(): Promise<void>;
|
|
8
|
+
static mountAutoTask(): void;
|
|
9
|
+
static getSystemProfile(): SystemProfile;
|
|
10
|
+
static getUserProfile(): UserProfile;
|
|
11
|
+
static setUserProfile(userProfile: UserProfile): void;
|
|
12
|
+
static init({ userProfile, ...restConfig }: TrackConfig): void;
|
|
13
|
+
static pushQueue({ type, log, }: {
|
|
14
|
+
type: TrackType;
|
|
15
|
+
log: ErrorProfile | CustomizeProfile;
|
|
16
|
+
}): void;
|
|
17
|
+
static getFormatBasePath(): string;
|
|
18
|
+
static getPageModuleName(): string[];
|
|
19
|
+
static errorLog(errorLog: ErrorProfile): void;
|
|
20
|
+
static eventLog(eventLog: CustomizeProfile | string): void;
|
|
21
|
+
static visitLog(visitLog?: CustomizeProfile): void;
|
|
22
|
+
static apiLog(apiLog: any): void;
|
|
23
|
+
}
|
|
24
|
+
export default Track;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/Track/index.ts
|
|
30
|
+
var Track_exports = {};
|
|
31
|
+
__export(Track_exports, {
|
|
32
|
+
default: () => Track_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(Track_exports);
|
|
35
|
+
var import_js_cookie = __toESM(require("js-cookie"));
|
|
36
|
+
var import_pako = __toESM(require("pako"));
|
|
37
|
+
var import_CurrentUser = __toESM(require("../CurrentUser"));
|
|
38
|
+
var import_Utils = require("../Utils");
|
|
39
|
+
var Track = class {
|
|
40
|
+
// 检查必填配置项
|
|
41
|
+
static checkConfig(config) {
|
|
42
|
+
if (!config) {
|
|
43
|
+
throw new Error("请配置Track");
|
|
44
|
+
}
|
|
45
|
+
if (!config.appId) {
|
|
46
|
+
throw new Error("请设置appId");
|
|
47
|
+
}
|
|
48
|
+
if (import_CurrentUser.default.profile === null) {
|
|
49
|
+
throw new Error("请先调用CurrentUser对象设置系统信息");
|
|
50
|
+
}
|
|
51
|
+
this.config = config;
|
|
52
|
+
}
|
|
53
|
+
// 发送埋点数据
|
|
54
|
+
static async send() {
|
|
55
|
+
const data = this.trackQueue.splice(0, this.trackQueue.length);
|
|
56
|
+
const compressed = import_pako.default.deflate(JSON.stringify(data));
|
|
57
|
+
if (data.length) {
|
|
58
|
+
navigator.sendBeacon(this.config.serverUrl, compressed);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// 挂载自动化任务
|
|
62
|
+
static mountAutoTask() {
|
|
63
|
+
const { autoReportError } = this.config;
|
|
64
|
+
if (autoReportError) {
|
|
65
|
+
addEventListener("error", (event) => {
|
|
66
|
+
const { message, filename } = event;
|
|
67
|
+
const errorInfo = {
|
|
68
|
+
message,
|
|
69
|
+
fileName: filename
|
|
70
|
+
};
|
|
71
|
+
this.errorLog(errorInfo);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
addEventListener("visibilitychange", () => {
|
|
75
|
+
if (document.visibilityState === "hidden") {
|
|
76
|
+
this.send();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// 获取系统信息
|
|
81
|
+
static getSystemProfile() {
|
|
82
|
+
const IMEI = import_js_cookie.default.get("__IMEI__");
|
|
83
|
+
if (!IMEI) {
|
|
84
|
+
import_js_cookie.default.set("__IMEI__", (0, import_Utils.generateRandomString)(16), {
|
|
85
|
+
expires: 90
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
innerHeight,
|
|
90
|
+
innerWidth,
|
|
91
|
+
href: location.href,
|
|
92
|
+
systemTime: /* @__PURE__ */ new Date(),
|
|
93
|
+
IMEI: import_js_cookie.default.get("__IMEI__")
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// 获取当前用户信息,返回格式化后的用户信息
|
|
97
|
+
static getUserProfile() {
|
|
98
|
+
let userProfile = this.userProfile;
|
|
99
|
+
if (!(userProfile == null ? void 0 : userProfile.userId)) {
|
|
100
|
+
userProfile.userId = "";
|
|
101
|
+
}
|
|
102
|
+
if (!(userProfile == null ? void 0 : userProfile.userName)) {
|
|
103
|
+
userProfile.userName = "";
|
|
104
|
+
}
|
|
105
|
+
return userProfile;
|
|
106
|
+
}
|
|
107
|
+
// 设置当前用户信息
|
|
108
|
+
static setUserProfile(userProfile) {
|
|
109
|
+
this.userProfile = userProfile;
|
|
110
|
+
}
|
|
111
|
+
// 挂载初始配置
|
|
112
|
+
static init({ userProfile, ...restConfig }) {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
this.checkConfig(restConfig);
|
|
115
|
+
this.config = restConfig;
|
|
116
|
+
if (userProfile) {
|
|
117
|
+
this.setUserProfile(userProfile);
|
|
118
|
+
} else {
|
|
119
|
+
this.setUserProfile({
|
|
120
|
+
userId: (_a = import_CurrentUser.default.profile) == null ? void 0 : _a.email,
|
|
121
|
+
userName: (_b = import_CurrentUser.default.profile) == null ? void 0 : _b.name
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
this.mountAutoTask();
|
|
125
|
+
}
|
|
126
|
+
// 推送埋点信息进入队列
|
|
127
|
+
static pushQueue({
|
|
128
|
+
type,
|
|
129
|
+
log
|
|
130
|
+
}) {
|
|
131
|
+
const config = this.config;
|
|
132
|
+
this.checkConfig(config);
|
|
133
|
+
const reqData = {
|
|
134
|
+
...this.getSystemProfile(),
|
|
135
|
+
...this.getUserProfile(),
|
|
136
|
+
type,
|
|
137
|
+
appId: config.appId,
|
|
138
|
+
log: JSON.stringify(log)
|
|
139
|
+
};
|
|
140
|
+
this.trackQueue.push(reqData);
|
|
141
|
+
if (this.trackQueue.length > 4) {
|
|
142
|
+
this.send();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// 获取格式化base后的路径
|
|
146
|
+
static getFormatBasePath() {
|
|
147
|
+
const { base = "/" } = this.config;
|
|
148
|
+
const { pathname } = location;
|
|
149
|
+
return pathname.replace(base, "/");
|
|
150
|
+
}
|
|
151
|
+
// 获取模块名称
|
|
152
|
+
static getPageModuleName() {
|
|
153
|
+
let routeNames = [];
|
|
154
|
+
const { pathMap } = import_CurrentUser.default;
|
|
155
|
+
if (pathMap) {
|
|
156
|
+
routeNames = pathMap[this.getFormatBasePath()].module || [];
|
|
157
|
+
}
|
|
158
|
+
return routeNames;
|
|
159
|
+
}
|
|
160
|
+
// 推送错误日志
|
|
161
|
+
static errorLog(errorLog) {
|
|
162
|
+
this.pushQueue({
|
|
163
|
+
log: errorLog,
|
|
164
|
+
type: "error"
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
// 推送用户触发日志
|
|
168
|
+
static eventLog(eventLog) {
|
|
169
|
+
var _a, _b, _c;
|
|
170
|
+
if (typeof eventLog === "string") {
|
|
171
|
+
const routeNames = this.getPageModuleName();
|
|
172
|
+
eventLog = {
|
|
173
|
+
module: routeNames.join("-"),
|
|
174
|
+
content: "触发: " + ((_c = (_b = (_a = import_CurrentUser.default.pathMap[this.getFormatBasePath()]) == null ? void 0 : _a.options) == null ? void 0 : _b[eventLog]) == null ? void 0 : _c.logAction)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
this.pushQueue({
|
|
178
|
+
log: eventLog,
|
|
179
|
+
type: "event"
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
// 推送页面访问日志
|
|
183
|
+
static visitLog(visitLog) {
|
|
184
|
+
if (visitLog === void 0) {
|
|
185
|
+
visitLog = { module: "", content: "" };
|
|
186
|
+
const routeNames = this.getPageModuleName();
|
|
187
|
+
Object.assign(visitLog, {
|
|
188
|
+
module: routeNames.join("-"),
|
|
189
|
+
content: `访问页面: ${[...routeNames].pop()}`
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
this.pushQueue({
|
|
193
|
+
log: visitLog,
|
|
194
|
+
type: "visit"
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
// 推送接口访问日志
|
|
198
|
+
static apiLog(apiLog) {
|
|
199
|
+
this.pushQueue({
|
|
200
|
+
log: apiLog,
|
|
201
|
+
type: "api"
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
Track.config = {};
|
|
206
|
+
Track.userProfile = {};
|
|
207
|
+
// 埋点队列
|
|
208
|
+
Track.trackQueue = [];
|
|
209
|
+
var Track_default = Track;
|