visual-buried-point-platform-uni 1.0.0-alpha
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/README.md +93 -0
- package/bpstorage.js +29 -0
- package/cache.js +28 -0
- package/config.js +25 -0
- package/index.js +309 -0
- package/lsi-md5.js +21 -0
- package/package.json +27 -0
- package/tools.js +209 -0
- package/webpack.config.js +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# 可视化埋点uni端
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
8
|
+
|
|
9
|
+
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
10
|
+
|
|
11
|
+
## Add your files
|
|
12
|
+
|
|
13
|
+
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
14
|
+
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
cd existing_repo
|
|
18
|
+
git remote add origin http://10.10.11.151:20216/teg/bigdata-center/buried-point/front-end/visual-buried-point-platform-uni.git
|
|
19
|
+
git branch -M main
|
|
20
|
+
git push -uf origin main
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Integrate with your tools
|
|
24
|
+
|
|
25
|
+
- [ ] [Set up project integrations](http://10.10.11.151:20216/teg/bigdata-center/buried-point/front-end/visual-buried-point-platform-uni/-/settings/integrations)
|
|
26
|
+
|
|
27
|
+
## Collaborate with your team
|
|
28
|
+
|
|
29
|
+
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
|
30
|
+
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
31
|
+
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
32
|
+
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
33
|
+
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
|
34
|
+
|
|
35
|
+
## Test and Deploy
|
|
36
|
+
|
|
37
|
+
Use the built-in continuous integration in GitLab.
|
|
38
|
+
|
|
39
|
+
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
|
40
|
+
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
|
41
|
+
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
|
42
|
+
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
43
|
+
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
44
|
+
|
|
45
|
+
***
|
|
46
|
+
|
|
47
|
+
# Editing this README
|
|
48
|
+
|
|
49
|
+
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
50
|
+
|
|
51
|
+
## Suggestions for a good README
|
|
52
|
+
|
|
53
|
+
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
54
|
+
|
|
55
|
+
## Name
|
|
56
|
+
Choose a self-explaining name for your project.
|
|
57
|
+
|
|
58
|
+
## Description
|
|
59
|
+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
60
|
+
|
|
61
|
+
## Badges
|
|
62
|
+
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
63
|
+
|
|
64
|
+
## Visuals
|
|
65
|
+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
72
|
+
|
|
73
|
+
## Support
|
|
74
|
+
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
75
|
+
|
|
76
|
+
## Roadmap
|
|
77
|
+
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
State if you are open to contributions and what your requirements are for accepting them.
|
|
81
|
+
|
|
82
|
+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
83
|
+
|
|
84
|
+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
85
|
+
|
|
86
|
+
## Authors and acknowledgment
|
|
87
|
+
Show your appreciation to those who have contributed to the project.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
For open source projects, say how it is licensed.
|
|
91
|
+
|
|
92
|
+
## Project status
|
|
93
|
+
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
package/bpstorage.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const storgkeyName = "buriedPointKey";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 新增数据
|
|
5
|
+
*/
|
|
6
|
+
export function addSData(data) {
|
|
7
|
+
if (data) {
|
|
8
|
+
uni.setStorageSync(storgkeyName, JSON.stringify(data));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 读取数据
|
|
14
|
+
*/
|
|
15
|
+
export function getSData() {
|
|
16
|
+
let allData = uni.getStorageSync(storgkeyName);
|
|
17
|
+
if (allData) {
|
|
18
|
+
return JSON.parse(allData);
|
|
19
|
+
} else {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 删除数据
|
|
26
|
+
*/
|
|
27
|
+
export function delSData() {
|
|
28
|
+
uni.setStorageSync(storgkeyName, "");
|
|
29
|
+
}
|
package/cache.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const deepCopy = (target) => {
|
|
2
|
+
if (typeof target === "object") {
|
|
3
|
+
const result = Array.isArray(target) ? [] : {};
|
|
4
|
+
for (const key in target) {
|
|
5
|
+
if (typeof target[key] == "object") {
|
|
6
|
+
result[key] = deepCopy(target[key]);
|
|
7
|
+
} else {
|
|
8
|
+
result[key] = target[key];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const cacheData = [];
|
|
17
|
+
|
|
18
|
+
export const addCache = (data) => {
|
|
19
|
+
cacheData.push(data);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const getCache = () => {
|
|
23
|
+
return deepCopy(cacheData);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const clearCache = () => {
|
|
27
|
+
cacheData.length = 0;
|
|
28
|
+
};
|
package/config.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function setReportUrl(env) {
|
|
2
|
+
switch (env) {
|
|
3
|
+
case "test":
|
|
4
|
+
return {
|
|
5
|
+
reportUrl: "https://buryingpoint.gcongo.com.cn/client/api/event",
|
|
6
|
+
reportTrackUrl: "https://buryingpoint.gcongo.com.cn/client/api/track",
|
|
7
|
+
eventListUrl:
|
|
8
|
+
"https://buryingpoint.gcongo.com.cn/api/event/query/eventList",
|
|
9
|
+
};
|
|
10
|
+
case "production":
|
|
11
|
+
return {
|
|
12
|
+
reportUrl: "https://buryingpoint.onebuygz.com/client/api/event",
|
|
13
|
+
reportTrackUrl: "https://buryingpoint.onebuygz.com/client/api/track",
|
|
14
|
+
eventListUrl:
|
|
15
|
+
"https://buryingpoint.onebuygz.com/api/event/query/eventList",
|
|
16
|
+
};
|
|
17
|
+
default:
|
|
18
|
+
return {
|
|
19
|
+
reportUrl: "https://buryingpoint.onebuygz.com/client/api/event",
|
|
20
|
+
reportTrackUrl: "https://buryingpoint.onebuygz.com/client/api/track",
|
|
21
|
+
eventListUrl:
|
|
22
|
+
"https://buryingpoint.onebuygz.com/api/event/query/eventList",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import MD5 from "md5";
|
|
2
|
+
import pk from "./package.json";
|
|
3
|
+
import { addCache, getCache, clearCache } from "./cache.js";
|
|
4
|
+
import { addSData, getSData, delSData } from "./bpstorage.js";
|
|
5
|
+
import {
|
|
6
|
+
randomUUID,
|
|
7
|
+
webH5Info,
|
|
8
|
+
wxInfo,
|
|
9
|
+
getAppInfo,
|
|
10
|
+
getDeviceInfo,
|
|
11
|
+
getDeviceInfoError,
|
|
12
|
+
timeToStr,
|
|
13
|
+
getTrackObj,
|
|
14
|
+
} from "./tools.js";
|
|
15
|
+
import { setReportUrl } from "./config.js";
|
|
16
|
+
|
|
17
|
+
const localLsi = pk.lsi;
|
|
18
|
+
let platform = "";
|
|
19
|
+
let uAgent = "";
|
|
20
|
+
let reportUrl = "";
|
|
21
|
+
let reportTrackUrl = "";
|
|
22
|
+
let trackId = "";
|
|
23
|
+
let _comInfo = { distinctId: "", anonymousId: "" };
|
|
24
|
+
let appData = {};
|
|
25
|
+
let deviceData = {};
|
|
26
|
+
let _config = {
|
|
27
|
+
env: "production",
|
|
28
|
+
token: "",
|
|
29
|
+
srcDomain: "",
|
|
30
|
+
flushInterval: 15,
|
|
31
|
+
};
|
|
32
|
+
//track upload interval
|
|
33
|
+
let tInterval = null;
|
|
34
|
+
let busObj = null;
|
|
35
|
+
let startTime = 0;
|
|
36
|
+
let startTimeLong = 0;
|
|
37
|
+
|
|
38
|
+
//common global upload interval
|
|
39
|
+
let cInterval = null;
|
|
40
|
+
|
|
41
|
+
export function init(config) {
|
|
42
|
+
if (config) {
|
|
43
|
+
let _cf = setReportUrl(config.env ? config.env : "");
|
|
44
|
+
reportUrl = _cf.reportUrl;
|
|
45
|
+
reportTrackUrl = _cf.reportTrackUrl;
|
|
46
|
+
eventListUrl = _cf.eventListUrl;
|
|
47
|
+
if (config.flushInterval) {
|
|
48
|
+
if (config.flushInterval < 5) {
|
|
49
|
+
config.flushInterval = 15;
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
config.flushInterval = 15;
|
|
53
|
+
}
|
|
54
|
+
_config = {
|
|
55
|
+
env: config.env,
|
|
56
|
+
token: config.token ? config.token : "",
|
|
57
|
+
srcDomain: config.sourceDomain ? config.sourceDomain : "",
|
|
58
|
+
flushInterval: config.flushInterval,
|
|
59
|
+
};
|
|
60
|
+
getBaseicInfo();
|
|
61
|
+
_comInfo.distinctId = uni.getStorageSync("v_userId")
|
|
62
|
+
? uni.getStorageSync("v_userId")
|
|
63
|
+
: "";
|
|
64
|
+
_comInfo.anonymousId = uni.getStorageSync("v_anonId");
|
|
65
|
+
if (!_comInfo.anonymousId) {
|
|
66
|
+
_comInfo.anonymousId = randomUUID();
|
|
67
|
+
uni.setStorageSync("v_anonId", _comInfo.anonymousId);
|
|
68
|
+
}
|
|
69
|
+
if (!trackId) {
|
|
70
|
+
trackId = Date.now().toString();
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
console.log("init config error, please check config!");
|
|
74
|
+
}
|
|
75
|
+
startGlobalTime();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//the general custom report interval is enabled
|
|
79
|
+
function startGlobalTime() {
|
|
80
|
+
clearInterval(cInterval);
|
|
81
|
+
cInterval = setInterval(() => {
|
|
82
|
+
let cData = getSData();
|
|
83
|
+
console.log("storage data " + cData);
|
|
84
|
+
if (cData) {
|
|
85
|
+
report(cData);
|
|
86
|
+
delSData();
|
|
87
|
+
}
|
|
88
|
+
}, _config.flushInterval * 1000);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//bind userID
|
|
92
|
+
export function setUserId(userId) {
|
|
93
|
+
if (userId) {
|
|
94
|
+
_comInfo.distinctId = userId;
|
|
95
|
+
uni.setStorageSync("v_userId", userId);
|
|
96
|
+
} else {
|
|
97
|
+
_comInfo.distinctId = "";
|
|
98
|
+
uni.setStorageSync("v_userId", "");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//set custom event
|
|
103
|
+
export function setCustomEvent(data) {
|
|
104
|
+
let reportData = null;
|
|
105
|
+
const _page = data.$page ? data.$page : "";
|
|
106
|
+
const _path = _page.path ? _page.path : getCurPath();
|
|
107
|
+
reportData = {
|
|
108
|
+
ctk: data.$ctk ? data.$ctk : "",
|
|
109
|
+
duration: "",
|
|
110
|
+
element: null,
|
|
111
|
+
eventId: data.$event_id ? data.$event_id : "",
|
|
112
|
+
event: data.$event_code ? data.$event_code : "",
|
|
113
|
+
groupId: "",
|
|
114
|
+
busSegment: data.$busSegment,
|
|
115
|
+
module: data.$module,
|
|
116
|
+
page: {
|
|
117
|
+
domain: _page.domain ? _page.domain : "",
|
|
118
|
+
pageId: MD5(_path),
|
|
119
|
+
path: _path,
|
|
120
|
+
title: _page.title ? _page.title : "",
|
|
121
|
+
},
|
|
122
|
+
path: data.$path ? data.$path : "",
|
|
123
|
+
properties: data.$extend_param ? JSON.stringify(data.$extend_param) : "",
|
|
124
|
+
traceId: "",
|
|
125
|
+
trackId: trackId,
|
|
126
|
+
triggerTime: timeToStr(Date.now()),
|
|
127
|
+
url: "",
|
|
128
|
+
};
|
|
129
|
+
if (reportData) {
|
|
130
|
+
addCache(reportData);
|
|
131
|
+
const data = getCache();
|
|
132
|
+
if (data.length) {
|
|
133
|
+
addSData(data);
|
|
134
|
+
clearCache();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function report(data) {
|
|
140
|
+
if (!reportUrl) {
|
|
141
|
+
//console.error("please set upload data url");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const comData = commonData(data);
|
|
145
|
+
const reportData = {
|
|
146
|
+
...comData,
|
|
147
|
+
dataAbstract: MD5(JSON.stringify(comData)),
|
|
148
|
+
};
|
|
149
|
+
uni.nextTick(function () {
|
|
150
|
+
uni.request({
|
|
151
|
+
url: reportUrl,
|
|
152
|
+
method: "POST",
|
|
153
|
+
header: {
|
|
154
|
+
"Content-Type": "application/json",
|
|
155
|
+
appKey: _config.token,
|
|
156
|
+
projectId: _config.token,
|
|
157
|
+
},
|
|
158
|
+
data: reportData,
|
|
159
|
+
success: function (res) {},
|
|
160
|
+
fail: function (error) {
|
|
161
|
+
console.error(error);
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
//track upload-注册
|
|
168
|
+
export function onStartTrack(tData) {
|
|
169
|
+
busObj = null;
|
|
170
|
+
startTime = 0;
|
|
171
|
+
startTimeLong = Date.now();
|
|
172
|
+
busObj = tData;
|
|
173
|
+
clearInterval(tInterval);
|
|
174
|
+
assemblyTrackData("start");
|
|
175
|
+
tInterval = setInterval(() => {
|
|
176
|
+
startTime += 15;
|
|
177
|
+
startTimeLong = Date.now();
|
|
178
|
+
assemblyTrackData("start");
|
|
179
|
+
}, 15 * 1000);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//track upload-销毁
|
|
183
|
+
export function onDestroyTrack() {
|
|
184
|
+
assemblyTrackData("destroy");
|
|
185
|
+
clearInterval(tInterval);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function assemblyTrackData(type) {
|
|
189
|
+
if (busObj) {
|
|
190
|
+
let obj = getTrackObj(busObj);
|
|
191
|
+
let trackData = null;
|
|
192
|
+
if (type === "destroy") {
|
|
193
|
+
startTime = (Date.now() - startTimeLong) / 1000;
|
|
194
|
+
}
|
|
195
|
+
trackData = {
|
|
196
|
+
busSegment: busObj.busSegment,
|
|
197
|
+
circulation: obj.circulation,
|
|
198
|
+
ctk: busObj.ctk ? busObj.ctk : "",
|
|
199
|
+
domain: obj.domain,
|
|
200
|
+
duration: startTime === 0 ? 0 : startTime,
|
|
201
|
+
module: busObj.module,
|
|
202
|
+
path: obj.path,
|
|
203
|
+
properties: busObj.extend_param
|
|
204
|
+
? JSON.stringify(busObj.extend_param)
|
|
205
|
+
: "",
|
|
206
|
+
sourceDomain: obj.sourceDomain ? obj.sourceDomain : _config.srcDomain,
|
|
207
|
+
sourceUrl: obj.sourceUrl,
|
|
208
|
+
title: obj.title,
|
|
209
|
+
traceId: busObj.traceId ? busObj.traceId : "",
|
|
210
|
+
trackId: trackId,
|
|
211
|
+
url: obj.url,
|
|
212
|
+
visitPage: obj.visitPage,
|
|
213
|
+
visitTime: busObj.visitTime ? busObj.visitTime : timeToStr(Date.now()),
|
|
214
|
+
};
|
|
215
|
+
if (trackData) {
|
|
216
|
+
reportTrack([trackData]);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// track upload data
|
|
222
|
+
function reportTrack(data) {
|
|
223
|
+
if (!reportTrackUrl) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const comData = commonData(data);
|
|
227
|
+
const reportTrackData = {
|
|
228
|
+
...comData,
|
|
229
|
+
dataAbstract: MD5(JSON.stringify(comData)),
|
|
230
|
+
};
|
|
231
|
+
uni.request({
|
|
232
|
+
url: reportTrackUrl,
|
|
233
|
+
method: "POST",
|
|
234
|
+
header: {
|
|
235
|
+
"Content-Type": "application/json",
|
|
236
|
+
appKey: _config.token,
|
|
237
|
+
projectId: _config.token,
|
|
238
|
+
},
|
|
239
|
+
data: reportTrackData,
|
|
240
|
+
success: function (res) {},
|
|
241
|
+
fail: function (error) {
|
|
242
|
+
console.error(error);
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function getCurPath() {
|
|
248
|
+
if (platform) {
|
|
249
|
+
if (platform == "wx") {
|
|
250
|
+
let gcp = getCurrentPages();
|
|
251
|
+
return gcp ? gcp[gcp.length - 1].route : "/";
|
|
252
|
+
} else if (platform == "web") {
|
|
253
|
+
return window.location.hostname;
|
|
254
|
+
} else if (platform == "android" || platform === "ios") {
|
|
255
|
+
return "";
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function commonData(allData) {
|
|
261
|
+
return {
|
|
262
|
+
app: appData,
|
|
263
|
+
data: allData,
|
|
264
|
+
deviceData: deviceData,
|
|
265
|
+
lsi: localLsi,
|
|
266
|
+
projectId: _config.token,
|
|
267
|
+
userAgent: uAgent ? uAgent : "",
|
|
268
|
+
anonymousId: _comInfo.anonymousId,
|
|
269
|
+
userId: _comInfo.distinctId,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
//获取基本信息
|
|
274
|
+
function getBaseicInfo() {
|
|
275
|
+
uni.getSystemInfo({
|
|
276
|
+
success: function (res) {
|
|
277
|
+
uAgent = res.ua;
|
|
278
|
+
let uniPlatform = res.uniPlatform;
|
|
279
|
+
if (uniPlatform.includes("app")) {
|
|
280
|
+
platform = res.osName;
|
|
281
|
+
appData = getAppInfo(res);
|
|
282
|
+
} else if (uniPlatform.includes("web") || uniPlatform.includes("h5")) {
|
|
283
|
+
platform = uniPlatform;
|
|
284
|
+
let wh5Info = webH5Info(res);
|
|
285
|
+
appData = {
|
|
286
|
+
...wh5Info,
|
|
287
|
+
version: _config.version ? _config.version : "unknown",
|
|
288
|
+
};
|
|
289
|
+
} else if (uniPlatform.includes("weixin")) {
|
|
290
|
+
platform = "wx";
|
|
291
|
+
appData = wxInfo();
|
|
292
|
+
}
|
|
293
|
+
deviceData = getDeviceInfo(res);
|
|
294
|
+
},
|
|
295
|
+
fail: function (error) {
|
|
296
|
+
deviceData = getDeviceInfoError();
|
|
297
|
+
},
|
|
298
|
+
complete: function () {
|
|
299
|
+
uni.getNetworkType({
|
|
300
|
+
success(res) {
|
|
301
|
+
deviceData = {
|
|
302
|
+
...deviceData,
|
|
303
|
+
network: res.networkType,
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
}
|
package/lsi-md5.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// 此js在npm build,根据name + version + md5后会自动修改package.json中的lsi
|
|
2
|
+
// 注:发给后端,作为标识依据和上报字段lsi值
|
|
3
|
+
import fs from 'fs' ;
|
|
4
|
+
import MD5 from 'md5' ;
|
|
5
|
+
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const { name, version } = packageJson;
|
|
9
|
+
// MD5
|
|
10
|
+
const combinedString = name + "-" + version;
|
|
11
|
+
const md5Str = MD5(combinedString);
|
|
12
|
+
packageJson.lsi = md5Str;
|
|
13
|
+
//base64
|
|
14
|
+
// const combinedString = name.substring(0, 16) + "v" + version;
|
|
15
|
+
// const base64Str = btoa(combinedString);
|
|
16
|
+
// packageJson.lsi = base64Str;
|
|
17
|
+
|
|
18
|
+
const updatedPackageJson = JSON.stringify(packageJson, null, 2);
|
|
19
|
+
fs.writeFileSync("./package.json", updatedPackageJson, "utf8");
|
|
20
|
+
|
|
21
|
+
console.log('write package.json "lsi" value success ');
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "visual-buried-point-platform-uni",
|
|
3
|
+
"version": "1.0.0-alpha",
|
|
4
|
+
"lsi": "e640f6dcca0160bfded7c074ba108e9f",
|
|
5
|
+
"description": "To make it easy for you to get started with GitLab, here's a list of recommended next steps.",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"build": "webpack --mode production && npm run lsi-md5",
|
|
10
|
+
"lsi-md5": "node lsi-md5.js"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": ""
|
|
16
|
+
},
|
|
17
|
+
"keywords": [],
|
|
18
|
+
"author": "",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"md5": "^2.3.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"webpack": "^5.72.1",
|
|
25
|
+
"webpack-cli": "4.9.2"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/tools.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
export function randomUUID() {
|
|
2
|
+
let uuid = "xxxx-4xxx-yxxx-xxxx".replace(/[xy]/g, function (c) {
|
|
3
|
+
let r = (Math.random() * 16) | 0,
|
|
4
|
+
v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
5
|
+
return v.toString(16);
|
|
6
|
+
});
|
|
7
|
+
return uuid;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function timeToStr(timestamp) {
|
|
11
|
+
const date = new Date(timestamp);
|
|
12
|
+
const year = date.getFullYear();
|
|
13
|
+
const month =
|
|
14
|
+
date.getMonth() + 1 < 10
|
|
15
|
+
? "0" + (date.getMonth() + 1)
|
|
16
|
+
: date.getMonth() + 1;
|
|
17
|
+
const day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
|
|
18
|
+
const hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
|
|
19
|
+
const minute =
|
|
20
|
+
date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
|
|
21
|
+
const second =
|
|
22
|
+
date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
|
|
23
|
+
const formattedDate = `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
|
24
|
+
return formattedDate;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//web或者h5的appInfo
|
|
28
|
+
export function webH5Info(result) {
|
|
29
|
+
let ecology = "unknown";
|
|
30
|
+
let ua = result.ua.toLowerCase();
|
|
31
|
+
let hostname = window.location.hostname;
|
|
32
|
+
let titleName = document.title;
|
|
33
|
+
let isMobile =
|
|
34
|
+
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua);
|
|
35
|
+
if (isMobile) {
|
|
36
|
+
ecology = "app";
|
|
37
|
+
} else {
|
|
38
|
+
ecology = "brower";
|
|
39
|
+
}
|
|
40
|
+
if (ua.includes("alipay")) {
|
|
41
|
+
ecology = "alipay";
|
|
42
|
+
} else if (ua.includes("unionPay")) {
|
|
43
|
+
ecology = "unionPay";
|
|
44
|
+
} else if (ua.includes("onbuygz")) {
|
|
45
|
+
ecology = "onbuygz";
|
|
46
|
+
} else if (ua.includes("onetravel")) {
|
|
47
|
+
ecology = "onetravel";
|
|
48
|
+
}
|
|
49
|
+
if (ua.includes("micromessenger")) {
|
|
50
|
+
if (ua.includes("miniprogram")) {
|
|
51
|
+
ecology = "wechat";
|
|
52
|
+
} else {
|
|
53
|
+
ecology = "brower";
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
name: titleName ? titleName : "",
|
|
58
|
+
packageName: hostname ? hostname : "",
|
|
59
|
+
version: "",
|
|
60
|
+
carrier: "h5",
|
|
61
|
+
ecology: ecology,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//微信的appInfo
|
|
66
|
+
export function wxInfo() {
|
|
67
|
+
let accInfo = uni.getAccountInfoSync();
|
|
68
|
+
return {
|
|
69
|
+
name: "",
|
|
70
|
+
packageName: accInfo ? accInfo.appId : "",
|
|
71
|
+
version: accInfo ? accInfo.envVersion + accInfo.version : "",
|
|
72
|
+
carrier: "mini",
|
|
73
|
+
ecology: "wechat",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//app的appInfo
|
|
78
|
+
export function getAppInfo(result) {
|
|
79
|
+
let version = plus.runtime.version;
|
|
80
|
+
let app = {
|
|
81
|
+
name: result.appName,
|
|
82
|
+
version: version ? version : "",
|
|
83
|
+
carrier: "app",
|
|
84
|
+
};
|
|
85
|
+
if (result.platform === "android") {
|
|
86
|
+
let osName = "android";
|
|
87
|
+
let pkName = plus.android.runtimeMainActivity().getPackageName();
|
|
88
|
+
if (result.romName.includes("HarmonyOS")) {
|
|
89
|
+
osName = "harmonyOS";
|
|
90
|
+
}
|
|
91
|
+
app = {
|
|
92
|
+
...app,
|
|
93
|
+
packageName: pkName ? pkName : "",
|
|
94
|
+
ecology: osName,
|
|
95
|
+
};
|
|
96
|
+
} else if (result.platform === "ios") {
|
|
97
|
+
let pkName = plus.ios
|
|
98
|
+
.importClass("NSBundle")
|
|
99
|
+
.mainBundle()
|
|
100
|
+
.bundleIdentifier();
|
|
101
|
+
app = {
|
|
102
|
+
...app,
|
|
103
|
+
packageName: pkName ? pkName : "",
|
|
104
|
+
ecology: "ios",
|
|
105
|
+
};
|
|
106
|
+
} else {
|
|
107
|
+
app = {
|
|
108
|
+
...app,
|
|
109
|
+
packageName: "",
|
|
110
|
+
version: "",
|
|
111
|
+
ecology: "unknown",
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return app;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function getCurDeviceType(ua) {
|
|
118
|
+
const userAgent = ua.toLowerCase();
|
|
119
|
+
if (/(windows|win32|win64|wow64)/.test(userAgent)) {
|
|
120
|
+
return 1;
|
|
121
|
+
} else if (/(linux|android)/.test(userAgent)) {
|
|
122
|
+
return 2;
|
|
123
|
+
} else if (/(macintosh|mac os x|iphone|ipad|ipod)/.test(userAgent)) {
|
|
124
|
+
return 2;
|
|
125
|
+
} else {
|
|
126
|
+
return 2;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//获取设备信息
|
|
131
|
+
export function getDeviceInfo(res) {
|
|
132
|
+
let device = {
|
|
133
|
+
lang: res.osLanguage ? res.osLanguage : res.hostLanguage,
|
|
134
|
+
brand: res.deviceBrand + " " + res.deviceModel,
|
|
135
|
+
os: res.os,
|
|
136
|
+
osVersion: res.osVersion,
|
|
137
|
+
resolution: res.screenWidth + "x" + res.screenHeight,
|
|
138
|
+
browser: res.browserName,
|
|
139
|
+
browserVersion: res.browserVersion,
|
|
140
|
+
color: "",
|
|
141
|
+
deviceId: res.deviceId,
|
|
142
|
+
deviceType: getCurDeviceType(res.ua),
|
|
143
|
+
network: "",
|
|
144
|
+
};
|
|
145
|
+
return device;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//error默认获取设备信息
|
|
149
|
+
export function getDeviceInfoError() {
|
|
150
|
+
return {
|
|
151
|
+
lang: "",
|
|
152
|
+
brand: "",
|
|
153
|
+
os: "",
|
|
154
|
+
osVersion: "",
|
|
155
|
+
resolution: "",
|
|
156
|
+
browser: "",
|
|
157
|
+
browserVersion: "",
|
|
158
|
+
color: "",
|
|
159
|
+
deviceId: "",
|
|
160
|
+
deviceType: "",
|
|
161
|
+
network: "",
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//流量上报H5环境
|
|
166
|
+
export function getTrackObj(busObj) {
|
|
167
|
+
//uni 通用h5、app、wx拿到当前路由栈
|
|
168
|
+
const pages = getCurrentPages();
|
|
169
|
+
const gcp = pages[pages.length - 1];
|
|
170
|
+
//h5
|
|
171
|
+
let wl = window.location;
|
|
172
|
+
let docTitle = document.title;
|
|
173
|
+
let refurl = document.referrer;
|
|
174
|
+
let parsedUrl;
|
|
175
|
+
if (refurl) {
|
|
176
|
+
parsedUrl = new URL(refurl);
|
|
177
|
+
} else {
|
|
178
|
+
let busRefUrl = busObj.sourceUrl;
|
|
179
|
+
if (busRefUrl) {
|
|
180
|
+
parsedUrl = new URL(busRefUrl);
|
|
181
|
+
} else {
|
|
182
|
+
parsedUrl = "";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (gcp) {
|
|
186
|
+
let domain = "";
|
|
187
|
+
let url = "";
|
|
188
|
+
if (busObj.domain) {
|
|
189
|
+
domain = busObj.domain;
|
|
190
|
+
} else {
|
|
191
|
+
domain = wl.hostname ? wl.hostname : "";
|
|
192
|
+
}
|
|
193
|
+
if (busObj.url) {
|
|
194
|
+
url = busObj.url;
|
|
195
|
+
} else {
|
|
196
|
+
url = wl.href ? wl.href : "";
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
path: gcp.route,
|
|
200
|
+
domain: domain,
|
|
201
|
+
url: url,
|
|
202
|
+
circulation: gcp.length > 1 ? 2 : 1,
|
|
203
|
+
visitPage: gcp.length,
|
|
204
|
+
sourceDomain: parsedUrl ? parsedUrl.hostname : "",
|
|
205
|
+
sourceUrl: parsedUrl,
|
|
206
|
+
title: docTitle ? docTitle : "",
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
4
|
+
const __dirname = path.dirname(__filename);
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
entry: "./index.js",
|
|
8
|
+
output: {
|
|
9
|
+
path: path.resolve(__dirname, "dist"),
|
|
10
|
+
filename: "buried-point-uni.js",
|
|
11
|
+
libraryTarget: "umd",
|
|
12
|
+
},
|
|
13
|
+
resolve: {
|
|
14
|
+
extensions: [".js"],
|
|
15
|
+
},
|
|
16
|
+
mode: "production",
|
|
17
|
+
};
|