@tmsfe/tms-core 0.0.204 → 0.0.207

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.204",
3
+ "version": "0.0.207",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.js CHANGED
@@ -56,6 +56,7 @@ import * as storage from './storage';
56
56
  import * as uiUtil from './tmsuiUtils';
57
57
  import { throttle, debounce } from './funcUtils';
58
58
  import { formatAmount } from './priceUtils';
59
+ import { getSystemInfoSync } from './wxApi';
59
60
 
60
61
  /**
61
62
  * @public
@@ -279,6 +280,8 @@ const api = {
279
280
 
280
281
  storage,
281
282
 
283
+ getSystemInfoSync,
284
+
282
285
  ...syncApi,
283
286
  ...uiUtil,
284
287
  throttle,
@@ -2,7 +2,23 @@
2
2
  * @desc: 获取导航高度的相关函数
3
3
  */
4
4
  import { compareVersion } from './compareVersion';
5
- import { getSystemInfoSync } from './wxApi';
5
+ let systemInfo = null;
6
+
7
+ /**
8
+ * 获取系统信息,有缓存, 返回数据同wx.getSystemInfoSync {@link https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html}
9
+ * @returns {Object} 系统信息
10
+ */
11
+ const getSystemInfoSync = () => {
12
+ if (systemInfo) return systemInfo;
13
+ let res;
14
+ try {
15
+ systemInfo = wx.getSystemInfoSync();
16
+ res = systemInfo;
17
+ } catch (_) {
18
+ res = {};
19
+ }
20
+ return res;
21
+ };
6
22
 
7
23
  /**
8
24
  * 获取系统信息,有缓存, 返回数据同wx.getSystemInfoSync {@link https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfoSync.html}
@@ -4,7 +4,6 @@
4
4
  */
5
5
 
6
6
  import clone from './clone';
7
- import { getSystemInfoSync } from '../wxApi';
8
7
  import {
9
8
  IPage,
10
9
  DataItem,
@@ -43,7 +42,7 @@ let systemInfo: ISystemInfo;
43
42
  */
44
43
  function getSystemInfo(): ISystemInfo {
45
44
  if (!systemInfo) {
46
- const currentSystemInfo = getSystemInfoSync() as any;
45
+ const currentSystemInfo = wx.getSystemInfoSync() as any;
47
46
  // eslint-disable-next-line
48
47
  const { model = '', version: wxVersion = '', platform = '', SDKVersion = '', host } = currentSystemInfo;
49
48
  systemInfo = { model, wxVersion, platform, SDKVersion, host };
@@ -5,7 +5,6 @@
5
5
 
6
6
  import clone from '../clone';
7
7
  import helper from '../helper';
8
- import { getSystemInfoSync } from '../../wxApi';
9
8
  import { IInitOptions, IBindEvent } from './types';
10
9
 
11
10
  let initOptions: IInitOptions;
@@ -31,11 +30,16 @@ function fastReportData(...args: any[]): any {
31
30
  initOptions.fastReport(...args);
32
31
  }
33
32
 
33
+ let systemInfo: WechatMiniprogram.SystemInfo;
34
+
34
35
  /**
35
36
  * 获取wx.getSystemInfoSync()
36
37
  */
37
38
  function getSystemInfo(): any {
38
- return getSystemInfoSync();
39
+ if (!systemInfo) {
40
+ systemInfo = wx.getSystemInfoSync();
41
+ }
42
+ return systemInfo;
39
43
  }
40
44
 
41
45
  let lastBindEvent: IBindEvent;
@@ -1,5 +1,3 @@
1
- import { getSystemInfoSync } from '../../wxApi';
2
-
3
1
  class CanvasDrawer {
4
2
  constructor(canvasId, container, instance = '', designWindowWidth = 750) {
5
3
  this.canvasId = canvasId; // canvasId
@@ -18,7 +16,7 @@ class CanvasDrawer {
18
16
  const canvas = res[0].node;
19
17
  this.canvas = canvas;
20
18
  this.ctx = canvas.getContext('2d');
21
- const { pixelRatio: dpr, windowWidth } = getSystemInfoSync();
19
+ const { pixelRatio: dpr, windowWidth } = wx.getSystemInfoSync();
22
20
  canvas.width = res[0].width * dpr;
23
21
  canvas.height = res[0].height * dpr;
24
22
  this.ratio = windowWidth / this.designWindowWidth;