增加聊天功能

This commit is contained in:
2025-12-04 17:14:47 +08:00
parent ca829d7f00
commit 6f1185be3a
25 changed files with 2504 additions and 2 deletions

11
common/api/market/chat.js Normal file
View File

@@ -0,0 +1,11 @@
// 引入 request 文件
import request from "@/common/api/request.js";
import { prveUrl } from "./config.js";
export const couponGrant = (data) => {
return request({
url: prveUrl + "/user/chat/coupon/grant",
method: "post",
data: data,
});
};

64
common/api/upload.js Normal file
View File

@@ -0,0 +1,64 @@
function getHeader() {
let token = uni.cache.get("token") || "";
const shopId = uni.cache.get("shopId") * 1;
const userInfo = uni.cache.get("userInfo") || {};
return {
version: uni.conf.version,
type: uni.getSystemInfoSync().platform,
// #ifdef APP-PLUS
platformType: "APP",
// #endif
// #ifdef H5
platformType: "H5",
// #endif
// #ifdef MP-WEIXIN
platformType: "WX",
// #endif
// #ifdef MP-ALIPAY
platformType: "ALI",
// #endif
token,
id: userInfo.id || "",
shopId: shopId || "",
userId: userInfo.id || "",
};
}
// 上传
export function upload(uri, file, data, showLoading = true, extParams = {}) {
return new Promise((resolve, reject) => {
uni.showLoading();
uni
.uploadFile(
Object.assign(
{
url: uni.conf.baseUrl + uri,
formData: data,
name: "file",
filePath: file.path || file.url || file,
header: getHeader(),
},
extParams
)
)
.then((httpData) => {
// uni.upload 返回bodyData 的是 string类型。 需要解析。
httpData.data = JSON.parse(httpData.data);
if( httpData.data.code==200){
resolve( httpData.data.data);
}
reject()
})
.catch((err) => {
reject();
uni.hideLoading();
infoBox.showErrorToast(`上传失败`);
});
});
}
export const uploadFile = (file, data) => {
return upload("/account/user/common/upload", file, data);
};

View File

@@ -37,6 +37,8 @@ export const changeEnv = (env) => {
uni.conf = {
debug: true,
baseUrl: "http://192.168.1.42",
phpUrl:'http://192.168.1.42:8787/api/',
phpChatWx:'ws://192.168.1.42:2348',
version: 100,
autoRemoveCache,
baseUrlwws: "ws://192.168.1.42:2348",

View File

@@ -105,6 +105,7 @@ page,
justify-content: center;
}
.u-flex-col{
display: flex;
flex-direction: column!important;
}
.min-h-100vh{
@@ -115,4 +116,59 @@ page,
}
.align-center{
align-items: center;
}
}
.u-row-between{
justify-content: space-between;
}
.u-row-right {
justify-content: flex-end;
}
// 定义字体(rpx)单位大于或等于20的都为rpx单位字体
@for $i from 20 through 40 {
.u-font-#{$i} {
font-size: $i + rpx;
}
}
.min-page{
/* #ifdef H5 */
min-height: calc(100vh - 44px);
/* #endif */
/* #ifndef H5 */
min-height: 100vh;
/* #endif */
}
.bg-f7{
background-color: #F7F7F7;
}
.default-box-padding{
padding: 32rpx 28rpx;
}
.default-box-radius{
border-radius: 16rpx;
}
.default-box-x-padding{
padding-left: 28rpx;
padding-right: 28rpx;
}
.default-box-y-padding{
padding-top: 32rpx;
padding-bottom: 32rpx;
}
$height: 70rpx;
.u-col-baseline{
align-items: baseline;
}
.text-right{
text-align: right;
}
.u-row-center{
justify-content: center;
}
.u-col-center{
align-items: center;
}

91
http/php/chat.js Normal file
View File

@@ -0,0 +1,91 @@
import { request } from "./request";
const prveUrl = "chat/";
/**
* 群消息
* @param {Object} data
* @returns
*/
export const groupInfo = (data) => {
return request(prveUrl + "group/info", "POST", data, true);
};
export const commonPhrase = (data) => {
return request(prveUrl + "common-phrase/index", "POST", data, true);
};
export const commonPhraseAdd = (data) => {
return request(prveUrl + "common-phrase/add", "POST", data, true);
};
export const commonPhraseDel = (data) => {
return request(prveUrl + "common-phrase/del", "POST", data, true);
};
export const groupCreate = (data) => {
return request(prveUrl + "group/create", "POST", data, true);
};
export const groupJoin = (data) => {
return request(prveUrl + "group/join", "POST", data, true);
};
export const groupGetGroupUrl = (data) => {
return request(prveUrl + "group/getgrepurl", "POST", data, true);
};
export const groupQuit = (data) => {
return request(prveUrl + "group/quit", "POST", data, true);
};
export const groupTarsGroup = (data) => {
return request(prveUrl + "group/tarsgroup", "POST", data, true);
};
export const groupAnnouncement = (data) => {
return request(prveUrl + "group/announcement", "POST", data, true);
};
export const groupMute = (data) => {
return request(prveUrl + "group/mute", "POST", data, true);
};
export const groupMunute = (data) => {
return request(prveUrl + "group/unmute", "POST", data, true);
};
export const groupKick = (data) => {
return request(prveUrl + "group/kick", "POST", data, true);
};
export const groupMembers = (data) => {
return request(prveUrl + "group/members", "POST", data, true);
};
export const messageHistory = (data) => {
return request(prveUrl + "message/history", "POST", data, true);
};
export const messageMarkRead = (data) => {
return request(prveUrl + "message/mark-read", "POST", data, true);
};
export const messageMarkReadAll = (data) => {
return request(prveUrl + "message/mark-read-all", "POST", data, true);
};
export const messageUnreadCount = (data) => {
return request(prveUrl + "message/unread-count", "POST", data, true);
};
export const messageSessionList = (data) => {
return request(prveUrl + "message/sessionlist", "POST", data, true);
};
export const groupDoNotDisturb = (data) => {
return request(prveUrl + "group/do-not-disturb", "POST", data, true);
};
export const groupShopinfo = (data) => {
return request(prveUrl + "group/shopinfo", "POST", data, true);
};
export const sessionlistdel = (data) => {
return request(prveUrl + "message/sessionlistdel", "POST", data, true);
};

100
http/php/request.ts Normal file
View File

