洛阳学员端
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.

166 lines
3.5 KiB

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