liu tao 1 rok pred
rodič
commit
5e5ddcae59

+ 6 - 0
apps/api/admin/examquestion/views.py

@@ -52,6 +52,12 @@ class ExamQuestionViewSet(CustomModelViewSet):
             SysLog.objects.addnew(request.user, SysLog.INSERT, u"删除试题库试题,id=%d" % instance.id)
         return response_ok()
 
+    @action(methods=['get'], detail=False)
+    def export(self, request):
+        queryset = self.filter_queryset(self.queryset)
+        serializer = self.get_serializer(queryset, many=True)
+        return response_ok(serializer.data)
+
     @action(methods=['post'], detail=False)
     def import_single(self, request):
         file = request.FILES.get('excel_file')

+ 122 - 0
uis/admin/examquestion/index.html

@@ -91,6 +91,9 @@
                                   </dl>
                                 </div>
                               </button>
+                            <button class="layui-btn layui-btn-sm" id="btn_download">
+                                <i class="layui-icon layui-icon-download-circle"></i>导出
+                            </button>
                         </div>
                         <form class="layui-form" lay-filter="query-form-element">
                             <div class="seach_items">
@@ -102,6 +105,16 @@
                                 <input type="text" name="title" autocomplete="off" class="layui-input"
                                        placeholder="名称"/>
                             </div>
+                            <div class="seach_items">
+                                <select name="type">
+                                    <option value="" selected>题型</option>
+                                    <option value="1">单选题</option>
+                                    <option value="2">多选题</option>
+                                    <option value="3">填空题</option>
+                                    <option value="4">判断题</option>
+                                    <option value="5">论述题</option>
+                                </select>
+                            </div>
                         </form>
                         <div style="clear: both;"></div>
                     </div>
@@ -129,6 +142,8 @@
 
 <script src="../../layuiadmin/layui/layui.js"></script>
 <script>
+    var _params = '';
+
     layui.config({
         base: '../../../layuiadmin/' //静态资源所在路径
     }).extend({
@@ -213,6 +228,7 @@
                 where: data.field
                 , page: {curr: 1}
             });
+            _params = data.field;
             layer.closeAll();
             return false
         });
@@ -348,6 +364,112 @@
         $('#btn_download_discuss').on('click', function () {
             layui.view.download("/static/xls/论述题导入模版.xlsx");
         });
+
+        $('#btn_download').on('click', function(){
+        $.get({
+            url: '/admin/examquestion/export/',
+            dataType: 'json',
+            data: _params,
+            success: function (res) {
+                var title = ['题型', '试题内容', '科目', '章节', '难度', '分数', '单选选项', '多选选项', '正确答案', '判断答案', '填空答案', '解析'];
+                var data = [];
+                for (var i = 0; i < res.data.length; i++) {
+                    var res_item = res.data[i];
+                    var data_item = [
+                        res_item.type_text,
+                        res_item.title,
+                        res_item.subject_text,
+                        res_item.chapter_text,
+                        res_item.difficulty_text,
+                        res_item.scores,
+                    ];
+                    if (res_item.type == 1 || res_item.type == 2) {
+                        data_item.push('');
+                        data_item.push('');
+                        data_item.push('');
+                        data_item.push('');
+                        data_item.push('');
+                    } else if (res_item.type == 3) {
+                        data_item.push('');
+                        data_item.push('');
+                        data_item.push('');
+                        data_item.push('');
+                        if ( res_item.items.length >= 1) {
+                            var option = res_item.items[0];
+                            data_item.push(option.content);
+                        }
+
+                    } else if (res_item.type == 4) {
+                        data_item.push('');
+                        data_item.push('');
+                        data_item.push('');
+                        if (res_item.judgment == '1') {
+                            data_item.push('正确');
+                        } else {
+                            data_item.push('错误');
+                        }
+                        data_item.push('');
+                    } else if (res_item.type == 5) {
+                        data_item.push('');
+                        data_item.push('');
+                        data_item.push(res_item.discuss_answer);
+                        data_item.push('');
+                        data_item.push('');
+                    } else {
+                        data_item.push('');
+                        data_item.push('');
+                        data_item.push('');
+                        data_item.push('');
+                        data_item.push('');
+                    }
+
+                    data_item.push(res_item.analysis);
+
+                    data.push(data_item);
+
+                    if (res_item.type == 1 || res_item.type == 2) {
+                        for (var n = 0; n < res_item.items.length; n++) {
+                            var option = res_item.items[n];
+                            var option_item = ['', '', '', '', '', ''];
+                            if (res_item.type == 1) {
+                                option_item.push(option.content);
+                                option_item.push('');
+                            } else {
+                                option_item.push('');
+                                option_item.push(option.content);
+                            }
+                            if (option.right == true) {
+                                option_item.push('正确');
+                            } else {
+                                option_item.push('');
+                            }
+                            option_item.push('');
+                            option_item.push('');
+                            option_item.push('');
+
+                            data.push(option_item);
+                        }
+                    } else if (res_item.type == 3) {
+                        for (var n = 1; n < res_item.items.length; n++) {
+                            var option = res_item.items[n];
+                            var option_item = ['', '', '', '', '', '', '', '', '', ''];
+                            option_item.push(option.content);
+                            option_item.push('');
+
+                            data.push(option_item);
+                        }
+                    }
+                }
+
+
+                table.exportFile(
+                    title,
+                    data,
+                    '试题.xls'
+                );
+            }
+        })
+    });
     });
 
 </script>