index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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, this.data.userInfo);
  55. },
  56. async getNewMsgDet() {
  57. let res = await getNewMsgDet({
  58. senderUid: this.data.targetUid,
  59. })
  60. console.log(res);
  61. },
  62. async sendReply() {
  63. if (!this.data.value) {
  64. return
  65. }
  66. await sendMsg({
  67. content: this.data.value,
  68. receiverUid: this.data.targetUid
  69. })
  70. },
  71. chooseImage() {
  72. wx.chooseImage({
  73. count: 1, // 可选择的图片数量
  74. sizeType: ['compressed'], // 压缩图片
  75. sourceType: ['album', 'camera'], // 来源:相册或相机
  76. success: (res) => {
  77. // 将选择的图片上传到服务器
  78. this.uploadImage(res.tempFilePaths[0]);
  79. }
  80. })
  81. },
  82. uploadImage(imagePath) {
  83. wx.uploadFile({
  84. url: 'https://reader-api.ai160.com/file/upload',
  85. filePath: imagePath,
  86. header: {
  87. uid: wx.getStorageSync('uid')
  88. },
  89. success: (res) => {
  90. console.log(res.data);
  91. }
  92. })
  93. },
  94. bindKeyInput(e) {
  95. this.setData({
  96. value: e.detail.value
  97. })
  98. },
  99. jumpUserInfo({
  100. currentTarget
  101. }) {
  102. wx.navigateTo({
  103. url: `/pages/personal/index?uid=${currentTarget.dataset.uid}&type=user`,
  104. })
  105. },
  106. })