|
|
@ -3,7 +3,7 @@ |
|
|
|
<el-container> |
|
|
|
<el-header class="header"> |
|
|
|
<el-text class="header-text">抢点班作业后台管理</el-text> |
|
|
|
<el-button class="header-button" type="primary" text style="float: right;">退出登录</el-button> |
|
|
|
<el-button class="header-button" type="primary" text style="float: right;" @click="logout">退出登录</el-button> |
|
|
|
</el-header> |
|
|
|
<el-main class="main"> |
|
|
|
<div class="main-title"> |
|
|
@ -30,11 +30,12 @@ |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="关联文章"> |
|
|
|
<el-autocomplete v-model="articleTitle" :fetch-suggestions="queryArticleList" placeholder="请输入" |
|
|
|
@select="handleSelectArticle" clearable/> |
|
|
|
@select="handleSelectArticle" clearable /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="关联直播"> |
|
|
|
<el-select v-model="form.LiveId" placeholder="请选择" style="width: 100%" clearable @change="handleLiveChange"> |
|
|
|
<el-option v-for="item in live" :key="item.id" :label="item.name" :value="item.id"/> |
|
|
|
<el-select v-model="form.LiveId" placeholder="请选择" style="width: 100%" clearable |
|
|
|
@change="handleLiveChange"> |
|
|
|
<el-option v-for="item in live" :key="item.id" :label="item.name" :value="item.id" /> |
|
|
|
</el-select> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="选择类型"> |
|
|
@ -76,7 +77,7 @@ |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div class="submit"> |
|
|
|
<el-button type="primary" :disabled="!form.Name||!form.picker" @click="onSubmit">确认</el-button> |
|
|
|
<el-button type="primary" :disabled="!form.Name || !form.picker" @click="onSubmit">确认</el-button> |
|
|
|
</div> |
|
|
|
</el-form> |
|
|
|
</div> |
|
|
@ -88,12 +89,16 @@ |
|
|
|
|
|
|
|
<script lang="ts" setup> |
|
|
|
import { ref, onMounted, computed } from 'vue' |
|
|
|
import { useRouter,useRoute } from 'vue-router'; |
|
|
|
import { useRouter, useRoute } from 'vue-router'; |
|
|
|
import AddWorkApi from '../api/AddWorkApi'; |
|
|
|
import _ from 'lodash'; |
|
|
|
import dayjs from 'dayjs'; |
|
|
|
import ClassListApi from '../api/ClassListApi'; |
|
|
|
import { ElMessage } from 'element-plus'; |
|
|
|
import LoginApi from '../api/LoginApi'; |
|
|
|
|
|
|
|
import { useTokenStore } from '../stores/token'; |
|
|
|
import { useUserStore } from '../stores/user'; |
|
|
|
|
|
|
|
const router = useRouter(); |
|
|
|
const options = ref([ |
|
|
@ -109,8 +114,8 @@ const options = ref([ |
|
|
|
]); |
|
|
|
|
|
|
|
const route = useRoute(); |
|
|
|
const id=ref(route.params.id) |
|
|
|
console.log(id.value+'============') |
|
|
|
const id = ref(route.params.id) |
|
|
|
console.log(id.value + '============') |
|
|
|
|
|
|
|
// 用于存储获取到的作业数据 |
|
|
|
const homeworkData = ref<{ |
|
|
@ -126,7 +131,9 @@ const homeworkData = ref<{ |
|
|
|
id: string; |
|
|
|
name: string; |
|
|
|
}; |
|
|
|
status: number; |
|
|
|
form: FormItemType[]; |
|
|
|
|
|
|
|
}>({ |
|
|
|
name: '', |
|
|
|
startDate: '', |
|
|
@ -140,6 +147,7 @@ const homeworkData = ref<{ |
|
|
|
id: '', |
|
|
|
name: '' |
|
|
|
}, |
|
|
|
status: 0, |
|
|
|
form: [] |
|
|
|
}); |
|
|
|
|
|
|
@ -170,24 +178,28 @@ const form = ref({ |
|
|
|
Questions: [] |
|
|
|
}); |
|
|
|
|
|
|
|
// 新增一个变量用于标识是否发布,这里先设为false表示未发布 |
|
|
|
const isPublished = ref(0); |
|
|
|
onMounted(async () => { |
|
|
|
try { |
|
|
|
const response = await ClassListApi.getClassListOne(id.value); |
|
|
|
homeworkData.value = response.data; |
|
|
|
console.log(homeworkData.value) |
|
|
|
form.value.Name = homeworkData.value.name; |
|
|
|
// 根据后端返回数据设置发布状态变量的值 |
|
|
|
isPublished.value = homeworkData.value.status; |
|
|
|
|
|
|
|
const start = dayjs(homeworkData.value.startDate).format('YYYY-MM-DD'); |
|
|
|
const end = dayjs(homeworkData.value.endDate).format('YYYY-MM-DD'); |
|
|
|
form.value.picker = [start, end]; |
|
|
|
|
|
|
|
if (homeworkData.value.article && homeworkData.value.article.title) { |
|
|
|
articleTitle.value = homeworkData.value.article.title; |
|
|
|
} else if (homeworkData.value.live && homeworkData.value.live.name) { |
|
|
|
form.value.LiveId = homeworkData.value.live.name; |
|
|
|
} |
|
|
|
form.value.ClubType = homeworkData.value.clubType; |
|
|
|
const processFormData = () => { |
|
|
|
const start = dayjs(homeworkData.value.startDate).format('YYYY-MM-DD'); |
|
|
|
const end = dayjs(homeworkData.value.endDate).format('YYYY-MM-DD'); |
|
|
|
form.value.picker = [start, end]; |
|
|
|
|
|
|
|
if (homeworkData.value.article && homeworkData.value.article.title) { |
|
|
|
articleTitle.value = homeworkData.value.article.title; |
|
|
|
} else if (homeworkData.value.live && homeworkData.value.live.name) { |
|
|
|
form.value.LiveId = homeworkData.value.live.name; |
|
|
|
} |
|
|
|
form.value.ClubType = homeworkData.value.clubType; |
|
|
|
const processFormData = () => { |
|
|
|
const newQuestions = []; |
|
|
|
homeworkData.value.form.forEach((formItem: FormItemType) => { |
|
|
|
// 解析content字段中的JSON字符串为实际的数组对象 |
|
|
@ -231,26 +243,26 @@ const onSubmit = () => { |
|
|
|
if (form.value.LiveId) { |
|
|
|
// 如果form.value.liveid有值,优先使用liveid,清空ArticleId(假设后端不接受同时传这两个值且以liveid为准,可根据实际情况调整) |
|
|
|
form.value.ArticleId = ''; |
|
|
|
} else if (form.value.ArticleId) { |
|
|
|
} else if (form.value.ArticleId) { |
|
|
|
// 如果手动选择了关联文章,使用手动选择后更新的文章id(form.value.ArticleId) |
|
|
|
} else if (homeworkData.value.article && homeworkData.value.article.id) { |
|
|
|
} else if (homeworkData.value.article && homeworkData.value.article.id) { |
|
|
|
// 如果没有手动选择,使用后端传回的数据中的关联文章id(homeworkData.value.article.id) |
|
|
|
form.value.ArticleId = homeworkData.value.article.id; |
|
|
|
} |
|
|
|
if (typeof id.value === 'string') { |
|
|
|
} |
|
|
|
if (typeof id.value === 'string') { |
|
|
|
form.value.id = id.value; |
|
|
|
} |
|
|
|
} |
|
|
|
ClassListApi.editWork(form.value) |
|
|
|
.then((response) => { |
|
|
|
console.log(response); |
|
|
|
ElMessage.success('编辑成功'); |
|
|
|
router.push('/list') |
|
|
|
}) |
|
|
|
.catch((error) => { |
|
|
|
console.error('编辑失败', error); |
|
|
|
ElMessage.error('编辑失败'); |
|
|
|
}); |
|
|
|
console.log(id.value+'--------------') |
|
|
|
.then((response) => { |
|
|
|
console.log(response); |
|
|
|
ElMessage.success('编辑成功'); |
|
|
|
router.push('/list') |
|
|
|
}) |
|
|
|
.catch((error) => { |
|
|
|
console.error('编辑失败', error); |
|
|
|
ElMessage.error('编辑失败'); |
|
|
|
}); |
|
|
|
console.log(id.value + '--------------') |
|
|
|
console.log(form.value) |
|
|
|
} |
|
|
|
const back = () => { |
|
|
@ -328,44 +340,62 @@ const getQuestionTypeText = (type) => { |
|
|
|
}; |
|
|
|
|
|
|
|
const addSingleChoice = () => { |
|
|
|
questions.value.push({ |
|
|
|
type: 1, // 假设1代表单选,和后端格式对应起来 |
|
|
|
description: '', |
|
|
|
content: [{ "id": "", "text": "" },{ "id": "", "text": "" }] |
|
|
|
}); |
|
|
|
if (isPublished.value === 1) { |
|
|
|
ElMessage.warning('处于发布中,不能添加新题目'); |
|
|
|
} else { |
|
|
|
questions.value.push({ |
|
|
|
type: 1, // 假设1代表单选,和后端格式对应起来 |
|
|
|
description: '', |
|
|
|
content: [{ "id": "", "text": "" }, { "id": "", "text": "" }] |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
const addMultipleChoice = () => { |
|
|
|
questions.value.push({ |
|
|
|
type: 2, // 假设2代表多选,和后端格式对应起来 |
|
|
|
description: '', |
|
|
|
content: [{ "id": "", "text": "" },{ "id": "", "text": "" }] |
|
|
|
}); |
|
|
|
if (isPublished.value === 1) { |
|
|
|
ElMessage.warning('处于发布中,不能添加新题目'); |
|
|
|
} else { |
|
|
|
questions.value.push({ |
|
|
|
type: 2, // 假设2代表多选,和后端格式对应起来 |
|
|
|
description: '', |
|
|
|
content: [{ "id": "", "text": "" }, { "id": "", "text": "" }] |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
const addBlank = () => { |
|
|
|
questions.value.push({ |
|
|
|
type: 3, // 假设3代表简答题,和后端格式对应起来 |
|
|
|
description: '', |
|
|
|
content: [{ "id": "", "text": "" }] |
|
|
|
}); |
|
|
|
if (isPublished.value === 1) { |
|
|
|
ElMessage.warning('处于发布中,不能添加新题目'); |
|
|
|
} else { |
|
|
|
questions.value.push({ |
|
|
|
type: 3, // 假设3代表简答题,和后端格式对应起来 |
|
|
|
description: '', |
|
|
|
content: [{ "id": "", "text": "" }] |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const addOption = (questionIndex) => { |
|
|
|
const currentQuestion = questions.value[questionIndex]; |
|
|
|
// 如果当前题目没有content属性,则初始化一个空数组 |
|
|
|
if (!currentQuestion.content) { |
|
|
|
currentQuestion.content = []; |
|
|
|
} |
|
|
|
currentQuestion.content.push({ id: "", text: "" }); |
|
|
|
const currentQuestion = questions.value[questionIndex]; |
|
|
|
// 如果当前题目没有content属性,则初始化一个空数组 |
|
|
|
if (!currentQuestion.content) { |
|
|
|
currentQuestion.content = []; |
|
|
|
} |
|
|
|
currentQuestion.content.push({ id: "", text: "" }); |
|
|
|
}; |
|
|
|
const removeOption = (questionIndex, optionIndex) => { |
|
|
|
const currentQuestion = questions.value[questionIndex]; |
|
|
|
currentQuestion.content.splice(optionIndex, 1); |
|
|
|
const currentQuestion = questions.value[questionIndex]; |
|
|
|
currentQuestion.content.splice(optionIndex, 1); |
|
|
|
}; |
|
|
|
|
|
|
|
const removeQuestion = (questionIndex) => { |
|
|
|
questions.value.splice(questionIndex, 1); |
|
|
|
if(isPublished.value === 1){ |
|
|
|
ElMessage.warning('处于发布中,不能删除题目'); |
|
|
|
}else{ |
|
|
|
questions.value.splice(questionIndex, 1); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// 计算属性,用于生成序号前缀 |
|
|
@ -390,6 +420,19 @@ onMounted(() => { |
|
|
|
isHovered.value = Array(questions.value.length).fill(false); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
//退出 |
|
|
|
function logout() { |
|
|
|
//清除登录信息 |
|
|
|
const tokenStore = useTokenStore(); |
|
|
|
const userStore = useUserStore(); |
|
|
|
tokenStore.clear(); |
|
|
|
userStore.clear(); |
|
|
|
LoginApi.logout().then(res => { |
|
|
|
console.log(res) |
|
|
|
}) |
|
|
|
router.push('/') |
|
|
|
} |
|
|
|
</script> |
|
|
|
|
|
|
|
<style scoped> |
|
|
|