tools.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. export function downloadFile({url}) {
  2. return new Promise((resolve, reject) => {
  3. wx.downloadFile({
  4. url,
  5. success: resolve,
  6. fail: reject
  7. });
  8. })
  9. }
  10. export function getQueryString(url, name) {
  11. let reg = new RegExp('(^|/?|&)' + name + '=([^&]*)(&|$)', 'i');
  12. let r = url.substr(1).match(reg);
  13. if (r != null) {
  14. return unescape(r[2]);
  15. }
  16. return null;
  17. }
  18. export function randomString(e) {
  19. for (var t = "", i = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", n = 0; n < e; n++)
  20. t += i.charAt(Math.floor(Math.random() * i.length));
  21. return t
  22. }
  23. export function isPhoneX () {
  24. return new Promise((resolve) => {
  25. let screenHeight = wx.getSystemInfoSync().screenHeight
  26. let windowHeight = wx.getSystemInfoSync().windowHeight
  27. let bottom = wx.getSystemInfoSync().safeArea.bottom
  28. resolve(screenHeight != bottom || windowHeight > 750)
  29. })
  30. }
  31. // export function getLocation () {
  32. // return new Promise ( (resolve, reject) => {
  33. // wx.getLocation({
  34. // type: 'wgs84',
  35. // success: function (res) {
  36. // var latitude = res.latitude;
  37. // var longitude = res.longitude;
  38. // getApp().globalData.qqmapsdk.reverseGeocoder({
  39. // location: {
  40. // latitude: latitude,
  41. // longitude: longitude
  42. // },
  43. // success: function (res) {
  44. // var ad_info = res.result.ad_info;
  45. // let city = ad_info.city.replace('市', '');
  46. // resolve(city)
  47. // },
  48. // fail:function (res) {
  49. // wx.showModal({
  50. // title: '定位失败',
  51. // });
  52. // }
  53. // });
  54. // },
  55. // fail(err) {
  56. // wx.showModal({
  57. // title: '定位失败,请手动选择城市',
  58. // });
  59. // }
  60. // })
  61. // })
  62. // }