优化聊天界面头像昵称
This commit is contained in:
@@ -4,9 +4,7 @@
|
|||||||
<text style="max-width: 600rpx" class="u-line-1 u-font-32">
|
<text style="max-width: 600rpx" class="u-line-1 u-font-32">
|
||||||
{{ groupInfo.name }}
|
{{ groupInfo.name }}
|
||||||
</text>
|
</text>
|
||||||
<text class="u-m-l-22"
|
<text class="u-m-l-22">({{ membersRes?.user_list?.length || 0 }}人)</text>
|
||||||
>({{ membersRes?.user_list?.length || 0 }}人)</text
|
|
||||||
>
|
|
||||||
<!-- <view class="" @click="toMore()">
|
<!-- <view class="" @click="toMore()">
|
||||||
<view class="u-flex u-row-center">
|
<view class="u-flex u-row-center">
|
||||||
<up-icon name="more-dot-fill" color="#333" size="14"></up-icon>
|
<up-icon name="more-dot-fill" color="#333" size="14"></up-icon>
|
||||||
@@ -29,58 +27,34 @@
|
|||||||
>
|
>
|
||||||
<view class="scroll-view-box">
|
<view class="scroll-view-box">
|
||||||
<view class="talk-list">
|
<view class="talk-list">
|
||||||
<view
|
<view :id="'msg-' + index" v-for="(item, index) in chatStore.chatList" :key="index">
|
||||||
:id="'msg-' + index"
|
|
||||||
v-for="(item, index) in chatStore.chatList"
|
|
||||||
:key="index"
|
|
||||||
>
|
|
||||||
<!-- 发消息 -->
|
<!-- 发消息 -->
|
||||||
<template
|
<template v-if="item.operate_type == 'sendMsg' || item.is_user_send == 1">
|
||||||
v-if="item.operate_type == 'sendMsg' || item.is_user_send == 1"
|
|
||||||
>
|
|
||||||
<view class="user u-flex u-row-right">
|
<view class="user u-flex u-row-right">
|
||||||
<view class="u-p-r-18">
|
<view class="u-p-r-18">
|
||||||
<view class="color-000 u-line-1 text-right">{{
|
<view class="name u-line-1 text-right">{{ item.nick_name }}</view>
|
||||||
item.nick_name
|
<view class="u-m-t-14 msg u-p-l-30" :class="['type' + item.msg_type]">
|
||||||
}}</view>
|
|
||||||
<view
|
|
||||||
class="u-m-t-14 msg u-p-l-30"
|
|
||||||
:class="['type' + item.msg_type]"
|
|
||||||
>
|
|
||||||
<chatItem :item="item" @previewImage="previewImage"></chatItem>
|
<chatItem :item="item" @previewImage="previewImage"></chatItem>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<up-avatar
|
<up-avatar size="70rpx" :src="item.avatar" shape="square" bg-color="#fff"></up-avatar>
|
||||||
size="122rpx"
|
|
||||||
:src="item.avatar"
|
|
||||||
shape="square"
|
|
||||||
bg-color="#fff"
|
|
||||||
></up-avatar>
|
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
<!-- 商家消息 -->
|
<!-- 商家消息 -->
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<view class="shop u-flex">
|
<view class="shop u-flex">
|
||||||
<up-avatar
|
<up-avatar :src="item.avatar" size="70rpx" shape="square" bg-color="#fff"></up-avatar>
|
||||||
:src="item.avatar"
|
|
||||||
size="122rpx"
|
|
||||||
shape="square"
|
|
||||||
bg-color="#fff"
|
|
||||||
></up-avatar>
|
|
||||||
<view class="u-p-l-18">
|
<view class="u-p-l-18">
|
||||||
<view class="u-flex">
|
<view class="u-flex">
|
||||||
<template v-if="item.is_shop == 1">
|
<template v-if="item.is_shop == 1">
|
||||||
<view class="tag">商家</view>
|
<view class="tag">商家</view>
|
||||||
<view class="color-000">{{ item.nick_name }}</view>
|
<view class="name">{{ item.nick_name }}</view>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<view class="color-000">{{ item.nick }}</view>
|
<view class="color-000">{{ item.nick }}</view>
|
||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view class="u-m-t-14 msg" :class="['type' + item.msg_type]">
|
||||||
class="u-m-t-14 msg"
|
|
||||||
:class="['type' + item.msg_type]"
|
|
||||||
>
|
|
||||||
<chatItem :item="item" @getCoupon="getCoupon" @previewImage="previewImage"></chatItem>
|
<chatItem :item="item" @getCoupon="getCoupon" @previewImage="previewImage"></chatItem>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -88,10 +62,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<up-loadmore
|
<up-loadmore v-if="isEnd" :status="isEnd ? 'nomore' : 'loading'"></up-loadmore>
|
||||||
v-if="isEnd"
|
|
||||||
:status="isEnd ? 'nomore' : 'loading'"
|
|
||||||
></up-loadmore>
|
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
</view>
|
</view>
|
||||||
@@ -99,11 +70,7 @@
|
|||||||
<!-- <view :style="bottomSlotHeight"></view> -->
|
<!-- <view :style="bottomSlotHeight"></view> -->
|
||||||
|
|
||||||
<view class="bottom" :class="[showMoreBtn ? '' : 'safe-bottom']">
|
<view class="bottom" :class="[showMoreBtn ? '' : 'safe-bottom']">
|
||||||
<view
|
<view class="u-flex" style="padding: 14rpx 28rpx" v-if="groupInfo && !groupInfo.is_mute">
|
||||||
class="u-flex"
|
|
||||||
style="padding: 14rpx 28rpx"
|
|
||||||
v-if="groupInfo && !groupInfo.is_mute"
|
|
||||||
>
|
|
||||||
<!-- <input
|
<!-- <input
|
||||||
type="text"
|
type="text"
|
||||||
class="u-flex-1 u-m-r-52 iput"
|
class="u-flex-1 u-m-r-52 iput"
|
||||||
@@ -111,32 +78,16 @@
|
|||||||
v-model="msg"
|
v-model="msg"
|
||||||
/> -->
|
/> -->
|
||||||
<view class="u-flex-1 u-m-r-52 iput">
|
<view class="u-flex-1 u-m-r-52 iput">
|
||||||
<up-input
|
<up-input v-model="msg" border="none" placeholder="请输入内容"></up-input>
|
||||||
v-model="msg"
|
|
||||||
border="none"
|
|
||||||
placeholder="请输入内容"
|
|
||||||
></up-input>
|
|
||||||
</view>
|
</view>
|
||||||
<button class="send-btn" v-if="msg.trim().length > 0" @click="sendText">
|
<button class="send-btn" v-if="msg.trim().length > 0" @click="sendText">
|
||||||
<text>发送</text>
|
<text>发送</text>
|
||||||
</button>
|
</button>
|
||||||
<up-icon
|
<up-icon name="plus-circle" color="#666" size="60rpx" @click="showMoreBtnToggle" v-else></up-icon>
|
||||||
name="plus-circle"
|
|
||||||
color="#666"
|
|
||||||
size="60rpx"
|
|
||||||
@click="showMoreBtnToggle"
|
|
||||||
v-else
|
|
||||||
></up-icon>
|
|
||||||
</view>
|
</view>
|
||||||
<view class="color-666 u-font-28 text-center u-m-t-28" v-else
|
<view class="color-666 u-font-28 text-center u-m-t-28" v-else>商家已禁言</view>
|
||||||
>商家已禁言</view
|
|
||||||
>
|
|
||||||
<view class="more-btn" v-if="showMoreBtn">
|
<view class="more-btn" v-if="showMoreBtn">
|
||||||
<view
|
<view v-for="(item, index) in moreBtns" @click="moreBtnsClick(item, index)" class="u-flex-col u-row-center u-col-center">
|
||||||
v-for="(item, index) in moreBtns"
|
|
||||||
@click="moreBtnsClick(item, index)"
|
|
||||||
class="u-flex-col u-row-center u-col-center"
|
|
||||||
>
|
|
||||||
<view class="u-flex icon">
|
<view class="u-flex icon">
|
||||||
<image :src="item.icon" class="img" mode="aspectFill"></image>
|
<image :src="item.icon" class="img" mode="aspectFill"></image>
|
||||||
</view>
|
</view>
|
||||||
@@ -147,68 +98,36 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 退出群聊 -->
|
<!-- 退出群聊 -->
|
||||||
<u-popup
|
<u-popup :show="popupShow" :safe-area-inset-bottom="false" mode="center" @close="popupShow = false">
|
||||||
:show="popupShow"
|
|
||||||
:safe-area-inset-bottom="false"
|
|
||||||
mode="center"
|
|
||||||
@close="popupShow = false"
|
|
||||||
>
|
|
||||||
<view class="popup-content">
|
<view class="popup-content">
|
||||||
<view class="header-wrap">
|
<view class="header-wrap">
|
||||||
<text class="t">退出群{{ "{" + groupInfo.name + "}" }}</text>
|
<text class="t">退出群{{ '{' + groupInfo.name + '}' }}</text>
|
||||||
<view class="close" @click="popupShow = false">
|
<view class="close" @click="popupShow = false">
|
||||||
<u-icon name="close" size="20" color="#666"></u-icon>
|
<u-icon name="close" size="20" color="#666"></u-icon>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="u-p-40 text-center u-font-28 color-333 border-bottom"
|
<view class="u-p-40 text-center u-font-28 color-333 border-bottom">是否确认退出,退出后将会错失更多活动和优惠</view>
|
||||||
>是否确认退出,退出后将会错失更多活动和优惠</view
|
|
||||||
>
|
|
||||||
<view class="btn-content">
|
<view class="btn-content">
|
||||||
<view class="btn">
|
<view class="btn">
|
||||||
<u-button
|
<u-button color="#E8AD7B" plain="" shape="circle" @click="popupShow = false">取消</u-button>
|
||||||
color="#E8AD7B"
|
|
||||||
plain=""
|
|
||||||
shape="circle"
|
|
||||||
@click="popupShow = false"
|
|
||||||
>取消</u-button
|
|
||||||
>
|
|
||||||
</view>
|
</view>
|
||||||
<view class="btn">
|
<view class="btn">
|
||||||
<u-button color="#E8AD7B" shape="circle" @click="exitGroup"
|
<u-button color="#E8AD7B" shape="circle" @click="exitGroup">退出</u-button>
|
||||||
>退出</u-button
|
|
||||||
>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</u-popup>
|
</u-popup>
|
||||||
|
|
||||||
|
|
||||||
<!-- 预览图 -->
|
<!-- 预览图 -->
|
||||||
<xbSwiperPreview :visable="showPrveImg" :imgs="prveImgsList" @update:visable="showPrveImg = $event"></xbSwiperPreview>
|
<xbSwiperPreview :visable="showPrveImg" :imgs="prveImgsList" @update:visable="showPrveImg = $event"></xbSwiperPreview>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import {
|
import { onReady, onShow, onReachBottom, onLoad, onPageScroll } from '@dcloudio/uni-app';
|
||||||
onReady,
|
import { ref, inject, onMounted, nextTick, reactive, watch, onUnmounted, computed } from 'vue';
|
||||||
onShow,
|
import { useChatStore } from '@/stores/chat';
|
||||||
onReachBottom,
|
import * as chatApi from '@/http/php/chat';
|
||||||
onLoad,
|
import { uploadFile } from '@/common/api/upload.js';
|
||||||
onPageScroll,
|
import * as javaChatApi from '@/common/api/market/chat';
|
||||||
} from "@dcloudio/uni-app";
|
|
||||||
import {
|
|
||||||
ref,
|
|
||||||
inject,
|
|
||||||
onMounted,
|
|
||||||
nextTick,
|
|
||||||
reactive,
|
|
||||||
watch,
|
|
||||||
onUnmounted,
|
|
||||||
computed,
|
|
||||||
} from "vue";
|
|
||||||
import { useChatStore } from "@/stores/chat";
|
|
||||||
import * as chatApi from "@/http/php/chat";
|
|
||||||
import { uploadFile } from "@/common/api/upload.js";
|
|
||||||
import * as javaChatApi from "@/common/api/market/chat";
|
|
||||||
import xbSwiperPreview from '@/components/xb-swiper-preview/index.vue';
|
import xbSwiperPreview from '@/components/xb-swiper-preview/index.vue';
|
||||||
|
|
||||||
const showPrveImg = ref(false);
|
const showPrveImg = ref(false);
|
||||||
@@ -218,15 +137,15 @@ const prveImgsList = ref([]);
|
|||||||
function exitGroup() {
|
function exitGroup() {
|
||||||
chatApi
|
chatApi
|
||||||
.groupQuit({
|
.groupQuit({
|
||||||
group_id: groupInfo.value.id,
|
group_id: groupInfo.value.id
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
popupShow.value = false;
|
popupShow.value = false;
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "退出成功",
|
title: '退出成功',
|
||||||
icon: "none",
|
icon: 'none',
|
||||||
duration: 1500,
|
duration: 1500
|
||||||
});
|
});
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.navigateBack();
|
uni.navigateBack();
|
||||||
@@ -241,14 +160,14 @@ function getCoupon(item) {
|
|||||||
id: item.coupon.activity_id,
|
id: item.coupon.activity_id,
|
||||||
// shopUserId: shopUserInfo.id,
|
// shopUserId: shopUserInfo.id,
|
||||||
shopId: groupInfo.value.shop_id,
|
shopId: groupInfo.value.shop_id,
|
||||||
userId: uni.cache.get("userInfo").id,
|
userId: uni.cache.get('userInfo').id
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "领取成功",
|
title: '领取成功',
|
||||||
icon: "none",
|
icon: 'none',
|
||||||
duration: 2000,
|
duration: 2000
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -259,23 +178,23 @@ function refresh() {
|
|||||||
getMsgList();
|
getMsgList();
|
||||||
}
|
}
|
||||||
const go = {
|
const go = {
|
||||||
to(item) {},
|
to(item) {}
|
||||||
};
|
};
|
||||||
const popupShow = ref(false);
|
const popupShow = ref(false);
|
||||||
import Modal from "./components/modal.vue";
|
import Modal from './components/modal.vue';
|
||||||
import chatItem from "./components/chat-item.vue";
|
import chatItem from './components/chat-item.vue';
|
||||||
const placeholderStyle = {
|
const placeholderStyle = {
|
||||||
color: "#999",
|
color: '#999',
|
||||||
fontSize: "28rpx",
|
fontSize: '28rpx'
|
||||||
};
|
};
|
||||||
|
|
||||||
function refresherrefresh() {
|
function refresherrefresh() {
|
||||||
console.log("refresherrefresh");
|
console.log('refresherrefresh');
|
||||||
// 关键:同时判断「正在加载」和「无更多数据」,只要一个为真就关闭刷新
|
// 关键:同时判断「正在加载」和「无更多数据」,只要一个为真就关闭刷新
|
||||||
if (isLoading.value || isEnd.value) {
|
if (isLoading.value || isEnd.value) {
|
||||||
scrollView.refresherTriggered = false; // 立即关闭刷新状态
|
scrollView.refresherTriggered = false; // 立即关闭刷新状态
|
||||||
if (isEnd.value) {
|
if (isEnd.value) {
|
||||||
uni.showToast({ title: "没有更多了", icon: "none" });
|
uni.showToast({ title: '没有更多了', icon: 'none' });
|
||||||
}
|
}
|
||||||
return; // 终止后续逻辑
|
return; // 终止后续逻辑
|
||||||
}
|
}
|
||||||
@@ -286,8 +205,8 @@ function refresherrefresh() {
|
|||||||
|
|
||||||
const scrollView = reactive({
|
const scrollView = reactive({
|
||||||
refresherTriggered: false,
|
refresherTriggered: false,
|
||||||
intoView: "",
|
intoView: '',
|
||||||
safeAreaHeight: 0,
|
safeAreaHeight: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
const showMoreBtn = ref(false);
|
const showMoreBtn = ref(false);
|
||||||
@@ -299,47 +218,47 @@ function showMoreBtnToggle() {
|
|||||||
const modalData = reactive({
|
const modalData = reactive({
|
||||||
show: false,
|
show: false,
|
||||||
form: {
|
form: {
|
||||||
title: "",
|
title: '',
|
||||||
getLimit: 1,
|
getLimit: 1,
|
||||||
giveNum: 1,
|
giveNum: 1,
|
||||||
couponId: "",
|
couponId: ''
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const chatStore = useChatStore();
|
const chatStore = useChatStore();
|
||||||
|
|
||||||
const msg = ref("");
|
const msg = ref('');
|
||||||
|
|
||||||
const shopInfo = uni.cache.get("shopInfo");
|
const shopInfo = uni.cache.get('shopInfo');
|
||||||
const shopUserInfo = uni.cache.get("shopUserInfo");
|
const shopUserInfo = uni.cache.get('shopUserInfo');
|
||||||
|
|
||||||
const moreBtns = ref([
|
const moreBtns = ref([
|
||||||
{
|
{
|
||||||
icon: "/pageChat/static/pic.png",
|
icon: '/pageChat/static/pic.png',
|
||||||
title: "发送照片",
|
title: '发送照片',
|
||||||
value: "pic",
|
value: 'pic'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "/pageChat/static/video.png",
|
icon: '/pageChat/static/video.png',
|
||||||
title: "发送视频",
|
title: '发送视频',
|
||||||
value: "video",
|
value: 'video'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "/pageChat/static/exit.png",
|
icon: '/pageChat/static/exit.png',
|
||||||
title: "退出群聊",
|
title: '退出群聊',
|
||||||
value: "exit",
|
value: 'exit'
|
||||||
},
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function moreBtnsClick(item, index) {
|
function moreBtnsClick(item, index) {
|
||||||
if (item.value == "exit") {
|
if (item.value == 'exit') {
|
||||||
popupShow.value = true;
|
popupShow.value = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (item.value == "pic") {
|
if (item.value == 'pic') {
|
||||||
sendImg();
|
sendImg();
|
||||||
}
|
}
|
||||||
if (item.value == "video") {
|
if (item.value == 'video') {
|
||||||
sendVideo();
|
sendVideo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,36 +271,36 @@ async function checkCameraAuth() {
|
|||||||
success: (settingRes) => {
|
success: (settingRes) => {
|
||||||
const authSetting = settingRes.authSetting || {};
|
const authSetting = settingRes.authSetting || {};
|
||||||
|
|
||||||
if (authSetting["scope.camera"]) {
|
if (authSetting['scope.camera']) {
|
||||||
// 2. 已授权:直接返回成功
|
// 2. 已授权:直接返回成功
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} else if (authSetting["scope.camera"] === undefined) {
|
} else if (authSetting['scope.camera'] === undefined) {
|
||||||
// 3. 未请求过授权:发起授权请求
|
// 3. 未请求过授权:发起授权请求
|
||||||
uni.authorize({
|
uni.authorize({
|
||||||
scope: "scope.camera",
|
scope: 'scope.camera',
|
||||||
success: () => {
|
success: () => {
|
||||||
// 授权成功
|
// 授权成功
|
||||||
resolve(true);
|
resolve(true);
|
||||||
},
|
},
|
||||||
fail: (authErr) => {
|
fail: (authErr) => {
|
||||||
// 授权失败(用户拒绝)
|
// 授权失败(用户拒绝)
|
||||||
console.error("相机授权失败:", authErr);
|
console.error('相机授权失败:', authErr);
|
||||||
reject(false);
|
reject(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 4. 已拒绝授权:提示用户去设置页开启
|
// 4. 已拒绝授权:提示用户去设置页开启
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: "开启相机权限",
|
title: '开启相机权限',
|
||||||
content: "请允许“零点八零”使用您的相机,方便您拍摄图片/视频",
|
content: '请允许“零点八零”使用您的相机,方便您拍摄图片/视频',
|
||||||
confirmText: "去设置",
|
confirmText: '去设置',
|
||||||
cancelText: "取消",
|
cancelText: '取消',
|
||||||
success: (modalRes) => {
|
success: (modalRes) => {
|
||||||
if (modalRes.confirm) {
|
if (modalRes.confirm) {
|
||||||
// 跳转微信小程序授权设置页
|
// 跳转微信小程序授权设置页
|
||||||
uni.openSetting({
|
uni.openSetting({
|
||||||
success: (openRes) => {
|
success: (openRes) => {
|
||||||
if (openRes.authSetting["scope.camera"]) {
|
if (openRes.authSetting['scope.camera']) {
|
||||||
// 用户在设置页开启授权
|
// 用户在设置页开启授权
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
@@ -390,7 +309,7 @@ async function checkCameraAuth() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (openErr) => {
|
fail: (openErr) => {
|
||||||
console.error("打开设置页失败:", openErr);
|
console.error('打开设置页失败:', openErr);
|
||||||
reject(false);
|
reject(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -400,19 +319,19 @@ async function checkCameraAuth() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (modalErr) => {
|
fail: (modalErr) => {
|
||||||
console.error("弹窗失败:", modalErr);
|
console.error('弹窗失败:', modalErr);
|
||||||
reject(false);
|
reject(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (settingErr) => {
|
fail: (settingErr) => {
|
||||||
console.error("获取权限设置失败:", settingErr);
|
console.error('获取权限设置失败:', settingErr);
|
||||||
reject(false);
|
reject(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("相机权限校验异常:", err);
|
console.error('相机权限校验异常:', err);
|
||||||
reject(false);
|
reject(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -432,14 +351,14 @@ async function sendImg() {
|
|||||||
const res = await new Promise((resolve, reject) => {
|
const res = await new Promise((resolve, reject) => {
|
||||||
uni.chooseImage({
|
uni.chooseImage({
|
||||||
count: 3,
|
count: 3,
|
||||||
sizeType: ["original", "compressed"],
|
sizeType: ['original', 'compressed'],
|
||||||
sourceType: ["album", "camera"],
|
sourceType: ['album', 'camera'],
|
||||||
success: resolve,
|
success: resolve,
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
// 捕获选择失败(如用户取消选择)
|
// 捕获选择失败(如用户取消选择)
|
||||||
if (err.errMsg && err.errMsg.includes("cancel")) {
|
if (err.errMsg && err.errMsg.includes('cancel')) {
|
||||||
// 用户主动取消,静默处理
|
// 用户主动取消,静默处理
|
||||||
reject(new Error("user cancel"));
|
reject(new Error('user cancel'));
|
||||||
} else {
|
} else {
|
||||||
// 其他错误(如系统异常)
|
// 其他错误(如系统异常)
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -448,8 +367,8 @@ async function sendImg() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
uni.showLoading({ title: "发送中" });
|
uni.showLoading({ title: '发送中' });
|
||||||
console.log("选择图片成功", res);
|
console.log('选择图片成功', res);
|
||||||
|
|
||||||
// 3. 批量上传图片
|
// 3. 批量上传图片
|
||||||
for (let i = 0; i < res.tempFiles.length; i++) {
|
for (let i = 0; i < res.tempFiles.length; i++) {
|
||||||
@@ -457,17 +376,17 @@ async function sendImg() {
|
|||||||
if (fileRes) {
|
if (fileRes) {
|
||||||
sendMsg({
|
sendMsg({
|
||||||
image_url: fileRes,
|
image_url: fileRes,
|
||||||
msg_type: 2,
|
msg_type: 2
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("图片选择/发送失败", err);
|
console.error('图片选择/发送失败', err);
|
||||||
// 仅处理非用户取消的错误
|
// 仅处理非用户取消的错误
|
||||||
if (err.message !== "user cancel") {
|
if (err.message !== 'user cancel') {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "图片发送失败",
|
title: '图片发送失败',
|
||||||
icon: "none",
|
icon: 'none',
|
||||||
duration: 2000
|
duration: 2000
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -490,14 +409,14 @@ async function sendVideo() {
|
|||||||
const res = await new Promise((resolve, reject) => {
|
const res = await new Promise((resolve, reject) => {
|
||||||
uni.chooseVideo({
|
uni.chooseVideo({
|
||||||
count: 1,
|
count: 1,
|
||||||
sizeType: ["original", "compressed"],
|
sizeType: ['original', 'compressed'],
|
||||||
sourceType: ["album", "camera"],
|
sourceType: ['album', 'camera'],
|
||||||
success: resolve,
|
success: resolve,
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
// 捕获选择失败(如用户取消选择)
|
// 捕获选择失败(如用户取消选择)
|
||||||
if (err.errMsg && err.errMsg.includes("cancel")) {
|
if (err.errMsg && err.errMsg.includes('cancel')) {
|
||||||
// 用户主动取消,静默处理
|
// 用户主动取消,静默处理
|
||||||
reject(new Error("user cancel"));
|
reject(new Error('user cancel'));
|
||||||
} else {
|
} else {
|
||||||
// 其他错误(如系统异常)
|
// 其他错误(如系统异常)
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -506,30 +425,30 @@ async function sendVideo() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
uni.showLoading({ title: "发送中" });
|
uni.showLoading({ title: '发送中' });
|
||||||
console.log("选择视频成功", res);
|
console.log('选择视频成功', res);
|
||||||
|
|
||||||
// 3. 上传视频
|
// 3. 上传视频
|
||||||
const fileRes = await uploadFile({ path: res.tempFilePath });
|
const fileRes = await uploadFile({ path: res.tempFilePath });
|
||||||
if (fileRes) {
|
if (fileRes) {
|
||||||
sendMsg({
|
sendMsg({
|
||||||
image_url: fileRes,
|
image_url: fileRes,
|
||||||
msg_type: 5,
|
msg_type: 5
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "视频发送失败",
|
title: '视频发送失败',
|
||||||
icon: "none",
|
icon: 'none',
|
||||||
duration: 2000
|
duration: 2000
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("视频选择/发送失败", err);
|
console.error('视频选择/发送失败', err);
|
||||||
// 仅处理非用户取消的错误
|
// 仅处理非用户取消的错误
|
||||||
if (err.message !== "user cancel") {
|
if (err.message !== 'user cancel') {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "视频发送失败",
|
title: '视频发送失败',
|
||||||
icon: "none",
|
icon: 'none',
|
||||||
duration: 2000
|
duration: 2000
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -542,7 +461,7 @@ const groupInfo = ref({});
|
|||||||
|
|
||||||
const handleReceiveMsg = (msg) => {
|
const handleReceiveMsg = (msg) => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
scrollView.intoView = "msg-0";
|
scrollView.intoView = 'msg-0';
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -550,7 +469,7 @@ const handleReceiveMsg = (msg) => {
|
|||||||
chatStore.registerReceiveMsgCallback(handleReceiveMsg);
|
chatStore.registerReceiveMsgCallback(handleReceiveMsg);
|
||||||
async function init() {
|
async function init() {
|
||||||
const res = await chatApi.groupInfo({
|
const res = await chatApi.groupInfo({
|
||||||
group_id: options.group_id,
|
group_id: options.group_id
|
||||||
});
|
});
|
||||||
console.log(res);
|
console.log(res);
|
||||||
groupInfo.value = res || {};
|
groupInfo.value = res || {};
|
||||||
@@ -563,7 +482,7 @@ async function init() {
|
|||||||
}
|
}
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
page: 1,
|
page: 1,
|
||||||
size: 10,
|
size: 10
|
||||||
});
|
});
|
||||||
async function getMsgList() {
|
async function getMsgList() {
|
||||||
// 提前拦截:已无更多数据,直接关闭状态
|
// 提前拦截:已无更多数据,直接关闭状态
|
||||||
@@ -577,11 +496,11 @@ async function getMsgList() {
|
|||||||
try {
|
try {
|
||||||
const msgRes = await chatApi.messageHistory({
|
const msgRes = await chatApi.messageHistory({
|
||||||
...query,
|
...query,
|
||||||
chat_type: "2",
|
chat_type: '2',
|
||||||
session_id: options.session_id,
|
session_id: options.session_id,
|
||||||
to_id: options.group_id,
|
to_id: options.group_id,
|
||||||
shop_id: options.group_id,
|
shop_id: options.group_id,
|
||||||
group_id: options.group_id,
|
group_id: options.group_id
|
||||||
});
|
});
|
||||||
const data = msgRes.list || [];
|
const data = msgRes.list || [];
|
||||||
const selector = `msg-${query.page == 1 ? 0 : chatStore.chatList.length}`;
|
const selector = `msg-${query.page == 1 ? 0 : chatStore.chatList.length}`;
|
||||||
@@ -598,11 +517,11 @@ async function getMsgList() {
|
|||||||
console.log(selector);
|
console.log(selector);
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("加载历史消息异常", err);
|
console.error('加载历史消息异常', err);
|
||||||
// 加载失败回退页码,避免页码错乱
|
// 加载失败回退页码,避免页码错乱
|
||||||
if (query.page > 1) query.page--;
|
if (query.page > 1) query.page--;
|
||||||
} finally {
|
} finally {
|
||||||
console.log("scrollView", scrollView);
|
console.log('scrollView', scrollView);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
scrollView.refresherTriggered = false;
|
scrollView.refresherTriggered = false;
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
@@ -617,7 +536,7 @@ onLoad((opt) => {
|
|||||||
Object.assign(options, opt);
|
Object.assign(options, opt);
|
||||||
init();
|
init();
|
||||||
chatApi.messageMarkReadAll({
|
chatApi.messageMarkReadAll({
|
||||||
session_ids: options.group_id,
|
session_ids: options.group_id
|
||||||
});
|
});
|
||||||
chatStore.group_id = options.group_id;
|
chatStore.group_id = options.group_id;
|
||||||
chatApi.groupMembers({ group_id: options.group_id }).then((res) => {
|
chatApi.groupMembers({ group_id: options.group_id }).then((res) => {
|
||||||
@@ -630,15 +549,15 @@ onLoad((opt) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function toMore() {
|
function toMore() {
|
||||||
go.to("PAGES_CHAT_GROUP_INFO", {
|
go.to('PAGES_CHAT_GROUP_INFO', {
|
||||||
group_id: groupInfo.value.id,
|
group_id: groupInfo.value.id,
|
||||||
session_id: options.session_id,
|
session_id: options.session_id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function sendText() {
|
function sendText() {
|
||||||
if (!msg.value.trim().length) return;
|
if (!msg.value.trim().length) return;
|
||||||
sendMsg({ content: msg.value, msg_type: 1 });
|
sendMsg({ content: msg.value, msg_type: 1 });
|
||||||
msg.value = "";
|
msg.value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMsg(msg) {
|
function sendMsg(msg) {
|
||||||
@@ -647,54 +566,53 @@ function sendMsg(msg) {
|
|||||||
to_user_type: groupInfo.value.id,
|
to_user_type: groupInfo.value.id,
|
||||||
chat_type: 2,
|
chat_type: 2,
|
||||||
content: msg.value,
|
content: msg.value,
|
||||||
image_url: "",
|
image_url: '',
|
||||||
order_id: "",
|
order_id: '',
|
||||||
session_id: groupInfo.value.session_id || options.session_id,
|
session_id: groupInfo.value.session_id || options.session_id,
|
||||||
...msg,
|
...msg
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
modalData.form = {
|
modalData.form = {
|
||||||
title: "",
|
title: '',
|
||||||
getLimit: 1,
|
getLimit: 1,
|
||||||
giveNum: 1,
|
giveNum: 1,
|
||||||
couponId: "",
|
couponId: ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function confirmCoupon() {
|
function confirmCoupon() {
|
||||||
console.log(modalData.form);
|
console.log(modalData.form);
|
||||||
if (!modalData.form.title) {
|
if (!modalData.form.title) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "请输入自定义文案",
|
title: '请输入自定义文案',
|
||||||
icon: "none",
|
icon: 'none'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!modalData.form.couponId) {
|
if (!modalData.form.couponId) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "请选择优惠券",
|
title: '请选择优惠券',
|
||||||
icon: "none",
|
icon: 'none'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!modalData.form.giveNum) {
|
if (!modalData.form.giveNum) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "请输入发放数量",
|
title: '请输入发放数量',
|
||||||
icon: "none",
|
icon: 'none'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!modalData.form.getLimit) {
|
if (!modalData.form.getLimit) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "请输入每人限领量",
|
title: '请输入每人限领量',
|
||||||
icon: "none",
|
icon: 'none'
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function previewImage(url) {
|
function previewImage(url) {
|
||||||
|
|
||||||
prveImgsList.value = [url];
|
prveImgsList.value = [url];
|
||||||
showPrveImg.value = true;
|
showPrveImg.value = true;
|
||||||
}
|
}
|
||||||
@@ -715,11 +633,11 @@ watch(
|
|||||||
const bottomSlotHeight = computed(() => {
|
const bottomSlotHeight = computed(() => {
|
||||||
if (showMoreBtn.value) {
|
if (showMoreBtn.value) {
|
||||||
return {
|
return {
|
||||||
height: "180px",
|
height: '180px'
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
height: "88px",
|
height: '88px'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -729,12 +647,12 @@ const pageHeight = computed(() => {
|
|||||||
if (safeAreaHeight > 0) {
|
if (safeAreaHeight > 0) {
|
||||||
return `height: calc(${safeAreaHeight}px - var(--window-top));`;
|
return `height: calc(${safeAreaHeight}px - var(--window-top));`;
|
||||||
}
|
}
|
||||||
return "";
|
return '';
|
||||||
});
|
});
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
// 页面显示时,检查连接状态
|
// 页面显示时,检查连接状态
|
||||||
if (!chatStore.isConnect || !chatStore.socketTask) {
|
if (!chatStore.isConnect || !chatStore.socketTask) {
|
||||||
console.log("聊天页显示,检查Socket连接");
|
console.log('聊天页显示,检查Socket连接');
|
||||||
chatStore.forceReconnect();
|
chatStore.forceReconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -745,6 +663,8 @@ onUnmounted(() => {
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
$grayColor: #9e9e9e;
|
||||||
|
$grayBorderColor: #bebebe;
|
||||||
.top {
|
.top {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
padding: 40rpx 32rpx;
|
padding: 40rpx 32rpx;
|
||||||
@@ -768,7 +688,7 @@ onUnmounted(() => {
|
|||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
// 添加弹性容器,让内容自动在顶部
|
// 添加弹性容器,让内容自动在顶部
|
||||||
&::before {
|
&::before {
|
||||||
content: ".";
|
content: '.';
|
||||||
display: inline;
|
display: inline;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
line-height: 0;
|
line-height: 0;
|
||||||
@@ -785,25 +705,34 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
.user {
|
.user {
|
||||||
margin-bottom: 88rpx;
|
margin-bottom: 88rpx;
|
||||||
|
.name {
|
||||||
|
margin-top: -4upx;
|
||||||
|
color: $grayColor;
|
||||||
|
font-size: 24upx;
|
||||||
|
}
|
||||||
.msg {
|
.msg {
|
||||||
padding: 16rpx 20rpx;
|
padding: 16rpx 20rpx;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border-radius: 8rpx;
|
border-radius: 20rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.shop {
|
.shop {
|
||||||
margin-bottom: 88rpx;
|
margin-bottom: 88rpx;
|
||||||
.tag {
|
.tag {
|
||||||
margin-right: 32rpx;
|
margin-right: 32rpx;
|
||||||
padding: 8rpx 20rpx;
|
padding: 4rpx 12rpx;
|
||||||
border: 1px solid #d9d9d9;
|
border: 1px solid $grayBorderColor;
|
||||||
border-radius: 8rpx;
|
border-radius: 8rpx;
|
||||||
font-size: 24rpx;
|
font-size: 20rpx;
|
||||||
color: #666;
|
color: $grayColor;
|
||||||
|
}
|
||||||
|
.name {
|
||||||
|
color: $grayColor;
|
||||||
|
font-size: 24upx;
|
||||||
}
|
}
|
||||||
.msg {
|
.msg {
|
||||||
padding: 16rpx 20rpx;
|
padding: 16rpx 20rpx;
|
||||||
border-radius: 8rpx;
|
border-radius: 20rpx;
|
||||||
&.type1 {
|
&.type1 {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user