index.js 27 KB

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