123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- <template>
- <!-- 看图写作题 -->
- <view class="write-picture-area" v-model="questionData">
- <view class="question_title">
- <text class="question_number">
- {{ questionNumberEndIsBracket(questionData.property.question_number) }}
- </text>
- <text class="question_stem" v-html="sanitizeHTML(questionData.stem)"
- :ref="'richText-1-1'+questionData.question_id"
- @longpress="previewByRichTextImg(-1,-1,questionData.question_id)"></text>
- </view>
- <view class="description" :ref="'richText-2-2'+questionData.question_id"
- @longpress="previewByRichTextImg(-2,-2,questionData.question_id)"
- v-if="isEnable(questionData.property.is_enable_description)&&questionData.description"
- v-html="sanitizeHTML(questionData.description)">
- </view>
- <view class="option-area">
- <!-- <view class="article-text" v-html="sanitizeHTML(questionData.article)"></view> -->
- <uni-swiper-dot :info="questionData.option_list" :current="active_index" :mode="mode" @clickItem="clickItem">
- <swiper class="swiper" circular previous-margin="50px" next-margin="50px" @change="changeImg"
- :current="swiperDotIndex">
- <swiper-item v-for="(item, index) in questionData.option_list" :key="index">
- <view :class="['swiper-item',active_index==index?'active':'']">
- <image :src="pic_list[item.picture_file_id]" mode="aspectFit"
- @click="preview(pic_list[item.picture_file_id])"></image>
- </view>
- </swiper-item>
- </swiper>
- </uni-swiper-dot>
- <!-- <view class="pic-title" v-html="sanitizeHTML(questionData.option_list[active_index].picture_title)"></view> -->
- <view class="pic-info" v-html="sanitizeHTML(questionData.option_list[active_index].picture_info)"
- :ref="'richText-3-3'+questionData.question_id"
- @longpress="previewByRichTextImg(-3,-3,questionData.question_id)"></view>
- <view class="write-content">
- <textarea :maxlength="questionData.property.word_num" v-model="answer_list[0].text"
- @input="sumfontnum($event,questionData.property.word_num)" placeholder="请输入"
- :disabled="answer_control[questionData.question_id].isReadOnly" auto-height
- @blur="handleTone(answer_list[0].text, questionData.question_id);" />
- <view class="fontNum">
- <text>
- {{fontNumList[0]>0?fontNumList[0]:answer_list[0].text.length}}
- </text>/{{questionData.property.word_num}}
- </view>
- </view>
- <template v-if="isEnable(questionData.property.is_enable_upload_accessory)">
- <!-- 上传文件 -->
- <UploadFiles upload-title="" :fileIdList="answer_list[0].accessory_file_id_list" @upload="handleUpload"
- @deleteFile="handleDelete" :disabled="answer_control[questionData.question_id].isReadOnly">
- </UploadFiles>
- </template>
- <view v-if="isViewSampleText&&answer_control[questionData.question_id].isViewRightAnswer" class="sample-area">
- <view class="line">
- <text :class="['sample-text', show_sample_text ? 'sample-show' : 'sample-hide']"
- @click="show_sample_text = !show_sample_text">{{ show_sample_text ? '隐藏范文' : '查看范文' }}</text>
- </view>
- <view class="sample-text article-content" v-if="show_sample_text" v-html="sanitizeHTML(show_sample_break)"
- :ref="'richText-4-4'+questionData.question_id"
- @longpress="previewByRichTextImg(-4,-4,questionData.question_id)"></view>
- </view>
- </view>
- <view class="reference" v-if="isViewAnalysis&&answer_control[questionData.question_id].isViewRightAnswer">
- <text class="reference-title">解析</text>
- <text class="reference-answer" v-html="sanitizeHTML(questionData.analysis)"
- :ref="'richText-5-5'+questionData.question_id"
- @longpress="previewByRichTextImg(-5,-5,questionData.question_id)">
- </text>
- </view>
- <uni-popup ref="message" type="message">
- <uni-popup-message type="warn" :message="messageText" :duration="2000"></uni-popup-message>
- </uni-popup>
- </view>
- </template>
- <script>
- import {
- questionData,
- sanitizeHTML,
- isEnable,
- answer_mode_list,
- answer_control,
- addTone,
- handleToneValue,
- } from '@/pages/answer_question/common/data/common.js';
- import {
- GetFileStoreInfo
- } from '@/api/api.js';
- import UploadFiles from '@/components/upload-files/upload-files.vue';
- import AnswerControlMixin from '@/pages/answer_question/common/data/AnswerControlMixin.js';
- export default {
- name: "write-picture-question",
- mixins: [AnswerControlMixin],
- props: {
- questionData: questionData
- },
- components: {
- UploadFiles
- },
- data() {
- return {
- sanitizeHTML,
- isEnable,
- answer_mode_list,
- answer_control,
- addTone,
- handleToneValue,
- pic_list: {},
- mode: 'indexes',
- swiperDotIndex: 0,
- active_index: 0,
- answer_list: [],
- show_sample_text: true,
- fontNumList: [],
- messageText: '',
- show_sample_break: '',
- };
- },
- watch: {
- answer_list: {
- handler(val) {
- if (this.isAnswerReady)
- this.saveUserAnswer();
- },
- deep: true,
- immediate: true,
- },
- 'questionData.question_id': {
- handler(val) {
- this.handleData();
- this.isAnswerReady = true;
- this.setUserAnswer();
- this.commonComputedAnswerControl(val);
- },
- immediate: true,
- deep: true
- }
- },
- computed: {
- isViewSampleText: function() {
- return isEnable(this.questionData.property.is_enable_sample_text);
- },
- isViewAnalysis: function() {
- return isEnable(this.questionData.property.is_enable_analysis);
- }
- },
- methods: {
- // 初始化数据
- handleData() {
- this.answer_list = [];
- this.pic_list = {};
- this.active_index = 0;
- this.swiperDotIndex = 0;
- this.questionData.file_id_list.forEach((item) => {
- GetFileStoreInfo({
- file_id: item
- }).then(({
- file_id,
- file_url
- }) => {
- this.$set(this.pic_list, file_id, file_url);
- });
- });
- this.questionData.option_list.forEach((item) => {
- let obj = {
- mark: item.mark,
- text: '',
- accessory_file_id_list: [],
- };
- this.answer_list.push(obj);
- });
- this.show_sample_break = this.questionData.sample_text ? this.questionData.sample_text.replace(/#/g, '</p><p>') : '';
- },
- changeImg(e) {
- this.active_index = e.detail.current;
- },
- clickItem(e) {
- this.swiperDotIndex = e;
- },
- sumfontnum(e, totalCount) {
- this.setQuestionEdit();
- this.fontNumList[0] = e.detail.value.length;
- if (this.fontNumList[0] === totalCount) {
- this.messageText = `字数达到${totalCount}字!`;
- this.$refs.message.open();
- }
- },
- setQuestionEdit() {
- this.questionData.user_answer[this.questionData.question_id].isEdit = true;
- this.$forceUpdate();
- },
- // 文件上传成功
- handleUpload(fileId) {
- this.answer_list[0].accessory_file_id_list.push(fileId);
- this.setQuestionEdit();
- },
- // 删除文件
- handleDelete(fileId) {
- if (this.answer_control[this.questionData.question_id].isReadOnly) return;
- var i = this.answer_list[0].accessory_file_id_list.indexOf(fileId);
- if (i > -1)
- this.answer_list[0].accessory_file_id_list.splice(i, 1);
- this.setQuestionEdit();
- },
- //填写答案后保存答案
- saveUserAnswer: function() {
- var that = this;
- var questionId = this.questionData.question_id;
- this.questionData.user_answer[questionId].isEdit = true;
- var ansed = that.answer_list;
- this.questionData.user_answer[questionId].is_fill_answer =
- ansed.filter(p => p.text || p.accessory_file_id_list).length > 0;
- this.questionData.user_answer[questionId].content = JSON.stringify(ansed);
- this.questionData.user_answer[questionId].answer_list = ansed;
- },
- //获取用户答案
- setUserAnswer: function() {
- var that = this;
- var callback = function() {
- var questionId = that.questionData.question_id;
- if (that.questionData.user_answer[questionId].answer_list.length > 0)
- that.answer_list = that.questionData.user_answer[questionId].answer_list;
- }
- this.$emit("getUserAnswer", this.questionData.question_id, callback);
- },
- handleTone(value, questionId) {
- this.questionData.user_answer[questionId].answer_list[0].text = value
- .trim()
- .split(/\s+/)
- .map((item) => {
- return handleToneValue(item);
- })
- .map((item) =>
- item.map(({
- number,
- con
- }) => (number && con ? addTone(Number(number), con) : number || con || '')),
- )
- .filter((item) => item.length > 0)
- .join(' ');
- this.$forceUpdate();
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .write-picture-area {
- .option-area {
- margin-top: 32rpx;
- .article-text {
- margin: 32rpx auto;
- font-size: $font-size-serial;
- }
- /deep/.uni-swiper__warp {
- height: 380rpx;
- .uni-swiper__dots-box {
- bottom: 0 !important;
- }
- .swiper {
- height: 328rpx;
- .swiper-item {
- height: 100%;
- margin: 0 8rpx;
- border-radius: 8rpx;
- background-color: $uni-bg-color-grey;
- display: flex;
- justify-content: center;
- align-items: center;
- opacity: 0.4;
- &.active {
- opacity: 1;
- }
- }
- }
- }
- // .pic-title {
- // margin: 32rpx 0;
- // font-size: $uni-font-size-sm;
- // font-weight: $uni-font-weight-6;
- // }
- .pic-info {
- margin: 32rpx 0;
- font-size: 12pt;
- }
- .write-content {
- margin: 32rpx 0;
- min-height: 330rpx;
- height: auto;
- width: 100%;
- background-color: $uni-bg-color-grey;
- border-radius: 16rpx;
- display: flex;
- flex-direction: column;
- textarea {
- width: 95%;
- height: 100%;
- font-size: 28rpx;
- line-height: 56rpx;
- margin: 0 auto;
- flex: 1;
- }
- .fontNum {
- position: relative;
- text-align: right;
- color: #86909C;
- padding: 8rpx 16rpx;
- border-radius: 0 0 16rpx 16rpx;
- }
- }
- }
- .sample-area {
- margin-top: 64rpx;
- .line {
- height: 1px;
- background: #dcdfe6;
- text-align: center;
- text {
- position: relative;
- background-color: #ffffff;
- padding: 0 10rpx;
- top: -22rpx;
- font-size: 26rpx;
- }
- }
- .sample-text {
- font-size: $font-size-serial;
- margin-top: 32rpx;
- /deep/ p {
- margin: 0;
- }
- &.sample-show {
- color: #306eff;
- }
- }
- .article-content {
- text-indent: 2em;
- }
- }
- .reference {
- margin: 32rpx 0;
- background-color: #f9f8f9;
- padding: 24rpx;
- .reference-title {
- display: block;
- line-height: 64rpx;
- color: #4E5969;
- font-size: 28rpx;
- }
- .reference-answer {
- color: #1D2129;
- line-height: 48rpx;
- font-size: 14pt;
- }
- }
- }
- </style>
- <style>
- /deep/ .uni-swiper__dots-box {
- .uni-swiper__dots-indexes {
- width: 38rpx !important;
- height: 38rpx !important;
- }
- }
- </style>
|