diff --git a/src/components/comment-input/comment-input.vue b/src/components/comment-input/comment-input.vue index 48b56264..1af81dae 100644 --- a/src/components/comment-input/comment-input.vue +++ b/src/components/comment-input/comment-input.vue @@ -3,24 +3,11 @@ - + - + @@ -33,36 +20,20 @@ 最多可添加4张图片 - + 建议 - + 提问 - + - + @@ -77,21 +48,23 @@ - 发送 + 发送 - + - + - + @@ -116,26 +89,38 @@ import commentInput2 from '@/static/images/courseDetail/comment-input-2.png' import commentInput3 from '@/static/images/courseDetail/comment-input-3.png' import commentInput4 from '@/static/images/courseDetail/comment-input-4.png' - import { reactive, ref, watch, nextTick, computed, onBeforeUnmount } from 'vue'; - import { emojiList } from '@/emoji'; - import { publishCrsEvaluation, queryTraMemeInfoList } from '@/api/courseDetail.js' + import { + reactive, + ref, + watch, + nextTick, + computed, + onBeforeUnmount + } from 'vue'; + import { + emojiList + } from '@/emoji'; + import { + publishCrsEvaluation, + queryTraMemeInfoList + } from '@/api/courseDetail.js' import common from '@/common/common.js'; import { uploadFile } from '@/api/common' - + const props = defineProps({ - crsId:{ + crsId: { type: String, default: '' } }) - + const emit = defineEmits(['submitOver', 'sendReply']) - + const isReply = ref(false) const clickHandler = () => { - if(!isShow.value){ + if (!isShow.value) { isReply.value = false } } @@ -149,7 +134,7 @@ const isShow = ref(false); const value = ref(''); const click_input = () => { - if(!isShow.value) isShow.value = true + if (!isShow.value) isShow.value = true } const textareaRef = ref() const isFocus = ref(false) @@ -163,7 +148,7 @@ isFocus.value = true cursorLength.value = resStart.value || value.value.length } - const sendDisabled = computed(()=>{ + const sendDisabled = computed(() => { return value.value.length === 0 && fileList.value.length === 0 }) const showEmoji = ref(false) @@ -174,14 +159,14 @@ const focus = (event) => { isShow.value = true isFocus.value = true - if(!isReply.value){ + if (!isReply.value) { getMemList() } } - const placeholder = computed(()=>{ - if(isReply.value){ - return answerData.value.placeholder||'请输入回复信息' - }else{ + const placeholder = computed(() => { + if (isReply.value) { + return answerData.value.placeholder || '请输入回复信息' + } else { return '发条评论,和大家一起讨论' } }) @@ -192,22 +177,23 @@ isShow.value = true isFocus.value = false } - const hideAll = (flag=false) => { + const hideAll = (flag = false) => { popHeight.value = '0px' isShow.value = false isFocus.value = false - if(flag){ + isReply.value = false + if (flag) { value.value = '' fileList.value = [] } } const answerData = ref({}) - const resetVal = (data={} , $isReply = true) => { + const resetVal = (data = {}, $isReply = true) => { value.value = '' fileList.value = [] - isReply.value = $isReply + isReply.value = $isReply answerData.value = data || {} - if($isReply){ + if ($isReply) { focus() // showKeyborad() } @@ -215,17 +201,17 @@ const insertValue = (emojiItem) => { let _val = value.value value.value = _val.substring(0, resStart.value) + emojiItem + _val.substring(resStart.value, _val.length) - resStart.value+=emojiItem.length + resStart.value += emojiItem.length } const fileList = ref([]); const bbsTag = ref('SUG') // 方法 - + const uploadNow = (limit = 4) => { - if(isImg.value || fileList.value === 0){ + if (isImg.value || fileList.value === 0) { upload(limit) - }else{ - common.show('','是否清空当前表情并重新添加?').then((res) => { + } else { + common.show('', '是否清空当前表情并重新添加?').then((res) => { if (res) { fileList.value = [] upload(limit) @@ -262,30 +248,30 @@ } const memList = ref([]) const getMemList = () => { - if(memList.value.length > 0){ + if (memList.value.length > 0) { return } - queryTraMemeInfoList().then(res=>{ + queryTraMemeInfoList().then(res => { memList.value = res.body || [] }) } const setMemValue = (item) => { - if(!isImg.value || fileList.value.length == 0){ + if (!isImg.value || fileList.value.length == 0) { fileList.value = [item.ossKey] isImg.value = false return } - common.show('','是否清空当前图片并重新添加?').then((res) => { + common.show('', '是否清空当前图片并重新添加?').then((res) => { if (res) { fileList.value = [item.ossKey] isImg.value = false } }); } - + const submit = () => { - if(isReply.value){ - reply_send() + if (isReply.value) { + reply_send() return } if (value.value === '' && fileList.value.length === 0) { @@ -303,7 +289,7 @@ bbsGrade: bbsGrade.value, // 综合评分(最高10分) bbsTag: bbsTag.value, // 评价标签 (SUG 建议 ASK 提问 ) bbsContent: value.value, // 评价内容 - imgTyp: isImg.value? '01':'02' + imgTyp: isImg.value ? '01' : '02' } publishCrsEvaluation(_params).then((res) => { const loadingDuration = Date.now() - loadingStartTime; @@ -320,71 +306,83 @@ emit('submitOver') }, 500); }, delayTime); - }).catch(err=>{}) + }).catch(err => {}) }; const reply_send = async () => { - emit('sendReply', {...answerData.value, bbsContent: value.value}) + emit('sendReply', { + ...answerData.value, + bbsContent: value.value + }) }; const bbsGrade = ref(10) const sliderChange = (event) => { bbsGrade.value = event.detail.value; }; - watch(()=> fileList.value, (val)=>{ - if(val.length === 0){ + watch(() => fileList.value, (val) => { + if (val.length === 0) { isImg.value = true } }) const keyboardHeight = ref(0) const maxKeyboardHeight = ref(0) - uni.onKeyboardHeightChange((res)=>{ - maxKeyboardHeight.value = res.height > keyboardHeight.value?res.height : keyboardHeight.value + uni.onKeyboardHeightChange((res) => { + maxKeyboardHeight.value = res.height > keyboardHeight.value ? res.height : keyboardHeight.value keyboardHeight.value = res.height }) - onBeforeUnmount(()=>{ - + onBeforeUnmount(() => { + }) - watch(()=> showEmoji.value,(val)=>{ - popHeight.value = val ? `${maxKeyboardHeight.value}px` : (keyboardHeight.value+'px') + watch(() => showEmoji.value, (val) => { + popHeight.value = val ? `${maxKeyboardHeight.value}px` : (keyboardHeight.value + 'px') }) - watch(()=> keyboardHeight.value,(val)=>{ - popHeight.value = showEmoji.value ? `${maxKeyboardHeight.value}px` : keyboardHeight.value+'px' + watch(() => keyboardHeight.value, (val) => { + popHeight.value = showEmoji.value ? `${maxKeyboardHeight.value}px` : keyboardHeight.value + 'px' + }) + defineExpose({ + hideAll, + resetVal }) - defineExpose({hideAll, resetVal}) + \ No newline at end of file diff --git a/src/pages/index/components/question.vue b/src/pages/index/components/question.vue index 324abf97..0f79a812 100644 --- a/src/pages/index/components/question.vue +++ b/src/pages/index/components/question.vue @@ -115,6 +115,7 @@ isPlaying.value = true if (talkVoiceObj.value && talkVoiceObj.value.src) { console.log(1, talkVoiceObj.value.src) + talkVoiceObj.value.seek(0); setTimeout(() => { talkVoiceObj.value.play() }, 100) @@ -135,6 +136,7 @@ itemVoice.value = url; talkVoiceObj.value.src = url; if (unref(dataInfo)?.id !== props.activeVoiceId) return + talkVoiceObj.value.seek(0); talkVoiceObj.value.play(); } else { downloadFile(unref(dataInfo).bucketKey)