chat.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // compontents/chat/chat.js
  2. Component({
  3. relations: {
  4. '../discuss/discuss': {
  5. type: 'child', // 关联的目标节点应为子节点
  6. linked: function(target) {
  7. // 每次有custom-li被插入时执行,target是该节点实例对象,触发在该节点attached生命周期之后
  8. console.log(target)
  9. },
  10. linkChanged: function(target) {
  11. // 每次有custom-li被移动后执行,target是该节点实例对象,触发在该节点moved生命周期之后
  12. console.log(target)
  13. },
  14. unlinked: function(target) {
  15. // 每次有custom-li被移除时执行,target是该节点实例对象,触发在该节点detached生命周期之后
  16. console.log(target)
  17. }
  18. }
  19. },
  20. /**
  21. * 组件的属性列表
  22. */
  23. properties: {
  24. productionData: {
  25. type: Object,
  26. value: {}
  27. },
  28. title: {
  29. type: String,
  30. value: ''
  31. },
  32. query: {
  33. type: String,
  34. value: ''
  35. },
  36. type: {
  37. type: String,
  38. value: ''
  39. },
  40. },
  41. /**
  42. * 组件的初始数据
  43. */
  44. data: {
  45. text: '',
  46. chatDatas: [],
  47. animationData: {},
  48. },
  49. /**
  50. * 组件的方法列表
  51. */
  52. methods: {
  53. uploadImage (e) {
  54. const type = this.properties.type;
  55. wx.navigateTo({
  56. url: '../input_content/input_content?type=' + type
  57. })
  58. },
  59. listenerButtonPreviewImage: function(e) {
  60. let imgUrl = [];
  61. imgUrl.push(e.target.dataset.img);
  62. wx.previewImage({
  63. current: '', // 当前显示图片的http链接
  64. urls: imgUrl, // 需要预览的图片http链接列表
  65. //这根本就不走
  66. success: function(res) {
  67. //console.log(res);
  68. },
  69. //也根本不走
  70. fail: function() {
  71. //console.log('fail')
  72. }
  73. })
  74. },
  75. shareImage: function(e){
  76. console.log(e);
  77. //分享查询单条的时候会用到这两个值
  78. const postId = e.currentTarget.dataset.postsid;
  79. this.share.showPopup(postId);
  80. },
  81. _getAllLi: function(){
  82. // 使用getRelationNodes可以获得nodes数组,包含所有已关联的custom-li,且是有序的
  83. var nodes = this.getRelationNodes('../discuss/discuss');
  84. console.log(nodes);
  85. }
  86. },
  87. ready: function(){
  88. this._getAllLi()
  89. this.share = this.selectComponent("#share");
  90. }
  91. })