chat.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // compontents/chat/chat.js
  2. const util = require('../../utils/util.js');
  3. const APIClient = require('../../utils/APIClient.js');
  4. const login = require('../../utils/loginSchedule.js');
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. * productionData 传过来的数据
  9. * title 头部标题
  10. * query 看是上传还是分享图片
  11. * type 主要是判断答疑和分享
  12. * columnType 主要是课程的编号 底下会用到
  13. * more是否显示展开更多
  14. */
  15. properties: {
  16. productionData: {
  17. type: Object,
  18. value: {}
  19. },
  20. title: {
  21. type: String,
  22. value: ''
  23. },
  24. query: {
  25. type: String,
  26. value: ''
  27. },
  28. type: {
  29. type: String,
  30. value: ''
  31. },
  32. columnType: {
  33. type: String,
  34. value: ''
  35. },
  36. more: {
  37. type: String,
  38. value: ''
  39. }
  40. },
  41. /**
  42. * 组件的初始数据
  43. * animationData 主要是定义一个展开的动画
  44. */
  45. data: {
  46. animationData: {},
  47. ratio: '',
  48. canvasHeight: ''
  49. },
  50. /**
  51. * 组件的方法列表
  52. */
  53. methods: {
  54. uploadImage (e) {
  55. const type = this.properties.type;
  56. const columnType = this.properties.columnType;
  57. wx.navigateTo({
  58. url: '../input_content/input_content?type=' + type + '&columnType=' + columnType
  59. })
  60. },
  61. listenerButtonPreviewImage: function(e) {
  62. let imgUrl = [];
  63. imgUrl.push(e.target.dataset.img);
  64. wx.previewImage({
  65. current: '', // 当前显示图片的http链接
  66. urls: imgUrl, // 需要预览的图片http链接列表
  67. //这根本就不走
  68. success: function(res) {
  69. //console.log(res);
  70. },
  71. //也根本不走
  72. fail: function() {
  73. //console.log('fail')
  74. }
  75. })
  76. },
  77. //分享
  78. shareImage: function(e){
  79. this.triggerEvent('getHeight');
  80. //分享查询单条的时候会用到这个值
  81. const postId = e.currentTarget.dataset.postsid;
  82. //获取分享的图片
  83. const imgUrl = e.currentTarget.dataset.imgurl;
  84. //获取分享的个人信息
  85. const featureMap = e.currentTarget.dataset.featuremap;
  86. //获取输入内容
  87. const title = e.currentTarget.dataset.title;
  88. //获取宽高比例
  89. const ratio = this.data.ratio;
  90. //分享组件弹窗调用里边方法,在底下会获取
  91. this.share.showPopup(postId, imgUrl, featureMap, title, ratio);
  92. },
  93. //跳转详情页
  94. particulars: function (e) {
  95. const postId = e.currentTarget.dataset.postsid;
  96. const type = e.currentTarget.dataset.type;
  97. //取消小点
  98. login.getOpenidSessionKey(function(res) {
  99. APIClient.cancelDian({
  100. uid: res.data.data.uid
  101. }, {
  102. "postsId":postId
  103. }).success((res) => {
  104. console.log(res);
  105. })
  106. }, function() {
  107. wx.showModal({
  108. title: '提示',
  109. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  110. showCancel: false,
  111. success: function (res) {
  112. if (res.confirm) {
  113. console.log('用户点击确定')
  114. } else if (res.cancel) {
  115. console.log('用户点击取消')
  116. }
  117. }
  118. })
  119. });
  120. wx.navigateTo({
  121. url: '../../pages/particulars/particulars?postId=' + postId + '&type=' + type
  122. })
  123. },
  124. //查看更多
  125. examine: function () {
  126. //组件间方法的调用
  127. var myEventDetail = {} // detail对象,提供给事件监听函数
  128. var myEventOption = {} // 触发事件的选项
  129. this.triggerEvent('myevent', myEventDetail, myEventOption)
  130. },
  131. //获取image宽高
  132. imageLoad: function(e) {
  133. let height = e.detail.height;
  134. let width = e.detail.width;
  135. //获取屏幕宽度
  136. const windowWidth = wx.getSystemInfoSync().windowWidth;
  137. //获取图片高度
  138. const imgHeight = windowWidth*(height/width);
  139. this.setData({
  140. ratio: height/width,
  141. canvasHeight: imgHeight + 300
  142. })
  143. }
  144. },
  145. ready: function(){
  146. //获取分享弹窗组件
  147. this.share = this.selectComponent("#share");
  148. }
  149. })