chat.js 4.3 KB

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