table-fill-question.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <!-- 填表题 -->
  3. <view class="table-fill-area" v-model="questionData">
  4. <view class="question_title">
  5. <text class="question_number">
  6. {{ questionNumberEndIsBracket(questionData.property.question_number) }}
  7. </text>
  8. <text class="question_stem" v-html="sanitizeHTML(questionData.stem)"
  9. :ref="'richText-1-1'+questionData.question_id"
  10. @longpress="previewByRichTextImg(-1,-1,questionData.question_id)"></text>
  11. </view>
  12. <view class="description" v-if="isEnable(questionData.property.is_enable_description)&&questionData.description"
  13. v-html="sanitizeHTML(questionData.description)" :ref="'richText-2-2'+questionData.question_id"
  14. @longpress="previewByRichTextImg(-2,-2,questionData.question_id)">
  15. </view>
  16. <view class="uni-container">
  17. <uni-table :style="{ width: `${questionData.property.form_width}px` }">
  18. <uni-tr v-if="isEnable(questionData.property.is_enable_table_header)">
  19. <uni-th width="50" align="left"> </uni-th>
  20. <uni-th v-for="(item, index) in questionData.option_header_list" align="left"
  21. :style="{ width: `${item.width}%` }">
  22. {{item.text}}
  23. </uni-th>
  24. </uni-tr>
  25. <uni-tr v-for="(row, rowIndex) in newOption_list" :key="rowIndex">
  26. <uni-td>{{ rowIndex+1 }}</uni-td>
  27. <uni-td v-for="(column, columnIndex) in row"
  28. :style="{ width: `${questionData.option_header_list[columnIndex].width}%`}">
  29. <view class="table-area">
  30. <view class="table-content">
  31. <text v-if="column.type==='text'">{{ column.text }}</text>
  32. <template v-else>
  33. <textarea v-model="column.text" auto-height placeholder="请输入"
  34. :disabled="answer_control[questionData.question_id].isReadOnly" class="fill"
  35. :style="{ width: '100%'}" @blur="handleTone(column.text,rowIndex,columnIndex)" />
  36. </template>
  37. </view>
  38. </view>
  39. </uni-td>
  40. </uni-tr>
  41. </uni-table>
  42. </view>
  43. <view class="reference" :style="{ width: `${questionData.property.form_width}px` }"
  44. v-if="isViewReference&&answer_control[questionData.question_id].isViewRightAnswer">
  45. <text class="reference-title">参考答案</text>
  46. <view class="uni-container">
  47. <uni-table :style="{ width: `${questionData.property.form_width}px` }">
  48. <uni-tr v-if="isEnable(questionData.property.is_enable_table_header)">
  49. <uni-th width="50" align="left"> </uni-th>
  50. <uni-th v-for="(item, index) in questionData.reference_answer_option_header_list" align="left"
  51. :style="{ width: `${item.width}%` }">
  52. {{item.text}}
  53. </uni-th>
  54. </uni-tr>
  55. <uni-tr v-for="(row, rowIndex) in questionData.reference_answer_option_list" :key="rowIndex">
  56. <uni-td>{{ rowIndex+1 }}</uni-td>
  57. <uni-td v-for="(column, columnIndex) in row">
  58. <view class="table-area">
  59. <view class="table-content">
  60. <text>{{ column.text }}</text>
  61. </view>
  62. </view>
  63. </uni-td>
  64. </uni-tr>
  65. </uni-table>
  66. </view>
  67. </view>
  68. <view class="reference" v-if="isViewAnalysis&&answer_control[questionData.question_id].isViewRightAnswer">
  69. <text class="reference-title">解析</text>
  70. <text class="reference-answer" v-html="sanitizeHTML(questionData.analysis)"
  71. :ref="'richText-3-3'+questionData.question_id"
  72. @longpress="previewByRichTextImg(-3,-3,questionData.question_id)">
  73. </text>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import {
  79. questionData,
  80. sanitizeHTML,
  81. isEnable,
  82. answer_control,
  83. addTone,
  84. handleToneValue,
  85. } from '@/pages/answer_question/common/data/common.js';
  86. import AnswerControlMixin from '@/pages/answer_question/common/data/AnswerControlMixin.js';
  87. import _ from 'lodash';
  88. export default {
  89. name: "table-fill-question",
  90. mixins: [AnswerControlMixin],
  91. props: {
  92. questionData: questionData
  93. },
  94. data() {
  95. return {
  96. sanitizeHTML,
  97. isEnable,
  98. answer_control,
  99. addTone,
  100. handleToneValue,
  101. newOption_list: [],
  102. };
  103. },
  104. computed: {
  105. isViewReference: function() {
  106. return isEnable(this.questionData.property.is_enable_reference_answer);
  107. },
  108. isViewAnalysis: function() {
  109. return isEnable(this.questionData.property.is_enable_analysis);
  110. }
  111. },
  112. watch: {
  113. 'questionData.question_id': {
  114. handler(val) {
  115. this.commonComputedAnswerControl(val);
  116. this.setUserAnswer();
  117. },
  118. immediate: true,
  119. deep: true
  120. },
  121. 'questionData.option_list': {
  122. handler(val) {
  123. this.newOption_list = _.cloneDeep(val);
  124. },
  125. immediate: true,
  126. deep: true,
  127. },
  128. newOption_list: {
  129. handler(val) {
  130. var answerList = this.questionData.user_answer[this.questionData.question_id].answer_list;
  131. answerList = [];
  132. val.forEach((item) => {
  133. item.forEach((li) => {
  134. if (['input'].includes(li.type)) {
  135. let findIndex = answerList.findIndex((p) => p.mark === li.mark);
  136. if (findIndex === -1 && li.text.length <= 0) return;
  137. if (findIndex !== -1 && li.text.length <= 0) {
  138. answerList.splice(findIndex, 1);
  139. return;
  140. }
  141. if (findIndex === -1) {
  142. answerList.push({
  143. mark: li.mark,
  144. value: li.text,
  145. });
  146. return;
  147. }
  148. if (findIndex !== -1) {
  149. answerList[findIndex].value = li.text;
  150. }
  151. }
  152. })
  153. });
  154. this.questionData.user_answer[this.questionData.question_id].answer_list = answerList;
  155. },
  156. deep: true,
  157. },
  158. },
  159. methods: {
  160. setUserAnswer: function() {
  161. var that = this;
  162. var callback = function() {
  163. var userAnswer = [];
  164. var questionId = that.questionData.question_id;
  165. var _ua = that.questionData.user_answer[questionId];
  166. if (_ua && _ua.answer_list && _ua.answer_list.length > 0)
  167. userAnswer = _ua.answer_list;
  168. if (userAnswer.length == 0) return;
  169. that.newOption_list.forEach(p => {
  170. p.forEach(x => {
  171. if (!x.mark) return false;
  172. var en = userAnswer.find(y => y.mark == x.mark)
  173. if (!en) return false;
  174. x.text = en.value;
  175. })
  176. })
  177. }
  178. this.$emit("getUserAnswer", this.questionData.question_id, callback);
  179. },
  180. handleTone(value, i, j) {
  181. this.newOption_list[i][j].text = value
  182. .trim()
  183. .split(/\s+/)
  184. .map((item) => {
  185. return handleToneValue(item);
  186. })
  187. .map((item) =>
  188. item.map(({
  189. number,
  190. con
  191. }) => (number && con ? addTone(Number(number), con) : number || con || '')),
  192. )
  193. .filter((item) => item.length > 0)
  194. .join(' ');
  195. },
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .table-fill-area {
  201. /deep/.uni-container {
  202. margin-top: 12rpx;
  203. .uni-table-scroll {
  204. overflow-x: visible;
  205. .uni-table {
  206. border-left: 1px #B5B5B5 solid;
  207. border-top: 1px #B5B5B5 solid;
  208. border-radius: 8rpx;
  209. .uni-table-th {
  210. color: $uni-color-main;
  211. background-color: #EAEFFB;
  212. font-size: 32rpx;
  213. padding: 24rpx 16rpx;
  214. font-weight: 700;
  215. border-right: 1px #B5B5B5 solid;
  216. border-bottom: 1px #B5B5B5 solid;
  217. .uni-table-th-content {
  218. justify-content: center !important;
  219. }
  220. }
  221. .uni-table-td {
  222. color: #000000;
  223. font-size: 32rpx;
  224. padding: 24rpx 16rpx;
  225. border-right: 1px #B5B5B5 solid;
  226. border-bottom: 1px #B5B5B5 solid;
  227. }
  228. }
  229. }
  230. }
  231. .reference {
  232. margin: 32rpx 0;
  233. background-color: $uni-bg-color-grey;
  234. padding: 24rpx;
  235. font-size: 28rpx;
  236. .reference-title {
  237. display: block;
  238. line-height: 64rpx;
  239. color: #4E5969;
  240. }
  241. .reference-answer {
  242. color: #1D2129;
  243. line-height: 48rpx;
  244. }
  245. }
  246. }
  247. </style>