index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. console.log('options.image',options.image);
  54. if(options.image){
  55. this.setData({
  56. fileList:images,
  57. saveimage:true,
  58. })
  59. }
  60. this.getUptoken()
  61. },
  62. /**
  63. * 生命周期函数--监听页面初次渲染完成
  64. */
  65. onReady: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面显示
  69. */
  70. onShow: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面隐藏
  74. */
  75. onHide: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload: function () {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh: function () {
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom: function () {
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage: function () {
  96. },
  97. //输入框高度随字体增多而变大
  98. onInput: function (event) {
  99. const value = event.detail.value; // 获取当前输入的值
  100. this.setData({
  101. inputValue: value,
  102. });
  103. console.log(this.data.inputValue);
  104. },
  105. async getUptoken() {
  106. let res = await Parse.Cloud.run('qiniu_uptoken', {
  107. company: company
  108. })
  109. this.setData({
  110. uptokenURL: res.uptoken,
  111. domain: res.domain,
  112. uploadURL: res.zoneUrl
  113. })
  114. console.log(this.data.uptokenURL, this.data.domain, this.data.uploadURL);
  115. },
  116. //获取图片数组
  117. picture(event) {
  118. console.log('event', event);
  119. let FileList = event.detail
  120. this.setData({
  121. fileList: FileList,
  122. })
  123. console.log('图片', this.data.fileLists);
  124. },
  125. //上传函数
  126. async send() {
  127. const currentUser = Parse.User.current();
  128. let Profilequery = new Parse.Query('Profile');
  129. Profilequery.equalTo('company', company);
  130. Profilequery.notEqualTo('isDeleted', true);
  131. Profilequery.equalTo('user', currentUser.id);
  132. let p = await Profilequery.first()
  133. let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
  134. let Comment = new Parse.Object('AIMoment');
  135. Comment.set('profile', p.toPointer())
  136. Comment.set('company', companyPointer);
  137. Comment.set('isVisible', true);
  138. if(this.data.fileList.length>0){
  139. let url = []
  140. for (let i = 0; i < this.data.fileList.length; i++) {
  141. url.push(this.data.fileList[i].url)
  142. }
  143. this.setData({
  144. fileLists:url,
  145. })
  146. Comment.set('images', this.data.fileLists);
  147. }
  148. Comment.set('content', this.data.inputValue);
  149. try {
  150. if(this.data.fileList.length==0&& !this.data.inputValue){
  151. console.log('新数据保存失败');
  152. }else{
  153. let saveDate2 = await Comment.save();
  154. console.log(saveDate2);
  155. console.log("新数据保存成功");
  156. wx.showToast({
  157. title: '发布成功',
  158. icon: 'success',
  159. duration: 1000
  160. });
  161. setTimeout(()=>{
  162. this.goback()
  163. },1000)
  164. }
  165. } catch (error) {
  166. console.error("保存数据时出现错误:", error);
  167. }
  168. },
  169. async goback(){
  170. if(!this.data.saveimage){
  171. let pages = getCurrentPages(); //页面对象
  172. let prevpage = pages[pages.length - 2]; //上一个页面对象
  173. await prevpage.updateCom()
  174. }
  175. wx.navigateBack({
  176. delta: 1
  177. });
  178. }
  179. })