index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // nova-werun/pages/send-circle/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. //屏幕高度
  10. statusBarHeight: 0, // 状态栏高度
  11. screenHeight: 0, // 屏幕高度
  12. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  13. bottomNavHeight: 0, // 底部导航栏高度
  14. contentHeight: 0, // 可用内容高度
  15. contentHeight2: 0,
  16. contentpadding: 0, //顶部padding高度
  17. //输入框
  18. inputValue: '', // 用于存储输入的内容
  19. textareaHeight: 52, // 初始高度,单位为 rpx
  20. // 图片
  21. fileList: [],
  22. fileLists:[],
  23. uptokenURL: '',
  24. domain: '',
  25. uploadURL: '',
  26. saveimage:false,
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. // 计算
  33. const systemInfo = wx.getSystemInfoSync();
  34. const statusBarHeight = systemInfo.statusBarHeight || 0;
  35. const screenHeight = systemInfo.screenHeight || 0;
  36. const custom = wx.getMenuButtonBoundingClientRect();
  37. const customHeight = custom.height + 10 + 2 || 0;
  38. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  39. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  40. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  41. this.setData({
  42. statusBarHeight,
  43. screenHeight,
  44. customHeight,
  45. bottomNavHeight,
  46. contentpadding,
  47. contentHeight
  48. });
  49. const images = []
  50. images.push({
  51. url:options.image
  52. })
  53. if(options.image){
  54. this.setData({
  55. fileList:images,
  56. saveimage:true,
  57. })
  58. }
  59. this.getUptoken()
  60. },
  61. /**
  62. * 生命周期函数--监听页面初次渲染完成
  63. */
  64. onReady: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面隐藏
  73. */
  74. onHide: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面卸载
  78. */
  79. onUnload: function () {
  80. },
  81. /**
  82. * 页面相关事件处理函数--监听用户下拉动作
  83. */
  84. onPullDownRefresh: function () {
  85. },
  86. /**
  87. * 页面上拉触底事件的处理函数
  88. */
  89. onReachBottom: function () {
  90. },
  91. /**
  92. * 用户点击右上角分享
  93. */
  94. onShareAppMessage: function () {
  95. },
  96. //输入框高度随字体增多而变大
  97. onInput: function (event) {
  98. const value = event.detail.value; // 获取当前输入的值
  99. this.setData({
  100. inputValue: value,
  101. });
  102. console.log(this.data.inputValue);
  103. },
  104. async getUptoken() {
  105. let res = await Parse.Cloud.run('qiniu_uptoken', {
  106. company: company
  107. })
  108. this.setData({
  109. uptokenURL: res.uptoken,
  110. domain: res.domain,
  111. uploadURL: res.zoneUrl
  112. })
  113. console.log(this.data.uptokenURL, this.data.domain, this.data.uploadURL);
  114. },
  115. //获取图片数组
  116. picture(event) {
  117. console.log('event', event);
  118. let FileList = event.detail
  119. this.setData({
  120. fileList: FileList,
  121. })
  122. console.log('图片', this.data.fileLists);
  123. },
  124. //上传函数
  125. async send() {
  126. const currentUser = Parse.User.current();
  127. let Profilequery = new Parse.Query('Profile');
  128. Profilequery.equalTo('company', company);
  129. Profilequery.notEqualTo('isDeleted', true);
  130. Profilequery.equalTo('user', currentUser.id);
  131. let p = await Profilequery.first()
  132. let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
  133. let Comment = new Parse.Object('AIMoment');
  134. Comment.set('profile', p.toPointer())
  135. Comment.set('company', companyPointer);
  136. Comment.set('isVisible', true);
  137. if(this.data.fileList.length>0){
  138. let url = []
  139. for (let i = 0; i < this.data.fileList.length; i++) {
  140. url.push(this.data.fileList[i].url)
  141. }
  142. this.setData({
  143. fileLists:url,
  144. })
  145. Comment.set('images', this.data.fileLists);
  146. }
  147. Comment.set('content', this.data.inputValue);
  148. try {
  149. if(this.data.fileList.length==0&& !this.data.inputValue){
  150. console.log('新数据保存失败');
  151. }else{
  152. let saveDate2 = await Comment.save();
  153. console.log(saveDate2);
  154. console.log("新数据保存成功");
  155. wx.showToast({
  156. title: '发布成功',
  157. icon: 'success',
  158. duration: 1000
  159. });
  160. setTimeout(()=>{
  161. this.goback()
  162. },1000)
  163. }
  164. } catch (error) {
  165. console.error("保存数据时出现错误:", error);
  166. }
  167. },
  168. async goback(){
  169. if(!this.data.saveimage){
  170. let pages = getCurrentPages(); //页面对象
  171. let prevpage = pages[pages.length - 2]; //上一个页面对象
  172. await prevpage.updateCom()
  173. }
  174. wx.navigateBack({
  175. delta: 1
  176. });
  177. }
  178. })