index.vue 35 KB

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