@haluo/util 2.0.21 → 2.0.23

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.
@@ -1,3 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
1
6
  /**
2
7
  * H5打开APP工具类
3
8
  *
@@ -5,30 +10,17 @@
5
10
  * 1、应用宝打开app指定页面,参考今日头条
6
11
  * 2、浏览器中进入页面立即打开app,参考掘金
7
12
  */
8
- import qs from 'qs';
9
- import tools from '../tools';
10
- class OpenAppClass {
11
- env;
12
- postJddTrack;
13
- trackId;
14
- openAppState;
15
- ua;
16
- _wx;
17
- _android;
18
- _isHarmonyos;
19
- _ios;
20
- _isPrice;
21
- currentEnv;
22
- appUrl;
23
- appStoreUrl;
24
- underway;
13
+ var qs_1 = __importDefault(require("qs"));
14
+ var tools_1 = __importDefault(require("../tools"));
15
+ var OpenAppClass = /** @class */ (function () {
25
16
  /**
26
17
  * @param {Object} env - 环境配置,必须
27
18
  * @param {Function} postJddTrack - 埋点方法,必须
28
19
  * @param {String} trackId - 埋点id,可选
29
20
  * @param {Object} openAppState - 打开app状态,可选
30
21
  */
31
- constructor(env, postJddTrack, trackId = 'S_00000000000108', openAppState) {
22
+ function OpenAppClass(env, postJddTrack, trackId, openAppState) {
23
+ if (trackId === void 0) { trackId = 'S_00000000000108'; }
32
24
  this.env = env; // 环境配置,必须
33
25
  this.postJddTrack = postJddTrack; // 埋点方法,必须
34
26
  this.trackId = trackId; // 埋点id,可选
@@ -48,8 +40,8 @@ class OpenAppClass {
48
40
  /**
49
41
  * 根据域名动态获取配置,保证多项目代码一样
50
42
  */
51
- getCurrentEnv() {
52
- const host = location.host;
43
+ OpenAppClass.prototype.getCurrentEnv = function () {
44
+ var host = location.host;
53
45
  if (host.includes('58moto')) {
54
46
  this.currentEnv = {
55
47
  motoAndroidScheme: this.env.motoAndroidScheme,
@@ -74,11 +66,11 @@ class OpenAppClass {
74
66
  APPLINKIOS: this.env.BIAOFINEAPPLINKIOS,
75
67
  };
76
68
  }
77
- }
69
+ };
78
70
  /**
79
71
  * 打开APP主流程
80
72
  */
81
- invoke() {
73
+ OpenAppClass.prototype.invoke = function () {
82
74
  if (this.underway) {
83
75
  return;
84
76
  }
@@ -89,13 +81,13 @@ class OpenAppClass {
89
81
  }
90
82
  this.underway = true;
91
83
  // 生成url并且放到剪贴板
92
- let url = this.getSechmaUrl();
84
+ var url = this.getSechmaUrl();
93
85
  if (url) {
94
- tools.clipboard(url);
86
+ tools_1.default.clipboard(url);
95
87
  }
96
- const apk = JSON.parse(sessionStorage.getItem('downloadApk') || '{}');
97
- const tag = this._ios ? (apk.channelName ? `App Store-${apk.channelName}` : 'App Store') : (apk.channelName ? `渠道${apk.channelName}包` : '安卓包');
98
- this.postJddTrack(this.trackId, { tag });
88
+ var apk = JSON.parse(sessionStorage.getItem('downloadApk') || '{}');
89
+ var tag = this._ios ? (apk.channelName ? "App Store-".concat(apk.channelName) : 'App Store') : (apk.channelName ? "\u6E20\u9053".concat(apk.channelName, "\u5305") : '安卓包');
90
+ this.postJddTrack(this.trackId, { tag: tag });
99
91
  // 厂家版 app
100
92
  if (this._android && location.href.includes('downloadPrise')) {
101
93
  window.location.href = (apk && apk.path) || this.appUrl;
@@ -105,7 +97,7 @@ class OpenAppClass {
105
97
  // 客户端打开app-下载页特殊处理
106
98
  if (location.href.includes('download') && window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
107
99
  this.underway = false;
108
- return window.AppCall.openOtherAppUrlRouter({ appUrlRouter: `https://${location.host}/home` });
100
+ return window.AppCall.openOtherAppUrlRouter({ appUrlRouter: "https://".concat(location.host, "/home") });
109
101
  }
110
102
  // 客户端打开app
111
103
  if (window.AppCall && window.AppCall.has('openOtherAppUrlRouter')) {
@@ -118,21 +110,22 @@ class OpenAppClass {
118
110
  url = this.appStoreUrl;
119
111
  }
120
112
  this.open(url);
121
- }
113
+ };
122
114
  // 获取自定义的url
123
- getUrl() {
124
- const searchParams = qs.parse(location.search.slice(1)); // 路由的query
125
- const url = searchParams.customOpenUrl || window.location.href;
115
+ OpenAppClass.prototype.getUrl = function () {
116
+ var searchParams = qs_1.default.parse(location.search.slice(1)); // 路由的query
117
+ var url = searchParams.customOpenUrl || window.location.href;
126
118
  return url;
127
- }
119
+ };
128
120
  /**
129
121
  * 获取打开 app sechma url
130
122
  * @returns {string | undefined} 打开app的schema或跳转链接
131
123
  * params:params={"type":"","id":0,"name":"","travelId":0}
132
124
  * type:原生页面key(必须);id:页面id(可选);subject 短话题、版块名称 或 页面标题(可选);travelId 游记id(可选)
133
125
  */
134
- getSechmaUrl() {
135
- const keys = {
126
+ OpenAppClass.prototype.getSechmaUrl = function () {
127
+ var _a, _b;
128
+ var keys = {
136
129
  '/posts/': 'thread_detail',
137
130
  '/detailedForum/': 'forum_detail',
138
131
  '/video/': 'video_detail',
@@ -151,94 +144,96 @@ class OpenAppClass {
151
144
  '/coupon-detail': 'coupon_detail',
152
145
  '/news/': 'essay_detail' // 文章详情
153
146
  };
154
- const target = Object.keys(keys).filter(function (value) {
147
+ var target = Object.keys(keys).filter(function (value) {
155
148
  return window.location.href.indexOf(value) > -1;
156
149
  });
157
- const type = target && target[0] && keys[target[0]];
158
- const searchParams = qs.parse(location.search.slice(1)); // 路由的query
159
- const id = parseInt(location.pathname.split('/').reverse()[0]) ||
150
+ var type = target && target[0] && keys[target[0]];
151
+ var searchParams = qs_1.default.parse(location.search.slice(1)); // 路由的query
152
+ var id = parseInt(location.pathname.split('/').reverse()[0]) ||
160
153
  parseInt(searchParams.id) ||
161
154
  parseInt(searchParams.carId) ||
162
155
  parseInt(searchParams.goodId); // 页面id
163
- const subject = searchParams.subject || undefined; // 页面标题或name
164
- const temp = {
156
+ var subject = searchParams.subject || undefined; // 页面标题或name
157
+ var temp = {
165
158
  relationType: type,
166
159
  id: id,
167
160
  name: subject
168
161
  };
169
- const data = this.openAppState?.state?.openApps || {};
170
- let open_url = '';
162
+ var data = ((_b = (_a = this.openAppState) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.openApps) || {};
163
+ var open_url = '';
171
164
  if (data.type && data.href === window.location.href) {
172
165
  temp.relationType = keys[data.type] || '';
173
166
  temp.id = data.id || '';
174
167
  temp.name = data.title || '';
175
168
  open_url = data.url || '';
176
169
  }
177
- const openUrl = open_url || searchParams.customOpenUrl || window.location.href;
170
+ var openUrl = open_url || searchParams.customOpenUrl || window.location.href;
178
171
  // activityId 大于零,type 为 activity
179
172
  if (searchParams.activityId) {
180
173
  temp.relationType = 'activity';
181
174
  temp.link = decodeURIComponent(decodeURIComponent(openUrl));
182
175
  }
183
176
  temp.jumpUrl = decodeURIComponent(decodeURIComponent(openUrl));
184
- const params = JSON.stringify(temp);
177
+ var params = JSON.stringify(temp);
185
178
  if (this._ios) {
186
- return `${this.currentEnv.motoIOSScheme}?params=${params}`;
179
+ return "".concat(this.currentEnv.motoIOSScheme, "?params=").concat(params);
187
180
  }
188
181
  if (this._android || this._isHarmonyos) {
189
- const url = this._wx ? `${this.appUrl}&android_scheme=${this.currentEnv.motoAndroidScheme}?params=${params}` : `${this.currentEnv.motoAndroidScheme}?params=${params}`;
182
+ var url = this._wx ? "".concat(this.appUrl, "&android_scheme=").concat(this.currentEnv.motoAndroidScheme, "?params=").concat(params) : "".concat(this.currentEnv.motoAndroidScheme, "?params=").concat(params);
190
183
  return url;
191
184
  }
192
185
  return undefined;
193
- }
186
+ };
194
187
  /**
195
188
  * 方法一(推荐):打开APP
196
189
  * http://www.cnblogs.com/shadajin/p/5724117.html
197
190
  */
198
- open(openUrl) {
191
+ OpenAppClass.prototype.open = function (openUrl) {
192
+ var _this = this;
199
193
  if (!openUrl) {
200
194
  this.underway = false;
201
195
  return;
202
196
  }
203
197
  if (this._ios) {
204
198
  this.underway = false;
205
- setTimeout(() => (location.href = this.appStoreUrl || ''), 3000);
199
+ setTimeout(function () { return (location.href = _this.appStoreUrl || ''); }, 3000);
206
200
  return (location.href = openUrl);
207
201
  }
208
202
  if (this._android) {
209
- const ifr = document.createElement('iframe');
210
- ifr.src = openUrl;
211
- ifr.style.display = 'none';
212
- document.body.appendChild(ifr);
203
+ var ifr_1 = document.createElement('iframe');
204
+ ifr_1.src = openUrl;
205
+ ifr_1.style.display = 'none';
206
+ document.body.appendChild(ifr_1);
213
207
  setTimeout(function () {
214
- document.body.removeChild(ifr);
208
+ document.body.removeChild(ifr_1);
215
209
  }, 3000);
216
210
  }
217
- return new Promise((resolve, reject) => {
211
+ return new Promise(function (resolve, reject) {
218
212
  // 检查APP是否打开
219
- const check = (elsTime) => {
213
+ var check = function (elsTime) {
220
214
  if (elsTime > 3000 || document.hidden) {
221
215
  // @ts-ignore
222
216
  resolve('成功打开APP');
223
217
  }
224
218
  else {
225
219
  // @ts-ignore
226
- window.location.href = `https://${location.host}/download`;
220
+ window.location.href = "https://".concat(location.host, "/download");
227
221
  reject('打开APP失败');
228
222
  }
229
- this.underway = false;
223
+ _this.underway = false;
230
224
  };
231
- let _count = 0;
232
- const _clickTime = +new Date();
233
- const intHandle = setInterval(() => {
225
+ var _count = 0;
226
+ var _clickTime = +new Date();
227
+ var intHandle = setInterval(function () {
234
228
  _count++;
235
- const elsTime = +new Date() - _clickTime;
229
+ var elsTime = +new Date() - _clickTime;
236
230
  if (_count >= 100 || elsTime > 3000) {
237
231
  clearInterval(intHandle);
238
232
  check(elsTime);
239
233
  }
240
234
  }, 20);
241
235
  });
242
- }
243
- }
244
- export default OpenAppClass;
236
+ };
237
+ return OpenAppClass;
238
+ }());
239
+ exports.default = OpenAppClass;
@@ -7,67 +7,75 @@
7
7
  * 3.自动捕获没有被catch的运行异常
8
8
  */
9
9
  'use strict';
10
- import Raven from 'raven-js';
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var raven_js_1 = __importDefault(require("raven-js"));
11
15
  // import RavenVue from 'raven-js/plugins/vue';
12
- class Report {
13
- static instance;
14
- constructor(Vue, options = {}) {
16
+ var Report = /** @class */ (function () {
17
+ function Report(Vue, options) {
18
+ if (options === void 0) { options = {}; }
15
19
  if (process.env.NODE_ENV !== 'development') {
16
20
  // todo
17
21
  }
18
22
  this.vue = Vue;
19
23
  this.options = options;
20
24
  }
21
- static getInstance(Vue, Option) {
25
+ Report.getInstance = function (Vue, Option) {
22
26
  if (!(this.instance instanceof this)) {
23
27
  this.instance = new this(Vue, Option);
24
28
  this.instance.install();
25
29
  }
26
30
  return this.instance;
27
- }
28
- install() {
31
+ };
32
+ Report.prototype.install = function () {
29
33
  if (process.env.NODE_ENV !== 'development') {
30
34
  // Raven.config(this.options.dsn, {
31
35
  // environment: process.env.NODE_ENV,
32
36
  // }).addPlugin(RavenVue, this.Vue).install();
33
37
  // raven内置了vue插件,会通过vue.config.errorHandler来捕获vue组件内错误并上报sentry服务
34
38
  // 记录用户信息
35
- Raven.setUserContext({ user: this.options.user || '' });
39
+ raven_js_1.default.setUserContext({ user: this.options.user || '' });
36
40
  // 设置全局tag标签
37
- Raven.setTagsContext({ environment: this.options.env || '' });
41
+ raven_js_1.default.setTagsContext({ environment: this.options.env || '' });
38
42
  }
39
- }
43
+ };
40
44
  /**
41
45
  * 主动上报
42
46
  * @param {String} data
43
47
  * @param {String} type 'info','warning','error'
44
48
  * @param {Object} options
45
49
  */
46
- log(data = null, type = 'error', options = {}) {
50
+ Report.prototype.log = function (data, type, options) {
51
+ if (data === void 0) { data = null; }
52
+ if (type === void 0) { type = 'error'; }
53
+ if (options === void 0) { options = {}; }
47
54
  // 添加面包屑
48
- Raven.captureBreadcrumb({
55
+ raven_js_1.default.captureBreadcrumb({
49
56
  message: data,
50
57
  category: 'manual message',
51
58
  });
52
59
  // 异常上报
53
60
  if (data instanceof Error) {
54
- Raven.captureException(data, {
61
+ raven_js_1.default.captureException(data, {
55
62
  level: type,
56
63
  logger: 'manual exception',
57
- tags: { options },
64
+ tags: { options: options },
58
65
  });
59
66
  }
60
67
  else {
61
- Raven.captureException('error', {
68
+ raven_js_1.default.captureException('error', {
62
69
  level: type,
63
70
  logger: 'manual data',
64
71
  extra: {
65
- data,
72
+ data: data,
66
73
  options: this.options,
67
74
  date: new Date(),
68
75
  },
69
76
  });
70
77
  }
71
- }
72
- }
73
- export default Report;
78
+ };
79
+ return Report;
80
+ }());
81
+ exports.default = Report;
@@ -76,7 +76,7 @@ declare class ToolsClass {
76
76
  * @param {String} str
77
77
  * @return {String}
78
78
  */
79
- clipboard(str: string): Error | Promise<void>;
79
+ clipboard(str: string): any;
80
80
  /**
81
81
  * 首字母大写
82
82
  * @param {String} str