123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <template>
- <div style="padding: 20px">
- <h2 style="text-align: center">
- 游戏题目{{ questionId ? "编辑" : "添加" }}
- </h2>
- <el-form ref="form" :model="form" label-width="90px" size="mini">
- <el-form-item label="题目:">
- <el-input v-model="form.title" placeholder="请输入实例名(必填)">
- <el-select slot="prepend" v-model="form.optType" style="width:100px" placeholder="请选择">
- <el-option label="单选题" value="1" />
- <el-option label="多选题" value="2" />
- <el-option label="判断题" value="3" />
- </el-select>
- </el-input>
- </el-form-item>
- <el-form-item v-if="questionId!==undefined" label="正确选项:">
- <!-- <el-input v-model="form.option"></el-input> -->
- <!-- filterable可搜索 multiple可多选 default-first-option回车可选-->
- <el-select
- v-model="form.rightAnswer"
- multiple
- filterable
- default-first-option
- placeholder="请选择"
- >
- <el-option
- v-for="item in rightList"
- :key="item"
- :label="item"
- :value="item"
- />
- </el-select>
- </el-form-item>
- <el-form-item style="text-align:center">
- <el-button type="primary" @click="onSubmit">确定</el-button>
- <el-button @click="$router.go(-1)">返回</el-button>
- </el-form-item>
- <el-form-item v-if="questionId!==undefined" label="答案:">
- <el-button type="primary" @click="onAddAnswer">添加答案</el-button>
- </el-form-item>
- </el-form>
-
- <ul style="list-style-type: none;margin:10px 0 10px -2px">
- <li v-for="answer in answerList" :key="answer.answerId" class="answerli">
- <div style="flex:1;width: 100%;overflow: hidden;display: flex;" @click="handleEdit(answer)">
- <span style="width:45px">{{ answer.option }}</span>
- <span style="flex:1">{{ answer.content }}</span>
- </div>
- <el-popconfirm
- style="width:15px"
- icon="el-icon-info"
- icon-color="red"
- title="确定删除这个答案吗?"
- @onConfirm="handleDelete(answer)"
- >
- <el-button slot="reference" type="text" class="deleteQuestion" style="color:red">×</el-button>
- </el-popconfirm>
- </li>
- </ul>
- <QuestionDrawer :dialog="dialog" :question-id="questionId" :answer-id="answerId" :game-id="gameId" @handleCloseDrawer="handleCloseDrawer" @handleEditDrawer="handleEditDrawer" />
- </div>
- </template>
- <script>
-
- import { saveQuestion, UpdateQuestion, getQuestionDetail } from '@/api/question'
- import { getAnswerList, deleteAnswer } from '@/api/answer'
- import QuestionDrawer from '@/components/Question/drawer.vue'
-
- export default {
- components: {
- QuestionDrawer
- },
- props: {
- gameId: String,
- questionId: String
- },
- data() {
- return {
- form: {
- title: undefined,
- optType: undefined,
- rightAnswer: undefined,
- gameId: undefined,
- questionId: undefined
- },
- // 答案列表(包括选项 内容 特征词列表)
- answerList: [],
- answerId: undefined,
- // 正确答案数据源
- rightList: [],
- dialog: false
- }
- },
- watch: {
- // 用于点击左边改变右边的页面
- questionId: function() {
- if (this.gameId) {
- this.form.gameId = this.gameId
- }
- if (this.questionId) {
- this.rightList = []
- getQuestionDetail(this.questionId).then((res) => {
- this.form = res.data
- this.form.rightAnswer = res.data.rightAnswer?.split(',')
- })
- this.handleAnswerList()
- } else {
- this.form = {
- title: undefined,
- optType: undefined,
- gameId: undefined,
- rightAnswer: undefined,
- questionId: undefined
- }
- this.answerList = []
- this.rightList = []
- }
- },
- gameId() {
- if (this.gameId) {
- this.form.gameId = this.gameId
- }
- }
- },
- methods: {
- // 添加答案
- onAddAnswer() {
- this.dialog = true
- this.answerId = undefined
- },
- // 编辑答案
- handleEdit(val) {
- this.dialog = true
- this.answerId = val.answerId
- },
- // 删除答案
- handleDelete(val) {
- deleteAnswer(val.answerId).then((res) => {
- this.$message('删除答案成功')
- this.handleAnswerList()
- })
- },
- // 关闭答案抽屉
- handleCloseDrawer() {
- this.dialog = false
- this.answerId = undefined
- },
- // 编辑答案抽屉成功重新查询列表
- handleEditDrawer(val) {
- this.handleCloseDrawer()
- this.handleAnswerList()
- },
- // 查询当前问题答案列表
- handleAnswerList() {
- getAnswerList({ questionId: this.questionId }).then((res) => {
- this.answerList = res.data.records
- // 给正确答按下拉菜单数据源赋值
- const list = []
- this.answerList.map(item => {
- list.push(item.option)
- })
- this.rightList = list
- })
- },
- // 转换特征数组数据格式
- handleToString(list) {
- const nameList = []
- list?.map(item => {
- nameList.push(item.name)
- })
- return nameList.toString()
- },
- onSubmit() {
- if (this.form.title && this.form.optType) {
- this.form.gameId = this.gameId
- if (this.questionId) {
- if (this.form.rightAnswer) {
- this.form.rightAnswer = this.form.rightAnswer.toString()
- }
- UpdateQuestion(this.form, this.questionId).then((res) => {
- this.$message('修改问题成功')
- // 告诉父页面实例表需要刷新并且关闭当前组件
- this.$emit('handleRefreshQuestion', true)
- this.form.rightAnswer = res.data.rightAnswer?.split(',')
- })
- } else {
- saveQuestion(this.form).then((res) => {
- this.$message('添加问题成功')
- // 告诉父页面实例表需要刷新并且关闭当前组件
- this.$emit('handleRefreshQuestion', true)
- this.$emit('handleEditQuestion', res.data.questionId)
- })
- }
- } else {
- this.$message('请输入问题名称和题型')
- }
- }
- }
- }
- </script>
- <style lang="scss">
- .answerli {
- width: 100%;
- overflow: hidden;
- display: flex;
- line-height:40px;
- background-color: white;
- .deleteQuestion{
- display: none;
- }
- }
- .answerli:hover {
- background-color: rgb(230, 247, 255);
- }
- .answerli:hover .deleteQuestion{
- display: block
- }
- </style>
|