index.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. uptokenURL: '',
  23. domain: '',
  24. uploadURL: '',
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. // 计算
  31. const systemInfo = wx.getSystemInfoSync();
  32. const statusBarHeight = systemInfo.statusBarHeight || 0;
  33. const screenHeight = systemInfo.screenHeight || 0;
  34. const custom = wx.getMenuButtonBoundingClientRect();
  35. const customHeight = custom.height + 10 + 2 || 0;
  36. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  37. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  38. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  39. this.setData({
  40. statusBarHeight,
  41. screenHeight,
  42. customHeight,
  43. bottomNavHeight,
  44. contentpadding,
  45. contentHeight
  46. });
  47. this.getUptoken()
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面显示
  56. */
  57. onShow: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面隐藏
  61. */
  62. onHide: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面卸载
  66. */
  67. onUnload: function () {
  68. },
  69. /**
  70. * 页面相关事件处理函数--监听用户下拉动作
  71. */
  72. onPullDownRefresh: function () {
  73. },
  74. /**
  75. * 页面上拉触底事件的处理函数
  76. */
  77. onReachBottom: function () {
  78. },
  79. /**
  80. * 用户点击右上角分享
  81. */
  82. onShareAppMessage: function () {
  83. },
  84. //输入框高度随字体增多而变大
  85. onInput: function (event) {
  86. const value = event.detail.value; // 获取当前输入的值
  87. this.setData({
  88. inputValue: value,
  89. });
  90. console.log(this.data.inputValue);
  91. },
  92. async getUptoken() {
  93. let res = await Parse.Cloud.run('qiniu_uptoken', {
  94. company: company
  95. })
  96. this.setData({
  97. uptokenURL: res.uptoken,
  98. domain: res.domain,
  99. uploadURL: res.zoneUrl
  100. })
  101. console.log(this.data.uptokenURL, this.data.domain, this.data.uploadURL);
  102. },
  103. //获取图片数组
  104. picture(event) {
  105. console.log('event', event);
  106. let FileList = event.detail
  107. let url = []
  108. for (let i = 0; i < FileList.length; i++) {
  109. url.push(FileList[i].url)
  110. }
  111. this.setData({
  112. fileList: url
  113. })
  114. console.log('图片', this.data.fileList);
  115. },
  116. //上传函数
  117. async send() {
  118. const currentUser = Parse.User.current();
  119. let Profilequery = new Parse.Query('Profile');
  120. Profilequery.equalTo('company', company);
  121. Profilequery.notEqualTo('isDeleted', true);
  122. Profilequery.equalTo('user', currentUser.id);
  123. let p = await Profilequery.first()
  124. let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
  125. let Comment = new Parse.Object('AIMoment');
  126. Comment.set('profile', p.toPointer())
  127. Comment.set('company', companyPointer);
  128. Comment.set('isVisible', true);
  129. Comment.set('images', this.data.fileList);
  130. Comment.set('content', this.data.inputValue);
  131. try {
  132. if(this.data.fileList.length==0&& !this.data.inputValue){
  133. console.log('新数据保存失败');
  134. }else{
  135. let saveDate2 = await Comment.save();
  136. console.log(saveDate2);
  137. console.log("新数据保存成功");
  138. this.goback()
  139. }
  140. } catch (error) {
  141. console.error("保存数据时出现错误:", error);
  142. }
  143. },
  144. async goback(){
  145. let pages = getCurrentPages(); //页面对象
  146. let prevpage = pages[pages.length - 2]; //上一个页面对象
  147. await prevpage.updateCom()
  148. wx.navigateBack({
  149. delta: 1
  150. });
  151. }
  152. })