index.vue 33 KB

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