index.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>试题管理</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport"
  9. content="width=agent-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  10. <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  11. <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
  12. <style type="text/css">
  13. .seach_items {
  14. float: right;
  15. margin-left: 10px;
  16. }
  17. </style>
  18. <style type="text/css">
  19. .LAY-btns .layui-nav {
  20. padding-left: 0;
  21. padding-right: 10px;
  22. top: -4px;
  23. margin: 0 10px;
  24. border: 0;
  25. background-color: #009688;
  26. }
  27. .LAY-btns .layui-nav .layui-nav-item {
  28. line-height: 30px;
  29. }
  30. .LAY-btns .layui-nav .layui-nav-child {
  31. top: 34px;
  32. }
  33. .LAY-btns .layui-nav .layui-nav-bar {
  34. display: none;
  35. }
  36. .LAY-btns .layui-nav .layui-nav-child dd.layui-this a {
  37. color: #333;
  38. background-color: #fff;
  39. }
  40. .LAY-btns .layui-nav .layui-nav-child dd.layui-this a:hover {
  41. background-color: #f2f2f2;
  42. color: #000;
  43. }
  44. .tableContent {
  45. width: 100%;
  46. display: flex;
  47. justify-content: space-between;
  48. flex-direction: row;
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <div class="layui-fluid">
  54. <div class="layui-card">
  55. <div class="layui-card-body" pad15>
  56. <div class="layui-row layui-col-space15">
  57. <div class="layui-col-md12">
  58. <div class="LAY-btns" style="margin-bottom: 10px;">
  59. <div style="float: left">
  60. <button class="layui-btn layui-btn-sm" id="exam_question_add">
  61. <i class="layui-icon layui-icon-add-circle"></i>添加
  62. </button>
  63. <button class="layui-nav">
  64. <div class="layui-nav-item">
  65. <a href="javascript:;" style="color:#fff;" >导入</a>
  66. <dl class="layui-nav-child"> <!-- 二级菜单 -->
  67. <dd><a href="#" id="btn_add_single">单选题</a></dd>
  68. <dd><a href="#" id="btn_add_multiple">多选题</a></dd>
  69. <dd><a href="#" id="btn_add_fill">填空题</a></dd>
  70. <dd><a href="#" id="btn_add_judgment">判断题</a></dd>
  71. <dd><a href="#" id="btn_add_discuss">论述题</a></dd>
  72. <dd><a href="#" id="btn_import_word">多题型导入(Word)</a></dd>
  73. </dl>
  74. </div>
  75. </button>
  76. <button class="layui-nav">
  77. <div class="layui-nav-item">
  78. <a href="javascript:;" style="color:#fff;" >下载模版</a>
  79. <dl class="layui-nav-child"> <!-- 二级菜单 -->
  80. <dd><a href="#" id="btn_download_single">单选题模版</a></dd>
  81. <dd><a href="#" id="btn_download_multiple">多选题模版</a></dd>
  82. <dd><a href="#" id="btn_download_fill">填空题模版</a></dd>
  83. <dd><a href="#" id="btn_download_judgment">判断题模版</a></dd>
  84. <dd><a href="#" id="btn_download_discuss">论述题模版</a></dd>
  85. </dl>
  86. </div>
  87. </button>
  88. <button class="layui-btn layui-btn-sm" id="btn_download">
  89. <i class="layui-icon layui-icon-download-circle"></i>导出
  90. </button>
  91. <button class="layui-btn layui-btn-sm" id="exam_question_del">
  92. <i class="layui-icon layui-icon-delete"></i>批量删除
  93. </button>
  94. </div>
  95. <form class="layui-form" lay-filter="query-form-element">
  96. <div class="seach_items">
  97. <button class="layui-btn" lay-submit lay-filter="query-form-element"><i
  98. class="layui-icon layui-icon-search"></i>查询
  99. </button>
  100. </div>
  101. <div class="seach_items">
  102. <input type="text" name="title" autocomplete="off" class="layui-input"
  103. placeholder="名称"/>
  104. </div>
  105. <div class="seach_items">
  106. <select name="type">
  107. <option value="" selected>题型</option>
  108. <option value="1">单选题</option>
  109. <option value="2">多选题</option>
  110. <option value="3">填空题</option>
  111. <option value="4">判断题</option>
  112. <option value="5">论述题</option>
  113. </select>
  114. </div>
  115. </form>
  116. <div style="clear: both;"></div>
  117. </div>
  118. <table class="layui-hide" id="exam_question_datagrid" lay-filter="exam_question-operate"></table>
  119. <script type="text/html" id="exam_question-operate-bar">
  120. <div class="layui-btn-group">
  121. <a class="layui-btn layui-btn-xs" lay-event="exam_question_detail"
  122. >查看</a>
  123. </div>
  124. <div class="layui-btn-group">
  125. <a class="layui-btn layui-btn-xs" lay-event="exam_question_edit"
  126. >修改</a>
  127. </div>
  128. <div class="layui-btn-group">
  129. <a class="layui-btn layui-btn-xs" lay-event="exam_question_delete"
  130. >删除</a>
  131. </div>
  132. </script>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. <script src="../../layuiadmin/layui/layui.js"></script>
  139. <script>
  140. var _params = '';
  141. layui.config({
  142. base: '../../../layuiadmin/' //静态资源所在路径
  143. }).extend({
  144. index: 'lib/index' //主入口模块
  145. }).use(['index', 'table', 'form', 'admin', 'upload', ], function () {
  146. var $ = layui.$;
  147. var table = layui.table
  148. , admin = layui.admin
  149. ,upload = layui.upload
  150. , form = layui.form;
  151. table.render({
  152. elem: '#exam_question_datagrid'
  153. , url: '/admin/examquestion/'
  154. , cols: [[
  155. {type: 'checkbox', fixed: 'left'}
  156. , {title: '编号', type: 'numbers'}
  157. , {field: 'subject_text', title: '科目', width: 150}
  158. , {field: 'chapter_text', title: '章节', width: 150}
  159. , {field: 'type_text', title: '题型', width: 100}
  160. , {field: 'title', title: '内容', width: 400}
  161. , {field: 'difficulty_text', title: '难度', width: 100}
  162. , {field: 'create_user_text', title: '录入人', width: 150}
  163. , {field: 'create_time', title: '录入时间', width: 200}
  164. , {title: '操作', width: 180, align: 'center', fixed: 'right', toolbar: '#exam_question-operate-bar'}
  165. ]]
  166. , page: true
  167. , height: 'full-108'
  168. });
  169. //监听工具条
  170. table.on('tool(exam_question-operate)', function (obj) {
  171. var data = obj.data;
  172. table.editdata = data;
  173. if (obj.event === 'exam_question_edit') {
  174. layer.open({
  175. type: 2,
  176. title: '修改试题',
  177. shadeClose: false,
  178. area: ['80%', '80%'],
  179. btn: ['保存', '取消'],
  180. yes: function (index, dom) {
  181. layui.onSubmitChild = function (res) {
  182. layer.close(index);
  183. table.reload('exam_question_datagrid', {});
  184. };
  185. layui.submitChild();
  186. },
  187. btn2: function (index, layero) {
  188. layer.close(index);//关闭当前按钮
  189. },
  190. content: 'edit.html?id=' + data.id
  191. });
  192. }
  193. else if (obj.event === 'exam_question_delete') {
  194. layer.confirm('确定要删除该试题吗?', function (index) {
  195. layer.close(index);
  196. admin.req({
  197. url: '/admin/examquestion/' + data.id + '/'
  198. , type: 'delete'
  199. , done: function (res) {
  200. table.reload('exam_question_datagrid', {});
  201. }
  202. });
  203. });
  204. } else if (obj.event === 'exam_question_detail') {
  205. layer.open({
  206. type: 2,
  207. title: '查看详情',
  208. shadeClose: false,
  209. area: ['70%', '80%'],
  210. btn: ['关闭'],
  211. yes: function (index, dom) {
  212. layer.close(index);//关闭当前按钮
  213. },
  214. content: 'details.html'
  215. });
  216. }
  217. });
  218. form.on('submit(query-form-element)', function (data) {
  219. table.reload('exam_question_datagrid', {
  220. where: data.field
  221. , page: {curr: 1}
  222. });
  223. _params = data.field;
  224. layer.closeAll();
  225. return false
  226. });
  227. $('#exam_question_add').on('click', function () {
  228. layer.open({
  229. type: 2,
  230. title: '添加试题',
  231. area: ['80%', '90%'],
  232. btn: ['保存', '取消'],
  233. yes: function (index, dom) {
  234. layui.onSubmitChild = function (res) {
  235. layer.close(index);
  236. table.reload('exam_question_datagrid', {});
  237. };
  238. layui.submitChild();
  239. },
  240. btn2: function (index, layero) {
  241. layer.close(index);//关闭当前按钮
  242. },
  243. content: 'edit.html'
  244. });
  245. });
  246. $('#exam_question_del').on('click', function () {
  247. layer.confirm('确定要删除选中试题吗?', function (index) {
  248. layer.close(index);
  249. var checkStatus = table.checkStatus('exam_question_datagrid');
  250. var item = [];
  251. for (var i = 0; i < checkStatus.data.length; i++) {
  252. item.push(checkStatus.data[i].id);
  253. }
  254. if (item.length <= 0) {
  255. return;
  256. }
  257. admin.req({
  258. url: '/admin/examquestion/batch_del/'
  259. , type: 'post'
  260. , data: JSON.stringify(item)
  261. , dataType: 'json'
  262. , contentType: 'application/json'
  263. , done: function (res) {
  264. table.reload('exam_question_datagrid', {});
  265. }
  266. });
  267. });
  268. });
  269. $('#btn_import_word').on('click', function () {
  270. layer.open({
  271. type: 2,
  272. title: '导入Word试题',
  273. area: ['450px', '505px'],
  274. btn: ['选择文件并执行', '取消'],
  275. yes: function (index, dom) {
  276. layui.onSubmitChild = function (res) {
  277. layer.close(index);
  278. table.reload('exam_question_datagrid', {});
  279. };
  280. layui.uploadFile();
  281. },
  282. btn2: function (index, layero) {
  283. layer.close(index);//关闭当前按钮
  284. },
  285. content: 'import.html'
  286. });
  287. });
  288. upload.render({
  289. elem: '#btn_add_single'
  290. ,url: '/admin/examquestion/import_single/'
  291. ,accept:'file'
  292. ,acceptMime:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  293. ,exts:'xlsx'
  294. ,field:'excel_file'
  295. ,multiple:false
  296. ,done: function(res){
  297. if (res.code == 0) {
  298. table.reload('exam_question_datagrid',{});
  299. } else {
  300. layer.msg(res.msg);
  301. }
  302. }
  303. ,error: function(){
  304. layer.msg('导入失败');
  305. }
  306. });
  307. upload.render({
  308. elem: '#btn_add_multiple'
  309. ,url: '/admin/examquestion/import_multiple/'
  310. ,accept:'file'
  311. ,acceptMime:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  312. ,exts:'xlsx'
  313. ,field:'excel_file'
  314. ,multiple:false
  315. ,done: function(res){
  316. if (res.code == 0) {
  317. table.reload('exam_question_datagrid',{});
  318. } else {
  319. layer.msg(res.msg);
  320. }
  321. }
  322. ,error: function(){
  323. layer.msg('导入失败');
  324. }
  325. });
  326. upload.render({
  327. elem: '#btn_add_fill'
  328. ,url: '/admin/examquestion/import_fill/'
  329. ,accept:'file'
  330. ,acceptMime:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  331. ,exts:'xlsx'
  332. ,field:'excel_file'
  333. ,multiple:false
  334. ,done: function(res){
  335. if (res.code == 0) {
  336. table.reload('exam_question_datagrid',{});
  337. } else {
  338. layer.msg(res.msg);
  339. }
  340. }
  341. ,error: function(){
  342. layer.msg('导入失败');
  343. }
  344. });
  345. upload.render({
  346. elem: '#btn_add_judgment'
  347. ,url: '/admin/examquestion/import_judgment/'
  348. ,accept:'file'
  349. ,acceptMime:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  350. ,exts:'xlsx'
  351. ,field:'excel_file'
  352. ,multiple:false
  353. ,done: function(res){
  354. if (res.code == 0) {
  355. table.reload('exam_question_datagrid',{});
  356. } else {
  357. layer.msg(res.msg);
  358. }
  359. }
  360. ,error: function(){
  361. layer.msg('导入失败');
  362. }
  363. });
  364. upload.render({
  365. elem: '#btn_add_discuss'
  366. ,url: '/admin/examquestion/import_discuss/'
  367. ,accept:'file'
  368. ,acceptMime:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  369. ,exts:'xlsx'
  370. ,field:'excel_file'
  371. ,multiple:false
  372. ,done: function(res){
  373. if (res.code == 0) {
  374. table.reload('exam_question_datagrid',{});
  375. } else {
  376. layer.msg(res.msg);
  377. }
  378. }
  379. ,error: function(){
  380. layer.msg('导入失败');
  381. }
  382. });
  383. $('#btn_download_single').on('click', function () {
  384. layui.view.download("/static/xls/单选题导入模版.xlsx");
  385. });
  386. $('#btn_download_multiple').on('click', function () {
  387. layui.view.download("/static/xls/多选题导入模版.xlsx");
  388. });
  389. $('#btn_download_fill').on('click', function () {
  390. layui.view.download("/static/xls/填空题导入模版.xlsx");
  391. });
  392. $('#btn_download_judgment').on('click', function () {
  393. layui.view.download("/static/xls/判断题导入模版.xlsx");
  394. });
  395. $('#btn_download_discuss').on('click', function () {
  396. layui.view.download("/static/xls/论述题导入模版.xlsx");
  397. });
  398. $('#btn_download').on('click', function(){
  399. $.get({
  400. url: '/admin/examquestion/export/',
  401. dataType: 'json',
  402. data: _params,
  403. success: function (res) {
  404. // var title = ['题型', '试题内容', '科目', '章节', '难度', '分数', '单选选项', '多选选项', '正确答案', '判断答案', '填空答案', '解析'];
  405. // var data = [];
  406. // for (var i = 0; i < res.data.length; i++) {
  407. // var res_item = res.data[i];
  408. // var data_item = [
  409. // res_item.type_text,
  410. // res_item.title,
  411. // res_item.subject_text,
  412. // res_item.chapter_text,
  413. // res_item.difficulty_text,
  414. // res_item.scores,
  415. // ];
  416. // if (res_item.type == 1 || res_item.type == 2) {
  417. // data_item.push('');
  418. // data_item.push('');
  419. // data_item.push('');
  420. // data_item.push('');
  421. // data_item.push('');
  422. // } else if (res_item.type == 3) {
  423. // data_item.push('');
  424. // data_item.push('');
  425. // data_item.push('');
  426. // data_item.push('');
  427. // if ( res_item.items.length >= 1) {
  428. // var option = res_item.items[0];
  429. // data_item.push(option.content);
  430. // }
  431. // } else if (res_item.type == 4) {
  432. // data_item.push('');
  433. // data_item.push('');
  434. // data_item.push('');
  435. // if (res_item.judgment == '1') {
  436. // data_item.push('正确');
  437. // } else {
  438. // data_item.push('错误');
  439. // }
  440. // data_item.push('');
  441. // } else if (res_item.type == 5) {
  442. // data_item.push('');
  443. // data_item.push('');
  444. // data_item.push(res_item.discuss_answer);
  445. // data_item.push('');
  446. // data_item.push('');
  447. // } else {
  448. // data_item.push('');
  449. // data_item.push('');
  450. // data_item.push('');
  451. // data_item.push('');
  452. // data_item.push('');
  453. // }
  454. // data_item.push(res_item.analysis);
  455. // data.push(data_item);
  456. // if (res_item.type == 1 || res_item.type == 2) {
  457. // for (var n = 0; n < res_item.items.length; n++) {
  458. // var option = res_item.items[n];
  459. // var option_item = ['', '', '', '', '', ''];
  460. // if (res_item.type == 1) {
  461. // option_item.push(option.content);
  462. // option_item.push('');
  463. // } else {
  464. // option_item.push('');
  465. // option_item.push(option.content);
  466. // }
  467. // if (option.right == true) {
  468. // option_item.push('正确');
  469. // } else {
  470. // option_item.push('');
  471. // }
  472. // option_item.push('');
  473. // option_item.push('');
  474. // option_item.push('');
  475. // data.push(option_item);
  476. // }
  477. // } else if (res_item.type == 3) {
  478. // for (var n = 1; n < res_item.items.length; n++) {
  479. // var option = res_item.items[n];
  480. // var option_item = ['', '', '', '', '', '', '', '', '', ''];
  481. // option_item.push(option.content);
  482. // option_item.push('');
  483. // data.push(option_item);
  484. // }
  485. // }
  486. // }
  487. // table.exportFile(
  488. // title,
  489. // data,
  490. // '试题.xls'
  491. // );
  492. }
  493. })
  494. });
  495. });
  496. </script>
  497. </body>
  498. </html>