Initial commit
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<template>
|
||||
<view class="chat_action_bar">
|
||||
<u-row class="action_row">
|
||||
<u-col
|
||||
v-for="item in actionList"
|
||||
:key="item.idx"
|
||||
@click="actionClick(item)"
|
||||
span="3"
|
||||
>
|
||||
<view class="action_item">
|
||||
<image :src="item.icon" alt="" srcset="" />
|
||||
<text class="action_item_title">{{ item.title }}</text>
|
||||
</view>
|
||||
</u-col>
|
||||
</u-row>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
ChatingFooterActionTypes,
|
||||
} from "@/constant";
|
||||
|
||||
export default {
|
||||
components: {},
|
||||
data() {
|
||||
return {
|
||||
actionList: [
|
||||
{
|
||||
idx: 0,
|
||||
type: ChatingFooterActionTypes.Album,
|
||||
title: "相册",
|
||||
icon: require("static/images/chating_action_image.png"),
|
||||
},
|
||||
{
|
||||
idx: 1,
|
||||
type: ChatingFooterActionTypes.File,
|
||||
title: "文件",
|
||||
icon: require("static/images/chating_action_file.png"),
|
||||
}
|
||||
],
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async actionClick(action) {
|
||||
switch (action.type) {
|
||||
case ChatingFooterActionTypes.Album:
|
||||
this.$emit("prepareMediaMessage", action.type);
|
||||
break;
|
||||
case ChatingFooterActionTypes.File:
|
||||
this.$emit("prepareMediaMessage", action.type);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.chat_action_bar {
|
||||
position: relative;
|
||||
background: #f0f2f6;
|
||||
padding: 24rpx 36rpx;
|
||||
|
||||
.action_row {
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.action_item {
|
||||
@include centerBox();
|
||||
flex-direction: column;
|
||||
margin-top: 24rpx;
|
||||
|
||||
image {
|
||||
width: 96rpx;
|
||||
height: 96rpx;
|
||||
}
|
||||
|
||||
&_title {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 6rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,107 @@
|
||||
<template>
|
||||
<view
|
||||
class="editor_wrap"
|
||||
>
|
||||
<editor
|
||||
:placeholder="placeholder"
|
||||
id="editor2"
|
||||
@ready="editorReady"
|
||||
@focus="editorFocus"
|
||||
@blur="editorBlur"
|
||||
@input="editorInput"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { html2Text } from "@/util/common";
|
||||
export default {
|
||||
props: {
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
editorCtx: null,
|
||||
lastStr: "",
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
editorReady() {
|
||||
uni
|
||||
.createSelectorQuery()
|
||||
.select("#editor2")
|
||||
.context((res) => {
|
||||
this.$emit("ready", res);
|
||||
this.editorCtx = res.context;
|
||||
})
|
||||
.exec();
|
||||
},
|
||||
editorFocus() {
|
||||
this.$emit("focus");
|
||||
},
|
||||
editorBlur() {
|
||||
this.$emit("blur");
|
||||
},
|
||||
editorInput(e) {
|
||||
let str = e.detail.html;
|
||||
const oldArr = (this.lastStr ?? '').split("");
|
||||
let contentStr = str;
|
||||
oldArr.forEach((str) => {
|
||||
contentStr = contentStr.replace(str, "");
|
||||
});
|
||||
contentStr = html2Text(contentStr);
|
||||
this.$emit("input", e);
|
||||
this.lastStr = e.detail.html;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.editor_wrap {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#editor2 {
|
||||
background-color: #fff;
|
||||
min-height: 30px;
|
||||
max-height: 120px;
|
||||
height: auto;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/deep/.ql-editor {
|
||||
img {
|
||||
vertical-align: sub !important;
|
||||
}
|
||||
|
||||
p {
|
||||
padding: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.canvas_container {
|
||||
position: fixed;
|
||||
bottom: -99px;
|
||||
z-index: -100;
|
||||
|
||||
&_name {
|
||||
max-width: 480rpx;
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#atCanvas {
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.convas_container_name {
|
||||
font-size: 16px !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
353
pages/conversation/chating/components/ChatingFooter/index.vue
Normal file
353
pages/conversation/chating/components/ChatingFooter/index.vue
Normal file
@@ -0,0 +1,353 @@
|
||||
<template>
|
||||
<view>
|
||||
<view>
|
||||
<view class="chat_footer">
|
||||
|
||||
<view class="footer_action_area">
|
||||
|
||||
<view class="input_content">
|
||||
<CustomEditor
|
||||
class="custom_editor"
|
||||
ref="customEditor"
|
||||
@ready="editorReady"
|
||||
@focus="editorFocus"
|
||||
@blur="editorBlur"
|
||||
@input="editorInput"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="footer_action_area">
|
||||
<!-- <image-->
|
||||
<!-- v-show="!hasContent"-->
|
||||
<!-- @click.prevent="updateActionBar"-->
|
||||
<!-- src="@/static/images/chating_footer_add.png"-->
|
||||
<!-- alt=""-->
|
||||
<!-- srcset=""-->
|
||||
<!-- />-->
|
||||
<image
|
||||
v-show="hasContent"
|
||||
@touchend.prevent="sendTextMessage"
|
||||
src="@/static/images/send_btn.png"
|
||||
alt=""
|
||||
srcset=""
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<chating-action-bar
|
||||
@sendMessage="sendMessage"
|
||||
@prepareMediaMessage="prepareMediaMessage"
|
||||
v-show="actionBarVisible"
|
||||
/>
|
||||
<u-action-sheet
|
||||
:safeAreaInsetBottom="true"
|
||||
round="12"
|
||||
:actions="actionSheetMenu"
|
||||
@select="selectClick"
|
||||
:closeOnClickOverlay="true"
|
||||
:closeOnClickAction="true"
|
||||
:show="showActionSheet"
|
||||
@close="showActionSheet = false"
|
||||
>
|
||||
</u-action-sheet>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapGetters, mapActions } from "vuex";
|
||||
import { getPurePath, html2Text } from "@/util/common";
|
||||
import { offlinePushInfo } from "@/util/imCommon";
|
||||
import {
|
||||
ChatingFooterActionTypes,
|
||||
UpdateMessageTypes,
|
||||
} from "@/constant";
|
||||
import IMSDK, {
|
||||
IMMethods,
|
||||
MessageStatus,
|
||||
MessageType,
|
||||
} from "openim-uniapp-polyfill";
|
||||
import UParse from "@/components/gaoyia-parse/parse.vue";
|
||||
import CustomEditor from "./CustomEditor.vue";
|
||||
import ChatingActionBar from "./ChatingActionBar.vue";
|
||||
|
||||
const needClearTypes = [MessageType.TextMessage];
|
||||
|
||||
const albumChoose = [
|
||||
{
|
||||
name: "图片",
|
||||
type: ChatingFooterActionTypes.Album,
|
||||
idx: 0,
|
||||
},
|
||||
{
|
||||
name: "拍照",
|
||||
type: ChatingFooterActionTypes.Camera,
|
||||
idx: 1,
|
||||
},
|
||||
];
|
||||
|
||||
export default {
|
||||
components: {
|
||||
CustomEditor,
|
||||
ChatingActionBar,
|
||||
UParse,
|
||||
},
|
||||
props: {
|
||||
footerOutsideFlag: Number,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
customEditorCtx: null,
|
||||
inputHtml: "",
|
||||
actionBarVisible: false,
|
||||
isInputFocus: false,
|
||||
actionSheetMenu: [],
|
||||
showActionSheet: false,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapGetters([
|
||||
"storeCurrentConversation",
|
||||
"storeCurrentGroup",
|
||||
"storeBlackList",
|
||||
]),
|
||||
hasContent() {
|
||||
return html2Text(this.inputHtml) !== "";
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
footerOutsideFlag(newVal) {
|
||||
this.onClickActionBarOutside();
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.setKeyboardListener();
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.disposeKeyboardListener();
|
||||
},
|
||||
methods: {
|
||||
...mapActions("message", ["pushNewMessage", "updateOneMessage"]),
|
||||
async createTextMessage() {
|
||||
let message = "";
|
||||
const text = html2Text(this.inputHtml);
|
||||
message = await IMSDK.asyncApi(
|
||||
IMMethods.CreateTextMessage,
|
||||
IMSDK.uuid(),
|
||||
text
|
||||
);
|
||||
console.log(message);
|
||||
return message;
|
||||
},
|
||||
async sendTextMessage() {
|
||||
if (!this.hasContent) return;
|
||||
const message = await this.createTextMessage();
|
||||
this.sendMessage(message);
|
||||
},
|
||||
sendMessage(message) {
|
||||
this.pushNewMessage(message);
|
||||
if (needClearTypes.includes(message.contentType)) {
|
||||
this.customEditorCtx.clear();
|
||||
}
|
||||
this.$emit("scrollToBottom");
|
||||
IMSDK.asyncApi(IMMethods.SendMessage, IMSDK.uuid(), {
|
||||
recvID: this.storeCurrentConversation.userID,
|
||||
groupID: this.storeCurrentConversation.groupID,
|
||||
message,
|
||||
offlinePushInfo,
|
||||
})
|
||||
.then(({ data }) => {
|
||||
this.updateOneMessage({
|
||||
message: data,
|
||||
isSuccess: true,
|
||||
});
|
||||
})
|
||||
.catch(({ data, errCode, errMsg }) => {
|
||||
this.updateOneMessage({
|
||||
message: data,
|
||||
type: UpdateMessageTypes.KeyWords,
|
||||
keyWords: [
|
||||
{
|
||||
key: "status",
|
||||
value: MessageStatus.Failed,
|
||||
},
|
||||
{
|
||||
key: "errCode",
|
||||
value: errCode,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// action
|
||||
onClickActionBarOutside() {
|
||||
if (this.actionBarVisible) {
|
||||
this.actionBarVisible = false;
|
||||
}
|
||||
},
|
||||
updateActionBar() {
|
||||
this.actionBarVisible = !this.actionBarVisible;
|
||||
},
|
||||
editorReady(e) {
|
||||
this.customEditorCtx = e.context;
|
||||
this.customEditorCtx.clear();
|
||||
},
|
||||
editorFocus() {
|
||||
this.isInputFocus = true;
|
||||
this.$emit("scrollToBottom");
|
||||
},
|
||||
editorBlur() {
|
||||
this.isInputFocus = false;
|
||||
},
|
||||
editorInput(e) {
|
||||
this.inputHtml = e.detail.html;
|
||||
},
|
||||
prepareMediaMessage(type) {
|
||||
if (type === ChatingFooterActionTypes.Album) {
|
||||
this.actionSheetMenu = [...albumChoose];
|
||||
}
|
||||
this.showActionSheet = true;
|
||||
},
|
||||
|
||||
// from comp
|
||||
batchCreateImageMesage(paths) {
|
||||
paths.forEach(async (path) => {
|
||||
const message = await IMSDK.asyncApi(
|
||||
IMMethods.CreateImageMessageFromFullPath,
|
||||
IMSDK.uuid(),
|
||||
getPurePath(path)
|
||||
);
|
||||
this.sendMessage(message);
|
||||
});
|
||||
},
|
||||
selectClick({ idx }) {
|
||||
if (idx === 0) {
|
||||
this.chooseOrShotImage(["album"]).then((paths) =>
|
||||
this.batchCreateImageMesage(paths)
|
||||
);
|
||||
} else {
|
||||
this.chooseOrShotImage(["camera"]).then((paths) =>
|
||||
this.batchCreateImageMesage(paths)
|
||||
);
|
||||
}
|
||||
},
|
||||
chooseOrShotImage(sourceType) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.chooseImage({
|
||||
count: 9,
|
||||
sizeType: ["compressed"],
|
||||
sourceType,
|
||||
success: function ({ tempFilePaths }) {
|
||||
resolve(tempFilePaths);
|
||||
},
|
||||
fail: function (err) {
|
||||
console.log(err);
|
||||
reject(err);
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// keyboard
|
||||
keyboardChangeHander({ height }) {
|
||||
if (height > 0) {
|
||||
if (this.actionBarVisible) {
|
||||
this.actionBarVisible = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
setKeyboardListener() {
|
||||
uni.onKeyboardHeightChange(this.keyboardChangeHander);
|
||||
},
|
||||
disposeKeyboardListener() {
|
||||
uni.offKeyboardHeightChange(this.keyboardChangeHander);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.custom_editor {
|
||||
img {
|
||||
vertical-align: sub;
|
||||
}
|
||||
}
|
||||
|
||||
.forbidden_footer {
|
||||
width: 100%;
|
||||
height: 112rpx;
|
||||
color: #8e9ab0;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: #f0f2f6;
|
||||
}
|
||||
|
||||
.chat_footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
// background-color: #e9f4ff;
|
||||
background: #f0f2f6;
|
||||
// height: 50px;
|
||||
max-height: 120px;
|
||||
padding: 24rpx 20rpx;
|
||||
|
||||
.input_content {
|
||||
flex: 1;
|
||||
min-height: 30px;
|
||||
max-height: 120px;
|
||||
margin: 0 24rpx;
|
||||
border-radius: 8rpx;
|
||||
position: relative;
|
||||
|
||||
.record_btn {
|
||||
// background-color: #3c9cff;
|
||||
background: #fff;
|
||||
color: black;
|
||||
height: 30px;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.quote_message {
|
||||
@include vCenterBox();
|
||||
justify-content: space-between;
|
||||
margin-top: 12rpx;
|
||||
padding: 8rpx;
|
||||
// padding-top: 20rpx;
|
||||
border-radius: 6rpx;
|
||||
background-color: #fff;
|
||||
color: #666;
|
||||
|
||||
.content {
|
||||
/deep/ uni-view {
|
||||
@include ellipsisWithLine(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.footer_action_area {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.emoji_action {
|
||||
margin-right: 24rpx;
|
||||
}
|
||||
|
||||
image {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
}
|
||||
|
||||
.send_btn {
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
background-color: #4a9cfc;
|
||||
padding: 0 8px;
|
||||
border-radius: 4px;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user