index.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. const host_port = "119.23.151.229:8006/";
  2. const url = "http://" + host_port;
  3. // const url = "http://127.0.0.1:8006/";
  4. var myPieEchart = echarts.init($('.pie')[0]); // 饼图
  5. var myLineEchart = echarts.init($('.line')[0]); // 折线图
  6. var myBarEchart = echarts.init($('.users .bar')[0]); // 柱状图
  7. var myMapChart = echarts.init($('.map .geo')[0]); // 地图
  8. var mapOption; // 地图参数
  9. var heartbeatTime, breakTime, showTime; // 定时任务
  10. var partId; // 机构id
  11. var colorList = ['#00f2f1','#006cff', '#eab408', '#ed8884', '#ff9f7f', '#0096ff', '#9fe6b8', '#32c5e9', '#1d9dff'];
  12. /*大屏*/
  13. //自调用函数
  14. (function () {
  15. // 1、页面一加载就要知道页面宽度计算
  16. var setFont = function () {
  17. // 因为要定义变量可能和别的变量相互冲突,污染,所有用自调用函数
  18. var html = document.documentElement;// 获取html
  19. // 获取宽度
  20. var width = html.clientWidth;
  21. // 判断
  22. if (width < 1024) width = 1024
  23. if (width > 1920) width = 1920
  24. // 设置html的基准值
  25. var fontSize = width / 80 + 'px';
  26. // 设置给html
  27. html.style.fontSize = fontSize;
  28. }
  29. setFont();
  30. $(".geo").height($(".map").height());
  31. // 2、页面改变的时候也需要设置
  32. // 尺寸改变事件
  33. window.onresize = function () {
  34. setFont();
  35. $(".geo").height($(".map").height());
  36. }
  37. //时间
  38. // $('.clock').FlipClock({
  39. // clockFace: 'TwentyFourHourClock'
  40. // });
  41. })();
  42. // 请求后台获取数据
  43. (function () {
  44. partId = getQuery("partId");
  45. if (partId) {
  46. // 连接webSocket
  47. initWebSocket();
  48. // 打开定时器
  49. openTimer();
  50. let image = document.getElementById('muteImg');
  51. image.addEventListener('click', function () {
  52. image.style.display = "none";
  53. })
  54. }
  55. })();
  56. // 获取看板用户信息
  57. function getUserInfo() {
  58. $.get(url + "bulletinBoard/user_info/" + partId, function (data, status) {
  59. console.log(data.partInfo.shop_name);
  60. $(".title").text(data.partInfo.shop_name);
  61. $("#allCount").text(data.userCount.all_count); // 总用户
  62. $("#quarterly-addition").text(data.userCount.quarterly_count); // 季度新增
  63. $("#monthly-addition").text(data.userCount.month_count); // 月度新增
  64. $("#manCount").text(data.userCount.man_count ? data.userCount.man_count : 0); // 男生人数
  65. $("#womanCount").text(data.userCount.woman_count ? data.userCount.woman_count : 0); // 女生人数
  66. // 地图人员分布
  67. mapOption = initMap();
  68. if (data.memberList.length > 0) {
  69. var d = []
  70. data.memberList.forEach((item, index) => {
  71. d.push({
  72. name: item.nickname,
  73. value: item.lng_lat.split(","),
  74. size: 10,
  75. text: formatText(item),
  76. })
  77. })
  78. mapOption.series[1].data = d;
  79. // mapOption.bmap.center = [114.08259, 22.356868]; // 114.08259, 22.556868
  80. mapOption.bmap.center = d[0].value; // 114.08259, 22.556868
  81. mapOption.bmap.zoom = 16;
  82. }
  83. myMapChart.setOption(mapOption);
  84. window.addEventListener('resize', myMapChart.resize);
  85. // 年龄段饼图
  86. var pieOption = initPieChar();
  87. pieOption.series[0].data = data.pieData;
  88. myPieEchart.setOption(pieOption);
  89. });
  90. }
  91. // 获取看板事件报警信息
  92. function getSOSInfo() {
  93. $.get(url + "bulletinBoard/sos_info/" + partId, function (data, status) {
  94. // 最新事件报警表格
  95. var rows = []
  96. $.each(data.actionList, function (i, n) {
  97. var name = '';
  98. if (n.from_member_name == null || n.from_member_name === "") {
  99. name = n.from_frame_name;
  100. } else {
  101. name = n.from_member_name;
  102. }
  103. var row = '<div class="row">\n' +
  104. '<span class="col">'+unixToDate(n.create_date, "MM-dd hh:mm")+'</span>\n' +
  105. '<span class="col">'+name+'</span>\n' +
  106. '<span class="col">'+n.from_device_name+'</span>\n' +
  107. '<span class="icon-dot"></span>\n' +
  108. '</div>';
  109. rows.push(row)
  110. });
  111. $("#vsLogTable").html(rows.join(''))
  112. // 报警分布
  113. var xData = [], yData = [];
  114. data.barList.forEach((item, index) => {
  115. xData.push(item.name)
  116. yData.push(item.value)
  117. })
  118. var barOption = initBarChar();
  119. barOption.xAxis[0].data = xData;
  120. barOption.series[0].data = yData;
  121. myBarEchart.setOption(barOption);
  122. // 动态报警折线图
  123. initDynamicAlarm(data);
  124. });
  125. }
  126. // 获取看板体征信息
  127. function getLogInfo() {
  128. $.get(url + "bulletinBoard/log_info/" + partId, function (data, status) {
  129. $("#dayCount").text(data.logCount.day_count); // 今日测量数
  130. $("#hourCount").text(data.logCount.hour_count); // 近1小时测量数
  131. // 动态测量项
  132. initMeasureItem(data);
  133. // 体征报警表格
  134. var rows = []
  135. $.each(data.errVsLogList, function (i, n) {
  136. var row = '<div class="row">\n' +
  137. '<span class="col">'+unixToDate(n.log_time, "MM-dd hh:mm")+'</span>\n' +
  138. '<span class="col">'+n.member_nickname+'</span>\n' +
  139. '<span class="col">'+n.param_name+'</span>\n' +
  140. '<span class="col">'+n.vs_value+'</span>\n' +
  141. '<span class="icon-dot"></span>\n' +
  142. '</div>';
  143. rows.push(row)
  144. });
  145. $("#errVsLogTable").html(rows.join(''))
  146. // $.each(data.errVsLogList, function (i, n) {
  147. // var row = $("#errVsLogTemplate").clone();
  148. // row.find(".errVsLogTime").text(unixToDate(n.log_time, "MM-dd hh:mm"));
  149. // row.find(".errVsLogUser").text(n.member_nickname);
  150. // row.find(".errVsLogItem").text(n.param_name);
  151. // row.find(".errVsLogValue").text(n.vs_value);
  152. // row.appendTo("#errVsLogTable");
  153. // });
  154. });
  155. }
  156. function initWebSocket() {
  157. var time = Math.round(new Date()) + "" + Math.round(Math.random()*100);
  158. console.log(time)
  159. // var s = "ws://127.0.0.1:8006/bulletinBoard/" + time + "/" + partId;
  160. var s = "ws://" + host_port + "bulletinBoard/" + time + "/" + partId;
  161. console.log(s)
  162. var ws = new WebSocket(s);
  163. ws.onopen = function(evt) {
  164. console.log("webSocket连接成功 ...");
  165. clearInterval(breakTime);
  166. breakTime = null;
  167. heartbeatTime = setInterval(function () {
  168. ws.send("ping");
  169. }, 55000); // 55秒心跳包
  170. // 获取看板用户信息
  171. getUserInfo();
  172. // 获取看板事件报警信息
  173. getSOSInfo();
  174. // 获取看板体征信息
  175. getLogInfo();
  176. };
  177. ws.onmessage = function(e) {
  178. console.log("收到消息: " + e.data);
  179. if (e.data === 'pong') {
  180. return
  181. }
  182. // {"address":"广东省深圳市南山区留仙大道大学城创客小镇","ageUnit":"岁","birthday":-189417600,"createTime":1661990011,"data":"15秒红外报警",
  183. // "frameId":1155,"id":457,"lngLat":"113.961957,22.579848","memberId":54658,"mobile":"18174091244","named":"小米面","partId":2,
  184. // "renewType":"SOS","sex":1,"status":0}
  185. const data = JSON.parse(e.data);
  186. if (data.renewType === 'SOS') {
  187. console.log('有人报警...')
  188. let mp3 = new Audio('./music/sos.mp3')
  189. mp3.loop = false
  190. mp3.play()
  191. openSOSMap(data); // 地图高亮
  192. getSOSInfo(); // 刷新看板
  193. } else if ("LOG") {
  194. console.log('体征异常...')
  195. openSOSMap(data); // 地图高亮
  196. getLogInfo(); // 刷新体征
  197. } else { // USER
  198. getUserInfo(); // 刷新用户
  199. }
  200. };
  201. ws.onclose = function(evt) {
  202. console.log("webSocket连接关闭.", breakTime);
  203. if (!breakTime) {
  204. console.log('新的定时任务....')
  205. clearInterval(heartbeatTime);
  206. breakTime = setInterval(function () {
  207. console.log('正在重连...')
  208. initWebSocket();
  209. }, 5000); // 5秒重连一次
  210. }
  211. // heartbeatTime.
  212. };
  213. }
  214. // 地图高亮
  215. function openSOSMap(data) {
  216. if (data.lngLat) {
  217. var d = []
  218. d.push({
  219. name: data.named,
  220. value: data.lngLat.split(","),
  221. size: 20,
  222. text: formatSOSText(data),
  223. })
  224. mapOption.series[0].data = d;
  225. mapOption.bmap.center = d[0].value;
  226. mapOption.bmap.zoom = 18;
  227. myMapChart.setOption(mapOption);
  228. myMapChart.dispatchAction({
  229. type: 'showTip',
  230. seriesIndex: 0,
  231. dataIndex: 0
  232. });
  233. clearTimeout(showTime);
  234. showTime = setTimeout(clearSOSMap, 15000);
  235. }
  236. }
  237. // 清除百度地图报警点
  238. function clearSOSMap() {
  239. console.log("我要清除报警高亮点了", mapOption.series[0].data, mapOption.series[1].data[0].value)
  240. mapOption.series[0].data = [];
  241. mapOption.bmap.center = mapOption.series[1].data[0].value;
  242. mapOption.bmap.zoom = 16;
  243. myMapChart.setOption(mapOption);
  244. }
  245. // 打开定时器
  246. function openTimer() {
  247. // 测量时间段定时器
  248. var i = 0, ii = 0;
  249. var aclick = $('.order a');
  250. setInterval(function () {
  251. i++;
  252. if (i > 3) {
  253. i = 0;
  254. }
  255. //每3秒调用点击事件
  256. aclick.eq(i).click();
  257. }, 3000);
  258. // 报警统计折线图定时器
  259. setInterval(function () {
  260. ii++;
  261. if (ii > 4) {
  262. ii = 0;
  263. }
  264. $('.alarms .caption a').eq(ii).click();
  265. }, 5000);
  266. }
  267. (function () {
  268. //事件委托
  269. $('.monitor').on('click', ' a', function () {
  270. //点击当前的a 加类名 active 他的兄弟删除类名
  271. $(this).addClass('active').siblings().removeClass('active');
  272. //获取一一对应的下标
  273. var index = $(this).index();
  274. //选取content 然后对应下标的 显示 当前的兄弟.content隐藏
  275. $('.content').eq(index).show().siblings('.content').hide();
  276. });
  277. //滚动
  278. //原理:把marquee下面的子盒子都复制一遍 加入到marquee中
  279. // 然后动画向上滚动,滚动到一半重新开始滚动
  280. //因为选取的是两个marquee 所以要遍历
  281. $('.monitor .marquee').each(function (index, dom) {
  282. //将每个 的所有子级都复制一遍
  283. var rows = $(dom).children().clone();
  284. //再将新的到的加入原来的
  285. $(dom).append(rows);
  286. });
  287. })();
  288. // 报警分布柱状图
  289. function initBarChar() {
  290. return {
  291. // 工具提示
  292. tooltip: {
  293. // 触发类型 经过轴触发axis 经过轴触发item
  294. trigger: 'item',
  295. // 轴触发提示才有效
  296. axisPointer: {
  297. // 默认为直线,可选为:'line' 线效果 | 'shadow' 阴影效果
  298. type: 'shadow'
  299. }
  300. },
  301. // 图表边界控制
  302. grid: {
  303. // 距离 上右下左 的距离
  304. left: '0',
  305. right: '3%',
  306. bottom: '3%',
  307. top: '5%',
  308. // 大小是否包含文本【类似于boxsizing】
  309. containLabel: true,
  310. //显示边框
  311. show: true,
  312. //边框颜色
  313. borderColor: 'rgba(0, 240, 255, 0.3)'
  314. },
  315. // 控制x轴
  316. xAxis: [
  317. {
  318. // 使用类目,必须有data属性
  319. type: 'category',
  320. // 使用 data 中的数据设为刻度文字
  321. data: [],
  322. // 刻度设置
  323. axisTick: {
  324. // true意思:图形在刻度中间
  325. // false意思:图形在刻度之间
  326. alignWithLabel: false,
  327. show: false
  328. },
  329. //文字
  330. axisLabel: {
  331. color: '#4c9bfd'
  332. }
  333. }
  334. ],
  335. // 控制y轴
  336. yAxis: [
  337. {
  338. // 使用数据的值设为刻度文字
  339. type: 'value',
  340. axisTick: {
  341. // true意思:图形在刻度中间
  342. // false意思:图形在刻度之间
  343. alignWithLabel: false,
  344. show: false
  345. },
  346. //文字
  347. axisLabel: {
  348. color: '#4c9bfd'
  349. },
  350. splitLine: {
  351. lineStyle: {
  352. color: 'rgba(0, 240, 255, 0.3)'
  353. }
  354. },
  355. }
  356. ],
  357. // 控制x轴
  358. series: [
  359. {
  360. // series配置
  361. // 颜色
  362. itemStyle: {
  363. // 提供的工具函数生成渐变颜色
  364. color: new echarts.graphic.LinearGradient(
  365. // (x1,y2) 点到点 (x2,y2) 之间进行渐变
  366. 0, 0, 0, 1,
  367. [
  368. {offset: 0, color: '#00fffb'}, // 0 起始颜色
  369. {offset: 1, color: '#0061ce'} // 1 结束颜色
  370. ]
  371. )
  372. },
  373. // 图表数据名称
  374. name: '报警分布',
  375. // 图表类型
  376. type: 'bar',
  377. // 柱子宽度
  378. barWidth: '60%',
  379. // 数据
  380. data: []
  381. }
  382. ]
  383. };
  384. }
  385. // 性别饼图
  386. function initPieChar() {
  387. return {
  388. // 控制提示
  389. tooltip: {
  390. // 非轴图形,使用item的意思是放到数据对应图形上触发提示
  391. trigger: 'item',
  392. // 格式化提示内容:
  393. // a 代表图表名称 b 代表数据名称 c 代表数据 d代表 当前数据/总数据的比例
  394. formatter: "{a} <br/>{b} : {c} ({d}%)"
  395. },
  396. // 控制图表
  397. series: [
  398. {
  399. // 图表名称
  400. name: '年龄段',
  401. // 图表类型
  402. type: 'pie',
  403. // 南丁格尔玫瑰图 有两个圆 内圆半径10% 外圆半径70%
  404. // 百分比基于 图表DOM容器的半径
  405. radius: ['10%', '70%'],
  406. // 图表中心位置 left 50% top 50% 距离图表DOM容器
  407. center: ['50%', '50%'],
  408. // 半径模式,另外一种是 area 面积模式
  409. roseType: 'radius',
  410. // 数据集 value 数据的值 name 数据的名称
  411. data: [],
  412. //文字调整
  413. label: {
  414. fontSize: 10
  415. },
  416. //引导线
  417. labelLine: {
  418. length: 8,
  419. length2: 10
  420. }
  421. },
  422. ],
  423. color: ['#006cff', '#60cda0', '#ed8884', '#ff9f7f', '#0096ff', '#9fe6b8', '#32c5e9', '#1d9dff']
  424. };
  425. }
  426. // 报警统计折线图
  427. function initLineChar() {
  428. return {
  429. //鼠标提示工具
  430. tooltip: {
  431. trigger: 'axis'
  432. },
  433. xAxis: {
  434. // 类目类型
  435. type: 'category',
  436. // x轴刻度文字
  437. data: [],
  438. axisTick: {
  439. show: false//去除刻度线
  440. },
  441. axisLabel: {
  442. color: '#4c9bfd'//文本颜色
  443. },
  444. axisLine: {
  445. show: false//去除轴线
  446. },
  447. boundaryGap: false//去除轴内间距
  448. },
  449. yAxis: {
  450. // 数据作为刻度文字
  451. type: 'value',
  452. axisTick: {
  453. show: false//去除刻度线
  454. },
  455. axisLabel: {
  456. color: '#4c9bfd'//文本颜色
  457. },
  458. axisLine: {
  459. show: false//去除轴线
  460. },
  461. boundaryGap: false//去除轴内间距
  462. },
  463. //图例组件
  464. legend: {
  465. textStyle: {
  466. color: '#4c9bfd' // 图例文字颜色
  467. },
  468. type: 'scroll',
  469. right: '10%'//距离右边10%
  470. },
  471. // 设置网格样式
  472. grid: {
  473. show: true,// 显示边框
  474. top: '20%',
  475. left: '3%',
  476. right: '4%',
  477. bottom: '3%',
  478. borderColor: '#012f4a',// 边框颜色
  479. containLabel: true // 包含刻度文字在内
  480. },
  481. series: [{
  482. // 数据
  483. data: [],
  484. // 图表类型
  485. type: 'line',
  486. // 圆滑连接
  487. smooth: true,
  488. itemStyle: {
  489. color: '#00f2f1' // 线颜色
  490. }
  491. }]
  492. };
  493. }
  494. // 动态测量项
  495. function initMeasureItem(data) {
  496. // 365天、90、30、7天测量
  497. var item = {
  498. day365: {
  499. count: data.logCount.year_count + data.logCount.year_err_count,
  500. errCount: data.logCount.year_err_count
  501. },
  502. day90: {
  503. count: data.logCount.season_count + data.logCount.season_err_count,
  504. errCount: data.logCount.season_err_count
  505. },
  506. day30: {
  507. count: data.logCount.month_count + data.logCount.month_err_count,
  508. errCount: data.logCount.month_err_count
  509. },
  510. day7: {
  511. count: data.logCount.week_count + data.logCount.week_err_count,
  512. errCount: data.logCount.week_err_count
  513. }
  514. };
  515. $('.order .item h4:eq(0)').text(item.day365.count);
  516. $('.order .item h4:eq(1)').text(item.day365.errCount);
  517. // 点击事件
  518. $('.order').on('click', '.filter a', function () {
  519. //点击之后加类名
  520. $(this).addClass('active').siblings().removeClass('active');
  521. // 先获取点击a的 data-key自定义属性
  522. var key = $(this).attr('data-key');
  523. key = item[key];
  524. $('.order .item h4:eq(0)').text(key.count);
  525. $('.order .item h4:eq(1)').text(key.errCount);
  526. });
  527. }
  528. // 动态报警折线图
  529. function initDynamicAlarm(item) {
  530. myLineEchart.resize({ height: $('.line').height() - 10 })
  531. var lineOption = initLineChar();
  532. lineOption.series = [];
  533. if (item.week[0].length > 0) {
  534. item.week[0].forEach((t, i) => {
  535. var d = {
  536. name: item.week[2][i],
  537. type: 'line',
  538. stack: 'year总量' + i,
  539. data: t,
  540. smooth: true,
  541. emphasis: {
  542. focus: 'series',
  543. blurScope: 'coordinateSystem'
  544. },
  545. itemStyle: {
  546. color: colorList[i] // 线颜色
  547. }
  548. };
  549. lineOption.series.push(d);
  550. });
  551. }
  552. // lineOption.series[0].data = item.year[0];
  553. lineOption.legend.data = item.week[2];
  554. lineOption.xAxis.data = item.week[1];
  555. var data = {
  556. year: item.year,
  557. month: item.month,
  558. week: item.week
  559. };
  560. myLineEchart.setOption(lineOption);
  561. $('.alarms ').on('click', '.caption a', function () {
  562. $(this).addClass('active').siblings('a').removeClass('active');
  563. lineOption = initLineChar();
  564. //option series data
  565. //获取自定义属性值
  566. var k = $(this).attr('data-type');
  567. //取出对应的值
  568. var key = data[k];
  569. //将值设置到 图表中
  570. if (key[0].length > 0) {
  571. if (k === 'week') {
  572. lineOption = initLineChar();
  573. myLineEchart.setOption(lineOption);
  574. }
  575. key[0].forEach((t, i) => {
  576. var d = {
  577. name: key[2][i],
  578. type: 'line',
  579. stack: k + '总量' + i,
  580. data: t,
  581. smooth: true,
  582. emphasis: {
  583. focus: 'series',
  584. blurScope: 'coordinateSystem'
  585. },
  586. itemStyle: {
  587. color: colorList[i] // 线颜色
  588. }
  589. }
  590. lineOption.series.push(d);
  591. })
  592. // lineOption.series[0].data = key[0];
  593. } else {
  594. var dd = [];
  595. key[1].forEach((t, i) => {
  596. dd.push('0');
  597. });
  598. lineOption.series.push({
  599. name: '',
  600. type: 'line',
  601. stack: k + '总量0',
  602. data: dd,
  603. smooth: true,
  604. emphasis: {
  605. focus: 'series',
  606. blurScope: 'coordinateSystem'
  607. },
  608. itemStyle: {
  609. color: '#00f2f1' // 线颜色
  610. }
  611. });
  612. key[2] = [''];
  613. }
  614. lineOption.legend.data = key[2];
  615. // 坐标修改
  616. lineOption.xAxis.data = key[1];
  617. //再次调用才能在页面显示
  618. myLineEchart.setOption(lineOption);
  619. });
  620. }
  621. // 初始化百度地图
  622. function initMap() {
  623. return {
  624. backgroundColor: 'transparent',
  625. title: {
  626. text: '用户地图一览',
  627. left: 'center',
  628. textStyle: {
  629. color: '#fff'
  630. }
  631. },
  632. tooltip: {
  633. trigger: 'item',
  634. formatter: function (params) {
  635. //console.log(params);
  636. return params.data.text
  637. }
  638. },
  639. bmap: {
  640. center: [114.25, 30.34], //地图中心点
  641. zoom: 11, //默认缩放倍数
  642. roam: true, //禁止放大缩小
  643. geo: {
  644. aspectScale: 0.3
  645. },
  646. mapStyleV2: {
  647. styleJson: returnMapStyleJson()
  648. }
  649. },
  650. series: [
  651. {
  652. name: '体征告警',
  653. type: 'effectScatter', //气泡动态效果
  654. coordinateSystem: 'bmap', // 地图选择项bmap为百度地图
  655. data: [],
  656. symbolSize: function (val1, val2) {
  657. // console.log(val1,val2)
  658. return val2.data.size;
  659. }, //标记大小
  660. showEffectOn: 'render', // 配置何时显示特效。 render 绘制完成后显示特效。emphasis 高亮(hover)的时候显示特效。
  661. rippleEffect: {
  662. brushType: 'stroke', // 波纹的绘制方式 stroke 和 fill
  663. number: 3, // 波纹的数量
  664. scale: 5, // 波纹放大的倍数
  665. color: '#8FD1C3'
  666. },
  667. hoverAnimation: true,
  668. label: {
  669. formatter: '{b}',
  670. position: 'right',
  671. show: true
  672. },
  673. itemStyle: {
  674. color: '#f37b1d',
  675. shadowBlur: 10,
  676. shadowColor: '#333'
  677. },
  678. zlevel: 1
  679. },
  680. {
  681. name: '正常体征',
  682. type: 'scatter', //气泡静态效果
  683. coordinateSystem: 'bmap',
  684. data: [],
  685. symbolSize: function (val1, val2) {
  686. return val2.data.size;
  687. }, //标记的大小
  688. label: {
  689. formatter: '{b}',
  690. position: 'right'
  691. },
  692. itemStyle: {
  693. color: '#ddb926'
  694. },
  695. emphasis: { // 高亮的图形和标签样式
  696. label: {
  697. show: true
  698. }
  699. }
  700. }
  701. ]
  702. };
  703. }
  704. // 获取网页链接参数
  705. function getQuery(name){
  706. let reg = new RegExp('(^|&)'+ name + "=([^&]*)", "i");
  707. let r = decodeURI(window.location.search.substr(1)).match(reg);
  708. if(r!=null) return r[2]; return null;
  709. }
  710. // 用户显示文字
  711. function formatText(item) {
  712. var str = "";
  713. if (item.address) {
  714. str = item.address + "<br/>";
  715. }
  716. str += item.nickname + "," + formatSex(item.sex) + (item.birthday ? ("," + formatAge(item.birthday)) : "");
  717. return str;
  718. }
  719. // SOS显示报警文字
  720. function formatSOSText(item) {
  721. var str = "";
  722. if (item.address) {
  723. str = item.address + "<br/>";
  724. }
  725. str += item.named + "," + formatSex(item.sex);
  726. if (item.birthday) {
  727. str += "," + formatAge(item.birthday);
  728. }
  729. str += "<br/>";
  730. str += "报警内容:" + item.data + "<br/>";
  731. if (item.relativeMobile) {
  732. str += "联系亲属:" + item.relativeMobile + "<br/>";
  733. }
  734. if (item.sOSLngLat) {
  735. str += "报警位置:" + item.sOSLngLat;
  736. }
  737. return str;
  738. }
  739. // 时间转换
  740. function unixToDate(unix, format) {
  741. if (!unix) return unix
  742. var _format = format || 'yyyy-MM-dd hh:mm:ss'
  743. const d = new Date(unix * 1000)
  744. const o = {
  745. 'M+': d.getMonth() + 1,
  746. 'd+': d.getDate(),
  747. 'h+': d.getHours(),
  748. 'm+': d.getMinutes(),
  749. 's+': d.getSeconds(),
  750. 'q+': Math.floor((d.getMonth() + 3) / 3),
  751. S: d.getMilliseconds()
  752. }
  753. if (/(y+)/.test(_format)) _format = _format.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length))
  754. 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)))
  755. return _format
  756. }
  757. // 性别转换
  758. function formatSex(sex) {
  759. return sex === 1 ? '男' : sex === 0 ? '女' : '未知'
  760. }
  761. // 生日转换
  762. function formatAge(birthday) {
  763. const data = formatBirthdayToAge(birthday * 1000)
  764. return data.age + data.ageunit
  765. }
  766. // 将生日转换成年龄
  767. function formatBirthdayToAge(birthday) {
  768. const birth = new Date(birthday)
  769. const birthYear = birth.getFullYear() // 出生年
  770. const birthMonth = birth.getMonth() + 1 // 出生月
  771. const birthDay = birth.getDate() // 出生日
  772. const nowYear = new Date().getFullYear() // 出生年
  773. const nowMonth = new Date().getMonth() + 1 // 出生月
  774. const nowDay = new Date().getDate() // 出生日
  775. if (nowYear === birthYear) { // 同年
  776. if (nowMonth === birthMonth) { // 同月
  777. return {
  778. age: nowDay - birthDay,
  779. ageunit: '天'
  780. }
  781. } else {
  782. return {
  783. age: nowMonth - birthMonth,
  784. ageunit: '月'
  785. }
  786. }
  787. } else { // 计算周岁
  788. const ageDiff = nowYear - birthYear // 年之差
  789. if (ageDiff > 0) {
  790. if (nowMonth === birthMonth) { // 同月
  791. const dayDiff = nowDay - birthDay// 日之差
  792. if (dayDiff < 0) {
  793. return {
  794. age: ageDiff - 1,
  795. ageunit: '岁'
  796. }
  797. } else {
  798. return {
  799. age: ageDiff,
  800. ageunit: '岁'
  801. }
  802. }
  803. } else {
  804. const monthDiff = nowMonth - birthMonth // 月之差
  805. if (monthDiff < 0) {
  806. return {
  807. age: ageDiff - 1,
  808. ageunit: '岁'
  809. }
  810. } else {
  811. return {
  812. age: ageDiff,
  813. ageunit: '岁'
  814. }
  815. }
  816. }
  817. }
  818. }
  819. }