/
inputer.vue
162 lines (154 loc) · 4.15 KB
/
inputer.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<template>
<div class="inputer_frame">
<div class="input">
<div class="attach">
<input @change="fileChangeHandler" ref="fileRef" type="file" />
<span v-popover:tooltip.top="'发送图片'" @click="imageUploadClickHandler" class="ico image"></span>
<span v-popover:tooltip.top="'发送文件'" @click="fileUploadClickHandler" class="ico file"></span>
</div>
<div>
<textarea
@blur="inputBlurHandler"
@focus="inputFocusHandler"
@keydown="textareaKeyDown"
class="input_text"
:placeholder="[[placeholder]]"
v-model="message"
wrap="hard"
ref="inputTextRef"
focus
></textarea>
<div class="button">
<div @click="handleSendMessage" class="im_send" />
</div>
</div>
</div>
<div class="support_link">
<span>AppID:{{ appid }}</span>
<a href="https://www.lanyingim.com" target="_blank">打造你的智能聊天APP,使用蓝莺IM SDK</a>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex';
export default {
name: 'rosterInputer',
data() {
return {
placeholder: '',
message: '',
fileType: ''
};
},
components: {},
computed: {
...mapGetters('content', ['getSid', 'getIntentMessage']),
im() {
return this.$store.state.im;
},
appid() {
return this.$store.state.im.userManage.getAppid();
}
},
mounted() {
this.initIntentMessage();
},
methods: {
textareaKeyDown(evt) {
if (evt.keyCode === 13 && !evt.shiftKey) {
this.handleSendMessage();
if (evt && evt.stopPropagation) {
evt.preventDefault();
} else {
window.event.cancelBubble = true;
return false;
}
}
},
imageUploadClickHandler() {
this.fileType = 'image';
this.$refs.fileRef.click();
},
fileUploadClickHandler() {
this.fileType = 'file';
this.$refs.fileRef.click();
},
locationClickHandler() {
const message = {
uid: this.getSid,
content: '',
type: 'location',
attachment: {
lat: 40.024422,
lon: 116.398376,
addr: '奥林匹克森林公园'
}
};
this.im.sysManage.sendRosterMessage(message);
},
handleSendMessage() {
if (/^\s*$/.test(this.message)) {
this.message = this.placeholder;
if (/^\s*$/.test(this.message)) return;
}
// 如果需要自定义消息,直接使用 ext 字段即可
this.im.sysManage.sendRosterMessage({
content: this.message,
uid: this.getSid
// ext: "自定义消息字段",
});
setTimeout(() => {
this.message = '';
}, 200);
},
fileChangeHandler(e) {
const file = e.target.files[0];
this.im.sysManage
.asyncFileUpload({
file,
fileType: this.fileType,
to_id: this.getSid,
toType: 'chat',
chatType: 'roster',
processCallback: function (res) {
console.log('fileChangeHandler roster chat file upload percent :' + Math.floor(100 * (res.loaded / res.total)));
}
})
.then((res) => {
const fileInfo = {
dName: file.name,
fLen: file.size,
width: 0,
height: 0
};
fileInfo.url = res.url;
this.im.sysManage.sendRosterMessage({
type: this.fileType,
uid: this.getSid,
content: '',
attachment: fileInfo
});
this.$refs.fileRef.value = '';
})
.catch(() => {
this.$refs.fileRef.value = '';
});
},
inputFocusHandler() {
this.im.sysManage.sendInputStatusMessage(this.getSid, 'typing');
},
inputBlurHandler() {
this.im.sysManage.sendInputStatusMessage(this.getSid, 'nothing');
},
initIntentMessage() {
if (this.getIntentMessage) {
this.placeholder = this.getIntentMessage;
this.$nextTick(() => {
this.$refs.inputTextRef.focus();
});
}
}
//methods finish
}
};
</script>