@ -2,7 +2,8 @@
< main class = "question-bank app-container" >
< header class = "page-head" > < div > < h1 > 题库管理 < / h1 > < p > 维护平台公共题库 , 供教师组卷使用 < / p > < / div > < div class = "actions" > < el -button type = "primary" :icon ="Plus" @click ="openEditor()" > 添 加 题 目 < / el -button > < el -button type = "success" :icon ="Upload" :loading ="loading" @click ="pickImport" > 批 量 导 入 < / el -button > < el -dropdown trigger = "click" @command ="downloadTemplate" > < el -button type = "success" :icon ="Download" > 下载模板 < el -icon class = "el-icon--right" > < ArrowDown / > < / e l - i c o n > < / e l - b u t t o n > < t e m p l a t e # d r o p d o w n > < e l - d r o p d o w n - m e n u > < e l - d r o p d o w n - i t e m c o m m a n d = " w o r d " > W o r d 导 入 模 板 < / e l - d r o p d o w n - i t e m > < e l - d r o p d o w n - i t e m c o m m a n d = " e x c e l " > E x c e l 导 入 模 板 < / e l - d r o p d o w n - i t e m > < / e l - d r o p d o w n - m e n u > < / t e m p l a t e > < / e l - d r o p d o w n > < / d i v > < / h e a d e r >
< section class = "toolbar" > < el -select v-model ="query.type" clearable placeholder="题型:请选择" @change="load"><el-option v-for="item in types" :key="item.value" :label="item.label" :value="item.value" /></el-select><el-input v-model="query.keyword" placeholder="请输入题干关键词" clearable @keyup.enter="load" /><el-button type="primary" :icon="Search" @click="load" > 搜 索 < / el -button > < input ref = "fileInput" type = "file" accept = ".docx,.xlsx,.xls" hidden @change ="importFile" / > < / section >
< el -table v-loading ="loading" :data="questions" class="data-table"><el-table-column type="index" label="序号" width="78" /><el-table-column label="题干" min-width="420" show-overflow-tooltip><template #default="{ row }"><span>{{ plainHtml(row.stem) }}</span></template></el-table-column><el-table-column label="题型" width="120"><template #default="{ row }"><el-tag>{{ typeName[row.type] }}</el-tag></template></el-table-column><el-table-column label="题目来源" width="140"><template #default><el-tag type="success">平台题库</el-tag></template></el-table-column><el-table-column label="操作" width="190" fixed="right"><template #default="{ row }"><el-button link type="primary" @click="openEditor(row)">编辑</el-button><el-button link type="primary" @click="openEditor(row)">查看</el-button><el-button link type="danger" @click="remove(row)" > 删 除 < / el -button > < / template > < /el-table-column><template #empty><el-empty description="暂无题目" / > < / template > < / e l - t a b l e >
< el -table v-loading ="loading" :data="pagedQuestions" class="data-table"><el-table-column type="index" label="序号" width="78" /><el-table-column label="题干" min-width="420" show-overflow-tooltip><template #default="{ row }"><span>{{ plainHtml(row.stem) }}</span></template></el-table-column><el-table-column label="题型" width="120"><template #default="{ row }"><el-tag>{{ typeName[row.type] }}</el-tag></template></el-table-column><el-table-column label="题目来源" width="140"><template #default><el-tag type="success">平台题库</el-tag></template></el-table-column><el-table-column label="操作" width="190" fixed="right"><template #default="{ row }"><el-button link type="primary" @click="openEditor(row)">编辑</el-button><el-button link type="primary" @click="openEditor(row)">查看</el-button><el-button link type="danger" @click="remove(row)" > 删 除 < / el -button > < / template > < /el-table-column><template #empty><el-empty description="暂无题目" / > < / template > < / e l - t a b l e >
< div class = "pagination-wrap" > < el -pagination v -model :current-page ="pagination.currentPage" v -model :page-size ="pagination.pageSize" :total ="pagination.total" : page -sizes = " [ 10 , 20 , 50 , 100 ] " layout = "total, sizes, prev, pager, next, jumper" background / > < / div >
< p class = "bank-note" > 说明 : 平台题库为系统默认题库 , 所有教师可见 ; 教师仅可查看平台题目 , 编辑删除自己新增的题目 。 < / p >
< el -dialog v -model = " editorVisible " : title = "form.id ? '编辑题目' : '新增题目'" width = "min(1180px, 94vw)" top = "4vh" class = "question-editor-dialog" destroy -on -close >
@ -11,7 +12,7 @@
< div class = "rich-row" > < label > 题干 < / label > < Editor v -model = " form.stem " :min-height ="154" / > < / div >
< template v-if ="isChoice" > < div class = "option-block" > < label > 选项 < / label > < div class = "option-list" > < div v-for ="(option, index) in form.options" :key="index" class="option-row"><div class="option-letter"><el-radio v-if="form.type === 'SINGLE'" v-model="singleAnswer" :label="optionLabel(index)" class="answer-control" /><el-checkbox v-else v-model="answers" :label="optionLabel(index)" class="answer-control" /><span class="letter-tag">{{ optionLabel(index) }}</span></div><Editor v-model="option.content" :min-height="92" /><el-button v-if="form.options.length > 2" link type="danger" :icon="Delete" @click="removeOption(index)" class="remove-btn" /></div><el-button type="primary" plain :icon="Plus" @click="addOption" class="add-option-btn">新增选项</el-button></div></div><div class="rich-row analysis-row" > < label > 答案解析 ( 选填 ) < / label > < Editor v -model = " form.analysis " :min-height ="112" / > < / div > < / template >
< template v -else -if = " form.type = = = ' TRUE_FALSE ' " > < div class = "tf-block" > < label > 选项 < / label > < div class = "tf-options" > < el -radio -group v-model ="form.answer" class="tf-radio-group"><el-radio-button :label="true" class="tf-radio">对</el-radio-button><el-radio-button :label="false" class="tf-radio">错</el-radio-button></el-radio-group></div></div><div class="rich-row analysis-row" > < label > 答案解析 ( 选填 ) < / label > < Editor v -model = " form.analysis " :min-height ="112" / > < / div > < / template >
< template v-else > < div class = "material-row" > < el -upload :show-file-list ="false" :http-request ="uploadMaterial" accept = ".pdf,.doc,.docx,.png,.jpg,.jpeg "> < el -button type = "primary" plain :loading ="uploading" > 上传简答题资料 < / e l - b u t t o n > < / e l - u p l o a d > < s p a n v - i f = " f o r m . a t t a c h m e n t N a m e " c l a s s = " m a t e r i a l - n a m e " > { { f o r m . a t t a c h m e n t N a m e } } < / s p a n > < / d i v > < d i v c l a s s = " r i c h - r o w " > < l a b e l > 参 考 答 案 < / l a b e l > < E d i t o r v - m o d e l = " f o r m . a n s w e r " : m i n - h e i g h t = " 1 8 0 " / > < / d i v > < d i v c l a s s = " r i c h - r o w a n a l y s i s - r o w " > < l a b e l > 答 案 解 析 ( 选 填 ) < / l a b e l > < E d i t o r v - m o d e l = " f o r m . a n a l y s i s " : m i n - h e i g h t = " 1 1 2 " / > < / d i v > < / t e m p l a t e >
< template v-else > < div class = "material-row" > < el -upload :show-file-list ="false" :http-request ="uploadMaterial" accept = ".pdf,.doc,.docx,.png,.jpg,.jpeg ,.xls,.xlsx "> < el -button type = "primary" plain :loading ="uploading" > 上传简答题资料 < / e l - b u t t o n > < / e l - u p l o a d > < s p a n v - i f = " f o r m . a t t a c h m e n t N a m e " c l a s s = " m a t e r i a l - n a m e " > { { f o r m . a t t a c h m e n t N a m e } } < / s p a n > < / d i v > < d i v c l a s s = " r i c h - r o w " > < l a b e l > 参 考 答 案 < / l a b e l > < E d i t o r v - m o d e l = " f o r m . a n s w e r " : m i n - h e i g h t = " 1 8 0 " / > < / d i v > < d i v c l a s s = " r i c h - r o w a n a l y s i s - r o w " > < l a b e l > 答 案 解 析 ( 选 填 ) < / l a b e l > < E d i t o r v - m o d e l = " f o r m . a n a l y s i s " : m i n - h e i g h t = " 1 1 2 " / > < / d i v > < / t e m p l a t e >
< / div > < template # footer > < el -button @click ="editorVisible=false" > 取 消 < / el -button > < el -button type = "primary" :loading ="saving" @click ="save" > 确 定 < / el -button > < / template >
< / e l - d i a l o g >
@ -29,11 +30,11 @@ import * as api from "@/api/exam";
const types = [ { label : "单选题" , value : "SINGLE" } , { label : "多选题" , value : "MULTIPLE" } , { label : "判断题" , value : "TRUE_FALSE" } , { label : "简答题" , value : "SHORT_ANSWER" } ] ;
const typeName = Object . fromEntries ( types . map ( ( item ) => [ item . value , item . label ] ) ) ;
const loading = ref ( false ) ; const saving = ref ( false ) ; const uploading = ref ( false ) ; const aiLoading = ref ( false ) ; const questions = ref ( [ ] ) ; const editorVisible = ref ( false ) ; const aiVisible = ref ( false ) ; const preview = ref ( [ ] ) ; const fileInput = ref ( ) ;
const query = reactive ( { type : "" , taskKey : "" , keyword : "" } ) ; const form = reactive ( emptyQuestion ( ) ) ; const aiForm = reactive ( { taskKey : "" , type : "SINGLE" , count : 5 , requirement : "" } ) ;
const isChoice = computed ( ( ) => [ "SINGLE" , "MULTIPLE" ] . includes ( form . type ) ) ; const answers = computed ( { get : ( ) => Array . isArray ( form . answer ) ? form . answer : [ ] , set : ( value ) => { form . answer = value ; } } ) ; const singleAnswer = computed ( { get : ( ) => Array . isArray ( form . answer ) ? form . answer [ 0 ] || "" : "" , set : ( value ) => { form . answer = value ? [ value ] : [ ] ; } } ) ;
const query = reactive ( { type : "" , taskKey : "" , keyword : "" } ) ; const pagination = reactive ( { currentPage : 1 , pageSize : 10 , total : 0 } ) ; const form = reactive ( emptyQuestion ( ) ) ; const aiForm = reactive ( { taskKey : "" , type : "SINGLE" , count : 5 , requirement : "" } ) ;
const isChoice = computed ( ( ) => [ "SINGLE" , "MULTIPLE" ] . includes ( form . type ) ) ; const pagedQuestions = computed ( ( ) => { const start = ( pagination . currentPage - 1 ) * pagination . pageSize ; return questions . value . slice ( start , start + pagination . pageSize ) ; } ) ; const answers = computed ( { get : ( ) => Array . isArray ( form . answer ) ? form . answer : [ ] , set : ( value ) => { form . answer = value ; } } ) ; const singleAnswer = computed ( { get : ( ) => Array . isArray ( form . answer ) ? form . answer [ 0 ] || "" : "" , set : ( value ) => { form . answer = value ? [ value ] : [ ] ; } } ) ;
function emptyQuestion ( ) { return { id : null , taskKey : "" , type : "SINGLE" , stem : "<p></p>" , options : [ "A" , "B" , "C" , "D" ] . map ( ( label ) => ( { label , content : "<p></p>" } ) ) , answer : [ ] , analysis : "<p></p>" , attachmentName : "" , attachmentUrl : "" } ; }
function plainHtml ( value ) { return String ( value || "" ) . replace ( /<[^>]+>/g , "" ) . replace ( / /g , " " ) ; }
async function load ( ) { loading . value = true ; try { questions . value = ( await api . getPlatformQuestions ( query ) ) . data || [ ] ; } finally { loading . value = false ; } } async function init ( ) { await load ( ) ; } onMounted ( init ) ;
async function load ( ) { loading . value = true ; try { questions . value = ( await api . getPlatformQuestions ( query ) ) . data || [ ] ; pagination . total = questions . value . length ; pagination . currentPage = 1 ; } finally { loading . value = false ; } } async function init ( ) { await load ( ) ; } onMounted ( init ) ;
function openEditor ( row ) { Object . assign ( form , row ? JSON . parse ( JSON . stringify ( row ) ) : emptyQuestion ( ) ) ; if ( ! Array . isArray ( form . answer ) && isChoice . value ) form . answer = [ ] ; editorVisible . value = true ; } function openAi ( ) { aiForm . taskKey = "" ; preview . value = [ ] ; aiVisible . value = true ; }
function optionLabel ( index ) { return String . fromCharCode ( 65 + index ) ; }
function addOption ( ) { if ( form . options . length >= 26 ) return ElMessage . warning ( "最多支持 26 个选项" ) ; form . options . push ( { label : optionLabel ( form . options . length ) , content : "<p></p>" } ) ; }
@ -53,6 +54,6 @@ function displayAnswer(value) { return Array.isArray(value) ? value.join("、")
. page - head { display : flex ; align - items : center ; justify - content : space - between ; gap : 24 px ; margin - bottom : 18 px ; }
. page - head h1 { margin : 0 ; font - size : 22 px ; font - weight : 700 ; color : # 1 f2937 ; } . page - head p { margin : 7 px 0 0 ; color : # 6 b7280 ; font - size : 13 px ; } . actions { display : flex ; flex - wrap : wrap ; justify - content : flex - end ; gap : 10 px ; }
. toolbar { display : flex ; align - items : center ; flex - wrap : wrap ; gap : 10 px ; padding : 14 px ; margin - bottom : 16 px ; border : 1 px solid # e5e7eb ; border - radius : 10 px ; background : # ffffff ; } . toolbar . el - select { width : 210 px ; } . toolbar . el - input { width : min ( 300 px , 30 vw ) ; }
. data - table { background : # ffffff ; border - radius : 10 px ; } . bank- note { margin : 14 px auto 0 ; max - width : 1180 px ; color : # 6 b7280 ; font - size : 13 px ; line - height : 1.8 ; text - align : center ; }
. data - table { background : # ffffff ; border - radius : 10 px ; } . pagination- wrap { display : flex ; justify - content : flex - end ; margin - top : 16 px ; } . bank- note { margin : 14 px auto 0 ; max - width : 1180 px ; color : # 6 b7280 ; font - size : 13 px ; line - height : 1.8 ; text - align : center ; }
. editor - shell { padding : 4 px 8 px 12 px ; color : # 1 f2937 ; } . editor - project { display : flex ; align - items : center ; gap : 14 px ; margin - bottom : 18 px ; } . editor - project > span { width : 62 px ; color : # 4 b5563 ; } . editor - project . el - select { width : 420 px ; } . type - switch { display : flex ; align - items : center ; gap : 12 px ; margin : 4 px 0 22 px ; } . type - switch > span { width : 62 px ; color : # 4 b5563 ; font - size : 15 px ; text - align : right ; } . type - select { width : 200 px ; } . rich - row , . option - block { display : grid ; grid - template - columns : 120 px minmax ( 0 , 1 fr ) ; gap : 12 px ; margin - bottom : 22 px ; align - items : start ; } . rich - row > label , . option - block > label , . tf - block > label { padding - top : 10 px ; color : # 4 b5563 ; font - size : 15 px ; text - align : right ; } . option - list { display : grid ; gap : 12 px ; } . option - row { display : grid ; grid - template - columns : 56 px minmax ( 0 , 1 fr ) 36 px ; align - items : start ; gap : 10 px ; } . option - letter { display : flex ; flex - direction : column ; align - items : center ; gap : 6 px ; padding - top : 12 px ; } . option - letter . answer - control { margin - right : 0 ; } . letter - tag { display : inline - flex ; align - items : center ; justify - content : center ; width : 26 px ; height : 26 px ; border - radius : 50 % ; background : # eff6ff ; color : # 2563 eb ; font - size : 13 px ; font - weight : 600 ; border : 1 px solid # bfdbfe ; } . remove - btn { padding - top : 16 px ; color : # 9 ca3af ; } . add - option - btn { justify - self : start ; margin - top : 4 px ; } . tf - block { display : grid ; grid - template - columns : 120 px minmax ( 0 , 1 fr ) ; gap : 12 px ; margin : 18 px 0 30 px ; align - items : center ; } . tf - options { display : flex ; gap : 16 px ; } . tf - radio - group { display : flex ; gap : 16 px ; } . tf - radio { padding : 10 px 36 px ; font - size : 15 px ; border - radius : 8 px ; } . material - row { display : flex ; align - items : center ; gap : 14 px ; margin : 6 px 0 22 px 132 px ; } . material - name { color : # 6 b7280 ; } . preview - alert { margin - bottom : 12 px ; } . preview - item { padding : 10 px 4 px ; border - bottom : 1 px solid # e5e7eb ; line - height : 1.7 ; color : # 1 f2937 ; } . editor - shell : deep ( . ql - container ) { min - height : 88 px ; font - size : 15 px ; color : # 1 f2937 ; } . editor - shell : deep ( . ql - editor ) { min - height : 74 px ; color : # 1 f2937 ; } . editor - shell : deep ( . ql - toolbar ) { background : # fff ; border - color : # e5e7eb ; } . editor - shell : deep ( . ql - editor . ql - blank : : before ) { color : # 9 ca3af ; font - style : normal ; }
< / style >