import { getMsgDet, sendMsg, getNewMsgDet } from "~/api/message" import { createStoreBindings } from 'mobx-miniprogram-bindings' import { store } from '~/store/index' const app = getApp() Page({ data: { targetUid: '', value: '', list: [], totalSize: 0, isIos: app.globalData.isIOS, uid: wx.getStorageSync('uid') }, onLoad(options) { console.log(options); wx.setNavigationBarTitle({ title: options.title, }) this.setData({ targetUid: options.uid }) this.storeBindings = createStoreBindings(this, { store, fields: { userInfo: 'userInfo' }, }) this.storeBindings.updateStoreBindings() this.getMsgDet() this.getNewMsgDet() }, async getMsgDet() { let data = await getMsgDet({ senderUid: this.data.targetUid, pageNo: 1, pageSize: 10 }) let { list, totalSize } = data this.setData({ list, totalSize }) console.log('就列表', data); }, async getNewMsgDet() { let res = await getNewMsgDet({ senderUid: this.data.targetUid, }) let newList = [...this.data.list, ...res] console.log(newList); /* this.setData({ list: newList }) */ }, async sendReply() { if (!this.data.value) { return } await sendMsg({ content: this.data.value, receiverUid: this.data.targetUid }) this.setData({ value: '' }) this.getNewMsgDet() }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { console.log('1'); }, chooseImage() { wx.chooseImage({ count: 1, // 可选择的图片数量 sizeType: ['compressed'], // 压缩图片 sourceType: ['album', 'camera'], // 来源:相册或相机 success: (res) => { // 将选择的图片上传到服务器 console.log(res); this.uploadImage(res.tempFilePaths[0]); } }) }, uploadImage(imagePath) { wx.uploadFile({ url: 'https://reader-api.ai160.com/file/upload', filePath: imagePath, name: '朗读录音', header: { uid: wx.getStorageSync('uid') }, success: async (res) => { console.log(res.data); await sendMsg({ content: JSON.parse(res.data).data, receiverUid: this.data.targetUid }) this.getNewMsgDet() } }) }, bindKeyInput(e) { this.setData({ value: e.detail.value }) }, jumpUserInfo({ currentTarget }) { wx.navigateTo({ url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`, }) }, })