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.
- package/.editorconfig +14 -0
- package/README.md +447 -0
- package/index.js +3 -0
- package/package.json +104 -0
- package/postcss.config.js +22 -0
- package/settings.js.tpl +68 -0
- package/src/XdAppClass.1.0.js +257 -0
- package/src/XdAppClass.js +150 -0
- package/src/components/XdAddress/XdAddress.vue +579 -0
- package/src/components/XdAddressSelect/XdAddressSelect.vue +243 -0
- package/src/components/XdBaiduMap/XdBaiduMap.vue +204 -0
- package/src/components/XdBaiduOverlay/XdBaiduOverlay.vue +345 -0
- package/src/components/XdBaiduSearch/XdBaiduSearch.vue +354 -0
- package/src/components/XdBar/XdBar.vue +339 -0
- package/src/components/XdButton/XdButton.vue +288 -0
- package/src/components/XdCartList/XdCartList.vue +791 -0
- package/src/components/XdCartNoStoreList/XdCartNoStoreList.vue +747 -0
- package/src/components/XdCity/XdCity.vue +620 -0
- package/src/components/XdCity/city.js +93 -0
- package/src/components/XdCity/testData.js +124 -0
- package/src/components/XdCityLocation/XdCityLocation.vue +314 -0
- package/src/components/XdCityLocation/jweixin.js +72 -0
- package/src/components/XdCityShow/XdCityShow.vue +354 -0
- package/src/components/XdClipImage/XdClipImage.vue +879 -0
- package/src/components/XdCoins/XdCoins.vue +66 -0
- package/src/components/XdConfirm/XdConfirm.vue +240 -0
- package/src/components/XdContentXss/XdContentXss.vue +71 -0
- package/src/components/XdDailog/XdDailog.vue +258 -0
- package/src/components/XdDate/XdDataItemOne.vue +236 -0
- package/src/components/XdDate/XdDate.vue +1081 -0
- package/src/components/XdDate/XdDateItem.vue +316 -0
- package/src/components/XdDate/XdDateTime.vue +929 -0
- package/src/components/XdDate/i18n/en.json +19 -0
- package/src/components/XdDate/i18n/index.js +8 -0
- package/src/components/XdDate/i18n/zh-Hans.json +19 -0
- package/src/components/XdDate/i18n/zh-Hant.json +19 -0
- package/src/components/XdDate/keypress.js +45 -0
- package/src/components/XdDate/util.js +418 -0
- package/src/components/XdDownDrawer/XdDownDrawer.vue +176 -0
- package/src/components/XdEditPwd/XdEditPwd.vue +305 -0
- package/src/components/XdEnterOrderList/XdEnterOrderList.vue +413 -0
- package/src/components/XdExpressTimeLine/XdExpressTimeLine.vue +280 -0
- package/src/components/XdFilter/XdFilter.vue +541 -0
- package/src/components/XdFontIcon/XdFontIcon.vue +165 -0
- package/src/components/XdFontIcon/css/icon.less +498 -0
- package/src/components/XdFooterBar/XdFooterBar.vue +291 -0
- package/src/components/XdFooterTabbar/XdFooterTabbar.vue +284 -0
- package/src/components/XdForm/XdForm.vue +481 -0
- package/src/components/XdForm/validate.js +486 -0
- package/src/components/XdFormCheckbox/XdFormCheckbox.vue +858 -0
- package/src/components/XdFormDate.vue +187 -0
- package/src/components/XdFormInput/XdFormInput.vue +535 -0
- package/src/components/XdFormInput/common.js +56 -0
- package/src/components/XdFormItem/XdFormItem.vue +583 -0
- package/src/components/XdFormSelect/XdFormSelect.vue +119 -0
- package/src/components/XdImage/XdImage.vue +113 -0
- package/src/components/XdItemCardUser/XdItemCardUser.vue +232 -0
- package/src/components/XdItemFilmImage/XdItemFilmImage.vue +146 -0
- package/src/components/XdItemFilmText/XdItemFilmText.vue +83 -0
- package/src/components/XdItemPhysical/XdItemPhysical.vue +410 -0
- package/src/components/XdItemPhysicalPack/XdItemPhysicalPack.vue +240 -0
- package/src/components/XdItemStore/XdItemStore.vue +236 -0
- package/src/components/XdItemUserInfo/XdItemUserInfo.vue +175 -0
- package/src/components/XdJson/XdJson.vue +398 -0
- package/src/components/XdKeyValue/XdKeyValue.vue +150 -0
- package/src/components/XdLabelNew/XdLabelNew.vue +193 -0
- package/src/components/XdLayout/XdLayout.vue +634 -0
- package/src/components/XdLoading/XdLoading.vue +165 -0
- package/src/components/XdMore/XdMore.vue +66 -0
- package/src/components/XdMpHtml/XdMpHtml.vue +458 -0
- package/src/components/XdMpHtml/node/node.vue +536 -0
- package/src/components/XdMpHtml/parser.js +1260 -0
- package/src/components/XdMpHtml/static/js/handler.js +1 -0
- package/src/components/XdMpHtml/static/js/uni.webview.min.js +1 -0
- package/src/components/XdMpHtml/static/local.html +1 -0
- package/src/components/XdMy/XdMy.vue +294 -0
- package/src/components/XdMySuccess/XdMySuccess.vue +603 -0
- package/src/components/XdNavTab/XdNavTab.vue +147 -0
- package/src/components/XdNoData/XdNoData.vue +87 -0
- package/src/components/XdNoticeBar/XdNoticeBar.vue +501 -0
- package/src/components/XdNumber/XdNumber.vue +210 -0
- package/src/components/XdNumberUni/XdNumberUni.vue +270 -0
- package/src/components/XdNumberUni/readme.md +42 -0
- package/src/components/XdOnlineConfirm/XdOnlineConfirm.vue +385 -0
- package/src/components/XdOnlineDetail/XdOnlineDetail.vue +332 -0
- package/src/components/XdOnlinePay/XdOnlinePay.vue +349 -0
- package/src/components/XdOnlineSchedule/XdOnlineSchedule.vue +453 -0
- package/src/components/XdOnlineSeat/XdOnlineSeat.vue +796 -0
- package/src/components/XdOnlineSeatMove/XdOnlineSeatMove.vue +1012 -0
- package/src/components/XdPayCombo/XdPayCombo.vue +118 -0
- package/src/components/XdPreviewImage/XdPreviewImage.vue +372 -0
- package/src/components/XdPwPay/XdPwPay.vue +214 -0
- package/src/components/XdRadio/XdRadio.vue +151 -0
- package/src/components/XdRangeSlider/XdRangeSlider.vue +355 -0
- package/src/components/XdRedName/XdRedName.vue +35 -0
- package/src/components/XdSearchBar/XdSearchBar.vue +286 -0
- package/src/components/XdSelect/XdSelect.vue +382 -0
- package/src/components/XdSelectCity/XdSelectCity.vue +270 -0
- package/src/components/XdSelectTime/XdSelectTime.vue +342 -0
- package/src/components/XdStar/XdStar.vue +261 -0
- package/src/components/XdStoreCashier/XdStoreCashier.vue +526 -0
- package/src/components/XdStoreItem/XdStoreItem.vue +400 -0
- package/src/components/XdStoreOrderDetail/XdStoreOrderDetail.vue +1571 -0
- package/src/components/XdStoreOrderList/XdStoreOrderList.vue +450 -0
- package/src/components/XdStoreProductInfo/XdStoreProductInfo.vue +940 -0
- package/src/components/XdStoreProductType/XdStoreProductType.vue +307 -0
- package/src/components/XdSuccess/XdSuccess.vue +527 -0
- package/src/components/XdSwipeSelect/XdSwipeSelect.vue +99 -0
- package/src/components/XdSwiper/XdSwiper.vue +124 -0
- package/src/components/XdSwitch/XdSwitch.vue +204 -0
- package/src/components/XdTab/XdTab.vue +220 -0
- package/src/components/XdTabScroll/XdTabScroll.vue +212 -0
- package/src/components/XdTag/XdTag.vue +423 -0
- package/src/components/XdTimeLine/XdTimeLine.vue +121 -0
- package/src/components/XdTips/XdTips.vue +212 -0
- package/src/components/XdTipsBlock/XdTipsBlock.vue +141 -0
- package/src/components/XdTitleSection/XdTitleSection.vue +152 -0
- package/src/components/XdTitleTab/XdTitleTab.vue +227 -0
- package/src/components/XdUnit/XdUnit.vue +206 -0
- package/src/components/XdUpload/XdUpload.vue +197 -0
- package/src/components/XdUploadImage/XdUploadImage.vue +145 -0
- package/src/components/Xdlogs/XdLogs.vue +144 -0
- package/src/components/autoload.js +211 -0
- package/src/components/swipeAction/UniSwipeAction.vue +43 -0
- package/src/components/swipeActionItem/UniSwipeActionItem.vue +386 -0
- package/src/components/swipeActionItem/bindingx.js +298 -0
- package/src/components/swipeActionItem/index.wxs +321 -0
- package/src/components/swipeActionItem/isPC.js +18 -0
- package/src/components/swipeActionItem/mpalipay.js +210 -0
- package/src/components/swipeActionItem/mpother.js +252 -0
- package/src/components/swipeActionItem/mpwxs.js +140 -0
- package/src/dome/dome/address.vue +415 -0
- package/src/dome/dome/auth/login.vue +166 -0
- package/src/dome/dome/baidu_show.vue +20 -0
- package/src/dome/dome/cake.vue +186 -0
- package/src/dome/dome/cart.vue +205 -0
- package/src/dome/dome/cart_store.vue +149 -0
- package/src/dome/dome/cashier/cashier.vue +73 -0
- package/src/dome/dome/cashier/check_cashier.vue +469 -0
- package/src/dome/dome/cashier/success.vue +127 -0
- package/src/dome/dome/city.vue +148 -0
- package/src/dome/dome/cityData.js +9 -0
- package/src/dome/dome/clip.vue +82 -0
- package/src/dome/dome/date/date.vue +273 -0
- package/src/dome/dome/date/selected.js +315 -0
- package/src/dome/dome/dcom/app1.vue +13 -0
- package/src/dome/dome/dcom/app2.vue +13 -0
- package/src/dome/dome/dcom/app3.vue +13 -0
- package/src/dome/dome/dcom/app4.vue +13 -0
- package/src/dome/dome/dcom/app5.vue +13 -0
- package/src/dome/dome/dcom/index.vue +1 -0
- package/src/dome/dome/debug/debug.vue +95 -0
- package/src/dome/dome/docache/docache.vue +88 -0
- package/src/dome/dome/express.vue +269 -0
- package/src/dome/dome/form.vue +312 -0
- package/src/dome/dome/icon.js +125 -0
- package/src/dome/dome/icon.vue +93 -0
- package/src/dome/dome/index.vue +725 -0
- package/src/dome/dome/item.vue +236 -0
- package/src/dome/dome/json/json.vue +88 -0
- package/src/dome/dome/layout.vue +105 -0
- package/src/dome/dome/line.vue +113 -0
- package/src/dome/dome/map/search.vue +70 -0
- package/src/dome/dome/my.vue +171 -0
- package/src/dome/dome/notice.vue +93 -0
- package/src/dome/dome/online/confirm.vue +92 -0
- package/src/dome/dome/online/detail.vue +80 -0
- package/src/dome/dome/online/pay.vue +78 -0
- package/src/dome/dome/online/schedule.vue +73 -0
- package/src/dome/dome/online/seat.vue +98 -0
- package/src/dome/dome/order/detail.vue +166 -0
- package/src/dome/dome/order/enter_order.vue +294 -0
- package/src/dome/dome/order/list.vue +219 -0
- package/src/dome/dome/order/order.js +18 -0
- package/src/dome/dome/order/success.vue +68 -0
- package/src/dome/dome/product.vue +179 -0
- package/src/dome/dome/store_cashier.vue +67 -0
- package/src/dome/dome/swiper.vue +32 -0
- package/src/dome/dome/webview.vue +61 -0
- package/src/install.js +183 -0
- package/src/main/address/address.vue +251 -0
- package/src/main/cart/cart.vue +149 -0
- package/src/main/cashier/cashier.vue +72 -0
- package/src/main/cashier/check_cashier.vue +483 -0
- package/src/main/city/city.vue +149 -0
- package/src/main/date/date.vue +260 -0
- package/src/main/order/order.js +19 -0
- package/src/main/order/order.vue +222 -0
- package/src/main/product/detail.vue +121 -0
- package/src/main/product/type.vue +108 -0
- package/src/main/search/search.vue +501 -0
- package/src/pages.json +337 -0
- package/src/plugins/CreatedComponentsPlugin.js +19 -0
- package/src/plugins/JsonRename.js +72 -0
- package/src/plugins/SetAppParams.js +171 -0
- package/src/project.js +18 -0
- package/src/utils/Cookie.js +68 -0
- package/src/utils/Runtime.js +105 -0
- package/src/utils/Storage.js +104 -0
- package/src/utils/XdNetwork.js +133 -0
- package/src/utils/helper.js +1321 -0
- package/src/utils/nourl.js +95 -0
- package/src/utils/project.js +17 -0
- package/src/utils/xd.auth.js +61 -0
- package/src/utils/xd.base.js +474 -0
- package/src/utils/xd.common.js +240 -0
- package/src/utils/xd.event.js +99 -0
- package/src/utils/xd.frame.js +96 -0
- package/src/utils/xd.path.js +96 -0
- package/src/utils/xdAppLog.js +170 -0
- package/src/utils/xdWxLog.js +302 -0
- package/src/utils/xdh5log.js +307 -0
- package/src/websetting.js +64 -0
- package/tsconfig.json +9 -0
- package/xd.less +180 -0
|
@@ -0,0 +1,1321 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
import {Base64} from 'js-base64';
|
|
3
|
+
import {
|
|
4
|
+
PLATFORM_PARAM_SETTING
|
|
5
|
+
} from "./../project";
|
|
6
|
+
|
|
7
|
+
import store from "@/store";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
baseCheckVarType,
|
|
11
|
+
baseIsEmpty,
|
|
12
|
+
baseCloneDeep,
|
|
13
|
+
baseJsDateToTime,
|
|
14
|
+
baseInArray
|
|
15
|
+
} from "@/utils/xd.base";
|
|
16
|
+
|
|
17
|
+
class Helpers {
|
|
18
|
+
|
|
19
|
+
constructor(){
|
|
20
|
+
/**
|
|
21
|
+
* @description 底部tabbar加载完成
|
|
22
|
+
* @type {boolean}
|
|
23
|
+
*/
|
|
24
|
+
this.footTabbar = false;
|
|
25
|
+
this.start = null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @description 首字母大写操作
|
|
30
|
+
* @param string
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
charFirstUpper(string) {
|
|
34
|
+
let words = string.split(' ');
|
|
35
|
+
for (let i = 0; i < words.length; i++) {
|
|
36
|
+
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
|
|
37
|
+
}
|
|
38
|
+
return words.join(' ');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/***
|
|
42
|
+
* @description 判断变量类型
|
|
43
|
+
* @param obj
|
|
44
|
+
* @returns {*}
|
|
45
|
+
*/
|
|
46
|
+
checkVarType(obj){
|
|
47
|
+
return baseCheckVarType(obj)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @description 获取最近某时间断内的时间
|
|
52
|
+
* @param lastDay 默认30天
|
|
53
|
+
* @returns {number}
|
|
54
|
+
*/
|
|
55
|
+
getTime(lastDay = 30) {
|
|
56
|
+
let now = new Date().getTime();
|
|
57
|
+
let randomDay = this.random({min: 0, max: lastDay}); //获取随机天数毫秒数字
|
|
58
|
+
let randomHour = this.random({min: 0, max: 23}); //获取随机小时数
|
|
59
|
+
let randomMinutes = this.random({min: 0, max: 59}); //获取随机分钟数
|
|
60
|
+
let randomSeconds = this.random({min: 0, max: 59}); //获取随机秒数
|
|
61
|
+
|
|
62
|
+
randomDay = randomDay * 24 * 60 * 60 * 1000;
|
|
63
|
+
randomHour = randomHour * 60 * 60 * 1000;
|
|
64
|
+
randomMinutes = randomMinutes * 60 * 1000;
|
|
65
|
+
randomSeconds = randomSeconds * 1000;
|
|
66
|
+
return now - randomDay + randomHour + randomMinutes + randomSeconds;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @description 简单深拷贝
|
|
71
|
+
* @param json
|
|
72
|
+
* @returns {any}
|
|
73
|
+
*/
|
|
74
|
+
cloneDeep(json){
|
|
75
|
+
return baseCloneDeep(json)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @description 自定义深拷贝
|
|
80
|
+
* @param any {Object|Array|Function|Date|RegExp|Map|Set|String}
|
|
81
|
+
* @returns {*}
|
|
82
|
+
*/
|
|
83
|
+
customClone(any){
|
|
84
|
+
if (this.checkVarType(any) === 'object') { // 拷贝对象
|
|
85
|
+
let o = {};
|
|
86
|
+
for (let key in any) {
|
|
87
|
+
o[key] = this.customClone(any[key])
|
|
88
|
+
}
|
|
89
|
+
return o;
|
|
90
|
+
}
|
|
91
|
+
else if (this.checkVarType(any) === 'array') { // 拷贝数组
|
|
92
|
+
let arr = []
|
|
93
|
+
for (let i = 0, leng = any.length; i < leng; i++) {
|
|
94
|
+
arr[i] = this.customClone(any[i])
|
|
95
|
+
}
|
|
96
|
+
return arr;
|
|
97
|
+
}
|
|
98
|
+
else if (this.checkVarType(any) === 'function') { // 拷贝函数
|
|
99
|
+
return new Function('return ' + any.toString()).call(this)
|
|
100
|
+
}
|
|
101
|
+
else if (this.checkVarType(any) === 'date') { // 拷贝日期
|
|
102
|
+
return new Date(any.valueOf())
|
|
103
|
+
}
|
|
104
|
+
else if (this.checkVarType(any) === 'regExp') { // 拷贝正则
|
|
105
|
+
return new RegExp(any)
|
|
106
|
+
}
|
|
107
|
+
else if (this.checkVarType(any) === 'map') { // 拷贝Map 集合
|
|
108
|
+
let m = new Map();
|
|
109
|
+
any.forEach((v, k) => {
|
|
110
|
+
m.set(k, this.customClone(v))
|
|
111
|
+
});
|
|
112
|
+
return m
|
|
113
|
+
}
|
|
114
|
+
else if (this.checkVarType(any) === 'set') { // 拷贝Set 集合
|
|
115
|
+
let s = new Set();
|
|
116
|
+
for (let val of any.values()) {
|
|
117
|
+
s.add(this.customClone(val))
|
|
118
|
+
}
|
|
119
|
+
return s
|
|
120
|
+
}
|
|
121
|
+
return any;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/***
|
|
125
|
+
* @description 随机数字值
|
|
126
|
+
* @param min 最小数
|
|
127
|
+
* @param max 最大数
|
|
128
|
+
* @returns {*}
|
|
129
|
+
*/
|
|
130
|
+
random(min, max) {
|
|
131
|
+
let Range = max - min;
|
|
132
|
+
let Rand = Math.random();
|
|
133
|
+
return (min + Math.round(Rand * Range));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @description 数据数组的值
|
|
138
|
+
* @param arr {Array}
|
|
139
|
+
*/
|
|
140
|
+
romdomArray(arr = []) {
|
|
141
|
+
if (arr.length === 0) return null;
|
|
142
|
+
if (arr.length === 1) return arr[0];
|
|
143
|
+
let min = 0;
|
|
144
|
+
let max = arr.length - 1;
|
|
145
|
+
let index = this.random(min, max);
|
|
146
|
+
return arr[index];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @description 统一返回格式
|
|
151
|
+
* @param data
|
|
152
|
+
* @param code
|
|
153
|
+
* @param message
|
|
154
|
+
*/
|
|
155
|
+
callback(data = [], code = 200, message = 'success') {
|
|
156
|
+
return {
|
|
157
|
+
code,
|
|
158
|
+
data,
|
|
159
|
+
message
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @description 检测查找数组是否在原数组中
|
|
166
|
+
* @param sourceArray 原数组
|
|
167
|
+
* @param findArray 查找数组
|
|
168
|
+
* @returns {boolean}
|
|
169
|
+
*/
|
|
170
|
+
inArray(sourceArray = [], findArray = []){
|
|
171
|
+
return baseInArray(sourceArray, findArray)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @description 数组去重复
|
|
176
|
+
* @param sourceArray
|
|
177
|
+
* @returns {*[]}
|
|
178
|
+
*/
|
|
179
|
+
repeatArray(sourceArray = []){
|
|
180
|
+
if(this.checkVarType(sourceArray) !== 'array') {
|
|
181
|
+
console.log('repeatArray.sourceArray.error', sourceArray);
|
|
182
|
+
throw new Error('sourceArray参数类型是数组')
|
|
183
|
+
}
|
|
184
|
+
return Array.from(new Set(sourceArray))
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/***
|
|
188
|
+
* @description 数组并集
|
|
189
|
+
* @param sourceArray
|
|
190
|
+
* @param findArray
|
|
191
|
+
* @returns {*[]}
|
|
192
|
+
*/
|
|
193
|
+
unionArray(sourceArray = [], findArray = []){
|
|
194
|
+
if (this.checkVarType(sourceArray) !== 'array') {
|
|
195
|
+
console.log('unionArray.sourceArray.error', sourceArray);
|
|
196
|
+
throw new Error('sourceArray参数类型是数组')
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
if (this.checkVarType(findArray) !== 'array') {
|
|
200
|
+
console.log('unionArray.findArray.error', findArray);
|
|
201
|
+
throw new Error('findArray参数类型是数组')
|
|
202
|
+
}
|
|
203
|
+
return Array.from(new Set(sourceArray.concat(findArray)))
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @description 数组交集
|
|
208
|
+
* @param sourceArray
|
|
209
|
+
* @param findArray
|
|
210
|
+
* @returns {*[]}
|
|
211
|
+
*/
|
|
212
|
+
intersectionArray(sourceArray = [], findArray = []){
|
|
213
|
+
if (this.checkVarType(sourceArray) !== 'array') {
|
|
214
|
+
console.log('intersectionArray.sourceArray.error', sourceArray);
|
|
215
|
+
throw new Error('sourceArray参数类型是数组')
|
|
216
|
+
}
|
|
217
|
+
if (this.checkVarType(findArray) !== 'array') {
|
|
218
|
+
console.log('intersectionArray.findArray.error', findArray);
|
|
219
|
+
throw new Error('findArray参数类型是数组')
|
|
220
|
+
}
|
|
221
|
+
return sourceArray.filter(function (v) {
|
|
222
|
+
return findArray.indexOf(v) > -1
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @description 数组差集
|
|
228
|
+
* @param sourceArray
|
|
229
|
+
* @param findArray
|
|
230
|
+
* @returns {*[]}
|
|
231
|
+
*/
|
|
232
|
+
differenceArray(sourceArray = [], findArray = []){
|
|
233
|
+
if (this.checkVarType(sourceArray) !== 'array') {
|
|
234
|
+
console.log('differenceArray.sourceArray.error', sourceArray);
|
|
235
|
+
throw new Error('sourceArray参数类型是数组')
|
|
236
|
+
}
|
|
237
|
+
if (this.checkVarType(findArray) !== 'array') {
|
|
238
|
+
console.log('differenceArray.findArray.error', findArray);
|
|
239
|
+
throw new Error('findArray参数类型是数组')
|
|
240
|
+
}
|
|
241
|
+
return sourceArray.filter(function (v) {
|
|
242
|
+
return findArray.indexOf(v) === -1
|
|
243
|
+
}).concat(findArray.filter(function (v) {
|
|
244
|
+
return sourceArray.indexOf(v) === -1
|
|
245
|
+
}))
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @description 检查对象或者数组是否为空
|
|
250
|
+
* @param obj
|
|
251
|
+
* @return boolean
|
|
252
|
+
*/
|
|
253
|
+
isEmpty(obj) {
|
|
254
|
+
return baseIsEmpty(obj)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @description 只支持数组与JSON对象格式遍历
|
|
260
|
+
* @param source
|
|
261
|
+
* @param callback
|
|
262
|
+
*/
|
|
263
|
+
forEach(source, callback){
|
|
264
|
+
if(this.checkVarType(source) === 'object' && !this.isEmpty(source)) {
|
|
265
|
+
Object.keys(source).forEach(callback);
|
|
266
|
+
}else if(this.checkVarType(source) === 'array') {
|
|
267
|
+
source.forEach((item, index)=>{
|
|
268
|
+
callback(index);
|
|
269
|
+
});
|
|
270
|
+
}else{
|
|
271
|
+
console.log('forEach.error', source);
|
|
272
|
+
throw new Error('只支持数组与JSON对象格式');
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/***
|
|
277
|
+
* @description 对象数组排序升序函数
|
|
278
|
+
* @param property 数组某条记录的键
|
|
279
|
+
* @returns {function(*, *): number}
|
|
280
|
+
*/
|
|
281
|
+
compareAscSort(property) {
|
|
282
|
+
return function (a, b) {
|
|
283
|
+
let value1 = a[property];
|
|
284
|
+
let value2 = b[property];
|
|
285
|
+
return value1 - value2;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/***
|
|
290
|
+
* @description 对象数组排序降序函数
|
|
291
|
+
* @param property 数组某条记录的键
|
|
292
|
+
* @returns {function(*, *): number}
|
|
293
|
+
*/
|
|
294
|
+
compareDescSort(property) {
|
|
295
|
+
return function (a, b) {
|
|
296
|
+
let value1 = a[property];
|
|
297
|
+
let value2 = b[property];
|
|
298
|
+
return value2 - value1;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* @deprecated 检查值是否在数组中或者对象中
|
|
305
|
+
* @param list
|
|
306
|
+
* @param value
|
|
307
|
+
* @param keyName
|
|
308
|
+
* @example
|
|
309
|
+
* [{id: 1,name:'gao'},{id: 2,name:'wu'}]
|
|
310
|
+
* OR
|
|
311
|
+
* {'1':{id: 1,name:'gao'},'2':{id: 2,name:'wu'}}
|
|
312
|
+
* @return []
|
|
313
|
+
*/
|
|
314
|
+
isKeyInLists(list, value, keyName='id'){
|
|
315
|
+
let items = null;
|
|
316
|
+
if(this.checkVarType(list) === 'array'
|
|
317
|
+
|| this.checkVarType(list) === 'object'
|
|
318
|
+
){
|
|
319
|
+
this.forEach(list,(index)=>{
|
|
320
|
+
let item = list[index];
|
|
321
|
+
if(String(value) === String(list[index][keyName])) {
|
|
322
|
+
items = item;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
return items;
|
|
326
|
+
}
|
|
327
|
+
else{
|
|
328
|
+
console.log('isKeyInLists.error', list);
|
|
329
|
+
throw new Error('只支持数组与JSON对象格式');
|
|
330
|
+
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @deprecated 获取数组或者对象中的摸个key的value值
|
|
336
|
+
* @param list
|
|
337
|
+
* @param keyName
|
|
338
|
+
* @example
|
|
339
|
+
* [{id: 1,name:'gao'},{id: 2,name:'wu'}]
|
|
340
|
+
* OR
|
|
341
|
+
* {'1':{id: 1,name:'gao'},'2':{id: 2,name:'wu'}}
|
|
342
|
+
* @return []
|
|
343
|
+
*/
|
|
344
|
+
getListKeyForValue(list, keyName = 'id'){
|
|
345
|
+
let arr = [];
|
|
346
|
+
if (this.checkVarType(list) === 'array'
|
|
347
|
+
|| this.checkVarType(list) === 'object'
|
|
348
|
+
) {
|
|
349
|
+
this.forEach(list, (index) => {
|
|
350
|
+
let item = list[index];
|
|
351
|
+
arr.push(item[keyName]);
|
|
352
|
+
});
|
|
353
|
+
return arr;
|
|
354
|
+
} else {
|
|
355
|
+
console.log('getListKeyForValue.error', list);
|
|
356
|
+
throw new Error('只支持数组与JSON对象格式');
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* @description 删除参数中[all|'']
|
|
362
|
+
* @param source
|
|
363
|
+
* @param ignoreKey 忽略的key
|
|
364
|
+
*/
|
|
365
|
+
deleteParamEmptyKey(source, ignoreKey = [] ){
|
|
366
|
+
let data = this.cloneDeep(source); //防止对象浅拷贝
|
|
367
|
+
this.forEach(data, (key) => {
|
|
368
|
+
if(ignoreKey.length > 0) {
|
|
369
|
+
if(!this.inArray(ignoreKey,[key])) {
|
|
370
|
+
if (data[key] === 'all' || data[key] === '') {
|
|
371
|
+
delete data[key];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else{
|
|
376
|
+
if (data[key] === 'all' || data[key] === '') {
|
|
377
|
+
delete data[key];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
});
|
|
382
|
+
return data;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* @description 对象转url参数
|
|
388
|
+
* @param params
|
|
389
|
+
*/
|
|
390
|
+
jsonToParams(params){
|
|
391
|
+
params = this.cloneDeep(params);
|
|
392
|
+
let paramsStr = '';
|
|
393
|
+
let count = 0;
|
|
394
|
+
this.forEach(params, (key) => {
|
|
395
|
+
if(count === 0) {
|
|
396
|
+
paramsStr = `${key}=${params[key]}`;
|
|
397
|
+
}
|
|
398
|
+
else{
|
|
399
|
+
paramsStr += `&${key}=${params[key]}`;
|
|
400
|
+
}
|
|
401
|
+
count++;
|
|
402
|
+
});
|
|
403
|
+
return paramsStr;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* @description 字符串截取
|
|
409
|
+
* @param val
|
|
410
|
+
* @param len
|
|
411
|
+
*/
|
|
412
|
+
cutStringLen(val, len = 10) {
|
|
413
|
+
let fix = '...';
|
|
414
|
+
let newLength = 0;
|
|
415
|
+
let newStr = "";
|
|
416
|
+
let chineseRegex = /[^\x00-\xff]/g;
|
|
417
|
+
let singleChar = "";
|
|
418
|
+
let strLength = val.replace(chineseRegex, "**").length;
|
|
419
|
+
for (let i = 0; i < strLength; i++) {
|
|
420
|
+
singleChar = val.charAt(i).toString();
|
|
421
|
+
if (singleChar.match(chineseRegex) != null) {
|
|
422
|
+
newLength += 2;
|
|
423
|
+
} else {
|
|
424
|
+
newLength++;
|
|
425
|
+
}
|
|
426
|
+
if (newLength > len) {
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
newStr += singleChar;
|
|
430
|
+
}
|
|
431
|
+
if (strLength > len) {
|
|
432
|
+
newStr += fix;
|
|
433
|
+
}
|
|
434
|
+
return newStr;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/***
|
|
438
|
+
* @description 解析url地址
|
|
439
|
+
* @param url
|
|
440
|
+
* @returns {}
|
|
441
|
+
*/
|
|
442
|
+
parseURL(url) {
|
|
443
|
+
let params = (search) => {
|
|
444
|
+
let ret = {},
|
|
445
|
+
seg = search.replace(/^\?/, '').split('&'),
|
|
446
|
+
len = seg.length, i = 0, s;
|
|
447
|
+
for (; i < len; i++) {
|
|
448
|
+
if (!seg[i]) {
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
s = seg[i].split('=');
|
|
452
|
+
if (s[1]) {
|
|
453
|
+
ret[s[0]] = s[1];
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return ret;
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
//#ifdef H5
|
|
460
|
+
if (!url) url = window.location.href;
|
|
461
|
+
let a = document.createElement('a');
|
|
462
|
+
a.href = url;
|
|
463
|
+
let http = a.protocol.replace(':', '');
|
|
464
|
+
let segments = a.pathname.replace(/^\//, '').split('/');
|
|
465
|
+
if(segments.length === 1 && segments['0'] === '') {
|
|
466
|
+
segments = [];
|
|
467
|
+
}
|
|
468
|
+
let path = a.pathname.replace(/^([^\/])/, '/$1');
|
|
469
|
+
|
|
470
|
+
//首页路径
|
|
471
|
+
if(path === '/') {
|
|
472
|
+
path = ROUTES[0]['path']
|
|
473
|
+
}
|
|
474
|
+
let fullhost = `${http}://${a.hostname}${a.port === '80' || a.port === ''?'': ':' + a.port}/${segments.join('/')}`;
|
|
475
|
+
return {
|
|
476
|
+
source: url,
|
|
477
|
+
protocol: http,
|
|
478
|
+
host: a.hostname,
|
|
479
|
+
port: a.port,
|
|
480
|
+
query: a.search,
|
|
481
|
+
params: params(a.search),
|
|
482
|
+
domainHost: `${http}://${a.hostname}${a.port === '80' || a.port === '' ? '' : ':' + a.port}`,
|
|
483
|
+
fullhost,
|
|
484
|
+
file: (a.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1],
|
|
485
|
+
hash: a.hash.replace('#', ''),
|
|
486
|
+
path: path,
|
|
487
|
+
relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1],
|
|
488
|
+
segments
|
|
489
|
+
};
|
|
490
|
+
//#endif
|
|
491
|
+
|
|
492
|
+
//#ifndef H5
|
|
493
|
+
if(!url) {
|
|
494
|
+
let routes = getCurrentPages();
|
|
495
|
+
let oroute = routes[routes.length - 1];
|
|
496
|
+
url = oroute['$page']['fullPath'];
|
|
497
|
+
}
|
|
498
|
+
let pathname = '';
|
|
499
|
+
let search = '';
|
|
500
|
+
if(url.indexOf('?') === -1) {
|
|
501
|
+
pathname = url;
|
|
502
|
+
}else{
|
|
503
|
+
pathname = url.split('?')[0];
|
|
504
|
+
search = url.split('?')[1];
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
return{
|
|
508
|
+
source: url,
|
|
509
|
+
query: search,
|
|
510
|
+
params: params(search),
|
|
511
|
+
relative: url,
|
|
512
|
+
segments: pathname.replace(/^\//, '').split('/'),
|
|
513
|
+
path: pathname.replace(/^([^\/])/, '/$1'),
|
|
514
|
+
file: (pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1],
|
|
515
|
+
}
|
|
516
|
+
//#endif
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* @description 获取参数值
|
|
521
|
+
* @param key
|
|
522
|
+
* @returns {null|*}
|
|
523
|
+
*/
|
|
524
|
+
getParmater(key) {
|
|
525
|
+
let params = this.parseURL()['params'];
|
|
526
|
+
if (params && params[key]) {
|
|
527
|
+
return params[key];
|
|
528
|
+
} else {
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* @description 判断俩个需要处理的数字谁的小数点后位数多,
|
|
535
|
+
* 以多的为准,值乘以10的小数位的幂数,相加以后,再除以10的小数位的幂数
|
|
536
|
+
* @param currentNum
|
|
537
|
+
* @param targetNum
|
|
538
|
+
*/
|
|
539
|
+
checkFloatMore(currentNum, targetNum){
|
|
540
|
+
let sq1, sq2;
|
|
541
|
+
try {sq1 = currentNum.toString().split(".")[1].length;}
|
|
542
|
+
catch (e) {sq1 = 0;}
|
|
543
|
+
try {sq2 = targetNum.toString().split(".")[1].length;}
|
|
544
|
+
catch (e) {sq2 = 0;}
|
|
545
|
+
return Math.pow(10, Math.max(sq1, sq2));
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* @description 两个小数相加
|
|
550
|
+
* @param currentNum
|
|
551
|
+
* @param targetNum
|
|
552
|
+
* @return number
|
|
553
|
+
*/
|
|
554
|
+
addFloatNumber(currentNum, targetNum){
|
|
555
|
+
let power = this.checkFloatMore(currentNum, targetNum);
|
|
556
|
+
return (this.multiplyFloatNumber(currentNum, power) + this.multiplyFloatNumber(targetNum, power)) / power;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* @description 两个小数减
|
|
561
|
+
* @param currentNum
|
|
562
|
+
* @param targetNum
|
|
563
|
+
* @return number
|
|
564
|
+
*/
|
|
565
|
+
cutFloatNumber(currentNum, targetNum) {
|
|
566
|
+
let power = this.checkFloatMore(currentNum, targetNum);
|
|
567
|
+
return (this.multiplyFloatNumber(currentNum, power) - this.multiplyFloatNumber(targetNum, power)) / power;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* @description 计算两个小数相乘
|
|
572
|
+
* @param currentNum
|
|
573
|
+
* @param targetNum
|
|
574
|
+
* @returns {number}
|
|
575
|
+
*/
|
|
576
|
+
multiplyFloatNumber(currentNum, targetNum){
|
|
577
|
+
let m = 0, s1 = currentNum.toString(), s2 = targetNum.toString();
|
|
578
|
+
try {m += s1.split(".")[1].length;} catch (e) {}
|
|
579
|
+
try {m += s2.split(".")[1].length;} catch (e) {}
|
|
580
|
+
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* @description 计算两个小数相除
|
|
585
|
+
* @param currentNum
|
|
586
|
+
* @param targetNum
|
|
587
|
+
* @returns {number}
|
|
588
|
+
*/
|
|
589
|
+
divisionFloatNumber(currentNum, targetNum){
|
|
590
|
+
let t1 = 0, t2 = 0, r1, r2;
|
|
591
|
+
try {t1 = currentNum.toString().split(".")[1].length} catch (e) {}
|
|
592
|
+
try {t2 = targetNum.toString().split(".")[1].length} catch (e) {}
|
|
593
|
+
r1 = Number(currentNum.toString().replace(".", ""))
|
|
594
|
+
r2 = Number(targetNum.toString().replace(".", ""))
|
|
595
|
+
return this.multiplyFloatNumber(r1 / r2, Math.pow(10, t2 - t1));
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* @description 获取元素详情信息
|
|
601
|
+
* @param ele
|
|
602
|
+
* @param component
|
|
603
|
+
* @param next
|
|
604
|
+
*/
|
|
605
|
+
getEleInfo(ele, component, next) {
|
|
606
|
+
let time = new Date().getTime();
|
|
607
|
+
if (!uni['getEleInfoCount']) {
|
|
608
|
+
uni['getEleInfoCount'] = 1;
|
|
609
|
+
} else {
|
|
610
|
+
uni['getEleInfoCount']++;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
let query = uni.createSelectorQuery().in(component);
|
|
614
|
+
query.select(ele).boundingClientRect().exec((res) => {
|
|
615
|
+
//未找到元素
|
|
616
|
+
if (res[0] === null) {
|
|
617
|
+
if (uni['getEleInfoCount'] > 100) {
|
|
618
|
+
next({}, ele);
|
|
619
|
+
} else {
|
|
620
|
+
this.getEleInfo(ele, component, next)
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
//已找到
|
|
625
|
+
else {
|
|
626
|
+
if (res[0]['width'] > 0
|
|
627
|
+
|| res[0]['height'] > 0
|
|
628
|
+
|| res[0]['left'] > 0
|
|
629
|
+
|| res[0]['right'] > 0
|
|
630
|
+
|| res[0]['top'] > 0
|
|
631
|
+
|| res[0]['bottom'] > 0
|
|
632
|
+
) {
|
|
633
|
+
res[0]['id'] = ele;
|
|
634
|
+
uni['getEleInfoCount'] = 1;
|
|
635
|
+
next(res[0], ele);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
//已找到但是节点信息为,重载
|
|
641
|
+
else {
|
|
642
|
+
setTimeout(() => {
|
|
643
|
+
this.getEleInfo(ele, component, next)
|
|
644
|
+
}, 10);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
})
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/***
|
|
651
|
+
* @description 获取元素的相关值
|
|
652
|
+
* @param ele
|
|
653
|
+
* @param component
|
|
654
|
+
* @returns {Promise<unknown>}
|
|
655
|
+
*/
|
|
656
|
+
getWindowHeight(ele = [], component= undefined) {
|
|
657
|
+
if(component === undefined) {
|
|
658
|
+
throw new Error('请传入vue实例')
|
|
659
|
+
}
|
|
660
|
+
let eleLen = ele.length;
|
|
661
|
+
let eleObject = {};
|
|
662
|
+
let eleObjectLen = [];
|
|
663
|
+
eleObject['systemInfo'] = getApp().globalData.$systemInfo || uni.getSystemInfoSync();
|
|
664
|
+
this.start = new Date().getTime();
|
|
665
|
+
return new Promise((resolve, reject) => {
|
|
666
|
+
if (uni === undefined || this.checkVarType(ele) !== 'array') {
|
|
667
|
+
reject('不支持操作')
|
|
668
|
+
}
|
|
669
|
+
ele.map((item, index) => {
|
|
670
|
+
this.getEleInfo(item, component, (res, keyword) => {
|
|
671
|
+
eleObject[keyword] = res;
|
|
672
|
+
eleObjectLen.push(keyword);
|
|
673
|
+
if (eleObjectLen.length === eleLen) {
|
|
674
|
+
resolve(eleObject);
|
|
675
|
+
}
|
|
676
|
+
})
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
})
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* @description 获取当前网页地址栏设置
|
|
684
|
+
* @param home 设置默认首页路径
|
|
685
|
+
*/
|
|
686
|
+
getCurrentPages(home = '/pages/index/index') {
|
|
687
|
+
let route = {
|
|
688
|
+
path: null,
|
|
689
|
+
hash: null,
|
|
690
|
+
query: {}
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
//#ifdef H5
|
|
694
|
+
let path = this.parseURL();
|
|
695
|
+
route['hash'] = path['hash'];
|
|
696
|
+
route['query'] = path['params'];
|
|
697
|
+
if (path['path'] === '/' || path['path'] === ' ') {
|
|
698
|
+
route['path'] = home;
|
|
699
|
+
} else {
|
|
700
|
+
route['path'] = path['path'];
|
|
701
|
+
}
|
|
702
|
+
return route;
|
|
703
|
+
//#endif
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
//#ifndef H5
|
|
707
|
+
let routes = getCurrentPages();
|
|
708
|
+
let oroute = routes[routes.length - 1];
|
|
709
|
+
route['hash'] = '';
|
|
710
|
+
route['query'] = oroute.$page['query'];
|
|
711
|
+
route['path'] = `/${oroute.route}`;
|
|
712
|
+
return route;
|
|
713
|
+
//#endif
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* @description 去掉左边指定字符串
|
|
718
|
+
* @param str
|
|
719
|
+
* @param replaceStr
|
|
720
|
+
* @returns {string}
|
|
721
|
+
*/
|
|
722
|
+
tirmL(str = '', replaceStr = ',') {
|
|
723
|
+
if (!str || this.checkVarType(str) !== 'string') {
|
|
724
|
+
return str;
|
|
725
|
+
}
|
|
726
|
+
let homeReg = new RegExp(`^(${replaceStr})(.+)$`);
|
|
727
|
+
let homeMatchStr = str.match(homeReg);
|
|
728
|
+
if (homeMatchStr) str = homeMatchStr[2];
|
|
729
|
+
return str;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* @description 去掉右边指定字符串
|
|
734
|
+
* @param str
|
|
735
|
+
* @param replaceStr
|
|
736
|
+
* @returns {string}
|
|
737
|
+
*/
|
|
738
|
+
tirmR(str = '', replaceStr = ',') {
|
|
739
|
+
if (!str || this.checkVarType(str) !== 'string') {
|
|
740
|
+
return str;
|
|
741
|
+
}
|
|
742
|
+
let endReg = new RegExp(`^(.+)(${replaceStr})$`);
|
|
743
|
+
let endMatchStr = str.match(endReg);
|
|
744
|
+
if (endMatchStr) str = endMatchStr[1];
|
|
745
|
+
return str;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* @description 去掉两部指定字符串
|
|
750
|
+
* @param str
|
|
751
|
+
* @param replaceStr
|
|
752
|
+
* @return {string}
|
|
753
|
+
*/
|
|
754
|
+
tirm(str = '', replaceStr = ',') {
|
|
755
|
+
str = this.tirmL(str, replaceStr);
|
|
756
|
+
str = this.tirmR(str, replaceStr);
|
|
757
|
+
return str;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* @description 跳转页面 https://uniapp.dcloud.io/api/router?id=navigateto
|
|
762
|
+
* @param obj 与(uni.navigateTo, uni.redirectTo)的Object参数相同
|
|
763
|
+
* @param redirect 是否添加当前页面地址路径最为回调地址
|
|
764
|
+
* @param type type {boolean} 跳转类型 true=>navigateTo false=>redirectTo
|
|
765
|
+
*/
|
|
766
|
+
handleTo(obj = {}, redirect, type = true) {
|
|
767
|
+
|
|
768
|
+
//是否开启xdRedirect参数
|
|
769
|
+
let proRedirect = null;
|
|
770
|
+
if(PLATFORM_PARAM_SETTING.IS_ClOSE_REDIRECT) proRedirect = PLATFORM_PARAM_SETTING.IS_ClOSE_REDIRECT;
|
|
771
|
+
if(proRedirect === null) {
|
|
772
|
+
redirect = redirect === undefined ? true: redirect;
|
|
773
|
+
}else {
|
|
774
|
+
redirect = false;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
let reg = /^(http:\/\/|https:\/\/|\/\/).+$/;
|
|
778
|
+
let isH5 = reg.test(obj.url);
|
|
779
|
+
|
|
780
|
+
//从参数 或者 本地Storage
|
|
781
|
+
let params = '';
|
|
782
|
+
let xdProject= obj[PLATFORM_PARAM_SETTING.EVENT_PARAM_SAVE_KEY]
|
|
783
|
+
|| uni.getStorageSync(PLATFORM_PARAM_SETTING.EVENT_PARAM_SAVE_KEY);
|
|
784
|
+
|
|
785
|
+
//全平台参数设置
|
|
786
|
+
if(xdProject) {
|
|
787
|
+
params = encodeURIComponent(xdProject);
|
|
788
|
+
params = `${PLATFORM_PARAM_SETTING.EVENT_PARAM_NAME}=${params}`;
|
|
789
|
+
delete obj[PLATFORM_PARAM_SETTING.EVENT_PARAM_SAVE_KEY];
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
if (redirect) {
|
|
793
|
+
let redirectUrl = `xdRedirect=${Base64.encodeURI(this.parseURL()['relative'])}`;
|
|
794
|
+
//h5端才能使用url绝对地址
|
|
795
|
+
if (isH5) {
|
|
796
|
+
redirectUrl = `xdRedirect=${Base64.encodeURI(this.parseURL()['source'])}`;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
//连接地址中已经有活动ID
|
|
800
|
+
if (obj['url'].indexOf(PLATFORM_PARAM_SETTING.EVENT_PARAM_NAME) !== -1) params = '';
|
|
801
|
+
else {
|
|
802
|
+
if(params) params = `&${params}`;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
if (obj['url'].indexOf('?') !== -1) {
|
|
806
|
+
obj['url'] = `${obj['url']}&${redirectUrl}${params}`;
|
|
807
|
+
} else {
|
|
808
|
+
obj['url'] = `${obj['url']}?${redirectUrl}${params}`;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
//设置活动ID
|
|
813
|
+
else{
|
|
814
|
+
//连接地址中已经有活动ID
|
|
815
|
+
if (obj['url'].indexOf(PLATFORM_PARAM_SETTING.EVENT_PARAM_NAME) !== -1) params = '';
|
|
816
|
+
if (obj['url'].indexOf('?') !== -1) {
|
|
817
|
+
obj['url'] = `${obj['url']}${params ? ('&' + params): params}`;
|
|
818
|
+
} else {
|
|
819
|
+
obj['url'] = `${obj['url']}${params ? ('?' + params) : params}`;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
if (isH5) {
|
|
824
|
+
window.location.href = obj['url'];
|
|
825
|
+
} else {
|
|
826
|
+
if (type) uni.navigateTo(obj);
|
|
827
|
+
else uni.redirectTo(obj);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* @description 返回处理
|
|
833
|
+
* @param type {boolean} 跳转类型 true=>navigateTo false=>redirectTo
|
|
834
|
+
* @private
|
|
835
|
+
*/
|
|
836
|
+
handleBack(type = true) {
|
|
837
|
+
let reg = /^(http:\/\/|https:\/\/|\/\/).+$/;
|
|
838
|
+
try {
|
|
839
|
+
let redirect = this.getParmater('xdRedirect');
|
|
840
|
+
let xdProjectCallback = this.getParmater('xdProjectCallback'); //项目间跳转
|
|
841
|
+
if(xdProjectCallback) {
|
|
842
|
+
window.location.href = Base64.decode(xdProjectCallback);
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
if (!redirect) {
|
|
846
|
+
throw new Error('无返回地址');
|
|
847
|
+
}
|
|
848
|
+
let url = decodeURIComponent(Base64.decode(redirect));
|
|
849
|
+
if (reg.test(url)) {
|
|
850
|
+
window.location.href = url;
|
|
851
|
+
} else {
|
|
852
|
+
if (type) {
|
|
853
|
+
uni.navigateBack({
|
|
854
|
+
delta: 1
|
|
855
|
+
});
|
|
856
|
+
} else uni.redirectTo({url});
|
|
857
|
+
}
|
|
858
|
+
} catch (e) {
|
|
859
|
+
uni.navigateBack({
|
|
860
|
+
delta: 1
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* @description 保留当前页面,跳转到应用内的某个页面 https://uniapp.dcloud.io/api/router?id=navigateto
|
|
867
|
+
* @param obj 与uni.navigateTo的Object参数相同
|
|
868
|
+
* @param redirect 是否添加当前页面地址路径最为回调地址
|
|
869
|
+
*/
|
|
870
|
+
navigateTo(obj = {}, redirect) {
|
|
871
|
+
this.handleTo( obj, redirect)
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* @description 项目与项目中跳转与返回, 仅支持H5端(url地址为绝对路径地址)
|
|
876
|
+
* 返回使用 navigateBack 和 redirectBack 均可以
|
|
877
|
+
* @param obj 与uni.navigateTo的Object参数相同
|
|
878
|
+
*@param redirect 是否添加当前页面地址路径最为回调地址
|
|
879
|
+
*/
|
|
880
|
+
navigateProjectTo(obj = {}, redirect = false) {
|
|
881
|
+
let reg = /^(http:\/\/|https:\/\/|\/\/).+$/;
|
|
882
|
+
let isH5 = reg.test(obj.url);
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
//将要跳转地址host与当前域名host相同
|
|
886
|
+
if (isH5) {
|
|
887
|
+
let currentHost = this.parseURL();
|
|
888
|
+
let toHost = this.parseURL(obj.url);
|
|
889
|
+
|
|
890
|
+
//判断同源地址
|
|
891
|
+
if (currentHost['host'] === toHost['host']
|
|
892
|
+
&& currentHost['port'] === toHost['port']
|
|
893
|
+
) {
|
|
894
|
+
obj.url = toHost['path'];
|
|
895
|
+
if (!this.isEmpty(toHost.params)) {
|
|
896
|
+
obj.url = `${obj.url}${toHost.query}`
|
|
897
|
+
}
|
|
898
|
+
isH5 = false;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
if(isH5){
|
|
903
|
+
let callback= Base64.encodeURI(window.location.href);
|
|
904
|
+
let url = '';
|
|
905
|
+
if(obj['url'].indexOf('?') === -1) url = `${obj['url']}?xdProjectCallback=${callback}`;
|
|
906
|
+
else url = `${obj['url']}&xdProjectCallback=${callback}`;
|
|
907
|
+
window.location.href = url;
|
|
908
|
+
}else{
|
|
909
|
+
this.handleTo(obj, redirect)
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* @description 返回页面处理
|
|
915
|
+
*/
|
|
916
|
+
navigateBack() {
|
|
917
|
+
this.handleBack()
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* @description 关闭当前页面,跳转到应用内的某个页面。 https://uniapp.dcloud.io/api/router?id=redirectto
|
|
922
|
+
* @param obj 与(uni.redirectTo)的Object参数相同
|
|
923
|
+
* @param redirect 是否添加当前页面地址路径最为回调地址
|
|
924
|
+
*/
|
|
925
|
+
redirectTo(obj, redirect) {
|
|
926
|
+
this.handleTo(obj, redirect, false)
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* @description 使用redirectTo之后返回上一页
|
|
931
|
+
*/
|
|
932
|
+
redirectBack() {
|
|
933
|
+
this.handleBack(false)
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* @description 检查是为vip用户
|
|
938
|
+
* @param callback 会员检查通过回调事件
|
|
939
|
+
* @param obj {Object}
|
|
940
|
+
* @param obj.$vm {Vue} vue实例化对象
|
|
941
|
+
* @param obj.$xd {XdAppClass} XdAppClass实例化对象
|
|
942
|
+
* @param obj.vipKey {Boolean} 用户对象中的键值 默认:N,其值Y:vip,N:非vip
|
|
943
|
+
* @param obj.url {String} 跳转页面
|
|
944
|
+
* @param obj.message {String} 非会员提示文案 默认:
|
|
945
|
+
* @param obj.pay {String} 开通会员页面地址 默认:/user/my/vip
|
|
946
|
+
*/
|
|
947
|
+
checkVip(obj, callback = null) {
|
|
948
|
+
let options = Object.assign({
|
|
949
|
+
width: '90%',
|
|
950
|
+
confirmText: '去充值',
|
|
951
|
+
cancelText: '我知道了',
|
|
952
|
+
pay: '/user/my/vip',
|
|
953
|
+
message: '您目前不是会员用户,无权限访问此功能,请开通会员后再次访问',
|
|
954
|
+
vipKey: 'is_vip',
|
|
955
|
+
customerKey: 'customer_vip'
|
|
956
|
+
}, obj);
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
if (!options.$xd || !options.$vm) {
|
|
960
|
+
throw new Error('必选参数: obj.$vm,obj.$xd');
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
//是会员获取直接跳转
|
|
964
|
+
if (options.$xd.userInfo[options.vipKey] === 'Y') {
|
|
965
|
+
if (options.url) {
|
|
966
|
+
this.handleTo({
|
|
967
|
+
url: options.url
|
|
968
|
+
}, false);
|
|
969
|
+
} else {
|
|
970
|
+
if (typeof callback === 'function') {
|
|
971
|
+
callback();
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
return;
|
|
975
|
+
} else {
|
|
976
|
+
if (options.$xd.userInfo[options.customerKey] === 'Y') {
|
|
977
|
+
switch (options.type) {
|
|
978
|
+
case 'greet':
|
|
979
|
+
if (typeof callback === 'function') {
|
|
980
|
+
callback();
|
|
981
|
+
}
|
|
982
|
+
return
|
|
983
|
+
break;
|
|
984
|
+
case 'message':
|
|
985
|
+
if (typeof callback === 'function') {
|
|
986
|
+
callback();
|
|
987
|
+
}
|
|
988
|
+
return
|
|
989
|
+
break;
|
|
990
|
+
case 'forumfilm':
|
|
991
|
+
if (typeof callback === 'function') {
|
|
992
|
+
callback();
|
|
993
|
+
}
|
|
994
|
+
return
|
|
995
|
+
break;
|
|
996
|
+
case 'forum':
|
|
997
|
+
if (typeof callback === 'function') {
|
|
998
|
+
callback();
|
|
999
|
+
}
|
|
1000
|
+
return
|
|
1001
|
+
break;
|
|
1002
|
+
case 'hide_vip':
|
|
1003
|
+
if (typeof callback === 'function') {
|
|
1004
|
+
callback(false);
|
|
1005
|
+
}
|
|
1006
|
+
break;
|
|
1007
|
+
case 'gift':
|
|
1008
|
+
if (typeof callback === 'function' && options.data.is_vip === 'N') {
|
|
1009
|
+
callback();
|
|
1010
|
+
} else {
|
|
1011
|
+
options.$vm.$xdHideLoading();
|
|
1012
|
+
options.$vm.$xdConfirm({
|
|
1013
|
+
width: '90%',
|
|
1014
|
+
content: '此礼物为会员专享,请开通会员后再次访问',
|
|
1015
|
+
confirmText: '去充值',
|
|
1016
|
+
cancelText: '我知道了',
|
|
1017
|
+
success: (res) => {
|
|
1018
|
+
if (res.confirm) {
|
|
1019
|
+
options.$xd.$storage.set('xd_to_vip_callback_url', options.$vm.$xdUniHelper.parseURL()['relative'], 12);
|
|
1020
|
+
this.handleTo({
|
|
1021
|
+
url: '/user/my/vip'
|
|
1022
|
+
}, false);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
})
|
|
1026
|
+
}
|
|
1027
|
+
return
|
|
1028
|
+
break;
|
|
1029
|
+
}
|
|
1030
|
+
} else {
|
|
1031
|
+
//由于有些loading需要调取页面中的接口才可以隐藏,在不满足调用callback的情况下,隐藏loading
|
|
1032
|
+
if (options.type === 'hide_vip') {
|
|
1033
|
+
callback(false);
|
|
1034
|
+
}
|
|
1035
|
+
options.$vm.$xdHideLoading();
|
|
1036
|
+
uni.hideLoading();
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
options.$vm.$xdConfirm({
|
|
1041
|
+
width: options.width,
|
|
1042
|
+
content: options.message,
|
|
1043
|
+
confirmText: options.confirmText,
|
|
1044
|
+
cancelText: options.cancelText,
|
|
1045
|
+
success: (res) => {
|
|
1046
|
+
if (res.confirm) {
|
|
1047
|
+
options.$xd.$storage.set('xd_to_vip_callback_url', options.$vm.$xdUniHelper.parseURL()['relative'], 12);
|
|
1048
|
+
this.handleTo({
|
|
1049
|
+
url: options.pay
|
|
1050
|
+
}, false);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
})
|
|
1054
|
+
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* @description 搜索到匹配关键字高亮处理
|
|
1060
|
+
* @param str {string} 需要检索的字符串
|
|
1061
|
+
* @param keyword {string|array} 搜索关键字
|
|
1062
|
+
* @param options {object}
|
|
1063
|
+
* @param options.tag 有效的html中有效的tag标签
|
|
1064
|
+
* @param options.color 匹配的字符高亮颜色 默认:red
|
|
1065
|
+
* @param options.weight
|
|
1066
|
+
* ,css font-weight有效值,默认:normal
|
|
1067
|
+
* @returns {*}
|
|
1068
|
+
*/
|
|
1069
|
+
searchHigh(str, keyword , options = {}){
|
|
1070
|
+
try{
|
|
1071
|
+
let __option = {
|
|
1072
|
+
tag: 'span',
|
|
1073
|
+
color: 'red',
|
|
1074
|
+
weight: 'normal',
|
|
1075
|
+
};
|
|
1076
|
+
if(this.checkVarType(keyword) === 'array') {
|
|
1077
|
+
keyword = keyword.join('|');
|
|
1078
|
+
}
|
|
1079
|
+
else if(this.checkVarType(keyword) === 'string') {
|
|
1080
|
+
keyword = keyword.trim();
|
|
1081
|
+
}
|
|
1082
|
+
else{
|
|
1083
|
+
throw new Error('关键字类型错误')
|
|
1084
|
+
}
|
|
1085
|
+
let opt = Object.assign({}, __option, options);
|
|
1086
|
+
let reg = new RegExp(`(${keyword})`, 'ig');
|
|
1087
|
+
return str.replace(reg, `<${opt.tag} style="color:${opt.color};font-weight: ${opt.weight}">$1</${opt.tag}>`);
|
|
1088
|
+
}catch (e) {
|
|
1089
|
+
console.error(e)
|
|
1090
|
+
return str;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/**
|
|
1095
|
+
* @description FooterTabBar 显示数字
|
|
1096
|
+
* @param $vm {Vue|null} 当前vue实例对象(也就是当前this)(必填)
|
|
1097
|
+
* @param index {number} tabbar索引值(必填)
|
|
1098
|
+
* @param num {number} tabbar索引位显示数字 (必填)
|
|
1099
|
+
*/
|
|
1100
|
+
setTabbarBadge($vm , index, num){
|
|
1101
|
+
this.setFooterBarBadge(index, num)
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
/**
|
|
1105
|
+
* @description FooterTabBar 显示数字
|
|
1106
|
+
* @param index {number} FooterBar索引值(必填)
|
|
1107
|
+
* @param num {number} FooterBar索引位显示数字 (必填)
|
|
1108
|
+
*/
|
|
1109
|
+
setFooterBarBadge(index, num){
|
|
1110
|
+
store['dispatch']('updateFooterBarBadge', {index,num})
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
/**
|
|
1114
|
+
* @description 强制把字符字符串强转为数字
|
|
1115
|
+
* @param str
|
|
1116
|
+
*/
|
|
1117
|
+
stringToNumber(str) {
|
|
1118
|
+
let reg = /^\d+$/;
|
|
1119
|
+
if(this.checkVarType(str) === 'number') {
|
|
1120
|
+
return str
|
|
1121
|
+
}
|
|
1122
|
+
if(this.checkVarType(str) === 'string' && reg.test(str)) {
|
|
1123
|
+
return Number(str);
|
|
1124
|
+
}
|
|
1125
|
+
else {
|
|
1126
|
+
throw new Error(`参数str不是数字字符串,str=${str}` );
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* @description 获取随机字符串
|
|
1132
|
+
* @param len {number}
|
|
1133
|
+
* @returns {string}
|
|
1134
|
+
*/
|
|
1135
|
+
randomChar(len) {
|
|
1136
|
+
let arrstring = 'qwertyuiopasdfghjklzxcvbnm123456789QWERTYUIOPASDFGHJKLZXCVBNM'.split('');
|
|
1137
|
+
let str = '';
|
|
1138
|
+
for (let i = 0; i < len; i++) {
|
|
1139
|
+
let index = this.random(0, arrstring.length - 1);
|
|
1140
|
+
str += arrstring[index];
|
|
1141
|
+
}
|
|
1142
|
+
return str;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* @description 获取随机字符串
|
|
1147
|
+
* @param arr {Array} 需要删除的数据的数组
|
|
1148
|
+
* @param value {number|string} 需要删除的值
|
|
1149
|
+
* @returns {Array}
|
|
1150
|
+
*/
|
|
1151
|
+
removeArrayIndex(arr, value) {
|
|
1152
|
+
let index = arr.indexOf(value);
|
|
1153
|
+
if (index === -1) return arr;
|
|
1154
|
+
else {
|
|
1155
|
+
arr.splice(index, 1);
|
|
1156
|
+
return arr;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* @description 时间戳转年月日
|
|
1162
|
+
* @param time {String|Number} 时间戳 (秒)
|
|
1163
|
+
*/
|
|
1164
|
+
js_date_time(time) {
|
|
1165
|
+
return baseJsDateToTime(time)
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* @description 获取任意时间
|
|
1170
|
+
* @param date {Date|null|Number|String} 当前时间 使用数字类型:date=>Number 毫秒
|
|
1171
|
+
* @param AddDayCount {Number} 增加或者加少天数(相对今天)默认:0(今天)
|
|
1172
|
+
* @param joinChar {String} 年,月,日 连接符 默认:-
|
|
1173
|
+
*
|
|
1174
|
+
*/
|
|
1175
|
+
getDate(date = null, AddDayCount = 0, joinChar='-') {
|
|
1176
|
+
/**
|
|
1177
|
+
* @type {null|Date}
|
|
1178
|
+
*/
|
|
1179
|
+
let day = null;
|
|
1180
|
+
//使用时间对象或者数字
|
|
1181
|
+
if(this.checkVarType(date) === 'number') {
|
|
1182
|
+
day = date;
|
|
1183
|
+
}
|
|
1184
|
+
if (this.checkVarType(date) === 'string') {
|
|
1185
|
+
day = date.replace(/-/g, '/')
|
|
1186
|
+
}
|
|
1187
|
+
let dd = new Date();
|
|
1188
|
+
if(this.checkVarType(date) === 'date') {
|
|
1189
|
+
dd = date;
|
|
1190
|
+
}
|
|
1191
|
+
if(day !== null) {
|
|
1192
|
+
dd = new Date(day);
|
|
1193
|
+
}
|
|
1194
|
+
dd.setDate(dd.getDate() + AddDayCount);
|
|
1195
|
+
const y = dd.getFullYear();
|
|
1196
|
+
const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1; // 获取当前月份的日期,不足10补0
|
|
1197
|
+
const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate(); // 获取当前几号,不足10补0
|
|
1198
|
+
let hour = dd.getHours();
|
|
1199
|
+
let minute = dd.getMinutes();
|
|
1200
|
+
let second = dd.getSeconds();
|
|
1201
|
+
hour = hour < 10 ? ('0' + hour) : hour;
|
|
1202
|
+
minute = minute < 10 ? ('0' + minute) : minute;
|
|
1203
|
+
second = second < 10 ? ('0' + second) : second;
|
|
1204
|
+
|
|
1205
|
+
return {
|
|
1206
|
+
fullDate: [y,m,d].join(joinChar),
|
|
1207
|
+
time: [hour, minute, second].join(':'),
|
|
1208
|
+
year: y,
|
|
1209
|
+
month: m,
|
|
1210
|
+
date: d,
|
|
1211
|
+
day: dd.getDay(),
|
|
1212
|
+
fullTime: `${[y, m, d].join(joinChar)} ${[hour, minute, second].join(':')}`
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
/**
|
|
1217
|
+
* @description 带有遮昭loading
|
|
1218
|
+
* @param obj
|
|
1219
|
+
*/
|
|
1220
|
+
showLoading(obj={}){
|
|
1221
|
+
uni.showLoading({
|
|
1222
|
+
...obj,
|
|
1223
|
+
mask: true,
|
|
1224
|
+
})
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* @description 去掉地址栏中字段
|
|
1229
|
+
* @param url
|
|
1230
|
+
* @param keys {Array} 特殊字段
|
|
1231
|
+
*/
|
|
1232
|
+
removeUrlParams(url, keys=[]) {
|
|
1233
|
+
if (url.indexOf('?') === -1) return url;
|
|
1234
|
+
if(keys.length === 0) return url;
|
|
1235
|
+
let urlRange = [];
|
|
1236
|
+
let newurl = url.split('?');
|
|
1237
|
+
urlRange.push(newurl[0]);
|
|
1238
|
+
urlRange.push(newurl[1]);
|
|
1239
|
+
if(url.indexOf('#') !== -1) {
|
|
1240
|
+
let search = urlRange[1].split('#');
|
|
1241
|
+
urlRange[1]= search[0];
|
|
1242
|
+
urlRange.push('#' + search[1]);
|
|
1243
|
+
}
|
|
1244
|
+
let params = urlRange[1].split('&');
|
|
1245
|
+
params = params.filter(item=>{
|
|
1246
|
+
let t = item.split('=');
|
|
1247
|
+
if(!keys.includes(t[0])) {
|
|
1248
|
+
return item
|
|
1249
|
+
}
|
|
1250
|
+
});
|
|
1251
|
+
urlRange[1] = params.join('&');
|
|
1252
|
+
if(urlRange[1].length > 0) {
|
|
1253
|
+
urlRange[0] = urlRange[0] + '?';
|
|
1254
|
+
}
|
|
1255
|
+
return urlRange.join('')
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* @description 过滤html标签
|
|
1260
|
+
* @param html html文本
|
|
1261
|
+
* @param allowed 允许通过的标签 例如:'<p><a><li>'
|
|
1262
|
+
* @returns {string|XML}
|
|
1263
|
+
*/
|
|
1264
|
+
filterHtml(html, allowed) {
|
|
1265
|
+
allowed = allowed === undefined ? '' : allowed;
|
|
1266
|
+
allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('');
|
|
1267
|
+
let tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
|
|
1268
|
+
commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
|
|
1269
|
+
return html.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
|
|
1270
|
+
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
|
|
1271
|
+
});
|
|
1272
|
+
};
|
|
1273
|
+
|
|
1274
|
+
/**
|
|
1275
|
+
* @description 输入到页面日志方法
|
|
1276
|
+
* @param type {String} 其值:info|error 默认:info
|
|
1277
|
+
* @param data {Object} 日志对象
|
|
1278
|
+
* @param data.key {String} 日志键值
|
|
1279
|
+
* @param data.data {*} 日志数据
|
|
1280
|
+
*/
|
|
1281
|
+
logger(type = 'info', data){
|
|
1282
|
+
let fn = 'debugLogs';
|
|
1283
|
+
if(type === 'error') fn = 'debugLogs';
|
|
1284
|
+
store['dispatch'](fn, data);
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* @description 初始化输入到页面日志
|
|
1289
|
+
*/
|
|
1290
|
+
setInitLogger(){
|
|
1291
|
+
store['dispatch']('setInitLogger');
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* @description 重写console.log方法
|
|
1296
|
+
*/
|
|
1297
|
+
reDoConsoleLog(){
|
|
1298
|
+
let __this = this;
|
|
1299
|
+
if (console && typeof console.log === 'function') {
|
|
1300
|
+
let old = console.log;
|
|
1301
|
+
console.log = function () {
|
|
1302
|
+
let arr = Object.keys(arguments);
|
|
1303
|
+
if (arr.length === 2
|
|
1304
|
+
&& arguments[arr[0]].length <= 15
|
|
1305
|
+
&& __this.checkVarType(arguments[arr[0]]) === 'string'
|
|
1306
|
+
&& arguments[arr[0]].indexOf('%s') === -1
|
|
1307
|
+
) {
|
|
1308
|
+
let params = {};
|
|
1309
|
+
params['key'] = `${arguments[arr[0]]}_${__this.randomChar(5)}`;
|
|
1310
|
+
params['data'] = arguments[arr[1]];
|
|
1311
|
+
store['dispatch']('debugLogs', params);
|
|
1312
|
+
}
|
|
1313
|
+
old.apply(this, arguments);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
export default new Helpers;
|