草稿处理

This commit is contained in:
2022-02-07 14:05:48 +08:00
parent 716792404c
commit 3c48112bf8

View File

@@ -1,12 +1,13 @@
<template> <template>
<view class="text"> <view class="text">
<input class="input" type="text" v-model="inputTxt" confirm-type="send" @confirm="send" cursor-spacing="10" /> <input class="input" type="text" v-model="inputTxt" confirm-type="send" @confirm="sent" cursor-spacing="10" />
<text class="button" size="mini" @click="send">发送</text> <button class="button" size="mini" :disabled="disabled" @click="sent">发送</button>
</view> </view>
</template> </template>
<script> <script>
import im from '@/utils/im/index.js' import im from '@/utils/im/index.js'
import * as RongIMLib from "@/uni_modules/RongCloud-IMWrapper/js_sdk/index"
export default { export default {
props: { props: {
@@ -20,29 +21,48 @@
}, },
inputTxt: { inputTxt: {
type: String, type: String,
default: '1234567890' default: ''
} }
}, },
computed: {
disabled() {
return this.inputTxt.length === 0
}
},
created() {
RongIMLib.getTextMessageDraft(this.conversationType, this.targetId, ({
draft
}) => {
draft ? this.inputTxt = draft : ''
})
},
beforeDestroy() {
RongIMLib.saveTextMessageDraft(this.conversationType, this.targetId, this.inputTxt, (res) => {
console.log('销毁组件之前,保存草稿信息,但是没有执行', res);
})
},
methods: { methods: {
// 发送文本消息 // 发送文本消息
send() { sent() {
if (this.inputTxt === '') return if (!this.disabled) {
im.sentText(this.conversationType, this.targetId, this.inputTxt, () => { RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId)
setTimeout(() => { im.sentText(this.conversationType, this.targetId, this.inputTxt, () => {
this.$emit('success') setTimeout(() => {
}, 500) this.$emit('success')
this.inputTxt = '' }, 500)
}) this.inputTxt = ''
}, })
}
}
} }
} }
</script> </script>
<style scoped> <style scoped>
.text { .text {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
} }
.input { .input {
@@ -55,6 +75,7 @@
} }
.button { .button {
border: none;
background: #34CE98; background: #34CE98;
color: white; color: white;
width: 120rpx; width: 120rpx;
@@ -64,4 +85,8 @@
font-size: 30rpx; font-size: 30rpx;
font-weight: bold; font-weight: bold;
} }
.button[disabled] {
background-color: #555555;
}
</style> </style>