|
@@ -6,7 +6,7 @@
|
|
|
class="avatar"
|
|
class="avatar"
|
|
|
:src="user.avatar || ''"
|
|
:src="user.avatar || ''"
|
|
|
@error="(e) => e.target.classList.add('error')"
|
|
@error="(e) => e.target.classList.add('error')"
|
|
|
- />
|
|
|
|
|
|
|
+ >
|
|
|
</comment-form>
|
|
</comment-form>
|
|
|
|
|
|
|
|
<!-- 底部评论列表 -->
|
|
<!-- 底部评论列表 -->
|
|
@@ -38,33 +38,41 @@
|
|
|
|
|
|
|
|
<!-- 单条评论下的回复列表 -->
|
|
<!-- 单条评论下的回复列表 -->
|
|
|
<template #subList="{ parentId }">
|
|
<template #subList="{ parentId }">
|
|
|
- <comment-list sub>
|
|
|
|
|
- <!-- 单条回复 -->
|
|
|
|
|
- <comment-item
|
|
|
|
|
- v-for="(child, j) in comment.children"
|
|
|
|
|
- :id="`${parentId}-${j}`"
|
|
|
|
|
- :key="`${parentId}-${j}`"
|
|
|
|
|
- :ref="`${parentId}-${j}`"
|
|
|
|
|
- :comment="child"
|
|
|
|
|
- :user="user"
|
|
|
|
|
- :parent="comment"
|
|
|
|
|
- @comment-reply="hasForm"
|
|
|
|
|
- @comment-like="handleCommentLike"
|
|
|
|
|
- @comment-delete="handleCommentDelete"
|
|
|
|
|
- >
|
|
|
|
|
- <!-- 单条回复的回复表单 -->
|
|
|
|
|
- <comment-form
|
|
|
|
|
- v-if="forms.includes(`${parentId}-${j}`)"
|
|
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <comment-list sub>
|
|
|
|
|
+ <!-- 单条回复 -->
|
|
|
|
|
+ <comment-item
|
|
|
|
|
+ v-for="(child, j) in comment.children"
|
|
|
:id="`${parentId}-${j}`"
|
|
:id="`${parentId}-${j}`"
|
|
|
|
|
+ :key="`${parentId}-${j}`"
|
|
|
|
|
+ :ref="`${parentId}-${j}`"
|
|
|
:comment="child"
|
|
:comment="child"
|
|
|
|
|
+ :user="user"
|
|
|
:parent="comment"
|
|
:parent="comment"
|
|
|
- :placeholder="`回复${child.user && child.user.name}...`"
|
|
|
|
|
- :upload-img="uploadImg"
|
|
|
|
|
- @form-delete="deleteForm"
|
|
|
|
|
- @form-submit="formSubmit"
|
|
|
|
|
- />
|
|
|
|
|
- </comment-item>
|
|
|
|
|
- </comment-list>
|
|
|
|
|
|
|
+ @comment-reply="hasForm"
|
|
|
|
|
+ @comment-like="handleCommentLike"
|
|
|
|
|
+ @comment-delete="handleCommentDelete"
|
|
|
|
|
+ >
|
|
|
|
|
+ <!-- 单条回复的回复表单 -->
|
|
|
|
|
+ <comment-form
|
|
|
|
|
+ v-if="forms.includes(`${parentId}-${j}`)"
|
|
|
|
|
+ :id="`${parentId}-${j}`"
|
|
|
|
|
+ :comment="child"
|
|
|
|
|
+ :parent="comment"
|
|
|
|
|
+ :placeholder="`回复${child.user && child.user.name}...`"
|
|
|
|
|
+ :upload-img="uploadImg"
|
|
|
|
|
+ @form-delete="deleteForm"
|
|
|
|
|
+ @form-submit="formSubmit"
|
|
|
|
|
+ />
|
|
|
|
|
+ </comment-item>
|
|
|
|
|
+ </comment-list>
|
|
|
|
|
+ <v-pagination
|
|
|
|
|
+ v-model="page"
|
|
|
|
|
+ :length="length"
|
|
|
|
|
+ :total-visible="7"
|
|
|
|
|
+ @input="pageChange"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
</template>
|
|
</template>
|
|
|
</comment-item>
|
|
</comment-item>
|
|
|
</comment-list>
|
|
</comment-list>
|
|
@@ -81,51 +89,54 @@ export default {
|
|
|
inheritAttrs: false,
|
|
inheritAttrs: false,
|
|
|
model: {
|
|
model: {
|
|
|
prop: 'data',
|
|
prop: 'data',
|
|
|
- event: 'input',
|
|
|
|
|
|
|
+ event: 'input'
|
|
|
},
|
|
},
|
|
|
props: {
|
|
props: {
|
|
|
/* 数据 */
|
|
/* 数据 */
|
|
|
data: {
|
|
data: {
|
|
|
type: Array,
|
|
type: Array,
|
|
|
default: () => [],
|
|
default: () => [],
|
|
|
- required: true,
|
|
|
|
|
|
|
+ required: true
|
|
|
},
|
|
},
|
|
|
/* 当前用户 */
|
|
/* 当前用户 */
|
|
|
user: {
|
|
user: {
|
|
|
type: Object,
|
|
type: Object,
|
|
|
default: () => {},
|
|
default: () => {},
|
|
|
- required: true,
|
|
|
|
|
|
|
+ required: true
|
|
|
},
|
|
},
|
|
|
/* 配置属性 */
|
|
/* 配置属性 */
|
|
|
props: {
|
|
props: {
|
|
|
type: Object,
|
|
type: Object,
|
|
|
- default: () => {},
|
|
|
|
|
|
|
+ default: () => {}
|
|
|
},
|
|
},
|
|
|
/* 提交表单前事件 */
|
|
/* 提交表单前事件 */
|
|
|
beforeSubmit: {
|
|
beforeSubmit: {
|
|
|
type: Function,
|
|
type: Function,
|
|
|
- required: true,
|
|
|
|
|
|
|
+ required: true
|
|
|
},
|
|
},
|
|
|
/* 执行点赞前事件 */
|
|
/* 执行点赞前事件 */
|
|
|
beforeLike: {
|
|
beforeLike: {
|
|
|
type: Function,
|
|
type: Function,
|
|
|
- required: true,
|
|
|
|
|
|
|
+ required: true
|
|
|
},
|
|
},
|
|
|
/* 执行删除前事件 */
|
|
/* 执行删除前事件 */
|
|
|
beforeDelete: {
|
|
beforeDelete: {
|
|
|
type: Function,
|
|
type: Function,
|
|
|
- required: true,
|
|
|
|
|
|
|
+ required: true
|
|
|
},
|
|
},
|
|
|
/* 上传图片 */
|
|
/* 上传图片 */
|
|
|
uploadImg: {
|
|
uploadImg: {
|
|
|
type: Function,
|
|
type: Function,
|
|
|
- required: true,
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ required: true
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
forms: [], // 显示在视图上的所有表单 id
|
|
forms: [], // 显示在视图上的所有表单 id
|
|
|
cacheData: [],
|
|
cacheData: [],
|
|
|
|
|
+ page: 1,
|
|
|
|
|
+ currentPage: 1,
|
|
|
|
|
+ length: 0
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
computed: {
|
|
computed: {
|
|
@@ -133,7 +144,7 @@ export default {
|
|
|
if (!props) return null
|
|
if (!props) return null
|
|
|
const entries = Object.entries(props)
|
|
const entries = Object.entries(props)
|
|
|
return entries.length > 0 ? entries : null
|
|
return entries.length > 0 ? entries : null
|
|
|
- },
|
|
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
created() {
|
|
created() {
|
|
|
// 监听并执行一次
|
|
// 监听并执行一次
|
|
@@ -162,7 +173,7 @@ export default {
|
|
|
reply: null,
|
|
reply: null,
|
|
|
createAt: null,
|
|
createAt: null,
|
|
|
user: {},
|
|
user: {},
|
|
|
- liked: false,
|
|
|
|
|
|
|
+ liked: false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 赋值
|
|
// 赋值
|
|
@@ -185,32 +196,32 @@ export default {
|
|
|
validate({ key, value }) {
|
|
validate({ key, value }) {
|
|
|
const map = {
|
|
const map = {
|
|
|
user: {
|
|
user: {
|
|
|
- validate: function (v) {
|
|
|
|
|
|
|
+ validate: function(v) {
|
|
|
return (
|
|
return (
|
|
|
(typeof v !== 'object' || JSON.stringify(v) === '{}') &&
|
|
(typeof v !== 'object' || JSON.stringify(v) === '{}') &&
|
|
|
this.message
|
|
this.message
|
|
|
)
|
|
)
|
|
|
},
|
|
},
|
|
|
- message: 'User must be an object with props.',
|
|
|
|
|
|
|
+ message: 'User must be an object with props.'
|
|
|
},
|
|
},
|
|
|
reply: {
|
|
reply: {
|
|
|
- validate: function (v) {
|
|
|
|
|
|
|
+ validate: function(v) {
|
|
|
return typeof v !== 'object' && this.message
|
|
return typeof v !== 'object' && this.message
|
|
|
},
|
|
},
|
|
|
- message: 'Reply must be an object',
|
|
|
|
|
|
|
+ message: 'Reply must be an object'
|
|
|
},
|
|
},
|
|
|
children: {
|
|
children: {
|
|
|
- validate: function (v) {
|
|
|
|
|
|
|
+ validate: function(v) {
|
|
|
return !Array.isArray(v) && this.message
|
|
return !Array.isArray(v) && this.message
|
|
|
},
|
|
},
|
|
|
- message: 'Children must be an array',
|
|
|
|
|
|
|
+ message: 'Children must be an array'
|
|
|
},
|
|
},
|
|
|
createAt: {
|
|
createAt: {
|
|
|
- validate: function () {
|
|
|
|
|
|
|
+ validate: function() {
|
|
|
return new Date(value).toString() === 'Invalid Date' && this.message
|
|
return new Date(value).toString() === 'Invalid Date' && this.message
|
|
|
},
|
|
},
|
|
|
- message: 'CreateAt is not a valid date.',
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ message: 'CreateAt is not a valid date.'
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const target = map[key]
|
|
const target = map[key]
|
|
@@ -276,7 +287,7 @@ export default {
|
|
|
*/
|
|
*/
|
|
|
async formSubmit({
|
|
async formSubmit({
|
|
|
newComment: { id, callback, ...params },
|
|
newComment: { id, callback, ...params },
|
|
|
- parent = null,
|
|
|
|
|
|
|
+ parent = null
|
|
|
}) {
|
|
}) {
|
|
|
const _params = Object.assign(params, { user: this.user })
|
|
const _params = Object.assign(params, { user: this.user })
|
|
|
|
|
|
|
@@ -297,7 +308,7 @@ export default {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- async handleCommentLike({ id, comment: { children, ...params } }) {
|
|
|
|
|
|
|
+ async handleCommentLike({ id, comment: { children, ...params }}) {
|
|
|
const _params = Object.assign(params, { user: this.user })
|
|
const _params = Object.assign(params, { user: this.user })
|
|
|
if (typeof this.beforeLike === 'function') {
|
|
if (typeof this.beforeLike === 'function') {
|
|
|
try {
|
|
try {
|
|
@@ -369,8 +380,8 @@ export default {
|
|
|
commentIndex === 'root'
|
|
commentIndex === 'root'
|
|
|
? this.cacheData.length - 1
|
|
? this.cacheData.length - 1
|
|
|
: `${commentIndex}-${
|
|
: `${commentIndex}-${
|
|
|
- this.cacheData[commentIndex].children.length - 1
|
|
|
|
|
- }`
|
|
|
|
|
|
|
+ this.cacheData[commentIndex].children.length - 1
|
|
|
|
|
+ }`
|
|
|
this.scrollIntoView(`comment-${signal}`)
|
|
this.scrollIntoView(`comment-${signal}`)
|
|
|
|
|
|
|
|
// 更新外部数据
|
|
// 更新外部数据
|
|
@@ -430,7 +441,13 @@ export default {
|
|
|
this.$refs[ref][0].$el.scrollIntoView(false)
|
|
this.$refs[ref][0].$el.scrollIntoView(false)
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- },
|
|
|
|
|
|
|
+ pageChange(page) {
|
|
|
|
|
+ if (page !== this.currentPage) {
|
|
|
|
|
+ this.currentPage = page
|
|
|
|
|
+ console.log('获取下一页子评论')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|