@@ -0,0 +1,100 @@
//服务器接口地址
// const baseURL : string = 'https://newblockwlx.sxczgkj.cn/index.php/api/'
let baseURL: string = "http://192.168.1.42:8787/api/";
// #ifdef H5
baseURL = "/phpapi/api/";
// #endif
// 封装公共请求方法
function request(
url: string,
method: "GET" | "POST" | undefined,
data: object | any,
toast: boolean
) {
let networkType = "";
uni.getNetworkType({
success: (res) => {
networkType = res.networkType;
},
});
if (networkType == "none") {
uni.showToast({
title: "网络异常,请检查网络",
icon: "none",
});
return false;
}
if (toast) {
uni.showLoading({
title: "加载中",
mask: true,
});
}
return new Promise(async (resolve, reject) => {
let header: any;
header = {
"content-type": "application/json",
token: uni.cache.get('token'),
};
uni.request({
url: baseURL + url,
method: method,
data: data,
header: header,
success(res: any) {
if (res.data.code != 1) {
if (res.data.code === 3000) {
uni.showToast({
title: '请登录后操作',
icon: "none",
});
uni.hideLoading();
reject();
return;
}
//是否提示错误
if (toast) {
uni.showToast({
title: res.data.msg || res.data.message,
icon: "none",
});
setTimeout(() => {
uni.hideLoading();
}, 1000);
}
if (res.data.code == 401) {
uni.showToast({
title: res.message || res.msg,
icon: "none",
success: () => {
// uni.removeStorageSync('logintoken');
// uni.removeStorageSync('token');
uni.reLaunch({
url: "/pages/index/index",
});
},
});
}
uni.hideLoading();
reject(res.message | res.msg);
} else {
uni.hideLoading();
console.log(res);
resolve(res.data.data);
}
},
fail(err) {
uni.hideLoading();
//请求失败
uni.showToast({
title: "无法连接到服务器",
icon: "none",
});
reject(err);
},
});
});
}
export { request, baseURL };

726
pageChat/chat.vue Normal file
View File

