@tmsfe/tms-core 0.0.99 → 0.0.100

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.100",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -5,11 +5,12 @@
5
5
 
6
6
  // / <reference path='./types.ts'/>
7
7
 
8
+ // uniapp转换工具执行之后会打开这句注释
9
+ // import Vue from 'vue';
10
+
8
11
  import clone from '../clone';
9
12
  import helper from './helper';
10
13
 
11
- let originalComponent: any = null;
12
-
13
14
  // 劫持Component的生命周期
14
15
  function proxyLifeMethod(componentName: string, componentOptions: any, methodName: string): void {
15
16
  /* eslint-disable */
@@ -21,7 +22,9 @@ function proxyLifeMethod(componentName: string, componentOptions: any, methodNam
21
22
  obj[methodName] = function (...args: any[]): any {
22
23
  // 生命周期函数先发埋点,避免次过程用户退出而丢失埋点
23
24
  const data = clone.deepClone(this.data);
24
- const eventName = `Component_${componentName}_${methodName}`;
25
+ // vue下组件ready事件名是mounted,这里统一改为跟小程序一样用ready
26
+ const funcName = methodName === 'mounted' ? 'ready' : methodName;
27
+ const eventName = `Component_${componentName}_${funcName}`;
25
28
  helper.reportData(eventName, data);
26
29
  // 执行原函数
27
30
  return helper.executeFunc(this, original, args, helper.emptyFunc);
@@ -48,9 +51,9 @@ function proxyBindEvent(componentName: string, methods: any, methodName: string,
48
51
  };
49
52
  }
50
53
 
51
- // 劫持Page
52
- function init(): void {
53
- originalComponent = Component;
54
+ // 劫持小程序的Component
55
+ function proxyMpComponent(): void {
56
+ const originalComponent = Component;
54
57
  // @ts-ignore
55
58
  Component = function (options: any) {
56
59
  // 只有tms的页面才需要上报
@@ -67,6 +70,37 @@ function init(): void {
67
70
  };
68
71
  }
69
72
 
73
+ // 劫持vue的Component
74
+ function proxyVueComponent(): void {
75
+ // @ts-ignore
76
+ Vue.mixin({
77
+ beforeCreate() {
78
+ const options = this.$options;
79
+ // 有组件名则不是页面
80
+ if (!options.tmsAutoReport || !options.tmsComponentName) {
81
+ return;
82
+ }
83
+
84
+ const { methods } = options;
85
+ for (const event of options.tmsReportEvents) {
86
+ const { name, type } = event;
87
+ proxyBindEvent(options.tmsComponentName, methods, name, type);
88
+ }
89
+
90
+ proxyLifeMethod(options.tmsComponentName, options, 'mounted');
91
+ },
92
+ });
93
+ }
94
+
95
+ // 劫持Page
96
+ function init(): void {
97
+ if (wx.isH5) {
98
+ proxyVueComponent();
99
+ } else {
100
+ proxyMpComponent();
101
+ }
102
+ }
103
+
70
104
  export default {
71
105
  init,
72
106
  };
@@ -5,6 +5,9 @@
5
5
 
6
6
  // / <reference path='./types.ts'/>
7
7
 
8
+ // uniapp转换工具执行之后会打开这句注释
9
+ // import Vue from 'vue';
10
+
8
11
  import clone from '../clone';
9
12
  import helper from './helper';
10
13
 
@@ -19,8 +22,6 @@ const maybeLifeMethods = [
19
22
  ];
20
23
  const lifeMethods = mustLifeMethods.concat(maybeLifeMethods);
21
24
 
22
- let originalPage: any = null;
23
-
24
25
  // 劫持Page的生命周期
25
26
  function proxyLifeMethod(pageOptions: any, methodName: string): void {
26
27
  if (!pageOptions[methodName] && !mustLifeMethods.includes(methodName)) {
@@ -104,9 +105,9 @@ function proxyBindEvent(pageOptions: any, methodName: string, bindType: string):
104
105
  };
105
106
  }
106
107
 
107
- // 劫持Page
108
- function proxyPage(): void {
109
- originalPage = Page;
108
+ // 劫持小程序的Page
109
+ function proxyMpPage(): void {
110
+ const originalPage = Page;
110
111
  Page = function (options: any) {
111
112
  // 只有tms的页面才需要上报
112
113
  if (options.tmsAutoReport) {
@@ -123,9 +124,35 @@ function proxyPage(): void {
123
124
  };
124
125
  }
125
126
 
127
+ // 劫持vue的Page
128
+ function proxyVuePage(): void {
129
+ // @ts-ignore
130
+ Vue.mixin({
131
+ beforeCreate() {
132
+ const options = this.$options;
133
+ // 有组件名则不是页面
134
+ if (!options.tmsAutoReport || options.tmsComponentName) {
135
+ return;
136
+ }
137
+
138
+ for (const methodName of lifeMethods) {
139
+ proxyLifeMethod(options, methodName);
140
+ }
141
+ for (const event of options.tmsReportEvents) {
142
+ const { name, type } = event;
143
+ proxyBindEvent(options.methods, name, type);
144
+ }
145
+ },
146
+ });
147
+ }
148
+
126
149
  // 劫持Page
127
150
  function init(): void {
128
- proxyPage();
151
+ if (wx.isH5) {
152
+ proxyVuePage();
153
+ } else {
154
+ proxyMpPage();
155
+ }
129
156
  }
130
157
 
131
158
  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
-