gap.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <div class="c_box">
  3. <!-- <div class="mask"></div> -->
  4. <div v-if="!checkJson">暂未设置题目</div>
  5. <div v-else class="choice_box">
  6. <!-- <div class="title"><div>{{ `(${option[checkJson.type].name})` }}</div><div v-html="checkJson.title"></div></div> -->
  7. <div class="c_title">
  8. <div class="title">
  9. {{ tindex + 1 + '、' + `(${option[checkJson.type].name})` + checkJson.title
  10. }}<span v-if="see" style="color: #efa030"
  11. >({{ checkJson.answer ? '参考答案:' + checkJson.answer : '暂无参考答案' }}
  12. {{ cJson.score ? '分值:' + cJson.score + '分' : '' }})</span
  13. >
  14. <span style="color: #efa030" v-if="checkJson.score && !see">({{ '分值:' + checkJson.score + '分' }})</span>
  15. <!-- </div><div v-html="checkJson.title"></div> -->
  16. </div>
  17. <div class="p_box" v-if="isTeacher == 1 && checkJson.score">
  18. <el-input v-model="checkJson.score2" class="c_input" @change="numberPan" placeholder="请输入得分"></el-input
  19. ><span style="margin: 0 10px">/</span><span>{{ checkJson.score }}分</span>
  20. </div>
  21. <div class="p_box" v-if="isTeacher == 2 && checkJson.score2">
  22. <span>{{ checkJson.score2 }}分</span><span style="margin: 0 10px">/</span><span>{{ checkJson.score }}分</span>
  23. </div>
  24. </div>
  25. <div class="choices">
  26. <textarea
  27. :readonly="checktype == 2"
  28. rows="2"
  29. v-autoHeight="68"
  30. class="binfo_input binfo_textarea"
  31. cols
  32. v-model="checkJson.answer2"
  33. placeholder=""
  34. ></textarea>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. export default {
  41. props: {
  42. tindex: {
  43. type: Number
  44. },
  45. cJson: {
  46. type: Object
  47. },
  48. checktype: {
  49. type: Number,
  50. default: 1
  51. },
  52. see: {
  53. type: Boolean,
  54. default: false
  55. },
  56. isTeacher: {
  57. type: Number,
  58. default: 2
  59. }
  60. },
  61. data() {
  62. return {
  63. option: {
  64. 1: { name: '问答题' }
  65. },
  66. checkJson: undefined
  67. }
  68. },
  69. watch: {
  70. checkJson: {
  71. handler(newValue) {
  72. this.$emit('update:cJson', newValue)
  73. },
  74. deep: true
  75. },
  76. cJson: {
  77. handler(newValue) {
  78. if (newValue.answer2 !== this.checkJson.answer2) {
  79. this.checkJson = this.depthCopy(newValue)
  80. this.$forceUpdate()
  81. }
  82. },
  83. deep: true
  84. }
  85. },
  86. directives: {
  87. autoHeight: {
  88. update(el, binding) {
  89. const { value } = binding
  90. if (value && typeof value === 'number') {
  91. el.style.height = `${value}px`
  92. } else {
  93. el.style.height = 'auto'
  94. }
  95. },
  96. componentUpdated(el) {
  97. el.style.height = `${el.scrollHeight + 5}px`
  98. }
  99. }
  100. },
  101. methods: {
  102. depthCopy(s) {
  103. return JSON.parse(JSON.stringify(s))
  104. },
  105. numberPan() {
  106. if (/[^\d]/.test(this.checkJson.score2) || parseInt(this.checkJson.score2) < 0) {
  107. this.$message.error('请输入大于0的数字')
  108. this.checkJson.score2 = ''
  109. }
  110. if (parseInt(this.checkJson.score2) > parseInt(this.checkJson.score)) {
  111. this.$message.error('不能输入大于得分的数字')
  112. this.checkJson.score2 = this.checkJson.score
  113. }
  114. }
  115. },
  116. mounted() {
  117. this.checkJson = this.cJson ? this.depthCopy(this.cJson) : undefined
  118. if (this.checkJson.answer2) {
  119. setTimeout(() => {
  120. this.checkJson.answer2 += '*0*%*'
  121. setTimeout(() => {
  122. this.checkJson.answer2 = this.checkJson.answer2.replaceAll('*0*%*', '')
  123. }, 0)
  124. }, 100)
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .c_box {
  131. width: 100%;
  132. position: relative;
  133. .choice_box {
  134. .c_title {
  135. display: flex;
  136. justify-content: space-between;
  137. .title {
  138. font-weight: bold;
  139. width: 100%;
  140. word-break: break-all;
  141. font-size: 16px;
  142. }
  143. .p_box {
  144. margin-left: 5px;
  145. min-width: fit-content;
  146. display: flex;
  147. align-items: center;
  148. .c_input {
  149. width: 90px;
  150. }
  151. /deep/.c_input .el-input__inner {
  152. padding: 0 5px;
  153. text-align: right;
  154. }
  155. }
  156. }
  157. .choices {
  158. margin-top: 10px;
  159. .binfo_input {
  160. width: 100%;
  161. margin: 0;
  162. padding: 12px 14px;
  163. display: block;
  164. min-width: 0;
  165. outline: none;
  166. box-sizing: border-box;
  167. background: none;
  168. border: none;
  169. border-radius: 4px;
  170. background: #fff;
  171. font-size: 16px;
  172. resize: none;
  173. font-family: 'Microsoft YaHei';
  174. min-height: 48px;
  175. /* border: 1px solid #3682fc00; */
  176. border: 1.5px solid #cad1dc;
  177. }
  178. .binfo_textarea {
  179. border: 1.5px solid #cad1dc;
  180. font-size: 16px;
  181. resize: none;
  182. /* background: #f6f6f6; */
  183. font-family: 'Microsoft YaHei';
  184. }
  185. .binfo_input:focus-visible {
  186. border: 1.5px solid #3681fc !important;
  187. }
  188. }
  189. }
  190. }
  191. </style>