tool.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import Vue from 'vue'
  2. function setBar() {
  3. uni.getSystemInfo({
  4. success: function (e) {
  5. // #ifndef MP
  6. Vue.prototype.usePort = 'h5';
  7. Vue.prototype.StatusBar = e.statusBarHeight;
  8. if (e.platform == 'android') {
  9. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  10. } else {
  11. Vue.prototype.CustomBar = e.statusBarHeight + 45;
  12. };
  13. // #endif
  14. // #ifdef MP-WEIXIN
  15. Vue.prototype.usePort = 'wechat';
  16. Vue.prototype.StatusBar = e.statusBarHeight;
  17. let custom = wx.getMenuButtonBoundingClientRect();
  18. Vue.prototype.Custom = custom;
  19. Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
  20. // #endif
  21. // #ifdef MP-ALIPAY
  22. Vue.prototype.StatusBar = e.statusBarHeight;
  23. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  24. // #endif
  25. }
  26. })
  27. }
  28. function mount() {
  29. Vue.prototype.getLocation = () => {
  30. return new Promise((resolve, reject) => {
  31. uni.getLocation({
  32. altitude: true,
  33. highAccuracyExpireTime: 5000,
  34. isHighAccuracy: true,
  35. success: res => resolve(res)
  36. })
  37. })
  38. }
  39. Vue.prototype.cutoff = (msg, title = "", mask = false, exitTime = 0, icon = 'none', duration = 2000, ) => {
  40. if (msg != '成功' || title) wx.showToast({
  41. title: msg == '成功' ? title : msg,
  42. duration,
  43. icon,
  44. mask: mask || exitTime,
  45. })
  46. if (exitTime && msg == '成功') setTimeout(uni.navigateBack, exitTime)
  47. return msg != '成功';
  48. };
  49. Vue.prototype.tovw = (num) => (num * 100 / 375).toFixed(3) + "vw";
  50. }
  51. function getCity() {
  52. return new Promise((resolve, reject) => {
  53. // #ifdef H5
  54. wx.request({
  55. url: 'http://www.nmc.cn/rest/position',
  56. method: "GET",
  57. timeout: 30000,
  58. success: res => resolve(res.data)
  59. })
  60. // #endif
  61. // #ifndef H5
  62. this.$Http.getLocationCode().then(res => resolve(res))
  63. // #endif
  64. })
  65. }
  66. module.exports = {
  67. mount,
  68. setBar,
  69. getCity
  70. }