tool.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import Vue from 'vue'
  2. function mount() {
  3. Vue.prototype.getLocation = (isReverseGeocoder = false) => {
  4. return new Promise((resolve, reject) => {
  5. let that = this;
  6. handle()
  7. function handle() {
  8. uni.getLocation({
  9. altitude: true,
  10. highAccuracyExpireTime: 8000,
  11. isHighAccuracy: true,
  12. success: res => {
  13. console.log("获取定位", res)
  14. if (isReverseGeocoder) {
  15. Vue.prototype.$Http.basic({
  16. "id": "10027201",
  17. "content": {
  18. "lon": res.longitude,
  19. "lat": res.latitude
  20. }
  21. }).then(s => {
  22. console.log("定位", s)
  23. res.result = s.data.result;
  24. resolve(res)
  25. })
  26. } else {
  27. resolve(res)
  28. }
  29. },
  30. fail: err => {
  31. uni.hideLoading();
  32. query()
  33. }
  34. })
  35. }
  36. function query() {
  37. uni.getSetting({
  38. success({
  39. authSetting
  40. }) {
  41. if (authSetting['scope.userLocation']) {
  42. handle()
  43. } else {
  44. uni.showModal({
  45. title: '提示',
  46. content: '您未开启地理位置授权',
  47. cancelText: '下次再说',
  48. confirmText: '前去授权',
  49. success: ({
  50. confirm
  51. }) => {
  52. if (confirm) {
  53. uni.openSetting({
  54. success(res) {
  55. if (res.authSetting['scope.userLocation']) handle();
  56. }
  57. })
  58. } else {
  59. uni.showToast({
  60. title: "已拒绝地理位置授权",
  61. icon: "none",
  62. })
  63. }
  64. }
  65. })
  66. }
  67. }
  68. })
  69. }
  70. })
  71. };
  72. Vue.prototype.cutoff = (msg, title = "", mask = false, exitTime = 0, icon = 'none', duration = 2000, ) => {
  73. if (msg != '成功' || title) uni.showToast({
  74. title: msg == '成功' ? title : msg,
  75. duration,
  76. icon,
  77. mask: mask || exitTime != 0
  78. })
  79. if (exitTime && msg == '成功') setTimeout(uni.navigateBack, exitTime)
  80. return msg != '成功';
  81. };
  82. Vue.prototype.paging = (content, init) => {
  83. if (content.pageTotal == undefined || !content.pageTotal) content.pageTotal = 1;
  84. if (content.pageNumber == undefined || !content.pageNumber) content.pageNumber = 1;
  85. if (content.pageSize == undefined || !content.pageSize) content.pageSize = 20;
  86. if (init) content.pageNumber = 1;
  87. return content.pageNumber > content.pageTotal;
  88. }
  89. Vue.prototype.tovw = (num) => (num * 100 / 375).toFixed(3) + "vw";
  90. Vue.prototype.getApps = appRemark => Object.values(uni.getStorageSync('authList')[appRemark]);
  91. Vue.prototype.getHeight = (even, that, calculate = true) => {
  92. return new Promise((resolve, reject) => {
  93. if (calculate) {
  94. uni.getSystemInfo({
  95. success(s) {
  96. uni.createSelectorQuery().in(that).select(even).boundingClientRect().exec(res => (!res[0]) ? reject('没有查询到元素') : resolve(s.windowHeight - res[0].bottom))
  97. }
  98. });
  99. } else {
  100. uni.createSelectorQuery().in(that).select(even).boundingClientRect().exec(res => (!res[0]) ? reject('没有查询到元素') : resolve(res[0]))
  101. }
  102. })
  103. };
  104. }
  105. module.exports = {
  106. mount
  107. }