index.html 19 KB

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