index.html 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <!-- <title>{{$t('board.wdkl')}}</title> -->
  8. <link rel="stylesheet" href="./css/index.css">
  9. <link rel="stylesheet" href="./fonts/icomoon.css">
  10. <!-- elementui -->
  11. <link rel="stylesheet" href="./css/element-ui.css">
  12. <!-- <link rel="stylesheet" href="./css/flipclock.css"> -->
  13. <script src="./js/scoket.js"></script>
  14. <script src="./js/api.js"></script>
  15. <!-- // 引入 Vue.js -->
  16. <script src="./js/vue.js"></script>
  17. <script src="./js/element-ui.js"></script>
  18. <!-- 先加载 ECharts -->
  19. <script src="./js/echarts.min.js"></script>
  20. <!-- 再加载百度地图 API 和 ECharts 的百度地图扩展 -->
  21. <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=4lgYDZ9MWQMbTvjX5R5M5pZG"></script>
  22. <script type="text/javascript" src="./js/MarkerClusterer_min.js"></script>
  23. <script type="text/javascript" src="./js/TextIconOverlay_min.js"></script>
  24. <script type="text/javascript" src="./js/bmap.min.js"></script>
  25. <script src="./js/axios.min.js"></script>
  26. <!-- 自定义 JS -->
  27. <script src="./js/mapStyleJson.js"></script>
  28. <!-- i18 -->
  29. <script src="./js/vue-i18n.min.js"></script>
  30. <script src="./js/i18n.js"></script>
  31. </head>
  32. <body>
  33. <!-- 星空特效 -->
  34. <canvas id="canvas" style="position: absolute;top: 0;left: 0;"></canvas>
  35. <script src="./js/bg.js"></script>
  36. <div id="app">
  37. <title>{{$t('wdklScreen.wdkl')}}</title>
  38. <div class="header">
  39. <div class="title" id="title">{{title}}</div>
  40. <!-- 添加语言切换按钮 -->
  41. <div style="position: absolute;top:25px; right: 80px;margin: auto 0;">
  42. <el-dropdown @command="handleLanguageChange">
  43. <el-button type="primary" size="mini" style="background-color: rgba(255, 255, 255, 0.05);font-size: 10px;padding: 3px 8px; height: 22px;
  44. color: rgba(255, 255, 255, 0.6); border: 1px solid rgba(255, 255, 255, 0.15);">
  45. {{ getLanguageName }}
  46. </el-button>
  47. <el-dropdown-menu slot="dropdown">
  48. <el-dropdown-item command="zh">中文</el-dropdown-item>
  49. <el-dropdown-item command="en">English</el-dropdown-item>
  50. <el-dropdown-item command="es">Español</el-dropdown-item>
  51. <el-dropdown-item command="ru">Русский</el-dropdown-item>
  52. </el-dropdown-menu>
  53. </el-dropdown>
  54. </div>
  55. <div id="muteImg" style="top:20px;right: 20px;position: absolute;">
  56. <image src="./images/mute.png" style="height: 30px;width: 30px"></image>
  57. </div>
  58. </div>
  59. <div class="clearfix"></div>
  60. <div class="viewport">
  61. <div class="column">
  62. <div class="overview panel">
  63. <div class="inner">
  64. <div class="item">
  65. <h4>{{ allCount }}</h4>
  66. <span>
  67. <i class="icon-dot" style="color: #006cff"></i>
  68. {{$t('wdklScreen.totalUsers')}}
  69. </span>
  70. </div>
  71. <div class="item">
  72. <h4>{{quarterlyAddition}}</h4>
  73. <span>
  74. <i class="icon-dot" style="color: #6acca3"></i>
  75. {{$t('wdklScreen.quarterlyNew')}}
  76. </span>
  77. </div>
  78. <div class="item">
  79. <h4>{{monthlyAddition}}</h4>
  80. <span>
  81. <i class="icon-dot" style="color: #ed3f35"></i>
  82. {{$t('wdklScreen.monthlyNew')}}
  83. </span>
  84. </div>
  85. </div>
  86. </div>
  87. <!--监控-->
  88. <div class="monitor panel">
  89. <div class="inner">
  90. <div class="tabs">
  91. <a href="javascript:;" data-index="0" class="active">{{$t('wdklScreen.latestAlarms')}}</a>
  92. </div>
  93. <div class="content" style="display: block;">
  94. <div class="head">
  95. <span class="col"> {{$t('wdklScreen.time')}}</span>
  96. <span class="col"> {{$t('wdklScreen.user')}}</span>
  97. <span class="col"> {{$t('wdklScreen.project')}}</span>
  98. <!-- <span class="col">值</span>-->
  99. </div>
  100. <div class="marquee-view">
  101. <div id="vsLogTable" class="marquee">
  102. <div class="row" v-for="(item,index) in sosInfo.actionList" :key="index">
  103. <span class="col">{{unixToDate(item.create_date, "MM-dd hh:mm")}}</span>
  104. <span class="col">{{item.from_member_name}}</span>
  105. <!-- from_device_type -->
  106. <!-- <span class="col">{{item.from_device_type}}</span> -->
  107. <span class="col">{{deviceTypeGetter(item.from_device_type)}}</span>
  108. <span class="icon-dot"></span>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. <!--点位-->
  116. <div class="point panel">
  117. <div class="inner">
  118. <h3> {{$t('wdklScreen.ageDistribution')}}</h3>
  119. <div class="chart">
  120. <div class="pie"></div>
  121. <div class="data">
  122. <div class="item">
  123. <h4>{{manCount}}</h4>
  124. <span>
  125. <i class="icon-dot" style="color: #ed3f35"></i>
  126. {{$t('wdklScreen.male')}}
  127. </span>
  128. </div>
  129. <div class="item">
  130. <h4>{{womanCount}}</h4>
  131. <span>
  132. <i class="icon-dot" style="color: #eacf19"></i>
  133. {{$t('wdklScreen.female')}}
  134. </span>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. <div class="column">
  142. <!-- 地图 -->
  143. <div class="map">
  144. <div class="chart">
  145. <div class="geo"></div>
  146. </div>
  147. </div>
  148. <!-- 用户 -->
  149. <div class="users panel">
  150. <div class="inner">
  151. <h3> {{$t('wdklScreen.alarmDistribution')}}</h3>
  152. <div class="chart">
  153. <div class="bar"></div>
  154. <div class="data">
  155. <div class="item">
  156. <h4>{{dayCount}}</h4>
  157. <span>
  158. <i class="icon-dot" style="color: #ed3f35"></i>
  159. {{$t('wdklScreen.todayMeasureCount')}}
  160. </span>
  161. </div>
  162. <div class="item">
  163. <h4>{{hourCount}}</h4>
  164. <span>
  165. <i class="icon-dot" style="color: #eacf19"></i>
  166. {{$t('wdklScreen.lastHour')}}
  167. </span>
  168. </div>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. </div>
  174. <div class="column">
  175. <div class="order panel">
  176. <div class="inner">
  177. <!-- 筛选 -->
  178. <div class="filter">
  179. <a href="javascript:;" v-for="(days, index) in ['365', '90', '30', '7']" :key="index"
  180. :class="{ active: activeTimeFilter === 'day' + days }"
  181. @click="handleMeasureFilter('day' + days)">
  182. {{days}}{{$t('wdklScreen.days')}}
  183. </a>
  184. </div>
  185. <!-- 数据 -->
  186. <div class="data">
  187. <div class="item">
  188. <h4>{{currentMeasureData.count}}</h4>
  189. <span>
  190. <i class="icon-dot" style="color: #ed3f35;"></i>
  191. {{$t('wdklScreen.measurement')}}
  192. </span>
  193. </div>
  194. <div class="item">
  195. <h4>{{currentMeasureData.errCount}}</h4>
  196. <span>
  197. <i class="icon-dot" style="color: #eacf19;"></i>
  198. {{$t('wdklScreen.alarm')}}
  199. </span>
  200. </div>
  201. </div>
  202. </div>
  203. </div>
  204. <!-- 报警统计 -->
  205. <div class="alarms panel">
  206. <div class="inner">
  207. <div class="caption">
  208. <h3>{{$t('wdklScreen.alarmStatistics')}}</h3>
  209. <a v-for="(item, index) in alarmTabs" :key="index"
  210. :class="{ active: activeAlarmType === getDataType(index) }"
  211. @click="handleAlarmTabClick(index)">
  212. {{ item }}
  213. </a>
  214. </div>
  215. <div class="chart">
  216. <div class="label"></div>
  217. <div class="line"></div>
  218. </div>
  219. </div>
  220. </div>
  221. <!--异常-->
  222. <div class="monitor panel">
  223. <div class="inner">
  224. <div class="tabs">
  225. <a href="javascript:;" data-index="0"
  226. class="active">{{$t('wdklScreen.vitalSignsAlarm')}}</a>
  227. </div>
  228. <div class="content" style="display: block;">
  229. <div class="head">
  230. <span class="col">{{$t('wdklScreen.time')}}</span>
  231. <span class="col">{{$t('wdklScreen.user')}}</span>
  232. <span class="col">{{$t('wdklScreen.project')}}</span>
  233. <span class="col">{{$t('wdklScreen.value')}}</span>
  234. </div>
  235. <div class="marquee-view">
  236. <div id="errVsLogTable" class="marquee alarms-list">
  237. <div class="row" v-for="(item,index) in logInfo.errVsLogList" :key="index">
  238. <span class="col">{{unixToDate(item.log_time, "MM-dd hh:mm")}}</span>
  239. <span class="col">{{item.member_nickname}}</span>
  240. <span class="col">{{item.param_name}}</span>
  241. <span class="col">{{item.vs_value}}</span>
  242. <span class="icon-dot"></span>
  243. </div>
  244. </div>
  245. </div>
  246. </div>
  247. </div>
  248. </div>
  249. </div>
  250. </div>
  251. </div>
  252. </body>
  253. <script>
  254. // 配置 axios 全局默认值
  255. axios.defaults.baseURL = window.api.base; // 设置默认的请求地址
  256. // http://192.168.1.199:7000
  257. axios.defaults.timeout = 5000; // 设置请求超时时间
  258. // axios.defaults.headers.common['Content-Type'] = 'application/json';
  259. // 将 axios 挂载到 Vue 原型上
  260. Vue.prototype.$http = axios;
  261. new Vue({
  262. el: '#app',
  263. i18n,
  264. data() {
  265. return {
  266. deviceTypeList: [],
  267. currentLang: localStorage.getItem('language') === null ? 'zh' : localStorage.getItem('language'),// 默认语言
  268. //右上第一个数据显示
  269. currentMeasureData: {
  270. count: 0,
  271. errCount: 0
  272. },
  273. //中间第二个图测量数据
  274. dayCount: 0,
  275. hourCount: 0,
  276. showTime: null,
  277. breakTime: null,
  278. heartbeatTime: null,
  279. partId: null,// 将 partId
  280. title: this.$t('wdklScreen.wdkl'),
  281. socket: null, // 添加 socket 实例变量
  282. mapHeight: 0,//地图高度
  283. host_port: window.api.base.replace('http://', ''),
  284. // host_port: "119.23.151.229:8006/",
  285. allCount: 0,
  286. quarterlyAddition: 0,
  287. monthlyAddition: 0,
  288. manCount: 0,
  289. womanCount: 0,
  290. vsLogs: [],
  291. errVsLogs: [],
  292. activeTimeFilter: 'day365',
  293. alarmTabs: [
  294. this.$t('wdklScreen.week'),
  295. this.$t('wdklScreen.month'),
  296. this.$t('wdklScreen.year')
  297. ],
  298. activeAlarmType: 'week',
  299. measureData: {
  300. day365: {
  301. count: 0,
  302. errCount: 0
  303. },
  304. day90: {
  305. count: 0,
  306. errCount: 0
  307. },
  308. day30: {
  309. count: 0,
  310. errCount: 0
  311. },
  312. day7: {
  313. count: 0,
  314. errCount: 0
  315. }
  316. },
  317. charts: {
  318. pie: null,
  319. line: null,
  320. bar: null,
  321. map: null
  322. },
  323. mapOption: null,
  324. timers: {
  325. heartbeat: null,
  326. break: null,
  327. show: null
  328. },
  329. colorList: ['#00f2f1', '#006cff', '#eab408', '#ed8884', '#ff9f7f', '#0096ff', '#9fe6b8', '#32c5e9', '#1d9dff'],
  330. // 数据
  331. userInfo: {
  332. allCount: 0,
  333. quarterlyCount: 0,
  334. monthCount: 0,
  335. manCount: 0,
  336. womanCount: 0,
  337. },
  338. sosInfo: {
  339. actionList: [],
  340. barList: []
  341. },
  342. chartData: {
  343. year: null, // 初始化为空数组而不是 null
  344. month: null,
  345. week: null
  346. },
  347. logInfo: {
  348. dayCount: 0,
  349. hourCount: 0,
  350. errVsLogList: []
  351. },
  352. // 当前激活的筛选
  353. activeFilters: {
  354. timeFilter: 'day365',
  355. alarmType: 'week'
  356. }
  357. }
  358. },
  359. created() {
  360. this.getDeviceTypeList();
  361. },
  362. mounted() {
  363. this.$nextTick(() => {
  364. this.partId = this.getQuery("partId");
  365. // 初始化各个图表实例
  366. this.myPieEchart = echarts.init(document.querySelector('.pie'));
  367. this.myLineEchart = echarts.init(document.querySelector('.line'));
  368. this.myBarEchart = echarts.init(document.querySelector('.bar'));
  369. this.myMapChart = echarts.init(document.querySelector('.geo'));
  370. // 初始化设置
  371. this.setFont();
  372. this.setGeoHeight();
  373. // 初始化监控面板
  374. this.initMonitor();
  375. if (this.partId) {
  376. // 连接webSocket
  377. this.initWebSocket();
  378. // 打开定时器
  379. this.openTimer();
  380. let image = document.getElementById('muteImg');
  381. image.addEventListener('click', function () {
  382. image.style.display = "none";
  383. })
  384. }
  385. const debouncedResize = this.debounce(this.handleResize, 300);
  386. window.addEventListener('resize', debouncedResize);
  387. this.handleResize();
  388. });
  389. },
  390. beforeDestroy() {
  391. // 关闭 WebSocket 连接
  392. if (this.ws) {
  393. this.ws.close();
  394. this.ws = null;
  395. }
  396. // 清除所有定时器
  397. if (this.heartbeatTime) {
  398. clearInterval(this.heartbeatTime);
  399. this.heartbeatTime = null;
  400. }
  401. if (this.breakTime) {
  402. clearInterval(this.breakTime);
  403. this.breakTime = null;
  404. }
  405. if (this.showTime) {
  406. clearTimeout(this.showTime);
  407. this.showTime = null;
  408. }
  409. if (this.debouncedResize) {
  410. window.removeEventListener('resize', this.debouncedResize);
  411. }
  412. },
  413. computed: {
  414. getLanguageName() {
  415. return this.$t('wdklScreen.languageSelector')
  416. }
  417. },
  418. methods: {
  419. //切换语言
  420. handleLanguageChange(lang) {
  421. this.currentLang = lang;
  422. this.$i18n.locale = lang;
  423. // 可以存储到 localStorage 以保持语言选择
  424. localStorage.setItem('language', lang);
  425. if (!this.partId || this.title === this.$t('wdklScreen.wdkl')) {
  426. this.title = this.$t('wdklScreen.wdkl');
  427. }
  428. this.getDeviceTypeList()
  429. this.alarmTabs = [
  430. this.$t('wdklScreen.week'),
  431. this.$t('wdklScreen.month'),
  432. this.$t('wdklScreen.year')
  433. ];
  434. // this.getDeviceTypeList();
  435. // this.getUserInfo();
  436. this.getSOSInfo();
  437. this.getLogInfo();
  438. },
  439. //设备类型转化
  440. deviceTypeGetter(item) {
  441. if (item === undefined || item === null) {
  442. console.warn('设备类型值无效:', item);
  443. return '未知设备';
  444. }
  445. const deviceType = this.deviceTypeList.find(type => type.value === item);
  446. if (!deviceType) {
  447. console.warn('未找到匹配的设备类型:', item);
  448. return '未知设备';
  449. }
  450. return deviceType.title;
  451. },
  452. // 获取设备类型列表
  453. getDeviceTypeList() {
  454. let data = []
  455. this.$http.post('/arrange/getDeviceTypeChildrenVO', { lg: this.$i18n.locale }, {
  456. headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
  457. }).then(res => {
  458. // 过滤并展平设备类型数据
  459. // console.log('333333333deviceTypeList', res)
  460. res.data.forEach(item => {
  461. if (item.bool_device) {
  462. data.push(item)
  463. }
  464. if (item.children) {
  465. item.children.forEach(t => {
  466. if (t.bool_device) {
  467. data.push(t)
  468. }
  469. })
  470. }
  471. })
  472. this.deviceTypeList = data
  473. // console.log('77777883deviceTypeList', data)
  474. }).catch(error => {
  475. // console.error('获取设备类型列表失败:', error);
  476. });
  477. },
  478. renderMapData(memberList) {
  479. if (!memberList || !memberList.length || !memberList[0].lng_lat) {
  480. console.log('memberList或经纬度为空');
  481. return;
  482. }
  483. this.mapOption = this.initMap();
  484. // console.log('悬停获取地图数据,data==== ', data);
  485. const d = [];
  486. if (memberList.length > 0) {
  487. memberList.forEach(item => {
  488. // console.log('悬停获取地图数据,item==== ', item.lng_lat);
  489. if (item.lng_lat) {
  490. const coordinates = item.lng_lat.split(',');
  491. const time = this.unixToDate(item.create_time, "MM-dd hh:mm");
  492. d.push({
  493. name: item.nickname,
  494. value: coordinates,
  495. size: 10,
  496. text: `${item.address}<br>${item.member_name},${time}`
  497. });
  498. }
  499. });
  500. }
  501. // 更新地图配置
  502. this.mapOption.series = [
  503. {
  504. name: "体征告警",
  505. type: 'effectScatter',
  506. coordinateSystem: 'bmap',
  507. data: [], // 用于显示报警点
  508. symbolSize: 10,
  509. showEffectOn: "render", // 配置何时显示特效。 render 绘制完成后显示特效。emphasis 高亮(hover)的时候显示特效。
  510. rippleEffect: {
  511. brushType: "stroke", // 波纹的绘制方式 stroke 和 fill
  512. number: 3, // 波纹的数量
  513. scale: 5, // 波纹放大的倍数
  514. color: "#8FD1C3",
  515. },
  516. hoverAnimation: true,
  517. label: {
  518. formatter: "{b}",
  519. position: "right",
  520. show: true,
  521. },
  522. itemStyle: {
  523. color: "#f37b1d",
  524. shadowBlur: 10,
  525. shadowColor: "#333",
  526. },
  527. zlevel: 1,
  528. },
  529. {
  530. name: '正常体征',
  531. type: 'scatter',
  532. coordinateSystem: 'bmap',
  533. data: d,
  534. symbolSize: 10,
  535. label: {
  536. formatter: '{b}',
  537. position: 'right',
  538. show: false
  539. },
  540. itemStyle: {
  541. color: "#ddb926",
  542. },
  543. emphasis: {
  544. label: {
  545. show: true
  546. }
  547. }
  548. }];
  549. // 设置地图中心和缩放级别
  550. if (d.length > 0) {
  551. this.mapOption.bmap.center = d[0].value;
  552. this.mapOption.bmap.zoom = 14;
  553. }
  554. // 应用配置
  555. this.myMapChart.setOption(this.mapOption, true);
  556. // 获取百度地图实例
  557. const bmap = this.myMapChart.getModel().getComponent('bmap').getBMap();
  558. // 转换为百度地图点位
  559. const points = d.map(item => {
  560. const point = new BMap.Point(item.value[0], item.value[1]);
  561. const marker = new BMap.Marker(point);
  562. // marker.setTitle(item.name); /
  563. return marker;
  564. });
  565. // 清除已有的聚合点
  566. if (this.markerClusterer) {
  567. this.markerClusterer.clearMarkers();
  568. }
  569. // 创建新的聚合实例
  570. this.markerClusterer = new BMapLib.MarkerClusterer(bmap, {
  571. markers: points,
  572. maxZoom: 16,
  573. minClusterSize: 2,
  574. styles: [{
  575. url: 'https://api.map.baidu.com/library/MarkerClusterer/1.2/examples/images/m1.png',
  576. size: new BMap.Size(53, 53),
  577. backgroundColor: '#1890FF',
  578. textColor: '#fff',
  579. textSize: '16'
  580. }],
  581. });
  582. // 计算所有点的边界
  583. const bounds = new BMap.Bounds();
  584. points.forEach(marker => { bounds.extend(marker.getPosition()); });
  585. // 根据边界自动调整视野
  586. bmap.setViewport(bounds, {
  587. enableAnimation: true,
  588. margins: [50, 50, 50, 50] // 设置上、右、下、左的边距,确保点不会太靠近边缘
  589. });
  590. window.addEventListener("resize", this.myMapChart.resize);
  591. },
  592. // 添加防抖函数
  593. debounce(fn, delay) {
  594. let timer = null;
  595. return function () {
  596. if (timer) clearTimeout(timer);
  597. timer = setTimeout(() => {
  598. fn.apply(this, arguments);
  599. }, delay);
  600. }
  601. },
  602. getDataType(index) {
  603. const types = ['week', 'month', 'year'];
  604. return types[index];
  605. },
  606. handleAlarmTabClick(index) {
  607. const type = this.getDataType(index);
  608. this.activeAlarmType = type;
  609. this.handleChartTypeChange(type);
  610. },
  611. // 获取看板用户信息
  612. getUserInfo() {
  613. const partId = this.getQuery('partId');
  614. this.$http.get("bulletinBoard/user_info/" + partId).then(response => {
  615. const data = response.data;
  616. this.title = data.partInfo.shop_name;
  617. this.allCount = data.userCount.all_count;
  618. this.quarterlyAddition = data.userCount.quarterly_count;
  619. this.monthlyAddition = data.userCount.month_count;
  620. this.manCount = data.userCount.man_count || 0;
  621. this.womanCount = data.userCount.woman_count || 0;
  622. // 渲染地图
  623. this.renderMapData(data.memberList);
  624. // 年龄段饼图
  625. const pieOption = this.initPieChar();
  626. pieOption.series[0].data = data.pieData;
  627. // console.log('饼图数据', pieOption.series[0].data);
  628. this.myPieEchart.setOption(pieOption);
  629. }).catch(error => {
  630. console.error('获取用户信息失败', error);
  631. });
  632. },
  633. // 获取看板事件报警信息 左二
  634. getSOSInfo() {
  635. const partId = this.getQuery('partId');
  636. this.$http.get("bulletinBoard/sos_info/" + partId)
  637. .then(response => {
  638. const data = response.data;
  639. // 更新数据
  640. this.sosInfo.actionList = data.actionList;
  641. console.log('获取看板事件报警信息', this.sosInfo.actionList);
  642. // 报警分布
  643. const xData = data.barList.map(item => item.name);
  644. const yData = data.barList.map(item => item.value);
  645. const barOption = this.initBarChar();
  646. barOption.xAxis[0].data = xData;
  647. barOption.series[0].data = yData;
  648. this.myBarEchart.setOption(barOption);
  649. // 动态报警折线图
  650. this.initDynamicAlarm(data);
  651. })
  652. .catch(error => {
  653. console.error('获取报警信息失败', error);
  654. });
  655. },
  656. // 获取体征看板信息 中三
  657. getLogInfo() {
  658. const partId = this.getQuery('partId');
  659. this.$http.get("bulletinBoard/log_info/" + partId)
  660. .then(response => {
  661. const data = response.data;
  662. // console.log('体征看板信息', data);
  663. // 更新今日测量数和近1小时测量数
  664. this.dayCount = data.logCount.day_count;
  665. this.hourCount = data.logCount.hour_count;
  666. // 动态测量项
  667. this.initMeasureItem(data);
  668. this.logInfo.errVsLogList = data.errVsLogList;
  669. })
  670. .catch(error => {
  671. console.error('获取体征信息失败', error);
  672. });
  673. },
  674. initWebSocket() {
  675. const that = this;
  676. if (!this.partId) {
  677. console.warn('partId 不存在,WebSocket 未初始化');
  678. return;
  679. }
  680. var time = Math.round(new Date()) + "" + Math.round(Math.random() * 100);
  681. console.log(time, this.partId)
  682. // var s = "ws://127.0.0.1:8006/bulletinBoard/" + time + "/" + partId;
  683. var s = "ws://" + this.host_port + "/" + "bulletinBoard/" + time + "/" + this.partId;
  684. console.log(s)
  685. var ws = new WebSocket(s);
  686. ws.onopen = function (evt) {
  687. console.log("webSocket连接成功 ...");
  688. clearInterval(that.breakTime);
  689. that.breakTime = null;
  690. that.heartbeatTime = setInterval(function () {
  691. ws.send("ping");
  692. }, 55000); // 55秒心跳包
  693. // 获取看板用户信息
  694. that.getUserInfo();
  695. // 获取看板事件报警信息
  696. that.getSOSInfo();
  697. // 获取看板体征信息
  698. that.getLogInfo();
  699. };
  700. ws.onmessage = function (e) {
  701. console.log("收到消息: " + e.data);
  702. if (e.data === 'pong') {
  703. return
  704. }
  705. // {"address":"广东省深圳市南山区留仙大道大学城创客小镇","ageUnit":"岁","birthday":-189417600,"createTime":1661990011,"data":"15秒红外报警",
  706. // "frameId":1155,"id":457,"lngLat":"113.961957,22.579848","memberId":54658,"mobile":"18174091244","named":"小米面","partId":2,
  707. // "renewType":"SOS","sex":1,"status":0}
  708. const data = JSON.parse(e.data);
  709. if (data.renewType === 'SOS') {
  710. console.log('有人报警...')
  711. let mp3 = new Audio('./music/sos.mp3')
  712. mp3.loop = false
  713. mp3.play()
  714. that.openSOSMap(data); // 地图高亮
  715. that.getSOSInfo(); // 刷新看板
  716. } else if (data.renewType === 'LOG') {
  717. console.log('体征异常...')
  718. that.openSOSMap(data); // 地图高亮
  719. that.getLogInfo(); // 刷新体征
  720. } else { // USER
  721. that.getUserInfo(); // 刷新用户
  722. }
  723. };
  724. ws.onclose = function (evt) {
  725. console.log("webSocket连接关闭.", that.breakTime);
  726. if (!that.breakTime) {
  727. console.log('新的定时任务....')
  728. clearInterval(that.heartbeatTime);
  729. that.breakTime = setInterval(function () {
  730. console.log('正在重连...')
  731. that.initWebSocket();
  732. }, 5000); // 5秒重连一次
  733. }
  734. // heartbeatTime.
  735. };
  736. },
  737. // 地图高亮
  738. openSOSMap(data) {
  739. if (data.lngLat) {
  740. var d = []
  741. d.push({
  742. name: data.named,
  743. value: data.lngLat.split(","),
  744. size: 20,
  745. text: formatSOSText(data),
  746. })
  747. this.mapOption.series[0].data = d;
  748. this.mapOption.bmap.center = d[0].value;
  749. this.mapOption.bmap.zoom = 18;
  750. this.myMapChart.setOption(this.mapOption);
  751. this.myMapChart.dispatchAction({
  752. type: 'showTip',
  753. seriesIndex: 0,
  754. dataIndex: 0
  755. });
  756. clearTimeout(this.showTime);
  757. this.showTime = setTimeout(() => this.clearSOSMap(), 15000);
  758. }
  759. },
  760. // 清除百度地图报警点
  761. clearSOSMap() {
  762. console.log("我要清除报警高亮点了", this.mapOption.series[0].data, this.mapOption.series[1].data[0].value)
  763. this.mapOption.series[0].data = [];
  764. this.mapOption.bmap.center = this.mapOption.series[1].data[0].value;
  765. this.mapOption.bmap.zoom = 16;
  766. this.myMapChart.setOption(this.mapOption);
  767. },
  768. openTimer() {
  769. // 测量时间段定时器
  770. let i = 0;
  771. const aclick = document.querySelectorAll('.order a');
  772. setInterval(() => {
  773. i = (i + 1) % 4; // 循环 0-3
  774. aclick[i].click(); // 触发点击事件
  775. }, 3000);
  776. // 报警统计折线图定时器
  777. let ii = 0;
  778. const alarmLinks = document.querySelectorAll('.alarms .caption a');
  779. setInterval(() => {
  780. ii = (ii + 1) % alarmLinks.length; // 根据实际元素数量循环
  781. alarmLinks[ii].click(); // 触发点击事件
  782. }, 5000);
  783. // setInterval(() => {
  784. // ii = (ii + 1) % 5; // 循环 0-4
  785. // alarmLinks[ii].click(); // 触发点击事件
  786. // }, 5000);
  787. },
  788. // 自调用函数设置字体大小
  789. setFont() {
  790. let html = document.documentElement
  791. let width = html.clientWidth
  792. if (width < 1024) width = 1024
  793. if (width > 1920) width = 1920
  794. let fontSize = width / 80 + 'px'
  795. html.style.fontSize = fontSize
  796. },
  797. setGeoHeight() {
  798. this.$nextTick(() => {
  799. let mapHeight = document.querySelector('.map').offsetHeight;
  800. document.querySelector('.geo').style.height = mapHeight + 'px';
  801. // console.log('地图高度!!:', mapHeight)
  802. });
  803. },
  804. // 窗口调整处理函数
  805. handleResize() {
  806. this.setFont();
  807. this.setGeoHeight();
  808. },
  809. initMonitor() {
  810. // 获取所有 marquee 元素并复制内容
  811. this.$nextTick(() => {
  812. const marquees = document.querySelectorAll('.monitor .marquee');
  813. if (!marquees || marquees.length === 0) return;
  814. marquees.forEach(marquee => {
  815. const clone = Array.from(marquee.children).map(child => child.cloneNode(true));
  816. clone.forEach(item => marquee.appendChild(item));
  817. });
  818. });
  819. },
  820. // 报警分布柱状图
  821. initBarChar() {
  822. return {
  823. // 工具提示
  824. tooltip: {
  825. // 触发类型 经过轴触发axis 经过轴触发item
  826. trigger: 'item',
  827. // 轴触发提示才有效
  828. axisPointer: {
  829. // 默认为直线,可选为:'line' 线效果 | 'shadow' 阴影效果
  830. type: 'shadow'
  831. }
  832. },
  833. // 图表边界控制
  834. grid: {
  835. // 距离 上右下左 的距离
  836. left: '0',
  837. right: '3%',
  838. bottom: '3%',
  839. top: '5%',
  840. // 大小是否包含文本【类似于boxsizing】
  841. containLabel: true,
  842. //显示边框
  843. show: true,
  844. //边框颜色
  845. borderColor: 'rgba(0, 240, 255, 0.3)'
  846. },
  847. // 控制x轴
  848. xAxis: [
  849. {
  850. // 使用类目,必须有data属性
  851. type: 'category',
  852. // 使用 data 中的数据设为刻度文字
  853. data: [],
  854. // 刻度设置
  855. axisTick: {
  856. // true意思:图形在刻度中间
  857. // false意思:图形在刻度之间
  858. alignWithLabel: false,
  859. show: false
  860. },
  861. //文字
  862. axisLabel: {
  863. color: '#4c9bfd'
  864. }
  865. }
  866. ],
  867. // 控制y轴
  868. yAxis: [
  869. {
  870. // 使用数据的值设为刻度文字
  871. type: 'value',
  872. axisTick: {
  873. // true意思:图形在刻度中间
  874. // false意思:图形在刻度之间
  875. alignWithLabel: false,
  876. show: false
  877. },
  878. //文字
  879. axisLabel: {
  880. color: '#4c9bfd'
  881. },
  882. splitLine: {
  883. lineStyle: {
  884. color: 'rgba(0, 240, 255, 0.3)'
  885. }
  886. },
  887. }
  888. ],
  889. // 控制x轴
  890. series: [
  891. {
  892. // series配置
  893. // 颜色
  894. itemStyle: {
  895. // 提供的工具函数生成渐变颜色
  896. color: new echarts.graphic.LinearGradient(
  897. // (x1,y2) 点到点 (x2,y2) 之间进行渐变
  898. 0, 0, 0, 1,
  899. [
  900. { offset: 0, color: '#00fffb' }, // 0 起始颜色
  901. { offset: 1, color: '#0061ce' } // 1 结束颜色
  902. ]
  903. )
  904. },
  905. // 图表数据名称
  906. name: this.$t('wdklScreen.alarmDistribution'),
  907. // 图表类型
  908. type: 'bar',
  909. // 柱子宽度
  910. barWidth: '60%',
  911. // 数据
  912. data: []
  913. }
  914. ]
  915. };
  916. },
  917. // 性别饼图
  918. initPieChar() {
  919. return {
  920. // 控制提示
  921. tooltip: {
  922. trigger: 'item', // 非轴图形,使用item的意思是放到数据对应图形上触发提示
  923. // 格式化提示内容:
  924. // a 代表图表名称 b 代表数据名称 c 代表数据 d代表 当前数据/总数据的比例
  925. formatter: "{a} <br/>{b} : {c} ({d}%)"
  926. },
  927. // 控制图表
  928. series: [
  929. {
  930. // 图表名称
  931. name: this.$t('wdklScreen.ageGroup'),
  932. // 图表类型
  933. type: 'pie',
  934. // 南丁格尔玫瑰图 有两个圆 内圆半径10% 外圆半径70%
  935. // 百分比基于 图表DOM容器的半径
  936. radius: ['10%', '70%'],
  937. // 图表中心位置 left 50% top 50% 距离图表DOM容器
  938. center: ['50%', '50%'],
  939. // 半径模式,另外一种是 area 面积模式
  940. roseType: 'radius',
  941. // 数据集 value 数据的值 name 数据的名称
  942. data: [],
  943. //文字调整
  944. label: {
  945. fontSize: 10
  946. },
  947. //引导线
  948. labelLine: {
  949. length: 8,
  950. length2: 10
  951. }
  952. },
  953. ],
  954. color: ['#006cff', '#60cda0', '#ed8884', '#ff9f7f', '#0096ff', '#9fe6b8', '#32c5e9', '#1d9dff']
  955. };
  956. },
  957. //报警统计折线图
  958. initLineChar() {
  959. return {
  960. tooltip: {
  961. trigger: 'axis'
  962. },
  963. xAxis: {
  964. type: 'category',
  965. data: [],
  966. axisTick: {
  967. show: false
  968. },
  969. axisLabel: {
  970. color: '#4c9bfd',
  971. },
  972. axisLine: {
  973. show: false
  974. },
  975. boundaryGap: false
  976. },
  977. yAxis: {
  978. // 数据作为刻度文字
  979. type: 'value',
  980. axisTick: {
  981. show: false//去除刻度线
  982. },
  983. axisLabel: {
  984. color: '#4c9bfd'//文本颜色
  985. },
  986. axisLine: {
  987. show: false//去除轴线
  988. },
  989. boundaryGap: false//去除轴内间距
  990. },
  991. legend: {
  992. textStyle: {
  993. color: '#4c9bfd' // 图例文字颜色
  994. },
  995. type: 'scroll',
  996. right: '10%'//距离右边10%
  997. },
  998. grid: {
  999. show: true,// 显示边框
  1000. top: '20%',
  1001. left: '3%',
  1002. right: '8%',
  1003. bottom: '3%',
  1004. borderColor: '#012f4a',// 边框颜色
  1005. containLabel: true // 包含刻度文字在内
  1006. },
  1007. series: [{
  1008. data: [], // 数据
  1009. type: 'line', // 图表类型
  1010. smooth: true, // 圆滑连接
  1011. itemStyle: {
  1012. color: '#00f2f1'
  1013. }
  1014. }]
  1015. };
  1016. },
  1017. // 动态测量项365天、90、30、7天测量
  1018. initMeasureItem(data) {
  1019. // console.log('动态测量项365天、90、30、7天测量',data);
  1020. this.measureData = {
  1021. day365: {
  1022. count: data.logCount.year_count + data.logCount.year_err_count,
  1023. errCount: data.logCount.year_err_count
  1024. },
  1025. day90: {
  1026. count: data.logCount.season_count + data.logCount.season_err_count,
  1027. errCount: data.logCount.season_err_count
  1028. },
  1029. day30: {
  1030. count: data.logCount.month_count + data.logCount.month_err_count,
  1031. errCount: data.logCount.month_err_count
  1032. },
  1033. day7: {
  1034. count: data.logCount.week_count + data.logCount.week_err_count,
  1035. errCount: data.logCount.week_err_count
  1036. }
  1037. };
  1038. // 更新初始数据
  1039. this.handleMeasureFilter('day365');
  1040. },
  1041. handleMeasureFilter(key) {
  1042. // console.log('!99989974854',key);
  1043. this.activeTimeFilter = key;
  1044. this.currentMeasureData = this.measureData[key];
  1045. },
  1046. // 报警统计折线图
  1047. initDynamicAlarm(item) {
  1048. this.myLineEchart.resize({ height: document.querySelector('.line').offsetHeight - 10 });
  1049. console.log('!动态报警折线图', item);
  1050. // 先处理周数据的国际化
  1051. if (item.week && item.week[1]) {
  1052. item.week[1] = item.week[1].map(day => {
  1053. return this.$t(`wdklScreen.${day.toLowerCase()}`);
  1054. });
  1055. }
  1056. // 保存数据到 Vue 实例中
  1057. this.chartData = {
  1058. year: item.year,
  1059. month: item.month,
  1060. week: item.week
  1061. };
  1062. // 初始化显示周数据
  1063. this.handleChartTypeChange('week');
  1064. },
  1065. // 添加独立的图表类型切换处理方法
  1066. handleChartTypeChange(type) {
  1067. this.activeAlarmType = type;
  1068. let lineOption = this.initLineChar();
  1069. const key = this.chartData[type];
  1070. // 先清空现有的图表
  1071. this.myLineEchart.clear();
  1072. this.myLineEchart.setOption(lineOption);
  1073. // console.log('2添加独立的图表类型切换处理方法', key);
  1074. if (key && key[0] && key[0].length > 0) {
  1075. key[0].forEach((t, i) => {
  1076. const d = {
  1077. name: this.deviceTypeGetter(Number(key[2][i])),
  1078. // name: key[2][i],
  1079. type: 'line',
  1080. stack: type + '总量' + i,
  1081. data: t,
  1082. smooth: true,
  1083. emphasis: {
  1084. focus: 'series',
  1085. blurScope: 'coordinateSystem'
  1086. },
  1087. itemStyle: {
  1088. color: this.colorList[i]
  1089. }
  1090. };
  1091. lineOption.series.push(d)
  1092. });
  1093. } else {
  1094. const dd = []
  1095. key[1].forEach((t, i) => {
  1096. dd.push('0');
  1097. });
  1098. lineOption.series.push({
  1099. name: '',
  1100. type: 'line',
  1101. stack: type + '总量0',
  1102. data: dd,
  1103. smooth: true,
  1104. emphasis: {
  1105. focus: 'series',
  1106. blurScope: 'coordinateSystem'
  1107. },
  1108. itemStyle: {
  1109. color: '#00f2f1'
  1110. }
  1111. });
  1112. key[2] = [''];
  1113. }
  1114. lineOption.legend.data = key[2].map(item => this.deviceTypeGetter(Number(item)));
  1115. lineOption.xAxis.data = key[1]
  1116. this.myLineEchart.setOption(lineOption);
  1117. },
  1118. // 初始化百度地图
  1119. initMap() {
  1120. return {
  1121. backgroundColor: 'transparent',
  1122. title: {
  1123. text: this.$t('wdklScreen.userMapOverview'),
  1124. left: 'center',
  1125. textStyle: {
  1126. color: '#fff'
  1127. }
  1128. },
  1129. tooltip: {
  1130. trigger: 'item',
  1131. formatter: (params) => {
  1132. return params.data.text;
  1133. }
  1134. },
  1135. bmap: {
  1136. center: [114.25, 30.34],
  1137. zoom: 11,
  1138. roam: true,
  1139. geo: {
  1140. aspectScale: 0.3
  1141. },
  1142. mapStyleV2: {
  1143. styleJson: returnMapStyleJson()
  1144. }
  1145. },
  1146. series: [
  1147. {
  1148. name: '体征告警',
  1149. type: 'effectScatter',
  1150. coordinateSystem: 'bmap',
  1151. data: [],
  1152. symbolSize: (val1, val2) => val2.data.size,
  1153. showEffectOn: 'render',
  1154. rippleEffect: {
  1155. brushType: 'stroke',
  1156. number: 3,
  1157. scale: 5,
  1158. color: '#8FD1C3'
  1159. },
  1160. hoverAnimation: true,
  1161. label: {
  1162. formatter: '{b}',
  1163. position: 'right',
  1164. show: true
  1165. },
  1166. itemStyle: {
  1167. color: '#f37b1d',
  1168. shadowBlur: 10,
  1169. shadowColor: '#333'
  1170. },
  1171. zlevel: 1
  1172. },
  1173. {
  1174. name: '正常体征',
  1175. type: 'scatter',
  1176. coordinateSystem: 'bmap',
  1177. data: [],
  1178. symbolSize: (val1, val2) => val2.data.size,
  1179. label: {
  1180. formatter: '{b}',
  1181. position: 'right'
  1182. },
  1183. itemStyle: {
  1184. color: '#ddb926'
  1185. },
  1186. emphasis: {
  1187. label: {
  1188. show: true
  1189. }
  1190. }
  1191. }
  1192. ]
  1193. };
  1194. },
  1195. // 获取网页链接参数
  1196. getQuery(name) {
  1197. let reg = new RegExp('(^|&)' + name + "=([^&]*)", "i");
  1198. let r = decodeURI(window.location.search.substr(1)).match(reg);
  1199. if (r != null) return r[2]; return null;
  1200. },
  1201. // 用户显示文字
  1202. formatText(item) {
  1203. var str = "";
  1204. if (item.address) {
  1205. str = item.address + "<br/>";
  1206. }
  1207. str += item.nickname + "," + this.formatSex(item.sex) + (item.birthday ? ("," + this.formatAge(item.birthday)) : "");
  1208. return str;
  1209. },
  1210. // SOS显示报警文字
  1211. formatSOSText(item) {
  1212. var str = "";
  1213. if (item.address) {
  1214. str = item.address + "<br/>";
  1215. }
  1216. str += item.named + "," + this.formatSex(item.sex);
  1217. if (item.birthday) {
  1218. str += "," + formatAge(item.birthday);
  1219. }
  1220. str += "<br/>";
  1221. str += "报警内容:" + item.data + "<br/>";
  1222. if (item.relativeMobile) {
  1223. str += "联系亲属:" + item.relativeMobile + "<br/>";
  1224. }
  1225. if (item.sOSLngLat) {
  1226. str += "报警位置:" + item.sOSLngLat;
  1227. }
  1228. return str;
  1229. },
  1230. // 时间转换
  1231. unixToDate(unix, format) {
  1232. if (!unix) return unix
  1233. var _format = format || 'yyyy-MM-dd hh:mm:ss'
  1234. const d = new Date(unix * 1000)
  1235. const o = {
  1236. 'M+': d.getMonth() + 1,
  1237. 'd+': d.getDate(),
  1238. 'h+': d.getHours(),
  1239. 'm+': d.getMinutes(),
  1240. 's+': d.getSeconds(),
  1241. 'q+': Math.floor((d.getMonth() + 3) / 3),
  1242. S: d.getMilliseconds()
  1243. }
  1244. if (/(y+)/.test(_format)) _format = _format.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length))
  1245. for (const k in o) if (new RegExp('(' + k + ')').test(_format)) _format = _format.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
  1246. return _format
  1247. },
  1248. // 性别转换
  1249. formatSex(sex) {
  1250. return sex === 1 ? '男' : sex === 0 ? '女' : '未知'
  1251. },
  1252. // 生日转换
  1253. formatAge(birthday) {
  1254. const data = this.formatBirthdayToAge(birthday * 1000)
  1255. return data.age + data.ageunit
  1256. },
  1257. // 将生日转换成年龄
  1258. formatBirthdayToAge(birthday) {
  1259. const birth = new Date(birthday)
  1260. const birthYear = birth.getFullYear() // 出生年
  1261. const birthMonth = birth.getMonth() + 1 // 出生月
  1262. const birthDay = birth.getDate() // 出生日
  1263. const nowYear = new Date().getFullYear() // 出生年
  1264. const nowMonth = new Date().getMonth() + 1 // 出生月
  1265. const nowDay = new Date().getDate() // 出生日
  1266. if (nowYear === birthYear) { // 同年
  1267. if (nowMonth === birthMonth) { // 同月
  1268. return {
  1269. age: nowDay - birthDay,
  1270. ageunit: '天'
  1271. }
  1272. } else {
  1273. return {
  1274. age: nowMonth - birthMonth,
  1275. ageunit: '月'
  1276. }
  1277. }
  1278. } else { // 计算周岁
  1279. const ageDiff = nowYear - birthYear // 年之差
  1280. if (ageDiff > 0) {
  1281. if (nowMonth === birthMonth) { // 同月
  1282. const dayDiff = nowDay - birthDay// 日之差
  1283. if (dayDiff < 0) {
  1284. return {
  1285. age: ageDiff - 1,
  1286. ageunit: '岁'
  1287. }
  1288. } else {
  1289. return {
  1290. age: ageDiff,
  1291. ageunit: '岁'
  1292. }
  1293. }
  1294. } else {
  1295. const monthDiff = nowMonth - birthMonth // 月之差
  1296. if (monthDiff < 0) {
  1297. return {
  1298. age: ageDiff - 1,
  1299. ageunit: '岁'
  1300. }
  1301. } else {
  1302. return {
  1303. age: ageDiff,
  1304. ageunit: '岁'
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. },
  1312. }
  1313. )
  1314. </script>
  1315. <script src="./js/mymap.js"></script>
  1316. </html>