This commit is contained in:
zzc
2026-06-01 16:18:27 +08:00
parent 99bc334d0b
commit ca1585962b
2 changed files with 154 additions and 2 deletions

View File

@@ -0,0 +1,146 @@
<template>
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="600px" @close="close">
<el-form ref="form" label-width="100px" :model="form" :rules="rules">
<el-form-item label="选择机器人" prop="userId">
<el-select
v-model="form.userId"
v-loadmore="loadMoreRobots"
filterable
placeholder="请选择评价机器人"
:popper-append-to-body="false"
style="width: 100%"
>
<el-option v-for="item in robotList" :key="item.id" :label="item.nickname" :value="item.id">
<div style="display: flex; align-items: center">
<el-image
v-if="item.avatar"
:src="getThumbUrl(item.avatar)"
style="width: 24px; height: 24px; border-radius: 50%; margin-right: 10px"
/>
<span>{{ item.nickname }}</span>
</div>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="评论内容" prop="content">
<el-input v-model="form.content" maxlength="500" placeholder="请输入评论内容" :rows="4" show-word-limit type="textarea" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="close"> </el-button>
<el-button :loading="loading" type="primary" @click="save"> </el-button>
</div>
</el-dialog>
</template>
<script>
import { getListBase as getRobotList } from '@/api/system/robot'
import { comment } from '@/api/rating/topicOperate'
import { getThumbUrl } from '@/utils/blessing'
export default {
name: 'TopicItemCommentEdit',
directives: {
loadmore: {
bind(el, binding) {
setTimeout(() => {
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
if (SELECTWRAP_DOM) {
SELECTWRAP_DOM.addEventListener('scroll', function () {
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 2
if (condition) {
binding.value()
}
})
}
}, 0)
},
},
},
data() {
return {
title: '评价项评论',
dialogFormVisible: false,
loading: false,
form: {
topicId: '',
itemId: '',
content: '',
userId: '',
},
rules: {
userId: [{ required: true, trigger: 'change', message: '请选择评价机器人' }],
content: [{ required: true, trigger: 'blur', message: '请输入评论内容' }],
},
robotList: [],
robotQuery: {
pageNo: 1,
pageSize: 20,
appId: '6a0d7dbe4c5de50f2ba66475',
},
robotTotal: 0,
fetchingRobots: false,
}
},
methods: {
getThumbUrl,
async showEdit(row, topicId) {
this.title = `${row.name} 写评论`
this.form = this.$options.data().form
this.form.topicId = topicId
this.form.itemId = row.id
this.dialogFormVisible = true
this.robotQuery.pageNo = 1
this.robotList = []
this.robotTotal = 0
await this.fetchRobotList()
},
close() {
this.$refs['form'].resetFields()
this.form = this.$options.data().form
this.robotList = []
this.dialogFormVisible = false
},
async fetchRobotList() {
if (this.fetchingRobots) return
this.fetchingRobots = true
try {
const { data } = await getRobotList(this.robotQuery)
this.robotList = this.robotList.concat(data.list || [])
this.robotTotal = data.totalCount || 0
} catch (error) {
console.error(error)
} finally {
this.fetchingRobots = false
}
},
loadMoreRobots() {
if (this.robotList.length >= this.robotTotal || this.fetchingRobots) {
return
}
this.robotQuery.pageNo += 1
this.fetchRobotList()
},
save() {
this.$refs['form'].validate(async (valid) => {
if (valid) {
this.loading = true
try {
const { msg } = await comment(this.form)
this.$baseMessage(msg || '评论成功', 'success')
this.close()
this.$emit('fetch-data')
} catch (error) {
console.error(error)
} finally {
this.loading = false
}
} else {
return false
}
})
},
},
}
</script>

View File

@@ -31,9 +31,10 @@
/> />
<el-table v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText"> <el-table v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText">
<el-table-column align="center" fixed="left" label="操作" width="100"> <el-table-column align="center" fixed="left" label="操作" width="120">
<template #default="{ row }"> <template #default="{ row }">
<el-button type="text" @click="handleRating(row)">评价</el-button> <el-button type="text" @click="handleRating(row)">评价</el-button>
<el-button type="text" @click="handleComment(row)">评论</el-button>
</template> </template>
</el-table-column> </el-table-column>
@@ -138,6 +139,7 @@
/> />
<topic-item-rating-edit ref="ratingEdit" @fetch-data="fetchData" /> <topic-item-rating-edit ref="ratingEdit" @fetch-data="fetchData" />
<topic-item-comment-edit ref="commentEdit" @fetch-data="fetchData" />
</div> </div>
</template> </template>
@@ -147,10 +149,11 @@
import { formatTime } from '@/utils' import { formatTime } from '@/utils'
import { getThumbUrl } from '@/utils/blessing' import { getThumbUrl } from '@/utils/blessing'
import TopicItemRatingEdit from './components/TopicItemRatingEdit' import TopicItemRatingEdit from './components/TopicItemRatingEdit'
import TopicItemCommentEdit from './components/TopicItemCommentEdit'
export default { export default {
name: 'RatingTopicItemIndex', name: 'RatingTopicItemIndex',
components: { TopicItemRatingEdit }, components: { TopicItemRatingEdit, TopicItemCommentEdit },
data() { data() {
return { return {
list: [], list: [],
@@ -229,6 +232,9 @@
handleRating(row) { handleRating(row) {
this.$refs['ratingEdit'].showEdit(row, this.queryForm.topicId) this.$refs['ratingEdit'].showEdit(row, this.queryForm.topicId)
}, },
handleComment(row) {
this.$refs['commentEdit'].showEdit(row, this.queryForm.topicId)
},
}, },
} }
</script> </script>