123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- <template>
- <div class="exercise">
- <div class="list">
- <el-button icon="el-icon-back" @click="back">返回练习管理</el-button>
- <div class="list-title">课上练习</div>
- <div class="exercise-list">
- <ul>
- <li v-for="(item, i) in index_list" :key="i" :class="['exercise-item', { active: i === curIndex }]">
- <SvgIcon icon-class="child" :size="20" />
- <span class="item-name nowrap-ellipsis" @click="selectExerciseItem(i)">
- {{ i + 1 }}. {{ exerciseNames[item.type] }}
- </span>
- <SvgIcon icon-class="copy" class="pointer" :size="10" @click="copy(i)" />
- </li>
- </ul>
- </div>
- <div class="list-operate">
- <el-button type="primary">批量导入</el-button>
- <el-button type="primary" @click="addQuestionToExercise('select', 'single')">新建</el-button>
- </div>
- </div>
- <CreateMain
- ref="createMain"
- :cur-index="curIndex"
- :index-list="index_list"
- @selectExerciseItem="selectExerciseItem"
- @setUp="setUp"
- @setPreview="setPreview"
- @deleteQuestion="deleteQuestion"
- @createNewQuestion="createNewQuestion"
- />
- <div class="preview" :style="{ minHeight: preview ? '300px' : 'auto' }">
- <div class="preview-header">
- <span class="quick-preview">快捷预览:</span>
- <div class="preview-right">
- <template v-if="preview">
- <span class="preview-button plain" @click="refreshPreviewData">
- <SvgIcon icon-class="loop" size="14" /><span>刷新</span>
- </span>
- <span class="preview-button"><SvgIcon icon-class="eye" /><span>完整预览</span></span>
- <span class="preview-button plain" @click="setPreview"><SvgIcon icon-class="close" />关闭预览</span>
- </template>
- <template v-else>
- <span class="preview-button" @click="setPreview"><SvgIcon icon-class="eye" />预览</span>
- </template>
- </div>
- </div>
- <div class="preview-content">
- <component :is="curPreviewPage" v-if="preview" :data="previewData" />
- </div>
- </div>
- </div>
- </template>
- <script>
- import { exerciseNames } from '../data/common';
- import { AddQuestionToExercise, DeleteQuestion, GetExerciseQuestionIndexList, GetQuestionInfo } from '@/api/exercise';
- import CreateMain from './components/create.vue';
- import SelectPreview from '@/views/exercise_questions/preview/SelectPreview.vue';
- import JudgePreview from '@/views/exercise_questions/preview/JudgePreview.vue';
- import MatchingPreview from '@/views/exercise_questions/preview/MatchingPreview.vue';
- import ChinesePreview from '@/views/exercise_questions/preview/ChinesePreview.vue';
- import WritePreview from '../preview/WritePreview.vue';
- import FillPreview from '../preview/FillPreview.vue';
- import ReadAloudPreview from '../preview/ReadAloudPreview.vue';
- import DialoguePreview from '../preview/DialoguePreview.vue';
- import TalkPictruePreview from '../preview/TalkPictruePreview.vue';
- import ChooseTonePreview from '../preview/ChooseTonePreview.vue';
- import RepeatPreview from '../preview/RepeatPreview.vue';
- import ReadPreview from '../preview/ReadPreview.vue';
- import SortPreview from '../preview/SortPreview.vue';
- export default {
- name: 'CreateExercise',
- components: {
- CreateMain,
- SelectPreview,
- JudgePreview,
- MatchingPreview,
- ChinesePreview,
- WritePreview,
- FillPreview,
- ReadAloudPreview,
- DialoguePreview,
- TalkPictruePreview,
- ChooseTonePreview,
- RepeatPreview,
- ReadPreview,
- SortPreview,
- },
- provide() {
- return {
- isSetUp: () => this.isSetUp,
- updateCurQuestionType: this.updateCurQuestionType,
- };
- },
- data() {
- const { id } = this.$route.query;
- return {
- id, // 练习id
- curIndex: 0, // 当前练习索引
- index_list: [], // 练习列表
- exerciseNames, // 练习名称
- isSetUp: false, // 设置
- preview: false, // 预览显示
- previewData: {}, // 预览数据
- previewComponents: {
- select: SelectPreview,
- judge: JudgePreview,
- matching: MatchingPreview,
- chinese: ChinesePreview,
- write: WritePreview,
- fill: FillPreview,
- read_aloud: ReadAloudPreview,
- dialogue: DialoguePreview,
- talk_picture: TalkPictruePreview,
- choose_tone: ChooseTonePreview,
- repeat: RepeatPreview,
- read: ReadPreview,
- sort: SortPreview,
- },
- };
- },
- computed: {
- curPreviewPage() {
- if (this.index_list.length === 0) return '';
- return this.previewComponents[this.index_list[this.curIndex].type];
- },
- },
- watch: {
- curIndex() {
- if (this.index_list.length === 0) return;
- this.getQuestionInfo();
- },
- },
- created() {
- this.getExerciseQuestionIndexList(true);
- },
- methods: {
- // 返回练习管理
- back() {
- this.$router.push('/personal_question');
- },
- /**
- * 添加题目到练习
- * @param {string} type 题目类型
- * @param {string} additional_type 附加类型
- * @param {string} content 题目内容
- */
- addQuestionToExercise(type, additional_type, content = '') {
- AddQuestionToExercise({
- exercise_id: this.id,
- type,
- additional_type,
- content,
- })
- .then(() => {
- this.getExerciseQuestionIndexList();
- })
- .catch(() => {
- this.$message.error('添加失败');
- });
- },
- // 创建新题
- createNewQuestion() {
- if (this.index_list.length === 0) {
- this.addQuestionToExercise('select', 'single');
- return;
- }
- let { type, additional_type } = this.index_list[this.curIndex];
- this.addQuestionToExercise(type, additional_type);
- },
- /**
- * 获取练习题目索引列表
- */
- getExerciseQuestionIndexList(init) {
- GetExerciseQuestionIndexList({ exercise_id: this.id })
- .then(({ index_list }) => {
- this.index_list = index_list;
- if (!init) return;
- this.getQuestionInfo();
- })
- .catch((err) => {
- console.log(err);
- });
- },
- /**
- * 获取题目信息
- */
- getQuestionInfo() {
- if (this.index_list.length === 0) return;
- GetQuestionInfo({ question_id: this.index_list[this.curIndex].id })
- .then(({ question }) => {
- if (question.content) {
- this.$nextTick(() => {
- this.$refs.createMain.$refs.exercise?.[0].setQuestion(question);
- this.refreshPreviewData();
- });
- }
- })
- .catch(() => {});
- },
- /**
- * 复制练习
- * @param {Number} index 练习索引
- */
- copy(index) {
- this.$confirm('是否复制当前题目', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- })
- .then(() => {
- GetQuestionInfo({ question_id: this.index_list[index].id }).then(
- ({ question: { type, additional_type, content } }) => {
- this.addQuestionToExercise(type, additional_type, content);
- },
- );
- })
- .catch(() => {});
- },
- /**
- * 选择练习
- * @param {Number} index 练习索引
- * @param {object} data 练习数据
- */
- selectExerciseItem(index, data) {
- if (index < 0 || index > this.index_list.length - 1) return;
- this.curIndex = index;
- this.$refs.createMain.resetSaveDate();
- this.$refs.createMain.saveQuestion(data);
- },
- // 设置
- setUp() {
- this.isSetUp = !this.isSetUp;
- },
- // 刷新预览数据
- refreshPreviewData() {
- this.previewData = this.$refs.createMain.$refs.exercise?.[0].data || {};
- },
- // 预览
- setPreview() {
- this.preview = !this.preview;
- this.refreshPreviewData();
- },
- // 删除练习
- deleteQuestion() {
- DeleteQuestion({ question_id: this.index_list[this.curIndex].id })
- .then(() => {
- this.curIndex = Math.max(0, this.curIndex - 1);
- this.getExerciseQuestionIndexList();
- this.$message.success('删除成功');
- })
- .catch(() => {
- this.$message.error('删除失败');
- });
- },
- /**
- * 修改当前题目类型
- * @param {Array} arr
- */
- updateCurQuestionType(arr) {
- let type = arr[arr.length - 1];
- this.index_list[this.curIndex].type = type;
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .exercise {
- display: grid;
- grid-template: 1fr auto / 224px 1fr;
- height: 100%;
- .list {
- display: flex;
- flex-direction: column;
- grid-area: 1 / 1 / -1;
- row-gap: 16px;
- padding: 16px 8px;
- background-color: #fff;
- border-right: 1px solid $border-color;
- &-title {
- font-weight: bold;
- }
- .exercise-list {
- max-height: calc(100% - 130px);
- overflow-y: auto;
- .exercise-item {
- display: flex;
- column-gap: 8px;
- align-items: center;
- padding: 4px 8px;
- color: #333;
- cursor: pointer;
- border-radius: 2px;
- &.active {
- color: $main-color;
- background-color: #f4f8ff;
- }
- .item-name {
- flex: 1;
- }
- }
- }
- &-operate {
- display: flex;
- > .el-button {
- width: 50%;
- }
- }
- }
- .preview {
- position: relative;
- max-height: 450px;
- padding: 16px 24px;
- overflow: auto;
- background-color: #eff1f5;
- border-top: 1px solid $border-color;
- .preview-header {
- display: flex;
- justify-content: space-between;
- width: 100%;
- .quick-preview {
- font-weight: bold;
- }
- .preview-right {
- display: flex;
- column-gap: 18px;
- align-items: center;
- .preview-button {
- display: flex;
- column-gap: 8px;
- align-items: center;
- color: #175dff;
- cursor: pointer;
- &.plain {
- color: #2f3742;
- }
- }
- }
- }
- &-content {
- width: 100%;
- height: calc(100% - 24px);
- overflow: auto;
- }
- }
- }
- </style>
- <style>
- .el-cascader-menu__wrap {
- height: 235px;
- }
- </style>
|