wewew
This commit is contained in:
parent
7477992bc7
commit
1b61e3de12
@ -260,21 +260,16 @@ Page({
|
|||||||
if (!text) return;
|
if (!text) return;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const id = 'u' + Date.now();
|
const id = 'u' + Date.now();
|
||||||
const timeStr = this.formatTime(now);
|
// const timeStr = this.formatTime(now);
|
||||||
// 判断是否需要显示时间分割线
|
// // 判断是否需要显示时间分割线
|
||||||
let showTime = false;
|
// let showTime = false;
|
||||||
const lastMsg = this.data.messages.length ? this.data.messages[this.data.messages.length - 1] : null;
|
// const lastMsg = this.data.messages.length ? this.data.messages[this.data.messages.length - 1] : null;
|
||||||
if (!lastMsg || now - (lastMsg._ts || now) > 5 * 60 * 1000) showTime = true;
|
// if (!lastMsg || now - (lastMsg._ts || now) > 5 * 60 * 1000) showTime = true;
|
||||||
const msg = {
|
const msg = {
|
||||||
id,
|
id,
|
||||||
from: 'user',
|
|
||||||
type: 'text',
|
|
||||||
content: {
|
content: {
|
||||||
messages: text
|
messages: text
|
||||||
},
|
},
|
||||||
showTime,
|
|
||||||
timeStr,
|
|
||||||
_ts: now,
|
|
||||||
"msg_type": 1,
|
"msg_type": 1,
|
||||||
receiver_id: '',
|
receiver_id: '',
|
||||||
send_time: "刚刚",
|
send_time: "刚刚",
|
||||||
@ -327,34 +322,37 @@ Page({
|
|||||||
chooseImage() {
|
chooseImage() {
|
||||||
const that = this;
|
const that = this;
|
||||||
wx.chooseImage({
|
wx.chooseImage({
|
||||||
count: 1,
|
count: 1, // 选择图片的数量
|
||||||
|
mediaType: ['image'], // 仅选择图片
|
||||||
sizeType: ['compressed', 'original'],
|
sizeType: ['compressed', 'original'],
|
||||||
sourceType: ['album', 'camera'],
|
sourceType: ['album', 'camera'],
|
||||||
success(res) {
|
success(res) {
|
||||||
const tempFilePaths = res.tempFilePaths;
|
const tempFilePaths = res.tempFilePaths;
|
||||||
console.log('选择的图片路径:', res);
|
console.log('选择的图片路径:', res);
|
||||||
if (tempFilePaths && tempFilePaths.length) {
|
if (tempFilePaths && tempFilePaths.length) {
|
||||||
const now = new Date();
|
const userInfo = wx.getStorageSync('user_info')
|
||||||
|
// const now = new Date();
|
||||||
const id = 'u' + Date.now();
|
const id = 'u' + Date.now();
|
||||||
const timeStr = that.formatTime(now);
|
// const timeStr = that.formatTime(now);
|
||||||
let showTime = false;
|
// let showTime = false;
|
||||||
const lastMsg = that.data.messages.length ? that.data.messages[that.data.messages.length - 1] : null;
|
// const lastMsg = that.data.messages.length ? that.data.messages[that.data.messages.length - 1] : null;
|
||||||
if (!lastMsg || now - (lastMsg._ts || now) > 5 * 60 * 1000) showTime = true;
|
// if (!lastMsg || now - (lastMsg._ts || now) > 5 * 60 * 1000) showTime = true;
|
||||||
const msg = {
|
const msg = {
|
||||||
id,
|
id,
|
||||||
from: 'user',
|
|
||||||
msg_type: '2',
|
msg_type: '2',
|
||||||
|
receiver_id: '',
|
||||||
content: {
|
content: {
|
||||||
messages: tempFilePaths[0]
|
messages: tempFilePaths[0]
|
||||||
},
|
},
|
||||||
showTime,
|
sender_id: userInfo.openid,
|
||||||
timeStr,
|
sender_name: userInfo.user_name,
|
||||||
_ts: now,
|
receiver_id: '',
|
||||||
sender_id: that.data.userInfo.openid,
|
send_time: "刚刚",
|
||||||
sender_name: that.data.userInfo.user_name
|
|
||||||
};
|
};
|
||||||
|
const list = that.data.messages
|
||||||
|
list.push(msg);
|
||||||
that.setData({
|
that.setData({
|
||||||
messages: that.data.messages.concat(msg)
|
messages: list
|
||||||
});
|
});
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
that.setData({
|
that.setData({
|
||||||
@ -362,6 +360,30 @@ Page({
|
|||||||
});
|
});
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
|
wx.uploadFile({
|
||||||
|
filePath: tempFilePaths[0], // 图片临时文件路径
|
||||||
|
name: 'file', // 服务器接收文件的字段名,需与后端对应
|
||||||
|
url: 'https://mini-chat.1024tool.vip/admin/upload/image', // 服务器接收图片的接口地址
|
||||||
|
success: (res) => {
|
||||||
|
const data = JSON.parse(res.data);
|
||||||
|
console.log('上传成功', data);
|
||||||
|
const accountInfo = wx.getAccountInfoSync();
|
||||||
|
|
||||||
|
request('app/send_message', 'POST', {
|
||||||
|
"app_id": accountInfo.miniProgram.appId,
|
||||||
|
"content": JSON.stringify({
|
||||||
|
messages: 'https://mini-chat.1024tool.vip/'+ data.preview_image_url
|
||||||
|
}),
|
||||||
|
"from_user_id": userInfo.openid,
|
||||||
|
"from_user_name": userInfo.user_name,
|
||||||
|
"msg_type": 2
|
||||||
|
})
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('上传失败', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 模拟客服返回图片确认
|
// 模拟客服返回图片确认
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
// const replyNow = new Date();
|
// const replyNow = new Date();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user