chat-input.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // chat.js
  2. import Toast from "../../utils/toast";
  3. let chatInput = require('../../modules/chat-input/chat-input');
  4. /**
  5. * 聊天输入组件展示页面
  6. */
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. textMessage: '',
  13. chatItems: [],
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad(options) {
  19. this.initData();
  20. },
  21. initData() {
  22. let that = this;
  23. let systemInfo = wx.getSystemInfoSync();
  24. chatInput.init(this, {
  25. systemInfo: systemInfo,
  26. minVoiceTime: 1,
  27. maxVoiceTime: 60,
  28. startTimeDown: 56,
  29. format: 'mp3',//aac/mp3
  30. sendButtonBgColor: 'mediumseagreen',
  31. sendButtonTextColor: 'white',
  32. extraArr: [{
  33. picName: 'choose_picture',
  34. description: '照片'
  35. }, {
  36. picName: 'take_photos',
  37. description: '拍摄'
  38. }, {
  39. picName: 'close_chat',
  40. description: '自定义功能'
  41. }],
  42. // tabbarHeigth: 48
  43. });
  44. that.setData({
  45. pageHeight: systemInfo.windowHeight,
  46. });
  47. wx.setNavigationBarTitle({
  48. title: '好友1'
  49. });
  50. that.textButton();
  51. that.extraButton();
  52. that.voiceButton();
  53. },
  54. textButton() {
  55. chatInput.setTextMessageListener(function (e) {
  56. console.log(1222);
  57. let content = e.detail.value;
  58. console.log(content);
  59. });
  60. },
  61. voiceButton() {
  62. chatInput.recordVoiceListener(function (res, duration) {
  63. let tempFilePath = res.tempFilePath;
  64. let vDuration = duration;
  65. console.log(tempFilePath, vDuration);
  66. });
  67. chatInput.setVoiceRecordStatusListener(function (status) {
  68. switch (status) {
  69. case chatInput.VRStatus.START://开始录音
  70. break;
  71. case chatInput.VRStatus.SUCCESS://录音成功
  72. break;
  73. case chatInput.VRStatus.CANCEL://取消录音
  74. break;
  75. case chatInput.VRStatus.SHORT://录音时长太短
  76. break;
  77. case chatInput.VRStatus.UNAUTH://未授权录音功能
  78. break;
  79. case chatInput.VRStatus.FAIL://录音失败(已经授权了)
  80. break;
  81. }
  82. })
  83. },
  84. extraButton() {
  85. let that = this;
  86. chatInput.clickExtraListener(function (e) {
  87. console.log(e);
  88. let itemIndex = parseInt(e.currentTarget.dataset.index);
  89. if (itemIndex === 2) {
  90. that.myFun();
  91. return;
  92. }
  93. wx.chooseImage({
  94. count: 1, // 默认9
  95. sizeType: ['compressed'],
  96. sourceType: itemIndex === 0 ? ['album'] : ['camera'],
  97. success: function (res) {
  98. let tempFilePath = res.tempFilePaths[0];
  99. }
  100. });
  101. });
  102. chatInput.setExtraButtonClickListener(function (dismiss) {
  103. console.log('Extra弹窗是否消失', dismiss);
  104. })
  105. },
  106. myFun() {
  107. wx.showModal({
  108. title: '小贴士',
  109. content: '这是用于拓展的自定义功能!',
  110. confirmText: '确认',
  111. showCancel: true,
  112. success: function (res) {
  113. if (res.confirm) {
  114. Toast.show('success', '自定义功能')
  115. }
  116. }
  117. })
  118. },
  119. resetInputStatus() {
  120. chatInput.closeExtraView();
  121. },
  122. });