short-answer.vue 6.7 KB

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