gxd-uni-library-editx 1.0.0

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.
Files changed (215) hide show
  1. package/.editorconfig +14 -0
  2. package/README.md +447 -0
  3. package/index.js +3 -0
  4. package/package.json +104 -0
  5. package/postcss.config.js +22 -0
  6. package/settings.js.tpl +68 -0
  7. package/src/XdAppClass.1.0.js +257 -0
  8. package/src/XdAppClass.js +150 -0
  9. package/src/components/XdAddress/XdAddress.vue +579 -0
  10. package/src/components/XdAddressSelect/XdAddressSelect.vue +243 -0
  11. package/src/components/XdBaiduMap/XdBaiduMap.vue +204 -0
  12. package/src/components/XdBaiduOverlay/XdBaiduOverlay.vue +345 -0
  13. package/src/components/XdBaiduSearch/XdBaiduSearch.vue +354 -0
  14. package/src/components/XdBar/XdBar.vue +339 -0
  15. package/src/components/XdButton/XdButton.vue +288 -0
  16. package/src/components/XdCartList/XdCartList.vue +791 -0
  17. package/src/components/XdCartNoStoreList/XdCartNoStoreList.vue +747 -0
  18. package/src/components/XdCity/XdCity.vue +620 -0
  19. package/src/components/XdCity/city.js +93 -0
  20. package/src/components/XdCity/testData.js +124 -0
  21. package/src/components/XdCityLocation/XdCityLocation.vue +314 -0
  22. package/src/components/XdCityLocation/jweixin.js +72 -0
  23. package/src/components/XdCityShow/XdCityShow.vue +354 -0
  24. package/src/components/XdClipImage/XdClipImage.vue +879 -0
  25. package/src/components/XdCoins/XdCoins.vue +66 -0
  26. package/src/components/XdConfirm/XdConfirm.vue +240 -0
  27. package/src/components/XdContentXss/XdContentXss.vue +71 -0
  28. package/src/components/XdDailog/XdDailog.vue +258 -0
  29. package/src/components/XdDate/XdDataItemOne.vue +236 -0
  30. package/src/components/XdDate/XdDate.vue +1081 -0
  31. package/src/components/XdDate/XdDateItem.vue +316 -0
  32. package/src/components/XdDate/XdDateTime.vue +929 -0
  33. package/src/components/XdDate/i18n/en.json +19 -0
  34. package/src/components/XdDate/i18n/index.js +8 -0
  35. package/src/components/XdDate/i18n/zh-Hans.json +19 -0
  36. package/src/components/XdDate/i18n/zh-Hant.json +19 -0
  37. package/src/components/XdDate/keypress.js +45 -0
  38. package/src/components/XdDate/util.js +418 -0
  39. package/src/components/XdDownDrawer/XdDownDrawer.vue +176 -0
  40. package/src/components/XdEditPwd/XdEditPwd.vue +305 -0
  41. package/src/components/XdEnterOrderList/XdEnterOrderList.vue +413 -0
  42. package/src/components/XdExpressTimeLine/XdExpressTimeLine.vue +280 -0
  43. package/src/components/XdFilter/XdFilter.vue +541 -0
  44. package/src/components/XdFontIcon/XdFontIcon.vue +165 -0
  45. package/src/components/XdFontIcon/css/icon.less +498 -0
  46. package/src/components/XdFooterBar/XdFooterBar.vue +291 -0
  47. package/src/components/XdFooterTabbar/XdFooterTabbar.vue +284 -0
  48. package/src/components/XdForm/XdForm.vue +481 -0
  49. package/src/components/XdForm/validate.js +486 -0
  50. package/src/components/XdFormCheckbox/XdFormCheckbox.vue +858 -0
  51. package/src/components/XdFormDate.vue +187 -0
  52. package/src/components/XdFormInput/XdFormInput.vue +535 -0
  53. package/src/components/XdFormInput/common.js +56 -0
  54. package/src/components/XdFormItem/XdFormItem.vue +583 -0
  55. package/src/components/XdFormSelect/XdFormSelect.vue +119 -0
  56. package/src/components/XdImage/XdImage.vue +113 -0
  57. package/src/components/XdItemCardUser/XdItemCardUser.vue +232 -0
  58. package/src/components/XdItemFilmImage/XdItemFilmImage.vue +146 -0
  59. package/src/components/XdItemFilmText/XdItemFilmText.vue +83 -0
  60. package/src/components/XdItemPhysical/XdItemPhysical.vue +410 -0
  61. package/src/components/XdItemPhysicalPack/XdItemPhysicalPack.vue +240 -0
  62. package/src/components/XdItemStore/XdItemStore.vue +236 -0
  63. package/src/components/XdItemUserInfo/XdItemUserInfo.vue +175 -0
  64. package/src/components/XdJson/XdJson.vue +398 -0
  65. package/src/components/XdKeyValue/XdKeyValue.vue +150 -0
  66. package/src/components/XdLabelNew/XdLabelNew.vue +193 -0
  67. package/src/components/XdLayout/XdLayout.vue +634 -0
  68. package/src/components/XdLoading/XdLoading.vue +165 -0
  69. package/src/components/XdMore/XdMore.vue +66 -0
  70. package/src/components/XdMpHtml/XdMpHtml.vue +458 -0
  71. package/src/components/XdMpHtml/node/node.vue +536 -0
  72. package/src/components/XdMpHtml/parser.js +1260 -0
  73. package/src/components/XdMpHtml/static/js/handler.js +1 -0
  74. package/src/components/XdMpHtml/static/js/uni.webview.min.js +1 -0
  75. package/src/components/XdMpHtml/static/local.html +1 -0
  76. package/src/components/XdMy/XdMy.vue +294 -0
  77. package/src/components/XdMySuccess/XdMySuccess.vue +603 -0
  78. package/src/components/XdNavTab/XdNavTab.vue +147 -0
  79. package/src/components/XdNoData/XdNoData.vue +87 -0
  80. package/src/components/XdNoticeBar/XdNoticeBar.vue +501 -0
  81. package/src/components/XdNumber/XdNumber.vue +210 -0
  82. package/src/components/XdNumberUni/XdNumberUni.vue +270 -0
  83. package/src/components/XdNumberUni/readme.md +42 -0
  84. package/src/components/XdOnlineConfirm/XdOnlineConfirm.vue +385 -0
  85. package/src/components/XdOnlineDetail/XdOnlineDetail.vue +332 -0
  86. package/src/components/XdOnlinePay/XdOnlinePay.vue +349 -0
  87. package/src/components/XdOnlineSchedule/XdOnlineSchedule.vue +453 -0
  88. package/src/components/XdOnlineSeat/XdOnlineSeat.vue +796 -0
  89. package/src/components/XdOnlineSeatMove/XdOnlineSeatMove.vue +1012 -0
  90. package/src/components/XdPayCombo/XdPayCombo.vue +118 -0
  91. package/src/components/XdPreviewImage/XdPreviewImage.vue +372 -0
  92. package/src/components/XdPwPay/XdPwPay.vue +214 -0
  93. package/src/components/XdRadio/XdRadio.vue +151 -0
  94. package/src/components/XdRangeSlider/XdRangeSlider.vue +355 -0
  95. package/src/components/XdRedName/XdRedName.vue +35 -0
  96. package/src/components/XdSearchBar/XdSearchBar.vue +286 -0
  97. package/src/components/XdSelect/XdSelect.vue +382 -0
  98. package/src/components/XdSelectCity/XdSelectCity.vue +270 -0
  99. package/src/components/XdSelectTime/XdSelectTime.vue +342 -0
  100. package/src/components/XdStar/XdStar.vue +261 -0
  101. package/src/components/XdStoreCashier/XdStoreCashier.vue +526 -0
  102. package/src/components/XdStoreItem/XdStoreItem.vue +400 -0
  103. package/src/components/XdStoreOrderDetail/XdStoreOrderDetail.vue +1571 -0
  104. package/src/components/XdStoreOrderList/XdStoreOrderList.vue +450 -0
  105. package/src/components/XdStoreProductInfo/XdStoreProductInfo.vue +940 -0
  106. package/src/components/XdStoreProductType/XdStoreProductType.vue +307 -0
  107. package/src/components/XdSuccess/XdSuccess.vue +527 -0
  108. package/src/components/XdSwipeSelect/XdSwipeSelect.vue +99 -0
  109. package/src/components/XdSwiper/XdSwiper.vue +124 -0
  110. package/src/components/XdSwitch/XdSwitch.vue +204 -0
  111. package/src/components/XdTab/XdTab.vue +220 -0
  112. package/src/components/XdTabScroll/XdTabScroll.vue +212 -0
  113. package/src/components/XdTag/XdTag.vue +423 -0
  114. package/src/components/XdTimeLine/XdTimeLine.vue +121 -0
  115. package/src/components/XdTips/XdTips.vue +212 -0
  116. package/src/components/XdTipsBlock/XdTipsBlock.vue +141 -0
  117. package/src/components/XdTitleSection/XdTitleSection.vue +152 -0
  118. package/src/components/XdTitleTab/XdTitleTab.vue +227 -0
  119. package/src/components/XdUnit/XdUnit.vue +206 -0
  120. package/src/components/XdUpload/XdUpload.vue +197 -0
  121. package/src/components/XdUploadImage/XdUploadImage.vue +145 -0
  122. package/src/components/Xdlogs/XdLogs.vue +144 -0
  123. package/src/components/autoload.js +211 -0
  124. package/src/components/swipeAction/UniSwipeAction.vue +43 -0
  125. package/src/components/swipeActionItem/UniSwipeActionItem.vue +386 -0
  126. package/src/components/swipeActionItem/bindingx.js +298 -0
  127. package/src/components/swipeActionItem/index.wxs +321 -0
  128. package/src/components/swipeActionItem/isPC.js +18 -0
  129. package/src/components/swipeActionItem/mpalipay.js +210 -0
  130. package/src/components/swipeActionItem/mpother.js +252 -0
  131. package/src/components/swipeActionItem/mpwxs.js +140 -0
  132. package/src/dome/dome/address.vue +415 -0
  133. package/src/dome/dome/auth/login.vue +166 -0
  134. package/src/dome/dome/baidu_show.vue +20 -0
  135. package/src/dome/dome/cake.vue +186 -0
  136. package/src/dome/dome/cart.vue +205 -0
  137. package/src/dome/dome/cart_store.vue +149 -0
  138. package/src/dome/dome/cashier/cashier.vue +73 -0
  139. package/src/dome/dome/cashier/check_cashier.vue +469 -0
  140. package/src/dome/dome/cashier/success.vue +127 -0
  141. package/src/dome/dome/city.vue +148 -0
  142. package/src/dome/dome/cityData.js +9 -0
  143. package/src/dome/dome/clip.vue +82 -0
  144. package/src/dome/dome/date/date.vue +273 -0
  145. package/src/dome/dome/date/selected.js +315 -0
  146. package/src/dome/dome/dcom/app1.vue +13 -0
  147. package/src/dome/dome/dcom/app2.vue +13 -0
  148. package/src/dome/dome/dcom/app3.vue +13 -0
  149. package/src/dome/dome/dcom/app4.vue +13 -0
  150. package/src/dome/dome/dcom/app5.vue +13 -0
  151. package/src/dome/dome/dcom/index.vue +1 -0
  152. package/src/dome/dome/debug/debug.vue +95 -0
  153. package/src/dome/dome/docache/docache.vue +88 -0
  154. package/src/dome/dome/express.vue +269 -0
  155. package/src/dome/dome/form.vue +312 -0
  156. package/src/dome/dome/icon.js +125 -0
  157. package/src/dome/dome/icon.vue +93 -0
  158. package/src/dome/dome/index.vue +725 -0
  159. package/src/dome/dome/item.vue +236 -0
  160. package/src/dome/dome/json/json.vue +88 -0
  161. package/src/dome/dome/layout.vue +105 -0
  162. package/src/dome/dome/line.vue +113 -0
  163. package/src/dome/dome/map/search.vue +70 -0
  164. package/src/dome/dome/my.vue +171 -0
  165. package/src/dome/dome/notice.vue +93 -0
  166. package/src/dome/dome/online/confirm.vue +92 -0
  167. package/src/dome/dome/online/detail.vue +80 -0
  168. package/src/dome/dome/online/pay.vue +78 -0
  169. package/src/dome/dome/online/schedule.vue +73 -0
  170. package/src/dome/dome/online/seat.vue +98 -0
  171. package/src/dome/dome/order/detail.vue +166 -0
  172. package/src/dome/dome/order/enter_order.vue +294 -0
  173. package/src/dome/dome/order/list.vue +219 -0
  174. package/src/dome/dome/order/order.js +18 -0
  175. package/src/dome/dome/order/success.vue +68 -0
  176. package/src/dome/dome/product.vue +179 -0
  177. package/src/dome/dome/store_cashier.vue +67 -0
  178. package/src/dome/dome/swiper.vue +32 -0
  179. package/src/dome/dome/webview.vue +61 -0
  180. package/src/install.js +183 -0
  181. package/src/main/address/address.vue +251 -0
  182. package/src/main/cart/cart.vue +149 -0
  183. package/src/main/cashier/cashier.vue +72 -0
  184. package/src/main/cashier/check_cashier.vue +483 -0
  185. package/src/main/city/city.vue +149 -0
  186. package/src/main/date/date.vue +260 -0
  187. package/src/main/order/order.js +19 -0
  188. package/src/main/order/order.vue +222 -0
  189. package/src/main/product/detail.vue +121 -0
  190. package/src/main/product/type.vue +108 -0
  191. package/src/main/search/search.vue +501 -0
  192. package/src/pages.json +337 -0
  193. package/src/plugins/CreatedComponentsPlugin.js +19 -0
  194. package/src/plugins/JsonRename.js +72 -0
  195. package/src/plugins/SetAppParams.js +171 -0
  196. package/src/project.js +18 -0
  197. package/src/utils/Cookie.js +68 -0
  198. package/src/utils/Runtime.js +105 -0
  199. package/src/utils/Storage.js +104 -0
  200. package/src/utils/XdNetwork.js +133 -0
  201. package/src/utils/helper.js +1321 -0
  202. package/src/utils/nourl.js +95 -0
  203. package/src/utils/project.js +17 -0
  204. package/src/utils/xd.auth.js +61 -0
  205. package/src/utils/xd.base.js +474 -0
  206. package/src/utils/xd.common.js +240 -0
  207. package/src/utils/xd.event.js +99 -0
  208. package/src/utils/xd.frame.js +96 -0
  209. package/src/utils/xd.path.js +96 -0
  210. package/src/utils/xdAppLog.js +170 -0
  211. package/src/utils/xdWxLog.js +302 -0
  212. package/src/utils/xdh5log.js +307 -0
  213. package/src/websetting.js +64 -0
  214. package/tsconfig.json +9 -0
  215. package/xd.less +180 -0
