index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import {
  2. getMsgDet,
  3. sendMsg,
  4. getNewMsgDet
  5. } from "~/api/message"
  6. import {
  7. createStoreBindings
  8. } from 'mobx-miniprogram-bindings'
  9. import {
  10. store
  11. } from '~/store/index'
  12. const app = getApp()
  13. Page({
  14. data: {
  15. targetUid: '',
  16. value: '',
  17. list: [],
  18. totalSize: 0,
  19. isIos: app.globalData.isIOS,
  20. uid: wx.getStorageSync('uid')
  21. },
  22. onLoad(options) {
  23. console.log(options);
  24. wx.setNavigationBarTitle({
  25. title: options.title,
  26. })
  27. this.setData({
  28. targetUid: options.uid
  29. })
  30. this.storeBindings = createStoreBindings(this, {
  31. store,
  32. fields: {
  33. userInfo: 'userInfo'
  34. },
  35. })
  36. this.storeBindings.updateStoreBindings()
  37. this.getMsgDet()
  38. this.getNewMsgDet()
  39. },
  40. async getMsgDet() {
  41. let data = await getMsgDet({
  42. senderUid: this.data.targetUid,
  43. pageNo: 1,
  44. pageSize: 10
  45. })
  46. let {
  47. list,
  48. totalSize
  49. } = data
  50. this.setData({
  51. list,
  52. totalSize
  53. })
  54. console.log('就列表', data);
  55. },
  56. async getNewMsgDet() {
  57. let res = await getNewMsgDet({
  58. senderUid: this.data.targetUid,
  59. })
  60. let newList = [...this.data.list, ...res]
  61. console.log(newList);
  62. /* this.setData({
  63. list: newList
  64. }) */
  65. },
  66. async sendReply() {
  67. if (!this.data.value) {
  68. return
  69. }
  70. await sendMsg({
  71. content: this.data.value,
  72. receiverUid: this.data.targetUid
  73. })
  74. this.setData({
  75. value: ''
  76. })
  77. this.getNewMsgDet()
  78. },
  79. /**
  80. * 页面相关事件处理函数--监听用户下拉动作
  81. */
  82. onPullDownRefresh() {
  83. console.log('1');
  84. },
  85. chooseImage() {
  86. wx.chooseImage({
  87. count: 1, // 可选择的图片数量
  88. sizeType: ['compressed'], // 压缩图片
  89. sourceType: ['album', 'camera'], // 来源:相册或相机
  90. success: (res) => {
  91. // 将选择的图片上传到服务器
  92. console.log(res);
  93. this.uploadImage(res.tempFilePaths[0]);
  94. }
  95. })
  96. },
  97. uploadImage(imagePath) {
  98. wx.uploadFile({
  99. url: 'https://reader-api.ai160.com/file/upload',
  100. filePath: imagePath,
  101. name: '朗读录音',
  102. header: {
  103. uid: wx.getStorageSync('uid')
  104. },
  105. success: async (res) => {
  106. console.log(res.data);
  107. await sendMsg({
  108. content: JSON.parse(res.data).data,
  109. receiverUid: this.data.targetUid
  110. })
  111. this.getNewMsgDet()
  112. }
  113. })
  114. },
  115. bindKeyInput(e) {
  116. this.setData({
  117. value: e.detail.value
  118. })
  119. },
  120. jumpUserInfo({
  121. currentTarget
  122. }) {
  123. wx.navigateTo({
  124. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  125. })
  126. },
  127. })