index.js 4.5 KB

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