发货方式优化及消息功能优化
This commit is contained in:
@@ -1,176 +1,82 @@
|
||||
// pages/message/detail/index.js
|
||||
import { fetchMessageDetail, messageSetRead } from '../../../services/message/fetchMessage';
|
||||
|
||||
// tabBar 页面(与 app.json 的 tabBar.list 保持一致):
|
||||
// navigateTo 无法跳转 tab 页,必须用 switchTab;而 switchTab 不支持带参数
|
||||
const TAB_PAGES = [
|
||||
'pages/home/home',
|
||||
'pages/goods/list/index',
|
||||
'pages/message/list/index',
|
||||
'pages/usercenter/index',
|
||||
];
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
// 客服信息
|
||||
serviceAvatar: '/assets/images/contact.png',
|
||||
serviceNickname: '在线客服',
|
||||
inputContent: '',
|
||||
// 消息列表
|
||||
messageList: [{
|
||||
id: 1,
|
||||
type: 'text',
|
||||
content: '您好,请问有什么可以帮您?',
|
||||
time: '12:30',
|
||||
avatar: '/assets/image/contact.png',
|
||||
isSelf: false
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
type: 'text',
|
||||
content: '我想咨询一下订单问题',
|
||||
time: '12:31',
|
||||
avatar: '/assets/image/default_avatar_big.png',
|
||||
isSelf: true
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
type: 'text',
|
||||
content: '好的,请问是哪个订单呢?',
|
||||
time: '12:31',
|
||||
avatar: '/assets/image/contact.png',
|
||||
isSelf: false
|
||||
}
|
||||
],
|
||||
scrollToMessage: '', // 用于消息定位
|
||||
|
||||
// 输入相关
|
||||
inputContent: '',
|
||||
showEmoji: false,
|
||||
id: 0,
|
||||
detail: null,
|
||||
jumpPage: '',
|
||||
loading: true,
|
||||
},
|
||||
|
||||
// 监听输入框内容变化
|
||||
onInput(e) {
|
||||
this.setData({
|
||||
inputContent: e.detail.value
|
||||
onLoad(options) {
|
||||
const id = options?.id || 0;
|
||||
this.setData({ id });
|
||||
// 页面标题用消息标题,onLoad 阶段先给默认值
|
||||
wx.setNavigationBarTitle({
|
||||
title: '消息详情'
|
||||
});
|
||||
this.loadDetail();
|
||||
},
|
||||
|
||||
// 发送消息
|
||||
sendMessage() {
|
||||
if (!this.data.inputContent.trim()) return;
|
||||
|
||||
const newMessage = {
|
||||
id: Date.now(), // 使用时间戳作为临时ID
|
||||
type: 'text',
|
||||
content: this.data.inputContent,
|
||||
isSelf: true,
|
||||
avatar: '你的默认头像URL',
|
||||
time: this.formatTime(new Date())
|
||||
};
|
||||
|
||||
this.setData({
|
||||
messageList: [...this.data.messageList, newMessage],
|
||||
inputContent: '', // 清空输入框
|
||||
scrollToMessage: `msg-${newMessage.id}` // 滚动到最新消息
|
||||
});
|
||||
},
|
||||
|
||||
// 选择图片
|
||||
chooseImage() {
|
||||
wx.chooseMedia({
|
||||
count: 1,
|
||||
mediaType: ['image'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: (res) => {
|
||||
const tempFilePath = res.tempFiles[0].tempFilePath;
|
||||
const newMessage = {
|
||||
id: Date.now(),
|
||||
type: 'image',
|
||||
content: tempFilePath,
|
||||
isSelf: true,
|
||||
avatar: '你的默认头像URL',
|
||||
time: this.formatTime(new Date())
|
||||
};
|
||||
|
||||
this.setData({
|
||||
messageList: [...this.data.messageList, newMessage],
|
||||
scrollToMessage: `msg-${newMessage.id}`
|
||||
loadDetail() {
|
||||
fetchMessageDetail(this.data.id).then((res) => {
|
||||
const detail = res.data || null;
|
||||
const jumpPage = String(detail?.extra_json?.page || '');
|
||||
this.setData({
|
||||
detail,
|
||||
jumpPage,
|
||||
loading: false
|
||||
});
|
||||
if (detail?.title) {
|
||||
wx.setNavigationBarTitle({
|
||||
title: detail.title
|
||||
});
|
||||
}
|
||||
// 进入即标记已读
|
||||
if (detail && !detail.is_read) {
|
||||
messageSetRead({ id: this.data.id }).then(() => {
|
||||
this.setData({ 'detail.is_read': 1 });
|
||||
}).catch(() => {});
|
||||
}
|
||||
}).catch(() => {
|
||||
this.setData({ loading: false });
|
||||
});
|
||||
},
|
||||
|
||||
// 预览图片
|
||||
previewImage(e) {
|
||||
const current = e.currentTarget.dataset.src;
|
||||
const urls = this.data.messageList
|
||||
.filter(msg => msg.type === 'image')
|
||||
.map(msg => msg.content);
|
||||
|
||||
wx.previewImage({
|
||||
current,
|
||||
urls
|
||||
// 前往消息关联的业务页面
|
||||
onJumpTap() {
|
||||
const jumpPage = String(this.data.jumpPage || '').replace(/^\//, '');
|
||||
if (!jumpPage) {
|
||||
return;
|
||||
}
|
||||
const pathname = jumpPage.split('?')[0];
|
||||
//tabBar 页只能 switchTab(不支持带参数),其余走 navigateTo
|
||||
if (TAB_PAGES.indexOf(pathname) !== -1) {
|
||||
wx.switchTab({
|
||||
url: '/' + pathname,
|
||||
fail: () => {
|
||||
wx.showToast({ title: '页面跳转失败', icon: 'none' });
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
wx.navigateTo({
|
||||
url: '/' + jumpPage,
|
||||
fail: () => {
|
||||
wx.showToast({ title: '页面跳转失败', icon: 'none' });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 格式化时间
|
||||
formatTime(date) {
|
||||
const hour = date.getHours().toString().padStart(2, '0');
|
||||
const minute = date.getMinutes().toString().padStart(2, '0');
|
||||
return `${hour}:${minute}`;
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
// 设置页面标题为客服名称
|
||||
wx.setNavigationBarTitle({
|
||||
title: this.serviceNickname
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
}
|
||||
})
|
||||
onShareAppMessage() { }
|
||||
});
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
{
|
||||
"navigationBarTitleText": "消息详情",
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon"
|
||||
"t-tag": "tdesign-miniprogram/tag/tag",
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-empty": "tdesign-miniprogram/empty/empty",
|
||||
"t-loading": "tdesign-miniprogram/loading/loading"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
<!--pages/message/detail/index.wxml-->
|
||||
<wxs src="./index.wxs" module="_index" />
|
||||
<view class="message-detail">
|
||||
<!-- 聊天记录区域 -->
|
||||
<scroll-view class="message-list" scroll-y scroll-into-view="{{scrollToMessage}}" enable-flex scroll-anchoring="{{true}}">
|
||||
<view wx:for="{{messageList}}" wx:key="id" class="message-item {{item.isSelf ? 'self' : 'other'}}" id="msg-{{item.id}}">
|
||||
<image class="avatar" src="{{item.avatar}}" />
|
||||
<view class="content">
|
||||
<view class="bubble">
|
||||
<text wx:if="{{item.type === 'text'}}">{{item.content}}</text>
|
||||
<image wx:if="{{item.type === 'image'}}" class="msg-image" src="{{item.content}}" mode="widthFix" bindtap="previewImage" data-src="{{item.content}}" />
|
||||
</view>
|
||||
<text class="time">{{item.time}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 底部输入区域 -->
|
||||
<view class="input-area">
|
||||
<view class="input-box">
|
||||
<view class="tool-item" bindtap="chooseImage">
|
||||
<t-icon name="image" size="48rpx" />
|
||||
</view>
|
||||
<textarea class="input" value="{{inputContent}}" placeholder="请输入消息" auto-height cursor-spacing="20" maxlength="500" bindinput="onInput" adjust-position="{{false}}" />
|
||||
<view class="send-btn {{inputContent ? 'active' : ''}}" bindtap="sendMessage">
|
||||
发送
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{loading}}" class="detail-loading">
|
||||
<t-loading theme="circular" size="40rpx" text="加载中..." />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<block wx:elif="{{detail}}">
|
||||
<view class="detail-card">
|
||||
<view class="detail-header">
|
||||
<text class="detail-title">{{detail.title}}</text>
|
||||
<t-tag size="small" variant="light" theme="{{_index.tagTheme(detail.message_type)}}">{{detail.message_type_text}}</t-tag>
|
||||
</view>
|
||||
<view class="detail-time">{{detail.createtime_text}}</view>
|
||||
<view class="detail-content">{{detail.content}}</view>
|
||||
</view>
|
||||
|
||||
<!-- 有跳转页面时才展示入口:不想前往可直接返回,不会被强制跳转 -->
|
||||
<view class="detail-actions" wx:if="{{jumpPage}}">
|
||||
<t-button theme="primary" size="large" block bind:tap="onJumpTap">前往查看</t-button>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view wx:else class="detail-empty">
|
||||
<t-empty icon="chat-bubble-error" description="消息不存在或已被删除" />
|
||||
</view>
|
||||
|
||||
</view>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// 消息类型对应的标签主题色:0=系统消息(蓝),1=公告消息(橙),2=需求消息(绿)
|
||||
function tagTheme(type) {
|
||||
var map = {
|
||||
'0': 'primary',
|
||||
'1': 'warning',
|
||||
'2': 'success'
|
||||
};
|
||||
return map[String(type)] || 'default';
|
||||
}
|
||||
module.exports = {
|
||||
tagTheme: tagTheme
|
||||
}
|
||||
@@ -1,145 +1,64 @@
|
||||
/* pages/message/detail/index.wxss */
|
||||
.message-detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
min-height: 100vh;
|
||||
padding: 24rpx;
|
||||
box-sizing: border-box;
|
||||
background: var(--bg-page);
|
||||
}
|
||||
|
||||
.service-info {
|
||||
padding: 20rpx;
|
||||
.detail-loading {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding-top: 120rpx;
|
||||
}
|
||||
|
||||
.detail-card {
|
||||
background: var(--bg-card);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 32rpx;
|
||||
box-shadow: var(--shadow-card);
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
border-bottom: 1rpx solid #eee;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.service-info .avatar {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 50%;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.service-info .nickname {
|
||||
font-size: 32rpx;
|
||||
.detail-title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin-right: 16rpx;
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
line-height: 48rpx;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.message-list {
|
||||
flex: 1;
|
||||
padding: 20rpx;
|
||||
background: var(--bg-page);
|
||||
.detail-time {
|
||||
margin-top: 12rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 36rpx;
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
|
||||
.message-item {
|
||||
display: flex;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.message-item.self {
|
||||
flex-direction: row-reverse;
|
||||
padding-right: 20rpx;
|
||||
}
|
||||
|
||||
.message-item .avatar {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.message-item .content {
|
||||
max-width: 60%;
|
||||
margin: 0 20rpx;
|
||||
}
|
||||
|
||||
.message-item .bubble {
|
||||
padding: 20rpx;
|
||||
border-radius: 10rpx;
|
||||
background: #fff;
|
||||
/* 正文:保留换行,长内容自然撑开页面滚动 */
|
||||
.detail-content {
|
||||
margin-top: 24rpx;
|
||||
padding-top: 24rpx;
|
||||
border-top: 1rpx solid var(--component-stroke, #eee);
|
||||
font-size: 28rpx;
|
||||
line-height: 44rpx;
|
||||
color: var(--text-secondary);
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.message-item.self .bubble {
|
||||
background: #07c160;
|
||||
color: #fff;
|
||||
/* 底部操作区:仅在需要跳转时出现 */
|
||||
.detail-actions {
|
||||
margin-top: 40rpx;
|
||||
}
|
||||
|
||||
.message-item .msg-image {
|
||||
max-width: 100%;
|
||||
border-radius: 10rpx;
|
||||
.detail-empty {
|
||||
padding-top: 200rpx;
|
||||
}
|
||||
|
||||
.message-item .time {
|
||||
font-size: 24rpx;
|
||||
color: var(--text-tertiary);
|
||||
margin-top: 10rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.input-area {
|
||||
background: #fff;
|
||||
border-top: 1rpx solid #eee;
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
position: fixed; bottom: 0; left: 0; right: 0;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
padding: 20rpx;
|
||||
border-bottom: 1rpx solid #eee;
|
||||
}
|
||||
|
||||
.tool-item {
|
||||
margin-right: 15rpx;
|
||||
}
|
||||
|
||||
.input-box {
|
||||
display: flex;
|
||||
padding: 20rpx;
|
||||
align-items: flex-end;
|
||||
justify-content: center; align-items: center;
|
||||
}
|
||||
|
||||
.input {
|
||||
flex: 1;
|
||||
background: var(--bg-page);
|
||||
border-radius: 8rpx;
|
||||
padding: 20rpx;
|
||||
min-height: 40rpx;
|
||||
max-height: 120rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.send-btn {
|
||||
width: 120rpx;
|
||||
height: 64rpx;
|
||||
line-height: 64rpx;
|
||||
text-align: center;
|
||||
background: #ddd;
|
||||
color: #fff;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.send-btn.active {
|
||||
background: #07c160;
|
||||
}
|
||||
|
||||
.emoji-panel {
|
||||
height: 400rpx;
|
||||
background: #fff;
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.emoji-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.emoji-item {
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
font-size: 40rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
Reference in New Issue
Block a user