essay-question.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <!-- 问答题 -->
  3. <view class="essay-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-html="sanitizeHTML(questionData.description)"
  13. v-if="isEnable(questionData.property.is_enable_description)&&questionData.description"
  14. :ref="'richText-2-2'+questionData.question_id" @longpress="previewByRichTextImg(-2,-2,questionData.question_id)">
  15. </view>
  16. <view class="write-content">
  17. <textarea :maxlength="word_num" v-model="questionData.user_answer[questionData.question_id].answer_list[0].text"
  18. placeholder="请输入内容" @input="sumfontnum($event,word_num)" @blur="saveUserAnswer"
  19. :disabled="answer_control[questionData.question_id].isReadOnly" />
  20. <view class="fontNum">
  21. <text>
  22. {{fontNum?fontNum:questionData.user_answer[questionData.question_id].answer_list[0].text.length}}
  23. </text>/{{word_num}}
  24. </view>
  25. </view>
  26. <!-- 语音作答 v-if="isEnable(questionData.property.is_enable_voice_answer)" -->
  27. <!-- <template>
  28. <SoundRecord :wav-blob.sync="questionData.user_answer[questionData.question_id].answer_list[0].audio_file_id"
  29. @setAudioId="setFileId" :disabled="answer_control[questionData.question_id].isReadOnly">
  30. </SoundRecord>
  31. </template> -->
  32. <!-- v-if="isEnable(questionData.property.is_enable_upload_accessory)" -->
  33. <!-- 上传文件 -->
  34. <!-- <template>
  35. <UploadFiles upload-title="上传附件:" :disabled="answer_control[questionData.question_id].isReadOnly"
  36. :fileIdList="uploadedIdList" @upload="handleUpload" @deleteFile="handleDelete">
  37. </UploadFiles>
  38. </template> -->
  39. <view class="reference" v-if="isViewReference&&answer_control[questionData.question_id].isViewRightAnswer">
  40. <text class="reference-title">参考答案</text>
  41. <text class="reference-answer" v-html="sanitizeHTML(questionData.reference_answer)"
  42. :ref="'richText-3-3'+questionData.question_id"
  43. @longpress="previewByRichTextImg(-3,-3,questionData.question_id)"></text>
  44. </view>
  45. <view class="reference" v-if="isViewAnalysis&&answer_control[questionData.question_id].isViewRightAnswer">
  46. <text class="reference-title">解析</text>
  47. <text class="reference-answer" v-html="sanitizeHTML(questionData.analysis)"
  48. :ref="'richText-4-4'+questionData.question_id"
  49. @longpress="previewByRichTextImg(-4,-4,questionData.question_id)">
  50. </text>
  51. </view>
  52. <uni-popup ref="message" type="message">
  53. <uni-popup-message type="warn" :message="messageText" :duration="2000"></uni-popup-message>
  54. </uni-popup>
  55. </view>
  56. </template>
  57. <script>
  58. import {
  59. questionData,
  60. sanitizeHTML,
  61. isEnable,
  62. answer_mode_list,
  63. answer_control,
  64. addTone,
  65. handleToneValue,
  66. } from '@/pages/answer_question/common/data/common.js';
  67. import SoundRecord from '@/components/sound-record/sound-record.vue';
  68. import UploadFiles from '@/components/upload-files/upload-files.vue';
  69. import AnswerControlMixin from '@/pages/answer_question/common/data/AnswerControlMixin.js';
  70. export default {
  71. name: "essay-question",
  72. mixins: [AnswerControlMixin],
  73. components: {
  74. SoundRecord,
  75. UploadFiles
  76. },
  77. props: {
  78. questionData: questionData
  79. },
  80. data() {
  81. return {
  82. sanitizeHTML,
  83. isEnable,
  84. answer_mode_list,
  85. answer_control,
  86. addTone,
  87. handleToneValue,
  88. show_sample_text: false,
  89. uploadedIdList: [],
  90. fontNum: 0,
  91. messageText: '',
  92. question_id: '',
  93. word_num: 1000,
  94. };
  95. },
  96. watch: {
  97. 'questionData.question_id': {
  98. handler(val) {
  99. this.commonComputedAnswerControl(val);
  100. this.question_id = this.questionData.question_id;
  101. this.setUserAnswer();
  102. },
  103. immediate: true,
  104. deep: true
  105. }
  106. },
  107. computed: {
  108. isViewReference: function() {
  109. return isEnable(this.questionData.property.is_enable_reference_answer);
  110. },
  111. isViewAnalysis: function() {
  112. return isEnable(this.questionData.property.is_enable_analysis);
  113. }
  114. },
  115. methods: {
  116. sumfontnum(e, totalCount) {
  117. this.setQuestionEdit();
  118. this.fontNum = e.detail.value.length;
  119. if (this.fontNum === totalCount) {
  120. this.messageText = `字数达到${totalCount}字!`;
  121. this.$refs.message.open();
  122. }
  123. },
  124. // 文件上传成功
  125. handleUpload(fileId) {
  126. this.questionData.user_answer[this.question_id].answer_list[0].accessory_file_id_list.push(fileId);
  127. this.setQuestionEdit();
  128. },
  129. // 删除文件
  130. handleDelete(fileId) {
  131. var i = this.questionData.user_answer[this.question_id].answer_list[0].accessory_file_id_list
  132. .indexOf(fileId);
  133. if (i > -1)
  134. this.questionData.user_answer[this.question_id].answer_list[0].accessory_file_id_list.splice(i,
  135. 1);
  136. this.setQuestionEdit();
  137. },
  138. //异步更新声音ID有问题,所以采用方法手动赋值
  139. setFileId(fileId) {
  140. this.setQuestionEdit();
  141. this.saveUserAnswer();
  142. },
  143. setQuestionEdit() {
  144. this.questionData.user_answer[this.question_id].isEdit = true;
  145. this.$forceUpdate();
  146. },
  147. //填写答案后保存答案
  148. saveUserAnswer: function(mark) {
  149. var that = this;
  150. var questionId = that.question_id;
  151. this.questionData.user_answer[questionId].isEdit = true;
  152. var ansed = this.questionData.user_answer[questionId].answer_list;
  153. this.handleTone(ansed[0].text, questionId);
  154. this.questionData.user_answer[questionId].is_fill_answer = ansed.filter(p => p.text || p.audio_file_id)
  155. .length > 0;
  156. this.questionData.user_answer[questionId].content = JSON.stringify(ansed);
  157. this.questionData.user_answer[questionId].answer_list = ansed;
  158. this.$emit("setSubAnswer", this.questionData.user_answer[questionId], questionId);
  159. },
  160. //获取用户答案
  161. setUserAnswer: function() {
  162. var that = this;
  163. var callback = function() {
  164. var userAnswer = [];
  165. var questionId = that.question_id;
  166. var _ua = that.questionData.user_answer[questionId];
  167. if (_ua && _ua.answer_list && _ua.answer_list.length > 0) {
  168. userAnswer = _ua.answer_list;
  169. that.questionData.user_answer[questionId].answer_list[0].accessory_file_id_list.forEach(
  170. p => {
  171. that.uploadedIdList.push(p);
  172. })
  173. } else {
  174. that.questionData.user_answer[questionId].answer_list = [{
  175. text: '', // 用户文章
  176. audio_file_id: '', // 录音内容
  177. accessory_file_id_list: [], // 上传文件列表
  178. }];
  179. }
  180. that.$forceUpdate();
  181. }
  182. if (this.questionData.isSubSub) {
  183. callback();
  184. } else {
  185. this.$emit("getUserAnswer", this.questionData.question_id, callback);
  186. }
  187. },
  188. handleTone(value, questionId) {
  189. this.questionData.user_answer[questionId].answer_list[0].text = value
  190. .trim()
  191. .split(/\s+/)
  192. .map((item) => {
  193. return handleToneValue(item);
  194. })
  195. .map((item) =>
  196. item.map(({
  197. number,
  198. con
  199. }) => (number && con ? addTone(Number(number), con) : number || con || '')),
  200. )
  201. .filter((item) => item.length > 0)
  202. .join(' ');
  203. this.$forceUpdate();
  204. },
  205. }
  206. }
  207. </script>
  208. <style lang="scss" scoped>
  209. .essay-area {
  210. .article {
  211. margin-top: 32rpx;
  212. line-height: 56rpx;
  213. }
  214. .write-content {
  215. margin: 32rpx 0 84rpx 0;
  216. height: 500rpx;
  217. width: 100%;
  218. background-color: $uni-bg-color-grey;
  219. border-radius: 16rpx 16rpx 0 0;
  220. textarea {
  221. width: 95%;
  222. height: 100%;
  223. font-size: 28rpx;
  224. line-height: 56rpx;
  225. margin: 0 auto;
  226. }
  227. .fontNum {
  228. position: relative;
  229. text-align: right;
  230. color: #86909C;
  231. padding: 8rpx 16rpx;
  232. background-color: $uni-bg-color-grey;
  233. border-radius: 0 0 16rpx 16rpx;
  234. }
  235. }
  236. .icon-area {
  237. width: 80rpx;
  238. height: 80rpx;
  239. border-radius: 40px;
  240. background-color: #306EFF;
  241. display: flex;
  242. justify-content: center;
  243. align-items: center;
  244. margin-top: 32rpx;
  245. .svg-icon {
  246. width: 40rpx;
  247. }
  248. }
  249. .sample-area {
  250. margin-top: 64rpx;
  251. .line {
  252. height: 1px;
  253. background: #dcdfe6;
  254. text-align: center;
  255. text {
  256. position: relative;
  257. background-color: #ffffff;
  258. padding: 0 10rpx;
  259. top: -22rpx;
  260. font-size: 26rpx;
  261. }
  262. }
  263. .sample-text {
  264. font-size: $font-size-serial;
  265. font-weight: 400;
  266. line-height: 40rpx;
  267. margin-top: 32rpx;
  268. &.sample-show {
  269. color: #306eff;
  270. }
  271. }
  272. }
  273. .reference {
  274. margin: 32rpx 0;
  275. background-color: #f9f8f9;
  276. padding: 24rpx;
  277. .reference-title {
  278. display: block;
  279. line-height: 64rpx;
  280. color: #4E5969;
  281. font-size: 28rpx;
  282. }
  283. .reference-answer {
  284. color: #1D2129;
  285. line-height: 48rpx;
  286. font-size: 14pt;
  287. }
  288. }
  289. }
  290. </style>