diff --git a/App.vue b/App.vue
index 502b5644..b50e878b 100644
--- a/App.vue
+++ b/App.vue
@@ -63,8 +63,8 @@ export default {
this.checkArguments(); // 检测启动参数
});
// init im
- var ddd = TUIChatKit.init();
- console.log('dasjdlasjdlajsldjaslkdjasljdklasdljasldadjaldjlkasdlkasjdalsdjl', ddd);
+ TUIChatKit.init();
+ console.log('IM初始化完成');
// 如果有缓存登录信息
console.log('是否登录', storage.getHasLogin());
if (storage.getHasLogin()) {
@@ -83,7 +83,6 @@ export default {
// #endif
},
methods: {
- //
hanleTabCenter() {
// 点击中间的➕
uni.onTabBarMidButtonTap(() => {
diff --git a/components/vlog/guanzhu.nvue b/components/vlog/guanzhu.nvue
index 42912c64..aaebab43 100644
--- a/components/vlog/guanzhu.nvue
+++ b/components/vlog/guanzhu.nvue
@@ -402,6 +402,7 @@
@@ -509,7 +510,8 @@ export default {
vlogId: '', // 视频id
url: '',
isPrivate: 0
- }
+ },
+ channelComment: null
};
},
// components: {
@@ -573,6 +575,16 @@ export default {
// },
created() {
this.channel = new BroadcastChannel('video-progress');
+ this.channelComment = new BroadcastChannel('comment-counts');
+ this.channelComment.onmessage = (event) => {
+ const { type, data } = event.data;
+ if (type == 'comment-counts') {
+ if (data.from == 'guanzhu') {
+ this.refreshVlogCounts();
+ this.freshCommentCounts();
+ }
+ }
+ };
this.platform = uni.getSystemInfoSync().platform;
var model = uni.getSystemInfoSync().model;
if (this.platform == 'ios' && (model !== 'iPhone6' || model !== 'iPhone6s' || model !== 'iPhone7' || model !== 'iPhone8')) {
@@ -609,6 +621,25 @@ export default {
},
onReady() {},
methods: {
+ async refreshVlogCounts() {
+ // 查询当前点赞数,重新赋值给当前视频
+ var me = this;
+ var vlog = me.dataList[this.k];
+ var result = await vlogTotalLikedCounts(vlog.vlogId);
+ if (result.data.status == 200) {
+ var counts = result.data.data;
+ this.dataList[this.k].likeCounts = counts;
+ }
+ },
+ async freshCommentCounts() {
+ var me = this;
+ var vlog = me.dataList[this.k];
+ var result = await vlogComment(vlog.vlogId);
+ if (result.data.status == 200) {
+ var counts = result.data.data;
+ this.dataList[this.k].commentsCounts = counts;
+ }
+ },
// 关注博主
async followMe(vlogerId) {
var myUserInfo = storage.getVlogUserInfo();
diff --git a/components/vlog/local.nvue b/components/vlog/local.nvue
index 3f73fbcb..7795f820 100644
--- a/components/vlog/local.nvue
+++ b/components/vlog/local.nvue
@@ -402,6 +402,7 @@
@@ -509,7 +510,8 @@ export default {
vlogId: '', // 视频id
url: '',
isPrivate: 0
- }
+ },
+ channelComment: null
};
},
// components: {
@@ -573,6 +575,16 @@ export default {
// },
created() {
this.channel = new BroadcastChannel('video-progress');
+ this.channelComment = new BroadcastChannel('comment-counts');
+ this.channelComment.onmessage = (event) => {
+ const { type, data } = event.data;
+ if (type == 'comment-counts') {
+ if (data.from == 'local') {
+ this.refreshVlogCounts();
+ this.freshCommentCounts();
+ }
+ }
+ };
this.platform = uni.getSystemInfoSync().platform;
var model = uni.getSystemInfoSync().model;
if (this.platform == 'ios' && (model !== 'iPhone6' || model !== 'iPhone6s' || model !== 'iPhone7' || model !== 'iPhone8')) {
@@ -609,6 +621,25 @@ export default {
},
onReady() {},
methods: {
+ async refreshVlogCounts() {
+ // 查询当前点赞数,重新赋值给当前视频
+ var me = this;
+ var vlog = me.dataList[this.k];
+ var result = await vlogTotalLikedCounts(vlog.vlogId);
+ if (result.data.status == 200) {
+ var counts = result.data.data;
+ this.dataList[this.k].likeCounts = counts;
+ }
+ },
+ async freshCommentCounts() {
+ var me = this;
+ var vlog = me.dataList[this.k];
+ var result = await vlogComment(vlog.vlogId);
+ if (result.data.status == 200) {
+ var counts = result.data.data;
+ this.dataList[this.k].commentsCounts = counts;
+ }
+ },
// 关注博主
async followMe(vlogerId) {
var myUserInfo = storage.getVlogUserInfo();
diff --git a/components/vlog/tuijian.nvue b/components/vlog/tuijian.nvue
index 62d587bf..6b1a6c58 100644
--- a/components/vlog/tuijian.nvue
+++ b/components/vlog/tuijian.nvue
@@ -395,6 +395,7 @@
@@ -494,7 +495,8 @@ export default {
player: '',
// 新增内容
page: 1,
- channel: null,
+ channel: null, // 处理进度条
+ channelComment: null, // 处理评论数量显示
userId: '',
pinglunInfo: {
vlogerId: '', // 博主id
@@ -565,6 +567,16 @@ export default {
// },
created() {
this.channel = new BroadcastChannel('video-progress');
+ this.channelComment = new BroadcastChannel('comment-counts');
+ this.channelComment.onmessage = (event) => {
+ const { type, data } = event.data;
+ if (type == 'comment-counts') {
+ if (data.from == 'tuijian') {
+ this.refreshVlogCounts();
+ this.freshCommentCounts();
+ }
+ }
+ };
this.platform = uni.getSystemInfoSync().platform;
var model = uni.getSystemInfoSync().model;
if (this.platform == 'ios' && (model !== 'iPhone6' || model !== 'iPhone6s' || model !== 'iPhone7' || model !== 'iPhone8')) {
@@ -600,6 +612,25 @@ export default {
},
onReady() {},
methods: {
+ async refreshVlogCounts() {
+ // 查询当前点赞数,重新赋值给当前视频
+ var me = this;
+ var vlog = me.dataList[this.k];
+ var result = await vlogTotalLikedCounts(vlog.vlogId);
+ if (result.data.status == 200) {
+ var counts = result.data.data;
+ this.dataList[this.k].likeCounts = counts;
+ }
+ },
+ async freshCommentCounts() {
+ var me = this;
+ var vlog = me.dataList[this.k];
+ var result = await vlogComment(vlog.vlogId);
+ if (result.data.status == 200) {
+ var counts = result.data.data;
+ this.dataList[this.k].commentsCounts = counts;
+ }
+ },
// 关注博主
async followMe(vlogerId) {
var myUserInfo = storage.getVlogUserInfo();
@@ -888,7 +919,7 @@ export default {
tozuozhe(userId) {
var myInfo = storage.getVlogUserInfo();
var myId = '';
- if (myId != null) {
+ if (myInfo != null) {
myId = myInfo.id;
}
if (userId == myId) {
diff --git a/pages/me/vlog.nvue b/pages/me/vlog.nvue
index 3af987ca..aaa31a31 100644
--- a/pages/me/vlog.nvue
+++ b/pages/me/vlog.nvue
@@ -405,6 +405,7 @@
@@ -512,7 +513,8 @@ export default {
url: '',
isPrivate: 0
},
- vlogId: ''
+ vlogId: '',
+ channelComment: null
};
},
// components: {
@@ -579,6 +581,16 @@ export default {
// this.channel = new BroadcastChannel('video-progress');
// },
created() {
+ this.channelComment = new BroadcastChannel('comment-counts');
+ this.channelComment.onmessage = (event) => {
+ const { type, data } = event.data;
+ if (type == 'comment-counts') {
+ if (data.from == 'item') {
+ this.refreshVlogCounts();
+ this.freshCommentCounts();
+ }
+ }
+ };
this.platform = uni.getSystemInfoSync().platform;
var model = uni.getSystemInfoSync().model;
if (this.platform == 'ios' && (model !== 'iPhone6' || model !== 'iPhone6s' || model !== 'iPhone7' || model !== 'iPhone8')) {
@@ -614,6 +626,25 @@ export default {
},
onReady() {},
methods: {
+ async refreshVlogCounts() {
+ // 查询当前点赞数,重新赋值给当前视频
+ var me = this;
+ var vlog = me.dataList[this.k];
+ var result = await vlogTotalLikedCounts(vlog.vlogId);
+ if (result.data.status == 200) {
+ var counts = result.data.data;
+ this.dataList[this.k].likeCounts = counts;
+ }
+ },
+ async freshCommentCounts() {
+ var me = this;
+ var vlog = me.dataList[this.k];
+ var result = await vlogComment(vlog.vlogId);
+ if (result.data.status == 200) {
+ var counts = result.data.data;
+ this.dataList[this.k].commentsCounts = counts;
+ }
+ },
back() {
uni.navigateBack({
delta: 1
diff --git a/pages/tabbar/vlog/index.nvue b/pages/tabbar/vlog/index.nvue
index e2ad8ebc..8b4aaa90 100644
--- a/pages/tabbar/vlog/index.nvue
+++ b/pages/tabbar/vlog/index.nvue
@@ -111,6 +111,7 @@
let animation = weex.requireModule('animation');
let dom = weex.requireModule('dom');
let system = uni.getSystemInfoSync();
+
console.log(system);
// 缓存每页最多
const MAX_CACHE_DATA = 100;
@@ -180,8 +181,8 @@ export default {
};
},
created() {
+ // 处理进度条事件
this.channel = new BroadcastChannel('video-progress');
-
this.channel.onmessage = (event) => {
console.log(event);
const { type, data } = event.data;
@@ -193,6 +194,7 @@ export default {
};
},
onReady() {
+ this.handleHuaWei();
this._lastTabIndex = 0;
this.swiperWidth = 0;
this.tabbarWidth = 0;
@@ -268,6 +270,17 @@ export default {
// },
methods: {
+ handleHuaWei() {
+ // 处理华为机型问题
+ const deviceInfo = uni.getSystemInfoSync();
+ console.log(deviceInfo.brand);
+ if (deviceInfo.brand === 'HUAWEI') {
+ // 针对华为设备,修改 Tabbar 样式
+ uni.setTabBarStyle({
+ color: '#e8e8e8'
+ });
+ }
+ },
getLocation() {
uni.getLocation({
type: 'wg84',
@@ -629,7 +642,8 @@ export default {
}
.uni-tab-item-title {
- color: #999;
+ /* color: #999; */
+ color: #e8e8e8;
font-size: 30upx;
height: 80upx;
line-height: 80upx;
diff --git a/uni_modules/uni-popup/components/uni-popup-comments/uni-popup-comments.vue b/uni_modules/uni-popup/components/uni-popup-comments/uni-popup-comments.vue
index 69fc0753..65375b37 100755
--- a/uni_modules/uni-popup/components/uni-popup-comments/uni-popup-comments.vue
+++ b/uni_modules/uni-popup/components/uni-popup-comments/uni-popup-comments.vue
@@ -388,6 +388,10 @@ export default {
thisVlogId: {
type: String,
default: ''
+ },
+ from: {
+ type: String,
+ default: ''
}
},
data() {
@@ -421,11 +425,20 @@ export default {
page: 0,
totalPage: 0,
commentCounts: 88,
- commentList: []
+ commentList: [],
+ channelComment: null
};
},
onShow() {},
+ destroyed() {
+ console.log('评论组件销毁');
+ // 销毁时关闭 BroadcastChannel
+ if (this.channelComment) {
+ this.channelComment.close();
+ }
+ },
created() {
+ console.log('评论组件创建');
var me = this;
var myUserInfo = storage.getVlogUserInfo();
var userId = '';
@@ -436,7 +449,7 @@ export default {
this.isLogin = false;
}
me.loginUserId = userId;
-
+ this.channelComment = new BroadcastChannel('comment-counts');
this.freshCommentCounts();
this.doCommentPagingList(this.page + 1, true);
},
@@ -548,6 +561,11 @@ export default {
var result = await vlogCommentDelete(vlogId, commentUserId, commentId);
if (result.data.status == 200) {
me.doCommentPagingList(1, true);
+ // 刷新评论数量-1
+ this.channelComment.postMessage({
+ type: 'comment-counts',
+ data: { handle: 'reduce', from: this.from }
+ });
} else {
uni.showToast({
title: result.data.msg,
@@ -680,21 +698,21 @@ export default {
var result = await vlogCommentCreate(pendingCommentObject);
console.log(result);
if (result.data.status == 200) {
- var newCommentObject = result.data.data;
- newCommentObject.commentId = newCommentObject.id;
- newCommentObject.commentUserNickname = myUserInfo.nickname;
- newCommentObject.commentUserFace = myUserInfo.face;
- newCommentObject.isLike = 0;
- newCommentObject.vlogerId = userId;
- newCommentObject.createTime = new Date().getTime();
+ // var newCommentObject = result.data.data;
+ // newCommentObject.commentId = newCommentObject.id;
+ // newCommentObject.commentUserNickname = myUserInfo.nickname;
+ // newCommentObject.commentUserFace = myUserInfo.face;
+ // newCommentObject.isLike = 0;
+ // newCommentObject.vlogerId = userId;
+ // // var timeStr = dateFormat('YYYY-MM-DD HH:mm:ss', new Date());
+ // // newCommentObject.createTime = timeStr;
- me.doCommentPagingList(1, true);
+ // // 评论/回复完毕后,回复thisFatherCommentId为“0”
+ // me.thisFatherCommentId = '0';
- // 评论/回复完毕后,回复thisFatherCommentId为“0”
- me.thisFatherCommentId = '0';
+ // // 把新评论添加到第一个位置,弱一致性,不需要从数据库里再去取
+ // me.commentList.unshift(newCommentObject);
- // 把新评论添加到第一个位置,弱一致性,不需要从数据库里再去取
- me.commentList.unshift(newCommentObject);
// 清空文本框
me.currentComment = '';
// 隐藏键盘
@@ -707,6 +725,11 @@ export default {
me.$nextTick(() => {
me.scrollTop = 0; //赋值为0即代表返回顶部
});
+ // 刷新评论数量+1
+ this.channelComment.postMessage({
+ type: 'comment-counts',
+ data: { handle: 'add', from: this.from }
+ });
} else {
uni.showToast({
title: result.data.msg,
@@ -716,26 +739,14 @@ export default {
}
me.freshCommentCounts();
-
- // uni.request({
- // method: "POST",
- // header: {
- // headerUserId: userId,
- // headerUserToken: app.getUserSessionToken()
- // },
- // url: serverUrl + "/comment/create",
- // data: pendingCommentObject,
- // success(result) {
-
- // }
- // });
+ me.doCommentPagingList(1, true);
},
// 把超过1000或10000的数字调整,比如1.3k/6.8w
getGraceNumber(num) {
return graceNumber(num);
},
// 时间显示 刚刚/xx小时前/...
- getGraceDateBeforeNow(dateTimeStr) {
+ getGraceDateBeforeNow(dateTimeStr = '') {
// var date = dateFormat('YYYY-MM-DD HH:mm:ss', new Date(dateTimeStr));
return getDateBeforeNow(dateTimeStr);
},
diff --git a/utils/tools.js b/utils/tools.js
index d0287f36..71f2b7bf 100644
--- a/utils/tools.js
+++ b/utils/tools.js
@@ -121,33 +121,71 @@ const graceNumber = (number) => {
// 时间格式化时间为: 多少分钟前、多少天前
// time 2020-09-10 20:20:20
-const getDateBeforeNow = (stringTime) => {
- stringTime = new Date(stringTime.replace(/-/g, "/"));
- let minute = 1000 * 60;
- let hour = minute * 60;
- let day = hour * 24;
- let week = day * 7;
- let month = day * 30;
- let time1 = new Date().getTime(); //当前的时间戳
- let time2 = Date.parse(new Date(stringTime)); //指定时间的时间戳
- let time = time1 - time2;
+const getDateBeforeNow = (stringTime = '') => {
+ const minute = 1000 * 60;
+ const hour = minute * 60;
+ const day = hour * 24;
+ const week = day * 7;
+ const month = day * 30;
+
+ // 获取当前时间戳
+ const currentTime = new Date().getTime();
+
+ // 如果没有传入时间参数,使用当前时间
+ const time = stringTime ? new Date(stringTime.replace(/-/g, "/")).getTime() : currentTime;
+
+ const difference = currentTime - time; // 计算时间差
+
let result = null;
- if (time < 0) {
+
+ // 如果时间差小于0(未来的时间),返回原始时间
+ if (difference < 0) {
result = stringTime;
- } else if (time / month >= 1) {
- result = parseInt(time / month) + "月前";
- } else if (time / week >= 1) {
- result = parseInt(time / week) + "周前";
- } else if (time / day >= 1) {
- result = parseInt(time / day) + "天前";
- } else if (time / hour >= 1) {
- result = parseInt(time / hour) + "小时前";
- } else if (time / minute >= 1) {
- result = parseInt(time / minute) + "分钟前";
+ } else if (difference >= month) {
+ result = Math.floor(difference / month) + "月前";
+ } else if (difference >= week) {
+ result = Math.floor(difference / week) + "周前";
+ } else if (difference >= day) {
+ result = Math.floor(difference / day) + "天前";
+ } else if (difference >= hour) {
+ result = Math.floor(difference / hour) + "小时前";
+ } else if (difference >= minute) {
+ result = Math.floor(difference / minute) + "分钟前";
} else {
result = "刚刚";
}
+
return result;
+ // let minute = 1000 * 60;
+ // let hour = minute * 60;
+ // let day = hour * 24;
+ // let week = day * 7;
+ // let month = day * 30;
+ // let time1 = new Date().getTime(); //当前的时间戳
+ // if (stringTime == '') {
+ // stringTime = time1
+ // } else {
+ // stringTime = new Date(stringTime.replace(/-/g, "/"));
+ // }
+ // let time2 = Date.parse(new Date(stringTime)); //指定时间的时间戳
+ // let time = time1 - time2;
+ // let result = null;
+ // if (time < 0) {
+ // result = stringTime;
+ // } else if (time / month >= 1) {
+ // result = parseInt(time / month) + "月前";
+ // } else if (time / week >= 1) {
+ // result = parseInt(time / week) + "周前";
+ // } else if (time / day >= 1) {
+ // result = parseInt(time / day) + "天前";
+ // } else if (time / hour >= 1) {
+ // result = parseInt(time / hour) + "小时前";
+ // } else if (time / minute >= 1) {
+ // result = parseInt(time / minute) + "分钟前";
+ // } else {
+ // result = "刚刚";
+ // }
+ // return result;
}
// 判断是否为空
const isStrEmpty = (str) => {