123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735 |
- <template>
- <view class="chat-bottom">
- <view :style="{height: height}"></view>
- <view class="safe-area-inset-bottom"></view>
- <view class="chat-down-box u-flex-col u-col-center">
- <view class="chat-down-btn u-flex u-row-between" v-if="isjianpan">
- <image @click="openchangyong" v-if="showtype == 2" class="img2" src="@/static/imagess/jianpan.png"
- mode=""></image>
- <input class="input" :cursor-spacing="15" v-model="text" type="text" confirm-type="send" @confirm="send"
- placeholder="请输入消息内容…">
- <image @click="openemoji" class="img1" src="@/static/imagess/biaoqing.png" mode=""></image>
- <text @click="send" v-if="text" class="send">发送</text>
- <image @click="openmore" v-else-if="showtype == 1" class="img2" src="@/static/imagess/jianpan.png"
- mode="">
- </image>
- <image @click="openmore" v-else-if="showtype != 1" class="img2" src="@/static/imagess/wenjian.png"
- mode=""></image>
- </view>
- <view class="chat-down-btn luyin u-flex u-row-between" v-else>
- <image @click="isjianpan = true" class="img2" src="@/static/imagess/jianpan.png" mode=""></image>
- <button class="record-btn" :class="longPress == '1' ? 'record-btn-1' : 'record-btn-2'"
- @longpress="longpressBtn()" @touchend="touchendBtn()">
-
- <text>{{longPress == '1' ? '按住说话' : '说话中...'}}</text>
- </button>
- </view>
- <view class="prompt-layer prompt-layer-1" v-if="longPress == '2'">
- <view class="prompt-loader">
- <view class="em" v-for="(item,index) in 15" :key="index"></view>
- </view>
- <text class="span">松手结束录音</text>
- </view>
- <view v-if="showtype == 1" class="more-box u-flex acenter">
-
- <view class="more-item u-flex-col u-col-center" @click="toalbum">
- <view class="item-img u-flex u-row-center">
- <image src="/static/imagess/more2.png" mode=""></image>
- </view>
- <view class="item-text">
- 相册
- </view>
- </view>
- <view class="more-item u-flex-col u-col-center" @click="tocapture">
- <view class="item-img u-flex u-row-center">
- <image src="/static/imagess/more3.png" mode=""></image>
- </view>
- <view class="item-text">
- 拍摄
- </view>
- </view>
- <view class="more-item u-flex-col u-col-center" @click="isjianpan = false;showtype = 0">
- <view class="item-img u-flex u-row-center">
- <image src="/static/imagess/more4.png" mode=""></image>
- </view>
- <view class="item-text">
- 语音
- </view>
- </view>
- </view>
- <view v-if="showtype == 2" class="changyong-box u-flex-col">
- <scroll-view scroll-y="true" class="changyong-scroll u-flex-1">
- <view class="changyong-text" v-for="(a,b) in changlist" :key="b" @click="select(a)">{{a.content}}
- </view>
- </scroll-view>
- <view class="changyong-btn u-flex u-row-between">
- <text class="text1" @click="toadd">新增</text>
- <text class="text2"></text>
- <text class="text1" @click="tolist">管理</text>
- </view>
- </view>
- <scroll-view v-if="showtype == 3" scroll-y="true" class="emoji-scroll">
- <view class="empji-box u-flex u-flex-wrap">
- <text v-for="(a,b) in emoji" :key="b" @click="changeemoji(a)">{{a}}</text>
- </view>
- </scroll-view>
- <view class="safe-area-inset-bottom"></view>
- </view>
- </view>
- </template>
- <script>
- import {
- conn,
- } from '@/utils/WebIM';
- import WebIM from '@/newSDK/Easemob-chat-4.1.7.js'
- import emoji from "@/commont/emoji.js"
- const recorderManager = uni.getRecorderManager()
- var init
- export default {
- props: {
- to: {
- typeof: String,
- default: ''
- },
- list: {
- typeof: Array,
- default: []
- },
- user_other: {
- type: Object,
- default: {}
- },
- user: {
- type: Object,
- default: {}
- }
- },
- data() {
- return {
- height: '100rpx',
- showtype: 0,
- emoji: emoji,
- text: '',
- changlist: [],
- isjianpan: true,
- longPress: '1',
- time: 0,
- duration: 60000,
- tempFilePath: '',
- playStatus: 0,
- }
- },
- created() {
- },
- methods: {
- longpressBtn() {
- console.log('长按说话');
- this.longPress = '2';
-
-
- recorderManager.onStop((res) => {
- console.log('onstop', res);
- this.tempFilePath = res.tempFilePath;
- this.recordingTimer(this.time);
- })
- const options = {
- duration: this.duration,
- sampleRate: 16000,
- numberOfChannels: 1,
- encodeBitRate: 96000,
- format: 'mp3',
- frameSize: 10,
- }
- this.recordingTimer();
- recorderManager.start(options);
-
- recorderManager.onStart((res) => {})
- recorderManager.onError((res) => {})
- },
-
- touchendBtn() {
- console.log('长按松开录音事件');
- let _this = this
- this.longPress = '1';
- recorderManager.onStop((res) => {
- console.log(res);
- _this.tempFilePath = res.tempFilePath
- console.log(_this.tempFilePath);
- uni.uploadFile({
- url: 'https://cbec.hdlkeji.com/api/upload/images',
- filePath: _this.tempFilePath,
- name: 'file',
- success: (res) => {
- console.log('发送语音',res);
- uni.hideLoading()
- if (JSON.parse(res.data).code == 1) {
- _this.sendluyin(JSON.parse(res.data).data.fullurl);
- } else {
- _this.$u.toast(JSON.parse(res.data).msg)
- }
- },
- fail: (e) => {
- console.log(e);
- }
- })
- })
- this.recordingTimer(this.time)
- recorderManager.stop()
- },
- recordingTimer(time) {
- var that = this;
- if (time == undefined) {
-
- init = setInterval(function() {
- that.time++
- }, 1000);
- } else {
- clearInterval(init)
- }
- },
- sendluyin(url) {
- var option = {
- type: "audio",
- chatType: "singleChat",
- filename: url,
-
- to: this.to,
- body: {
-
- url: url,
-
- type: "audio",
-
- filename: url,
-
- length: this.time,
- },
- };
- let msg = new WebIM.message.create(option);
-
- conn.send(msg).then((res) => {
-
- console.log("Success");
- setTimeout(() => {
- this.$emit('success', true)
- }, 800)
- })
- .catch((e) => {
-
- console.log("Fail", e);
- });
- },
- send() {
- let _this = this
- if (this.text == '' || this.text == null) {
- this.$u.toast('发送消息不能为空')
- return
- }
- let id = conn.getUniqueId();
- let msg = new WebIM.message('txt', id);
- console.log(this.user_other);
- msg.set({
- msg: this.text,
- to: this.to,
- chatType: 'singleChat',
- ext: {
- user_other: this.user_other,
- user:this.user
- },
- success: function(id, serverMsgId) {
- console.log('成功发送消息');
- setTimeout(() => {
- _this.$emit('success', true)
- }, 800);
- },
- fail: function(e) {
- console.log("发送消息失败");
- }
- });
- conn.send(msg.body);
- this.text = ''
- },
- toalbum() {
- let _this = this
- uni.chooseImage({
- count: 1,
- sizeType: ["original", "compressed"],
- sourceType: ["album"],
- success(img) {
- uni.showLoading({
- mask: true,
- title: "请稍后"
- })
- console.log('img', img);
- uni.uploadFile({
- url: 'https://hire.hdlkeji.com/api/common/upload',
- filePath: img.tempFilePaths[0],
- name: 'file',
- success: (res) => {
- uni.hideLoading()
- if (JSON.parse(res.data).code == 1) {
- console.log('data', JSON.parse(res.data).data.fullurl);
- _this.sendPrivateImg(JSON.parse(res.data).data.fullurl);
- } else {
- _this.$u.toast(JSON.parse(res.data).msg)
- }
- },
- fail: (e) => {
- console.log(e);
- }
- })
- },
- });
- },
- tocapture() {
- let _this = this
- uni.chooseImage({
- count: 1,
- sizeType: ["original", "compressed"],
- sourceType: ["camera"],
- success(img) {
- uni.showLoading({
- mask: true,
- title: "请稍后"
- })
- uni.uploadFile({
- url: 'https://hire.hdlkeji.com/api/common/upload',
- filePath: img.tempFilePaths[0],
- name: 'file',
- success: (res) => {
- uni.hideLoading()
- if (JSON.parse(res.data).code == 1) {
- _this.sendPrivateImg(JSON.parse(res.data).data.fullurl);
- } else {
- _this.$u.toast(JSON.parse(res.data).msg)
- }
- },
- fail: (e) => {
- console.log(e);
- }
- })
- },
- });
- },
- sendPrivateImg(res) {
- console.log('sendPrivateImg', res);
- let option = {
- chatType: "singleChat",
-
- type: "img",
-
- url: res,
-
- to: this.to,
- ext: {
-
-
- user_other: this.user_other,
- user:this.user
- },
- };
-
- let msg = new WebIM.message.create(option);
-
- conn.send(msg).then((res) => {
- console.log('发送图片成功');
- setTimeout(() => {
- this.$emit('success', true)
- }, 800)
- });
- },
- select(item) {
- this.text = item.content
- },
- tolist() {
- uni.navigateTo({
- url: "/pagesC/changyong-list"
- })
- },
- toadd() {
- uni.navigateTo({
- url: "/pagesC/changyong-add"
- })
- },
- changeemoji(item) {
- this.text = this.text + item
- },
- openemoji() {
- this.showtype = this.showtype == 3 ? 0 : 3
- this.height = this.showtype == 3 ? '400rpx' : '100rpx'
- },
- openmore() {
- this.showtype = this.showtype == 1 ? 0 : 1
- this.height = this.showtype == 1 ? '300rpx' : '100rpx'
- },
- openchangyong() {
- this.showtype = this.showtype == 2 ? 0 : 2
- this.height = this.showtype == 2 ? '600rpx' : '100rpx'
- this.isjianpan = true
- }
- }
- }
- </script>
- <style lang="scss">
- .send {
- font-size: 26rpx;
- color: #fff;
- padding: 16rpx 20rpx;
- background: #0C66C2;
- border-radius: 16rpx;
- }
- .chat-bottom {
- .chat-down-box {
- position: fixed;
- bottom: 0;
- left: 0;
- z-index: 99;
- width: 750rpx;
- background-color: #fff;
- .emoji-scroll {
- height: 300rpx;
- .empji-box {
- width: 750rpx;
- text {
- padding: 10rpx 0;
- text-align: center;
- width: 10%;
- font-size: 40rpx;
- }
- }
- }
- .changyong-box {
- height: 500rpx;
- width: 100%;
- .changyong-scroll {
- min-height: 1rpx;
- padding: 0 32rpx;
- width: 100%;
- box-sizing: border-box;
- border-top: 2rpx solid #F0F0F0;
- .changyong-text {
- border-bottom: 2rpx solid #F0F0F0;
- padding: 32rpx 0;
- font-size: 30rpx;
- font-family: PingFangSC-Regular, PingFang SC;
- font-weight: 400;
- color: #222222;
- }
- .changyong-text:last-child {
- border: none;
- }
- }
- .changyong-btn {
- height: 90rpx;
- width: 100%;
- box-shadow: 0rpx -1rpx 0rpx 0rpx rgba(0, 0, 0, 0.2);
- .text2 {
- height: 44rpx;
- border: 2rpx solid #E5E5E5;
- }
- .text1 {
- line-height: 90rpx;
- width: 45%;
- text-align: center;
- font-size: 32rpx;
- font-family: PingFangSC-Regular, PingFang SC;
- font-weight: 400;
- color: #0C66C2;
- }
- }
- }
- .more-box {
- height: 200rpx;
- padding: 0 60rpx;
- width: 100%;
- box-sizing: border-box;
- .more-item {
- margin: 0 58rpx 0 0;
- .item-text {
- font-size: 22rpx;
- font-family: PingFangSC-Regular, PingFang SC;
- font-weight: 400;
- color: #444444;
- }
- .item-img {
- width: 114rpx;
- height: 114rpx;
- background: #F3F3F3;
- border-radius: 20rpx;
- margin-bottom: 24rpx;
- .hide {
- position: absolute;
- top: 0;
- right: 0;
- min-width: 100%;
- min-height: 100%;
- filter: alpha(opacity=0);
- opacity: 0;
- cursor: inherit;
- display: none;
- }
- image {
- width: 52rpx;
- height: 52rpx;
- }
- }
- }
- }
- .chat-down-btn {
- margin: 12rpx auto;
- width: 686rpx;
- height: 84rpx;
- background: #F3F3F3;
- border-radius: 42rpx;
- padding: 0 28rpx;
- .input {
- flex: 1;
- margin-left: 28rpx;
- font-size: 28rpx;
- }
- .img1 {
- width: 44rpx;
- height: 44rpx;
- margin: 0 28rpx;
- }
- .img2 {
- width: 44rpx;
- height: 44rpx;
- }
- .changyong {
- width: 44rpx;
- height: 44rpx;
- line-height: 44rpx;
- border: 3rpx solid #131415;
- text-align: center;
- border-radius: 100rpx;
- font-size: 26rpx;
- font-family: PingFangSC-Medium, PingFang SC;
- font-weight: 500;
- color: #131415;
- }
- }
- }
- .record-box {
- width: 100%;
- position: relative;
- }
- .luyin button::after {
- border: none;
- }
- .luyin button {
- font-size: 14px;
- line-height: 38px;
- width: 100%;
- height: 38px;
- border-radius: 8px;
- text-align: center;
- background: #f3f3f3;
- }
- .luyin button image {
- width: 16px;
- height: 16px;
- margin-right: 4px;
- vertical-align: middle;
- }
- .record-btn-2 {
- background: rgba(255, 211, 0, 0.2);
- }
- /* 提示小弹窗 */
- .prompt-layer {
- border-radius: 8px;
- background: #fff;
- padding: 8px 16px;
- box-sizing: border-box;
- position: absolute;
- left: 50%;
- transform: translateX(-50%);
- }
- .prompt-layer::after {
- content: '';
- display: block;
- border: 6px solid rgba(0, 0, 0, 0);
- border-top-color: rgba(255, 211, 0, 1);
- position: absolute;
- bottom: -10px;
- left: 50%;
- transform: translateX(-50%);
- }
- .prompt-layer-1 {
- font-size: 12px;
- width: 128px;
- text-align: center;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- top: -80px;
- }
- .prompt-layer-1 .p {
- color: #000000;
- }
- .prompt-layer-1 .span {
- color: rgba(0, 0, 0, .6);
- }
- .prompt-loader .em {}
- /* 语音音阶------------- */
- .prompt-loader {
- width: 96px;
- height: 20px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 6px;
- }
- .prompt-loader .em {
- display: block;
- background: #333333;
- width: 1px;
- height: 10%;
- margin-right: 2.5px;
- float: left;
- }
- .prompt-loader .em:last-child {
- margin-right: 0px;
- }
- .prompt-loader .em:nth-child(1) {
- animation: load 2.5s 1.4s infinite linear;
- }
- .prompt-loader .em:nth-child(2) {
- animation: load 2.5s 1.2s infinite linear;
- }
- .prompt-loader .em:nth-child(3) {
- animation: load 2.5s 1s infinite linear;
- }
- .prompt-loader .em:nth-child(4) {
- animation: load 2.5s 0.8s infinite linear;
- }
- .prompt-loader .em:nth-child(5) {
- animation: load 2.5s 0.6s infinite linear;
- }
- .prompt-loader .em:nth-child(6) {
- animation: load 2.5s 0.4s infinite linear;
- }
- .prompt-loader .em:nth-child(7) {
- animation: load 2.5s 0.2s infinite linear;
- }
- .prompt-loader .em:nth-child(8) {
- animation: load 2.5s 0s infinite linear;
- }
- .prompt-loader .em:nth-child(9) {
- animation: load 2.5s 0.2s infinite linear;
- }
- .prompt-loader .em:nth-child(10) {
- animation: load 2.5s 0.4s infinite linear;
- }
- .prompt-loader .em:nth-child(11) {
- animation: load 2.5s 0.6s infinite linear;
- }
- .prompt-loader .em:nth-child(12) {
- animation: load 2.5s 0.8s infinite linear;
- }
- .prompt-loader .em:nth-child(13) {
- animation: load 2.5s 1s infinite linear;
- }
- .prompt-loader .em:nth-child(14) {
- animation: load 2.5s 1.2s infinite linear;
- }
- .prompt-loader .em:nth-child(15) {
- animation: load 2.5s 1.4s infinite linear;
- }
- @keyframes load {
- 0% {
- height: 10%;
- }
- 50% {
- height: 100%;
- }
- 100% {
- height: 10%;
- }
- }
- /* 语音音阶-------------------- */
- .prompt-layer-2 {
- top: -40px;
- }
- .prompt-layer-2 .text {
- color: rgba(0, 0, 0, 1);
- font-size: 12px;
- }
- }
- </style>
|