index.vue 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. <template>
  2. <view>
  3. <!-- v-if="!deviceCode" -->
  4. <view class="map-box" v-if="!deviceCode">
  5. <!-- <view class="mp-header">
  6. <view class="sys-head" :style="'height:'+(statusBarHeight)+'px;'"></view>
  7. <view class="serch-box" :style="{height:barHeight+'px'}">
  8. <view class="serch-wrapper flex" @click="goEquList">
  9. <image class="logo" src='/static/img/addequ.png' mode="" />
  10. <view class="name">奶奶</view>
  11. <image class="arrow" src="/static/img/arrow.png" mode=""></image>
  12. </view>
  13. </view>
  14. </view> -->
  15. <!-- <map id='map' :latitude="latitude" :longitude="longitude" :markers="covers" :polyline="polyline"
  16. :scale="scale">
  17. </map> -->
  18. <!-- v-if="!deviceId" -->
  19. <view class="top-input" >
  20. <image src="../../static/img/noneEqu.png" mode=""></image>
  21. <view class="btn-box" @click="goEquList">
  22. <view class="btn">添加设备</view>
  23. </view>
  24. </view>
  25. <view class="info-box" v-if="deviceId" @click="goBindPage">
  26. <view class="scroll-view_H">
  27. <scroll-view class="scroll-view-content" scroll-x @scroll="scroll" scroll-left="0">
  28. <view id="demo1" class="scroll-view-item_H uni-bg-red" @click="toHeartRate">
  29. <image class="bg-image" src="../../static/img/heart.png" mode=""></image>
  30. <view class="text-wrapper">
  31. <view class="text-overlay black">
  32. <view class="top-box">
  33. <view class="top-left">
  34. <view class="english">Heart rate</view>
  35. <view class="chinese">心率</view>
  36. </view>
  37. <image class="top-right"
  38. src="https://app.tjzhxx.cn:11443/image/enterprise_icon.png" mode=""></image>
  39. </view>
  40. <view class="under-box">
  41. <view class="under-left">
  42. <view class="number">98</view>
  43. <view class="unit">bpm</view>
  44. </view>
  45. <view class="under-right">
  46. <view class="range">75~96 bpm</view>
  47. <view class="range-word">平局区间</view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view id="demo2" class="scroll-view-item_H uni-bg-green">
  54. <image class="bg-image" src="../../static/img/sleep.png" mode=""></image>
  55. <view class="text-wrapper white">
  56. <view class="text-overlay">
  57. <view class="top-box">
  58. <view class="top-left">
  59. <view class="english">Sleep log</view>
  60. <view class="chinese">睡眠</view>
  61. </view>
  62. </view>
  63. <view class="under-box">
  64. <view class="under-left white">
  65. <view class="number">5h</view>
  66. <view class="unit">28 min</view>
  67. </view>
  68. <view class="under-left white">
  69. <view class="number">66%</view>
  70. <view class="unit">深睡</view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. <view id="demo3" class="scroll-view-item_H uni-bg-blue">
  77. <image class="bg-image" src="../../static/img/breathe.png" mode=""></image>
  78. <view class="text-wrapper white">
  79. <view class="text-overlay">
  80. <view class="top-box">
  81. <view class="top-left">
  82. <view class="english">Breathe log</view>
  83. <view class="chinese">呼吸</view>
  84. </view>
  85. </view>
  86. <view class="under-box">
  87. <view class="under-left white">
  88. <view class="number">21次</view>
  89. <view class="unit">最高</view>
  90. </view>
  91. <view class="under-left white">
  92. <view class="number">17次</view>
  93. <view class="unit">平均呼吸</view>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. </scroll-view>
  100. </view>
  101. <view class="sos-btn">
  102. <image src="../../static/img/sos.png" mode=""></image>
  103. </view>
  104. </view>
  105. <view class="icon-box-right" v-if="showBtn">
  106. <image src="/static/image/calendarIcon.png" mode="" @click="showDayPicker = true"></image>
  107. </view>
  108. <van-loading class="loading" v-if="showLoading" type="spinner" color="#000" />
  109. </view>
  110. <!-- #ifdef APP-PLUS||H5 -->
  111. <view class="status_bar"></view>
  112. <view class="aaa" style="margin-top: var(--status-bar-height);margin-bottom: var(--status-bar-height);">
  113. <uni-nav-bar title="" height="var(--status-bar-height)" left-icon="left" backgroundColor="#F35546" color="#fff" @clickLeft="webviewback"></uni-nav-bar>
  114. </view>
  115. <!-- <view class="" @click="webviewback" style="z-index: 1;position: absolute;">
  116. 我是来展位的
  117. </view> -->
  118. <!-- #endif -->
  119. <view class="" v-if="deviceCode">
  120. <!-- <web-view :src="h5url"></web-view> -->
  121. <!-- <web-view style="position: absolute; top: 100px;z-index: 2;" src="https://openapiweb.slaaplekker.cn/reportH5?accessToken=9f36cea4a4f64ba8bfb680ff98d98c1b&sn=289935886000036"></web-view> -->
  122. <web-view ref="webview" v-if="h5url" style="position: absolute; top: 100px;z-index: 2;" :src="h5url" @message="bbb"></web-view>
  123. </view>
  124. <!-- </page-container> -->
  125. <van-popup :show="showDayPicker" position="bottom">
  126. <van-datetime-picker @cancel="showDayPicker=false" @confirm="onConfirm" :value="currentDay" type="date" />
  127. <!-- :min-date="minDate" -->
  128. </van-popup>
  129. </view>
  130. </template>
  131. <script>
  132. // import AMapLoader from "@amap/amap-jsapi-loader";
  133. import {
  134. toLogin
  135. } from '@/libs/login.js';
  136. import {
  137. mapGetters
  138. } from "vuex";
  139. import * as hrApi from '@/api/sleep/index.js';
  140. // import * as infoApi from '@/api/info/index.js';
  141. // import dayjs from "@/plugin/dayjs/dayjs.min.js";
  142. // #ifdef MP
  143. const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  144. const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
  145. // 获取导航栏高度
  146. const barHeight = menuButtonInfo.height + (menuButtonInfo.top - statusBarHeight) * 2
  147. // #endif
  148. // #ifdef APP-PLUS
  149. // import web from 'https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js'
  150. // const webview =web.webview
  151. // #endif
  152. export default {
  153. computed: mapGetters(['deviceCode', 'isLogin']),
  154. data() {
  155. return {
  156. statusBarHeight: statusBarHeight,
  157. barHeight: barHeight,
  158. showPage: false,
  159. aaa: [117.662369, 39.032391],
  160. showInfo: true,
  161. map: null,
  162. windowHeight: 0,
  163. mapHeight: 0,
  164. timer: null,
  165. showDayPicker: false, //日
  166. dateTime: '',
  167. navigationBarTitle: '定位',
  168. currentDay: new Date().getTime(),
  169. showLoading: false,
  170. isDisabled: false,
  171. isStart: false,
  172. playIndex: 1,
  173. showBtn: false, //展示右边日历按钮
  174. scale: 13,
  175. id: 0, // 使用 marker点击事件 需要填写id
  176. title: 'map',
  177. latitude: 39.0313466,
  178. longitude: 117.6637305,
  179. // latitude: '',
  180. // longitude: '',
  181. // deviceCode: '',
  182. onlineForce: false,
  183. onlineStatus: false,
  184. gpsUpdateTime: '',
  185. addressDesc: '',
  186. // 标记点
  187. // covers: [{
  188. // id: 1,
  189. // width: 42,
  190. // height: 47,
  191. // // rotate: 270,
  192. // // latitude: '',
  193. // // longitude: '',
  194. // latitude: 39.0313466,
  195. // longitude: 117.6637305,
  196. // iconPath: "https://app.tjzhxx.cn:11443/image/enterprise_icon.png",
  197. // // callout: {
  198. // // content: "陕A·88888", // 车牌信息
  199. // // display: "ALWAYS",
  200. // // fontWeight: "bold",
  201. // // color: "#5A7BEE", //文本颜色
  202. // // fontSize: "12px",
  203. // // bgColor: "#ffffff", //背景色
  204. // // padding: 5, //文本边缘留白
  205. // // textAlign: "center",
  206. // // },
  207. // // anchor: {
  208. // // x: 0.5,
  209. // // y: 0.5,
  210. // // }
  211. // },
  212. // // 找到当前数据得id,在这个数据得前面造出一个没有id得json,用作北京图片,前提是经纬度一样
  213. // {
  214. // id: 2,
  215. // width: 47,
  216. // height: 49,
  217. // latitude: 39.037,
  218. // longitude: 117.660,
  219. // iconPath: "https://app.tjzhxx.cn:11443/image/gender_man.png",
  220. // },
  221. // {
  222. // // id: 3,
  223. // width: 40,
  224. // height: 45,
  225. // latitude: 39.037,
  226. // longitude: 117.660,
  227. // iconPath: "https://app.tjzhxx.cn:11443/image/enterprise_icon.png",
  228. // },
  229. // {
  230. // id: 3,
  231. // width: 42,
  232. // height: 47,
  233. // latitude: 39.052,
  234. // longitude: 117.657,
  235. // iconPath: "https://app.tjzhxx.cn:11443/image/enterprise_icon.png",
  236. // },
  237. // ],
  238. covers:[],
  239. // 线
  240. polyline: [],
  241. // 坐标数据
  242. coordinates: [{
  243. id: 1,
  244. latitude: 23.098994,
  245. longitude: 113.322520,
  246. },
  247. {
  248. id: 2,
  249. latitude: 23.097994,
  250. longitude: 113.323520,
  251. // iconPath: '/image/location.png',
  252. },
  253. ],
  254. coordinate: [], //坐标数据
  255. posi: { // 汽车定位点的数据,后面只用改latitude、longitude即可
  256. id: 1,
  257. width: 32,
  258. height: 32,
  259. latitude: 0,
  260. longitude: 0,
  261. iconPath: "/static/image/positonimg.png",
  262. callout: {
  263. content: "陕A·85Q1Q", // 车牌信息
  264. display: "BYCLICK",
  265. fontWeight: "bold",
  266. color: "#5A7BEE", //文本颜色
  267. fontSize: "12px",
  268. bgColor: "#ffffff", //背景色
  269. padding: 5, //文本边缘留白
  270. textAlign: "center",
  271. },
  272. anchor: {
  273. x: 0.5,
  274. y: 0.5,
  275. },
  276. },
  277. h5url:'',// 当前H5页面的URL
  278. }
  279. },
  280. beforeCreate() {
  281. console.log('我只行啊')
  282. uni.setStorageSync('useSleep', true);
  283. },
  284. onReady() {
  285. // 创建map对象
  286. this.map = uni.createMapContext('map');
  287. // 获取屏幕高度
  288. uni.getSystemInfo({
  289. success: res => {
  290. this.windowHeight = res.windowHeight;
  291. }
  292. });
  293. },
  294. onShow() {
  295. // this.initAmap();
  296. this.getLocationInfo()
  297. // this.getHrdata()
  298. console.log(this.deviceCode,this.h5url,'deviceCodedeviceCode')
  299. if(this.deviceCode){
  300. this.geth5Url()
  301. }
  302. },
  303. onPageUnload: function() {
  304. uni.navigateBack({
  305. delta: 0
  306. })
  307. },
  308. onLoad() {
  309. let that =this
  310. uni.getLocation({
  311. type: 'wgs84',
  312. success: function (res) {
  313. console.log(res,'我是定位接口得返回数据')
  314. console.log('当前位置的经度:' + res.longitude);
  315. console.log('当前位置的纬度:' + res.latitude);
  316. },
  317. fail: function (error) {
  318. console.log('获取位置信息失败:', error.errMsg);
  319. // 或者将错误信息显示在页面上
  320. // this.errorMessage = '获取位置信息失败: ' + error.errMsg;
  321. }
  322. });
  323. // #ifdef APP-PLUS
  324. this.setWebviewHeight()
  325. // #endif
  326. },
  327. onHide: function() {
  328. uni.setStorageSync('useSleep', false);
  329. },
  330. mounted() {
  331. },
  332. methods: {
  333. bbb(e){
  334. console.log(e,'我是刚触发得事件')
  335. },
  336. webviewback(){
  337. uni.reLaunch({
  338. url: '/pages/index/index'
  339. })
  340. // webview.navigateBack({
  341. // delta:1
  342. // })
  343. // webview.postMessage({data:'deletefile'})
  344. },
  345. setWebviewHeight() {
  346. // #ifdef APP-PLUS
  347. let height = 0; //定义动态的高度变量,如高度为定值,可以直接写
  348. uni.getSystemInfo({
  349. //成功获取的回调函数,返回值为系统信息
  350. success: sysinfo => {
  351. height = sysinfo.windowHeight - 47; //自行修改,自己需要的高度
  352. },
  353. });
  354. const currentWebview = this.$scope.$getAppWebview(); //获取当前web-view
  355. setTimeout(function() {
  356. const wv = currentWebview.children()[0];
  357. wv.setStyle({
  358. top: 80, //设置web-view距离顶部的距离以及自己的高度,单位为px
  359. height: height
  360. });
  361. }, 1000); //如页面初始化调用需要写延迟
  362. // #endif
  363. },
  364. geth5Url(){
  365. // this.h5url='https://openapiweb.slaaplekker.cn/reportH5?accessToken=9f36cea4a4f64ba8bfb680ff98d98c1b&sn=289935886000036'
  366. // return
  367. hrApi.geth5url({sn:this.deviceCode}).then(res=>{
  368. console.log(res,this.h5url,777)
  369. this.h5url=res.data.httpsURL
  370. this.$forceUpdate();
  371. // this.$set(this,"h5url",res.data.httpsURL)
  372. })
  373. },
  374. getHrdata(){
  375. hrApi.getHrInfo({sn:"B1E507CD076164C7",date:"2024-06-30"}).then(res=>{
  376. console.log('我是首页得心率数据',res)
  377. })
  378. },
  379. toHeartRate() {
  380. uni.navigateTo({
  381. url: '/pages/index/condition/heart_rate/index'
  382. })
  383. },
  384. goEquList() {
  385. console.log('走到这')
  386. // 记得放开
  387. if (!this.isLogin) {
  388. console.log('进来了')
  389. toLogin();
  390. return
  391. }
  392. console.log('点击了')
  393. uni.navigateTo({
  394. url: '/pages/equ_list/index',
  395. })
  396. },
  397. beforeleave() {
  398. console.log('出发了');
  399. this.showPage = false
  400. //判断是上一个页面进入(返回),还是直接进入这个页面(回首页)
  401. let pages = getCurrentPages()
  402. console.log(pages.length, 5555);
  403. pages.length = 2
  404. console.log(pages.length, 6666);
  405. console.log(this.showBtn, '轨迹');
  406. console.log(!this.showBtn, '定位');
  407. if (pages.length == 2 && this.showBtn) {
  408. this.showPage = true
  409. uni.navigateTo({
  410. url: '/pages/index/map/index'
  411. })
  412. } else {
  413. this.showPage = true
  414. uni.switchTab({
  415. url: '/pages/index/index'
  416. })
  417. }
  418. },
  419. onConfirm(e) {
  420. this.dateTime = this.formatDate(e.detail)
  421. this.showDayPicker = false
  422. this.initAmap(3)
  423. },
  424. getLocationInfo() {
  425. this.showLoading = true
  426. return
  427. infoApi.getLocationInfo({
  428. deviceId: this.deviceId
  429. }).then(res => {
  430. this.showLoading = false
  431. this.latitude = res.data.lat
  432. this.longitude = res.data.lng
  433. this.covers[0].latitude = res.data.lat
  434. this.covers[0].longitude = res.data.lng
  435. this.deviceCode = res.data.deviceCode
  436. this.onlineForce = res.data.onlineForce
  437. this.onlineStatus = res.data.onlineStatus
  438. this.gpsUpdateTime = this.formaTime(res.data.gpsUpdateTime)
  439. this.addressDesc = res.data.addressDesc
  440. })
  441. },
  442. formaTime: function(date) {
  443. return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
  444. },
  445. formatDate: function(date) {
  446. return dayjs(date).format("YYYY-MM-DD");
  447. },
  448. goFenceList() {
  449. let center = `${this.longitude},${this.latitude}`
  450. uni.navigateTo({
  451. url: `/pages/index/map/fencelist?center=${center}`,
  452. });
  453. },
  454. goBindPage() {
  455. },
  456. formatDate: function(date) {
  457. return dayjs(date).format("YYYY-MM-DD");
  458. },
  459. initAmap(type) {
  460. let _this = this;
  461. // _this.addMarkers()
  462. if (type === 2) {
  463. this.showLoading = true
  464. infoApi.refreshLocation({
  465. deviceId: this.deviceId
  466. }).then(res => {
  467. this.showLoading = false
  468. this.latitude = res.data.lat
  469. this.longitude = res.data.lng
  470. this.covers[0].latitude = res.data.lat
  471. this.covers[0].longitude = res.data.lng
  472. this.gpsUpdateTime = this.formaTime(res.data.gpsUpdateTime)
  473. this.addressDesc = res.data.addressDesc
  474. })
  475. }
  476. if (type === 3) {
  477. uni.navigateTo({
  478. url: '/pages/index/map/driving'
  479. })
  480. // return
  481. // this.showBtn = true
  482. // this.scale = 18
  483. // wx.setNavigationBarTitle({
  484. // title: "轨迹"
  485. // })
  486. // // this.onLoad()//重新调方法 改标题,有问题
  487. // this.dateTime = this.dateTime ? this.dateTime : this.formatDate(new Date())
  488. // let params = {
  489. // deviceId: this.deviceId,
  490. // dateTime: this.dateTime,
  491. // // deviceId:this.deviceId,
  492. // // dateTime:this.formatDate(new Date())
  493. // }
  494. // infoApi.getLocationLocus(params).then(res => {
  495. // if (res.code === 0 && res.data.length) {
  496. // this.coordinate = res.data.map(item => {
  497. // console.log('11111');
  498. // return {
  499. // latitude: item.lat,
  500. // longitude: item.lng,
  501. // }
  502. // })
  503. // _this.polyline = [{
  504. // points: this.coordinate,
  505. // color: '#F35546',
  506. // width: 4,
  507. // dottedLine: false,
  508. // }];
  509. // // TODO 找相关api,将轨迹缩放到合适比例,将起点终点放上图标
  510. // _this.map.translateMarker({
  511. // markerId: 1,
  512. // fail(e) {
  513. // // 轨迹回放失败
  514. // },
  515. // });
  516. // } else {
  517. // _this.polyline = [{
  518. // points: [],
  519. // color: '#F35546',
  520. // width: 4,
  521. // dottedLine: false,
  522. // }];
  523. // this.$util.Tips({
  524. // title: `${this.dateTime}暂无轨迹数据`,
  525. // }, () => {
  526. // });
  527. // }
  528. // })
  529. }
  530. },
  531. // start() {
  532. // this.isStart = true;
  533. // this.isDisabled = true;
  534. // let data = this.coordinate;
  535. // let len = data.length;
  536. // let datai = data[this.playIndex];
  537. // let _this = this;
  538. // _this.map.translateMarker({
  539. // markerId: 1,
  540. // autoRotate: true,
  541. // destination: {
  542. // longitude: datai.longitude, // 车辆即将移动到的下一个点的经度
  543. // latitude: datai.latitude, // 车辆即将移动到的下一个点的纬度
  544. // },
  545. // duration: 700,
  546. // complete: function() {
  547. // _this.playIndex++;
  548. // if (_this.playIndex < len) {
  549. // _this.start(_this.playIndex, data);
  550. // } else {
  551. // console.log('okokok');
  552. // uni.showToast({
  553. // title: '播放完成',
  554. // duration: 1400,
  555. // icon: 'none'
  556. // });
  557. // _this.playIndex = 0;
  558. // _this.isStart = false;
  559. // _this.isDisabled = false;
  560. // }
  561. // },
  562. // animationEnd: function() {
  563. // // 轨迹回放完成 处理H5端
  564. // _this.playIndex++;
  565. // if (_this.playIndex < len) {
  566. // _this.start(_this.playIndex, data);
  567. // } else {
  568. // console.log('okokok');
  569. // uni.showToast({
  570. // title: '播放完成',
  571. // duration: 1400,
  572. // icon: 'none'
  573. // });
  574. // _this.playIndex = 0;
  575. // _this.isStart = false;
  576. // _this.isDisabled = false;
  577. // }
  578. // },
  579. // fail(e) {
  580. // // 轨迹回放失败
  581. // },
  582. // });
  583. // },
  584. // },
  585. // addMarkers() {
  586. // let _this = this;
  587. // const positions = [{
  588. // latitude: 23.099994,
  589. // longitude: 113.324520,
  590. // }, {
  591. // latitude: 23.099994,
  592. // longitude: 113.322520,
  593. // }, {
  594. // latitude: 23.099994,
  595. // longitude: 113.326520,
  596. // }, {
  597. // latitude: 23.096994,
  598. // longitude: 113.329520,
  599. // }]
  600. // const markers = []
  601. // positions.forEach((p, i) => {
  602. // console.log(i)
  603. // markers.push(
  604. // Object.assign({}, {
  605. // id: i + 1,
  606. // iconPath: "http://cdn.zhoukaiwen.com/car.png",
  607. // width: 50,
  608. // height: 50,
  609. // joinCluster: true, // 指定了该参数才会参与聚合
  610. // label: {
  611. // width: 50,
  612. // height: 30,
  613. // borderWidth: 1,
  614. // borderRadius: 10,
  615. // bgColor: '#ffffff',
  616. // content: `label ${i + 1}`
  617. // }
  618. // }, p)
  619. // )
  620. // })
  621. // _this.map.addMarkers({
  622. // markers,
  623. // clear: false,
  624. // complete(res) {
  625. // console.log('addMarkers', res)
  626. // }
  627. // })
  628. // },
  629. initmap(type) {
  630. AMapLoader.load({
  631. // key: '2d7215a1d0f8893f2417d134af7c3798',
  632. key: 'c968deab485d6e688e7c68689722ffb4',
  633. version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  634. plugins: [
  635. 'AMap.Autocomplete',
  636. 'AMap.PlaceSearch',
  637. 'AMap.Scale',
  638. 'AMap.OverView',
  639. 'AMap.ToolBar',
  640. 'AMap.MapType',
  641. 'AMap.PolyEditor',
  642. 'AMap.CircleEditor',
  643. 'MarkerClusterer',
  644. 'AMap.Geocoder'
  645. ]
  646. })
  647. .then((AMap) => {
  648. console.log('AMap', AMap)
  649. // 地图初始化
  650. // Map构造函数第一个传参的map为初始化地图的容器的id,第二个传参是配置对象
  651. var map = new AMap.Map('amap', {
  652. zoom: 15, //显示的缩放级别
  653. // zooms: [2, 30], //地图显示的缩放级别范围, 默认为 [2, 20] ,取值范围 [2 ~ 30]
  654. // center: [108.954239, 34.265472], //todo 中心点坐标
  655. mapStyle: 'amap://styles/macaron', //todo 地图样式
  656. resizeEnable: true //是否监控地图容器尺寸变化
  657. });
  658. /** 定位 */
  659. let marker = new AMap.Marker();
  660. if (this.aaa.length) {
  661. map.setCenter(this.aaa);
  662. map.add(marker);
  663. marker.setPosition(this.aaa);
  664. }
  665. /** 轨迹 */
  666. if (type === 3) {
  667. this.showInfo = false
  668. console.log('进来');
  669. map.clearMap();
  670. marker?.hide()
  671. const historyList = [{
  672. "lat": 39.91055750509886,
  673. "lng": 116.4036806180665,
  674. "gpsTime": "2023-10-08 13:47:14",
  675. "gpsId": 867605051108718,
  676. "compensate": null
  677. },
  678. {
  679. "lat": 39.910380195191074,
  680. "lng": 116.74977990361894,
  681. "gpsTime": "2023-10-08 14:08:14",
  682. "gpsId": 867605051108718,
  683. "compensate": null
  684. },
  685. {
  686. "lat": 39.91055750509886,
  687. "lng": 116.4036806180665,
  688. "gpsTime": "2023-10-08 14:26:00",
  689. "gpsId": 867605051108718,
  690. "compensate": null
  691. },
  692. {
  693. "lat": 39.91055750509886,
  694. "lng": 116.4036806180665,
  695. "gpsTime": "2023-10-08 14:27:00",
  696. "gpsId": 867605051108718,
  697. "compensate": null
  698. },
  699. {
  700. "lat": 39.91055750509886,
  701. "lng": 116.4036806180665,
  702. "gpsTime": "2023-10-08 14:30:00",
  703. "gpsId": 867605051108718,
  704. "compensate": null
  705. },
  706. {
  707. "lat": 39.910557505765034,
  708. "lng": 116.40368361866521,
  709. "gpsTime": "2023-10-08 14:31:00",
  710. "gpsId": 867605051108718,
  711. "compensate": null
  712. },
  713. {
  714. "lat": 39.032391,
  715. "lng": 117.662369,
  716. "gpsTime": "2023-10-08 19:10:00",
  717. "gpsId": 867605051108718,
  718. "compensate": null
  719. }
  720. ]
  721. AMap.plugin('AMap.Driving', function() {
  722. if (historyList.length >= 2) {
  723. var drivingOption = {
  724. policy: AMap.DrivingPolicy
  725. .LEAST_TIME, // 其它policy参数请参考 https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingPolicy
  726. ferry: 1, // 是否可以使用轮渡
  727. province: '京', // 车牌省份的汉字缩写
  728. }
  729. // 构造路线导航类
  730. var driving = new AMap.Driving(drivingOption)
  731. // 根据起终点经纬度规划驾车导航路线
  732. driving.search(new AMap.LngLat(historyList[0].lng, historyList[0]
  733. .lat),
  734. new AMap.LngLat(historyList[historyList.length - 1].lng,
  735. historyList[historyList.length - 1].lat),
  736. function(status, result) {
  737. if (status === 'complete') {
  738. if (result.routes && result.routes.length) {
  739. console.log(result.routes, 'result.routes');
  740. // 绘制第一条路线,也可以按需求绘制其它几条路线
  741. drawRoute(result.routes[0])
  742. console.log('绘制驾车路线完成')
  743. }
  744. } else {
  745. console.log('获取驾车数据失败:' + result)
  746. }
  747. });
  748. function drawRoute(route) {
  749. var path = parseRouteToPath(route)
  750. var startMarker = new AMap.Marker({
  751. position: path[0],
  752. icon: 'https://webapi.amap.com/theme/v1.3/markers/n/start.png',
  753. map: map
  754. })
  755. var endMarker = new AMap.Marker({
  756. position: path[path.length - 1],
  757. icon: 'https://webapi.amap.com/theme/v1.3/markers/n/end.png',
  758. map: map
  759. })
  760. var routeLine = new AMap.Polyline({
  761. path: path,
  762. isOutline: true,
  763. outlineColor: '#ffeeee',
  764. borderWeight: 2,
  765. strokeWeight: 5,
  766. strokeOpacity: 0.9,
  767. strokeColor: '#F35546',
  768. lineJoin: 'round'
  769. })
  770. map.add(routeLine);
  771. // 调整视野达到最佳显示区域
  772. map.setFitView([startMarker, endMarker, routeLine])
  773. }
  774. // 解析DrivingRoute对象,构造成AMap.Polyline的path参数需要的格式
  775. // DrivingResult对象结构参考文档 https://lbs.amap.com/api/javascript-api/reference/route-search#m_DriveRoute
  776. function parseRouteToPath(route) {
  777. var path = []
  778. for (var i = 0, l = route.steps.length; i < l; i++) {
  779. var step = route.steps[i]
  780. for (var j = 0, n = step.path.length; j < n; j++) {
  781. path.push(step.path[j])
  782. }
  783. }
  784. return path
  785. }
  786. }
  787. })
  788. }
  789. })
  790. .catch((e) => {
  791. console.error(e) //加载错误提示
  792. })
  793. },
  794. }
  795. };
  796. </script>
  797. <style lang="scss">
  798. .map-box {
  799. z-index: 888;
  800. width: 100%;
  801. height: 100vh;
  802. position: relative;
  803. .mp-header {
  804. z-index: 999;
  805. position: fixed;
  806. left: 0;
  807. top: 0;
  808. width: 100%;
  809. /* #ifdef H5 */
  810. padding-bottom: 20rpx;
  811. /* #endif */
  812. // background-color: $theme-color;
  813. .serch-box {
  814. height: 100%;
  815. width: 210rpx;
  816. background-color: #fff;
  817. border-radius: 35rpx;
  818. // margin: 33rpx 0 0 30rpx;
  819. margin: 0 0 0 30rpx;
  820. .serch-wrapper {
  821. height: 100%;
  822. align-items: center;
  823. padding: 19rpx;
  824. box-sizing: border-box;
  825. image {
  826. width: 118rpx;
  827. height: 42rpx;
  828. }
  829. .logo {
  830. width: 32rpx;
  831. height: 32rpx;
  832. display: flex;
  833. }
  834. .arrow {
  835. width: 48rpx;
  836. height: 48rpx;
  837. }
  838. .name {
  839. flex: 1;
  840. text-align: center;
  841. color: #7C7C7C;
  842. font-size: 36rpx;
  843. margin: 0 13rpx 0 18rpx;
  844. white-space: nowrap;
  845. }
  846. .input {
  847. display: flex;
  848. align-items: center;
  849. /* #ifdef MP */
  850. width: 305rpx;
  851. /* #endif */
  852. height: 50rpx;
  853. padding: 0 0 0 30rpx;
  854. background: rgba(247, 247, 247, 1);
  855. border: 1px solid rgba(241, 241, 241, 1);
  856. border-radius: 29rpx;
  857. color: #BBBBBB;
  858. font-size: 28rpx;
  859. .iconfont {
  860. margin-right: 20rpx;
  861. }
  862. }
  863. }
  864. }
  865. }
  866. #map {
  867. width: 100%;
  868. height: 100%;
  869. }
  870. ::v-deep .uni-image[src^="https://app.tjzhxx.cn:11443/"] {
  871. border: 2px solid red;
  872. /* 添加2px宽的红色边框 */
  873. border-radius: 50%;
  874. /* 可选,设置为圆形边框 */
  875. }
  876. .custom-marker {
  877. position: relative;
  878. width: 42px;
  879. /* 根据您的标记点图标宽度调整 */
  880. height: 47px;
  881. /* 根据您的标记点图标高度调整 */
  882. }
  883. .custom-marker img {
  884. width: 100%;
  885. height: 100%;
  886. /* 在这里添加您需要的自定义CSS样式 */
  887. border: 1rpx solid red;
  888. }
  889. .loading {
  890. z-index: 999;
  891. width: 100%;
  892. top: 30%;
  893. // left:50%;
  894. position: absolute;
  895. }
  896. .top-input::before {
  897. content: "";
  898. position: absolute;
  899. top: 0;
  900. left: 0;
  901. width: 100%;
  902. height: 100%;
  903. background: #FF0000;
  904. opacity: 0.1;
  905. filter: blur(50px);
  906. z-index: 66;
  907. pointer-events: none;
  908. }
  909. .top-input {
  910. width: 70%;
  911. height: 45%;
  912. top: 20%;
  913. left: 15%;
  914. text-align: center;
  915. position: absolute;
  916. box-sizing: border-box;
  917. font-size: 32rpx;
  918. font-weight: 500;
  919. color: #000000;
  920. // border: 1rpx solid red;
  921. padding: 119rpx 90rpx;
  922. image {
  923. width: 100%;
  924. height: 368rpx;
  925. }
  926. .btn-box {
  927. z-index: 999;
  928. width: 100%;
  929. display: flex;
  930. align-items: center;
  931. justify-content: center;
  932. .btn {
  933. background: rgba(255, 247, 247, 0.3);
  934. border-radius: 35rpx;
  935. border: 3rpx solid #EC3534;
  936. margin-top: 42rpx;
  937. width: 236rpx;
  938. height: 70rpx;
  939. display: flex;
  940. align-items: center;
  941. justify-content: center;
  942. font-weight: 600;
  943. font-size: 36rpx;
  944. color: #EC3534;
  945. }
  946. }
  947. }
  948. // .top-input {
  949. // width: 70%;
  950. // height: 45%;
  951. // top: 20%;
  952. // left: 15%;
  953. // text-align: center;
  954. // position: absolute;
  955. // box-sizing: border-box;
  956. // font-size: 32rpx;
  957. // font-weight: 500;
  958. // color: #000000;
  959. // border: 1rpx solid red;
  960. // background: #FF0000;
  961. // opacity: 0.4;
  962. // filter: blur(50px);
  963. // padding:119rpx 90rpx;
  964. // image{
  965. // width: 100%;
  966. // height: 368rpx;
  967. // }
  968. // .btn-box{
  969. // width: 100%;
  970. // display: flex;
  971. // align-items: center;
  972. // justify-content: center;
  973. // .btn{
  974. // background: rgba(255,247,247,0.3);
  975. // border-radius: 35rpx;
  976. // border: 3rpx solid #EC3534;
  977. // margin-top: 42rpx;
  978. // width: 236rpx;
  979. // height: 70rpx;
  980. // display: flex;
  981. // align-items: center;
  982. // justify-content: center;
  983. // }
  984. // }
  985. // }
  986. .info-box {
  987. width: 100%;
  988. height: 40%;
  989. display: flex;
  990. justify-content: center;
  991. flex-direction: column;
  992. position: absolute;
  993. bottom: 75rpx;
  994. z-index: 1000;
  995. // background-color: #fff;
  996. padding: 0 30rpx 0;
  997. font-size: 32rpx;
  998. font-weight: 400;
  999. color: #000000;
  1000. box-sizing: border-box;
  1001. .scroll-view_H {
  1002. width: 100%;
  1003. height: 80%;
  1004. /* 设置适当的高度 */
  1005. .scroll-view-content {
  1006. height: 100%;
  1007. white-space: nowrap;
  1008. font-size: 0;
  1009. overflow-x: auto;
  1010. .scroll-view-item_H {
  1011. width: 50%;
  1012. height: 100%;
  1013. display: inline-block;
  1014. font-size: 16px;
  1015. margin-right: 15rpx;
  1016. position: relative;
  1017. .bg-image {
  1018. width: 100%;
  1019. height: 100%;
  1020. object-fit: cover;
  1021. }
  1022. .text-wrapper {
  1023. position: absolute;
  1024. top: 0;
  1025. left: 0;
  1026. width: 100%;
  1027. height: 100%;
  1028. display: flex;
  1029. justify-content: flex-start;
  1030. padding: 60rpx 30rpx 0;
  1031. }
  1032. .black {
  1033. color: #2D2D2D;
  1034. }
  1035. .white {
  1036. color: #fff;
  1037. }
  1038. .text-overlay {
  1039. // color: white;
  1040. font-size: 16px;
  1041. width: 100%;
  1042. overflow: hidden;
  1043. .top-box {
  1044. display: flex;
  1045. justify-content: space-between;
  1046. .top-left {
  1047. .english {
  1048. font-size: 24rpx;
  1049. }
  1050. .chinese {
  1051. font-size: 32rpx;
  1052. }
  1053. }
  1054. .top-right {
  1055. width: 76rpx;
  1056. height: 76rpx;
  1057. border-radius: 50%;
  1058. }
  1059. }
  1060. .under-box {
  1061. margin-top: 8rpx;
  1062. display: flex;
  1063. justify-content: space-between;
  1064. align-items: flex-end;
  1065. .under-left {
  1066. color: #EC3534;
  1067. .number {
  1068. font-size: 36rpx;
  1069. font-weight: 600;
  1070. }
  1071. .unit {
  1072. font-size: 28rpx;
  1073. font-weight: 500;
  1074. }
  1075. }
  1076. .under-right {
  1077. font-weight: 500;
  1078. .range {
  1079. font-size: 24rpx;
  1080. }
  1081. .range-word {
  1082. font-size: 24rpx;
  1083. }
  1084. }
  1085. .white {
  1086. color: #fff;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. }
  1092. }
  1093. .sos-btn {
  1094. width: 100%;
  1095. height: 140rpx;
  1096. image {
  1097. width: 100%;
  1098. height: 100%;
  1099. }
  1100. }
  1101. .code {
  1102. font-size: 32rpx;
  1103. font-weight: 600;
  1104. color: #000000;
  1105. }
  1106. .time {
  1107. font-size: 28rpx;
  1108. font-weight: 400;
  1109. color: #999999;
  1110. margin: 10rpx 0 16rpx;
  1111. display: flex;
  1112. align-items: center;
  1113. .online-box {
  1114. margin-right: 25rpx;
  1115. width: 55rpx;
  1116. height: 30rpx;
  1117. image {
  1118. width: 100%;
  1119. height: 100%;
  1120. }
  1121. }
  1122. }
  1123. .position {
  1124. // margin-top: 16rpx;
  1125. }
  1126. }
  1127. .icon-box {
  1128. width: 10%;
  1129. height: 30%;
  1130. top: 20%;
  1131. position: absolute;
  1132. left: 5%;
  1133. display: flex;
  1134. background-color: #ECECEC;
  1135. flex-direction: column;
  1136. justify-content: space-between;
  1137. border-radius: 10rpx;
  1138. .img-box {
  1139. text-align: center;
  1140. height: 24.5%;
  1141. line-height: 130rpx;
  1142. background-color: #fff;
  1143. image {
  1144. width: 42rpx;
  1145. height: 42rpx;
  1146. }
  1147. }
  1148. .first {
  1149. border-radius: 10rpx 10rpx 0 0;
  1150. }
  1151. .last {
  1152. border-radius: 0 0 10rpx 10rpx;
  1153. }
  1154. image {
  1155. width: 42rpx;
  1156. height: 42rpx;
  1157. }
  1158. }
  1159. .icon-box-right {
  1160. width: 10%;
  1161. height: 25%;
  1162. top: 10%;
  1163. position: absolute;
  1164. right: 5%;
  1165. display: flex;
  1166. flex-direction: column;
  1167. justify-content: space-between;
  1168. image {
  1169. width: 70rpx;
  1170. height: 70rpx;
  1171. }
  1172. }
  1173. }
  1174. </style>