index.js 27 KB

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