【新增】试卷任务前端
This commit is contained in:
@@ -0,0 +1,352 @@
|
||||
<template>
|
||||
<Dialog
|
||||
v-model="visible"
|
||||
:title="isUpdate ? '修改试卷方案' : '添加试卷方案'"
|
||||
width="460"
|
||||
center
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
label-width="80px"
|
||||
@submit.prevent=""
|
||||
>
|
||||
<!-- 知识点 -->
|
||||
<el-form-item label="知识点" prop="pointName">
|
||||
<el-tree
|
||||
ref="treeRef"
|
||||
:data="pointOptions"
|
||||
show-checkbox
|
||||
node-key="value"
|
||||
default-expand-all
|
||||
:props="{ label: 'label', children: 'children' }"
|
||||
highlight-current
|
||||
:disabled="isUpdate"
|
||||
@check="handleCheckChange"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 题型 -->
|
||||
<el-form-item label="题型" prop="spName">
|
||||
<el-select v-model="form.spName" placeholder="请选择题型" clearable :disabled="isUpdate">
|
||||
<el-option
|
||||
v-for="item in CourseOptions"
|
||||
:key="item"
|
||||
:label="item"
|
||||
:value="item"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 难度 -->
|
||||
<el-form-item label="难度" prop="quLevel">
|
||||
<el-select v-model="form.quLevel" placeholder="请选择难度" :disabled="isUpdate">
|
||||
<el-option label="全部" :value="3" />
|
||||
<el-option label="简单" :value="0" />
|
||||
<el-option label="一般" :value="1" />
|
||||
<el-option label="困难" :value="2" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 关键字 -->
|
||||
<el-form-item label="关键字" prop="keyword">
|
||||
<el-select
|
||||
v-model="form.keyword"
|
||||
placeholder="请选择关键字"
|
||||
multiple
|
||||
clearable
|
||||
:disabled="isUpdate"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in keyOptions"
|
||||
:key="item"
|
||||
:label="item"
|
||||
:value="item"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 数量、分数 -->
|
||||
<el-form-item label="试题数量" prop="quNumbers">
|
||||
<el-input-number v-model="form.quNumbers" placeholder="请输入试题数量" :disabled="isUpdate" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="每题分数" prop="quScores">
|
||||
<el-input-number v-model="form.quScores" placeholder="请输入每题分数" :disabled="isUpdate" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="小计分数" prop="subtotalScore">
|
||||
<el-input-number v-model="form.subtotalScore" :disabled="true" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="可用数量">
|
||||
<el-text>{{ availableCount }}</el-text>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="visible = false">取 消</el-button>
|
||||
<el-button type="primary" :loading="loading" @click="save" :disabled="isUpdate">保存</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, nextTick } from 'vue'
|
||||
import {
|
||||
addScheme,
|
||||
updateScheme,
|
||||
getCourseList,
|
||||
getKeyList,
|
||||
getPoints,
|
||||
fetchQuestionCount
|
||||
} from '@/api/system/scheme'
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
const emit = defineEmits(['done'])
|
||||
const props = defineProps({
|
||||
taskSpecialty: String,
|
||||
taskId: String
|
||||
})
|
||||
|
||||
/** --------- 状态定义 --------- **/
|
||||
const visible = defineModel({ type: Boolean });
|
||||
|
||||
const isUpdate = ref(false)
|
||||
const loading = ref(false)
|
||||
const formRef = ref()
|
||||
const treeRef = ref()
|
||||
const availableCount = ref<number | string>('')
|
||||
|
||||
const CourseOptions = ref<string[]>([])
|
||||
const keyOptions = ref<string[]>([])
|
||||
|
||||
// 扁平接口返回的原始结构
|
||||
interface PointRaw {
|
||||
spId: number
|
||||
spName: string
|
||||
parentId: number
|
||||
orderNum?: number
|
||||
ancestors?: string
|
||||
[key: string]: any
|
||||
}
|
||||
// 构造给 el-tree 用的节点结构
|
||||
interface TreeNode extends PointRaw {
|
||||
label: string
|
||||
value: number
|
||||
children: TreeNode[]
|
||||
}
|
||||
|
||||
const pointOptions = ref<TreeNode[]>([])
|
||||
|
||||
const form = ref<{
|
||||
schemeId?: string
|
||||
taskId?: string
|
||||
spName?: string
|
||||
quLevel?: number
|
||||
keyword: string[]
|
||||
pointName: string[]
|
||||
quNumbers?: number
|
||||
quScores?: number
|
||||
subtotalScore?: number
|
||||
taskSpecialty?: string
|
||||
}>({
|
||||
keyword: [],
|
||||
pointName: []
|
||||
})
|
||||
|
||||
const rules = reactive({
|
||||
spName: [{ required: true, message: '请选择题型', trigger: 'change' }],
|
||||
quLevel: [{ required: true, message: '请选择难度', trigger: 'change' }],
|
||||
pointName: [{ required: true, message: '请选择知识点', trigger: 'change' }],
|
||||
quNumbers: [{ required: true, message: '请输入试题数量', trigger: 'blur' }],
|
||||
quScores: [{ required: true, message: '请输入每题分数', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
/** --------- 打开弹窗 --------- **/
|
||||
const open = async (type: 'create' | 'update', data?: any) => {
|
||||
visible.value = true
|
||||
isUpdate.value = type === 'update'
|
||||
|
||||
// 1. 并行拉下拉所需的选项
|
||||
const [courses, keywords] = await Promise.all([
|
||||
getCourseList(),
|
||||
getKeyList()
|
||||
])
|
||||
CourseOptions.value = courses
|
||||
keyOptions.value = keywords
|
||||
|
||||
// 2. 拉知识点并建树
|
||||
await loadPointTree()
|
||||
|
||||
// 3. 填表单
|
||||
if (isUpdate.value && data) {
|
||||
form.value = {
|
||||
...data,
|
||||
keyword: data.keywords?.split(',') || [],
|
||||
pointName: data.pointNames?.split(',') || [],
|
||||
taskId: props.taskId,
|
||||
taskSpecialty: props.taskSpecialty
|
||||
}
|
||||
|
||||
// 4. 等树节点数据都生效了,再设置默认选中
|
||||
await nextTick()
|
||||
treeRef.value?.setCheckedKeys(form.value.pointName)
|
||||
|
||||
calcSubtotal()
|
||||
fetchCount()
|
||||
} else {
|
||||
// 新增时重置
|
||||
form.value = {
|
||||
schemeId: undefined,
|
||||
taskId: props.taskId,
|
||||
spName: undefined,
|
||||
quLevel: undefined,
|
||||
keyword: [],
|
||||
pointName: [],
|
||||
quNumbers: undefined,
|
||||
quScores: undefined,
|
||||
subtotalScore: undefined,
|
||||
taskSpecialty: props.taskSpecialty
|
||||
}
|
||||
}
|
||||
|
||||
// 清除校验
|
||||
await nextTick()
|
||||
formRef.value?.clearValidate?.()
|
||||
}
|
||||
|
||||
/** --------- 拉取扁平知识点并建树 --------- **/
|
||||
async function loadPointTree() {
|
||||
try {
|
||||
const res = await getPoints(props.taskSpecialty)
|
||||
// 兼容:getPoints 有可能直接返回数组,也可能返回 { data: [] }
|
||||
const raw: PointRaw[] = Array.isArray(res)
|
||||
? res
|
||||
: Array.isArray((res as any).data)
|
||||
? (res as any).data
|
||||
: []
|
||||
|
||||
pointOptions.value = buildTree(raw)
|
||||
} catch (e: any) {
|
||||
message.error('获取知识点失败:' + (e.message || e))
|
||||
pointOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
/** 扁平 -> 树 */
|
||||
function buildTree(data: PointRaw[]): TreeNode[] {
|
||||
const idMap = new Map<number, TreeNode>()
|
||||
data.forEach(item => {
|
||||
idMap.set(item.spId, {
|
||||
...item,
|
||||
label: item.spName,
|
||||
value: item.spId,
|
||||
children: []
|
||||
})
|
||||
})
|
||||
|
||||
const tree: TreeNode[] = []
|
||||
data.forEach(item => {
|
||||
const node = idMap.get(item.spId)!
|
||||
const parent = idMap.get(item.parentId)
|
||||
if (parent) {
|
||||
parent.children.push(node)
|
||||
} else {
|
||||
tree.push(node)
|
||||
}
|
||||
})
|
||||
|
||||
// (可选)按 orderNum 排序
|
||||
const sortRecursively = (nodes: TreeNode[]) => {
|
||||
nodes.sort((a, b) => (a.orderNum ?? 0) - (b.orderNum ?? 0))
|
||||
nodes.forEach(n => sortRecursively(n.children))
|
||||
}
|
||||
sortRecursively(tree)
|
||||
|
||||
return tree
|
||||
}
|
||||
|
||||
/** 计算小计 */
|
||||
const calcSubtotal = () => {
|
||||
const n = Number(form.value.quNumbers ?? 0)
|
||||
const s = Number(form.value.quScores ?? 0)
|
||||
form.value.subtotalScore = n * s
|
||||
}
|
||||
|
||||
/** 选中回调 */
|
||||
const handleCheckChange = () => {
|
||||
form.value.pointName = treeRef.value.getCheckedKeys()
|
||||
|
||||
}
|
||||
|
||||
/** 拉取可用题目数量 */
|
||||
const fetchCount = async () => {
|
||||
const res = await fetchQuestionCount({
|
||||
taskSpecialty: props.taskSpecialty,
|
||||
pointIds: form.value.pointName, // 知识点
|
||||
spName: form.value.spName, // 题型
|
||||
quLevel: form.value.quLevel, // 难度
|
||||
keyword: form.value.keyword // **关键字**,加上这一行
|
||||
|
||||
})
|
||||
availableCount.value = res ?? 0
|
||||
}
|
||||
|
||||
/** 保存 */
|
||||
const save = async () => {
|
||||
|
||||
if (Number(availableCount.value) === 0) {
|
||||
message.warning('当前条件下没有可用的试题,请调整条件后再试');
|
||||
return;
|
||||
}
|
||||
await formRef.value.validate()
|
||||
loading.value = true
|
||||
try {
|
||||
const payload = {
|
||||
...form.value,
|
||||
keywords: form.value.keyword.join(','),
|
||||
pointNames: form.value.pointName.join(',')
|
||||
}
|
||||
const fn = isUpdate.value ? updateScheme : addScheme
|
||||
await fn(payload)
|
||||
emit('done')
|
||||
visible.value = false
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
watch(
|
||||
() => [
|
||||
form.value.spName,
|
||||
form.value.quLevel,
|
||||
form.value.pointName,
|
||||
form.value.keyword,
|
||||
props.taskSpecialty
|
||||
],
|
||||
([spName, quLevel, pointName, keyword, taskSpecialty]) => {
|
||||
// 当题型、难度、专业、知识点、关键字都有值时,才去请求可用题目数
|
||||
if (
|
||||
spName &&
|
||||
quLevel !== null &&
|
||||
quLevel !== undefined &&
|
||||
taskSpecialty &&
|
||||
pointName!== null &&
|
||||
keyword!== null // **关键字也要有选项**
|
||||
// 如果你也想加关键字限制:&& keyword.length > 0
|
||||
) {
|
||||
fetchCount()
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
watch(
|
||||
() => [form.value.quNumbers, form.value.quScores],
|
||||
() => {
|
||||
calcSubtotal()
|
||||
}
|
||||
)
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
@@ -0,0 +1,82 @@
|
||||
<!-- 搜索表单 -->
|
||||
<template>
|
||||
<ele-card :body-style="{ paddingBottom: '2px' }">
|
||||
<el-form label-width="72px" @keyup.enter="search" @submit.prevent="">
|
||||
<el-row :gutter="8">
|
||||
<el-col :lg="6" :md="12" :sm="12" :xs="24">
|
||||
<el-form-item label="题型">
|
||||
<el-input
|
||||
clearable
|
||||
v-model.trim="form.spName"
|
||||
placeholder="请输入"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :lg="6" :md="12" :sm="12" :xs="24">
|
||||
<el-form-item label="难度">
|
||||
<el-input
|
||||
clearable
|
||||
v-model.trim="form.quLevel"
|
||||
placeholder="请输入"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :lg="6" :md="12" :sm="12" :xs="24">
|
||||
<el-form-item label="关键字">
|
||||
<el-input
|
||||
clearable
|
||||
v-model.trim="form.keywords"
|
||||
placeholder="请输入"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :lg="6" :md="12" :sm="12" :xs="24">
|
||||
<el-form-item label="知识点">
|
||||
<el-input
|
||||
clearable
|
||||
v-model.trim="form.pointNames"
|
||||
placeholder="请输入"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :lg="6" :md="12" :sm="12" :xs="24">
|
||||
<el-form-item label-width="16px">
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</ele-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useFormData } from '@/utils/use-form-data';
|
||||
|
||||
const emit = defineEmits(['search']);
|
||||
|
||||
/** 表单数据 */
|
||||
const [form, resetFields] = useFormData({
|
||||
taskId: '',
|
||||
spName: '',
|
||||
quLevel: '',
|
||||
keywords: '',
|
||||
pointNames: '',
|
||||
quNumbers: '',
|
||||
quScores: '',
|
||||
subtotalScore: ''
|
||||
});
|
||||
|
||||
/** 搜索 */
|
||||
const search = () => {
|
||||
emit('search', { ...form });
|
||||
};
|
||||
|
||||
/** 重置 */
|
||||
const reset = () => {
|
||||
resetFields();
|
||||
search();
|
||||
};
|
||||
</script>
|
||||
|
@@ -0,0 +1,204 @@
|
||||
<template>
|
||||
|
||||
<ContentWrap>
|
||||
<el-form
|
||||
class="-mb-15px"
|
||||
:model="queryParams"
|
||||
ref="queryFormRef"
|
||||
:inline="true"
|
||||
label-width="68px"
|
||||
>
|
||||
|
||||
<el-form-item>
|
||||
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
||||
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
@click="openEdit('create')"
|
||||
v-hasPermi="['system:sms-channel:create']"
|
||||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新增</el-button
|
||||
>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<el-table v-loading="loading" :data="list">
|
||||
<el-table-column label="方案ID" align="center" prop="taskId" />
|
||||
<el-table-column label="题型" align="center" prop="spName" />
|
||||
<el-table-column label="难度" align="center" prop="quLevel">
|
||||
<template #default="scope">
|
||||
<span v-if="scope.row.quLevel === '0'">简单</span>
|
||||
<span v-else-if="scope.row.quLevel === '1'">一般</span>
|
||||
<span v-else-if="scope.row.quLevel === '2'">困难</span>
|
||||
<span v-else-if="scope.row.quLevel === '3'">全部</span>
|
||||
<span v-else>未知</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
|
||||
<!-- <el-table-column label="关键字" align="center" prop="keywords" /> -->
|
||||
<el-table-column label="试题数量" align="center" prop="quNumbers"/>
|
||||
|
||||
<el-table-column label="每题分数" align="center" prop="quScores"/>
|
||||
<el-table-column label="小计分数" align="center" prop="subtotalScore"/>
|
||||
|
||||
<el-table-column label="操作" align="center">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openEdit('update', scope.row)"
|
||||
v-hasPermi="['system:sms-channel:update']"
|
||||
>
|
||||
查看
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
@click="handleDelete(scope.row.schemeId)"
|
||||
v-hasPermi="['system:sms-channel:delete']"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!-- 分页 -->
|
||||
<Pagination
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNo"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</ContentWrap>
|
||||
|
||||
|
||||
|
||||
|
||||
<scheme-edit v-model="showEdit" v-if="showEdit" :form-data="props.formData" :task-specialty="props.taskSpecialty" :task-Id="props.taskId" ref="taskEditRef" @done="reload"/>
|
||||
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
|
||||
import * as SmsChannelApi from '@/api/system/scheme';
|
||||
|
||||
import SchemeEdit from './components/step-edit.vue';
|
||||
import SchemeSearch from './components/step-search.vue';
|
||||
|
||||
|
||||
defineOptions({ name: 'SystemSmsChannel' })
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
const props = defineProps({
|
||||
taskSpecialty: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
taskId: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
formData:{
|
||||
type: Object,
|
||||
default: null
|
||||
}
|
||||
})
|
||||
|
||||
/** 当前编辑数据 */
|
||||
const current = ref<object>();
|
||||
|
||||
/** 是否显示编辑弹窗 */
|
||||
const showEdit = ref(false);
|
||||
const showOpenTemplate = ref(false);
|
||||
|
||||
const showAdd = ref(false);
|
||||
|
||||
|
||||
|
||||
const smsChannelFormRef = ref()
|
||||
const taskEditRef = ref()
|
||||
const taskAddRef = ref()
|
||||
const taskTempRef = ref()
|
||||
|
||||
|
||||
|
||||
const loading = ref(false) // 列表的加载中
|
||||
const total = ref(0) // 列表的总页数
|
||||
const list = ref([]) // 列表的数据
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
signature: undefined,
|
||||
status: undefined,
|
||||
createTime: [],
|
||||
taskId: props.taskId
|
||||
})
|
||||
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await SmsChannelApi.pageSchemes(queryParams)
|
||||
console.log(res)
|
||||
list.value = res
|
||||
total.value = res.total
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNo = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value.resetFields()
|
||||
handleQuery()
|
||||
}
|
||||
const reload = () => {
|
||||
getList()
|
||||
}
|
||||
/** 添加/修改操作 */
|
||||
const formRef = ref();
|
||||
|
||||
|
||||
const openEdit = (type: string, row?: object) => {
|
||||
showEdit.value = true
|
||||
current.value = row
|
||||
nextTick(() => {
|
||||
taskEditRef.value?.open(type, row)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
// 发起删除
|
||||
console.log(id+"idididid")
|
||||
await SmsChannelApi.removeScheme(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
|
||||
</script>
|
Reference in New Issue
Block a user