index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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('/admin/api/talent', (res) => {
  25. talent_init(res)
  26. });
  27. $.get('/admin/api/odd_job', (res) => {
  28. odd_init(res)
  29. });
  30. $.get('/admin/api/recruit', (res) => {
  31. recruit_init(res)
  32. });
  33. function recruit_init(data) {
  34. $('.recruit_count').text(data.recruit_count);
  35. $('.recruit_post').text(data.recruit_post);
  36. $('.recruit_apply').text(data.recruit_apply);
  37. this.pieAge(data);
  38. this.pieEdu(data);
  39. }
  40. function talent_init(data) {
  41. this.talent_count(data);
  42. this.talent_level(data.talent_level);
  43. $('.train_join').text(data.total_count[0].count);
  44. }
  45. function odd_init(data) {
  46. this.geo(data);
  47. this.odd_total(data);
  48. }
  49. //人才分布
  50. function talent_count(data) {
  51. var htmlArr = [];
  52. htmlArr['talent_industry'] = '';
  53. htmlArr['talent_age'] = '';
  54. htmlArr['talent_education'] = '';
  55. data.talent_industry.forEach(function (item) {
  56. htmlArr['talent_industry'] += `<li><span>${item.name}</span><span>${item.count} <s class="icon-up"></s></span></li>`;
  57. });
  58. data.talent_age.forEach(function (item) {
  59. htmlArr['talent_age'] += `<li><span>${item.name}</span><span>${item.count} <s class="icon-up"></s></span></li>`;
  60. });
  61. data.talent_education.forEach(function (item) {
  62. htmlArr['talent_education'] += `<li><span>${item.name}</span><span>${item.count} <s class="icon-up"></s></span></li>`;
  63. });
  64. $('.inner').on('mouseenter', '.sup li', function () {
  65. $(this).addClass('active').siblings().removeClass('active');
  66. //渲染
  67. $('.sub').html(htmlArr[$(this).attr('data-type')]);
  68. });
  69. $('.province .sup li').eq(0).mouseenter();
  70. var index = 0;
  71. var timer = setInterval(() => {
  72. index++;
  73. if (index > 2) {
  74. index = 0;
  75. }
  76. $('.sup li').eq(index).mouseenter();
  77. }, 2000);
  78. }
  79. function talent_level(data) {
  80. let titleArr = [];
  81. let countArr = [];
  82. let total = 0;
  83. let count = data.length;
  84. // 中间省略的数据 准备三项
  85. var hiddenItem = {
  86. name: '',
  87. value: 10,
  88. // 柱子颜色
  89. itemStyle: {
  90. color: '#254065'
  91. },
  92. // 鼠标经过柱子颜色
  93. emphasis: {
  94. itemStyle: {
  95. color: '#254065'
  96. }
  97. },
  98. // 工具提示隐藏
  99. tooltip: {
  100. extraCssText: 'opacity:0'
  101. }
  102. };
  103. data.forEach((item, index) => {
  104. if (index < 7 || index + 7 >= count) {
  105. titleArr.push(item.name)
  106. countArr.push(item.count)
  107. } else if (count > 12 && index == 7) {
  108. //随机三个
  109. let arr = []
  110. for (let i = 7; i < count - 7; i++) {
  111. arr.push(i)
  112. }
  113. let randomArr = [];
  114. while (randomArr.length < 3) {
  115. let temp = (Math.random() * arr.length) >> 0;
  116. randomArr.push(arr.splice(temp, 1)[0]);
  117. }
  118. randomArr.forEach((randomIndex) => {
  119. titleArr.push(data[randomIndex].name)
  120. countArr.push(data[randomIndex].count)
  121. })
  122. }
  123. total += (item.count - 0)
  124. });
  125. $('.talent_level-total').text(total)
  126. option = {
  127. // 工具提示
  128. tooltip: {
  129. // 触发类型 经过轴触发axis 经过轴触发item
  130. trigger: 'item',
  131. // 轴触发提示才有效
  132. axisPointer: {
  133. // 默认为直线,可选为:'line' 线效果 | 'shadow' 阴影效果
  134. type: 'shadow'
  135. }
  136. },
  137. // 图表边界控制
  138. grid: {
  139. // 距离 上右下左 的距离
  140. left: '0',
  141. right: '3%',
  142. bottom: '3%',
  143. top: '5%',
  144. // 大小是否包含文本【类似于boxsizing】
  145. containLabel: true,
  146. //显示边框
  147. show: true,
  148. //边框颜色
  149. borderColor: 'rgba(0, 240, 255, 0.3)'
  150. },
  151. // 控制x轴
  152. xAxis: [{
  153. // 使用类目,必须有data属性
  154. type: 'category',
  155. // 使用 data 中的数据设为刻度文字
  156. data: titleArr,
  157. // 刻度设置
  158. axisTick: {
  159. // true意思:图形在刻度中间
  160. // false意思:图形在刻度之间
  161. alignWithLabel: false,
  162. show: false
  163. },
  164. //文字
  165. axisLabel: {
  166. color: '#4c9bfd'
  167. }
  168. }],
  169. // 控制y轴
  170. yAxis: [{
  171. // 使用数据的值设为刻度文字
  172. type: 'value',
  173. axisTick: {
  174. // true意思:图形在刻度中间
  175. // false意思:图形在刻度之间
  176. alignWithLabel: false,
  177. show: false
  178. },
  179. //文字
  180. axisLabel: {
  181. color: '#4c9bfd'
  182. },
  183. splitLine: {
  184. lineStyle: {
  185. color: 'rgba(0, 240, 255, 0.3)'
  186. }
  187. },
  188. }],
  189. // 控制x轴
  190. series: [
  191. {
  192. // series配置
  193. // 颜色
  194. itemStyle: {
  195. // 提供的工具函数生成渐变颜色
  196. color: new echarts.graphic.LinearGradient(
  197. // (x1,y2) 点到点 (x2,y2) 之间进行渐变
  198. 0, 0, 0, 1,
  199. [{
  200. offset: 0,
  201. color: '#00fffb'
  202. }, // 0 起始颜色
  203. {
  204. offset: 1,
  205. color: '#0061ce'
  206. } // 1 结束颜色
  207. ]
  208. )
  209. },
  210. // 图表数据名称
  211. name: '层次人数',
  212. // 图表类型
  213. type: 'bar',
  214. // 柱子宽度
  215. barWidth: '60%',
  216. // 数据
  217. data: countArr
  218. }
  219. ]
  220. };
  221. var myechart = echarts.init($('.talent_level')[0]);
  222. myechart.setOption(option);
  223. }
  224. function pieAge(data) {
  225. let recruit_age = data.recruit_age;
  226. let gt35 = 0;
  227. let lt35 = 0;
  228. recruit_age.map((item, index) => {
  229. if (item.name == '35到40岁' || item.name == '40岁以上') {
  230. gt35 += item.count;
  231. //其他数据
  232. item.value = item.count;
  233. } else {
  234. lt35 += item.count;
  235. item.value = item.count;
  236. }
  237. return item;
  238. });
  239. $('.age-gt35').text(gt35);
  240. $('.age-lt35').text(lt35);
  241. var myechartAge = echarts.init($('.recruit_age')[0]);
  242. option = {
  243. // 控制提示
  244. tooltip: {
  245. // 非轴图形,使用item的意思是放到数据对应图形上触发提示
  246. trigger: 'item',
  247. // 格式化提示内容:
  248. // a 代表图表名称 b 代表数据名称 c 代表数据 d代表 当前数据/总数据的比例
  249. formatter: "{a} <br/>{b} : {c} ({d}%)"
  250. },
  251. // 控制图表
  252. series: [{
  253. // 图表名称
  254. name: '年龄',
  255. // 图表类型
  256. type: 'pie',
  257. // 南丁格尔玫瑰图 有两个圆 内圆半径10% 外圆半径70%
  258. // 百分比基于 图表DOM容器的半径
  259. radius: ['10%', '70%'],
  260. // 图表中心位置 left 50% top 50% 距离图表DOM容器
  261. center: ['50%', '50%'],
  262. // 半径模式,另外一种是 area 面积模式
  263. roseType: 'radius',
  264. // 数据集 value 数据的值 name 数据的名称
  265. data: recruit_age,
  266. //文字调整
  267. label: {
  268. fontSize: 10
  269. },
  270. //引导线
  271. labelLine: {
  272. length: 8,
  273. length2: 10
  274. }
  275. }],
  276. color: ['#006cff', '#9fe6b8', '#32c5e9', '#1d9dff', '#60cda0', '#ed8884', '#ff9f7f', '#0096ff']
  277. };
  278. myechartAge.setOption(option);
  279. }
  280. function pieEdu(data) {
  281. let eduction = data.recruit_education;
  282. let unknown = 0;
  283. let total = 0;
  284. eduction.map((item, index) => {
  285. if (item.name == '其他') {
  286. unknown += item.count;
  287. eduction.splice(index, 1);
  288. } else {
  289. total += item.count;
  290. item.value = item.count;
  291. }
  292. return item;
  293. });
  294. $('.edu-unknown').text(unknown);
  295. $('.edu-total').text(total);
  296. var myechart = echarts.init($('.recruit_education')[0]);
  297. option = {
  298. // 控制提示
  299. tooltip: {
  300. // 非轴图形,使用item的意思是放到数据对应图形上触发提示
  301. trigger: 'item',
  302. // 格式化提示内容:
  303. // a 代表图表名称 b 代表数据名称 c 代表数据 d代表 当前数据/总数据的比例
  304. formatter: "{a} <br/>{b} : {c} ({d}%)"
  305. },
  306. // 控制图表
  307. series: [{
  308. // 图表名称
  309. name: '学历',
  310. // 图表类型
  311. type: 'pie',
  312. // 南丁格尔玫瑰图 有两个圆 内圆半径10% 外圆半径70%
  313. // 百分比基于 图表DOM容器的半径
  314. radius: ['10%', '70%'],
  315. // 图表中心位置 left 50% top 50% 距离图表DOM容器
  316. center: ['50%', '50%'],
  317. // 半径模式,另外一种是 area 面积模式
  318. roseType: 'radius',
  319. // 数据集 value 数据的值 name 数据的名称
  320. data: eduction,
  321. //文字调整
  322. label: {
  323. fontSize: 10
  324. },
  325. //引导线
  326. labelLine: {
  327. length: 8,
  328. length2: 10
  329. }
  330. }],
  331. color: ['#006cff', '#60cda0', '#ed8884', '#ff9f7f', '#0096ff', '#9fe6b8', '#32c5e9', '#1d9dff']
  332. };
  333. myechart.setOption(option);
  334. }
  335. function geo(data) {
  336. let community = data.community;
  337. let other = 0;
  338. let max = 0; //最大人数
  339. community = community.map((item) => {
  340. if (item.name == '其他') {
  341. other += item.count;
  342. } else if (item.count > max) {
  343. max = item.count;
  344. }
  345. return {
  346. name: item.name,
  347. value: item.count
  348. };
  349. });
  350. community.push({
  351. name: '泉州出口加工区',
  352. value: 0
  353. });
  354. community.push({
  355. name: '安平开发区',
  356. value: 0
  357. });
  358. var myecharts = echarts.init($('.map .geo')[0])
  359. // $.get('https://geo.datav.aliyun.com/areas_v3/bound/350582.json', result => {
  360. $.get('js/350582.json', result => {
  361. // 注册 echarts 地图
  362. echarts.registerMap('jinjiang', result);
  363. var option = {
  364. backgroundColor: '#080a20',
  365. title: {
  366. text: '其他地区:' + other + ' (人)',
  367. // subtext: '其他地区:' + community[community.length - 1].count,
  368. left: 'left',
  369. textStyle: {
  370. color: '#ffffff'
  371. }
  372. },
  373. tooltip: {
  374. trigger: 'item',
  375. formatter: '{b}<br/>{c} (人)'
  376. },
  377. visualMap: {
  378. min: 0,
  379. max: max,
  380. text: ['多', '少'],
  381. realtime: true,
  382. calculable: true,
  383. color: '#fff',
  384. inRange: {
  385. color: ['#142957', '#0b1c2d']
  386. },
  387. textStyle: {
  388. color: '#fff'
  389. }
  390. },
  391. series: [{
  392. type: 'map',
  393. map: 'jinjiang',
  394. zoom: 1.2,
  395. roam: true,
  396. coordinateSystem: 'geo',
  397. // rippleEffect: {
  398. // brushType: 'stroke'
  399. // },
  400. symbolSize: function(val, params) {
  401. return 8;
  402. },
  403. label: {
  404. show: true,
  405. color: '#fff'
  406. },
  407. itemStyle: {
  408. normal: {
  409. areaColor: '#142957',
  410. borderColor: '#0692a4'
  411. }
  412. },
  413. emphasis: {
  414. areaColor: '#0b1c2d'
  415. },
  416. data: community,
  417. nameMap: {
  418. '晋江市经济开发区': '经济开发区'
  419. }
  420. }]
  421. };
  422. myecharts.setOption(option);
  423. })
  424. }
  425. function odd_total(data) {
  426. $('.odd_job_number').text(data.user_total);
  427. $('.odd_job_company').text(data.company_total);
  428. $('.odd_job_job').text(data.comjobs_total);
  429. }