index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import moment from 'moment';
  2. const assetsUrl="https://zhenyanapp-gen.oss-cn-qingdao.aliyuncs.com/wechat-mini-pro/";
  3. const IMSDKCode=1400293452;
  4. //const IMSDKCode=1400456480;
  5. //const apiHost = 'http://192.168.1.253:8080' //本地;
  6. //const apiHost = 'https://mini.sugarpark.cn'
  7. const apiHost = 'http://jliao-api2-svc-test.internal.jiebide.xin'
  8. const protocal={
  9. behaviorStandar:'https://h5.sugarpark.cn/agreement/behavior-standard.html',
  10. userAgreement:'https://h5.sugarpark.cn/agreement/user-agreement.html',
  11. privacy:'https://h5.sugarpark.cn/agreement/privacy.html',
  12. addedService:'https://h5.sugarpark.cn/agreement/added-service.html'
  13. }
  14. const dataURLtoBlob=(dataurl)=>{
  15. var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  16. bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  17. while (n--) {
  18. u8arr[n] = bstr.charCodeAt(n);
  19. }
  20. return new Blob([u8arr], { type: mime });
  21. }
  22. const blobToFile=(theBlob, fileName)=>{
  23. theBlob.lastModifiedDate = new Date();
  24. theBlob.name = fileName;
  25. return theBlob;
  26. }
  27. const getApiHost=()=>{
  28. return apiHost;
  29. }
  30. const showMsg = msg => {
  31. uni.showToast({
  32. title: msg,
  33. icon: 'none',
  34. mask: true
  35. });
  36. }
  37. const hasSafeArea = () => {
  38. let result = uni.getSystemInfoSync();
  39. let sWidth = result.screenWidth * result.pixelRatio,
  40. sHeight = result.screenHeight * result.pixelRatio;
  41. if (result.model.indexOf('iPhone') == -1) {
  42. return false;
  43. } else if (sWidth == 1125 && sHeight == 2436) {
  44. return true;
  45. } else if (sWidth == 828 && sHeight == 1792) {
  46. return true;
  47. } else if (sWidth == 1170 && sHeight == 2532) {
  48. return true;
  49. } else if (sWidth == 1242 && sHeight == 2688) {
  50. return true;
  51. } else if (sWidth == 1284 && sHeight == 2778) {
  52. return true;
  53. }
  54. return false
  55. }
  56. const timeFn = (dateBeginTime, dateEndTime) => {
  57. var timeFn;
  58. var dateDiff = dateEndTime - dateBeginTime; //时间差的毫秒数
  59. var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
  60. var leave1 = dateDiff % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
  61. var hours = Math.floor(leave1 / (3600 * 1000)) //计算出小时数
  62. //计算相差分钟数
  63. var leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数
  64. var minutes = Math.floor(leave2 / (60 * 1000)) //计算相差分钟数
  65. //计算相差秒数
  66. var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
  67. var seconds = Math.round(leave3 / 1000)
  68. var timeFn = dayDiff + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒";
  69. return timeFn;
  70. }
  71. const checkPhone = (phone) => { //手机号码
  72. 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}$/;
  73. if(phone.substr(0,3)==='120'&&phone.length===11){
  74. return true;
  75. }
  76. if (reg.test(phone)) {
  77. return true;
  78. } else {
  79. return false;
  80. }
  81. }
  82. const checkTel = (tel) => { //座机号码不支持分机
  83. return /0\d{2,3}-\d{7,8}/.test(tel)
  84. }
  85. const checkIdNo = (idNo) => {
  86. return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idNo)
  87. }
  88. const checkChinese = (str) => {
  89. return /^[\u4e00-\u9fa5]+$/.test(str)
  90. }
  91. const compare = (property) => {
  92. return (a, b) => {
  93. var value1 = a[property];
  94. var value2 = b[property];
  95. return value1 - value2;
  96. }
  97. }
  98. const request = (url, method, data) => {
  99. return new Promise((resolve, reject) => {
  100. if (method === undefined) {
  101. method = 'GET';
  102. }
  103. let deviceConfig=uni.getSystemInfoSync();
  104. let LL_Ukn =uni.getStorageSync('LL_Ukn')||"szxe/TwE/wNJxcF+51069Dw3KHJQmbEuE2tEVHG4ETQ1TEnZ6loF7MQdmCFePTWTS9NE8zhDBrvPplTUYNnlPa10jJ1GycLQjpe2CkO+UvflA8adpe/uD5z2C8Bp1Pg9cThzHmqxeAe1Oq9G1eo3PKfGGYLALGx+dgFPYMn06M/Y+lVio4WpXbNW8KMNkWyxnFZnpZEXzzyDUCT13TMF9tevVJ9/Sb3yBgLiLYnydplax+zjkFqwGSiDrQWR/E8s";
  105. let LL_Csi=uni.getStorageSync('LL_Csi')||{
  106. av:"2.6.0",
  107. brand:"Apple",
  108. currTime:1654149186191,
  109. deviceCode:deviceConfig.deviceId,
  110. iOS:{"idfa":"00000000-0000-0000-0000-000000000000"},
  111. lang:"zh","model":"iPhone12,5","ov":"15.3.1",
  112. pkgCate:"JyPark",
  113. platform:"WechatMP",
  114. resolution:{"h":2688,"s":3,"w":1242},
  115. appId:15,
  116. android:{market:'Unknown'}
  117. };
  118. let token= uni.getStorageSync('token')||"88b99b11d3fc4cc3a71959b824678ce8";
  119. uni.request({
  120. url: `${apiHost}${url}`,
  121. method: method,
  122. data: data,
  123. header: {
  124. 'Content-Type': 'application/json',
  125. // 'token': url === ('/cufd') ? '' : token,
  126. // 'LL_Ukn': url === ('/cufd') ? '' : LL_Ukn,
  127. // 'LL_Csi':url === ('/cufd') ? '' : JSON.stringify(LL_Csi),
  128. 'token': url === 'userLogin/login' ? '' : token,
  129. 'LL_Ukn': LL_Ukn,
  130. 'LL_Csi': JSON.stringify(LL_Csi),
  131. },
  132. success: res => {
  133. if (res.data.status === 'Unauthorized') {
  134. uni.setStorageSync('token','');
  135. }
  136. else if(res.data.status === 'FrozenUser'){
  137. // 用户异常
  138. uni.showToast({
  139. icon:'none',
  140. title:"用户已被冻结"
  141. })
  142. setTimeout(()=>{
  143. uni.reLaunch({
  144. url:'/pages/login/login'
  145. })
  146. },2000)
  147. }
  148. else if(res.data.status=== 'Fail'){
  149. // 用户异常
  150. uni.showToast({
  151. icon:'none',
  152. title:res.data.msg
  153. })
  154. setTimeout(()=>{
  155. uni.reLaunch({
  156. url:'/pages/login/login'
  157. })
  158. },2000)
  159. }
  160. else if(res.data.status=== 'Exception'){
  161. // 自动登录异常
  162. uni.showToast({
  163. icon:'none',
  164. title:res.data.msg
  165. })
  166. }
  167. else if(res.data.status==='Succ'||res.data.code===0){
  168. resolve(res.data)
  169. }
  170. else{
  171. reject(res.data)
  172. }
  173. },
  174. fail: res => reject(res.data),
  175. complete: res => {}
  176. });
  177. });
  178. }
  179. const get = (url) => {
  180. return new Promise((resolve,reject)=>{
  181. uni.request({
  182. url:url,
  183. method:'GET',
  184. header:{'Access-Control-Allow-Origin':'*'},
  185. success:res=>{
  186. return res.data
  187. }
  188. })
  189. })
  190. }
  191. // const upload = (url, path) => {
  192. // return new Promise((resolve, reject) => {
  193. // let LL_Ukn =uni.getStorageSync('LL_Ukn')||"szxe/TwE/wNJxcF+51069Dw3KHJQmbEuE2tEVHG4ETQ1TEnZ6loF7MQdmCFePTWTS9NE8zhDBrvPplTUYNnlPa10jJ1GycLQjpe2CkO+UvflA8adpe/uD5z2C8Bp1Pg9cThzHmqxeAe1Oq9G1eo3PKfGGYLALGx+dgFPYMn06M/Y+lVio4WpXbNW8KMNkWyxnFZnpZEXzzyDUCT13TMF9tevVJ9/Sb3yBgLiLYnydplax+zjkFqwGSiDrQWR/E8s";
  194. // let LL_Csi=uni.getStorageSync('LL_Csi')||{
  195. // av:"2.6.0",
  196. // brand:"Apple",
  197. // currTime:1654149186191,
  198. // deviceCode:"8b4eef5c5614033bfd3bcbdf4577c339",
  199. // iOS:{"idfa":"00000000-0000-0000-0000-000000000000"},
  200. // lang:"zh","model":"iPhone12,5","ov":"15.3.1",
  201. // pkgCate:"Main",
  202. // platform:"iOS",
  203. // resolution:{"h":2688,"s":3,"w":1242},
  204. // };
  205. // let token= uni.getStorageSync('token')||"88b99b11d3fc4cc3a71959b824678ce8";
  206. // uni.uploadFile({
  207. // url: `${apiHost}${url}`,
  208. // filePath: path,
  209. // name: 'file',
  210. // timeout: 10000,
  211. // header: {
  212. // 'token': token,
  213. // 'LL_Ukn': LL_Ukn,
  214. // 'LL_Csi': JSON.stringify(LL_Csi),
  215. // },
  216. // success: (res) => {
  217. // let result = JSON.parse(res.data);
  218. // if (result.status === 'Unauthorized') {
  219. // uni.reLaunch({
  220. // url:'/pages/login/login'
  221. // })
  222. // uni.showToast({
  223. // icon:'none',
  224. // title:'登录已失效'
  225. // })
  226. // }
  227. // else if(res.data.status === 'FrozenUser'){
  228. // // 用户异常
  229. // uni.reLaunch({
  230. // url:'/pages/login/login'
  231. // })
  232. // uni.showToast({
  233. // icon:'none',
  234. // title:"用户已被冻结"
  235. // })
  236. // }
  237. // else if(res.data.status=== 'Fail'){
  238. // // 用户异常
  239. // uni.reLaunch({
  240. // url:'/pages/login/login'
  241. // })
  242. // uni.showToast({
  243. // icon:'none',
  244. // title:res.data.msg
  245. // })
  246. // }
  247. // else if (result.status === 'Succ') {
  248. // resolve(result.data);
  249. // } else {
  250. // uni.showToast({
  251. // icon:'none',
  252. // title:result.msg
  253. // })
  254. // reject(result.data);
  255. // }
  256. // },
  257. // fail: (err) => {
  258. // reject(err.data);
  259. // }
  260. // })
  261. // })
  262. // }
  263. module.exports = {
  264. assetsUrl,
  265. request,
  266. get,
  267. showMsg,
  268. hasSafeArea,
  269. checkPhone,
  270. checkIdNo,
  271. checkChinese,
  272. compare,
  273. timeFn,
  274. protocal,
  275. IMSDKCode,
  276. dataURLtoBlob,
  277. blobToFile
  278. }