This commit is contained in:
133
src/views/rating/pk/list/components/PkParticipantList.vue
Normal file
133
src/views/rating/pk/list/components/PkParticipantList.vue
Normal file
@@ -0,0 +1,133 @@
|
||||
<template>
|
||||
<el-dialog :title="title" :visible.sync="dialogVisible" width="500px" @close="close">
|
||||
<el-table v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText">
|
||||
<el-table-column align="left" label="投票用户" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<div class="user-info-cell">
|
||||
<el-image v-if="row.avatar" class="user-avatar" :preview-src-list="[row.avatar]" :src="getThumbUrl(row.avatar)" />
|
||||
<div v-else class="user-avatar-placeholder"><i class="el-icon-user" /></div>
|
||||
<div class="user-details">
|
||||
<div class="user-nickname">{{ row.nickname || '未知用户' }}</div>
|
||||
<div class="user-id">{{ row.id }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-pagination
|
||||
background
|
||||
:current-page="queryForm.pageNo"
|
||||
:layout="layout"
|
||||
:page-size="queryForm.pageSize"
|
||||
:total="total"
|
||||
@current-change="handleCurrentChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getParticipantList } from '@/api/rating/pk'
|
||||
import { getThumbUrl } from '@/utils/blessing'
|
||||
|
||||
export default {
|
||||
name: 'PkParticipantList',
|
||||
data() {
|
||||
return {
|
||||
title: '投票用户列表',
|
||||
dialogVisible: false,
|
||||
list: [],
|
||||
listLoading: false,
|
||||
layout: 'total, prev, pager, next',
|
||||
total: 0,
|
||||
elementLoadingText: '正在加载...',
|
||||
queryForm: {
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
pkId: '',
|
||||
chooseItemId: '',
|
||||
},
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getThumbUrl,
|
||||
show(pkId, chooseItemId, titlePrefix) {
|
||||
this.title = `${titlePrefix}的投票用户`
|
||||
this.queryForm.pkId = pkId
|
||||
this.queryForm.chooseItemId = chooseItemId
|
||||
this.queryForm.pageNo = 1
|
||||
this.dialogVisible = true
|
||||
this.fetchData()
|
||||
},
|
||||
close() {
|
||||
this.dialogVisible = false
|
||||
this.list = []
|
||||
},
|
||||
handleSizeChange(val) {
|
||||
this.queryForm.pageSize = val
|
||||
this.fetchData()
|
||||
},
|
||||
handleCurrentChange(val) {
|
||||
this.queryForm.pageNo = val
|
||||
this.fetchData()
|
||||
},
|
||||
async fetchData() {
|
||||
this.listLoading = true
|
||||
try {
|
||||
const { data } = await getParticipantList(this.queryForm)
|
||||
this.list = data.list || []
|
||||
this.total = data.totalCount || 0
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
this.listLoading = false
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.user-info-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.user-avatar,
|
||||
.user-avatar-placeholder {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
margin-right: 10px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.user-avatar-placeholder {
|
||||
background-color: #f0f2f5;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #909399;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.user-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.user-nickname {
|
||||
font-weight: bold;
|
||||
color: #303133;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.user-id {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
</style>
|
||||
138
src/views/rating/pk/list/components/PkVoteEdit.vue
Normal file
138
src/views/rating/pk/list/components/PkVoteEdit.vue
Normal file
@@ -0,0 +1,138 @@
|
||||
<template>
|
||||
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close">
|
||||
<el-form ref="form" label-width="80px" :model="form" :rules="rules">
|
||||
<el-form-item label="支持项">
|
||||
<span style="font-weight: bold; color: #409eff">{{ targetName }}</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="投票用户" prop="userId">
|
||||
<el-select v-model="form.userId" v-loadmore="loadMoreRobots" filterable placeholder="请选择投票的机器人" style="width: 100%">
|
||||
<el-option v-for="item in robotList" :key="item.id" :label="item.nickname || item.id" :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>
|
||||
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="close">取 消</el-button>
|
||||
<el-button :loading="saving" type="primary" @click="save">确 定</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getListBase as getRobotList } from '@/api/system/robot'
|
||||
import { vote } from '@/api/rating/pk'
|
||||
import { getThumbUrl } from '@/utils/blessing'
|
||||
|
||||
export default {
|
||||
name: 'PkVoteEdit',
|
||||
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,
|
||||
saving: false,
|
||||
targetName: '',
|
||||
form: {
|
||||
pkId: '',
|
||||
itemId: '',
|
||||
userId: '',
|
||||
},
|
||||
rules: {
|
||||
userId: [{ required: true, trigger: 'change', message: '请选择投票的机器人' }],
|
||||
},
|
||||
|
||||
// 机器人下拉列表状态
|
||||
robotList: [],
|
||||
robotQuery: {
|
||||
appId: '6a0d7dbe4c5de50f2ba66475',
|
||||
pageNo: 1,
|
||||
pageSize: 20,
|
||||
},
|
||||
robotTotal: 0,
|
||||
fetchingRobots: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getThumbUrl,
|
||||
showEdit(pkId, itemId, itemName) {
|
||||
this.dialogFormVisible = true
|
||||
this.targetName = itemName
|
||||
this.form = this.$options.data().form
|
||||
this.form.pkId = pkId
|
||||
this.form.itemId = itemId
|
||||
|
||||
// 重置列表并加载第一页
|
||||
this.robotList = []
|
||||
this.robotQuery.pageNo = 1
|
||||
this.robotTotal = 0
|
||||
this.fetchRobotList()
|
||||
},
|
||||
close() {
|
||||
this.$refs['form'].resetFields()
|
||||
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.saving = true
|
||||
try {
|
||||
const { msg } = await vote(this.form)
|
||||
this.$baseMessage(msg || '投票成功', 'success')
|
||||
this.close()
|
||||
this.$emit('fetch-data')
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
this.saving = false
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -51,9 +51,18 @@
|
||||
<el-image v-if="row.leftItemName && row.leftItemAvatar" class="pk-avatar" :src="getThumbUrl(row.leftItemAvatar)" />
|
||||
<span class="pk-name">{{ row.leftItemName ? row.leftItemName : '-' }}</span>
|
||||
<div class="pk-stats">
|
||||
<span class="pk-vote">{{ row.leftVoteCount || 0 }} 票</span>
|
||||
<span
|
||||
class="pk-vote"
|
||||
style="cursor: pointer; text-decoration: underline"
|
||||
@click="handleViewParticipants(row.id, row.leftItemId, row.leftItemName)"
|
||||
>
|
||||
{{ row.leftVoteCount || 0 }} 票
|
||||
</span>
|
||||
<span class="pk-rate">({{ calculateRate(row.leftVoteCount, row.voteCount) }})</span>
|
||||
</div>
|
||||
<div style="margin-top: 5px">
|
||||
<el-button plain size="mini" type="primary" @click="handleVote(row.id, row.leftItemId, row.leftItemName)">支持</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pk-vs-wrapper">
|
||||
<div class="pk-vs">VS</div>
|
||||
@@ -63,9 +72,18 @@
|
||||
<el-image v-if="row.rightItemName && row.rightItemAvatar" class="pk-avatar" :src="getThumbUrl(row.rightItemAvatar)" />
|
||||
<span class="pk-name">{{ row.rightItemName ? row.rightItemName : '-' }}</span>
|
||||
<div class="pk-stats">
|
||||
<span class="pk-vote">{{ row.rightVoteCount || 0 }} 票</span>
|
||||
<span
|
||||
class="pk-vote"
|
||||
style="cursor: pointer; text-decoration: underline"
|
||||
@click="handleViewParticipants(row.id, row.rightItemId, row.rightItemName)"
|
||||
>
|
||||
{{ row.rightVoteCount || 0 }} 票
|
||||
</span>
|
||||
<span class="pk-rate">({{ calculateRate(row.rightVoteCount, row.voteCount) }})</span>
|
||||
</div>
|
||||
<div style="margin-top: 5px">
|
||||
<el-button plain size="mini" type="primary" @click="handleVote(row.id, row.rightItemId, row.rightItemName)">支持</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -89,6 +107,8 @@
|
||||
/>
|
||||
|
||||
<pk-generate ref="generate" @fetch-data="fetchData" />
|
||||
<pk-participant-list ref="participantList" />
|
||||
<pk-vote-edit ref="voteEdit" @fetch-data="fetchData" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -99,10 +119,12 @@
|
||||
import { formatTime } from '@/utils'
|
||||
import { getThumbUrl } from '@/utils/blessing'
|
||||
import PkGenerate from './components/PkGenerate'
|
||||
import PkParticipantList from './components/PkParticipantList'
|
||||
import PkVoteEdit from './components/PkVoteEdit'
|
||||
|
||||
export default {
|
||||
name: 'RatingPkListIndex',
|
||||
components: { PkGenerate },
|
||||
components: { PkGenerate, PkParticipantList, PkVoteEdit },
|
||||
directives: {
|
||||
loadmore: {
|
||||
bind(el, binding) {
|
||||
@@ -253,6 +275,12 @@
|
||||
const rate = ((count || 0) / total) * 100
|
||||
return `${rate.toFixed(1)}%`
|
||||
},
|
||||
handleViewParticipants(pkId, chooseItemId, itemName) {
|
||||
this.$refs['participantList'].show(pkId, chooseItemId, itemName)
|
||||
},
|
||||
handleVote(pkId, itemId, itemName) {
|
||||
this.$refs['voteEdit'].showEdit(pkId, itemId, itemName)
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user