洛阳学员端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
3.4 KiB

  1. import store from '@/store';
  2. const install = (Vue, vm) => {
  3. // 打开地图
  4. const openMap = (lat, lng) => {
  5. uni.openLocation({
  6. latitude: lat,
  7. longitude: lng
  8. })
  9. }
  10. // 距离换算
  11. const distanceFn = (val) => {
  12. if(!val) return 0
  13. if (val * 1 < 1000) {
  14. return val.toFixed(2) + '米'
  15. } else {
  16. return (val / 1000).toFixed(2) + '公里'
  17. }
  18. }
  19. // 价格计算
  20. const priceTo = (price = 0) => {
  21. if(!price) return 0
  22. // return (price / 100).toFixed(2)
  23. return (parseInt(price * 100) / 100 / 100).toFixed(2)
  24. }
  25. const distanceLatLng = (lat1, lng1) => {
  26. var that = this;
  27. let lat2 = store.state.latLng.lat;
  28. let lng2 = store.state.latLng.lng;
  29. let rad1 = lat1 * Math.PI / 180.0;
  30. let rad2 = lat2 * Math.PI / 180.0;
  31. let a = rad1 - rad2;
  32. let b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
  33. let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) *
  34. Math.cos(
  35. rad2) * Math.pow(
  36. Math.sin(b / 2), 2)));
  37. s = s * 6378.137;
  38. s = Math.round(s * 10000) / 10000;
  39. s = s.toString();
  40. s = s.substring(0, s.indexOf('.') + 2);
  41. return s
  42. }
  43. const getLocation = () => {
  44. return new Promise((resolve, reject) => {
  45. uni.getLocation({
  46. type: 'wgs84',
  47. success: function(res) {
  48. console.log('当前位置的经度:' + res.longitude);
  49. console.log('当前位置的纬度:' + res.latitude);
  50. let obj = {
  51. lat: res.latitude,
  52. lng: res.longitude
  53. }
  54. store.commit('updateLatLng', obj)
  55. resolve(obj)
  56. }
  57. });
  58. }).catch((e) => {})
  59. }
  60. function addZeroPrefix(number) {
  61. return number < 10 ? `0${number}` : number
  62. }
  63. let getDate = (date, splitor = '-') => {
  64. const year = date.getFullYear()
  65. const month = date.getMonth() + 1
  66. const day = date.getDate()
  67. return `${year}${splitor}${addZeroPrefix(month)}${splitor}${addZeroPrefix(day)}`
  68. }
  69. const callPhone = (phone)=> {
  70. phone = phone.trim()
  71. if(!phone) {
  72. uni.showToast({
  73. title: '暂无联系方式',
  74. icon: 'none'
  75. });
  76. return
  77. }
  78. uni.showModal({
  79. content: '确定要拨打:'+phone+'?' ,
  80. success: function (res) {
  81. if (res.confirm) {
  82. uni.makePhoneCall({
  83. phoneNumber: phone //仅为示例
  84. });
  85. } else if (res.cancel) {
  86. console.log('用户点击取消');
  87. }
  88. }
  89. });
  90. }
  91. let truncateText = (text, maxLength)=> {
  92. if(!text) return
  93. if (text.length > maxLength) {
  94. return text.substring(0, maxLength) + "...";
  95. }
  96. return text
  97. }
  98. let goPage = (url, params={}, type='navigateTo')=> {
  99. uni.$u.route({
  100. url,
  101. params,
  102. type
  103. })
  104. }
  105. let clickSignUp = ()=> {
  106. let accessToken = store.state.user.vuex_loginInfo.accessToken
  107. if(!accessToken) {
  108. store.commit('goLogin')
  109. return
  110. }
  111. store.commit('updateNonPlatformStudent', false)
  112. if( vm.vuex_userInfo.applyStep<2) {
  113. vm.$goPage('/pages/indexEntry/enroll/enroll')
  114. }
  115. // 去填表
  116. if( vm.vuex_userInfo.applyStep&& vm.vuex_userInfo.applyStep<5) {
  117. return vm.$goPage('/pages/indexEntry/enroll/registInfo/registInfo')
  118. }
  119. }
  120. let isImagePath = (path)=> {
  121. // 定义常见的图片文件扩展名
  122. const imageExtensions = /\.(jpg|jpeg|png|gif|bmp|svg)$/i;
  123. // 使用正则表达式进行匹配
  124. return imageExtensions.test(path);
  125. }
  126. vm.$u.utils = {
  127. openMap,
  128. getLocation,
  129. priceTo,
  130. distanceLatLng,
  131. distanceFn,
  132. getDate,
  133. callPhone,
  134. truncateText,
  135. clickSignUp,
  136. isImagePath
  137. }
  138. }
  139. export default {
  140. install
  141. }