write-question.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 article-content" v-if="show_sample_text" v-html="sanitizeHTML(show_sample_break)"
  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. show_sample_break: '',
  101. };
  102. },
  103. watch: {
  104. 'questionData.question_id': {
  105. handler(val) {
  106. this.questionData.user_answer[val].answer_list = [{
  107. text: '', // 用户文章
  108. voice_file_id: '', // 录音内容
  109. accessory_file_id_list: [], // 上传文件列表
  110. }]
  111. this.question_id = this.questionData.question_id;
  112. this.setUserAnswer();
  113. this.commonComputedAnswerControl(val);
  114. this.show_sample_break = this.questionData.sample_text ? this.questionData.sample_text.replace(/#/g, '</p><p>') : '';
  115. },
  116. immediate: true,
  117. deep: true
  118. }
  119. },
  120. computed: {
  121. isViewSampleText: function() {
  122. return isEnable(this.questionData.property.is_enable_sample_text);
  123. },
  124. isViewAnalysis: function() {
  125. return isEnable(this.questionData.property.is_enable_analysis);
  126. }
  127. },
  128. methods: {
  129. sumfontnum(e, totalCount) {
  130. this.setQuestionEdit();
  131. this.fontNum = e.detail.value.length;
  132. if (this.fontNum === totalCount) {
  133. this.messageText = `字数达到${totalCount}字!`;
  134. this.$refs.message.open();
  135. }
  136. },
  137. // 文件上传成功
  138. handleUpload(fileId) {
  139. this.questionData.user_answer[this.question_id].answer_list[0].accessory_file_id_list.push(fileId);
  140. this.setQuestionEdit();
  141. },
  142. // 删除文件
  143. handleDelete(fileId) {
  144. if (this.answer_control[this.questionData.question_id].isReadOnly) return;
  145. var i = this.questionData.user_answer[this.question_id].answer_list[0].accessory_file_id_list
  146. .indexOf(fileId);
  147. if (i > -1)
  148. this.questionData.user_answer[this.question_id].answer_list[0].accessory_file_id_list.splice(i,
  149. 1);
  150. this.setQuestionEdit();
  151. },
  152. //异步更新声音ID有问题,所以采用方法手动赋值
  153. // setFileId(fileId) {
  154. // this.setQuestionEdit();
  155. // },
  156. setQuestionEdit() {
  157. this.questionData.user_answer[this.question_id].isEdit = true;
  158. this.$forceUpdate();
  159. },
  160. //获取用户答案
  161. setUserAnswer: function() {
  162. var that = this;
  163. var callback = function() {
  164. that.questionData.user_answer[that.question_id].answer_list[0].accessory_file_id_list.forEach(
  165. p => {
  166. that.uploadedIdList.push(p);
  167. })
  168. that.$forceUpdate();
  169. }
  170. this.$emit("getUserAnswer", this.question_id, callback);
  171. },
  172. handleTone(value, questionId) {
  173. this.questionData.user_answer[questionId].answer_list[0].text = value
  174. .trim()
  175. .split(/\s+/)
  176. .map((item) => {
  177. return handleToneValue(item);
  178. })
  179. .map((item) =>
  180. item.map(({
  181. number,
  182. con
  183. }) => (number && con ? addTone(Number(number), con) : number || con || '')),
  184. )
  185. .filter((item) => item.length > 0)
  186. .join(' ');
  187. this.$forceUpdate();
  188. },
  189. }
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. .write-area {
  194. .write-content {
  195. margin: 32rpx 0;
  196. min-height: 330rpx;
  197. height: auto;
  198. width: 100%;
  199. background-color: $uni-bg-color-grey;
  200. border-radius: 16rpx;
  201. display: flex;
  202. flex-direction: column;
  203. textarea {
  204. width: 95%;
  205. height: 100%;
  206. font-size: 28rpx;
  207. line-height: 56rpx;
  208. margin: 0 auto;
  209. flex: 1;
  210. }
  211. .fontNum {
  212. position: relative;
  213. text-align: right;
  214. color: #86909C;
  215. padding: 8rpx 16rpx;
  216. border-radius: 0 0 16rpx 16rpx;
  217. }
  218. }
  219. .icon-area {
  220. width: 80rpx;
  221. height: 80rpx;
  222. border-radius: 40px;
  223. background-color: #306EFF;
  224. display: flex;
  225. justify-content: center;
  226. align-items: center;
  227. margin-top: 32rpx;
  228. .svg-icon {
  229. width: 40rpx;
  230. }
  231. }
  232. .sample-area {
  233. margin-top: 64rpx;
  234. .line {
  235. height: 1px;
  236. background: #dcdfe6;
  237. text-align: center;
  238. text {
  239. position: relative;
  240. background-color: #ffffff;
  241. padding: 0 10rpx;
  242. top: -22rpx;
  243. font-size: 26rpx;
  244. }
  245. }
  246. .sample-text {
  247. font-size: $font-size-serial;
  248. margin-top: 32rpx;
  249. /deep/ p {
  250. margin: 0;
  251. }
  252. &.sample-show {
  253. color: #306eff;
  254. }
  255. }
  256. .article-content {
  257. text-indent: 2em;
  258. }
  259. }
  260. .reference {
  261. margin: 32rpx 0;
  262. background-color: #f9f8f9;
  263. padding: 24rpx;
  264. .reference-title {
  265. display: block;
  266. line-height: 64rpx;
  267. color: #4E5969;
  268. font-size: 28rpx;
  269. }
  270. .reference-answer {
  271. color: #1D2129;
  272. line-height: 48rpx;
  273. font-size: 14pt;
  274. }
  275. }
  276. }
  277. </style>