video_point.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','echarts', 'echarts-theme', 'template','china'],
  2. function ($, undefined, Backend, Table, Form,Echarts, EchartsTheme, Template,china) {
  3. var Controller = {
  4. index: function () {
  5. // 初始化表格参数配置
  6. Table.api.init({
  7. extend: {
  8. index_url: 'video_point/index' + location.search,
  9. add_url: 'video_point/add',
  10. edit_url: 'video_point/edit',
  11. del_url: 'video_point/del',
  12. multi_url: 'video_point/multi',
  13. import_url: 'video_point/import',
  14. table: 'video_point',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'id',
  23. searchFormVisible:true,
  24. columns: [
  25. [
  26. //{checkbox: true},
  27. {field:'id',title:"ID"},
  28. {field: 'video.title', title: __('Video.title'),operate:"like",formatter(a,b){
  29. let aa=a,
  30. aaa=''
  31. if(a.length>10){
  32. a=`${a.substr(0,10)}`
  33. aaa='...'
  34. }
  35. return `<a target="_blank" href="${b.video.src}" title="${aa}">${a}${aaa}</a>`
  36. }},
  37. {field: 'type', title: __('Type'),searchList:{'decide':'判断题','choose':'选择题','vote':'投票','wenda':'问答'},formatter:Table.api.formatter.label},
  38. {field: 'second', title: __('Second'),operate: false},
  39. {field: 'title', title: __('Title'),formatter(a, b) {
  40. let txt=''
  41. if(b.title){
  42. txt+=`<span title="${a}">${a.length>10?(a.substr(0,10)+'...'):a}</span>`;
  43. }
  44. if(b.title_img){
  45. txt+=`<img src="${b.title_img}" style="max-width: 60px;max-height: 60px;" alt=""/>`
  46. }
  47. return txt
  48. }},
  49. {field: 'items', title: __('选项'),operate:'LIKE',formatter(a, b) {
  50. if(b.type==='wenda'){
  51. return ''
  52. }
  53. let items=[]
  54. Object.keys(b.items).forEach(idx=>{
  55. if(b.item_type==='txt') {
  56. let txt=b.items[idx].length>10?(b.items[idx].substr(0,10)+'...'):b.items[idx]
  57. items.push(`<p class="" title="${b.items[idx]}">${idx}:${txt}</p>`)
  58. }else{
  59. items.push(`<a style="display: block;" href="${b.items[idx]}" target="_blank">${idx}:<img src="${b.items[idx]}" alt="pic" style="width: 50px;height: 50px;object-fit: cover;"></a>`)
  60. }
  61. })
  62. return items.join('')
  63. }},
  64. {field: 'key', title: __('答案'),formatter(a, b) {
  65. return a
  66. }
  67. },
  68. {field: 'ave_time', title: __('平均耗时(秒)'),operate:"BETWEEN",formatter(a, b) {
  69. if(b.type==='vote'){
  70. return '-'
  71. }
  72. return a
  73. }
  74. },
  75. {field: 'total_time', title: __('总耗时(秒)'),operate:"BETWEEN",formatter(a, b) {
  76. if(b.type==='vote'){
  77. return '-'
  78. }
  79. return a
  80. }
  81. },
  82. {
  83. field: 'buttons',
  84. title:'操作',
  85. table: table,
  86. events: Table.api.events.operate,
  87. formatter: Table.api.formatter.buttons,
  88. buttons: [
  89. {
  90. name: 'detail',
  91. text: __('耗时曲线'),
  92. title: __('耗时曲线'),
  93. classname: 'btn btn-xs btn-info btn-dialog',
  94. extend:'data-area=\'["1000px", "800px"]\'',
  95. url: 'video_point/time',
  96. callback: function (data) {},
  97. visible: function (row) {
  98. return row.type!=='vote';
  99. }
  100. },
  101. {
  102. name: 'detail',
  103. text: __('选择曲线'),
  104. title: __('选择曲线'),
  105. classname: 'btn btn-xs btn-info btn-dialog',
  106. extend:'data-area=\'["1000px", "800px"]\'',
  107. url: 'video_point/curve',
  108. callback: function (data) {},
  109. visible: function (row) {
  110. return row.type!=='wenda';
  111. }
  112. },
  113. {
  114. name: 'detail',
  115. text: __('正确率'),
  116. title: __('第一次答题正确率'),
  117. classname: 'btn btn-xs btn-info btn-dialog',
  118. extend:'data-area=\'["1000px", "800px"]\'',
  119. url: 'video_point/rate',
  120. callback: function (data) {},
  121. visible: function (row) {
  122. return ['choose','decide'].indexOf(row.type)>-1;
  123. }
  124. },
  125. {
  126. name: 'addtabs',
  127. text: __('互动记录'),
  128. title: __('互动记录'),
  129. classname: 'btn btn-xs btn-info btn-addtabs',
  130. url: 'video_point_user/index?frm=video_point',
  131. callback: function (data) {},
  132. visible: function (row) {
  133. return true;
  134. }
  135. },
  136. {
  137. name: 'addtabs',
  138. text: __('地图展示'),
  139. title: __('地图展示'),
  140. classname: 'btn btn-xs btn-info btn-dialog btn-map',
  141. url: 'video_point/map',
  142. callback: function (data) {},
  143. visible: function (row) {
  144. return true;
  145. },
  146. extend:'data-area=["100%","100%"]'
  147. },
  148. ]
  149. },
  150. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
  151. ]
  152. ]
  153. });
  154. // 为表格绑定事件
  155. Table.api.bindevent(table);
  156. },
  157. add: function () {
  158. Controller.api.bindevent();
  159. },
  160. edit: function () {
  161. Controller.api.bindevent();
  162. },
  163. curve:()=>{
  164. Controller.api.bindevent()
  165. let e=Echarts.init(document.getElementById('charts'))
  166. let option = {
  167. tooltip: {
  168. trigger: 'axis',
  169. formatter:(p)=>{
  170. let a=p[0]
  171. return `选择:${a.name}<br>${a.value}%`
  172. }
  173. },
  174. xAxis: {
  175. type: 'category',
  176. data: x
  177. },
  178. yAxis: {
  179. type: 'value'
  180. },
  181. series: [
  182. {
  183. data: value,
  184. type: 'bar',
  185. tooltip: {
  186. formatter:(a)=>{
  187. return `${a.value}%`
  188. }
  189. }
  190. }
  191. ]
  192. };
  193. e.setOption(option)
  194. $(window).resize(function () {
  195. e.resize();
  196. });
  197. $("#search").on('click',function (){
  198. let time=$('.form-time').val(),
  199. sex=$('.form-sex').val(),age_start=$('input[name=age_start]').val(),age_end=$('input[name=age_end]').val(),
  200. province_id=$('select[name="province_id"]').val(),
  201. city_id=$('select[name="city_id"]').val()||''
  202. location.href=`${location.origin}${location.pathname}?time=${time}&sex=${sex}&age_start=${age_start}&age_end=${age_end}&province_id=${province_id}&city_id=${city_id}`
  203. })
  204. function makeCity(){
  205. let province_id=$('.province-select').val()
  206. if(!province_id){
  207. $('.city-select').html('<option value="">请选择市</option>')
  208. return
  209. }
  210. $.getJSON(`ajax/area?province=${province_id}`,{},function (res) {
  211. let a='<option value="">请选择市</option>'
  212. res.data.forEach(item=>{
  213. a+=`<option value="${item.value}" ${city_id==item.value?'selected':''}>${item.name}</option>`
  214. })
  215. $('.city-select').html(a)
  216. })
  217. }
  218. $('.province-select').change(function (){
  219. makeCity()
  220. })
  221. makeCity()
  222. },
  223. rate:()=>{
  224. Controller.api.bindevent()
  225. let e=Echarts.init(document.getElementById('charts'))
  226. let option = {
  227. tooltip: {
  228. trigger: 'axis',
  229. formatter:(p)=>{
  230. let a=p[0]
  231. if(a.name==='回答次数'){
  232. return `${a.name}<br>${a.value}`
  233. }else {
  234. return `${a.name}<br>${a.value}%`
  235. }
  236. }
  237. },
  238. xAxis: {
  239. type: 'category',
  240. data: x
  241. },
  242. yAxis: {
  243. type: 'value'
  244. },
  245. series: [
  246. {
  247. data: value,
  248. type: 'line',
  249. tooltip: {
  250. formatter:(a)=>{
  251. return `${a.value}%`
  252. }
  253. }
  254. }
  255. ]
  256. };
  257. e.setOption(option)
  258. $(window).resize(function () {
  259. e.resize();
  260. });
  261. $("#search").on('click',function (){
  262. let time=$('.form-time').val()
  263. if(!time){
  264. layer.msg('请选择时间')
  265. return
  266. }
  267. location.href=`${location.origin}${location.pathname}?time=${time}`
  268. })
  269. },
  270. time:()=>{
  271. Controller.api.bindevent();
  272. let e=Echarts.init(document.getElementById('charts'))
  273. let option = {
  274. tooltip: {
  275. trigger: 'axis',
  276. formatter:(p)=>{
  277. let a=p[0]
  278. return `日期:${a.name}<br>${a.value}S`
  279. }
  280. },
  281. xAxis: {
  282. type: 'category',
  283. data: x
  284. },
  285. yAxis: {
  286. type: 'value'
  287. },
  288. series: [
  289. {
  290. data: value,
  291. type: 'line',
  292. tooltip: {
  293. formatter:(a)=>{
  294. return `日期:${a.name}<br>耗时:${a.value}`
  295. }
  296. }
  297. }
  298. ]
  299. };
  300. e.setOption(option)
  301. $(window).resize(function () {
  302. e.resize();
  303. });
  304. $("#search").on('click',function (){
  305. let time=$('.form-time').val()
  306. if(!time){
  307. layer.msg('请选择时间')
  308. return
  309. }
  310. location.href=`${location.origin}${location.pathname}?time=${time}`
  311. })
  312. },
  313. map(){
  314. Form.api.bindevent($("#search"));
  315. let searchForm=$('#search')
  316. function pyChinese(pro){
  317. var str = '';
  318. switch(pro){
  319. case '黑龙江':
  320. str = 'heilongjiang';
  321. break;
  322. case '河北':
  323. str = 'hebei';
  324. break;
  325. case '甘肃':
  326. str = 'gansu';
  327. break;
  328. case '云南':
  329. str = 'yunnan';
  330. break;
  331. case '四川':
  332. str = 'sichuan';
  333. break;
  334. case '吉林':
  335. str = 'jilin';
  336. break;
  337. case '辽宁':
  338. str = 'liaoning';
  339. break;
  340. case '青海':
  341. str = 'qinghai';
  342. break;
  343. case '陕西':
  344. str = 'shanxi';
  345. break;
  346. case '河南':
  347. str = 'henan';
  348. break;
  349. case '山东':
  350. str = 'shandong';
  351. break;
  352. case '山西':
  353. str = 'shanxi';
  354. break;
  355. case '安徽':
  356. str = 'anhui';
  357. break;
  358. case '湖北':
  359. str = 'hubei';
  360. break;
  361. case '湖南':
  362. str = 'hunan';
  363. break;
  364. case '江苏':
  365. str = 'jiangsu';
  366. break;
  367. case '贵州':
  368. str = 'guizhou';
  369. break;
  370. case '浙江':
  371. str = 'zhejiang';
  372. break;
  373. case '江西':
  374. str = 'jiangxi';
  375. break;
  376. case '广东':
  377. str = 'guangdong';
  378. break;
  379. case '福建':
  380. str = 'fujian';
  381. break;
  382. case '台湾':
  383. str = 'taiwan';
  384. break;
  385. case '海南':
  386. str = 'hainan';
  387. break;
  388. case '广西':
  389. str = 'guangxi';
  390. break;
  391. case '内蒙古':
  392. str = 'neimenggu';
  393. break;
  394. case '宁夏':
  395. str = 'ningxia';
  396. break;
  397. case '新疆':
  398. str = 'xinjiang';
  399. break;
  400. case '西藏':
  401. str = 'xizang';
  402. break;
  403. case '澳门':
  404. str = 'aomen';
  405. break;
  406. case '北京':
  407. str = 'beijing';
  408. break;
  409. case '上海':
  410. str = 'shanghai';
  411. break;
  412. case '香港':
  413. str = 'xianggang';
  414. break;
  415. case '天津':
  416. str = 'tianjin';
  417. break;
  418. case '重庆':
  419. str = 'chongqing';
  420. break;
  421. default:
  422. str = '';
  423. break;
  424. }
  425. return str;
  426. }
  427. let height=$('body').height(),
  428. reset=$('.btn-reset'),
  429. levelInput=$('#ilevel'),
  430. search=$('.btn-search')
  431. $('#mainMap').css('height',height-55)
  432. //creatChinaMap('mainMap');
  433. $('.back_btn').click(function(){
  434. //creatChinaMap('mainMap');
  435. reset.click()
  436. level=1
  437. search.click()
  438. })
  439. function creatChinaMap(id,data){
  440. reset.click()
  441. var myChart = Echarts.init(document.getElementById(id));
  442. $('.back_btn').hide();
  443. myChart.setOption({
  444. title: {
  445. text: '全国各省',
  446. left: 'center',
  447. textStyle: {
  448. color: '#000'
  449. }
  450. ,top:30
  451. },
  452. tooltip: {
  453. formatter: function (params) {
  454. if(!params.data){
  455. params.data={name:params.name,value:0}
  456. }
  457. console.log(params)
  458. var info = '<p style="font-size:18px">' + params.name + `</p><p style="font-size:14px">${params.data.value}</p>`
  459. return info;
  460. },
  461. trigger: 'item',
  462. backgroundColor: "#ff7f50",//提示标签背景颜色
  463. textStyle: { color: "#fff" } //提示标签字体颜色
  464. },
  465. series: [
  466. {
  467. name: '产品分布',
  468. type: 'map',
  469. mapType: 'china',
  470. roam: false,
  471. label: {
  472. normal: {
  473. show: true
  474. },
  475. emphasis: {
  476. show: true
  477. }
  478. },
  479. data:data,
  480. itemStyle: {
  481. normal: {
  482. borderColor: '#ccc',
  483. areaColor: '#ffffff'
  484. },
  485. emphasis: {
  486. areaColor: '#ccc',
  487. color:'#fff',
  488. borderWidth: 0,
  489. show:false,
  490. }
  491. },
  492. }
  493. ]
  494. });
  495. myChart.on('click', function (param) {
  496. level = 2
  497. currentProvinceName = param.name
  498. reset.click()
  499. search.click()
  500. //creatProvince(parm.name,id);
  501. })
  502. }
  503. function creatProvince(name,id,data){
  504. var pro = pyChinese(name);
  505. if(pro==''){
  506. return false;
  507. }
  508. $('.back_btn').show();
  509. var childChart = Echarts.init(document.getElementById(id));
  510. var seriesdata = [{
  511. type: 'map',
  512. mapType: pro,
  513. label: {
  514. normal: {
  515. show: true
  516. },
  517. emphasis: {
  518. show: true
  519. }
  520. },
  521. data:data,
  522. itemStyle: {
  523. normal: {
  524. borderColor: '#ccc',
  525. areaColor: '#ffffff'
  526. },
  527. emphasis: {
  528. areaColor: '#ccc',
  529. color:'#fff',
  530. borderWidth: 0,
  531. show:false,
  532. }
  533. },
  534. animation: false
  535. }];
  536. var option = {
  537. tooltip: {
  538. formatter: function (params) {
  539. if(!params.data){
  540. params.data={name:params.name,value:0}
  541. }
  542. var info = '<p style="font-size:18px">' + params.name + `</p><p style="font-size:14px">${params.data.value}</p>`
  543. return info;
  544. },
  545. trigger: 'item',
  546. backgroundColor: "#ff7f50",//提示标签背景颜色
  547. textStyle: { color: "#fff" } //提示标签字体颜色
  548. },
  549. title: {
  550. text: name,
  551. left: 'center',
  552. textStyle: {
  553. color: '#000'
  554. }
  555. ,top:30
  556. },
  557. series: seriesdata
  558. };
  559. $.get('/assets/js/map/json/'+pro+'.json', function(gdMap) {
  560. console.log(gdMap)
  561. Echarts.registerMap(pro, gdMap);
  562. childChart.setOption(option, true);
  563. childChart.on('click',function (){})
  564. });
  565. }
  566. search.on('click',function (){
  567. levelInput.val(level)
  568. let form=searchForm.serializeArray()
  569. let idx = layer.load(2),
  570. call = () => {
  571. layer.close(idx)
  572. };
  573. if(level==1) {
  574. form.push({name: 'province', value: JSON.stringify(province)})
  575. $.post('', form, function (res) {
  576. if (res.code !== 1) {
  577. layer.alert(res.msg)
  578. call()
  579. return
  580. }
  581. creatChinaMap('mainMap', res.data)
  582. call()
  583. })
  584. }else if(level==2){
  585. form.push({name:'province',value:currentProvinceName})
  586. form.push({name:'province_pinyin',value:pyChinese(currentProvinceName)})
  587. creatProvince(currentProvinceName,'mainMap',[{name:'济南市',value:1222}])
  588. $.post('', form, function (res) {
  589. if (res.code !== 1) {
  590. layer.alert(res.msg)
  591. call()
  592. return
  593. }
  594. //creatChinaMap('mainMap', res.data)
  595. creatProvince(currentProvinceName,'mainMap',res.data)
  596. call()
  597. })
  598. }
  599. })
  600. search.click()
  601. },
  602. api: {
  603. bindevent: function () {
  604. Form.api.bindevent($("form[role=form]"));
  605. }
  606. }
  607. };
  608. return Controller;
  609. });