write-picture-question.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <!-- 看图写作题 -->
  3. <view class="write-picture-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" :ref="'richText-2-2'+questionData.question_id"
  13. @longpress="previewByRichTextImg(-2,-2,questionData.question_id)"
  14. v-if="isEnable(questionData.property.is_enable_description)&&questionData.description"
  15. v-html="sanitizeHTML(questionData.description)">
  16. </view>
  17. <view class="option-area">
  18. <!-- <view class="article-text" v-html="sanitizeHTML(questionData.article)"></view> -->
  19. <uni-swiper-dot :info="questionData.option_list" :current="active_index" :mode="mode" @clickItem="clickItem">
  20. <swiper class="swiper" circular previous-margin="50px" next-margin="50px" @change="changeImg"
  21. :current="swiperDotIndex">
  22. <swiper-item v-for="(item, index) in questionData.option_list" :key="index">
  23. <view :class="['swiper-item',active_index==index?'active':'']">
  24. <image :src="pic_list[item.picture_file_id]" mode="aspectFit"
  25. @click="preview(pic_list[item.picture_file_id])"></image>
  26. </view>
  27. </swiper-item>
  28. </swiper>
  29. </uni-swiper-dot>
  30. <!-- <view class="pic-title" v-html="sanitizeHTML(questionData.option_list[active_index].picture_title)"></view> -->
  31. <view class="pic-info" v-html="sanitizeHTML(questionData.option_list[active_index].picture_info)"
  32. :ref="'richText-3-3'+questionData.question_id"
  33. @longpress="previewByRichTextImg(-3,-3,questionData.question_id)"></view>
  34. <view class="write-content">
  35. <textarea :maxlength="questionData.property.word_num" v-model="answer_list[0].text"
  36. @input="sumfontnum($event,questionData.property.word_num)" placeholder="请输入"
  37. :disabled="answer_control[questionData.question_id].isReadOnly" auto-height
  38. @blur="handleTone(answer_list[0].text, questionData.question_id);" />
  39. <view class="fontNum">
  40. <text>
  41. {{fontNumList[0]>0?fontNumList[0]:answer_list[0].text.length}}
  42. </text>/{{questionData.property.word_num}}
  43. </view>
  44. </view>
  45. <template v-if="isEnable(questionData.property.is_enable_upload_accessory)">
  46. <!-- 上传文件 -->
  47. <UploadFiles upload-title="" :fileIdList="answer_list[0].accessory_file_id_list" @upload="handleUpload"
  48. @deleteFile="handleDelete" :disabled="answer_control[questionData.question_id].isReadOnly">
  49. </UploadFiles>
  50. </template>
  51. <view v-if="isViewSampleText&&answer_control[questionData.question_id].isViewRightAnswer" class="sample-area">
  52. <view class="line">
  53. <text :class="['sample-text', show_sample_text ? 'sample-show' : 'sample-hide']"
  54. @click="show_sample_text = !show_sample_text">{{ show_sample_text ? '隐藏范文' : '查看范文' }}</text>
  55. </view>
  56. <view class="sample-text article-content" v-if="show_sample_text" v-html="sanitizeHTML(show_sample_break)"
  57. :ref="'richText-4-4'+questionData.question_id"
  58. @longpress="previewByRichTextImg(-4,-4,questionData.question_id)"></view>
  59. </view>
  60. </view>
  61. <view class="reference" v-if="isViewAnalysis&&answer_control[questionData.question_id].isViewRightAnswer">
  62. <text class="reference-title">解析</text>
  63. <text class="reference-answer" v-html="sanitizeHTML(questionData.analysis)"
  64. :ref="'richText-5-5'+questionData.question_id"
  65. @longpress="previewByRichTextImg(-5,-5,questionData.question_id)">
  66. </text>
  67. </view>
  68. <uni-popup ref="message" type="message">
  69. <uni-popup-message type="warn" :message="messageText" :duration="2000"></uni-popup-message>
  70. </uni-popup>
  71. </view>
  72. </template>
  73. <script>
  74. import {
  75. questionData,
  76. sanitizeHTML,
  77. isEnable,
  78. answer_mode_list,
  79. answer_control,
  80. addTone,
  81. handleToneValue,
  82. } from '@/pages/answer_question/common/data/common.js';
  83. import {
  84. GetFileStoreInfo
  85. } from '@/api/api.js';
  86. import UploadFiles from '@/components/upload-files/upload-files.vue';
  87. import AnswerControlMixin from '@/pages/answer_question/common/data/AnswerControlMixin.js';
  88. export default {
  89. name: "write-picture-question",
  90. mixins: [AnswerControlMixin],
  91. props: {
  92. questionData: questionData
  93. },
  94. components: {
  95. UploadFiles
  96. },
  97. data() {
  98. return {
  99. sanitizeHTML,
  100. isEnable,
  101. answer_mode_list,
  102. answer_control,
  103. addTone,
  104. handleToneValue,
  105. pic_list: {},
  106. mode: 'indexes',
  107. swiperDotIndex: 0,
  108. active_index: 0,
  109. answer_list: [],
  110. show_sample_text: true,
  111. fontNumList: [],
  112. messageText: '',
  113. show_sample_break: '',
  114. };
  115. },
  116. watch: {
  117. answer_list: {
  118. handler(val) {
  119. if (this.isAnswerReady)
  120. this.saveUserAnswer();
  121. },
  122. deep: true,
  123. immediate: true,
  124. },
  125. 'questionData.question_id': {
  126. handler(val) {
  127. this.handleData();
  128. this.isAnswerReady = true;
  129. this.setUserAnswer();
  130. this.commonComputedAnswerControl(val);
  131. },
  132. immediate: true,
  133. deep: true
  134. }
  135. },
  136. computed: {
  137. isViewSampleText: function() {
  138. return isEnable(this.questionData.property.is_enable_sample_text);
  139. },
  140. isViewAnalysis: function() {
  141. return isEnable(this.questionData.property.is_enable_analysis);
  142. }
  143. },
  144. methods: {
  145. // 初始化数据
  146. handleData() {
  147. this.answer_list = [];
  148. this.pic_list = {};
  149. this.active_index = 0;
  150. this.swiperDotIndex = 0;
  151. this.questionData.file_id_list.forEach((item) => {
  152. GetFileStoreInfo({
  153. file_id: item
  154. }).then(({
  155. file_id,
  156. file_url
  157. }) => {
  158. this.$set(this.pic_list, file_id, file_url);
  159. });
  160. });
  161. this.questionData.option_list.forEach((item) => {
  162. let obj = {
  163. mark: item.mark,
  164. text: '',
  165. accessory_file_id_list: [],
  166. };
  167. this.answer_list.push(obj);
  168. });
  169. this.show_sample_break = this.questionData.sample_text ? this.questionData.sample_text.replace(/#/g, '</p><p>') : '';
  170. },
  171. changeImg(e) {
  172. this.active_index = e.detail.current;
  173. },
  174. clickItem(e) {
  175. this.swiperDotIndex = e;
  176. },
  177. sumfontnum(e, totalCount) {
  178. this.setQuestionEdit();
  179. this.fontNumList[0] = e.detail.value.length;
  180. if (this.fontNumList[0] === totalCount) {
  181. this.messageText = `字数达到${totalCount}字!`;
  182. this.$refs.message.open();
  183. }
  184. },
  185. setQuestionEdit() {
  186. this.questionData.user_answer[this.questionData.question_id].isEdit = true;
  187. this.$forceUpdate();
  188. },
  189. // 文件上传成功
  190. handleUpload(fileId) {
  191. this.answer_list[0].accessory_file_id_list.push(fileId);
  192. this.setQuestionEdit();
  193. },
  194. // 删除文件
  195. handleDelete(fileId) {
  196. if (this.answer_control[this.questionData.question_id].isReadOnly) return;
  197. var i = this.answer_list[0].accessory_file_id_list.indexOf(fileId);
  198. if (i > -1)
  199. this.answer_list[0].accessory_file_id_list.splice(i, 1);
  200. this.setQuestionEdit();
  201. },
  202. //填写答案后保存答案
  203. saveUserAnswer: function() {
  204. var that = this;
  205. var questionId = this.questionData.question_id;
  206. this.questionData.user_answer[questionId].isEdit = true;
  207. var ansed = that.answer_list;
  208. this.questionData.user_answer[questionId].is_fill_answer =
  209. ansed.filter(p => p.text || p.accessory_file_id_list).length > 0;
  210. this.questionData.user_answer[questionId].content = JSON.stringify(ansed);
  211. this.questionData.user_answer[questionId].answer_list = ansed;
  212. },
  213. //获取用户答案
  214. setUserAnswer: function() {
  215. var that = this;
  216. var callback = function() {
  217. var questionId = that.questionData.question_id;
  218. if (that.questionData.user_answer[questionId].answer_list.length > 0)
  219. that.answer_list = that.questionData.user_answer[questionId].answer_list;
  220. }
  221. this.$emit("getUserAnswer", this.questionData.question_id, callback);
  222. },
  223. handleTone(value, questionId) {
  224. this.questionData.user_answer[questionId].answer_list[0].text = value
  225. .trim()
  226. .split(/\s+/)
  227. .map((item) => {
  228. return handleToneValue(item);
  229. })
  230. .map((item) =>
  231. item.map(({
  232. number,
  233. con
  234. }) => (number && con ? addTone(Number(number), con) : number || con || '')),
  235. )
  236. .filter((item) => item.length > 0)
  237. .join(' ');
  238. this.$forceUpdate();
  239. },
  240. }
  241. }
  242. </script>
  243. <style lang="scss" scoped>
  244. .write-picture-area {
  245. .option-area {
  246. margin-top: 32rpx;
  247. .article-text {
  248. margin: 32rpx auto;
  249. font-size: $font-size-serial;
  250. }
  251. /deep/.uni-swiper__warp {
  252. height: 380rpx;
  253. .uni-swiper__dots-box {
  254. bottom: 0 !important;
  255. }
  256. .swiper {
  257. height: 328rpx;
  258. .swiper-item {
  259. height: 100%;
  260. margin: 0 8rpx;
  261. border-radius: 8rpx;
  262. background-color: $uni-bg-color-grey;
  263. display: flex;
  264. justify-content: center;
  265. align-items: center;
  266. opacity: 0.4;
  267. &.active {
  268. opacity: 1;
  269. }
  270. }
  271. }
  272. }
  273. // .pic-title {
  274. // margin: 32rpx 0;
  275. // font-size: $uni-font-size-sm;
  276. // font-weight: $uni-font-weight-6;
  277. // }
  278. .pic-info {
  279. margin: 32rpx 0;
  280. font-size: 12pt;
  281. }
  282. .write-content {
  283. margin: 32rpx 0;
  284. min-height: 330rpx;
  285. height: auto;
  286. width: 100%;
  287. background-color: $uni-bg-color-grey;
  288. border-radius: 16rpx;
  289. display: flex;
  290. flex-direction: column;
  291. textarea {
  292. width: 95%;
  293. height: 100%;
  294. font-size: 28rpx;
  295. line-height: 56rpx;
  296. margin: 0 auto;
  297. flex: 1;
  298. }
  299. .fontNum {
  300. position: relative;
  301. text-align: right;
  302. color: #86909C;
  303. padding: 8rpx 16rpx;
  304. border-radius: 0 0 16rpx 16rpx;
  305. }
  306. }
  307. }
  308. .sample-area {
  309. margin-top: 64rpx;
  310. .line {
  311. height: 1px;
  312. background: #dcdfe6;
  313. text-align: center;
  314. text {
  315. position: relative;
  316. background-color: #ffffff;
  317. padding: 0 10rpx;
  318. top: -22rpx;
  319. font-size: 26rpx;
  320. }
  321. }
  322. .sample-text {
  323. font-size: $font-size-serial;
  324. margin-top: 32rpx;
  325. /deep/ p {
  326. margin: 0;
  327. }
  328. &.sample-show {
  329. color: #306eff;
  330. }
  331. }
  332. .article-content {
  333. text-indent: 2em;
  334. }
  335. }
  336. .reference {
  337. margin: 32rpx 0;
  338. background-color: #f9f8f9;
  339. padding: 24rpx;
  340. .reference-title {
  341. display: block;
  342. line-height: 64rpx;
  343. color: #4E5969;
  344. font-size: 28rpx;
  345. }
  346. .reference-answer {
  347. color: #1D2129;
  348. line-height: 48rpx;
  349. font-size: 14pt;
  350. }
  351. }
  352. }
  353. </style>
  354. <style>
  355. /deep/ .uni-swiper__dots-box {
  356. .uni-swiper__dots-indexes {
  357. width: 38rpx !important;
  358. height: 38rpx !important;
  359. }
  360. }
  361. </style>