Files
ZhHealth/pages/im/components/sentText.nvue
2022-02-08 14:11:15 +08:00

96 lines
2.8 KiB
Plaintext

<template>
<view class="sent--text">
<input class="input" type="text" @focus="focus" @blur="blur" v-model="inputTxt" confirm-type="send" @confirm="sent" cursor-spacing="10" />
<!-- <button class="button" size="mini" :disabled="disabled" @click="sent">发送</button> -->
</view>
</template>
<script>
import im from '@/utils/im/index.js'
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
export default {
props: {
conversationType: {
type: Number,
default: 0
},
targetId: {
type: String,
default: ''
},
inputTxt: {
type: String,
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: {
// 发送文本消息
sent() {
if (!this.disabled) {
RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId)
im.sentText(this.conversationType, this.targetId, this.inputTxt, () => {
this.$emit('success')
this.inputTxt = ''
})
}
},
focus() {
this.$emit('focus')
},
blur() {
this.$emit('blur')
}
}
}
</script>
<style scoped lang="scss">
.sent--text {
display: flex;
flex-direction: row;
justify-content: space-between;
.input {
background: #F3F6FB;
height: 70rpx;
width: 460rpx;
border-radius: 10rpx;
margin-right: 15rpx;
padding: 0 20rpx;
}
// .button {
// border: none;
// background: #34CE98;
// color: white;
// width: 120rpx;
// line-height: 70rpx;
// text-align: center;
// border-radius: 10rpx;
// font-size: 30rpx;
// font-weight: bold;
// }
// .button[disabled] {
// background-color: #555555;
// }
}
</style>