Include complete API and frontend sources for unified deployment

This commit is contained in:
Vladimir Kutkovoy committed 2026-11-18 07:44:20 +00:00
1 parent 627b0ae60e
commit d8fcae32b0
93 files changed
+53270 -3

No files matched your search

@@ -0,0 +1,369 @@
<template>
<div>
<NuxtLink to="/admin" class="back-link"><AppIcon name="back" :size="15" /> Кейсы</NuxtLink>
<div class="page-heading">
<div class="case-title">
<CaseIcon :src="task.icon" />
<h1>{{ task.name }}</h1>
</div>
<button class="button" type="button" @click="editCase">Изменить</button>
</div>
<p v-if="task.description" class="plain-description">{{ task.description }}</p>
<div class="section-heading">
<h2>Команды</h2>
<button class="button button-primary" type="button" @click="editTeam()">
<AppIcon name="plus" :size="16" /> Добавить команду
</button>
</div>
<div v-if="scoreError" class="form-error" role="alert">{{ scoreError }}</div>
<div class="panel">
<div class="table-scroll">
<table class="data-table">
<thead>
<tr>
<SortHeader
v-for="column in teamColumns"
:key="column.key"
:active="teamSortKey === column.key"
:direction="teamSortDirection"
@sort="sortTeamsBy(column.key)"
>{{ column.name }}</SortHeader
>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr v-for="team in sortedTeams" :key="team.id">
<td>
<strong>{{ team.name }}</strong>
<p v-if="team.description" class="table-description">{{ team.description }}</p>
<p
v-if="team.TeamInCase && team.TeamInCase.technicalComment"
class="table-description technical-comment-text"
>
Комментарий тех. эксперта: {{ team.TeamInCase.technicalComment }}
</p>
</td>
<td>
<input
class="score-input"
type="number"
min="0"
max="5"
step="1"
:value="implementation[team.id]"
:aria-label="'Качество реализации — ' + team.name"
:disabled="savingScores"
@input="setScore(implementation, team.id, $event)"
/>
</td>
<td>
<input
class="score-input"
type="number"
min="0"
max="5"
step="1"
:value="work[team.id]"
:aria-label="'Работа на хакатоне — ' + team.name"
:disabled="savingScores"
@input="setScore(work, team.id, $event)"
/>
</td>
<td>
<button
class="button button-sm"
type="button"
:aria-label="'Изменить команду ' + team.name"
@click="editTeam(team)"
>
Изменить
</button>
</td>
</tr>
<tr v-if="!task.teams.length">
<td colspan="4" class="table-empty">Команд пока нет.</td>
</tr>
</tbody>
</table>
</div>
</div>
<div v-if="task.teams.length" class="save-row">
<span class="muted">{{
task.users.length ? 'Оценки тех. экспертов · 0–5' : 'Сначала назначьте экспертов в разделе «Эксперты».'
}}</span
><button
class="button button-primary"
type="button"
:disabled="savingScores || !task.users.length"
@click="saveScores"
>
{{ savingScores ? 'Сохраняем…' : 'Сохранить оценки' }}
</button>
</div>
<div class="section-heading" style="margin-top: 32px">
<h2>Эксперты</h2>
<div ref="assignmentPicker" class="assignment-picker" @keydown.esc.prevent.stop="closeAssignments">
<button
ref="assignmentButton"
type="button"
class="button button-sm"
:aria-expanded="String(assignmentOpen)"
aria-controls="case-expert-picker"
:disabled="savingAssignments"
@click="toggleAssignments"
>
Назначить
</button>
<div v-if="assignmentOpen" id="case-expert-picker" class="assignment-dropdown">
<input
v-model="expertSearch"
class="text-input"
type="search"
aria-label="Найти эксперта"
placeholder="Найти эксперта"
/>
<p v-if="loadingAssignments" class="muted">Загрузка…</p>
<div v-else class="assignment-options">
<label v-for="user in filteredAssignmentUsers" :key="user.id" class="checkbox-row">
<input
type="checkbox"
:checked="isAssigned(user)"
:disabled="savingAssignments"
@change="setAssignment(user, $event)"
/>
<span
>{{ [user.lastName, user.firstName, user.middleName].filter(Boolean).join(' ')
}}{{ user.role === 'technical' ? ' · Технический эксперт' : '' }}</span
>
</label>
<p v-if="!filteredAssignmentUsers.length" class="muted">Эксперты не найдены.</p>
</div>
<div v-if="assignmentError" class="form-error" role="alert">{{ assignmentError }}</div>
</div>
</div>
</div>
<div class="panel">
<div v-for="user in task.users" :key="user.id" class="simple-row">
<span>{{ [user.lastName, user.firstName, user.middleName].filter(Boolean).join(' ') }}</span>
<span v-if="user.role === 'technical'" class="badge">Технический эксперт</span>
</div>
<div v-if="!task.users.length" class="table-empty">Эксперты не назначены.</div>
</div>
<FormDialog
v-if="editor"
:title="editor === 'case' ? 'Изменить кейс' : teamId ? 'Изменить команду' : 'Новая команда'"
:busy="saving"
@close="editor = null"
@save="save"
><label class="field" for="entityName"
><span>Название</span
><input id="entityName" v-model.trim="name" class="text-input" maxlength="255" required /></label
><label class="field" for="entityDescription"
><span>Описание</span
><textarea id="entityDescription" v-model.trim="description" class="text-input" maxlength="10000" rows="3" />
</label>
<CaseIconUpload v-if="editor === 'case'" v-model="icon" :disabled="saving" />
<div v-if="error" class="form-error" role="alert">{{ error }}</div></FormDialog
>
<div v-if="message" class="toast" role="status">{{ message }}</div>
</div>
</template>
<script>
export default {
name: 'CaseDetails',
async asyncData({ $axios, params, error }) {
const [{ cases }, { marks }] = await Promise.all([$axios.$get('/admin/cases'), $axios.$get('/admin')])
const task = cases.find(c => c.id === params.id)
if (!task) {
error({ statusCode: 404, message: 'Кейс не найден' })
return {}
}
return { task, implementation: marks.implementation, work: marks.work }
},
data() {
return {
task: { name: '', teams: [], users: [] },
implementation: {},
work: {},
editor: null,
teamId: null,
name: '',
description: '',
icon: null,
saving: false,
error: '',
savingScores: false,
scoreError: '',
message: '',
timer: null,
assignmentOpen: false,
assignmentUsers: [],
expertSearch: '',
loadingAssignments: false,
savingAssignments: false,
assignmentError: '',
teamSortKey: 'name',
teamSortDirection: 'asc',
teamColumns: [
{ key: 'name', name: 'Команда' },
{ key: 'implementation', name: 'Качество реализации (тех.)' },
{ key: 'work', name: 'Работа на хакатоне (тех.)' },
],
}
},
computed: {
sortedTeams() {
const direction = this.teamSortDirection === 'asc' ? 1 : -1
return [...this.task.teams].sort((a, b) => {
const nameOrder = a.name.localeCompare(b.name, 'ru', { numeric: true, sensitivity: 'base' })
if (this.teamSortKey === 'name') return direction * nameOrder
const left = this[this.teamSortKey][a.id]
const right = this[this.teamSortKey][b.id]
const leftMissing = left === null || left === undefined || left === ''
const rightMissing = right === null || right === undefined || right === ''
if (leftMissing || rightMissing) return leftMissing === rightMissing ? nameOrder : leftMissing ? 1 : -1
return direction * (Number(left) - Number(right)) || nameOrder
})
},
filteredAssignmentUsers() {
const search = this.expertSearch.trim().toLowerCase()
return this.assignmentUsers.filter(user =>
[user.lastName, user.firstName, user.middleName].filter(Boolean).join(' ').toLowerCase().includes(search)
)
},
},
mounted() {
document.addEventListener('click', this.assignmentOutsideClick)
},
beforeDestroy() {
clearTimeout(this.timer)
document.removeEventListener('click', this.assignmentOutsideClick)
},
methods: {
sortTeamsBy(key) {
this.teamSortDirection = this.teamSortKey === key && this.teamSortDirection === 'asc' ? 'desc' : 'asc'
this.teamSortKey = key
},
isAssigned(user) {
return user.cases.some(task => task.id === this.task.id)
},
closeAssignments() {
if (this.savingAssignments) return
this.assignmentOpen = false
this.$refs.assignmentButton?.focus()
},
assignmentOutsideClick(event) {
if (!this.savingAssignments && !this.$refs.assignmentPicker?.contains(event.target)) this.assignmentOpen = false
},
async toggleAssignments() {
this.assignmentOpen = !this.assignmentOpen
if (!this.assignmentOpen) return
this.expertSearch = ''
this.assignmentError = ''
this.loadingAssignments = true
try {
const { users } = await this.$axios.$get('/admin/users')
this.assignmentUsers = users.filter(user => !user.deletedAt)
} catch (e) {
this.assignmentUsers = []
this.assignmentError = 'Не удалось загрузить экспертов.'
} finally {
this.loadingAssignments = false
}
},
async setAssignment(user, event) {
if (this.savingAssignments) return
const checked = event.target.checked
const caseIds = user.cases.filter(task => task.id !== this.task.id).map(task => task.id)
if (checked) caseIds.push(this.task.id)
this.savingAssignments = true
this.assignmentError = ''
try {
await this.$axios.$put('/admin/users/' + user.id + '/cases', { caseIds })
user.cases = user.cases.filter(task => task.id !== this.task.id)
this.task.users = this.task.users.filter(expert => expert.id !== user.id)
if (checked) {
user.cases.push({ id: this.task.id, name: this.task.name })
const { id, firstName, lastName, middleName, login, role } = user
this.task.users.push({ id, firstName, lastName, middleName, login, role })
}
} catch (e) {
event.target.checked = this.isAssigned(user)
this.assignmentError = e.response?.data?.message || 'Не удалось сохранить назначение. Попробуйте ещё раз.'
} finally {
this.savingAssignments = false
}
},
async reload() {
const { cases } = await this.$axios.$get('/admin/cases')
this.task = cases.find(c => c.id === this.$route.params.id)
},
editCase() {
this.editor = 'case'
this.name = this.task.name
this.description = this.task.description
this.icon = this.task.icon || null
this.error = ''
},
editTeam(team) {
this.editor = 'team'
this.teamId = team?.id || null
this.name = team?.name || ''
this.description = team?.description || ''
this.error = ''
},
async save() {
if (this.saving || !this.name) return
this.saving = true
this.error = ''
try {
const body = { name: this.name, description: this.description || '' }
const base = '/admin/cases/' + this.task.id
if (this.editor === 'case') await this.$axios.$put(base, { ...body, icon: this.icon })
else if (this.teamId) await this.$axios.$put(base + '/teams/' + this.teamId, body)
else await this.$axios.$post(base + '/teams', body)
await this.reload()
this.editor = null
} catch (e) {
this.error = 'Не удалось сохранить изменения.'
} finally {
this.saving = false
}
},
setScore(target, id, event) {
const value =
event.target.value === '' ? '' : Math.min(5, Math.max(0, Math.round(Number(event.target.value) || 0)))
this.$set(target, id, value)
event.target.value = value
},
async saveScores() {
if (this.savingScores) return
this.scoreError = ''
const values = this.task.teams.map(team => ({
id: team.id,
implementation: this.implementation[team.id],
work: this.work[team.id],
}))
const filled = value => value !== '' && value !== undefined && value !== null
if (values.some(m => filled(m.implementation) !== filled(m.work))) {
this.scoreError = 'Заполните оба критерия для команды.'
return
}
this.savingScores = true
try {
await this.$axios.$post('/admin', { marks: values.filter(m => filled(m.implementation) && filled(m.work)) })
this.message = 'Оценки сохранены'
clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.message = ''
}, 3500)
} catch (e) {
this.scoreError = 'Не удалось сохранить оценки.'
} finally {
this.savingScores = false
}
},
},
}
</script>
@@ -0,0 +1,73 @@
<template>
<div>
<div class="page-heading">
<h1>Кейсы</h1>
<button class="button button-primary" type="button" @click="editing = true">
<AppIcon name="plus" :size="16" /> Добавить кейс
</button>
</div>
<div class="panel">
<NuxtLink v-for="task in cases" :key="task.id" :to="'/admin/cases/' + task.id" class="simple-row"
><div class="case-row-label">
<CaseIcon :src="task.icon" />
<div>
<strong>{{ task.name }}</strong>
<p>{{ task.teams.length }} команд · {{ task.users.length }} экспертов</p>
</div>
</div>
<AppIcon name="arrow" :size="18"
/></NuxtLink>
<div v-if="!cases.length" class="table-empty">Кейсов пока нет.</div>
</div>
<FormDialog
v-if="editing"
title="Новый кейс"
:busy="saving"
submit-label="Добавить"
@close="
editing = false
error = ''
"
@save="save"
><label class="field" for="caseName"
><span>Название</span
><input id="caseName" v-model.trim="name" class="text-input" maxlength="255" required /></label
><label class="field" for="caseDescription"
><span>Описание</span
><textarea id="caseDescription" v-model.trim="description" class="text-input" maxlength="10000" rows="3" />
</label>
<CaseIconUpload v-model="icon" :disabled="saving" />
<div v-if="error" class="form-error" role="alert">{{ error }}</div></FormDialog
>
</div>
</template>
<script>
export default {
name: 'AdminCases',
async asyncData({ $axios }) {
return await $axios.$get('/admin/cases')
},
data() {
return { cases: [], editing: false, name: '', description: '', icon: null, saving: false, error: '' }
},
methods: {
async save() {
if (this.saving || !this.name) return
this.saving = true
this.error = ''
try {
const { case: task } = await this.$axios.$post('/admin/cases', {
name: this.name,
description: this.description,
icon: this.icon,
})
await this.$router.push('/admin/cases/' + task.id)
} catch (e) {
this.error = 'Не удалось добавить кейс.'
} finally {
this.saving = false
}
},
},
}
</script>
@@ -0,0 +1,317 @@
<template>
<div>
<div class="page-heading">
<h1>Результаты</h1>
<button class="button" type="button" :disabled="refreshing" @click="refresh">
{{ refreshing ? 'Обновляем…' : 'Обновить' }}
</button>
</div>
<div class="toolbar">
<div class="tabs report-tabs" role="group" aria-label="Отчёт">
<button
v-for="item in tabs"
:key="item.id"
class="tab"
:class="{ active: tab === item.id }"
:aria-pressed="String(tab === item.id)"
type="button"
@click="tab = item.id"
>
{{ item.name }}
</button>
</div>
<select v-model="selectedCase" class="filter-select" aria-label="Кейс">
<option value="">Все кейсы</option>
<option v-for="(name, id) in cases" :key="id" :value="id">{{ name }}</option>
</select>
</div>
<div v-if="error" class="form-error" role="alert">{{ error }}</div>
<template v-if="tab === 'ranking'"
><section v-for="(ranking, id) in filteredPositions" :key="id" class="panel report-section">
<div class="panel-header">
<h2>{{ cases[id] }}</h2>
</div>
<div class="table-scroll">
<table class="data-table">
<thead>
<tr>
<SortHeader
v-for="column in rankingColumns"
:key="column.key"
:active="sorting.key === column.key"
:direction="sorting.direction"
@sort="sortBy(column.key)"
>{{ column.name }}</SortHeader
>
</tr>
</thead>
<tbody>
<tr v-for="[teamId, place] in sortedRanking(ranking)" :key="teamId">
<td style="width: 80px">{{ place }}</td>
<td>{{ teams[teamId] }}</td>
</tr>
</tbody>
</table>
</div>
</section>
<div v-if="!Object.keys(filteredPositions).length" class="panel table-empty">Оценок пока нет.</div></template
>
<template v-else-if="tab === 'details'">
<section v-for="task in filteredDetails" :key="task.id" class="panel report-section">
<div class="panel-header">
<h2>{{ task.name }}</h2>
</div>
<div class="table-scroll">
<table class="data-table all-marks-table">
<thead>
<tr>
<SortHeader
v-for="column in detailColumns"
:key="column.key"
:active="sorting.key === column.key"
:direction="sorting.direction"
@sort="sortBy(column.key)"
>{{ column.name }}</SortHeader
>
</tr>
</thead>
<tbody>
<tr v-for="row in sortedDetails(task.rows)" :key="row.teamId + row.userId">
<td>{{ row.team }}</td>
<td>{{ row.expert }}<span v-if="row.role === 'technical'" class="badge">Технический эксперт</span></td>
<td v-for="(_, type) in criteria" :key="type">
{{ row.marks[type] === null ? '—' : row.marks[type] }}
</td>
<td>{{ row.total === null ? '—' : row.total }}</td>
</tr>
<tr v-if="!task.rows.length">
<td :colspan="Object.keys(criteria).length + 3" class="table-empty">
Нет назначенных экспертов или команд.
</td>
</tr>
</tbody>
</table>
</div>
</section>
<div v-if="!filteredDetails.length" class="panel table-empty">Кейсов пока нет.</div>
</template>
<section v-else class="panel">
<div class="table-scroll">
<table class="data-table">
<thead>
<tr>
<SortHeader
v-for="column in reportColumns"
:key="column.key"
:active="sorting.key === column.key"
:direction="sorting.direction"
@sort="sortBy(column.key)"
>{{ column.name }}</SortHeader
>
</tr>
</thead>
<template v-if="tab === 'zero'">
<tbody v-for="group in zeroGroups" :key="group.id">
<tr v-for="(row, index) in group.rows" :key="index">
<td v-if="index === 0" :rowspan="group.rows.length">{{ group.user }}</td>
<td>{{ row.task }}</td>
<td class="assignment-cell">{{ row.teams[0] }}</td>
<td class="assignment-cell">{{ row.criterion }}</td>
<td>0</td>
</tr>
</tbody>
</template>
<tbody v-if="tab !== 'zero' || !reportRows.length">
<tr v-for="(row, index) in reportRows" :key="index">
<td>{{ row.user }}</td>
<td>{{ row.task }}</td>
<td class="assignment-cell">{{ row.teams.join(', ') }}</td>
<td v-if="tab === 'zero'">{{ row.criterion }}</td>
<td v-if="tab === 'zero'">0</td>
</tr>
<tr v-if="!reportRows.length">
<td :colspan="reportColumns.length" class="table-empty">
{{ tab === 'missing' ? 'Все оценки заполнены.' : 'Нулевых оценок нет.' }}
</td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</template>
<script>
export default {
name: 'Results',
async asyncData({ $axios }) {
const [missing, ranking, detail] = await Promise.all([
$axios.$get('/admin/marks'),
$axios.$get('/admin/positions'),
$axios.$get('/admin/marks/details'),
])
return { ...missing, ...ranking, ...detail }
},
data() {
return {
noMarks: {},
zeroMarks: {},
positions: {},
details: [],
criteria: {},
cases: {},
teams: {},
selectedCase: '',
tab: 'ranking',
sorts: {
ranking: { key: 'place', direction: 'asc' },
details: { key: '', direction: 'asc' },
missing: { key: '', direction: 'asc' },
zero: { key: '', direction: 'asc' },
},
rankingColumns: [
{ key: 'place', name: 'Место' },
{ key: 'team', name: 'Команда' },
],
missingColumns: [
{ key: 'user', name: 'Эксперт' },
{ key: 'task', name: 'Кейс' },
{ key: 'teams', name: 'Команды' },
],
refreshing: false,
error: '',
tabs: [
{ id: 'ranking', name: 'Рейтинг' },
{ id: 'details', name: 'Все оценки' },
{ id: 'missing', name: 'Без оценок' },
{ id: 'zero', name: 'Нулевые оценки' },
],
}
},
computed: {
zeroGroups() {
if (this.tab !== 'zero') return []
const groups = new Map()
for (const row of this.reportRows) {
if (!groups.has(row.userId)) groups.set(row.userId, { id: row.userId, user: row.user, rows: [] })
groups.get(row.userId).rows.push(row)
}
const direction = this.sorting.key === 'user' && this.sorting.direction === 'desc' ? -1 : 1
return [...groups.values()].sort(
(a, b) => direction * a.user.localeCompare(b.user, 'ru', { sensitivity: 'base', numeric: true })
)
},
reportColumns() {
if (this.tab !== 'zero') return this.missingColumns
return [
{ key: 'user', name: 'Эксперт' },
{ key: 'task', name: 'Кейс' },
{ key: 'teams', name: 'Команда' },
{ key: 'criterion', name: 'Критерий' },
{ key: 'value', name: 'Оценка' },
]
},
sorting() {
return this.sorts[this.tab]
},
detailColumns() {
return [
{ key: 'team', name: 'Команда' },
{ key: 'expert', name: 'Эксперт' },
...Object.entries(this.criteria).map(([type, name]) => ({
key: 'mark:' + type,
name: name + ([20, 30].includes(+type) ? ' (тех.)' : ''),
})),
{ key: 'total', name: 'Сумма' },
]
},
filteredDetails() {
return this.details.filter(task => !this.selectedCase || task.id === this.selectedCase)
},
filteredPositions() {
return this.selectedCase
? this.positions[this.selectedCase]
? { [this.selectedCase]: this.positions[this.selectedCase] }
: {}
: this.positions
},
reportRows() {
if (this.tab === 'zero') {
const rows = this.filteredDetails.flatMap(task =>
task.rows.flatMap(row => {
const types = Object.entries(row.marks)
.filter(([, value]) => value === 0)
.map(([type]) => type)
return types.length
? [
{
userId: row.userId,
user: row.expert + (row.role === 'technical' ? ' (тех.)' : ''),
task: task.name,
teams: [row.team],
criterion: types
.map(type => this.criteria[type] + ([20, 30].includes(+type) ? ' (тех.)' : ''))
.join(', '),
value: 0,
},
]
: []
})
)
return this.sortRows(rows, (row, key) => (key === 'teams' ? row.teams[0] : row[key]))
}
const data = this.noMarks
const rows = Object.entries(data).flatMap(([user, tasks]) =>
Object.entries(tasks)
.filter(([name]) => !this.selectedCase || name === this.cases[this.selectedCase])
.map(([task, teams]) => ({ user, task, teams }))
)
return this.sortRows(rows, (row, key) => (key === 'teams' ? row.teams.join(', ') : row[key]))
},
},
methods: {
sortBy(key) {
this.$set(this.sorts, this.tab, {
key,
direction: this.sorting.key === key && this.sorting.direction === 'asc' ? 'desc' : 'asc',
})
},
sortRows(rows, value) {
const { key, direction } = this.sorting
if (!key) return rows
return [...rows].sort((a, b) => {
const left = value(a, key)
const right = value(b, key)
if (left == null) return right == null ? 0 : 1
if (right == null) return -1
const result =
typeof left === 'number' && typeof right === 'number'
? left - right
: String(left).localeCompare(String(right), 'ru', { numeric: true, sensitivity: 'base' })
return direction === 'asc' ? result : -result
})
},
sortedDetails(rows) {
return this.sortRows(rows, (row, key) => (key.startsWith('mark:') ? row.marks[key.slice(5)] : row[key]))
},
sortedRanking(ranking) {
return this.sortRows(Object.entries(ranking), (row, key) => (key === 'place' ? row[1] : this.teams[row[0]]))
},
async refresh() {
this.refreshing = true
this.error = ''
try {
const [missing, ranking, detail] = await Promise.all([
this.$axios.$get('/admin/marks'),
this.$axios.$get('/admin/positions'),
this.$axios.$get('/admin/marks/details'),
])
Object.assign(this, missing, ranking, detail)
} catch (e) {
this.error = 'Не удалось обновить результаты.'
} finally {
this.refreshing = false
}
},
},
}
</script>
@@ -0,0 +1,452 @@
<template>
<div>
<div class="page-heading expert-heading">
<h1>Эксперты</h1>
<div class="expert-header-actions">
<button class="button" type="button" :disabled="!activeCount" @click="openExport">QR-коды PDF</button
><button class="button button-primary" type="button" @click="openNew">
<AppIcon name="plus" :size="16" /> Добавить эксперта
</button>
</div>
</div>
<div class="toolbar">
<div class="tabs" role="group" aria-label="Статус эксперта">
<button
v-for="tab in tabs"
:key="tab.id"
class="tab"
:class="{ active: filter === tab.id }"
:aria-pressed="String(filter === tab.id)"
type="button"
@click="filter = tab.id"
>
{{ tab.name }}
</button>
</div>
<label class="search-box"
><AppIcon name="search" :size="16" /><input
v-model="search"
type="search"
aria-label="Найти эксперта"
placeholder="Найти эксперта"
/></label>
</div>
<div v-if="pageError" class="form-error" role="alert">{{ pageError }}</div>
<div class="panel">
<div class="table-scroll">
<table class="data-table">
<thead>
<tr>
<th scope="col">Эксперт</th>
<th scope="col">Роль</th>
<th scope="col">Логин / пароль</th>
<th scope="col">Кейсы</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr v-for="user in filteredUsers" :key="user.id">
<td>{{ fullName(user) }}</td>
<td>{{ user.role === 'technical' ? 'Технический эксперт' : 'Эксперт' }}</td>
<td>
<span class="mono">{{ user.login }}</span>
<div class="password-cell">
<span class="mono">{{ revealed[user.id] ? user.passwordForAdmin || '—' : '••••••••' }}</span
><button
v-if="user.passwordForAdmin"
class="icon-button"
type="button"
:aria-label="(revealed[user.id] ? 'Скрыть пароль: ' : 'Показать пароль: ') + user.login"
:aria-pressed="String(!!revealed[user.id])"
@click="$set(revealed, user.id, !revealed[user.id])"
>
<AppIcon name="eye" :size="15" />
</button>
</div>
</td>
<td class="assignment-cell">{{ user.cases.map(c => c.name).join(', ') || 'Не назначены' }}</td>
<td>
<div class="expert-actions">
<template v-if="!user.deletedAt"
><button
class="button button-sm"
type="button"
:aria-label="'Назначить кейсы: ' + user.login"
:disabled="saving"
@click="assign(user)"
>
Кейсы</button
><button
class="button button-sm"
type="button"
:aria-label="'Изменить эксперта: ' + user.login"
:disabled="saving"
@click="openEdit(user)"
>
Изменить</button
><button
class="button button-sm danger-text"
type="button"
:aria-label="'Удалить эксперта: ' + user.login"
:disabled="saving"
@click="openDelete(user)"
>
Удалить
</button></template
><button
v-else
class="button button-sm"
type="button"
:disabled="saving"
:aria-label="'Восстановить эксперта: ' + user.login"
@click="restore(user)"
>
Восстановить
</button>
</div>
</td>
</tr>
<tr v-if="!filteredUsers.length">
<td colspan="5" class="table-empty">Эксперты не найдены.</td>
</tr>
</tbody>
</table>
</div>
</div>
<FormDialog
v-if="editor === 'new' || editor === 'edit'"
:title="editor === 'new' ? 'Новый эксперт' : 'Изменить эксперта'"
:busy="saving"
:submit-label="editor === 'new' ? 'Добавить' : 'Сохранить'"
@close="editor = null"
@save="saveUser"
><label class="field" for="lastName"
><span>Фамилия</span
><input
id="lastName"
v-model.trim="draft.lastName"
class="text-input"
maxlength="50"
autocomplete="family-name"
required /></label
><label class="field" for="firstName"
><span>Имя</span
><input
id="firstName"
v-model.trim="draft.firstName"
class="text-input"
maxlength="50"
autocomplete="given-name"
required /></label
><label class="field" for="middleName"
><span>Отчество</span
><input
id="middleName"
v-model.trim="draft.middleName"
class="text-input"
maxlength="50"
autocomplete="additional-name" /></label
><template v-if="editor === 'edit'"
><label class="field" for="expertLogin"
><span>Логин</span
><input
id="expertLogin"
v-model.trim="draft.login"
class="text-input"
minlength="2"
maxlength="100"
pattern="[a-zA-Z0-9_.@\-]+"
autocomplete="off"
required /></label
><label class="field" for="expertPassword"
><span>Новый пароль</span
><input
id="expertPassword"
v-model="draft.password"
class="text-input"
type="password"
placeholder="Не менять"
minlength="6"
maxlength="72"
autocomplete="new-password" /></label
></template>
<label class="field" for="expertRole">
<span>Роль</span>
<select id="expertRole" v-model="draft.role" class="text-input" aria-label="Роль" :disabled="saving">
<option value="expert">Эксперт</option>
<option value="technical">Технический эксперт</option>
</select>
</label>
<div v-if="editor === 'new'" class="field">
<span>Кейсы</span>
<div class="checkbox-list">
<label v-for="task in cases" :key="task.id" class="checkbox-row">
<input v-model="selectedCaseIds" type="checkbox" :value="task.id" :disabled="saving" />
<span>{{ task.name }}</span>
</label>
<p v-if="!cases.length" class="muted">Сначала добавьте кейсы.</p>
</div>
</div>
<div v-if="error" class="form-error" role="alert">{{ error }}</div></FormDialog
>
<FormDialog
v-if="editor === 'cases'"
:title="fullName(selectedUser)"
:busy="saving"
@close="editor = null"
@save="saveAssignments"
><div class="checkbox-list">
<label v-for="task in cases" :key="task.id" class="checkbox-row"
><input v-model="selectedCaseIds" type="checkbox" :value="task.id" :disabled="saving" /><span>{{
task.name
}}</span></label
>
<p v-if="!cases.length" class="muted">Сначала добавьте кейсы.</p>
</div>
<div v-if="error" class="form-error" role="alert">{{ error }}</div></FormDialog
>
<FormDialog
v-if="editor === 'delete'"
title="Удалить эксперта?"
:busy="saving"
submit-label="Удалить"
danger
@close="editor = null"
@save="deleteUser"
><p>{{ fullName(selectedUser) }}</p>
<p class="muted" style="margin-top: 12px">Доступ будет закрыт. Оценки сохранятся.</p>
<div v-if="error" class="form-error" role="alert" style="margin-top: 16px">{{ error }}</div></FormDialog
>
<FormDialog
v-if="editor === 'export'"
title="QR-коды экспертов"
:busy="exporting"
submit-label="Скачать PDF"
@close="editor = null"
@save="downloadQr"
><label class="field" for="baseUrl"
><span>Адрес приложения</span
><input
id="baseUrl"
v-model.trim="baseUrl"
class="text-input"
type="url"
maxlength="300"
placeholder="https://grading.example.ru/"
required
/></label>
<p class="muted">Все активные эксперты · A4 · 3 × 4 карточки</p>
<p v-if="localAddress" class="muted" style="margin-top: 10px">
Для входа с телефона укажите адрес, доступный экспертам.
</p>
<div v-if="error" class="form-error" role="alert" style="margin-top: 16px">{{ error }}</div></FormDialog
>
<div v-if="message" class="toast" role="status">{{ message }}</div>
</div>
</template>
<script>
export default {
name: 'Experts',
async asyncData({ $axios }) {
const [{ users }, { cases }] = await Promise.all([$axios.$get('/admin/users'), $axios.$get('/admin/cases')])
return { users, cases }
},
data() {
return {
users: [],
cases: [],
search: '',
filter: 'active',
tabs: [
{ id: 'active', name: 'Активные' },
{ id: 'deleted', name: 'Удалённые' },
],
revealed: {},
editor: null,
selectedUser: null,
selectedCaseIds: [],
draft: { firstName: '', lastName: '', middleName: '', login: '', password: '', role: 'expert' },
error: '',
pageError: '',
saving: false,
exporting: false,
baseUrl: '',
message: '',
timer: null,
}
},
computed: {
activeCount() {
return this.users.filter(u => !u.deletedAt).length
},
filteredUsers() {
const query = this.search.toLowerCase()
return this.users.filter(
u =>
(this.filter === 'deleted' ? !!u.deletedAt : !u.deletedAt) &&
`${this.fullName(u)} ${u.login}`.toLowerCase().includes(query)
)
},
localAddress() {
try {
return ['localhost', '127.0.0.1', '[::1]'].includes(new URL(this.baseUrl).hostname)
} catch (e) {
return false
}
},
},
beforeDestroy() {
clearTimeout(this.timer)
},
methods: {
fullName(user) {
return [user.lastName, user.firstName, user.middleName].filter(Boolean).join(' ')
},
async reload() {
const { users } = await this.$axios.$get('/admin/users')
this.users = users
},
notify(message) {
this.message = message
clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.message = ''
}, 3500)
},
openNew() {
this.draft = { firstName: '', lastName: '', middleName: '', login: '', password: '', role: 'expert' }
this.selectedCaseIds = []
this.error = ''
this.editor = 'new'
},
openEdit(user) {
this.selectedUser = user
this.draft = {
firstName: user.firstName,
lastName: user.lastName,
middleName: user.middleName || '',
login: user.login,
password: '',
role: user.role || 'expert',
}
this.error = ''
this.editor = 'edit'
},
openDelete(user) {
this.selectedUser = user
this.error = ''
this.editor = 'delete'
},
openExport() {
this.baseUrl = 'https://cg.vkhost.ru/'
this.error = ''
this.editor = 'export'
},
assign(user) {
this.selectedUser = user
this.selectedCaseIds = user.cases.map(c => c.id)
this.error = ''
this.editor = 'cases'
},
async saveUser() {
if (this.saving) return
this.saving = true
this.error = ''
try {
if (this.editor === 'new')
await this.$axios.$post('/admin/users', { ...this.draft, caseIds: this.selectedCaseIds })
else await this.$axios.$put('/admin/users/' + this.selectedUser.id, this.draft)
await this.reload()
this.editor = null
this.revealed = {}
this.filter = 'active'
this.search = ''
this.notify('Эксперт сохранён')
} catch (e) {
this.error =
e.response?.status === 409
? e.response.data.key === 'SYSTEM_ERROR'
? e.response.data.message
: 'Эксперт или логин уже существует.'
: 'Не удалось сохранить эксперта. Проверьте ФИО, логин и пароль.'
} finally {
this.saving = false
}
},
async deleteUser() {
if (this.saving) return
this.saving = true
this.error = ''
try {
await this.$axios.$delete('/admin/users/' + this.selectedUser.id)
await this.reload()
this.editor = null
this.revealed = {}
this.notify('Эксперт удалён')
} catch (e) {
this.error = 'Не удалось удалить эксперта.'
} finally {
this.saving = false
}
},
async restore(user) {
if (this.saving) return
this.saving = true
this.pageError = ''
try {
await this.$axios.$post('/admin/users/' + user.id + '/restore')
await this.reload()
this.notify('Эксперт восстановлен')
} catch (e) {
this.pageError = e.response?.data?.message || 'Не удалось восстановить эксперта.'
} finally {
this.saving = false
}
},
async saveAssignments() {
if (this.saving) return
this.saving = true
this.error = ''
try {
await this.$axios.$put('/admin/users/' + this.selectedUser.id + '/cases', { caseIds: this.selectedCaseIds })
await this.reload()
this.editor = null
this.notify('Кейсы назначены')
} catch (e) {
this.error = e.response?.data?.message || 'Не удалось сохранить назначения.'
} finally {
this.saving = false
}
},
async downloadQr() {
if (this.exporting) return
this.exporting = true
this.error = ''
try {
const response = await this.$axios.post(
'/admin/users/qr-pdf',
{ baseUrl: this.baseUrl },
{ responseType: 'blob' }
)
const url = URL.createObjectURL(response.data)
const link = document.createElement('a')
link.href = url
link.download = 'experts-qr.pdf'
document.body.appendChild(link)
link.click()
link.remove()
setTimeout(() => URL.revokeObjectURL(url), 10000)
this.editor = null
} catch (e) {
let message = ''
try {
message = JSON.parse(await e.response.data.text()).message
} catch (ignored) {}
this.error = message || 'Не удалось скачать PDF. Попробуйте ещё раз.'
} finally {
this.exporting = false
}
},
},
}
</script>