123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- 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`,
- })
- },
- })
|