index.html 20 KB

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