Initial commit
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
// pages/message/detail/index.js
|
||||
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,
|
||||
},
|
||||
|
||||
// 监听输入框内容变化
|
||||
onInput(e) {
|
||||
this.setData({
|
||||
inputContent: e.detail.value
|
||||
});
|
||||
},
|
||||
|
||||
// 发送消息
|
||||
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}`
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 预览图片
|
||||
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
|
||||
});
|
||||
},
|
||||
|
||||
// 格式化时间
|
||||
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() {
|
||||
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<!--pages/message/detail/index.wxml-->
|
||||
<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>
|
||||
</view>
|
||||
@@ -0,0 +1,145 @@
|
||||
/* pages/message/detail/index.wxss */
|
||||
.message-detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.service-info {
|
||||
padding: 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
border-bottom: 1rpx solid #eee;
|
||||
}
|
||||
|
||||
.service-info .avatar {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 50%;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.service-info .nickname {
|
||||
font-size: 32rpx;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.message-list {
|
||||
flex: 1;
|
||||
padding: 20rpx;
|
||||
background: var(--bg-page);
|
||||
}
|
||||
|
||||
.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;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.message-item.self .bubble {
|
||||
background: #07c160;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.message-item .msg-image {
|
||||
max-width: 100%;
|
||||
border-radius: 10rpx;
|
||||
}
|
||||
|
||||
.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