瀏覽代碼

增加题型

罗永浩 5 月之前
父節點
當前提交
7a0ae4c728

+ 32 - 25
addons/admin/src/views/exam/component/ExcelImport.vue

@@ -65,31 +65,32 @@
                 <template slot="default">
                     <p><strong>Excel格式要求:</strong></p>
                     CREATE TABLE `lev_ad` (
-                        `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
-                        `title` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '广告标题',
-                        `position` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '广告位置:1-主页轮播图,2-会员中心占位图',
-                        `cover` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '广告图片',
-                        `type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '广告访问:1-站内链接,2-站外链接,3-其他小程序,4-微信视频号',
-                        `description` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '广告描述',
-                        `url` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '广告链接/小程序链接/视频号链接',
-                        `link_type` tinyint(1) DEFAULT '1' COMMENT '跳转类型:1-默认,2-小程序',
-                        `mp_appid` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '跳转小程序APPID',
-                        `width` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '广告宽度',
-                        `height` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '广告高度',
-                        `start_time` int(10) unsigned NOT NULL COMMENT '开始时间',
-                        `end_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '结束时间',
-                        `view_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '广告点击次数',
-                        `status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '状态:1在用 2停用',
-                        `sort` smallint(5) unsigned NOT NULL DEFAULT '125' COMMENT '排序',
-                        `create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间',
-                        `update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
-                        `mark` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '有效标识(1正常 0删除)',
-                        PRIMARY KEY (`id`) USING BTREE,
-                        KEY `title` (`title`) USING BTREE,
-                        KEY `ad_sort_id` (`position`) USING BTREE
-                      ) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='广告管理表';                    <p>• 第一行必须是标题行,支持以下列名:题目类型、题目、选项A~F(或答案A~F)、正确答案、解析、分数</p>
+                    `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+                    `title` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '广告标题',
+                    `position` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '广告位置:1-主页轮播图,2-会员中心占位图',
+                    `cover` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '广告图片',
+                    `type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '广告访问:1-站内链接,2-站外链接,3-其他小程序,4-微信视频号',
+                    `description` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '广告描述',
+                    `url` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '广告链接/小程序链接/视频号链接',
+                    `link_type` tinyint(1) DEFAULT '1' COMMENT '跳转类型:1-默认,2-小程序',
+                    `mp_appid` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '跳转小程序APPID',
+                    `width` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '广告宽度',
+                    `height` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '广告高度',
+                    `start_time` int(10) unsigned NOT NULL COMMENT '开始时间',
+                    `end_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '结束时间',
+                    `view_num` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '广告点击次数',
+                    `status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '状态:1在用 2停用',
+                    `sort` smallint(5) unsigned NOT NULL DEFAULT '125' COMMENT '排序',
+                    `create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间',
+                    `update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
+                    `mark` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '有效标识(1正常 0删除)',
+                    PRIMARY KEY (`id`) USING BTREE,
+                    KEY `title` (`title`) USING BTREE,
+                    KEY `ad_sort_id` (`position`) USING BTREE
+                    ) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
+                    ROW_FORMAT=DYNAMIC COMMENT='广告管理表'; <p>• 第一行必须是标题行,支持以下列名:题目类型、题目、选项A~F(或答案A~F)、正确答案、解析、分数</p>
                     <p>• 列顺序可以任意排列,系统会自动识别各列</p>
-                    <p>• 题目类型:单选题、多选题、判断题、填空题、问答题</p>
+                    <p>• 题目类型:单选题、多选题、判断题、填空题、问答题、写作题、应用题、计算题、证明题、解答题、论述题</p>
                     <p>• 正确答案:单选题填选项字母(A/B/C/D/E/F),多选题用逗号分隔(A,B),判断题填对/错,填空题填答案,问答题可留空</p>
                     <p>• 分数:每道题的分值,建议单选题2-5分,多选题5-10分,判断题1-2分,填空题3-8分,问答题10-20分</p>
                     <p>• 支持富文本格式</p>
@@ -211,7 +212,13 @@ export default {
                 ['多选题', '这是一道多选题示例?', '选项A内容', '选项B内容', '选项C内容', '选项D内容', '', '', 'A,B', '这是多选题的解析', '10'],
                 ['判断题', '这是一道判断题示例?', '', '', '', '', '', '', '对', '这是判断题的解析', '2'],
                 ['填空题', '这是一道填空题示例,答案是___', '', '', '', '', '', '', '答案内容', '这是填空题的解析', '8'],
-                ['问答题', '这是一道问答题示例?', '', '', '', '', '', '', '', '这是问答题的解析', '15']
+                ['问答题', '这是一道问答题示例?', '', '', '', '', '', '', '', '这是问答题的解析', '15'],
+                ['写作题', '这是一道写作题示例?', '', '', '', '', '', '', '', '这是写作题的解析', '20'],
+                ['应用题', '这是一道应用题示例?', '', '', '', '', '', '', '', '这是应用题的解析', '25'],
+                ['计算题', '这是一道计算题示例?', '', '', '', '', '', '', '', '这是计算题的解析', '30'],
+                ['证明题', '这是一道证明题示例?', '', '', '', '', '', '', '', '这是证明题的解析', '35'],
+                ['解答题', '这是一道解答题示例?', '', '', '', '', '', '', '', '这是解答题的解析', '40'],
+                ['论述题', '这是一道论述题示例?', '', '', '', '', '', '', '', '这是论述题的解析', '45']
             ];
 
             // 创建工作簿

+ 19 - 5
addons/admin/src/views/exam/component/TopicManager.vue

@@ -89,11 +89,8 @@
             <el-form :model="form" :rules="rules" ref="formRef" label-width="120px">
                 <el-form-item label="题目类型" prop="topic_type">
                     <el-select v-model="form.topic_type" placeholder="请选择题型" @change="changeTopicType">
-                        <el-option label="单选题" value="单选题"></el-option>
-                        <el-option label="多选题" value="多选题"></el-option>
-                        <el-option label="判断题" value="判断题"></el-option>
-                        <el-option label="填空题" value="填空题"></el-option>
-                        <el-option label="简答题" value="简答题"></el-option>
+                        <el-option v-for="type in topicTypes" :key="type.value" :label="type.label" :value="type.value">
+                        </el-option>
                     </el-select>
                 </el-form-item>
 
@@ -249,6 +246,7 @@ export default {
         return {
             loading: false,
             topics: [],
+            topicTypes: [], // 题目类型列表
             showForm: false,
             isEdit: false,
             editingIndex: -1,
@@ -296,6 +294,9 @@ export default {
             imageDialogImage: ''
         };
     },
+    mounted() {
+        this.loadTopicTypes();
+    },
     watch: {
         visible(val) {
             if (val) {
@@ -306,6 +307,19 @@ export default {
         },
     },
     methods: {
+        async loadTopicTypes() {
+            try {
+                const res = await this.$http.get('/topics/topicTypes');
+                if (res.data.code === 0) {
+                    this.topicTypes = res.data.data;
+                } else {
+                    this.$message.error(res.data.msg);
+                }
+            } catch (error) {
+                this.$message.error('加载题目类型失败');
+                console.error(error);
+            }
+        },
         async loadTopics() {
             this.loading = true;
             try {

+ 25 - 0
app/Http/Controllers/Admin/TopicController.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace App\Http\Controllers\Admin;
 
 use App\Services\Exam\TopicService;
@@ -32,4 +33,28 @@ class TopicController extends Backend
         return $this->service->sort($param);
     }
 
+    /**
+     * 获取题目类型列表
+     */
+    public function getTopicTypes()
+    {
+        $types = [
+            ['label' => '单选题', 'value' => '单选题'],
+            ['label' => '多选题', 'value' => '多选题'],
+            ['label' => '判断题', 'value' => '判断题'],
+            ['label' => '填空题', 'value' => '填空题'],
+            ['label' => '简答题', 'value' => '简答题'],
+            ['label' => '写作题', 'value' => '写作题'],
+            ['label' => '应用题', 'value' => '应用题'],
+            ['label' => '计算题', 'value' => '计算题'],
+            ['label' => '证明题', 'value' => '证明题'],
+            ['label' => '解答题', 'value' => '解答题'],
+            ['label' => '论述题', 'value' => '论述题'],
+        ];
+        return response()->json([
+            'code' => 0,
+            'msg' => '获取成功',
+            'data' => $types
+        ]);
+    }
 }

+ 6 - 8
app/Services/Api/ExamService.php

@@ -191,9 +191,9 @@ class ExamService extends BaseService
             return $datas;
         }
 
-        $prefix = env('DB_PREFIX','lev_');
+        $prefix = env('DB_PREFIX', 'lev_');
         $query = $this->getQuery($params);
-        $list = $query->with(['error'])->whereRaw("{$prefix}a.accurate_count < {$prefix}a.answer_count")->where('b.id','>',0)
+        $list = $query->with(['error'])->whereRaw("{$prefix}a.accurate_count < {$prefix}a.answer_count")->where('b.id', '>', 0)
             ->select(['a.id', 'a.user_id', 'a.paper_id', 'a.score', 'a.accurate_count', 'a.answer_count', 'b.name', 'b.type', 'b.scene_type', 'b.topic_count', 'b.score_total', 'b.is_charge', 'a.create_time', 'a.answer_times', 'a.status'])
             ->orderBy('a.create_time', 'desc')
             ->paginate($pageSize > 0 ? $pageSize : 9999999);
@@ -202,7 +202,7 @@ class ExamService extends BaseService
             foreach ($list['data'] as &$item) {
                 $item['error_count'] = $item['answer_count'] - $item['accurate_count'];
                 $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
-                $item['error_id'] = isset($item['error']) && isset($item['error']['topic_id'])? $item['error']['topic_id'] : 0;
+                $item['error_id'] = isset($item['error']) && isset($item['error']['topic_id']) ? $item['error']['topic_id'] : 0;
             }
         }
 
@@ -407,7 +407,7 @@ class ExamService extends BaseService
         $rid = isset($params['rid']) ? $params['rid'] : 0;
         $tid = isset($params['tid']) ? $params['tid'] : 0;
         $isSubmit = isset($params['is_submit']) ? $params['is_submit'] : 1;
-        $answer = isset($params['answer']) && $params['answer']? str_replace("\n",'\n', $params['answer']) : '';
+        $answer = isset($params['answer']) && $params['answer'] ? str_replace("\n", '\n', $params['answer']) : '';
         $answerImage = isset($params['answer_image']) ? $params['answer_image'] : '';
         $answerType = isset($params['answer_type']) && $params['answer_type'] ? $params['answer_type'] : 2;
         $remainTime = isset($params['remain_time']) && $params['remain_time'] ? $params['remain_time'] : 0;
@@ -443,7 +443,7 @@ class ExamService extends BaseService
         $topicInfo = ExamTopicModel::where(['id' => $tid, 'paper_id' => $paperId, 'status' => 1, 'mark' => 1])->first();
         $topicType = isset($topicInfo['topic_type']) ? trim($topicInfo['topic_type']) : '';
         $topicScore = isset($topicInfo['score']) ? intval($topicInfo['score']) : 0;
-        $topicName = isset($topicInfo['topic_name']) && $topicInfo['topic_name']? str_replace("\n",'\n', $topicInfo['topic_name']) : '';
+        $topicName = isset($topicInfo['topic_name']) && $topicInfo['topic_name'] ? str_replace("\n", '\n', $topicInfo['topic_name']) : '';
         $topicShowType = isset($topicInfo['show_type']) ? $topicInfo['show_type'] : 1;
         $correctAnswer = isset($topicInfo['correct_answer']) ? $topicInfo['correct_answer'] : '';
         if (empty($topicInfo) || empty($topicType) || empty($topicName)) {
@@ -543,7 +543,7 @@ class ExamService extends BaseService
             } else {
                 $topicData['accurate'] = 0;
             }
-//      }else if (in_array($topicType, ['简答题','计算题','阅读理解'])){
+            //      }else if (in_array($topicType, ['简答题','计算题','阅读理解'])){
         } else {
             // 图片答案AI验证
             if ($answerType == 1) {
@@ -626,7 +626,6 @@ class ExamService extends BaseService
                 RedisService::clear($cacheKey . '_lock');
                 $this->error = '答题失败,请刷新后重新提交';
                 return false;
-
             }
         }
         // 答题题目数据
@@ -714,5 +713,4 @@ class ExamService extends BaseService
 
         return $data;
     }
-
 }

+ 1 - 0
routes/web.php

@@ -244,6 +244,7 @@ Route::post('/topics/edit', [TopicController::class, 'edit']);
 Route::post('/topics/delete', [TopicController::class, 'delete']);
 Route::post('/topics/status', [TopicController::class, 'status']);
 Route::post('/topics/sort', [TopicController::class, 'sort']);
+Route::get('/topics/topicTypes', [TopicController::class, 'getTopicTypes']);
 
 // videos
 Route::get('/videos/index', [VideoController::class, 'index']);