short-answer.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <div class="app-container">
  3. <a-form :model="form" ref="formRef" :rules="rules" layout="vertical">
  4. <!-- <a-form-item label="年级:" name="gradeLevel" required>
  5. <a-select v-model:value="form.gradeLevel" placeholder="年级" @change="levelChange">
  6. <a-select-option v-for="item in levelEnum" :key="item.key" :value="item.key">
  7. {{ item.value }}
  8. </a-select-option>
  9. </a-select>
  10. </a-form-item>
  11. <a-form-item label="学科:" name="subjectId" required>
  12. <a-select v-model:value="form.subjectId" placeholder="学科">
  13. <a-select-option v-for="item in subjectFilter" :key="item.id" :value="item.id">
  14. {{ item.name + ' ( ' + item.levelName + ' )' }}
  15. </a-select-option>
  16. </a-select>
  17. </a-form-item> -->
  18. <a-form-item label="题库类型:" name="bankType" required>
  19. <a-select v-model:value="form.bankType" placeholder="题库类型">
  20. <a-select-option v-for="item in bankTypeEnum" :key="item.key" :value="item.key">
  21. {{ item.value }}
  22. </a-select-option>
  23. </a-select>
  24. </a-form-item>
  25. <a-form-item label="题干:" name="title" required>
  26. <a-input v-model:value="form.title" readonly @click="inputClick(form, 'title')" />
  27. </a-form-item>
  28. <a-form-item label="答案:" name="correct" required>
  29. <a-input v-model:value="form.correct" readonly @click="inputClick(form, 'correct')" />
  30. </a-form-item>
  31. <a-form-item label="解析:" name="analyze" required>
  32. <a-input v-model:value="form.analyze" readonly @click="inputClick(form, 'analyze')" />
  33. </a-form-item>
  34. <a-form-item label="分数:" name="score" required>
  35. <a-input-number v-model:value="form.score" :precision="1" :step="1" :max="100" />
  36. </a-form-item>
  37. <a-form-item label="难度:" required>
  38. <a-rate v-model:value="form.difficult" class="question-item-rate" />
  39. </a-form-item>
  40. <a-form-item>
  41. <a-button type="primary" @click="submitForm" :loading="formLoading">提交</a-button>
  42. <a-button @click="resetForm">重置</a-button>
  43. <a-button type="success" @click="showQuestion">预览</a-button>
  44. </a-form-item>
  45. </a-form>
  46. <a-modal
  47. v-model:visible="richEditor.dialogVisible"
  48. width="800px"
  49. :footer="null"
  50. :closable="false"
  51. centered
  52. destroy-on-close
  53. >
  54. <Editor v-model="richEditorContent" :height="300" />
  55. <div style="text-align: right; margin-top: 16px">
  56. <a-button type="primary" @click="editorConfirm">确定</a-button>
  57. <a-button @click="richEditor.dialogVisible = false">取消</a-button>
  58. </div>
  59. </a-modal>
  60. <a-modal v-model:visible="questionShow.dialog" width="800px" :footer="null" :bodyStyle="{ padding: '24px' }">
  61. <QuestionShow :qType="questionShow.qType" :question="questionShow.question" :qLoading="questionShow.loading" />
  62. </a-modal>
  63. </div>
  64. </template>
  65. <script setup>
  66. import { ref, reactive, computed, onMounted } from 'vue'
  67. import { message } from 'ant-design-vue'
  68. import { useExamStore } from '@/store/exam'
  69. import tQuestionApi from '@/api/exam/question/tQuestionApi'
  70. import QuestionShow from '../components/Show.vue'
  71. import Editor from '@/components/Editor/index.vue'
  72. const bankTypeEnum = computed(() => examStore.getBankTypeEnum)
  73. const examStore = useExamStore()
  74. const props = defineProps({
  75. id: {
  76. type: Number,
  77. default: 0
  78. }
  79. })
  80. const emit = defineEmits(['successful'])
  81. const formRef = ref()
  82. const form = reactive({
  83. id: null,
  84. questionType: 5,
  85. // gradeLevel: null,
  86. // subjectId: null,
  87. title: '',
  88. items: [],
  89. analyze: '',
  90. correct: '',
  91. score: '',
  92. difficult: 0,
  93. bankType: 1
  94. })
  95. const subjectFilter = ref([])
  96. const formLoading = ref(false)
  97. const rules = {
  98. bankType: [{ required: true, message: '请选择题库类型', trigger: 'change' }],
  99. gradeLevel: [{ required: true, message: '请选择年级', trigger: 'change' }],
  100. subjectId: [{ required: true, message: '请选择学科', trigger: 'change' }],
  101. title: [{ required: true, message: '请输入题干', trigger: 'blur' }],
  102. correct: [{ required: true, message: '请输入答案', trigger: 'blur' }],
  103. analyze: [{ required: true, message: '请输入解析', trigger: 'blur' }],
  104. score: [{ required: true, message: '请输入分数', trigger: 'blur' }]
  105. }
  106. const richEditor = reactive({
  107. dialogVisible: false,
  108. object: null,
  109. parameterName: '',
  110. instance: null
  111. })
  112. const richEditorContent = ref('')
  113. const questionShow = reactive({
  114. qType: 0,
  115. dialog: false,
  116. question: null,
  117. loading: false
  118. })
  119. const levelEnum = computed(() => examStore.levelEnum)
  120. const subjects = computed(() => examStore.subjects)
  121. onMounted(async () => {
  122. await examStore.initSubject()
  123. subjectFilter.value = subjects.value
  124. const id = props.id
  125. if (id && parseInt(id) !== 0) {
  126. formLoading.value = true
  127. tQuestionApi.select(id).then((re) => {
  128. Object.assign(form, re)
  129. formLoading.value = false
  130. })
  131. }
  132. })
  133. function inputClick(object, parameterName) {
  134. richEditor.object = object
  135. richEditor.parameterName = parameterName
  136. richEditorContent.value = object[parameterName] || ''
  137. richEditor.dialogVisible = true
  138. }
  139. function editorConfirm() {
  140. richEditor.object[richEditor.parameterName] = richEditorContent.value
  141. richEditor.dialogVisible = false
  142. }
  143. function submitForm() {
  144. formRef.value.validate().then((valid) => {
  145. if (valid) {
  146. formLoading.value = true
  147. tQuestionApi
  148. .edit(form)
  149. .then(() => {
  150. emit('successful')
  151. formLoading.value = false
  152. })
  153. .catch(() => {
  154. formLoading.value = false
  155. })
  156. }
  157. })
  158. }
  159. function resetForm() {
  160. const lastId = form.id
  161. formRef.value.resetFields()
  162. Object.assign(form, {
  163. id: null,
  164. questionType: 5,
  165. // gradeLevel: null,
  166. // subjectId: null,
  167. title: '',
  168. items: [],
  169. analyze: '',
  170. correct: '',
  171. score: '',
  172. bankType: 1,
  173. difficult: 0
  174. })
  175. form.id = lastId
  176. }
  177. function levelChange() {
  178. form.subjectId = null
  179. subjectFilter.value = subjects.value.filter((data) => data.level === form.gradeLevel)
  180. }
  181. function showQuestion() {
  182. questionShow.dialog = true
  183. questionShow.qType = form.questionType
  184. questionShow.question = { ...form }
  185. }
  186. </script>
  187. <style lang="less" scoped>
  188. .app-container {
  189. background: #fff;
  190. padding: 24px;
  191. border-radius: 8px;
  192. }
  193. .question-item-rate {
  194. line-height: 2.5;
  195. }
  196. </style>