| | |
| | | data, |
| | | method, |
| | | }) { |
| | | if(this.requestLock){ |
| | | console.warn("该请求被锁定,已退出请求!") |
| | | if (this.requestLock) { |
| | | console.log("该请求被锁定,不能重复请求!!!") |
| | | return |
| | | } |
| | | |
| | | this.requestLock = true |
| | | return new Promise((resolve, reject) => { |
| | | // that = that || this; |
| | |
| | | }) |
| | | }) |
| | | } |
| | | //没有添加锁的异步查询 |
| | | async doRequest2Async({ |
| | | url, |
| | | data, |
| | | method, |
| | | }) { |
| | | return new Promise((resolve, reject) => { |
| | | // that = that || this; |
| | | let errorTip = null; |
| | | uni.showLoading({ |
| | | title: '加载中...' |
| | | }) |
| | | uni.request({ |
| | | method: method || "GET", |
| | | url: this.serverUrl + url, |
| | | data: data || "", |
| | | success: (res) => { |
| | | resolve(res) |
| | | }, |
| | | fail: (err) => { |
| | | reject(err) |
| | | }, |
| | | complete: () => { |
| | | uni.hideLoading() |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | stringToBoolean(str) { |
| | | // 忽略大小写的转换 |
| | | return str?.toLowerCase() === "true"; |
| | |
| | | console.log(res.errCode); |
| | | }); |
| | | innerAudioContext.onPause(function() { |
| | | console.log('播放出现错误,销毁'); |
| | | console.log('播放暂停,销毁'); |
| | | innerAudioContext.destroy(); |
| | | }) |
| | | }); |
| | | |
| | | } |
| | | // playSound(e) { |
| | | // // 全局维护一个音频实例,防止缓存溢出 |
| | |
| | | // } |
| | | |
| | | |
| | | showTips({ |
| | | type, |
| | | message, |
| | | title, |
| | | duration |
| | | }) { |
| | | if (!message) { |
| | | return |
| | | } |
| | | |
| | | if (message.length < 20) { |
| | | return uni.showToast({ |
| | | icon: type || 'none', |
| | | title: message |
| | | }) |
| | | } |
| | | |
| | | return uni.showModal({ |
| | | title: title, |
| | | content: message, |
| | | showCancel: false |
| | | }) |
| | | } |
| | | |
| | | replaceWithFunction(str, handler) { |
| | | return str.replace(/\{(.+?)\}/g, (match, key) => { |
| | |
| | | return handler(key, match); |
| | | }); |
| | | } |
| | | |
| | | fieldListFilterRole({FieldList, ExcludeKeys = [] ,RoleList = null}) { |
| | | if(!RoleList) { |
| | | RoleList = [ |
| | | /^[a-zA-Z]+$/, |
| | | /id$/i |
| | | ] |
| | | } |
| | | if(!Array.isArray(RoleList)){ |
| | | return { |
| | | status: false, |
| | | data: null, |
| | | Message: "过滤字段列表失败,规则必须是数组。" |
| | | } |
| | | } |
| | | |
| | | let FieldListCache = Array(...FieldList) |
| | | |
| | | RoleList.forEach(role => { |
| | | FieldListCache = FieldListCache.filter(elem => !role.test(elem.ColmCols)) |
| | | }) |
| | | |
| | | FieldListCache = FieldListCache.filter(elem => !ExcludeKeys.includes(elem.ColmCols)) |
| | | return { |
| | | status: true, |
| | | data: FieldListCache, |
| | | Message: "" |
| | | } |
| | | } |
| | | |
| | | emptyValueFilter(item, fieldList){ |
| | | return fieldList.filter(e => { |
| | | return item[e.ColmCols] |
| | | }) |
| | | } |
| | | } |
| | | |
| | | export const CommonUtils = new commonUtils() |