index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. checked: false,
  28. address: '',
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. // 计算
  35. const systemInfo = wx.getSystemInfoSync();
  36. const statusBarHeight = systemInfo.statusBarHeight || 0;
  37. const screenHeight = systemInfo.screenHeight || 0;
  38. const custom = wx.getMenuButtonBoundingClientRect();
  39. const customHeight = custom.height + 10 + 2 || 0;
  40. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  41. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  42. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  43. this.setData({
  44. statusBarHeight,
  45. screenHeight,
  46. customHeight,
  47. bottomNavHeight,
  48. contentpadding,
  49. contentHeight
  50. });
  51. const images = []
  52. images.push({
  53. url: options.image
  54. })
  55. console.log('options.image', options.image);
  56. if (options.image) {
  57. this.setData({
  58. fileList: images,
  59. saveimage: true,
  60. })
  61. }
  62. this.getUptoken()
  63. },
  64. /**
  65. * 生命周期函数--监听页面初次渲染完成
  66. */
  67. onReady: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面显示
  71. */
  72. onShow: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面隐藏
  76. */
  77. onHide: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面卸载
  81. */
  82. onUnload: function () {
  83. },
  84. /**
  85. * 页面相关事件处理函数--监听用户下拉动作
  86. */
  87. onPullDownRefresh: function () {
  88. },
  89. /**
  90. * 页面上拉触底事件的处理函数
  91. */
  92. onReachBottom: function () {
  93. },
  94. /**
  95. * 用户点击右上角分享
  96. */
  97. onShareAppMessage: function () {
  98. },
  99. //输入框高度随字体增多而变大
  100. onInput: function (event) {
  101. const value = event.detail.value; // 获取当前输入的值
  102. this.setData({
  103. inputValue: value,
  104. });
  105. console.log(this.data.inputValue);
  106. },
  107. async getUptoken() {
  108. let res = await Parse.Cloud.run('qiniu_uptoken', {
  109. company: company
  110. })
  111. this.setData({
  112. uptokenURL: res.uptoken,
  113. domain: res.domain,
  114. uploadURL: res.zoneUrl
  115. })
  116. console.log(this.data.uptokenURL, this.data.domain, this.data.uploadURL);
  117. },
  118. //获取图片数组
  119. picture(event) {
  120. console.log('event', event);
  121. let FileList = event.detail
  122. this.setData({
  123. fileList: FileList,
  124. })
  125. console.log('图片', this.data.fileLists);
  126. },
  127. //上传函数
  128. async send() {
  129. const currentUser = Parse.User.current();
  130. let Profilequery = new Parse.Query('Profile');
  131. Profilequery.equalTo('company', company);
  132. Profilequery.equalTo('isCheck', true);
  133. Profilequery.notEqualTo('isDeleted', true);
  134. Profilequery.equalTo('user', currentUser.id);
  135. let p = await Profilequery.first()
  136. let userequery = new Parse.Query('_User');
  137. userequery.equalTo('company', company);
  138. userequery.notEqualTo('isDeleted', true);
  139. userequery.equalTo('objectId', currentUser.id);
  140. let user = await userequery.first()
  141. let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
  142. let Comment = new Parse.Object('AIMoment');
  143. if(p){
  144. Comment.set('profile', p.toPointer())
  145. Comment.set('isVisible', true);
  146. }
  147. Comment.set('company', companyPointer);
  148. Comment.set('user', user.toPointer());
  149. if (this.data.fileList.length > 0) {
  150. let url = []
  151. for (let i = 0; i < this.data.fileList.length; i++) {
  152. url.push(this.data.fileList[i].url)
  153. }
  154. this.setData({
  155. fileLists: url,
  156. })
  157. Comment.set('images', this.data.fileLists);
  158. }
  159. Comment.set('content', this.data.inputValue);
  160. if (this.data.checked) {
  161. Comment.set('location', this.data.address);
  162. }
  163. try {
  164. if (this.data.fileList.length == 0 && !this.data.inputValue) {
  165. console.log('新数据保存失败');
  166. } else {
  167. let saveDate2 = await Comment.save();
  168. console.log(saveDate2);
  169. console.log("新数据保存成功");
  170. wx.showToast({
  171. title: '发布成功',
  172. icon: 'success',
  173. duration: 1000
  174. });
  175. setTimeout(() => {
  176. this.goback()
  177. }, 1000)
  178. }
  179. } catch (error) {
  180. console.error("保存数据时出现错误:", error);
  181. }
  182. },
  183. async goback() {
  184. if (!this.data.saveimage) {
  185. let pages = getCurrentPages(); //页面对象
  186. console.log(pages);
  187. let prevpage = pages[pages.length - 2]; //上一个页面对象
  188. console.log(prevpage);
  189. await prevpage.updateCom()
  190. }
  191. wx.navigateBack({
  192. delta: 1
  193. });
  194. },
  195. //选择展示当前位置
  196. onChange(event) {
  197. this.setData({
  198. checked: event.detail,
  199. });
  200. console.log(this.data.checked);
  201. this.Getlocation()
  202. },
  203. //获取当前位置
  204. Getlocation() {
  205. // 获取当前位置信息
  206. wx.getLocation({
  207. type: 'wgs84',
  208. success: (res) => {
  209. const {
  210. latitude,
  211. longitude
  212. } = res;
  213. //调用api解析地址
  214. wx.request({
  215. url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=sHZTomd7grslfP7sPKB8tRgT49FK9TEu&output=json&coordtype=gcj02&location=' + latitude + ',' + longitude,
  216. data: {},
  217. header: {
  218. 'Content-Type': 'application/json'
  219. },
  220. success: (ops) => { // 使用箭头函数
  221. console.log(ops);
  222. // const address = ops.data.result.formatted_address;//详细地址
  223. const address = ops.data.result.formatted_address;
  224. this.setData({
  225. address: address,
  226. });
  227. console.log(this.data.address);
  228. },
  229. fail: function (resq) {
  230. wx.showModal({
  231. title: '信息提示',
  232. content: '请求失败',
  233. showCancel: false,
  234. confirmColor: '#f37938'
  235. });
  236. },
  237. complete: function () {}
  238. })
  239. },
  240. fail: (err) => {
  241. console.error(err);
  242. wx.showToast({
  243. title: '获取位置失败',
  244. icon: 'none'
  245. });
  246. }
  247. });
  248. },
  249. })