| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 | 
							- // nova-werun/components/circle-card/index.js
 
- const Parse = getApp().Parse;
 
- const company = getApp().globalData.company;
 
- Component({
 
-     /**
 
-      * 组件的属性列表
 
-      */
 
-     properties: {
 
-         objectId: '',
 
-         type: ''
 
-     },
 
-     /**
 
-      * 组件的初始数据
 
-      */
 
-     data: {
 
-         //图片
 
-         images: [],
 
-         imageclass: '',
 
-         //是否展示点赞评论按钮
 
-         isgood: false,
 
-         isclick: false,
 
-         //朋友圈
 
-         cicleList: [],
 
-         time: '',
 
-         //点赞人
 
-         chickList: ''
 
-     },
 
-     lifetimes: {
 
-         detached: function () {
 
-             // 在组件实例被从页面节点树移除时执行
 
-         },
 
-         attached: async function () {
 
-             // 在组件实例进入页面节点树时执行
 
-             this.getcircle()
 
-             this.showischick()
 
-         },
 
-     },
 
-     /**
 
-      * 组件的方法列表
 
-      */
 
-     methods: {
 
-         onImageLoad: function (e) {
 
-             const {
 
-                 width,
 
-                 height
 
-             } = e.detail; // 获取图片的宽高
 
-             const imageClass = width > height ? 'image-landscape' : 'image-portrait'; // 判断横竖屏
 
-             this.setData({
 
-                 imageclass: imageClass // 动态设置图片的类名
 
-             });
 
-         },
 
-         previewImage: function (e) {
 
-             const index = e.currentTarget.dataset.index; // 获取当前点击图片的索引
 
-             const images = this.data.images; // 获取所有图片的链接
 
-             wx.previewImage({
 
-                 current: images[index], // 当前显示图片的链接
 
-                 urls: images // 需要预览的图片链接列表
 
-             });
 
-         },
 
-         gourl(e) {
 
-             const url = e.currentTarget.dataset.url
 
-             const objectId = e.currentTarget.dataset.id
 
-             wx.navigateTo({
 
-                 url: `${url}?id=` + objectId // 目标页面的路径
 
-             });
 
-         },
 
-         showgood() {
 
-             this.setData({
 
-                 isgood: !this.data.isgood
 
-             })
 
-         },
 
-         isclick() {
 
-             this.chickin()
 
-             setTimeout(() => {
 
-                 this.showchick()
 
-                 this.showgood()
 
-             }, 400)
 
-         },
 
-         async getcircle() {
 
-             let AIMomentquery = new Parse.Query('AIMoment');
 
-             AIMomentquery.equalTo('company', company);
 
-             AIMomentquery.equalTo('objectId', this.data.objectId);
 
-             AIMomentquery.equalTo('isVisible', true);
 
-             AIMomentquery.include('profile.user');
 
-             AIMomentquery.include('profile');
 
-             AIMomentquery.notEqualTo('isDeleted', true)
 
-             let P = await AIMomentquery.find();
 
-             let AIMoment1List = P.map(item => item.toJSON());
 
-             this.setData({
 
-                 cicleList: AIMoment1List,
 
-             })
 
-             this.setData({
 
-                 images: this.data.cicleList[0].images
 
-             })
 
-             // 将 ISO 字符串转换为时间戳并传递给 formatTime
 
-             const createdAt = new Date(this.data.cicleList[0].createdAt).getTime();
 
-             const time = this.formatTime(createdAt);
 
-             this.setData({
 
-                 time
 
-             })
 
-             this.showchick()
 
-         },
 
-         formatTime(timestamp) {
 
-             const now = Date.now();
 
-             const diff = now - timestamp;
 
-             if (diff < 60000) { // 小于1分钟
 
-                 return '刚刚';
 
-             } else if (diff < 3600000) { // 小于1小时
 
-                 return Math.floor(diff / 60000) + '分钟前';
 
-             } else if (diff < 86400000) { // 小于24小时
 
-                 return Math.floor(diff / 3600000) + '小时前';
 
-             } else if (diff < 172800000) { // 小于48小时
 
-                 return '昨天';
 
-             } else {
 
-                 const date = new Date(timestamp);
 
-                 return date.toLocaleDateString(); // 显示具体日期
 
-             }
 
-         },
 
-         //点击点赞按钮
 
-         async chickin() {
 
-             this.setData({
 
-                 isclick: !this.data.isclick
 
-             })
 
-             let AIMomentquery = new Parse.Query('AIMoment');
 
-             AIMomentquery.equalTo('company', company);
 
-             AIMomentquery.equalTo('objectId', this.data.objectId);
 
-             AIMomentquery.equalTo('isVisible', true);
 
-             AIMomentquery.include('profile.user');
 
-             AIMomentquery.include('profile');
 
-             AIMomentquery.notEqualTo('isDeleted', true)
 
-             let P = await AIMomentquery.first();
 
-             const currentUser = Parse.User.current();
 
-             let AIMomentCommentquery = new Parse.Query('AIMomentComment');
 
-             AIMomentCommentquery.equalTo('company', company);
 
-             AIMomentCommentquery.equalTo('type', 'chickin');
 
-             AIMomentCommentquery.equalTo('moment', P.toPointer());
 
-             AIMomentCommentquery.equalTo('user', currentUser.id);
 
-             let moment = await AIMomentCommentquery.first()
 
-             if (moment) {
 
-                 moment.set('isDeleted', this.data.isclick)
 
-                 try {
 
-                     let saveDate = await moment.save();
 
-                     console.log(saveDate);
 
-                     console.log("新数据保存成功");
 
-                 } catch (error) {
 
-                     console.error("保存数据时出现错误:", error);
 
-                 }
 
-             } else {
 
-                 const currentUser = Parse.User.current();
 
-                 let userquery = new Parse.Query('_User');
 
-                 userquery.equalTo('company', company);
 
-                 userquery.equalTo('objectId', currentUser.id);
 
-                 userquery.notEqualTo('isDeleted', true)
 
-                 let user = await userquery.first();
 
-                 let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
 
-                 let Comment = new Parse.Object('AIMomentComment');
 
-                 Comment.set('moment', P.toPointer())
 
-                 Comment.set('company', companyPointer);
 
-                 Comment.set('type', 'chickin');
 
-                 Comment.set('user', user.toPointer());
 
-                 Comment.set('isDeleted', false);
 
-                 try {
 
-                     let saveDate2 = await Comment.save();
 
-                     console.log(saveDate2);
 
-                     console.log("新数据保存成功");
 
-                 } catch (error) {
 
-                     console.error("保存数据时出现错误:", error);
 
-                 }
 
-             }
 
-         },
 
-         //显示是否点过赞
 
-         async showischick() {
 
-             const currentUser = Parse.User.current();
 
-             let AIMomentCommentquery2 = new Parse.Query('AIMomentComment');
 
-             AIMomentCommentquery2.equalTo('company', company);
 
-             AIMomentCommentquery2.equalTo('type', 'chickin');
 
-             AIMomentCommentquery2.equalTo('moment', this.data.objectId);
 
-             AIMomentCommentquery2.equalTo('user', currentUser.id);
 
-             let moment2 = await AIMomentCommentquery2.find()
 
-             let AIMoment1List2 = moment2.map(item => item.toJSON());
 
-             this.setData({
 
-                 isclick:AIMoment1List2[0].isDeleted
 
-             })
 
-             console.log('isclick',AIMoment1List2);
 
-         },
 
-         //显示点赞人
 
-         async showchick() {
 
-             let Momentquery = new Parse.Query('AIMomentComment');
 
-             Momentquery.equalTo('company', company);
 
-             Momentquery.equalTo('type', 'chickin');
 
-             Momentquery.equalTo('moment', this.data.objectId);
 
-             Momentquery.notEqualTo('isDeleted', true)
 
-             Momentquery.include('user')
 
-             let r = await Momentquery.find();
 
-             let chickList = r.map(item => item.toJSON());
 
-             console.log(chickList);
 
-             this.setData({
 
-                 chickList
 
-             })
 
-         }
 
-     }
 
- })
 
 
  |