write-question.vue 8.1 KB

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