write-picture-question.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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" v-if="show_sample_text" v-html="sanitizeHTML(questionData.sample_text)"
  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. };
  114. },
  115. watch: {
  116. answer_list: {
  117. handler(val) {
  118. if (this.isAnswerReady)
  119. this.saveUserAnswer();
  120. },
  121. deep: true,
  122. immediate: true,
  123. },
  124. 'questionData.question_id': {
  125. handler(val) {
  126. this.handleData();
  127. this.isAnswerReady = true;
  128. this.setUserAnswer();
  129. this.commonComputedAnswerControl(val);
  130. },
  131. immediate: true,
  132. deep: true
  133. }
  134. },
  135. computed: {
  136. isViewSampleText: function() {
  137. return isEnable(this.questionData.property.is_enable_sample_text);
  138. },
  139. isViewAnalysis: function() {
  140. return isEnable(this.questionData.property.is_enable_analysis);
  141. }
  142. },
  143. methods: {
  144. // 初始化数据
  145. handleData() {
  146. this.answer_list = [];
  147. this.pic_list = {};
  148. this.active_index = 0;
  149. this.swiperDotIndex = 0;
  150. this.questionData.file_id_list.forEach((item) => {
  151. GetFileStoreInfo({
  152. file_id: item
  153. }).then(({
  154. file_id,
  155. file_url
  156. }) => {
  157. this.$set(this.pic_list, file_id, file_url);
  158. });
  159. });
  160. this.questionData.option_list.forEach((item) => {
  161. let obj = {
  162. mark: item.mark,
  163. text: '',
  164. accessory_file_id_list: [],
  165. };
  166. this.answer_list.push(obj);
  167. });
  168. },
  169. changeImg(e) {
  170. this.active_index = e.detail.current;
  171. },
  172. clickItem(e) {
  173. this.swiperDotIndex = e;
  174. },
  175. sumfontnum(e, totalCount) {
  176. this.setQuestionEdit();
  177. this.fontNumList[0] = e.detail.value.length;
  178. if (this.fontNumList[0] === totalCount) {
  179. this.messageText = `字数达到${totalCount}字!`;
  180. this.$refs.message.open();
  181. }
  182. },
  183. setQuestionEdit() {
  184. this.questionData.user_answer[this.questionData.question_id].isEdit = true;
  185. this.$forceUpdate();
  186. },
  187. // 文件上传成功
  188. handleUpload(fileId) {
  189. this.answer_list[0].accessory_file_id_list.push(fileId);
  190. this.setQuestionEdit();
  191. },
  192. // 删除文件
  193. handleDelete(fileId) {
  194. if (this.answer_control[this.questionData.question_id].isReadOnly) return;
  195. var i = this.answer_list[0].accessory_file_id_list.indexOf(fileId);
  196. if (i > -1)
  197. this.answer_list[0].accessory_file_id_list.splice(i, 1);
  198. this.setQuestionEdit();
  199. },
  200. //填写答案后保存答案
  201. saveUserAnswer: function() {
  202. var that = this;
  203. var questionId = this.questionData.question_id;
  204. this.questionData.user_answer[questionId].isEdit = true;
  205. var ansed = that.answer_list;
  206. this.questionData.user_answer[questionId].is_fill_answer =
  207. ansed.filter(p => p.text || p.accessory_file_id_list).length > 0;
  208. this.questionData.user_answer[questionId].content = JSON.stringify(ansed);
  209. this.questionData.user_answer[questionId].answer_list = ansed;
  210. },
  211. //获取用户答案
  212. setUserAnswer: function() {
  213. var that = this;
  214. var callback = function() {
  215. var questionId = that.questionData.question_id;
  216. if (that.questionData.user_answer[questionId].answer_list.length > 0)
  217. that.answer_list = that.questionData.user_answer[questionId].answer_list;
  218. }
  219. this.$emit("getUserAnswer", this.questionData.question_id, callback);
  220. },
  221. handleTone(value, questionId) {
  222. this.questionData.user_answer[questionId].answer_list[0].text = value
  223. .trim()
  224. .split(/\s+/)
  225. .map((item) => {
  226. return handleToneValue(item);
  227. })
  228. .map((item) =>
  229. item.map(({
  230. number,
  231. con
  232. }) => (number && con ? addTone(Number(number), con) : number || con || '')),
  233. )
  234. .filter((item) => item.length > 0)
  235. .join(' ');
  236. this.$forceUpdate();
  237. },
  238. }
  239. }
  240. </script>
  241. <style lang="scss" scoped>
  242. .write-picture-area {
  243. .option-area {
  244. margin-top: 32rpx;
  245. .article-text {
  246. margin: 32rpx auto;
  247. font-size: $font-size-serial;
  248. }
  249. /deep/.uni-swiper__warp {
  250. height: 380rpx;
  251. .uni-swiper__dots-box {
  252. bottom: 0 !important;
  253. }
  254. .swiper {
  255. height: 328rpx;
  256. .swiper-item {
  257. height: 100%;
  258. margin: 0 8rpx;
  259. border-radius: 8rpx;
  260. background-color: $uni-bg-color-grey;
  261. display: flex;
  262. justify-content: center;
  263. align-items: center;
  264. opacity: 0.4;
  265. &.active {
  266. opacity: 1;
  267. }
  268. }
  269. }
  270. }
  271. // .pic-title {
  272. // margin: 32rpx 0;
  273. // font-size: $uni-font-size-sm;
  274. // font-weight: $uni-font-weight-6;
  275. // }
  276. .pic-info {
  277. margin: 32rpx 0;
  278. font-size: 12pt;
  279. }
  280. .write-content {
  281. margin: 32rpx 0;
  282. min-height: 330rpx;
  283. height: auto;
  284. width: 100%;
  285. background-color: $uni-bg-color-grey;
  286. border-radius: 16rpx;
  287. display: flex;
  288. flex-direction: column;
  289. textarea {
  290. width: 95%;
  291. height: 100%;
  292. font-size: 28rpx;
  293. line-height: 56rpx;
  294. margin: 0 auto;
  295. flex: 1;
  296. }
  297. .fontNum {
  298. position: relative;
  299. text-align: right;
  300. color: #86909C;
  301. padding: 8rpx 16rpx;
  302. border-radius: 0 0 16rpx 16rpx;
  303. }
  304. }
  305. }
  306. .sample-area {
  307. margin-top: 64rpx;
  308. .line {
  309. height: 1px;
  310. background: #dcdfe6;
  311. text-align: center;
  312. text {
  313. position: relative;
  314. background-color: #ffffff;
  315. padding: 0 10rpx;
  316. top: -22rpx;
  317. font-size: 26rpx;
  318. }
  319. }
  320. .sample-text {
  321. font-size: $font-size-serial;
  322. margin-top: 32rpx;
  323. /deep/ p {
  324. margin: 0;
  325. }
  326. &.sample-show {
  327. color: #306eff;
  328. }
  329. }
  330. }
  331. .reference {
  332. margin: 32rpx 0;
  333. background-color: #f9f8f9;
  334. padding: 24rpx;
  335. .reference-title {
  336. display: block;
  337. line-height: 64rpx;
  338. color: #4E5969;
  339. font-size: 28rpx;
  340. }
  341. .reference-answer {
  342. color: #1D2129;
  343. line-height: 48rpx;
  344. font-size: 14pt;
  345. }
  346. }
  347. }
  348. </style>
  349. <style>
  350. /deep/ .uni-swiper__dots-box {
  351. .uni-swiper__dots-indexes {
  352. width: 38rpx !important;
  353. height: 38rpx !important;
  354. }
  355. }
  356. </style>