Claw 项目完整结构提交
This commit is contained in:
163
Claw/client/wechat_app/components/message/message.js
Normal file
163
Claw/client/wechat_app/components/message/message.js
Normal file
@@ -0,0 +1,163 @@
|
||||
// 消息组件逻辑
|
||||
Component({
|
||||
properties: {
|
||||
// 消息内容
|
||||
content: {
|
||||
type: String,
|
||||
value: ''
|
||||
},
|
||||
// 消息类型
|
||||
type: {
|
||||
type: String,
|
||||
value: 'text'
|
||||
},
|
||||
// 发送者头像
|
||||
avatar: {
|
||||
type: String,
|
||||
value: '/assets/images/default-avatar.png'
|
||||
},
|
||||
// 发送者昵称
|
||||
nickname: {
|
||||
type: String,
|
||||
value: '未知用户'
|
||||
},
|
||||
// 发送时间
|
||||
time: {
|
||||
type: String,
|
||||
value: ''
|
||||
},
|
||||
// 是否是自己发送的消息
|
||||
isMe: {
|
||||
type: Boolean,
|
||||
value: false
|
||||
},
|
||||
// 文件名(文件消息)
|
||||
fileName: {
|
||||
type: String,
|
||||
value: ''
|
||||
},
|
||||
// 文件大小(文件消息)
|
||||
fileSize: {
|
||||
type: String,
|
||||
value: ''
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
// 预览图片
|
||||
previewImage() {
|
||||
if (this.properties.type === 'image') {
|
||||
wx.previewImage({
|
||||
urls: [this.properties.content],
|
||||
current: this.properties.content
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 下载文件
|
||||
downloadFile() {
|
||||
if (this.properties.type === 'file') {
|
||||
wx.showLoading({
|
||||
title: '下载中...'
|
||||
})
|
||||
|
||||
wx.downloadFile({
|
||||
url: this.properties.content,
|
||||
success: (res) => {
|
||||
wx.hideLoading()
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
// 保存文件到本地
|
||||
wx.saveFile({
|
||||
tempFilePath: res.tempFilePath,
|
||||
success: (saveRes) => {
|
||||
wx.showToast({
|
||||
title: '文件已保存',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 打开文件
|
||||
wx.openDocument({
|
||||
filePath: saveRes.savedFilePath,
|
||||
showMenu: true
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({
|
||||
title: '保存失败',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '下载失败',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.hideLoading()
|
||||
wx.showToast({
|
||||
title: '下载失败',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 长按消息
|
||||
onLongPress() {
|
||||
wx.showActionSheet({
|
||||
itemList: ['复制', '转发', '删除'],
|
||||
success: (res) => {
|
||||
switch (res.tapIndex) {
|
||||
case 0: // 复制
|
||||
this.copyMessage()
|
||||
break
|
||||
case 1: // 转发
|
||||
this.forwardMessage()
|
||||
break
|
||||
case 2: // 删除
|
||||
this.deleteMessage()
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 复制消息
|
||||
copyMessage() {
|
||||
if (this.properties.type === 'text') {
|
||||
wx.setClipboardData({
|
||||
data: this.properties.content,
|
||||
success: () => {
|
||||
wx.showToast({
|
||||
title: '已复制',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 转发消息
|
||||
forwardMessage() {
|
||||
this.triggerEvent('forward', {
|
||||
content: this.properties.content,
|
||||
type: this.properties.type,
|
||||
fileName: this.properties.fileName,
|
||||
fileSize: this.properties.fileSize
|
||||
})
|
||||
},
|
||||
|
||||
// 删除消息
|
||||
deleteMessage() {
|
||||
this.triggerEvent('delete', {
|
||||
content: this.properties.content,
|
||||
type: this.properties.type
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
3
Claw/client/wechat_app/components/message/message.json
Normal file
3
Claw/client/wechat_app/components/message/message.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"component": true
|
||||
}
|
||||
20
Claw/client/wechat_app/components/message/message.wxml
Normal file
20
Claw/client/wechat_app/components/message/message.wxml
Normal file
@@ -0,0 +1,20 @@
|
||||
<!-- 消息组件 -->
|
||||
<view class="message-item {{isMe ? 'message-right' : 'message-left'}}">
|
||||
<view class="message-avatar">
|
||||
<image src="{{avatar}}" mode="aspectFill"></image>
|
||||
</view>
|
||||
<view class="message-content">
|
||||
<view class="message-header">
|
||||
<text class="message-nickname">{{nickname}}</text>
|
||||
<text class="message-time">{{time}}</text>
|
||||
</view>
|
||||
<view class="message-body">
|
||||
<text class="message-text" wx:if="{{type === 'text'}}">{{content}}</text>
|
||||
<image class="message-image" wx:if="{{type === 'image'}}" src="{{content}}" mode="widthFix" bindtap="previewImage"></image>
|
||||
<view class="message-file" wx:if="{{type === 'file'}}" bindtap="downloadFile">
|
||||
<text class="file-name">{{fileName}}</text>
|
||||
<text class="file-size">{{fileSize}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
98
Claw/client/wechat_app/components/message/message.wxss
Normal file
98
Claw/client/wechat_app/components/message/message.wxss
Normal file
@@ -0,0 +1,98 @@
|
||||
/* 消息组件样式 */
|
||||
.message-item {
|
||||
display: flex;
|
||||
margin: 20rpx 0;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.message-left {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.message-right {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
|
||||
.message-avatar {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
margin: 0 20rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.message-avatar image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
max-width: 70%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.message-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.message-nickname {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
|
||||
.message-time {
|
||||
font-size: 20rpx;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.message-body {
|
||||
background-color: #f0f0f0;
|
||||
border-radius: 10rpx;
|
||||
padding: 20rpx;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.message-right .message-body {
|
||||
background-color: #95ec69;
|
||||
}
|
||||
|
||||
.message-text {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.message-right .message-text {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.message-image {
|
||||
max-width: 300rpx;
|
||||
max-height: 300rpx;
|
||||
border-radius: 10rpx;
|
||||
}
|
||||
|
||||
.message-file {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #fff;
|
||||
border: 1rpx solid #e0e0e0;
|
||||
border-radius: 10rpx;
|
||||
padding: 20rpx;
|
||||
min-width: 200rpx;
|
||||
}
|
||||
|
||||
.file-name {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
Reference in New Issue
Block a user