index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. //自调用函数
  2. (function() {
  3. // 1、页面一加载就要知道页面宽度计算
  4. var setFont = function() {
  5. // 因为要定义变量可能和别的变量相互冲突,污染,所有用自调用函数
  6. var html = document.documentElement; // 获取html
  7. // 获取宽度
  8. var width = html.clientWidth;
  9. // 判断
  10. if (width < 1024) width = 1024
  11. if (width > 1920) width = 1920
  12. // 设置html的基准值
  13. var fontSize = width / 80 + 'px';
  14. // 设置给html
  15. html.style.fontSize = fontSize;
  16. }
  17. setFont();
  18. // 2、页面改变的时候也需要设置
  19. // 尺寸改变事件
  20. window.onresize = function() {
  21. setFont();
  22. }
  23. })();
  24. $.get('https://linggong.jinjianghc.com/mainapp.php/screen/index', (res) => {
  25. init(res.data)
  26. })
  27. function init(data) {
  28. $('.broker_total').text(data.broker_total);
  29. $('.comjobs_total').text(data.comjobs_total);
  30. $('.company_total').text(data.company_total);
  31. $('.people_man').text(data.people_man);
  32. $('.people_total').text(data.people_total);
  33. $('.people_woman').text(data.people_woman);
  34. $('.train').text(data.train);
  35. $('.train_join').text(data.train_join);
  36. this.geo(data);
  37. this.monitor(data);
  38. this.pie(data);
  39. this.user(data);
  40. this.order(data);
  41. this.sale(data);
  42. this.gauge(data);
  43. this.province(data);
  44. }
  45. function geo(data) {
  46. let community = data.community;
  47. let other = 0;
  48. let max = 0; //最大人数
  49. community = community.map((item) => {
  50. if (item.name == '其他') {
  51. other += item.count;
  52. } else if (item.count > max) {
  53. max = item.count;
  54. }
  55. return {
  56. name: item.name,
  57. value: item.count
  58. };
  59. });
  60. community.push({
  61. name: '泉州出口加工区',
  62. value: 0
  63. });
  64. community.push({
  65. name: '安平开发区',
  66. value: 0
  67. });
  68. var myecharts = echarts.init($('.map .geo')[0])
  69. // $.get('https://geo.datav.aliyun.com/areas_v3/bound/350582.json', result => {
  70. $.get('js/350582.json', result => {
  71. // 注册 echarts 地图
  72. echarts.registerMap('jinjiang', result);
  73. var option = {
  74. backgroundColor: '#080a20',
  75. title: {
  76. text: '其他地区:' + other + ' (人)',
  77. // subtext: '其他地区:' + community[community.length - 1].count,
  78. left: 'left',
  79. textStyle: {
  80. color: '#ffffff'
  81. }
  82. },
  83. tooltip: {
  84. trigger: 'item',
  85. formatter: '{b}<br/>{c} (人)'
  86. },
  87. visualMap: {
  88. min: 0,
  89. max: max,
  90. text: ['多', '少'],
  91. realtime: true,
  92. calculable: true,
  93. color: '#fff',
  94. inRange: {
  95. color: ['#142957', '#0b1c2d']
  96. },
  97. textStyle: {
  98. color: '#fff'
  99. }
  100. },
  101. series: [{
  102. type: 'map',
  103. map: 'jinjiang',
  104. zoom: 1.2,
  105. roam: true,
  106. coordinateSystem: 'geo',
  107. // rippleEffect: {
  108. // brushType: 'stroke'
  109. // },
  110. symbolSize: function(val, params) {
  111. return 8;
  112. },
  113. label: {
  114. show: true,
  115. color: '#fff'
  116. },
  117. itemStyle: {
  118. normal: {
  119. areaColor: '#142957',
  120. borderColor: '#0692a4'
  121. }
  122. },
  123. emphasis: {
  124. areaColor: '#0b1c2d'
  125. },
  126. data: community,
  127. nameMap: {
  128. '晋江市经济开发区': '经济开发区'
  129. }
  130. }]
  131. };
  132. myecharts.setOption(option);
  133. })
  134. }
  135. function monitor(data) {
  136. //事件委托
  137. // $('.monitor').on('click', ' a', function () {
  138. // //点击当前的a 加类名 active 他的兄弟删除类名
  139. // $(this).addClass('active').siblings().removeClass('active');
  140. // //获取一一对应的下标
  141. // var index = $(this).index();
  142. // //选取content 然后狗日对应下标的 显示 当前的兄弟.content隐藏
  143. // $('.content').eq(index).show().siblings('.content').hide();
  144. // });
  145. //填充数据
  146. let comjobs = data.comjobs;
  147. var html = '';
  148. comjobs.forEach(function(item) {
  149. html += `<div class="row">`;
  150. html += `<span class="col">${item.title}</span>`;
  151. html += `<span class="col">${item.company}</span>`;
  152. html += `<span class="col">${item.salary || '面谈'}</span>`;
  153. html += `<span class="icon-dot"></span>`;
  154. html += `</div>`;
  155. });
  156. //渲染
  157. $('.monitor .marquee').html(html);
  158. //滚动
  159. //原理:把marquee下面的子盒子都复制一遍 加入到marquee中
  160. // 然后动画向上滚动,滚动到一半重新开始滚动
  161. //因为选取的是两个marquee 所以要遍历
  162. // $('.monitor .marquee').each(function (index, dom) {
  163. // //将每个 的所有子级都复制一遍
  164. // var rows = $(dom).children().clone();
  165. // //再将新的到的加入原来的
  166. // $(dom).append(rows);
  167. // });
  168. }
  169. function pie(data) {
  170. let eduction = data.eduction;
  171. let unknown = 0;
  172. let total = 0;
  173. eduction.map((item, index) => {
  174. if (item.name == '未知') {
  175. unknown += item.count;
  176. eduction.splice(index, 1);
  177. } else {
  178. total += item.count;
  179. item.value = item.count;
  180. }
  181. return item;
  182. });
  183. $('.edu-unknown').text(unknown);
  184. $('.edu-total').text(total);
  185. var myechart = echarts.init($('.pie')[0]);
  186. option = {
  187. // 控制提示
  188. tooltip: {
  189. // 非轴图形,使用item的意思是放到数据对应图形上触发提示
  190. trigger: 'item',
  191. // 格式化提示内容:
  192. // a 代表图表名称 b 代表数据名称 c 代表数据 d代表 当前数据/总数据的比例
  193. formatter: "{a} <br/>{b} : {c} ({d}%)"
  194. },
  195. // 控制图表
  196. series: [{
  197. // 图表名称
  198. name: '学历',
  199. // 图表类型
  200. type: 'pie',
  201. // 南丁格尔玫瑰图 有两个圆 内圆半径10% 外圆半径70%
  202. // 百分比基于 图表DOM容器的半径
  203. radius: ['10%', '70%'],
  204. // 图表中心位置 left 50% top 50% 距离图表DOM容器
  205. center: ['50%', '50%'],
  206. // 半径模式,另外一种是 area 面积模式
  207. roseType: 'radius',
  208. // 数据集 value 数据的值 name 数据的名称
  209. data: eduction,
  210. //文字调整
  211. label: {
  212. fontSize: 10
  213. },
  214. //引导线
  215. labelLine: {
  216. length: 8,
  217. length2: 10
  218. }
  219. }],
  220. color: ['#006cff', '#60cda0', '#ed8884', '#ff9f7f', '#0096ff', '#9fe6b8', '#32c5e9', '#1d9dff']
  221. };
  222. myechart.setOption(option);
  223. }
  224. // 用户
  225. function user(data) {
  226. let cate = data.cate;
  227. let titleArr = [];
  228. let countArr = [];
  229. let total = 0;
  230. let count = cate.length;
  231. // 中间省略的数据 准备三项
  232. var hiddenItem = {
  233. name: '',
  234. value: 10,
  235. // 柱子颜色
  236. itemStyle: {
  237. color: '#254065'
  238. },
  239. // 鼠标经过柱子颜色
  240. emphasis: {
  241. itemStyle: {
  242. color: '#254065'
  243. }
  244. },
  245. // 工具提示隐藏
  246. tooltip: {
  247. extraCssText: 'opacity:0'
  248. }
  249. };
  250. cate.forEach((item, index) => {
  251. if (index < 5 || index + 5 >= count) {
  252. titleArr.push(item.title)
  253. countArr.push(item.count)
  254. } else if (count > 10 && index == 5) {
  255. //随机三个
  256. let arr = []
  257. for (let i = 5; i < count - 5; i++) {
  258. arr.push(i)
  259. }
  260. let randomArr = [];
  261. while (randomArr.length < 3) {
  262. let temp = (Math.random() * arr.length) >> 0;
  263. randomArr.push(arr.splice(temp, 1)[0]);
  264. }
  265. randomArr.forEach((randomIndex) => {
  266. titleArr.push(cate[randomIndex].title)
  267. countArr.push(cate[randomIndex].count)
  268. })
  269. }
  270. total += item.count
  271. });
  272. $('.cate-count').text(count)
  273. $('.cate-total').text(total)
  274. option = {
  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. // 使用类目,必须有data属性
  302. type: 'category',
  303. // 使用 data 中的数据设为刻度文字
  304. data: titleArr,
  305. // 刻度设置
  306. axisTick: {
  307. // true意思:图形在刻度中间
  308. // false意思:图形在刻度之间
  309. alignWithLabel: false,
  310. show: false
  311. },
  312. //文字
  313. axisLabel: {
  314. color: '#4c9bfd'
  315. }
  316. }],
  317. // 控制y轴
  318. yAxis: [{
  319. // 使用数据的值设为刻度文字
  320. type: 'value',
  321. axisTick: {
  322. // true意思:图形在刻度中间
  323. // false意思:图形在刻度之间
  324. alignWithLabel: false,
  325. show: false
  326. },
  327. //文字
  328. axisLabel: {
  329. color: '#4c9bfd'
  330. },
  331. splitLine: {
  332. lineStyle: {
  333. color: 'rgba(0, 240, 255, 0.3)'
  334. }
  335. },
  336. }],
  337. // 控制x轴
  338. series: [
  339. {
  340. // series配置
  341. // 颜色
  342. itemStyle: {
  343. // 提供的工具函数生成渐变颜色
  344. color: new echarts.graphic.LinearGradient(
  345. // (x1,y2) 点到点 (x2,y2) 之间进行渐变
  346. 0, 0, 0, 1,
  347. [{
  348. offset: 0,
  349. color: '#00fffb'
  350. }, // 0 起始颜色
  351. {
  352. offset: 1,
  353. color: '#0061ce'
  354. } // 1 结束颜色
  355. ]
  356. )
  357. },
  358. // 图表数据名称
  359. name: '岗位统计',
  360. // 图表类型
  361. type: 'bar',
  362. // 柱子宽度
  363. barWidth: '60%',
  364. // 数据
  365. data: countArr
  366. }
  367. ]
  368. };
  369. var myechart = echarts.init($('.users .bar')[0]);
  370. myechart.setOption(option);
  371. }
  372. //订单
  373. function order(data) {
  374. var data = {
  375. day365: {
  376. orders: '20,301,987',
  377. amount: '99834'
  378. },
  379. day90: {
  380. orders: '301,987',
  381. amount: '9834'
  382. },
  383. day30: {
  384. orders: '1,987',
  385. amount: '3834'
  386. },
  387. day1: {
  388. orders: '987',
  389. amount: '834'
  390. }
  391. }
  392. //点击事件
  393. $('.order').on('click', '.filter a', function() {
  394. //点击之后加类名
  395. $(this).addClass('active').siblings().removeClass('active');
  396. // 先获取点击a的 data-key自定义属性
  397. var key = $(this).attr('data-key');
  398. //获取自定义属性
  399. // data{}==>data.shuxing data['shuxing]
  400. key = data[key]; //
  401. $('.order .item h4:eq(0)').text(key.orders);
  402. $('.order .item h4:eq(1)').text(key.amount);
  403. });
  404. //定时器
  405. var index = 0;
  406. var aclick = $('.order a');
  407. setInterval(function() {
  408. index++;
  409. if (index > 3) {
  410. index = 0;
  411. }
  412. //每san秒调用点击事件
  413. aclick.eq(index).click();
  414. }, 3000);
  415. }
  416. //销售
  417. function sale(data) {
  418. let user_month = data.user_month;
  419. let titleArr = [];
  420. let countArr = [];
  421. user_month.forEach((item, index) => {
  422. titleArr.push(item.name)
  423. countArr.push(item.count)
  424. });
  425. var option = {
  426. //鼠标提示工具
  427. tooltip: {
  428. trigger: 'axis'
  429. },
  430. xAxis: {
  431. // 类目类型
  432. type: 'category',
  433. // x轴刻度文字
  434. data: titleArr,
  435. axisTick: {
  436. show: false //去除刻度线
  437. },
  438. axisLabel: {
  439. color: '#4c9bfd' //文本颜色
  440. },
  441. axisLine: {
  442. show: false //去除轴线
  443. },
  444. boundaryGap: false //去除轴内间距
  445. },
  446. yAxis: {
  447. // 数据作为刻度文字
  448. type: 'value',
  449. axisTick: {
  450. show: false //去除刻度线
  451. },
  452. axisLabel: {
  453. color: '#4c9bfd' //文本颜色
  454. },
  455. axisLine: {
  456. show: false //去除轴线
  457. },
  458. boundaryGap: false //去除轴内间距
  459. },
  460. //图例组件
  461. legend: {
  462. textStyle: {
  463. color: '#4c9bfd' // 图例文字颜色
  464. },
  465. right: '10%' //距离右边10%
  466. },
  467. // 设置网格样式
  468. grid: {
  469. show: true, // 显示边框
  470. top: '20%',
  471. left: '3%',
  472. right: '4%',
  473. bottom: '3%',
  474. borderColor: '#012f4a', // 边框颜色
  475. containLabel: true // 包含刻度文字在内
  476. },
  477. series: [{
  478. name: '注册用户',
  479. // 数据
  480. data: countArr,
  481. // 图表类型
  482. type: 'line',
  483. // 圆滑连接
  484. smooth: true,
  485. itemStyle: {
  486. color: '#00f2f1' // 线颜色
  487. }
  488. }]
  489. };
  490. var myechart = echarts.init($('.line')[0]);
  491. myechart.setOption(option);
  492. //点击效果
  493. var data = {
  494. year: [
  495. [24, 40, 101, 134, 90, 230, 210, 230, 120, 230, 210, 120],
  496. [40, 64, 191, 324, 290, 330, 310, 213, 180, 200, 180, 79]
  497. ],
  498. quarter: [
  499. [23, 75, 12, 97, 21, 67, 98, 21, 43, 64, 76, 38],
  500. [43, 31, 65, 23, 78, 21, 82, 64, 43, 60, 19, 34]
  501. ],
  502. month: [
  503. [34, 87, 32, 76, 98, 12, 32, 87, 39, 36, 29, 36],
  504. [56, 43, 98, 21, 56, 87, 43, 12, 43, 54, 12, 98]
  505. ],
  506. week: [
  507. [43, 73, 62, 54, 91, 54, 84, 43, 86, 43, 54, 53],
  508. [32, 54, 34, 87, 32, 45, 62, 68, 93, 54, 54, 24]
  509. ]
  510. }
  511. $('.sales ').on('click', '.caption a', function() {
  512. $(this).addClass('active').siblings('a').removeClass('active');
  513. //option series data
  514. //获取自定义属性值
  515. var key = $(this).attr('data-type');
  516. //取出对应的值
  517. key = data[key];
  518. //将值设置到 图表中
  519. option.series[0].data = key[0];
  520. option.series[1].data = key[1];
  521. //再次调用才能在页面显示
  522. myechart.setOption(option);
  523. });
  524. //定时器
  525. var index = 0;
  526. var timer = setInterval(function() {
  527. index++;
  528. if (index > 4) {
  529. index = 0;
  530. };
  531. $('.sales .caption a').eq(index).click();
  532. }, 2000);
  533. }
  534. function gauge(data) {
  535. var option = {
  536. series: [{
  537. type: 'pie',
  538. radius: ['130%', '150%'], // 放大图形
  539. center: ['50%', '80%'], // 往下移动 套住75%文字
  540. label: {
  541. show: false,
  542. },
  543. startAngle: 180,
  544. hoverOffset: 0, // 鼠标经过不变大
  545. data: [{
  546. value: 100,
  547. itemStyle: { // 颜色渐变#00c9e0->#005fc1
  548. color: {
  549. type: 'linear',
  550. x: 0,
  551. y: 0,
  552. x2: 0,
  553. y2: 1,
  554. colorStops: [{
  555. offset: 0,
  556. color: '#00c9e0'
  557. },
  558. {
  559. offset: 1,
  560. color: '#005fc1'
  561. }
  562. ]
  563. }
  564. }
  565. },
  566. {
  567. value: 100,
  568. itemStyle: {
  569. color: '#12274d'
  570. }
  571. }, // 颜色#12274d
  572. {
  573. value: 200,
  574. itemStyle: {
  575. color: 'transparent'
  576. }
  577. } // 透明隐藏第三块区域
  578. ]
  579. }]
  580. };
  581. var myechart = echarts.init($('.gauge')[0]);
  582. myechart.setOption(option);
  583. }
  584. function province(data) {
  585. var data = [{
  586. name: '可爱多',
  587. num: '9,086'
  588. },
  589. {
  590. name: '娃哈哈',
  591. num: '8,341'
  592. },
  593. {
  594. name: '喜之郎',
  595. num: '7,407'
  596. },
  597. {
  598. name: '八喜',
  599. num: '6,080'
  600. },
  601. {
  602. name: '小洋人',
  603. num: '6,724'
  604. },
  605. {
  606. name: '好多鱼',
  607. num: '2,170'
  608. },
  609. ]
  610. $('.inner').on('mouseenter', '.sup li', function() {
  611. $(this).addClass('active').siblings().removeClass('active');
  612. //获取随机的值 sort方法 是给数组排序 a-b是从小到大
  613. //.5-随机0-1的数 可能为正可能为负 排序就会随机
  614. var radomData = data.sort(function(a, b) {
  615. return 0.5 - Math.random()
  616. });
  617. var html = '';
  618. radomData.forEach(function(item) {
  619. html +=
  620. `<li><span>${item.name}</span><span>${item.num} <s class="icon-up"></s></span></li>`;
  621. });
  622. //渲染
  623. $('.sub').html(html);
  624. });
  625. $('.province .sup li').eq(0).mouseenter();
  626. var index = 0;
  627. var timer = setInterval(() => {
  628. index++;
  629. if (index > 5) {
  630. index = 0;
  631. }
  632. $('.sup li').eq(index).mouseenter();
  633. }, 2000);
  634. }