@@ -0,0 +1,302 @@
1
+ 'use strict';
2
+ import {Base64} from 'js-base64';
3
+ import {runtime} from "@/common/runtime";
4
+
5
+ const settings = require('./../../settings');
6
+ const md5 = require('md5');
7
+ import Vue from 'vue';
8
+ import store from "@/store";
9
+ import {
10
+ baseIsEmpty,
11
+ baseJsDateToTime,
12
+ baseGetHost
13
+ } from "@/utils/xd.base";
14
+
15
+
16
+ let logInstance = null;
17
+
18
+
19
+ class Logs {
20
+ constructor() {
21
+ this.initDone = false; //是否已加载uni.request和brandInfo['api_host']完成
22
+ this.checkcount = 0; //最大检查1000次
23
+ this.startcount = 0; //最大检查可以上传日志次数
24
+ this.checkMaxWaitTime = 1000;
25
+ this.check();
26
+ this.saveUploadedLog = [];
27
+ this.onUpdateKeyword = [
28
+ '$vm', //跟uniApp uni.createSelectorQuery() 有关
29
+ "e.x", //跟uniApp滚动组件有关
30
+ 'null is not an object (evaluating', //跟uniApp滚动组件有关
31
+ "Cannot read property 'x' of ",// 跟uniApp滚动组件有关
32
+ ];
33
+
34
+ //#ifdef H5
35
+ this.initH5GlobalEvent()
36
+ //#endif
37
+ }
38
+
39
+ checkUniRequest() {
40
+ if (typeof uni === 'undefined') return false;
41
+ return typeof uni.request === 'function';
42
+ }
43
+
44
+ checkUniSetStorage() {
45
+ if (typeof uni === 'undefined') return false;
46
+ return typeof uni.setStorageSync === 'function';
47
+ }
48
+
49
+
50
+ checkApiHost() {
51
+ if (typeof getApp !== 'function') return false;
52
+ if (typeof getApp().globalData === "undefined") return false;
53
+ if (typeof getApp().globalData.$xd === 'undefined') return false;
54
+ if (typeof getApp().globalData.$xd['brandInfo'] === 'undefined') return false;
55
+ return typeof getApp().globalData.$xd['brandInfo']['api_host'] !== 'undefined';
56
+ }
57
+
58
+ check() {
59
+ let timer = setInterval(() => {
60
+ if ((this.checkUniRequest() && this.checkApiHost())
61
+ || this.checkcount > this.checkMaxWaitTime
62
+ ) {
63
+ this.initDone = true;
64
+ if (this.checkUniRequest() && this.checkApiHost()) {
65
+ setTimeout(() => {
66
+ this.checkBeforeStart();
67
+ }, 2000)
68
+ }
69
+ clearInterval(timer);
70
+ } else {
71
+ this.checkcount++;
72
+ }
73
+ }, 10)
74
+ }
75
+
76
+ checkBeforeStart() {
77
+ let timer = setInterval(() => {
78
+ if (this.startcount > this.checkMaxWaitTime) {
79
+ clearTimeout(timer);
80
+ return;
81
+ }
82
+ if (getApp().globalData.$xd['userInfo'] !== undefined
83
+ && !baseIsEmpty(getApp().globalData.$xd['userInfo'])
84
+ ) {
85
+ this.goBeforeUploadLogs();
86
+ clearTimeout(timer);
87
+ } else {
88
+ this.startcount++;
89
+ }
90
+ }, 10)
91
+ }
92
+
93
+ goBeforeUploadLogs() {
94
+ let logsSave = uni.getStorageInfoSync();
95
+ let logs = [];
96
+ logsSave.keys.map((key) => {
97
+ if (key.indexOf('xd.log.') === 0) {
98
+ logs.push(key);
99
+ }
100
+ });
101
+ logs.map((key) => {
102
+ let logStorage = uni.getStorageSync(key);
103
+ let system = this.getSystemInfo();
104
+
105
+ this.ajaxLogs({
106
+ baseApi: getApp().globalData.$xd.brandInfo['api_host'],
107
+ level: logStorage.level,
108
+ content: JSON.stringify({
109
+ ...system,
110
+ date: baseJsDateToTime(new Date().getTime() / 1000),
111
+ ...logStorage.logs
112
+ })
113
+ })
114
+ uni.removeStorageSync(key);
115
+ })
116
+
117
+ }
118
+
119
+ getSystemInfo() {
120
+ console.log(getApp().globalData.$xd.userInfo);
121
+ let userInfo = {};
122
+ let ext = {};
123
+ if (getApp().globalData
124
+ && getApp().globalData.$xd
125
+ && getApp().globalData.$xd.userInfo
126
+ ) {
127
+ userInfo = Base64.encodeURI(JSON.stringify(getApp().globalData.$xd.userInfo));
128
+ }
129
+
130
+ //#ifdef MP-WEIXIN
131
+ if (!baseIsEmpty(uni.getExtConfigSync())) {
132
+ ext = Base64.encodeURI(JSON.stringify(uni.getExtConfigSync()));
133
+ }
134
+ //#endif
135
+
136
+ const {
137
+ SDKVersion,
138
+ model,
139
+ system,
140
+ version,
141
+ deviceOrientation
142
+ } = uni.getSystemInfoSync();
143
+
144
+ console.log(userInfo, ext, uni.getSystemInfoSync());
145
+ return {
146
+ platform: 'weixin',
147
+ project: settings.system,
148
+ SDKVersion,
149
+ model,
150
+ system,
151
+ version,
152
+ deviceOrientation,
153
+ userInfo,
154
+ ext,
155
+ }
156
+ }
157
+
158
+
159
+ /**
160
+ * @description 上报日志
161
+ * @param log {Object} 上报日志内容
162
+ * @param type {String} 上报日志内容类型
163
+ * type = global(全局错误)
164
+ * type = onerror(系统捕获全局错误信息)
165
+ * type = promise(异步请求全局捕获错误)
166
+ * type = info(普通日志上报错误)
167
+ * type = debug(上报调试日志)
168
+ * type = ajax(返回异步请求字符串错误)
169
+ * type = unkown(返回异步请求字符串错误)
170
+ * tyoe = setting.error (项目配置错误)
171
+ * type = entry.index (记录访问首页入口来源)
172
+ * type = ajax.default {记录异步请求不知道的code的值}
173
+ * @param level {String} 上报级别 alert|info|debug
174
+ */
175
+ push(log, level = 'alert', type = "info") {
176
+ if (level === 'debug') {
177
+ if (settings.isDebug) {
178
+ level = 'info';
179
+ type = 'debug';
180
+ } else return;
181
+ }
182
+ type = `handle.${type}`;
183
+ if (!this.initDone) {
184
+ this.saveLog({log, type, level});
185
+ } else {
186
+ this.updateLog(log, type, level);
187
+ }
188
+ }
189
+
190
+ ajaxLogs(data) {
191
+ store['dispatch']('saveLogs', data)
192
+ .then(res => {
193
+ })
194
+ .catch(res => {
195
+ })
196
+ }
197
+
198
+ /**
199
+ * @description 上报日志
200
+ * @param log
201
+ * @param type
202
+ * @param level
203
+ */
204
+ updateLog(log, type, level) {
205
+ console.log(log, type, level);
206
+ let system = this.getSystemInfo();
207
+ if (level === 'info') system = {}
208
+ let logs = {...system, type, ...log};
209
+ let key = 'xd.log.' + md5(JSON.stringify(logs));
210
+ if (!this.saveUploadedLog.includes(key)) {
211
+ this.ajaxLogs({
212
+ baseApi: getApp().globalData.$xd.brandInfo['api_host'],
213
+ level: level,
214
+ content: JSON.stringify({
215
+ date: baseJsDateToTime(new Date().getTime() / 1000),
216
+ ...logs
217
+ }),
218
+ });
219
+ this.saveUploadedLog.push(key);
220
+ }
221
+ }
222
+
223
+ saveLog({log, type, level}) {
224
+ let logs = {type, before: true, ...log};
225
+ let key = 'xd.log.' + md5(JSON.stringify(logs));
226
+ if (this.checkUniSetStorage()) {
227
+ uni.setStorageSync(key, {logs, level});
228
+ }
229
+ }
230
+
231
+ checkMessage(error) {
232
+ let errorStr = error;
233
+ if (Object.prototype.toString.call(error) === '[object Error]') {
234
+ errorStr = JSON.stringify(runtime().getErrorInfo(error));
235
+ }
236
+ if (Object.prototype.toString.call(error) === '[object String]') {
237
+ errorStr = error;
238
+ }
239
+ if (Object.prototype.toString.call(error) === '[object Object]') {
240
+ errorStr = JSON.stringify(error);
241
+ }
242
+
243
+ let isUpdate = true;
244
+ this.onUpdateKeyword.map((keyword) => {
245
+ if (errorStr.indexOf(keyword) !== -1) {
246
+ isUpdate = false
247
+ }
248
+ });
249
+ return isUpdate === false ? isUpdate : Base64.encodeURI(errorStr);
250
+ }
251
+
252
+ initH5GlobalEvent() {
253
+ /**vue捕获全局错误**/
254
+ this.vueErrorHandler();
255
+ }
256
+
257
+ /**
258
+ * @description vue全局报错
259
+ */
260
+ vueErrorHandler() {
261
+ Vue.config.errorHandler = (error, vm) => {
262
+ let messageStr = this.checkMessage(error);
263
+ if (messageStr !== false) {
264
+ this.push(
265
+ {error: messageStr},
266
+ 'alert',
267
+ 'global'
268
+ )
269
+ }
270
+
271
+ };
272
+ }
273
+
274
+ /**
275
+ * @description 统一Promise catch处理
276
+ * @param error {Error|String} 错误对象(new Error())|字符串当为字符串时候,全局捕获不会处理
277
+ * @param callback 回调事件
278
+ */
279
+ catch(error, callback = null) {
280
+ let messageStr = logInstance.checkMessage(error);
281
+ if (messageStr !== false) {
282
+ logInstance.push(
283
+ {error: messageStr},
284
+ 'alert',
285
+ 'catch'
286
+ );
287
+ }
288
+ if (typeof callback === 'function') callback()
289
+ }
290
+ }
291
+
292
+ function xdWxlog() {
293
+ if (logInstance === null) {
294
+ logInstance = new Logs();
295
+ }
296
+ return logInstance;
297
+ }
298
+
299
+
300
+ export default xdWxlog();
301
+
302
+
@@ -0,0 +1,307 @@
1
+ 'use strict';
2
+ import {Base64} from 'js-base64';
3
+ import {runtime} from "@/common/runtime";
4
+ const settings = require('./../../settings');
5
+ const md5 = require('md5');
6
+ import Vue from 'vue';
7
+ import store from "@/store";
8
+ import {
9
+ baseIsEmpty,
10
+ baseJsDateToTime,
11
+ baseGetHost
12
+ } from "@/utils/xd.base";
13
+
14
+
15
+ let logInstance = null;
16
+
17
+
18
+ class Logs {
19
+ constructor(){
20
+ this.initDone = false; //是否已加载uni.request和brandInfo['api_host']完成
21
+ this.checkcount = 0; //最大检查1000次
22
+ this.startcount = 0; //最大检查可以上传日志次数
23
+ this.checkMaxWaitTime = 1000;
24
+ this.check();
25
+ this.saveUploadedLog = [];
26
+ this.onUpdateKeyword = [
27
+ '$vm', //跟uniApp uni.createSelectorQuery() 有关
28
+ "e.x", //跟uniApp滚动组件有关
29
+ 'null is not an object (evaluating', //跟uniApp滚动组件有关
30
+ "Cannot read property 'x' of ",// 跟uniApp滚动组件有关
31
+ ];
32
+
33
+ //#ifdef H5
34
+ this.initH5GlobalEvent()
35
+ //#endif
36
+ }
37
+
38
+ checkUniRequest(){
39
+ if(typeof uni === 'undefined') return false;
40
+ return typeof uni.request === 'function';
41
+ }
42
+
43
+ checkUniSetStorage() {
44
+ if (typeof uni === 'undefined') return false;
45
+ return typeof uni.setStorageSync === 'function';
46
+ }
47
+
48
+
49
+ checkApiHost(){
50
+ if(typeof getApp !== 'function') return false;
51
+ if(typeof getApp().globalData === "undefined") return false;
52
+ if(typeof getApp().globalData.$xd === 'undefined') return false;
53
+ if(typeof getApp().globalData.$xd['brandInfo'] === 'undefined') return false;
54
+ return typeof getApp().globalData.$xd['brandInfo']['api_host'] !== 'undefined';
55
+ }
56
+
57
+ check(){
58
+ let timer = setInterval(()=>{
59
+ if((this.checkUniRequest() && this.checkApiHost())
60
+ || this.checkcount > this.checkMaxWaitTime
61
+ ) {
62
+ this.initDone = true;
63
+ if(this.checkUniRequest() && this.checkApiHost()) {
64
+ setTimeout(()=>{
65
+ this.checkBeforeStart();
66
+ }, 2000)
67
+ }
68
+ clearInterval(timer);
69
+ }
70
+ else{
71
+ this.checkcount++;
72
+ }
73
+ }, 10)
74
+ }
75
+
76
+ checkBeforeStart(){
77
+ let timer = setInterval(()=>{
78
+ if(this.startcount > this.checkMaxWaitTime) {
79
+ clearTimeout(timer);
80
+ return;
81
+ }
82
+ if(getApp().globalData.$xd['userInfo'] !== undefined
83
+ && !baseIsEmpty(getApp().globalData.$xd['userInfo'])
84
+ ){
85
+ this.goBeforeUploadLogs();
86
+ clearTimeout(timer);
87
+ }
88
+ else {
89
+ this.startcount++;
90
+ }
91
+ }, 10)
92
+ }
93
+
94
+ goBeforeUploadLogs(){
95
+ let logsSave = uni.getStorageInfoSync();
96
+ let logs = [];
97
+ logsSave.keys.map((key)=>{
98
+ if(key.indexOf('xd.log.') === 0) {
99
+ logs.push(key);
100
+ }
101
+ });
102
+ logs.map((key)=>{
103
+ let logStorage = uni.getStorageSync(key);
104
+ let system = this.getSystemInfo();
105
+ if(logStorage.level === 'info') {
106
+ system = this.getBaseInfo();
107
+ }
108
+ this.ajaxLogs({
109
+ baseApi: getApp().globalData.$xd.brandInfo['api_host'],
110
+ level: logStorage.level,
111
+ content: JSON.stringify({
112
+ ...system,
113
+ date: baseJsDateToTime(new Date().getTime()/1000),
114
+ ...logStorage.logs
115
+ })
116
+ })
117
+ uni.removeStorageSync(key);
118
+ })
119
+
120
+ }
121
+
122
+ getSystemInfo(){
123
+ return {
124
+ ...this.getBaseInfo(),
125
+ //#ifdef H5
126
+ page: window.location.href,
127
+ userAgent: window.navigator.userAgent,
128
+ //#endif
129
+
130
+ }
131
+ }
132
+
133
+ getBaseInfo(){
134
+ return {
135
+ from: 'javascript',
136
+ host: baseGetHost(),
137
+ system: this.checkApiHost() ? getApp().globalData.$xd['brandInfo']['system'] : settings.system,
138
+ }
139
+ }
140
+
141
+ /**
142
+ * @description 上报日志
143
+ * @param log {Object} 上报日志内容
144
+ * @param type {String} 上报日志内容类型
145
+ * type = global(全局错误)
146
+ * type = onerror(系统捕获全局错误信息)
147
+ * type = promise(异步请求全局捕获错误)
148
+ * type = info(普通日志上报错误)
149
+ * type = debug(上报调试日志)
150
+ * type = ajax(返回异步请求字符串错误)
151
+ * type = unkown(返回异步请求字符串错误)
152
+ * tyoe = setting.error (项目配置错误)
153
+ * type = entry.index (记录访问首页入口来源)
154
+ * type = ajax.default {记录异步请求不知道的code的值}
155
+ * @param level {String} 上报级别 alert|info|debug
156
+ */
157
+ push(log, level = 'alert', type="info"){
158
+ if(level === 'debug') {
159
+ if(settings.isDebug) {
160
+ level = 'info';
161
+ type = 'debug';
162
+ }
163
+ else return;
164
+ }
165
+ type = `handle.${type}`;
166
+ if(!this.initDone) {
167
+ this.saveLog({log, type, level});
168
+ }else{
169
+ this.updateLog(log, type, level);
170
+ }
171
+ }
172
+
173
+ ajaxLogs(data){
174
+ store['dispatch']('saveLogs', data)
175
+ .then(res => {
176
+ })
177
+ .catch(res => {})
178
+ }
179
+
180
+ /**
181
+ * @description 上报日志
182
+ * @param log
183
+ * @param type
184
+ * @param level
185
+ */
186
+ updateLog(log, type, level){
187
+ console.log(log, type, level);
188
+ let system = this.getSystemInfo();
189
+ if(level === 'info') system = this.getBaseInfo();
190
+ let logs = {...system, type, ...log};
191
+ let key = 'xd.log.' + md5(JSON.stringify(logs));
192
+ if(!this.saveUploadedLog.includes(key)) {
193
+ this.ajaxLogs({
194
+ baseApi: getApp().globalData.$xd.brandInfo['api_host'],
195
+ level: level,
196
+ content: JSON.stringify({
197
+ date: baseJsDateToTime(new Date().getTime()/1000),
198
+ ...logs
199
+ }),
200
+ });
201
+ this.saveUploadedLog.push(key);
202
+ }
203
+ }
204
+
205
+ saveLog({log, type, level}){
206
+ let logs = {type , before: true, ...log};
207
+ let key = 'xd.log.' + md5(JSON.stringify(logs));
208
+ if(this.checkUniSetStorage()) {
209
+ uni.setStorageSync(key, {logs, level});
210
+ }
211
+ }
212
+
213
+ checkMessage(error){
214
+ let errorStr = error;
215
+ if(Object.prototype.toString.call(error) === '[object Error]') {
216
+ errorStr = JSON.stringify(runtime().getErrorInfo(error));
217
+ }
218
+ if(Object.prototype.toString.call(error) === '[object String]') {
219
+ errorStr = error;
220
+ }
221
+ if (Object.prototype.toString.call(error) === '[object Object]') {
222
+ errorStr = JSON.stringify(error);
223
+ }
224
+
225
+ let isUpdate = true;
226
+ this.onUpdateKeyword.map((keyword)=>{
227
+ if(errorStr.indexOf(keyword) !== -1) {
228
+ isUpdate = false
229
+ }
230
+ });
231
+ return isUpdate === false ? isUpdate: Base64.encodeURI(errorStr);
232
+ }
233
+
234
+ initH5GlobalEvent(){
235
+ /**promise全局报错捕获错误**/
236
+ window.addEventListener('unhandledrejection', (event)=> {
237
+ if(Object.prototype.toString.call(event.reason) === '[object Error]') {
238
+ let message = this.checkMessage(event.reason);
239
+ if(message!== false) {
240
+ this.push(
241
+ {error: message},
242
+ 'alert',
243
+ 'promise'
244
+ );
245
+ }
246
+ }
247
+ });
248
+
249
+ window.onerror = (message, line, yPos, xPos, error)=>{
250
+ console.log(message, line, yPos, xPos, error);
251
+ if(Object.prototype.toString.call(error) === '[object Error]') {
252
+ let messageStr = this.checkMessage(message);
253
+ if (messageStr !== false) {
254
+ this.push(
255
+ {message, line, yPos, xPos, error: messageStr},
256
+ 'alert',
257
+ 'onerror'
258
+ )
259
+ }
260
+
261
+ }
262
+ };
263
+
264
+ /**vue捕获全局错误**/
265
+ this.vueErrorHandler();
266
+ }
267
+
268
+ /**
269
+ * @description vue全局报错
270
+ */
271
+ vueErrorHandler(){
272
+ Vue.config.errorHandler = (error, vm) => {
273
+ let messageStr = this.checkMessage(error);
274
+ if (messageStr !== false) {
275
+ this.push(
276
+ {error: messageStr},
277
+ 'alert',
278
+ 'global'
279
+ )
280
+ }
281
+
282
+ };
283
+ }
284
+
285
+ /**
286
+ * @description 统一Promise catch处理
287
+ * @param error {Error|String} 错误对象(new Error())|字符串当为字符串时候,全局捕获不会处理
288
+ * @param callback 回调事件
289
+ */
290
+ catch(error, callback = null){
291
+ console.log(typeof callback)
292
+ if(typeof callback === "function") callback();
293
+ throw error;
294
+ }
295
+ }
296
+
297
+ function xdh5log() {
298
+ if(logInstance === null){
299
+ logInstance = new Logs();
300
+ }
301
+ return logInstance;
302
+ }
303
+
304
+
305
+ export default xdh5log();
306
+
307
+
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+ /**
3
+ * @description 网址配置文件
4
+ * @attr websetting.mainColor 主色调
5
+ * @attr websetting.btnColor 按钮主色调
6
+ * @attr websetting.subBtnColor 次级按钮主色调
7
+ * @attr websetting.home //首页路径默认为:/pages/index/index
8
+ * @attr websetting.color tabbar文字颜色
9
+ *
10
+ * @attr websetting.selectedColor tabbar当前选中文字颜色
11
+ * @attr websetting.backgroundColor tabbar背景颜色值
12
+ * @attr websetting.showIcon tabbar图标类型 false=》图片(本地路径与base64)推荐使用base64 true=》iconfont图标(需要自己自定义)
13
+ * @attr websetting.list tabbar列表
14
+ * @attr websetting.list.text tabbar文案(4个汉字)
15
+ * @attr websetting.list.iconPath tabbar图标图片路径
16
+ * @attr websetting.list.selectedIconPath tabbar当前路径图标图片路径
17
+ * @attr websetting.list.pagePath 链接路径
18
+ * @attr websetting.list.icon iconfont图标
19
+ */
20
+ export default Object.assign({}, {
21
+ "color": "#333",//文字颜色
22
+ "showIcon": true, //icon 获取 图片
23
+ "mainColor": '#EC4D71', //主色调
24
+ "btnColor": '#EC4D71', //按钮主色调
25
+ "subBtnColor": '#FB8B9C', //次级按钮主色调
26
+ "barBackground": '#fff', //bar背景颜色
27
+ "barTextAlign": 'center', //top bar 文字对齐方式
28
+ "barBackgroundImage": 'https://image.jufubao.cn/default_gonghui_bg.png', //bar背景图片(背景图片优先)
29
+ "selectedColor": "#EC4D71", //tabbar选中颜色
30
+ "backgroundColor": "#fff", //tabbar背景颜色
31
+ "unitTextColor": "#f00", //单位颜色
32
+ "home": '/pages/index/index', //首页路径默认为:/pages/index/index
33
+ "isRedirect": false, //底部Tabber连接是否自带路径参数:xdRedirect=L21haW4vaW5kZXgvaW5kZXg
34
+ //计算单位
35
+ 'unitIcon': 'https://jfb-public-images.oss-cn-qingdao.aliyuncs.com/admin-upload/202110031633364777.png', //100*100
36
+ "list": [
37
+ {
38
+ "pagePath": "/dome/dome/index",
39
+ "icon": "iconshouye_mian",
40
+ 'size': 38,
41
+ "text": "首页"
42
+ },
43
+ {
44
+ "pagePath": "/main/product/type",
45
+ "icon": "iconxiangqin_mian",
46
+ 'size': 40,
47
+ "text": "分类"
48
+ },
49
+ {
50
+ "pagePath": "/dome/dome/cart",
51
+ "icon": 'iconzhaohu_mian',
52
+ 'size': 34,
53
+ "text": "购物车"
54
+ },
55
+ {
56
+ "pagePath": "/dome/dome/item",
57
+ "icon": "iconwode_mian",
58
+ "text": "Items",
59
+ 'size': 40,
60
+ }
61
+ ]
62
+ }) ;
63
+
64
+
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "types": [
4
+ "@dcloudio/types",
5
+ "miniprogram-api-typings",
6
+ "mini-types"
7
+ ]
8
+ }
9
+ }