| | |
| | | method: method || "GET", |
| | | url: this.serverUrl + url, |
| | | data: data || "", |
| | | // header: this.getHeader(), |
| | | success: (res) => { |
| | | if (typeof resFunction === 'function') { |
| | | resFunction.call(that, res) |
| | |
| | | method: method || "GET", |
| | | url: this.serverUrl + url, |
| | | data: data || "", |
| | | // header: this.getHeader(), |
| | | success: (res) => { |
| | | if (typeof resFunction === 'function') { |
| | | resFunction.call(that, res) |
| | |
| | | method: method || "GET", |
| | | url: this.serverUrl + url, |
| | | data: data || "", |
| | | // header: this.getHeader(), |
| | | success: (res) => { |
| | | resolve(res) |
| | | }, |
| | |
| | | }) |
| | | }) |
| | | } |
| | | //没有添加锁的异步查询 |
| | | //没有添加锁的异步查询 |
| | | async doRequest2Async({ |
| | | url, |
| | | data, |
| | | method, |
| | | showLoading = true, |
| | | }) { |
| | | return new Promise((resolve, reject) => { |
| | | // that = that || this; |
| | | let errorTip = null; |
| | | uni.showLoading({ |
| | | title: '加载中...' |
| | | }) |
| | | if (showLoading) { |
| | | uni.showLoading({ |
| | | title: '加载中...' |
| | | }) |
| | | } |
| | | |
| | | uni.request({ |
| | | method: method || "GET", |
| | | url: this.serverUrl + url, |
| | | data: data || "", |
| | | // header: this.getHeader(), |
| | | success: (res) => { |
| | | resolve(res) |
| | | }, |
| | |
| | | reject(err) |
| | | }, |
| | | complete: () => { |
| | | uni.hideLoading() |
| | | if (showLoading) { |
| | | uni.hideLoading() |
| | | } |
| | | } |
| | | }) |
| | | }) |
| | |
| | | console.log('播放暂停,销毁'); |
| | | innerAudioContext.destroy(); |
| | | }); |
| | | |
| | | |
| | | } |
| | | // playSound(e) { |
| | | // // 全局维护一个音频实例,防止缓存溢出 |
| | |
| | | return handler(key, match); |
| | | }); |
| | | } |
| | | |
| | | fieldListFilterRole({FieldList, ExcludeKeys = [] ,RoleList = null}) { |
| | | if(!RoleList) { |
| | | |
| | | fieldListFilterRole({ |
| | | FieldList, |
| | | ExcludeKeys = [], |
| | | RoleList = null |
| | | }) { |
| | | if (!RoleList) { |
| | | RoleList = [ |
| | | /^[a-zA-Z]+$/, |
| | | /id$/i |
| | | ] |
| | | } |
| | | if(!Array.isArray(RoleList)){ |
| | | 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, |
| | |
| | | Message: "" |
| | | } |
| | | } |
| | | |
| | | emptyValueFilter(item, fieldList){ |
| | | |
| | | emptyValueFilter(item, fieldList) { |
| | | return fieldList.filter(e => { |
| | | return item[e.ColmCols] |
| | | }) |
| | | } |
| | | |
| | | httpFormatWs(httpUrl=this.serverUrl) { |
| | | if(httpUrl.indexOf("http://") === 0){ |
| | | |
| | | httpFormatWs(httpUrl = this.serverUrl) { |
| | | if (httpUrl.indexOf("http://") === 0) { |
| | | httpUrl = httpUrl.replace("http://", "") |
| | | httpUrl = httpUrl.substring(0, httpUrl.length - 1) |
| | | let BackSlashLast = httpUrl.lastIndexOf('/') |
| | | httpUrl = httpUrl.substring(0, BackSlashLast) |
| | | httpUrl = "ws://" + httpUrl.split(":")[0]+":12345/ws" |
| | | }else if(httpUrl.indexOf("https://") === 0) { |
| | | httpUrl = "ws://" + httpUrl.split(":")[0] + ":12345/ws" |
| | | } else if (httpUrl.indexOf("https://") === 0) { |
| | | httpUrl = httpUrl.replace("https://", "") |
| | | httpUrl = httpUrl.substring(0, httpUrl.length - 1) |
| | | let BackSlashLast = httpUrl.lastIndexOf('/') |
| | | httpUrl = httpUrl.substring(0, BackSlashLast) |
| | | httpUrl = "wss://" + httpUrl.split(":")[0]+":12345/ws" |
| | | }else{ |
| | | httpUrl = "wss://" + httpUrl.split(":")[0] + ":12345/ws" |
| | | } else { |
| | | // 提示传入连接错误 |
| | | } |
| | | |
| | | |
| | | return httpUrl |
| | | } |
| | | |
| | | |
| | | |
| | | getHeader() { |
| | | let header = {} |
| | | let Token = uni.getStorageSync("Token") |
| | | |
| | | if (Token) { |
| | | header['Authorization'] = `Bearer ${uni.getStorageSync("Token")}` |
| | | } |
| | | |
| | | return header |
| | | } |
| | | } |
| | | |
| | | export const CommonUtils = new commonUtils() |