@@ -0,0 +1,726 @@
<template>
<view class="min-page bg-f7 u-font-28 color-333" :style="pageHeight">
<view class="top u-flex u-row-between">
<text style="max-width: 600rpx" class="u-line-1 u-font-32">
{{ groupInfo.name }}
</text>
<text class="u-m-l-22"
>{{ membersRes?.user_list?.length || 0 }}</text
>
<!-- <view class="" @click="toMore()">
<view class="u-flex u-row-center">
<up-icon name="more-dot-fill" color="#333" size="14"></up-icon>
</view>
<view class="color-666">更多</view>
</view> -->
</view>
<view class="box-1">
<!-- @refresherrefresh="refresherrefresh" -->
<scroll-view
scroll-y
refresher-background="transparent"
style="height: 100%"
@scrolltoupper="refresherrefresh"
:refresher-enabled="false"
:scroll-with-animation="false"
:refresher-triggered="scrollView.refresherTriggered"
:scroll-into-view="scrollView.intoView"
>
<view class="scroll-view-box">
<view class="talk-list">
<view
:id="'msg-' + index"
v-for="(item, index) in chatStore.chatList"
:key="index"
>
<!-- 发消息 -->
<template
v-if="item.operate_type == 'sendMsg' || item.is_user_send == 1"
>
<view class="user u-flex u-row-right">
<view class="u-p-r-18">
<view class="color-000 u-line-1 text-right">{{ item.nick_name }}</view>
<view
class="u-m-t-14 msg u-p-l-30"
:class="['type' + item.msg_type]"
>
<chatItem :item="item"></chatItem>
</view>
</view>
<up-avatar
size="122rpx"
:src="item.avatar"
shape="square"
bg-color="#fff"
></up-avatar>
</view>
</template>
<!-- 商家消息 -->
<template v-else>
<view class="shop u-flex">
<up-avatar
:src="shopInfo.logo"
size="122rpx"
shape="square"
bg-color="#fff"
></up-avatar>
<view class="u-p-l-18">
<view class="u-flex">
<view class="tag">商家</view>
<view class="color-000">{{ shopInfo.shopName }}</view>
</view>
<view
class="u-m-t-14 msg"
:class="['type' + item.msg_type]"
>
<chatItem :item="item" @getCoupon="getCoupon"></chatItem>
</view>
</view>
</view>
</template>
</view>
</view>
<up-loadmore
v-if="isEnd"
:status="isEnd ? 'nomore' : 'loading'"
></up-loadmore>
</view>
</scroll-view>
</view>
<!-- <view :style="bottomSlotHeight"></view> -->
<view class="bottom" :class="[showMoreBtn ? '' : 'safe-bottom']">
<view class="u-flex" style="padding: 14rpx 28rpx" v-if="groupInfo&&!groupInfo.is_mute">
<!-- <input
type="text"
class="u-flex-1 u-m-r-52 iput"
placeholder="请输入内容"
v-model="msg"
/> -->
<view class="u-flex-1 u-m-r-52 iput">
<up-input
v-model="msg"
border="none"
placeholder="请输入内容"
></up-input>
</view>
<button class="send-btn" v-if="msg.trim().length > 0" @click="sendText">
<text>发送</text>
</button>
<up-icon
name="plus-circle"
color="#666"
size="40rpx"
@click="showMoreBtnToggle"
v-else
></up-icon>
</view>
<view class="color-666 u-font-28 text-center u-m-t-28" v-else>商家已禁言</view>
<view class="more-btn" v-if="showMoreBtn">
<view
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">
<image :src="item.icon" class="img" mode="aspectFill"></image>
</view>
<view class="u-m-t-8">{{ item.title }}</view>
</view>
</view>
</view>
</view>
<!-- 退出群聊 -->
<u-popup
:show="popupShow"
:safe-area-inset-bottom="false"
mode="center"
@close="popupShow = false"
>
<view class="popup-content">
<view class="header-wrap">
<text class="t">退出群{{ "{" + groupInfo.name + "}" }}</text>
<view class="close" @click="popupShow = false">
<u-icon name="close" size="16" color="#666"></u-icon>
</view>
</view>
<view class="u-p-40 text-center u-font-28 color-333 border-bottom"
>是否确认退出退出后将会错失更多活动和优惠</view
>
<view class="btn-content">
<view class="btn">
<u-button
color="#E8AD7B"
plain=""
shape="circle"
@click="popupShow = false"
>取消</u-button
>
</view>
<view class="btn">
<u-button color="#E8AD7B" shape="circle" @click="exitGroup"
>退出</u-button
>
</view>
</view>
</view>
</u-popup>
</template>
<script setup>
import {
onReady,
onReachBottom,
onLoad,
onPageScroll,
} from "@dcloudio/uni-app";
import {
ref,
inject,
onMounted,
nextTick,
reactive,
watch,
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";
function exitGroup() {
chatApi
.groupQuit({
group_id: groupInfo.value.id,
})
.then((res) => {
if (res) {
popupShow.value = false;
uni.showToast({
title: "退出成功",
icon: "none",
duration: 1500,
});
setTimeout(() => {
uni.navigateBack();
}, 1500);
}
});
}
function getCoupon(item) {
javaChatApi
.couponGrant({
id: item.coupon.activity_id,
shopUserId: shopInfo.id,
userId: uni.cache.get("userInfo").id,
})
.then((res) => {
if (res) {
uni.showToast({
title: "领取成功",
icon: "none",
duration: 2000,
});
refresh()
}
});
}
function refresh() {
query.page=1;
getMsgList();
}
const go = {
to(item) {},
};
const popupShow = ref(false);
import Modal from "./components/modal.vue";
import chatItem from "./components/chat-item.vue";
const placeholderStyle = {
color: "#999",
fontSize: "28rpx",
};
function refresherrefresh() {
console.log("refresherrefresh");
// 关键:同时判断「正在加载」和「无更多数据」,只要一个为真就关闭刷新
if (isLoading.value || isEnd.value) {
scrollView.refresherTriggered = false; // 立即关闭刷新状态
if (isEnd.value) {
uni.showToast({ title: "没有更多了", icon: "none" });
}
return; // 终止后续逻辑
}
query.page++;
getMsgList();
}
const scrollView = reactive({
refresherTriggered: false,
intoView: "",
safeAreaHeight: 0,
});
const showMoreBtn = ref(false);
function showMoreBtnToggle() {
showMoreBtn.value = !showMoreBtn.value;
if (showMoreBtn.value) {
}
}
const modalData = reactive({
show: false,
form: {
title: "",
getLimit: 1,
giveNum: 1,
couponId: "",
},
});
const chatStore = useChatStore();
chatStore.onReceiveMsg = (msg) => {
nextTick(() => {
scrollView.intoView = "msg-0";
});
};
chatStore.connectSocket();
const msg = ref("");
const shopInfo = uni.cache.get("shopInfo");
const shopUserInfo = uni.cache.get("shopUserInfo");
const moreBtns = ref([
{
icon: "/pageChat/static/pic.png",
title: "发送照片",
value: "pic",
},
{
icon: "/pageChat/static/video.png",
title: "发送视频",
value: "video",
},
{
icon: "/pageChat/static/exit.png",
title: "退出群聊",
value: "exit",
},
]);
function moreBtnsClick(item, index) {
if (item.value == "exit") {
popupShow.value = true;
return;
}
if (item.value == "pic") {
sendImg();
}
if (item.value == "video") {
sendVideo();
}
}
function videoErrorCallback(e) {
console.error("视频播放失败", e);
}
function sendImg() {
uni.chooseImage({
count: 3, //默认9
sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
sourceType: ["album", "camera "],
success: async function (res) {
uni.showLoading({
title: "发送中",
});
console.log(res);
for (let i = 0; i < res.tempFiles.length; i++) {
const fileRes = await uploadFile(res.tempFiles[i]);
if (fileRes) {
sendMsg({
image_url: fileRes,
msg_type: 2,
});
} else {
}
}
},
});
}
function sendVideo() {
uni.chooseVideo({
count: 1, //默认9
sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
sourceType: ["album", "camera "],
success: async function (res) {
uni.showLoading({
title: "发送中",
});
console.log(res);
const fileRes = await uploadFile({ path: res.tempFilePath });
uni.hideLoading();
if (fileRes) {
sendMsg({
image_url: fileRes,
msg_type: 5,
});
} else {
uni.showToast({
title: "发送失败",
icon: "none",
});
}
},
});
}
const groupInfo = ref({});
async function init() {
const res = await chatApi.groupInfo({
group_id: options.group_id,
});
console.log(res);
groupInfo.value = res || {};
getMsgList();
}
const query = reactive({
page: 1,
size: 10,
});
async function getMsgList() {
// 提前拦截:已无更多数据,直接关闭状态
if (isEnd.value) {
scrollView.refresherTriggered = false;
isLoading.value = false;
uni.showToast({ title: "没有更多了", icon: "none" });
return;
}
isLoading.value = true;
try {
const msgRes = await chatApi.messageHistory({
...query,
chat_type: "2",
session_id: options.session_id,
to_id: options.group_id,
shop_id: options.group_id,
group_id: options.group_id,
});
const data = msgRes.list || [];
const selector = `msg-${query.page == 1 ? 0 : chatStore.chatList.length}`;
if (query.page == 1) {
chatStore.chatList = data;
} else {
chatStore.chatList.push(...data);
}
isEnd.value = chatStore.chatList.length >= msgRes.total;
nextTick(() => {
scrollView.intoView = selector;
console.log(selector);
});
} catch (err) {
console.error("加载历史消息异常", err);
// 加载失败回退页码,避免页码错乱
if (query.page > 1) query.page--;
} finally {
console.log("scrollView", scrollView);
setTimeout(() => {
scrollView.refresherTriggered = false;
isLoading.value = false;
}, 100);
}
}
const options = reactive({});
const membersRes = ref(null);
onLoad((opt) => {
Object.assign(options, opt);
init();
chatApi.messageMarkReadAll({
session_ids: options.session_id,
});
chatApi.groupMembers({ group_id: options.group_id }).then((res) => {
console.log(res);
membersRes.value = res;
});
// #ifdef H5
scrollView.safeAreaHeight = uni.getSystemInfoSync().safeArea.height;
// #endif
});
function toMore() {
go.to("PAGES_CHAT_GROUP_INFO", {
group_id: groupInfo.value.id,
session_id: options.session_id,
});
}
function sendText() {
if (!msg.value.trim().length) return;
sendMsg({ content: msg.value, msg_type: 1 });
msg.value = "";
}
function sendMsg(msg) {
chatStore.sendMessage({
to_id: groupInfo.value.id,
to_user_type: groupInfo.value.id,
chat_type: 2,
content: msg.value,
image_url: "",
order_id: "",
session_id: "",
...msg,
});
}
function closeModal() {
modalData.form = {
title: "",
getLimit: 1,
giveNum: 1,
couponId: "",
};
}
function confirmCoupon() {
console.log(modalData.form);
if (!modalData.form.title) {
uni.showToast({
title: "请输入自定义文案",
icon: "none",
});
return;
}
if (!modalData.form.couponId) {
uni.showToast({
title: "请选择优惠券",
icon: "none",
});
return;
}
if (!modalData.form.giveNum) {
uni.showToast({
title: "请输入发放数量",
icon: "none",
});
return;
}
if (!modalData.form.getLimit) {
uni.showToast({
title: "请输入每人限领量",
icon: "none",
});
return;
}
}
function previewImage(url) {
uni.previewImage({
urls: [url],
});
}
//是否到底了
const isBottom = ref(false);
const isLoading = ref(false);
//消息是否完了
const isEnd = ref(false);
watch(
() => chatStore.chatList.length,
(newVal, oldVal) => {}
);
const bottomSlotHeight = computed(() => {
if (showMoreBtn.value) {
return {
height: "180px",
};
} else {
return {
height: "88px",
};
}
});
onReady(() => {});
const pageHeight = computed(() => {
const safeAreaHeight = scrollView.safeAreaHeight;
if (safeAreaHeight > 0) {
return `height: calc(${safeAreaHeight}px - var(--window-top));`;
}
return "";
});
</script>
<style lang="scss" scoped>
.top {
background-color: #fff;
padding: 40rpx 32rpx;
}
.min-page {
height: calc(100vh - var(--window-top));
display: flex;
flex-direction: column;
flex-wrap: nowrap;
align-content: center;
justify-content: space-between;
align-items: stretch;
}
.talk-list {
padding: 30rpx 28rpx 30rpx 26rpx;
display: flex;
flex-direction: column-reverse;
flex-wrap: nowrap;
align-content: flex-start;
justify-content: flex-end;
align-items: stretch;
// 添加弹性容器,让内容自动在顶部
&::before {
content: ".";
display: inline;
visibility: hidden;
line-height: 0;
font-size: 0;
flex: 1 0 auto;
height: 1px;
}
}
.box-1 {
width: 100%;
height: 0;
flex: 1 0 auto;
box-sizing: content-box;
}
.user {
margin-bottom: 88rpx;
.msg {
padding: 16rpx 20rpx;
background-color: #fff;
border-radius: 8rpx;
}
}
.shop {
margin-bottom: 88rpx;
.tag {
margin-right: 32rpx;
padding: 8rpx 20rpx;
border: 1px solid #d9d9d9;
border-radius: 8rpx;
font-size: 24rpx;
color: #666;
}
.msg {
padding: 16rpx 20rpx;
border-radius: 8rpx;
&.type1 {
background-color: #fff;
}
&.type4 {
background-color: #fff;
}
.img {
width: 50vw;
}
}
}
.bottom {
height: auto;
z-index: 2;
border-top: #e5e5e5 solid 1px;
box-sizing: content-box;
background-color: #f3f3f3;
/* 兼容iPhoneX */
padding-bottom: 0;
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
&.safe-bottom {
padding-bottom: calc(env(safe-area-inset-bottom) + 4rpx);
}
.iput {
background-color: #f8f8f8;
padding: 16rpx 20rpx;
}
}
.send-btn {
background-color: $my-main-color;
color: #fff;
line-height: 1;
padding: 16rpx 20rpx;
border-radius: 8rpx;
font-size: 28rpx;
display: flex;
align-items: center;
}
.more-btn {
display: flex;
justify-content: center;
align-items: center;
padding: 30rpx;
background-color: #f0f0f0;
gap: 74rpx;
text-align: center;
color: #666;
padding-bottom: calc(env(safe-area-inset-bottom) + 4rpx);
.icon {
width: 100rpx;
height: 100rpx;
background-color: #fff;
border-radius: 16rpx;
display: flex;
justify-content: center;
align-items: center;
.img {
height: 70rpx;
width: 70rpx;
}
}
}
.scroll-view-box {
display: flex;
flex-direction: column-reverse;
}
.popup-content {
width: 90vw;
background-color: #fff;
border-radius: 8px;
.header-wrap {
height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #ececec;
padding: 0 28upx;
.t {
font-size: 32upx;
color: #333;
}
.close {
$size: 60upx;
width: $size;
height: $size;
display: flex;
align-items: center;
justify-content: center;
}
}
.btn-content {
height: 86px;
display: flex;
align-items: center;
justify-content: center;
gap: 60upx;
.btn {
width: 248upx;
}
}
}
</style>

View File

@@ -0,0 +1,152 @@
<template>
<text class="" v-if="item.msg_type == 1">{{ item.content }}</text>
<image
v-if="item.msg_type == 2"
:src="item.image_url"
class="img"
mode="widthFix"
@click="previewImage(item.image_url)"
></image>
<video
@error="videoErrorCallback"
v-if="item.msg_type == 5"
:src="item.image_url"
class="img"
mode="widthFix"
@click="previewVideo(item.video_url)"
></video>
<view class="" v-if="item.msg_type == 4">
<view>{{ item.coupon.title }}</view>
<view class="u-m-t-16 bg-f7 coupon u-flex" style="min-width: 500rpx;">
<template v-if="item.coupon.type == 1">
<view class="left">
<view class="price">
<text class="u-font-32">¥</text>
<text style="font-size: 72rpx">{{
item.coupon.discountAmount
}}</text>
</view>
<view class="u-font-24 color-999 no-wrap"
>{{ item.coupon.fullAmount }}可用</view
>
</view>
</template>
<template v-if="item.coupon.type == 2">
<view class="left">
<view class="price">
<text class="u-font-32"
>商品兑换券</text
>
</view>
<view class="u-font-24 color-999 no-wrap"
>{{ item.coupon.fullAmount }}可用</view
>
</view>
</template>
<template v-if="item.coupon.type == 3">
<view class="left">
<view class="price">
<text class="u-font-32"
>{{ item.coupon.discountRate / 100 }}</text
>
</view>
<view class="u-font-24 color-999 no-wrap"
>{{ item.coupon.fullAmount }}可用</view
>
</view>
</template>
<template v-if="item.coupon.type == 4">
<view class="left">
<view class="price">
<text class="u-font-32"
>第二件半价券</text
>
</view>
</view>
</template>
<template v-if="item.coupon.type == 6">
<view class="left">
<view class="price">
<text class="u-font-32"
>买一送一券</text
>
</view>
</view>
</template>
<view class="right u-p-l-28">
<view class="u-font-32">{{ item.coupon.couponName }}</view>
<view class="u-font-24 color-999 u-m-t-8"
>有效期{{ returnTime(item.coupon) }}</view
>
</view>
</view>
<view class="u-flex u-row-center u-m-t-32">
<!-- <view class="lingqu hasGet" v-if="item.coupon_claim">已领取</view> -->
<view class="lingqu" @click="getCoupon()" >领取</view>
</view>
</view>
</template>
<script setup>
const props = defineProps({
item: {
type: Object,
default: () => {},
},
});
const emits = defineEmits(["getCoupon"]);
function getCoupon() {
emits("getCoupon", props.item);
}
function previewImage(url) {
uni.previewImage({
urls: [url],
});
}
function returnTime(coupon){
let startTime = coupon.useStartTime;
let endTime = coupon.useEndTime;
if(startTime && endTime){
return startTime.split(' ')[0] + '-' + endTime.split(' ')[0]
}
}
</script>
<style lang="scss" scoped>
.img {
width: 50vw;
}
.coupon {
padding: 16rpx 10rpx;
border-radius: 16rpx;
.price {
color: #ff1c1c;
font-weight: 700;
}
.left {
width: 112rpx;
margin-right: 26rpx;
}
.right {
border-left: 1rpx solid #ededed;
}
}
.lingqu {
background-color: #e8ad7b;
line-height: 48rpx;
font-size: 28rpx;
padding: 6rpx 70rpx;
color: #fff;
border-radius: 140rpx;
&.hasGet {
background-color: #eee;
color: #999;
}
}
</style>

View File

@@ -0,0 +1,108 @@
<template>
<view>
<view @click="open">
<slot v-if="$slots.default"> </slot>
<view v-else class="choose-goods u-flex u-row-between">
<text class="color-999" v-if="!startTime && !endTime"
>请选择日期范围</text
>
<text class="color-333 u-font-24 u-m-r-32 " v-else
>{{ startTime }} - {{ endTime }}</text
>
<view class="u-flex" v-if="startTime&&endTime" @click.stop="clear">
<up-icon name="close" size="14"></up-icon>
</view>
<up-icon size="14" name="arrow-right" v-else ></up-icon>
</view>
</view>
<my-date-pickerview
@confirm="datePickerConfirm"
mode="all"
ref="datePicker"
></my-date-pickerview>
</view>
</template>
<script setup>
import { ref } from "vue";
const datePicker = ref(null);
const startTime = defineModel("startTime", {
default: () => "",
type: String,
});
const endTime = defineModel("endTime", {
default: () => "",
type: String,
});
function clear(){
startTime.value = "";
endTime.value = "";
}
function open() {
datePicker.value.toggle();
}
function datePickerConfirm(e) {
startTime.value = e.start;
endTime.value = e.end;
console.log(e);
}
</script>
<style lang="scss">
.popup-content {
background: #fff;
width: 640rpx;
border-radius: 18rpx;
}
.top {
padding: 40rpx 48rpx;
border-bottom: 1px solid #d9d9d9;
}
.bottom {
padding: 48rpx 52rpx;
display: flex;
justify-content: space-between;
border-top: 1px solid #d9d9d9;
gap: 50rpx;
.btn {
flex: 1;
text-align: center;
padding: 18rpx 60rpx;
border-radius: 100rpx;
font-size: 32rpx;
border: 2rpx solid transparent;
&.success {
background-color: $my-main-color;
color: #fff;
}
&.cancel {
border-color: #d9d9d9;
box-shadow: 0 4rpx 0 0 #00000005;
}
}
}
.item {
padding: 10rpx 30rpx;
border: 1px solid #d9d9d9;
margin: 10rpx;
border-radius: 8rpx;
transition: all 0.3s ease-in-out;
box-shadow: 0 0 10px transparent;
&.selected {
border-color: $my-main-color;
box-shadow: 0 0 10px $my-main-color;
}
}
.choose-goods {
display: flex;
padding: 24rpx;
align-items: center;
border-radius: 8rpx;
border: 2rpx solid #d9d9d9;
background: #fff;
font-size: 28rpx;
font-weight: 400;
min-height: 90rpx;
}
</style>

View File

@@ -0,0 +1,85 @@
<template>
<view>
<up-popup :show="show" mode="center">
<view class="popup-content">
<view class="top u-flex u-row-between">
<text class="font-bold u-font-32 color-333">{{ title }}</text>
<up-icon size="18" name="close" @click="close"></up-icon>
</view>
<up-line></up-line>
<scroll-view style="max-height: 50vh" :scroll-y="true">
<slot></slot>
</scroll-view>
<up-line></up-line>
<view class="bottom">
<view class="btn cancel" @click="close">{{ cancelText }}</view>
<view class="btn success" @click="confirm">{{ confirmText }}</view>
</view>
</view>
</up-popup>
</view>
</template>
<script setup>
import { ref } from "vue";
const props = defineProps({
title: {
type: String,
default: "标题",
},
confirmText: {
type: String,
default: "保存",
},
cancelText: {
type: String,
default: "取消",
},
});
const show = defineModel({
type: Boolean,
default: false,
});
const emits = defineEmits(["close", "confirm"]);
function close() {
show.value = false;
emits("close");
}
function confirm() {
emits("confirm");
}
</script>
<style lang="scss">
.popup-content {
background: #fff;
width: 640rpx;
border-radius: 18rpx;
}
.top {
padding: 40rpx 48rpx;
}
.bottom {
padding: 48rpx 52rpx;
display: flex;
justify-content: space-between;
gap: 50rpx;
.btn {
flex: 1;
text-align: center;
padding: 18rpx 60rpx;
border-radius: 100rpx;
font-size: 32rpx;
border: 2rpx solid transparent;
white-space: nowrap;
&.success {
background-color: $my-main-color;
color: #fff;
}
&.cancel {
border-color: #d9d9d9;
box-shadow: 0 4rpx 0 0 #00000005;
}
}
}
</style>

View File

@@ -0,0 +1,49 @@
<template>
<view>
<up-action-sheet
:round="14"
:actions="list"
:title="title"
:show="show"
closeOnClickAction
cancelText="取消"
@close="close"
@select="sheetSelect"
></up-action-sheet>
</view>
</template>
<script setup >
import { ref, reactive, onMounted } from "vue";
import { getShopList } from "@/http/api/shop.js";
const props = defineProps({
title: {
type: String,
default: "请选择",
},
});
const list = ref([]);
const show=defineModel({
name: "show",
default: false,
})
function close() {
show.value = false;
}
const emit=defineEmits(["choose"]);
function sheetSelect(e) {
console.log(e);
emit("choose", e);
}
onMounted(() => {
getShopList().then((res) => {
list.value = res.map((v) => ({
...v,
value: v.shopId,
name: v.shopName,
}));
});
});
</script>

View File

@@ -0,0 +1,184 @@
<template>
<view class="min-page bg-f7 u-font-28 color-333 u-p-t-32">
<view class="bg-fff">
<view class="default-box u-flex u-row-between border-bottom">
<text class="font-bold">优惠券名称</text>
<text>{{ couponActivity.couponJson.couponName }}</text>
</view>
<view class="default-box u-flex u-row-between border-bottom">
<text class="font-bold">发放数量</text>
<text>{{ couponActivity.giveNum }}</text>
</view>
<view class="default-box u-flex u-row-between border-bottom">
<text class="font-bold">已领取数量</text>
<text>{{ couponActivity.giveNum - couponActivity.leftNum }}</text>
</view>
<view class="default-box u-flex u-row-between border-bottom">
<text class="font-bold">剩余数量</text>
<text>{{ couponActivity.leftNum }}</text>
</view>
<view class="default-box u-flex u-row-between border-bottom">
<text class="font-bold">已使用数量</text>
<text>{{ couponActivity.useNum }}</text>
</view>
</view>
<view class="u-flex u-row-right default-box u-p-r-32 bg-fff">
<up-select
:options="statusOptions"
@select="selectItem"
labelName="label"
>
<template #text>
<view class="select">
<text v-if="selStatus">{{ selStatus.label }}</text>
<text v-else class="color-999">请选择状态</text>
<up-icon name="arrow-down"></up-icon>
</view>
</template>
<template #icon> <view></view></template>
</up-select>
</view>
<view class="u-m-t-32 table bg-fff">
<view class="header">
<view class="user">用户</view>
<view class="gettime">领取时间</view>
<view class="usetime">使用时间</view>
<view class="status">状态</view>
<view class="operation">操作</view>
</view>
<view class="body">
<view class="item" v-for="(item,index) in 10" :key="index">
<view class="user">用户昵称40239</view>
<view class="gettime">2025/06/27 20:07:18</view>
<view class="usetime">2025/01/15 08:02:38</view>
<view class="status">已使用</view>
<view class="operation status3">失效</view>
</view>
</view>
</view>
<up-loadmore :status="isEnd ? 'nomore' : 'loading'"></up-loadmore>
<view style="height: 40px"></view>
</view>
</template>
<script setup>
import { onReachBottom, onLoad } from "@dcloudio/uni-app";
import { reactive, ref, watch } from "vue";
import { onShow } from "@dcloudio/uni-app";
import go from "@/commons/utils/go.js";
import * as chatCouponApi from "@/http/api/market/chat";
const statusOptions = ref([
{ label: "全部", value: "" },
{ label: "未使用", value: 0 },
{ label: "已使用", value: 1 },
{ label: "已过期", value: 2 },
]);
const selStatus = ref("");
const query = reactive({
page: 1,
pageSize: 10,
status: "",
});
const options = reactive({
id: "",
});
function selectItem(item) {
selStatus.value = item;
}
watch(
() => selStatus.value,
(newVal, oldVal) => {
query.status = newVal.value;
refresh();
}
);
function refresh() {
query.page = 1;
isEnd.value = false;
getList();
}
const couponActivity = ref({});
const list = ref([]);
const isEnd = ref(false);
function getList() {
chatCouponApi.chatCouponRecord({ ...query, id: options.id }).then((res) => {
if (query.page == 1) {
list.value = res.records;
} else {
list.value.push(...res.records);
}
isEnd.value = query.page >= res.totalPage * 1;
});
}
onReachBottom(() => {
if (!isEnd.value) {
query.page++;
getList();
}
});
onLoad((opt) => {
Object.assign(options, opt);
const item = uni.getStorageSync("cach_couponActivity");
couponActivity.value = item || {};
console.log(item);
getList();
});
</script>
<style lang="scss" scoped>
.default-box {
padding: 24rpx 28rpx;
}
.select {
padding: 20rpx;
border-radius: 8rpx;
border: 2rpx solid #d9d9d9;
min-width: 322rpx;
display: flex;
justify-content: space-between;
}
.table{
.user{
width: 142rpx;
}
.gettime{
width: 172rpx;
}
.usetime{
width: 158rpx;
}
.status{
width: 84rpx;
}
.operation{
width: 56rpx;
&.status3{
color: #FF383C;
}
}
.header{
display: flex;
justify-content: space-between;
padding: 32rpx 16rpx;
color: #666;
border-bottom: 1px solid #E5E5E5;
}
.body{
.item{
display: flex;
justify-content: space-between;
padding: 24rpx 16rpx;
border-bottom: 1px solid #E5E5E5;
}
}
}
</style>

View File

@@ -0,0 +1,310 @@
<template>
<view class="min-page bg-f7">
<up-sticky>
<view class="top">
<my-tabs
:list="tabs.list"
v-model="tabs.selIndex"
@change="tabsChange"
textKey="label"
></my-tabs>
</view>
</up-sticky>
<view class="list">
<view class="item" v-for="(item, index) in list" :key="index">
<view class="u-flex u-row-between">
<view>{{ item.couponJson.couponName }}</view>
<view class="u-flex">
<view class="status" :class="['status' + item.status]">{{
returnStateText(item)
}}</view>
<view class="Id">ID:{{ item.id }}</view>
</view>
</view>
<view class="u-m-t-28 desc">
<view class="u-flex">
<text class="color-666 text-right u-m-r-48" style="min-width: 96rpx"
>使用门槛</text
>
<text class="color-333"
>{{ item.couponJson.fullAmount }}元可用</text
>
</view>
<view class="u-flex u-m-t-16">
<text class="color-666 text-right u-m-r-48" style="min-width: 96rpx"
>有效期</text
>
<text class="color-333"
>领券后{{ item.couponJson.validDays }}天过期</text
>
</view>
</view>
<view class="u-flex u-row-between u-m-t-24">
<view
class="u-flex u-flex-col u-row-center u-font-24 u-col-center text-center"
>
<view class="color-333 font-bold">{{ item.giveNum }}</view>
<view class="color-666 u-m-t-16">发放数量</view>
</view>
<view
class="u-flex u-flex-col u-row-center u-font-24 u-col-center text-center"
>
<view class="color-333 font-bold">{{
item.giveNum - item.leftNum
}}</view>
<view class="color-666 u-m-t-16">已领取</view>
</view>
<view
class="u-flex u-flex-col u-row-center u-font-24 u-col-center text-center"
>
<view class="color-333 font-bold">{{ item.leftNum }}</view>
<view class="color-666 u-m-t-16">剩余</view>
</view>
<view
class="u-flex u-flex-col u-row-center u-font-24 u-col-center text-center"
>
<view class="color-333 font-bold">{{ item.useNum }}</view>
<view class="color-666 u-m-t-16">已使用</view>
</view>
</view>
<view class="u-m-t-16 u-flex u-row-right" style="gap: 16rpx">
<view
class="btn share"
@click="toShare(item)"
v-if="item.status == 1"
>
分享</view
>
<view class="btn cancel" @click="cancel(item)">失效</view>
<view class="btn primary" @click="toDetail(item)"> 查看</view>
</view>
</view>
</view>
<up-loadmore :status="isEnd ? 'nomore' : 'loading'"></up-loadmore>
<view style="height: 40px"></view>
</view>
</template>
<script setup>
import * as chatApi from "@/http/php/chat";
import { onReachBottom, onLoad } from "@dcloudio/uni-app";
import { reactive, ref, watch } from "vue";
import { onShow } from "@dcloudio/uni-app";
import go from "@/commons/utils/go.js";
import * as chatCouponApi from "@/http/api/market/chat";
import { useChatStore } from "@/store/chat";
const chatStore = useChatStore();
chatStore.onReceiveMsg = (msg) => {};
chatStore.connectSocket();
function toDetail(item) {
uni.setStorageSync("cach_couponActivity", item);
go.to("PAGES_CHAT_COUPON_ACTIVITY_DETAIL", {
id: item.id,
});
}
const tabs = reactive({
list: [
{
label: "全部",
value: "",
},
{
label: "发放中",
value: 1,
},
{
label: "已失效",
value: 3,
},
],
selIndex: 0,
});
const query = reactive({
page: 1,
size: 10,
});
function cancelChatCoupon(item) {
chatCouponApi.chatCouponExpired(item.id).then((res) => {
if (res) {
uni.showToast({
title: "操作成功",
icon: "none",
});
refresh();
} else {
uni.showToast({
title: "取消失败",
icon: "none",
});
}
});
}
function sendMsg(msg) {
chatStore.sendMessage({
to_id: groupInfo.value.id,
to_user_type: groupInfo.value.id,
chat_type: 2,
content: msg.value,
image_url: "",
order_id: "",
session_id: options.session_id,
...msg,
});
}
function toShare(item) {
sendMsg({
coupon: { ...item.couponJson, title: item.title },
msg_type: 4,
});
uni.navigateBack({
delta: 2,
});
}
const options = reactive({});
const groupInfo = ref({});
onLoad((opt) => {
Object.assign(options, opt);
chatApi
.groupInfo({
group_id: options.group_id,
})
.then((res) => {
groupInfo.value = res || {};
});
});
function cancel(item) {
uni.showModal({
title: "提示",
content: "确定取消该优惠券吗?",
confirmText: "确定",
cancelText: "取消",
success: function (res) {
if (res.confirm) {
cancelChatCoupon(item);
} else if (res.cancel) {
console.log("用户点击取消");
}
},
});
}
function returnStateText(item) {
if (item.status == 1) {
return "发放中";
} else if (item.status == 3) {
return "已失效";
}
}
function tabsChange(e) {
tabs.selIndex = e;
refresh();
}
function refresh() {
query.page = 1;
isEnd.value = false;
init();
}
const list = ref([]);
const isEnd = ref(false);
function init() {
chatCouponApi
.chatCouponPage({ ...query, status: tabs.list[tabs.selIndex].value })
.then((res) => {
console.log(res);
const arr = (res.records || []).map((v) => {
return {
...v,
couponJson: JSON.parse(v.couponJson),
};
});
if (query.page == 1) {
list.value = arr;
} else {
list.value.push(...arr);
}
console.log(list.value);
isEnd.value = query.page >= res.totalPage * 1;
});
}
onReachBottom(() => {
if (!isEnd.value) {
query.page++;
init();
}
});
onShow(init);
</script>
<style scoped lang="scss">
.top {
padding: 20rpx 62rpx;
background-color: #fff;
}
.list {
padding: 32rpx 28rpx;
.item {
padding: 32rpx;
background-color: #fff;
margin-bottom: 28rpx;
.desc {
padding: 32rpx 28rpx;
background: #f8f8f8;
font-size: 24rpx;
}
.status {
padding: 4rpx 12rpx;
border-radius: 8rpx;
font-size: 24rpx;
&.status1 {
color: rgba(52, 199, 89, 1);
background-color: rgba(52, 199, 89, 0.15);
}
&.status3 {
color: #999999;
background-color: rgba(153, 153, 153, 0.15);
}
}
.Id {
padding: 8rpx 6rpx;
margin-left: 36rpx;
font-size: 18rpx;
color: #999;
border-radius: 4rpx;
background-color: #f8f8f8;
}
}
}
.btn {
padding: 8rpx 42rpx;
border-radius: 100rpx;
font-size: 28rpx;
font-weight: 700;
&.cancel {
background-color: #f8f8f8;
color: #999999;
}
&.primary {
background-color: $my-main-color;
color: #fff;
}
&.share {
background-color: #ecf5ff;
color: $my-main-color;
border: 1px solid $my-main-color;
}
}
</style>

View File

@@ -0,0 +1,182 @@
<template>
<view class="min-page bg-f7 u-font-28">
<view class="user-list bg-fff">
<view class="u-flex u-row-between u-col-center">
<text class="color-000">群成员22</text>
<text class="color-red" @click="showRemove = !showRemove">移除</text>
</view>
<view class="list u-m-t-26">
<view
class="u-flex u-flex-col u-row-center u-col-center relative"
v-for="(item, index) in userLists"
:key="index"
>
<up-avatar
size="104rpx"
shape="square"
:src="item.avatar"
round="8rpx"
></up-avatar>
<view class="u-m-t-8 color-000">{{ item.nick_name }}</view>
<view
class="remove u-absolute"
v-if="showRemove && item.role != 1"
@click="removeMember(item)"
>
<up-icon
name="minus-circle-fill"
size="24rpx"
color="#FF2424"
></up-icon>
</view>
</view>
</view>
<view class="u-flex u-row-center color-666 u-m-t-30" v-if="hasMore">
<text class="u-m-r-20">查看更多</text>
<up-icon name="arrow-down" size="24rpx" color="#666"></up-icon>
</view>
</view>
<view class="bottom">
<view class="u-flex u-row-between default-padding bg-fff border-bottom">
<text>群聊名称</text>
<view class="u-flex color-666">
<text>{{ groupInfo.name }}</text>
<up-icon name="arrow-right" size="24rpx" color="#666"></up-icon>
</view>
</view>
<view class="u-flex u-row-between default-padding bg-fff border-bottom">
<view>
<view>禁言</view>
<view class="color-999 u-font-24">
开启后顾客将不能在群内发消息</view
>
</view>
<up-switch
v-model="groupInfo.is_mute"
:active-value="1"
:inactive-value="0"
@change="groupMuteChange"
></up-switch>
</view>
<view
class="u-flex u-row-between default-padding bg-fff"
@click="go.to('PAGES_CHAT_COUPON_ACTIVITY', {
group_id: options.group_id,
session_id: options.session_id,
})"
>
<text>优惠券领取记录</text>
<view class="u-flex color-666">
<text class="color-main">去查看</text>
<up-icon name="arrow-right" size="24rpx" color="#318AFE"></up-icon>
</view>
</view>
</view>
</view>
</template>
<script setup>
import go from "@/commons/utils/go.js";
import * as chatApi from "@/http/php/chat";
import { onShow, onLoad } from "@dcloudio/uni-app";
import { reactive, toRefs, computed, watch, onMounted, ref } from "vue";
const options = reactive({});
const groupInfo = ref({});
onLoad((opt) => {
Object.assign(options, opt);
chatApi
.groupInfo({
group_id: options.group_id,
})
.then((res) => {
groupInfo.value = res || {};
});
});
function groupMuteChange(e) {
if (e) {
chatApi
.groupMute({
group_id: options.group_id,
})
.then((res) => {
if (res) {
uni.showToast({
title: "已禁言",
icon: "none",
});
}
});
return;
}
chatApi
.groupMunute({
group_id: options.group_id,
})
.then((res) => {
if (res) {
uni.showToast({
title: "禁言已取消",
icon: "none",
});
}
});
}
const showRemove = ref(false);
let allUser = [];
const userLists = ref([]);
const hasMore = ref(false);
function getMembers() {
chatApi.groupMembers({ group_id: options.group_id }).then((res) => {
allUser = res.user_list || [];
hasMore.value = allUser.length > 20;
userLists.value = allUser.slice(0, 20);
});
}
onShow(() => {
getMembers();
});
function removeMember(item) {
chatApi
.groupKick({ group_id: options.group_id, target_uid: item.user_id })
.then((res) => {
if (res) {
uni.showToast({
title: "移除成功",
icon: "none",
});
setTimeout(() => {
getMembers();
}, 1000);
}
});
}
</script>
<style lang="scss" scoped>
.user-list {
padding: 32rpx 28rpx;
.list {
gap: 20rpx;
display: grid;
grid-template-columns: repeat(5, 1fr);
}
}
.color-red {
color: #ff2424;
}
.bottom {
margin: 28rpx;
border-radius: 16rpx;
overflow: hidden;
}
.default-padding {
padding: 32rpx 28rpx;
}
.relative {
position: relative;
}
.remove {
top: -6rpx;
right: -6rpx;
}
</style>

