common.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*******************************************************************************
  2. * Copyright(c) 2020 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 2.功能描述:共同类
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * admin 2021-03-31 1.00 新建
  9. *******************************************************************************/
  10. var QQMapWX = require('./qqmap-wx-jssdk.min');
  11. const config = require('../config/config.js');
  12. const Constants = require('../utils/Constants.js');
  13. const util = require('./util');
  14. const app = getApp();
  15. var qqmapsdk;
  16. /**
  17. * 小程序地图调用
  18. */
  19. function onClickWxchartAddress() {
  20. const key = config.key; //使用在腾讯位置服务申请的key
  21. const referer = 'wx76a9a06e5b4e693e'; //调用插件的app的名称
  22. const category = '小区';
  23. wx.navigateTo({
  24. url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&category=' + category
  25. });
  26. }
  27. /**
  28. * 判断是否有按钮权限
  29. * @param {*} functionCode
  30. */
  31. function hasRight(functionCode) {
  32. let rights = app.globalData.user.rights
  33. let value = false
  34. if (rights != null && rights.length > 0) {
  35. rights.forEach(item => {
  36. if (item.FunctionCode == functionCode) {
  37. value = true
  38. return
  39. }
  40. })
  41. }
  42. return value
  43. }
  44. /**
  45. * 跳转到固定节点的位置
  46. * @param {*} selectid
  47. * @param {*} minus
  48. */
  49. function navigatePosition(selectid, minus) {
  50. //1、返回一个查询实例
  51. const query = wx.createSelectorQuery();
  52. //2、选择要跳转的节点id
  53. query.select('#' + selectid).boundingClientRect();
  54. //3、获取显示区域的尺寸、滚动等位置等信息,然后添加节点的滚动位置查询
  55. query.selectViewport().scrollOffset();
  56. //4、执行跳转
  57. query.exec((res) => {
  58. //5、res[0]是步骤2中的数据,res[1]是步骤3中的数据
  59. if (res[0] && res[1]) {
  60. //6、将页面滚动到目标位置 减300不是固定的 根据自己的要求调
  61. wx.pageScrollTo({
  62. //7、计算滚动到目标的位置
  63. scrollTop: res[0].top + res[1].scrollTop - minus,
  64. duration: 300
  65. })
  66. }
  67. });
  68. }
  69. /**
  70. * 导航
  71. */
  72. function navigate(address) {
  73. qqmapsdk.geocoder({
  74. //获取表单传入地址
  75. address: address,
  76. //地址参数,例:固定地址,address: '北京市海淀区彩和坊路海淀西大街74号'
  77. success: function (res) {//成功后的回调
  78. var res = res.result;
  79. var latitude = res.location.lat;
  80. var longitude = res.location.lng;
  81. wx.openLocation({
  82. latitude,
  83. longitude,
  84. scale: 18
  85. })
  86. },
  87. fail: function (error) {
  88. wx.showToast({
  89. title: '地址无法导航',
  90. image: '/static/image/warning.png',
  91. duration: 1000
  92. })
  93. },
  94. complete: function (res) {
  95. }
  96. })
  97. }
  98. /**
  99. * 本接口提供由坐标到坐标所在位置的文字描述的转换,输入坐标返回地理位置信息和附近poi列表。
  100. * @param {*} loc
  101. */
  102. function reverseGeocoder(loc) {
  103. return new Promise(resolve => {
  104. qqmapsdk.reverseGeocoder({
  105. location: {
  106. latitude: loc.latitude,
  107. longitude: loc.longitude
  108. } || '',
  109. //get_poi: 1, //是否返回周边POI列表:1.返回;0不返回(默认),非必须参数
  110. success: function (res) {//成功后的回调
  111. resolve(res)
  112. },
  113. fail: function (error) {
  114. resolve('')
  115. },
  116. complete: function (res) {
  117. }
  118. })
  119. });
  120. }
  121. /**
  122. * 调用距离计算接口
  123. * @param {*} fromloc
  124. * @param {*} toloc
  125. */
  126. function calculateDistance(fromloc, toloc) {
  127. return new Promise(resolve => {
  128. //调用距离计算接口
  129. qqmapsdk.calculateDistance({
  130. //mode: 'straight',//可选值:'driving'(驾车)、'walking'(步行),不填默认:'walking',可不填 新增直线距离计算,‘straight’(直线)
  131. //from参数不填默认当前地址
  132. //获取表单提交的经纬度并设置from和to参数(示例为string格式)
  133. from: fromloc, //若起点有数据则采用起点坐标,若为空默认当前地址
  134. to: toloc, //终点坐标
  135. success: function (res) {//成功后的回调
  136. var destinationDistance = res.result.elements[0].distance;
  137. console.log("calculateDistance-ok", res);
  138. resolve(destinationDistance)
  139. },
  140. fail: function (error) {
  141. console.log("calculateDistance-error", error);
  142. resolve(0)
  143. },
  144. complete: function (res) {
  145. }
  146. });
  147. });
  148. }
  149. /**
  150. * 百度转腾讯
  151. * @param {*} lat
  152. * @param {*} lng
  153. */
  154. function bdMap_to_wxMap(lat, lng) {
  155. let pi = 3.14159265358979324 * 3000.0 / 180.0;
  156. let x = lng - 0.0065;
  157. let y = lat - 0.006;
  158. var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * pi);
  159. var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * pi);
  160. let lngv = z * Math.cos(theta);
  161. let latv = z * Math.sin(theta);
  162. return { 'longitude': lngv, 'latitude': latv };
  163. }
  164. /**
  165. * 腾讯转百度
  166. * @param {*} lat
  167. * @param {*} lng
  168. */
  169. function wxMap_to_bdMap(lat, lng) {
  170. let pi = 3.14159265358979324 * 3000.0 / 180.0;
  171. let x = lng;
  172. let y = lat;
  173. var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * pi);
  174. var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * pi);
  175. let lngv = z * Math.cos(theta) + 0.0065;
  176. let latv = z * Math.sin(theta) + 0.006;
  177. return { 'longitude': lngv, 'latitude': latv };
  178. }
  179. /**
  180. * 在onload时间中新建qq地址对象
  181. */
  182. function openQQMap() {
  183. if (qqmapsdk === undefined || qqmapsdk === null) {
  184. qqmapsdk = new QQMapWX({
  185. key: '7I3BZ-VADCX-TJQ4C-TN5O4-F4BZE-RDFCK'
  186. });
  187. }
  188. }
  189. /**
  190. * 判断是否有按钮权限
  191. * @param {*} functionCode
  192. */
  193. function hasButtonRight(functionCode) {
  194. let buttonRights = app.globalData.buttonRights
  195. let orderAuditVisible = buttonRights.indexOf(functionCode)
  196. return orderAuditVisible == -1 ? false : true
  197. }
  198. /**
  199. * 判断是否有画面的uuid权限
  200. * @param {*} functionCode
  201. */
  202. function hasPageUUidRight(uuid) {
  203. let pageRights = app.globalData.pageRights
  204. let pageVisible = pageRights.indexOf(uuid)
  205. return pageVisible == -1 ? false : true
  206. }
  207. /**
  208. * 导出函数
  209. */
  210. module.exports = {
  211. openQQMap,
  212. navigate,
  213. reverseGeocoder,
  214. calculateDistance,
  215. hasButtonRight,
  216. hasRight,
  217. wxMap_to_bdMap,
  218. bdMap_to_wxMap,
  219. onClickWxchartAddress,
  220. hasPageUUidRight
  221. }