@tmsfe/tms-core 0.0.71 → 0.0.74

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.71",
3
+ "version": "0.0.74",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,9 +8,10 @@
8
8
  import syncApi from './syncfnmanager';
9
9
  import AutoReport from './report/proxy/index';
10
10
  import md5 from './md5';
11
- import { rpxToPx } from './rpx';
12
11
  import { serialize } from './objUtils';
13
12
  import { calCoordinateDistance, formatDistance } from './distanceUtils';
13
+ import { getNavBarConfigData } from './navbarUtils';
14
+ import * as rpxUtil from './rpx';
14
15
  import * as stringUtils from './stringUtils';
15
16
  import * as timeUtils from './timeUtils';
16
17
  import * as ipxHelper from './ipxHelper';
@@ -210,15 +211,16 @@ const api = {
210
211
  md5,
211
212
  getCarManager,
212
213
  getLocationManager,
213
- rpxToPx,
214
214
  serialize,
215
215
  calCoordinateDistance,
216
216
  formatDistance,
217
+ getNavBarConfigData,
217
218
  createRequest,
218
219
  getEnvInfo,
219
220
  isAppPageExist,
220
221
  getHomePage,
221
222
  storage,
223
+ ...rpxUtil,
222
224
  ...asyncFuncs,
223
225
  ...objFuncs,
224
226
  ...syncApi,
package/src/index.js CHANGED
@@ -11,7 +11,8 @@ import { callCloudFunc } from './cloudService';
11
11
  import EventDispatcher from './eventDispatcher';
12
12
  import { serialize } from './objUtils';
13
13
  import { calCoordinateDistance, formatDistance } from './distanceUtils';
14
- import { rpxToPx } from './rpx';
14
+ import { rpxToPx, pxToRpx } from './rpx';
15
+ import { getNavBarConfigData } from './navbarUtils';
15
16
  import {
16
17
  formatPlate,
17
18
  subStr,
@@ -192,6 +193,9 @@ const api = {
192
193
 
193
194
  /** rpx转px */
194
195
  rpxToPx,
196
+ pxToRpx,
197
+
198
+ getNavBarConfigData,
195
199
 
196
200
  storage,
197
201
 
@@ -8,6 +8,7 @@ interface PostionType {
8
8
  province: string,
9
9
  cityCode: string,
10
10
  cityName: string,
11
+ district: string,
11
12
  latitude: number,
12
13
  longitude: number,
13
14
  }
@@ -55,6 +56,7 @@ class Location extends LocationBase {
55
56
  province: '广东省',
56
57
  cityCode: '440300',
57
58
  cityName: '深圳市',
59
+ district: '福田区',
58
60
  latitude: 22.54286,
59
61
  longitude: 114.05956,
60
62
  };
@@ -93,6 +95,7 @@ class Location extends LocationBase {
93
95
  nationCode: adInfo.nation_code,
94
96
  province: adInfo.province,
95
97
  cityName: adInfo.city,
98
+ district: adInfo.district,
96
99
  adCode: adInfo.adcode,
97
100
  cityCode: formatCityCode(adInfo.city_code, adInfo.nation_code),
98
101
  latitude: lat,
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 获取导航栏相关信息
3
+ * @returns {Object} data 导航栏布局信息
4
+ * @returns {Number} data.enable 是否支持自定义导航栏
5
+ * @returns {Number} data.statusBarHeight 状态栏高度,单位px
6
+ * @returns {Number} data.navBarHeight 导航栏高度(不含状态栏),单位px
7
+ * @returns {Number} data.menuTop 菜单按钮上边距,单位px
8
+ * @returns {Number} data.menuRight 菜单按钮右边缘距离屏幕左边缘的距离,单位px
9
+ * @returns {Number} data.menuWidth 菜单按钮宽度,单位px
10
+ * @returns {Number} data.menuHeight 菜单按钮高度,单位px
11
+ */
12
+ const getNavBarConfigData = () => {
13
+ const { statusBarHeight } = wx.getSystemInfoSync();
14
+ const { right, width, height = 0, top } = wx.getMenuButtonBoundingClientRect(); // 插件下基础库2.15.0起支持
15
+ return {
16
+ enable: true,
17
+ statusBarHeight, // 顶部状态栏高度
18
+ navBarHeight: height + ((top - statusBarHeight) * 2), // 小程序导航栏高度
19
+ menuTop: top, // 菜单按钮上边距
20
+ menuRight: right, // 菜单按钮右边距离屏幕左边缘的距离
21
+ menuWidth: width, // 菜单按钮宽度
22
+ menuHeight: height, // 菜单按钮高度
23
+ };
24
+ };
25
+
26
+ export {
27
+ getNavBarConfigData,
28
+ };
@@ -48,7 +48,7 @@
48
48
  #### 页面自动上报事件
49
49
  ##### 一、必须上报的生命周期事件:
50
50
  1. onLoad: 页面加载
51
- 2. onShow: 页面显示
51
+ 2. onShow: 页面显示(曝光)
52
52
  3. onReady: 页面初次渲染完成
53
53
  4. onHide: 页面隐藏
54
54
  5. onUnload: 页面卸载
@@ -56,7 +56,7 @@
56
56
  ##### 二、可能会上报的生命周期事件(取决于页面是否实现该函数):
57
57
  1. onPullDownRefresh: 用户下拉动作
58
58
  2. onReachBottom: 页面上拉触底
59
- 3. onShareAppMessage: 用户点击右上角转发
59
+ 3. onShareAppMessage: 用户点击右上角转发(分享)
60
60
  4. onShareTimeline: 用户点击右上角转发到朋友圈
61
61
  5. onAddToFavorites: 用户点击右上角收藏
62
62
  6. onReportPageTouch: 用户触摸页面 - 如果页面wxml有view节点则会注入该事件
@@ -65,7 +65,13 @@ function emptyFunc(): void {
65
65
  * @param callback
66
66
  */
67
67
  function executeFunc(context: any, func: Function, args: any[], callback: Function): any {
68
- const value = func.apply(context, args);
68
+ let value: any;
69
+ try {
70
+ value = func.apply(context, args);
71
+ } catch (e) {
72
+ callback();
73
+ throw e;
74
+ }
69
75
  // 如果不会返回promise
70
76
  if (!value || !value.then || typeof value.then !== 'function') {
71
77
  callback();
package/src/rpx.js CHANGED
@@ -12,6 +12,19 @@ const rpxToPx = (rpx) => {
12
12
  return rpx * ratio;
13
13
  };
14
14
 
15
+ /**
16
+ * @description px to rpx
17
+ * @returns {Number} 转换后的rpx数值
18
+ * @param px
19
+ */
20
+ const pxToRpx = (px) => {
21
+ const sys = syncApi.getSystemInfoSync();
22
+ const ww = sys.windowWidth;
23
+ const ratio = 750 / ww;
24
+ return px * ratio;
25
+ };
26
+
15
27
  export {
16
28
  rpxToPx,
29
+ pxToRpx,
17
30
  };
package/rollup.config.js DELETED
@@ -1,177 +0,0 @@
1
- import path from 'path';
2
- import ts from 'rollup-plugin-typescript2';
3
- import babel from '@rollup/plugin-babel';
4
- import json from '@rollup/plugin-json';
5
- import replace from 'rollup-plugin-replace';
6
- import nodeResolve from 'rollup-plugin-node-resolve';
7
- import commonjs from '@rollup/plugin-commonjs';
8
-
9
- if (!process.env.TARGET) {
10
- throw new Error('TARGET package must be specified via --environment flag.');
11
- }
12
-
13
- // 指定包地址
14
- const packageDir = path.resolve(__dirname);
15
- // 包名
16
- const name = path.basename(packageDir);
17
- // 环境
18
- const interEnv = process.env.INTER_ENV || 'public';
19
-
20
- // eslint-disable-next-line
21
- const packageJson = require('./package.json');
22
-
23
- const packageOptions = packageJson.buildOptions || {};
24
-
25
- function resolve(name) { // eslint-disable-line
26
- return path.resolve(packageDir, name);
27
- }
28
-
29
- const outputConfig = {
30
- esm: {
31
- dir: resolve('dist'),
32
- entryFileNames: '[name].js',
33
- format: 'es',
34
- },
35
- 'esm-browser': {
36
- dir: resolve('dist'),
37
- entryFileNames: '[name].esm-browser.js',
38
- format: 'es',
39
- },
40
- cjs: {
41
- dir: resolve('dist'),
42
- entryFileNames: '[name].cjs.js',
43
- format: 'cjs',
44
- },
45
- global: {
46
- dir: resolve('dist'),
47
- entryFileNames: '[name].global.js',
48
- format: 'iife',
49
- },
50
- };
51
-
52
- const defaultFormats = ['esm'];
53
- // 打包格式
54
- const packageFormats = packageOptions.formats || defaultFormats;
55
-
56
- const packageConfigs = packageFormats.map(format => createConfig(format, outputConfig[format]));
57
-
58
- export default packageConfigs;
59
-
60
- /**
61
- * format rollup package configuration object
62
- * @param {string} format 文件打包格式
63
- * @param {object} output 输出对象
64
- * @param {array} plugins 插件
65
- * @returns {object} rollup配置对象
66
- */
67
- function createConfig(format, output, plugins = []) {
68
- if (!output) {
69
- // eslint-disable-next-line
70
- console.log(require('chalk').yellow(`invalid format: "${format}"`)); // eslint-disable-line no-console
71
- process.exit(1);
72
- }
73
-
74
- output.sourceMap = true; // eslint-disable-line
75
- output.externalLiveBindings = false; // eslint-disable-line
76
-
77
- // 兼容不同的包的入口文件 -- 后面会统一为index.ts
78
- const entryFile = setEntryFile(name);
79
-
80
- // 定制化cjs的插件和esmodule的插件。
81
- const extralPlugin = setEsPlugin(output.format);
82
-
83
- return {
84
- input: entryFile,
85
- output,
86
- external: [],
87
- plugins: [
88
- json({
89
- namedExports: false,
90
- }),
91
- commonjs({
92
- ignoreDynamicRequires: true,
93
- // include: 'node_modules/**', // Default: undefined
94
- browser: true,
95
- }),
96
- babel({
97
- plugins: ['@babel/plugin-proposal-nullish-coalescing-operator', '@babel/plugin-proposal-optional-chaining'],
98
- // exclude: ['node_modules/**'],
99
- }),
100
- // terser(),
101
- createReplacePlugin(),
102
- ...extralPlugin,
103
- ...plugins,
104
- ],
105
- onwarn: (msg, warn) => {
106
- if (!/Circular/.test(msg)) {
107
- warn(msg);
108
- }
109
- },
110
- treeshake: {
111
- moduleSideEffects: false,
112
- },
113
- };
114
- }
115
-
116
- /**
117
- * 兼容现在的包会存在不同入口的情况。 后面会统一为index.ts
118
- * @param { string } packageN ame 包名称
119
- * @returns { Object } entryFile
120
- */
121
- function setEntryFile(packageName) {
122
- let entryFile = resolve('src/index.js');
123
-
124
- switch (packageName) {
125
- case 'tms-core':
126
- entryFile = {
127
- index: resolve('src/index'),
128
- request: resolve('src/request'),
129
- cloudService: resolve('src/cloudService'),
130
- 'index-proxy': resolve('src/index-proxy'),
131
- };
132
- break;
133
- case 'tms-websdk':
134
- entryFile = resolve('src/index.ts');
135
- break;
136
- default:
137
- entryFile = resolve('src/index.js');
138
- };
139
-
140
- return entryFile;
141
- }
142
-
143
- /**
144
- * 定制化cjs和esmodule的插件
145
- * @param { string } format 打包格式
146
- * @returns { Array<plugin> } 插件数组
147
- */
148
- function setEsPlugin(format) {
149
- const extralPlugins = [];
150
-
151
-
152
- if (format.indexOf('es') > -1) {
153
- extralPlugins.push(ts({
154
- tsconfig: resolve('tsconfig.json'),
155
- }));
156
- };
157
- if (format.indexOf('iife') > -1) {
158
- extralPlugins.push(nodeResolve({ jsnext: true, preferBuiltins: true, browser: true }));
159
- }
160
- return extralPlugins;
161
- }
162
-
163
- /**
164
- * 创建变量替换插件
165
- * @returns {function} 插件函数
166
- */
167
- function createReplacePlugin() {
168
- const replacements = {
169
- tmsCore: interEnv === 'public' ? '@tmsfe/tms-core' : '@tmsfe/tms-core',
170
- INTER_ENV_VB: JSON.stringify(interEnv || 'private'),
171
- };
172
-
173
- return replace({
174
- values: replacements,
175
- preventAssignment: true,
176
- });
177
- }