223
pageChat/index.vue Normal file
View File

@@ -0,0 +1,223 @@
<template>
<view class="min-page bg-f7 color-333 u-font-28">
<up-sticky>
<view class="top u-flex u-row-between u-col-center">
<view style="width: 420rpx;">
<up-search
v-model="query.key"
placeholder="搜索群名称"
:showAction="false"
@clear="throttleSearch"
@change="throttleSearch"
></up-search>
</view>
<view class="u-flex u-col-center" @click="clearAllmsg">
<text class="color-666 u-m-r-12">清空未读</text>
<image src="/pageChat/static/clear.png" class="clear"></image>
</view>
</view>
</up-sticky>
<view class="list">
<up-swipe-action>
<up-swipe-action-item
:options="options1"
v-for="(item, index) in list"
v-model:show="item.showOptions"
@click="optionsClick($event, item, index)"
:key="item.id"
>
<view class="item u-flex" @click="toDetail(item)">
<view class="u-flex avatar">
<up-avatar
size="118rpx"
:src="item.avatar"
shape="square"
round="8rpx"
></up-avatar>
<view class="bandage" v-if="item.unread_count > 0">{{
item.unread_count >= 99 ? "99" : item.unread_count
}}</view>
</view>
<view class="u-flex-1 u-flex u-row-between u-p-l-14">
<view style="max-width: 364rpx">
<view class="color-000 u-line-1">{{ item.name }}</view>
<view class="u-m-t-28 u-line-1 u-font-24 color-999"
>{{ item.msg }}</view
>
</view>
<view class="color-333 u-font-24">{{ item.send_time }}</view>
</view>
</view>
</up-swipe-action-item>
</up-swipe-action>
</view>
</view>
</template>
<script setup>
import * as chatApi from "@/http/php/chat";
import { ref, reactive } from "vue";
import { onShow } from "@dcloudio/uni-app";
// 使用 reactive 创建响应式对象
const options1 = reactive([
{
text: "删除",
style: {
backgroundColor: "#f56c6c",
color: "#fff",
},
},
]);
function optionsClick(e, item, index) {
if (e.index == 0) {
//删除
chatApi
.sessionlistdel({
session_id: item.session_id,
})
.then((res) => {
if (res) {
uni.showToast({
title: "删除成功",
icon: "none",
duration: 1000,
});
list.value.splice(index, 1);
setTimeout(() => {
getList();
}, 1000);
}
});
}
}
const list = ref([]);
let allList = [];
const query = reactive({
key: "",
});
function throttle(fn, delay) {
let timer = null;
return function (...args) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
fn.apply(this, args);
}, delay);
};
}
//使用节流函数
const throttleSearch = throttle(search, 500);
function search() {
list.value = allList
.filter((v) => v.name.includes(query.key.trim()))
.map((v) => {
return {
...v,
showOptions: false,
};
});
}
async function getList() {
const res = await chatApi.messageSessionList({});
allList = (res.list || []).filter((v) => !v.is_del);
search();
}
async function clearAllmsg() {
uni.showModal({
title: "提示",
content: "确定要清空所有未读消息吗?",
success: async (res) => {
if (res.confirm) {
const res = await chatApi.messageMarkReadAll({
session_ids: list.value.map((v) => v.session_id).join(","),
});
if (res) {
uni.showToast({
title: "清空成功",
icon: "none",
duration: 2000,
});
setTimeout(() => {
getList();
}, 1000);
}
}
},
});
}
function toDetail(item) {
if (!item.is_th) {
return uni.showToast({
title: "你已不在该群内",
icon: "none",
duration: 1500,
});
}
uni.navigateTo({
url:
"/pageChat/chat" +
`?group_id=${item.group_id}&session_id=${item.session_id}`,
});
}
const messageUnreadCount = ref(0);
onShow(() => {
getList();
// 获取未读消息总数
chatApi.messageUnreadCount({}).then((res) => {
console.log(res);
messageUnreadCount.value = res.total;
});
});
</script>
<style lang="scss" scoped>
.top {
padding: 32rpx 28rpx;
background-color: #fff;
}
.clear {
width: 38rpx;
height: 38rpx;
}
.list {
padding: 36rpx 28rpx;
.item {
padding: 32rpx 28rpx;
background-color: #fff;
border-radius: 16rpx;
display: flex;
flex-direction: column;
gap: 16rpx;
.avatar {
position: relative;
.bandage {
position: absolute;
flex-direction: column;
justify-content: center;
align-items: center;
border-radius: 50%;
background: #ff1c1c;
font-size: 24rpx;
color: #ffffff;
width: 38rpx;
height: 38rpx;
text-align: center;
line-height: 38rpx;
right: -10rpx;
top: -10rpx;
}
}
}
}
</style>

