修复小芸源评论的翻页加载问题
parent
784d2fda6d
commit
0baaffdad8
|
@ -18,7 +18,7 @@ div(:class="$style.comment")
|
||||||
material-comment-floor(v-if="!isHotLoadError && hotComments.length" :class="[$style.commentFloor, isHotLoading ? $style.loading : null]" :comments="hotComments")
|
material-comment-floor(v-if="!isHotLoadError && hotComments.length" :class="[$style.commentFloor, isHotLoading ? $style.loading : null]" :comments="hotComments")
|
||||||
p(:class="$style.commentLabel" v-else-if="!isHotLoadError && !isHotLoading") {{$t('core.player.comment_no_content')}}
|
p(:class="$style.commentLabel" v-else-if="!isHotLoadError && !isHotLoading") {{$t('core.player.comment_no_content')}}
|
||||||
div
|
div
|
||||||
h2(:class="$style.commentType") {{$t('core.player.comment_new_title')}}
|
h2(:class="$style.commentType") {{$t('core.player.comment_new_title')}} ({{total}})
|
||||||
p(:class="$style.commentLabel" style="cursor: pointer;" v-if="isNewLoadError" @click="handleGetNewComment(currentMusicInfo, nextPage, limit)") {{$t('core.player.comment_new_load_error')}}
|
p(:class="$style.commentLabel" style="cursor: pointer;" v-if="isNewLoadError" @click="handleGetNewComment(currentMusicInfo, nextPage, limit)") {{$t('core.player.comment_new_load_error')}}
|
||||||
p(:class="$style.commentLabel" v-else-if="isNewLoading && !newComments.length") {{$t('core.player.comment_new_loading')}}
|
p(:class="$style.commentLabel" v-else-if="isNewLoading && !newComments.length") {{$t('core.player.comment_new_loading')}}
|
||||||
material-comment-floor(v-if="!isNewLoadError && newComments.length" :class="[$style.commentFloor, isNewLoading ? $style.loading : null]" :comments="newComments")
|
material-comment-floor(v-if="!isNewLoadError && newComments.length" :class="[$style.commentFloor, isNewLoading ? $style.loading : null]" :comments="newComments")
|
||||||
|
@ -137,6 +137,7 @@ export default {
|
||||||
scrollTo(this.$refs.dom_comment, 0, 300)
|
scrollTo(this.$refs.dom_comment, 0, 300)
|
||||||
})
|
})
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
console.log(err)
|
||||||
if (err.message == '取消请求') return
|
if (err.message == '取消请求') return
|
||||||
this.isNewLoadError = true
|
this.isNewLoadError = true
|
||||||
this.isNewLoading = false
|
this.isNewLoading = false
|
||||||
|
@ -149,6 +150,7 @@ export default {
|
||||||
this.isHotLoading = false
|
this.isHotLoading = false
|
||||||
this.hotComments = hotComment.comments
|
this.hotComments = hotComment.comments
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
console.log(err)
|
||||||
if (err.message == '取消请求') return
|
if (err.message == '取消请求') return
|
||||||
this.isHotLoadError = true
|
this.isHotLoadError = true
|
||||||
this.isHotLoading = false
|
this.isHotLoading = false
|
||||||
|
@ -156,12 +158,12 @@ export default {
|
||||||
},
|
},
|
||||||
handleShowComment() {
|
handleShowComment() {
|
||||||
if (!this.musicInfo.songmid || !music[this.musicInfo.source].comment) return
|
if (!this.musicInfo.songmid || !music[this.musicInfo.source].comment) return
|
||||||
if (this.musicInfo.songmid != this.currentMusicInfo.songmid) {
|
// if (this.musicInfo.songmid != this.currentMusicInfo.songmid) {
|
||||||
this.page = 1
|
this.page = 1
|
||||||
this.total = 0
|
this.total = 0
|
||||||
this.maxPage = 1
|
this.maxPage = 1
|
||||||
this.nextPage = 1
|
this.nextPage = 1
|
||||||
}
|
// }
|
||||||
this.isShowComment = true
|
this.isShowComment = true
|
||||||
this.currentMusicInfo = this.musicInfo
|
this.currentMusicInfo = this.musicInfo
|
||||||
|
|
||||||
|
@ -235,7 +237,7 @@ export default {
|
||||||
.commentType {
|
.commentType {
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: @color-theme_2-font;
|
color: @color-theme;
|
||||||
}
|
}
|
||||||
.commentFloor {
|
.commentFloor {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
@ -261,7 +263,7 @@ each(@themes, {
|
||||||
color: ~'@{color-@{value}-theme_2-font-label}';
|
color: ~'@{color-@{value}-theme_2-font-label}';
|
||||||
}
|
}
|
||||||
.commentType {
|
.commentType {
|
||||||
color: ~'@{color-@{value}-theme_2-font}';
|
color: ~'@{color-@{value}-theme}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,50 +2,109 @@ import { httpFetch } from '../../request'
|
||||||
import { weapi } from './utils/crypto'
|
import { weapi } from './utils/crypto'
|
||||||
import { dateFormat2 } from '../../'
|
import { dateFormat2 } from '../../'
|
||||||
|
|
||||||
|
let cursorTools = {
|
||||||
|
cache: {},
|
||||||
|
getCursor(id, page, limit) {
|
||||||
|
let cacheData = this.cache[id]
|
||||||
|
if (!cacheData) cacheData = this.cache[id] = {}
|
||||||
|
let orderType
|
||||||
|
let cursor
|
||||||
|
let offset
|
||||||
|
if (page == 1) {
|
||||||
|
cacheData.page = 1
|
||||||
|
cursor = cacheData.cursor = cacheData.prevCursor = Date.now()
|
||||||
|
orderType = 1
|
||||||
|
offset = 0
|
||||||
|
} else if (cacheData.page) {
|
||||||
|
cursor = cacheData.cursor
|
||||||
|
if (page > cacheData.page) {
|
||||||
|
orderType = 1
|
||||||
|
offset = (page - cacheData.page - 1) * limit
|
||||||
|
} else if (page < cacheData.page) {
|
||||||
|
orderType = 0
|
||||||
|
offset = (cacheData.page - page - 1) * limit
|
||||||
|
} else {
|
||||||
|
cursor = cacheData.cursor = cacheData.prevCursor
|
||||||
|
offset = cacheData.offset
|
||||||
|
orderType = cacheData.orderType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
orderType,
|
||||||
|
cursor,
|
||||||
|
offset,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setCursor(id, cursor, orderType, offset, page) {
|
||||||
|
let cacheData = this.cache[id]
|
||||||
|
if (!cacheData) cacheData = this.cache[id] = {}
|
||||||
|
cacheData.prevCursor = cacheData.cursor
|
||||||
|
cacheData.cursor = cursor
|
||||||
|
cacheData.orderType = orderType
|
||||||
|
cacheData.offset = offset
|
||||||
|
cacheData.page = page
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
_requestObj: null,
|
_requestObj: null,
|
||||||
_requestObj2: null,
|
_requestObj2: null,
|
||||||
async getComment({ songmid }, page = 1, limit = 20) {
|
async getComment({ songmid }, page = 1, limit = 20) {
|
||||||
if (this._requestObj) this._requestObj.cancelHttp()
|
if (this._requestObj) this._requestObj.cancelHttp()
|
||||||
|
|
||||||
const _requestObj = httpFetch(`https://music.163.com/api/v1/resource/comments/R_SO_4_${songmid}`, {
|
const id = 'R_SO_4_' + songmid
|
||||||
|
|
||||||
|
const cursorInfo = cursorTools.getCursor(songmid, page, limit)
|
||||||
|
|
||||||
|
const _requestObj = httpFetch('https://music.163.com/weapi/comment/resource/comments/get', {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
|
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
|
||||||
origin: 'https://music.163.com',
|
origin: 'https://music.163.com',
|
||||||
|
Refere: 'http://music.163.com/',
|
||||||
},
|
},
|
||||||
form: weapi({
|
form: weapi({
|
||||||
rid: songmid,
|
cursor: cursorInfo.cursor,
|
||||||
limit: limit,
|
offset: cursorInfo.offset,
|
||||||
offset: (page - 1) * limit,
|
orderType: cursorInfo.orderType,
|
||||||
beforeTime: 0,
|
pageNo: page,
|
||||||
|
pageSize: limit,
|
||||||
|
rid: id,
|
||||||
|
threadId: id,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
const { body, statusCode } = await _requestObj.promise
|
const { body, statusCode } = await _requestObj.promise
|
||||||
|
// console.log(body)
|
||||||
if (statusCode != 200 || body.code !== 200) throw new Error('获取评论失败')
|
if (statusCode != 200 || body.code !== 200) throw new Error('获取评论失败')
|
||||||
console.log(body)
|
cursorTools.setCursor(songmid, body.data.cursor, cursorInfo.orderType, cursorInfo.offset, page)
|
||||||
return { source: 'wy', comments: this.filterComment(body.comments), total: body.total, page, limit, maxPage: Math.ceil(body.total / limit) || 1 }
|
return { source: 'wy', comments: this.filterComment(body.data.comments), total: body.data.totalCount, page, limit, maxPage: Math.ceil(body.data.totalCount / limit) || 1 }
|
||||||
},
|
},
|
||||||
async getHotComment({ songmid }, page = 1, limit = 100) {
|
async getHotComment({ songmid }, page = 1, limit = 100) {
|
||||||
if (this._requestObj2) this._requestObj2.cancelHttp()
|
if (this._requestObj2) this._requestObj2.cancelHttp()
|
||||||
|
|
||||||
const _requestObj2 = httpFetch(`https://music.163.com/api/v1/resource/comments/R_SO_4_${songmid}`, {
|
const id = 'R_SO_4_' + songmid
|
||||||
|
|
||||||
|
const _requestObj2 = httpFetch('https://music.163.com/weapi/comment/resource/comments/get', {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
|
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
|
||||||
origin: 'https://music.163.com',
|
origin: 'https://music.163.com',
|
||||||
|
Refere: 'http://music.163.com/',
|
||||||
},
|
},
|
||||||
form: weapi({
|
form: weapi({
|
||||||
rid: songmid,
|
cursor: Date.now().toString(),
|
||||||
limit: limit,
|
offset: 0,
|
||||||
offset: (page - 1) * limit,
|
orderType: 1,
|
||||||
beforeTime: 0,
|
pageNo: page,
|
||||||
|
pageSize: limit,
|
||||||
|
rid: id,
|
||||||
|
threadId: id,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
const { body, statusCode } = await _requestObj2.promise
|
const { body, statusCode } = await _requestObj2.promise
|
||||||
if (statusCode != 200 || body.code !== 200) throw new Error('获取热门评论失败')
|
if (statusCode != 200 || body.code !== 200) throw new Error('获取热门评论失败')
|
||||||
// console.log(body)
|
// console.log(body)
|
||||||
return { source: 'wy', comments: this.filterComment(body.hotComments) }
|
return { source: 'wy', comments: this.filterComment(body.data.hotComments) }
|
||||||
},
|
},
|
||||||
filterComment(rawList) {
|
filterComment(rawList) {
|
||||||
return rawList.map(item => {
|
return rawList.map(item => {
|
||||||
|
@ -60,12 +119,13 @@ export default {
|
||||||
likedCount: item.likedCount,
|
likedCount: item.likedCount,
|
||||||
reply: [],
|
reply: [],
|
||||||
}
|
}
|
||||||
let replyData = item.beReplied[0]
|
|
||||||
|
let replyData = item.beReplied && item.beReplied[0]
|
||||||
return replyData ? {
|
return replyData ? {
|
||||||
id: item.commentId,
|
id: item.commentId,
|
||||||
rootId: replyData.beRepliedCommentId,
|
rootId: replyData.beRepliedCommentId,
|
||||||
text: replyData.content ? replyData.content.split('\n') : '',
|
text: replyData.content ? replyData.content.split('\n') : '',
|
||||||
time: null,
|
time: item.time,
|
||||||
timeStr: null,
|
timeStr: null,
|
||||||
userName: replyData.user.nickname,
|
userName: replyData.user.nickname,
|
||||||
avatar: replyData.user.avatarUrl,
|
avatar: replyData.user.avatarUrl,
|
||||||
|
|
Loading…
Reference in New Issue