@tmsfe/tms-core 0.0.99 → 0.0.101

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.99",
3
+ "version": "0.0.101",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,8 +8,6 @@
8
8
  import clone from '../clone';
9
9
  import helper from './helper';
10
10
 
11
- let originalComponent: any = null;
12
-
13
11
  // 劫持Component的生命周期
14
12
  function proxyLifeMethod(componentName: string, componentOptions: any, methodName: string): void {
15
13
  /* eslint-disable */
@@ -21,7 +19,9 @@ function proxyLifeMethod(componentName: string, componentOptions: any, methodNam
21
19
  obj[methodName] = function (...args: any[]): any {
22
20
  // 生命周期函数先发埋点,避免次过程用户退出而丢失埋点
23
21
  const data = clone.deepClone(this.data);
24
- const eventName = `Component_${componentName}_${methodName}`;
22
+ // vue下组件ready事件名是mounted,这里统一改为跟小程序一样用ready
23
+ const funcName = methodName === 'mounted' ? 'ready' : methodName;
24
+ const eventName = `Component_${componentName}_${funcName}`;
25
25
  helper.reportData(eventName, data);
26
26
  // 执行原函数
27
27
  return helper.executeFunc(this, original, args, helper.emptyFunc);
@@ -48,9 +48,9 @@ function proxyBindEvent(componentName: string, methods: any, methodName: string,
48
48
  };
49
49
  }
50
50
 
51
- // 劫持Page
52
- function init(): void {
53
- originalComponent = Component;
51
+ // 劫持小程序的Component
52
+ function proxyMpComponent(): void {
53
+ const originalComponent = Component;
54
54
  // @ts-ignore
55
55
  Component = function (options: any) {
56
56
  // 只有tms的页面才需要上报
@@ -67,6 +67,37 @@ function init(): void {
67
67
  };
68
68
  }
69
69
 
70
+ // 劫持vue的Component
71
+ function proxyVueComponent(): void {
72
+ // @ts-ignore
73
+ Vue.mixin({
74
+ beforeCreate() {
75
+ const options = this.$options;
76
+ // 有组件名则不是页面
77
+ if (!options.tmsAutoReport || !options.tmsComponentName) {
78
+ return;
79
+ }
80
+
81
+ const { methods } = options;
82
+ for (const event of options.tmsReportEvents) {
83
+ const { name, type } = event;
84
+ proxyBindEvent(options.tmsComponentName, methods, name, type);
85
+ }
86
+
87
+ proxyLifeMethod(options.tmsComponentName, options, 'mounted');
88
+ },
89
+ });
90
+ }
91
+
92
+ // 劫持Page
93
+ function init(): void {
94
+ if (wx.isH5) {
95
+ proxyVueComponent();
96
+ } else {
97
+ proxyMpComponent();
98
+ }
99
+ }
100
+
70
101
  export default {
71
102
  init,
72
103
  };
@@ -19,8 +19,6 @@ const maybeLifeMethods = [
19
19
  ];
20
20
  const lifeMethods = mustLifeMethods.concat(maybeLifeMethods);
21
21
 
22
- let originalPage: any = null;
23
-
24
22
  // 劫持Page的生命周期
25
23
  function proxyLifeMethod(pageOptions: any, methodName: string): void {
26
24
  if (!pageOptions[methodName] && !mustLifeMethods.includes(methodName)) {
@@ -104,9 +102,9 @@ function proxyBindEvent(pageOptions: any, methodName: string, bindType: string):
104
102
  };
105
103
  }
106
104
 
107
- // 劫持Page
108
- function proxyPage(): void {
109
- originalPage = Page;
105
+ // 劫持小程序的Page
106
+ function proxyMpPage(): void {
107
+ const originalPage = Page;
110
108
  Page = function (options: any) {
111
109
  // 只有tms的页面才需要上报
112
110
  if (options.tmsAutoReport) {
@@ -123,9 +121,35 @@ function proxyPage(): void {
123
121
  };
124
122
  }
125
123
 
124
+ // 劫持vue的Page
125
+ function proxyVuePage(): void {
126
+ // @ts-ignore
127
+ Vue.mixin({
128
+ beforeCreate() {
129
+ const options = this.$options;
130
+ // 有组件名则不是页面
131
+ if (!options.tmsAutoReport || options.tmsComponentName) {
132
+ return;
133
+ }
134
+
135
+ for (const methodName of lifeMethods) {
136
+ proxyLifeMethod(options, methodName);
137
+ }
138
+ for (const event of options.tmsReportEvents) {
139
+ const { name, type } = event;
140
+ proxyBindEvent(options.methods, name, type);
141
+ }
142
+ },
143
+ });
144
+ }
145
+
126
146
  // 劫持Page
127
147
  function init(): void {
128
- proxyPage();
148
+ if (wx.isH5) {
149
+ proxyVuePage();
150
+ } else {
151
+ proxyMpPage();
152
+ }
129
153
  }
130
154
 
131
155
  export default {
package/src/request.js CHANGED
@@ -264,7 +264,7 @@ export default class Request {
264
264
  /**
265
265
  * @memberof Request
266
266
  * @param {string} path 请求接口路径
267
- * @param {string} param 业务参数
267
+ * @param {object} param 业务参数
268
268
  * @param {string} method 请求方法 get/post
269
269
  * @param {object} header 自定义的请求头
270
270
  * @returns {object} 接口返回结果
@@ -52,10 +52,10 @@ const getLoginInfo = () => loginInfoPromise;
52
52
  * @description 获取用户userId等登录信息
53
53
  * @param autoLogin 未登录时是否自动登录(小程序中启动时就已登录,该参数用于uniapp的h5页面)
54
54
  */
55
- const checkLogin = (autoLogin = false) => {
55
+ function checkLogin(autoLogin = false) {
56
56
  // uniapp的h5会覆盖checkLogin函数实现检查和自动登录功能
57
57
  return getLoginInfo().then(() => true);
58
- };
58
+ }
59
59
 
60
60
  /**
61
61
  * tms.getCarManager 用户获取小程序统一维护的车信息管理器
@@ -71,7 +71,7 @@ const getCarManager = () => Car;
71
71
  * 返回数据示意
72
72
  * {
73
73
  * userId: "1135608",
74
- * token: "a209e79c667d8711ec7564c1bf86f327",
74
+ * token: "xxxxxx",
75
75
  * firstLogin: 0,
76
76
  * },
77
77
  */
package/tsconfig.json DELETED
@@ -1,30 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "sourceMap": false,
4
- "target": "esnext",
5
- "module": "esnext",
6
- "moduleResolution": "node",
7
- "allowJs": true,
8
- "strict": false,
9
- "declarationMap": false,
10
- "noUnusedLocals": false,
11
- "experimentalDecorators": true,
12
- "resolveJsonModule": true,
13
- "esModuleInterop": true,
14
- "removeComments": false,
15
- "jsx": "preserve",
16
- "lib": ["esnext"],
17
- "rootDir": ".",
18
- "types": [
19
- "miniprogram-api-typings"
20
- ],
21
- "outDir": "dist",
22
- "paths": {
23
- }
24
- },
25
- "include": [
26
- "src/**/*.js",
27
- "src/**/*.ts"
28
- ]
29
- }
30
-