BIN
pageChat/static/clear.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
pageChat/static/coupon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
pageChat/static/exit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
pageChat/static/pic.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
pageChat/static/video.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@@ -295,6 +295,22 @@
}
}
]
},
{
"root": "pageChat",
"pages": [{
"path": "index",
"style": {
"navigationBarTitleText": "消息"
}
},
{
"path": "chat",
"style": {
"navigationBarTitleText": "群聊"
}
}
]
}
],
"uniIdRouter": {},

View File

@@ -157,6 +157,7 @@ import { APIusershopInfodetail, APIshopUserInfo } from '@/common/api/member.js';
import { APImemberPointsmyPoints, APImemberPointscalcUsablePoints } from '@/common/api/shop/index.js';
import { useCartsStore } from '@/stores/carts.js';
import { useWebSocket } from '@/stores/carts-websocket.js';
import * as chatApi from "@/http/php/chat";
function pwdClose() {
ispws.value = false;
@@ -977,10 +978,18 @@ const navTitle = computed(() => {
});
//支付成功后的处理
function paySucessCallback() {
async function paySucessCallback() {
console.log('paySucessCallback');
cartsSocket.closeSocket();
showDrainage.value = true;
const groupinfo=await chatApi.groupShopinfo({shop_id:cartStore.shopInfo.id})
if(groupinfo&&groupinfo[0]){
console.log('groupinfo',groupinfo[0].id);
chatApi.groupJoin({
group_id:groupinfo[0].id
})
}
}
//私域引流配置

View File

@@ -281,6 +281,11 @@ const myFunList = ref([
type: "fenxiao",
icon: "/static/icon/fenxiao.svg",
},
{
name: "商家推送",
type: "msg",
icon: "/static/icon/msg.png",
},
// {
// name: "我的订单",
// type: "my_order",
@@ -383,6 +388,9 @@ const clickTo = (item, index) => {
}
let shopId = null;
switch (item.type) {
case "msg":
uni.navigateTo({ url: "/pageChat/index" });
break;
case "my_order":
uni.pro.switchTab("order/index");
break;

BIN
static/icon/msg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

126
stores/chat.js Normal file
View File

@@ -0,0 +1,126 @@
import {
defineStore
} from "pinia";
// import * as shopApi from "@/http/api/shop.js";
// #ifdef H5
const socketUrl = "http://192.168.1.42:2348";
// #endif
// #ifndef H5
const socketUrl = "ws://192.168.1.42:2348";
// #endif
// 聊天
export const useChatStore = defineStore("chat", {
state: () => {
return {
socketUrl,
isConnect: false,
socketTask: null,
onReceiveMsg: () => {},
chatList: [],
};
},
actions: {
init() {
if (!this.isConnect) {
return uni.showToast({
title: "请先连接socket",
icon: "none",
});
}
this.sendMessage({
type: "OnbocChat",
operate_type: "init",
shop_id: uni.cache.get('shopInfo').id || '',
token: uni.cache.get('token'),
},
false
);
},
sendMessage(msg, isAutoAppend = true) {
if (!this.isConnect) {
return uni.showToast({
title: "请先连接socket",
icon: "none",
});
}
console.log(this.socketTask);
const message = isAutoAppend ? {
type: "OnbocChat",
operate_type: "sendMsg",
shop_id: uni.cache.get('shopInfo').id || '',
token: uni.cache.get('token'),
...msg,
} :
msg;
this.socketTask.send({
data: JSON.stringify(message),
success: (res) => {
console.log("发送成功", message);
},
fail: (error) => {
console.log("发送失败", error);
},
});
},
connectSocket() {
this.socketTask = uni.connectSocket({
url: socketUrl,
success: (res) => {},
fail: (res) => {
console.log(res);
},
});
this.socketTask.onOpen((res) => {
this.isConnect = true;
this.init();
});
this.socketTask.onMessage((res) => {
const data = JSON.parse(res.data);
console.log("收到服务器消息", data);
if (data.msg) {
uni.showToast({
title: data.msg,
icon: "none",
});
}
if (data && data.operate_type == "sendMsg") {
this.chatList.unshift(data.data);
this.onReceiveMsg(data.data);
console.log(this.chatList);
}
if (data && data.operate_type == "receive_msg") {
const msg={
...data.data,
coupon:data.data.coupon?JSON.parse(data.data.coupon):{},
operate_type:"receive_msg",
}
this.chatList.unshift(msg);
this.onReceiveMsg(msg);
console.log(this.chatList);
}
});
this.socketTask.onError((res) => {
this.isConnect = false;
console.log("连接错误", res);
});
this.socketTask.onClose(() => {
this.isConnect = false;
console.log("连接已关闭");
this.connectSocket();
});
},
closeSocket() {
this.socketTask.close();
this.isConnect = false;
},
},
unistorage: false, // 开启后对 state 的数据读写都将持久化
});