import moment from 'moment'; const assetsUrl="https://zhenyanapp-gen.oss-cn-qingdao.aliyuncs.com/wechat-mini-pro/"; const IMSDKCode=1400293452; //const IMSDKCode=1400456480; //const apiHost = 'http://192.168.1.253:8080' //本地; //const apiHost = 'https://mini.sugarpark.cn' const apiHost = 'http://jliao-api2-svc-test.internal.jiebide.xin' const protocal={ behaviorStandar:'https://h5.sugarpark.cn/agreement/behavior-standard.html', userAgreement:'https://h5.sugarpark.cn/agreement/user-agreement.html', privacy:'https://h5.sugarpark.cn/agreement/privacy.html', addedService:'https://h5.sugarpark.cn/agreement/added-service.html' } const dataURLtoBlob=(dataurl)=>{ var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new Blob([u8arr], { type: mime }); } const blobToFile=(theBlob, fileName)=>{ theBlob.lastModifiedDate = new Date(); theBlob.name = fileName; return theBlob; } const getApiHost=()=>{ return apiHost; } const showMsg = msg => { uni.showToast({ title: msg, icon: 'none', mask: true }); } const hasSafeArea = () => { let result = uni.getSystemInfoSync(); let sWidth = result.screenWidth * result.pixelRatio, sHeight = result.screenHeight * result.pixelRatio; if (result.model.indexOf('iPhone') == -1) { return false; } else if (sWidth == 1125 && sHeight == 2436) { return true; } else if (sWidth == 828 && sHeight == 1792) { return true; } else if (sWidth == 1170 && sHeight == 2532) { return true; } else if (sWidth == 1242 && sHeight == 2688) { return true; } else if (sWidth == 1284 && sHeight == 2778) { return true; } return false } const timeFn = (dateBeginTime, dateEndTime) => { var timeFn; var dateDiff = dateEndTime - dateBeginTime; //时间差的毫秒数 var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数 var leave1 = dateDiff % (24 * 3600 * 1000) //计算天数后剩余的毫秒数 var hours = Math.floor(leave1 / (3600 * 1000)) //计算出小时数 //计算相差分钟数 var leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数 var minutes = Math.floor(leave2 / (60 * 1000)) //计算相差分钟数 //计算相差秒数 var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数 var seconds = Math.round(leave3 / 1000) var timeFn = dayDiff + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒"; return timeFn; } const checkPhone = (phone) => { //手机号码 let reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; if(phone.substr(0,3)==='120'&&phone.length===11){ return true; } if (reg.test(phone)) { return true; } else { return false; } } const checkTel = (tel) => { //座机号码不支持分机 return /0\d{2,3}-\d{7,8}/.test(tel) } const checkIdNo = (idNo) => { return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idNo) } const checkChinese = (str) => { return /^[\u4e00-\u9fa5]+$/.test(str) } const compare = (property) => { return (a, b) => { var value1 = a[property]; var value2 = b[property]; return value1 - value2; } } const request = (url, method, data) => { return new Promise((resolve, reject) => { if (method === undefined) { method = 'GET'; } let deviceConfig=uni.getSystemInfoSync(); let LL_Ukn =uni.getStorageSync('LL_Ukn')||"szxe/TwE/wNJxcF+51069Dw3KHJQmbEuE2tEVHG4ETQ1TEnZ6loF7MQdmCFePTWTS9NE8zhDBrvPplTUYNnlPa10jJ1GycLQjpe2CkO+UvflA8adpe/uD5z2C8Bp1Pg9cThzHmqxeAe1Oq9G1eo3PKfGGYLALGx+dgFPYMn06M/Y+lVio4WpXbNW8KMNkWyxnFZnpZEXzzyDUCT13TMF9tevVJ9/Sb3yBgLiLYnydplax+zjkFqwGSiDrQWR/E8s"; let LL_Csi=uni.getStorageSync('LL_Csi')||{ av:"2.6.0", brand:"Apple", currTime:1654149186191, deviceCode:deviceConfig.deviceId, iOS:{"idfa":"00000000-0000-0000-0000-000000000000"}, lang:"zh","model":"iPhone12,5","ov":"15.3.1", pkgCate:"JyPark", platform:"WechatMP", resolution:{"h":2688,"s":3,"w":1242}, appId:15, android:{market:'Unknown'} }; let token= uni.getStorageSync('token')||"88b99b11d3fc4cc3a71959b824678ce8"; uni.request({ url: `${apiHost}${url}`, method: method, data: data, header: { 'Content-Type': 'application/json', // 'token': url === ('/cufd') ? '' : token, // 'LL_Ukn': url === ('/cufd') ? '' : LL_Ukn, // 'LL_Csi':url === ('/cufd') ? '' : JSON.stringify(LL_Csi), 'token': url === 'userLogin/login' ? '' : token, 'LL_Ukn': LL_Ukn, 'LL_Csi': JSON.stringify(LL_Csi), }, success: res => { if (res.data.status === 'Unauthorized') { uni.setStorageSync('token',''); } else if(res.data.status === 'FrozenUser'){ // 用户异常 uni.showToast({ icon:'none', title:"用户已被冻结" }) setTimeout(()=>{ uni.reLaunch({ url:'/pages/login/login' }) },2000) } else if(res.data.status=== 'Fail'){ // 用户异常 uni.showToast({ icon:'none', title:res.data.msg }) setTimeout(()=>{ uni.reLaunch({ url:'/pages/login/login' }) },2000) } else if(res.data.status=== 'Exception'){ // 自动登录异常 uni.showToast({ icon:'none', title:res.data.msg }) } else if(res.data.status==='Succ'||res.data.code===0){ resolve(res.data) } else{ reject(res.data) } }, fail: res => reject(res.data), complete: res => {} }); }); } const get = (url) => { return new Promise((resolve,reject)=>{ uni.request({ url:url, method:'GET', header:{'Access-Control-Allow-Origin':'*'}, success:res=>{ return res.data } }) }) } // const upload = (url, path) => { // return new Promise((resolve, reject) => { // let LL_Ukn =uni.getStorageSync('LL_Ukn')||"szxe/TwE/wNJxcF+51069Dw3KHJQmbEuE2tEVHG4ETQ1TEnZ6loF7MQdmCFePTWTS9NE8zhDBrvPplTUYNnlPa10jJ1GycLQjpe2CkO+UvflA8adpe/uD5z2C8Bp1Pg9cThzHmqxeAe1Oq9G1eo3PKfGGYLALGx+dgFPYMn06M/Y+lVio4WpXbNW8KMNkWyxnFZnpZEXzzyDUCT13TMF9tevVJ9/Sb3yBgLiLYnydplax+zjkFqwGSiDrQWR/E8s"; // let LL_Csi=uni.getStorageSync('LL_Csi')||{ // av:"2.6.0", // brand:"Apple", // currTime:1654149186191, // deviceCode:"8b4eef5c5614033bfd3bcbdf4577c339", // iOS:{"idfa":"00000000-0000-0000-0000-000000000000"}, // lang:"zh","model":"iPhone12,5","ov":"15.3.1", // pkgCate:"Main", // platform:"iOS", // resolution:{"h":2688,"s":3,"w":1242}, // }; // let token= uni.getStorageSync('token')||"88b99b11d3fc4cc3a71959b824678ce8"; // uni.uploadFile({ // url: `${apiHost}${url}`, // filePath: path, // name: 'file', // timeout: 10000, // header: { // 'token': token, // 'LL_Ukn': LL_Ukn, // 'LL_Csi': JSON.stringify(LL_Csi), // }, // success: (res) => { // let result = JSON.parse(res.data); // if (result.status === 'Unauthorized') { // uni.reLaunch({ // url:'/pages/login/login' // }) // uni.showToast({ // icon:'none', // title:'登录已失效' // }) // } // else if(res.data.status === 'FrozenUser'){ // // 用户异常 // uni.reLaunch({ // url:'/pages/login/login' // }) // uni.showToast({ // icon:'none', // title:"用户已被冻结" // }) // } // else if(res.data.status=== 'Fail'){ // // 用户异常 // uni.reLaunch({ // url:'/pages/login/login' // }) // uni.showToast({ // icon:'none', // title:res.data.msg // }) // } // else if (result.status === 'Succ') { // resolve(result.data); // } else { // uni.showToast({ // icon:'none', // title:result.msg // }) // reject(result.data); // } // }, // fail: (err) => { // reject(err.data); // } // }) // }) // } module.exports = { assetsUrl, request, get, showMsg, hasSafeArea, checkPhone, checkIdNo, checkChinese, compare, timeFn, protocal, IMSDKCode, dataURLtoBlob, blobToFile }