feat(permission): replace OA roles with post-bound roles and assignee posts

Unify effective roles via post-role bindings, remove dedicated OA role UI, and update OA assignee resolution plus related SQL/docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-04 17:41:04 +08:00
1 parent a3c73d76bb
commit 06db3bc966
66 files changed
+55337 -38647

No files matched your search

+12 -1
View File
@@ -103,6 +103,9 @@
<el-dropdown-item command="edit">
<el-icon><Edit /></el-icon>编辑基础
</el-dropdown-item>
<el-dropdown-item command="copy">
<el-icon><CopyDocument /></el-icon>复制
</el-dropdown-item>
<el-dropdown-item command="delete" divided>
<el-icon><Delete /></el-icon>删除
</el-dropdown-item>
@@ -275,10 +278,12 @@
Upload,
Folder,
Search,
Refresh
Refresh,
CopyDocument
} from '@element-plus/icons-vue'
import { fetchUploadAttachment } from '@/api/business'
import {
fetchCopyOaApp,
fetchCreateOaApp,
fetchCreateOaGroup,
fetchDeleteOaApp,
@@ -494,9 +499,15 @@
function onMore(cmd: string, row: any) {
if (cmd === 'publish') handlePublish(row)
if (cmd === 'edit') handleEdit(row)
if (cmd === 'copy') handleCopy(row)
if (cmd === 'delete') handleDelete(row)
}
async function handleCopy(row: any) {
await fetchCopyOaApp(row.id)
await loadData()
}
async function handleDelete(row: any) {
await ElMessageBox.confirm(`确定删除应用「${row.appName}」吗?`, '提示', { type: 'warning' })
await fetchDeleteOaApp(row.id)
@@ -1,767 +0,0 @@
<!-- OA 工作流角色(非 sys_role) -->
<!-- eslint-disable vue/no-v-model-argument -->
<template>
<div class="page-container">
<section class="panel">
<div class="panel-top">
<h2 class="title-bar-heading">工作流角色</h2>
</div>
<div class="filter-block">
<el-form :model="searchForm" class="filter-form" @submit.prevent>
<div class="filter-grid">
<el-form-item label="关键词">
<el-input
v-model="searchForm.keyword"
placeholder="角色名称/编码"
clearable
@keyup.enter="handleSearch"
/>
</el-form-item>
<el-form-item label="状态">
<el-select v-model="searchForm.status" placeholder="请选择" clearable>
<el-option label="启用" value="1" />
<el-option label="停用" value="0" />
</el-select>
</el-form-item>
</div>
<div class="filter-actions-row">
<div class="filter-actions-end">
<el-button class="btn-ghost" @click="handleReset">
<el-icon><RefreshLeft /></el-icon>重置
</el-button>
<el-button class="btn-main" type="primary" @click="handleSearch">
<el-icon><Search /></el-icon>搜索
</el-button>
</div>
</div>
</el-form>
</div>
<div class="list-toolbar">
<div class="list-toolbar-row">
<div class="list-toolbar-selected">
已选 <span class="sel-num">{{ selectedRows.length }}</span> 项
</div>
<el-button class="btn-main" type="primary" @click="handleAdd">
<el-icon><Plus /></el-icon>
新增角色
</el-button>
</div>
</div>
<div class="list-body list-wrap">
<el-table
class="list-table"
:data="tableData"
v-loading="loading"
stripe
row-key="id"
@selection-change="(rows: any[]) => (selectedRows = rows)"
>
<el-table-column type="selection" min-width="55" align="center" header-align="center" />
<el-table-column
type="index"
label="序号"
min-width="68"
align="center"
header-align="center"
/>
<el-table-column
prop="roleName"
label="角色名称"
min-width="140"
align="left"
header-align="left"
/>
<el-table-column
prop="roleCode"
label="编码"
min-width="120"
align="center"
header-align="center"
/>
<el-table-column
prop="roleKind"
label="类型"
min-width="100"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-tag :type="row.roleKind === 'preset' ? 'primary' : 'info'" size="small">
{{ row.roleKind === 'preset' ? '预置' : '自定义' }}
</el-tag>
</template>
</el-table-column>
<el-table-column
prop="memberCount"
label="成员数"
min-width="90"
align="center"
header-align="center"
/>
<el-table-column
prop="status"
label="状态"
min-width="90"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-tag :type="row.status === '1' ? 'success' : 'info'" size="small">
{{ row.status === '1' ? '启用' : '停用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column
prop="createTime"
label="创建时间"
min-width="170"
align="center"
header-align="center"
>
<template #default="{ row }">{{ formatDisplayOrDash(row.createTime) }}</template>
</el-table-column>
<el-table-column
label="操作"
min-width="280"
fixed="right"
align="center"
header-align="center"
>
<template #default="{ row }">
<div style="display: flex; justify-content: center; gap: 8px">
<el-button class="btn-op-item primary" @click="handleMembers(row)">
<el-icon><User /></el-icon>成员
</el-button>
<el-button class="btn-op-item" @click="handleEdit(row)">
<el-icon><Edit /></el-icon>编辑
</el-button>
<el-button
class="btn-op-item"
:disabled="row.roleKind === 'preset'"
@click="handleDelete(row)"
>
<el-icon><Delete /></el-icon>删除
</el-button>
</div>
</template>
</el-table-column>
</el-table>
</div>
<el-dialog
v-model="dialogVisible"
:title="dialogTitle"
width="560px"
class="dialog-form-layout"
align-center
append-to-body
modal-class="protocol-dialog-mask"
destroy-on-close
:close-on-click-modal="false"
>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-position="top"
class="oa-role-dialog-form"
scroll-to-error
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
>
<div class="form-grid-2">
<el-form-item label="角色名称" prop="roleName">
<el-input v-model="formData.roleName" placeholder="如:财务审批" maxlength="100" />
</el-form-item>
<el-form-item label="角色编码" prop="roleCode">
<el-input
v-model="formData.roleCode"
placeholder="如:FINANCE"
maxlength="64"
:disabled="isEdit"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="formData.status" placeholder="请选择">
<el-option label="启用" value="1" />
<el-option label="停用" value="0" />
</el-select>
</el-form-item>
<el-form-item label="备注" class="form-col-span-2">
<el-input v-model="formData.remark" type="textarea" :rows="2" placeholder="可选" />
</el-form-item>
</div>
</el-form>
<template #footer>
<el-button class="btn-ghost" @click="dialogVisible = false">
<el-icon><Close /></el-icon>
取消
</el-button>
<el-button class="btn-main" type="primary" :loading="submitLoading" @click="handleSubmit">
<el-icon><Check /></el-icon>
确定
</el-button>
</template>
</el-dialog>
<el-dialog
v-model="memberVisible"
:title="`成员管理 · ${memberRole?.roleName || ''}`"
width="640px"
class="dialog-form-layout"
align-center
append-to-body
modal-class="protocol-dialog-mask"
destroy-on-close
:close-on-click-modal="false"
>
<el-form label-position="top">
<el-form-item>
<template #label>
绑定用户
<span class="form-label-tip">可多选,已选成员将展示在下方列表</span>
</template>
<div v-loading="memberLoading" class="member-picker">
<el-select
v-model="memberPickBuffer"
filterable
clearable
:loading="memberLoading"
placeholder="搜索姓名 / 工号,点击添加"
style="width: 100%"
popper-class="oa-role-member-select-popper"
@change="onMemberPick"
>
<el-option
v-for="u in userOptions"
:key="u.id"
:label="memberOptionLabel(u)"
:value="u.id"
:disabled="memberUserIds.includes(u.id)"
>
<div class="member-option">
<span class="member-avatar" :style="{ background: avatarColor(u.id) }">
{{ avatarInitial(u.nickName) }}
</span>
<span class="member-option__meta">
<span class="member-option__name">{{ u.nickName || '未命名' }}</span>
<span v-if="memberOptionSub(u)" class="member-option__sub">
{{ memberOptionSub(u) }}
</span>
</span>
<el-tag
v-if="memberUserIds.includes(u.id)"
size="small"
type="info"
effect="plain"
class="member-option__tag"
>
已选
</el-tag>
</div>
</el-option>
</el-select>
<div
class="member-chips"
:class="{ 'is-empty': !memberUserIds.length }"
>
<template v-if="memberUserIds.length">
<span v-for="id in memberUserIds" :key="id" class="member-chip">
<span
class="member-avatar member-avatar--sm"
:style="{ background: avatarColor(id) }"
>
{{ avatarInitial(resolveUser(id)?.nickName) }}
</span>
<span class="member-chip__name" :title="chipTitle(id)">
{{ resolveUser(id)?.nickName || id }}
</span>
<button
type="button"
class="member-chip__rm"
:aria-label="`移除 ${resolveUser(id)?.nickName || id}`"
@click="removeMember(id)"
>
×
</button>
</span>
</template>
<template v-else>暂未选择成员,请从上方搜索添加</template>
</div>
<p class="member-picked-count">已选 {{ memberUserIds.length }} 人</p>
</div>
</el-form-item>
</el-form>
<template #footer>
<el-button class="btn-ghost" @click="memberVisible = false">
<el-icon><Close /></el-icon>
取消
</el-button>
<el-button
class="btn-main"
type="primary"
:loading="memberSubmitLoading"
@click="handleMemberSubmit"
>
<el-icon><Check /></el-icon>
确定
</el-button>
</template>
</el-dialog>
</section>
</div>
</template>
<script setup lang="ts">
import { formatDisplayOrDash } from '@/utils/datetime-display'
import { nextTick, onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
Plus,
Close,
Check,
Edit,
Delete,
User,
RefreshLeft,
Search
} from '@element-plus/icons-vue'
import { fetchUserList } from '@/api/admin'
import {
fetchCreateOaRole,
fetchDeleteOaRole,
fetchOaRoleList,
fetchOaRoleUsers,
fetchReplaceOaRoleUsers,
fetchUpdateOaRole
} from '@/api/oaApproval'
import { MAX_ADMIN_LIST_PAGE_SIZE } from '@/utils/fetch-paged-list'
import { watchDebounced } from '@vueuse/core'
defineOptions({ name: 'OaApprovalRoles' })
const searchForm = reactive({ keyword: '', status: '' })
const tableData = ref<any[]>([])
const selectedRows = ref<any[]>([])
const loading = ref(false)
const dialogVisible = ref(false)
const dialogTitle = ref('新增工作流角色')
const isEdit = ref(false)
const editingId = ref<string | null>(null)
const submitLoading = ref(false)
const formRef = ref()
const formData = reactive({
roleName: '',
roleCode: '',
status: '1',
remark: ''
})
const formRules = {
roleName: [{ required: true, message: '请输入角色名称', trigger: 'blur' }],
roleCode: [{ required: true, message: '请输入角色编码', trigger: 'blur' }],
status: [{ required: true, message: '请选择状态', trigger: 'change' }]
}
type UserOption = { id: string; nickName: string; userNo: string }
const AVATAR_COLORS = [
'#059669',
'#0ea5e9',
'#8b5cf6',
'#d97706',
'#ef4444',
'#14b8a6',
'#6366f1',
'#ec4899'
]
const memberVisible = ref(false)
const memberRole = ref<any>(null)
const memberUserIds = ref<string[]>([])
const memberPickBuffer = ref('')
const memberLoading = ref(false)
const memberSubmitLoading = ref(false)
const userOptions = ref<UserOption[]>([])
function avatarColor(id: string) {
let hash = 0
for (let i = 0; i < id.length; i++) hash = (hash * 31 + id.charCodeAt(i)) >>> 0
return AVATAR_COLORS[hash % AVATAR_COLORS.length]
}
function avatarInitial(name?: string) {
const t = (name || '?').trim()
return t ? t.slice(0, 1) : '?'
}
function resolveUser(id: string) {
return userOptions.value.find((u) => u.id === id)
}
function memberOptionLabel(u: UserOption) {
const name = (u.nickName || '').trim() || '未命名'
const no = (u.userNo || '').trim()
if (no && no !== name) return `${name}(${no})`
return name
}
function memberOptionSub(u: UserOption) {
const name = (u.nickName || '').trim()
const no = (u.userNo || '').trim()
if (!no || no === name) return ''
return `账号 ${no}`
}
function chipTitle(id: string) {
const u = resolveUser(id)
return u ? memberOptionLabel(u) : id
}
function onMemberPick(id: string) {
if (!id) return
if (!memberUserIds.value.includes(id)) {
memberUserIds.value = [...memberUserIds.value, id]
}
nextTick(() => {
memberPickBuffer.value = ''
})
}
function removeMember(id: string) {
memberUserIds.value = memberUserIds.value.filter((x) => x !== id)
}
async function loadData() {
loading.value = true
try {
const res = await fetchOaRoleList({
keyword: searchForm.keyword || undefined,
status: searchForm.status || undefined
})
tableData.value = res?.list || []
} finally {
loading.value = false
}
}
function handleSearch() {
loadData()
}
function handleReset() {
searchForm.keyword = ''
searchForm.status = ''
loadData()
}
function resetForm() {
formData.roleName = ''
formData.roleCode = ''
formData.status = '1'
formData.remark = ''
editingId.value = null
}
function handleAdd() {
isEdit.value = false
dialogTitle.value = '新增工作流角色'
resetForm()
dialogVisible.value = true
formRef.value?.clearValidate?.()
}
function handleEdit(row: any) {
isEdit.value = true
dialogTitle.value = '编辑工作流角色'
editingId.value = row.id
formData.roleName = row.roleName || ''
formData.roleCode = row.roleCode || ''
formData.status = row.status || '1'
formData.remark = row.remark || ''
dialogVisible.value = true
formRef.value?.clearValidate?.()
}
async function handleSubmit() {
await formRef.value?.validate?.()
submitLoading.value = true
try {
if (isEdit.value && editingId.value) {
await fetchUpdateOaRole(editingId.value, {
roleName: formData.roleName.trim(),
status: formData.status,
remark: formData.remark?.trim() || undefined
})
} else {
await fetchCreateOaRole({
roleName: formData.roleName.trim(),
roleCode: formData.roleCode.trim().toUpperCase(),
status: formData.status,
remark: formData.remark?.trim() || undefined
})
}
dialogVisible.value = false
await loadData()
} finally {
submitLoading.value = false
}
}
async function handleDelete(row: any) {
if (row.roleKind === 'preset') {
ElMessage.warning('预置角色不可删除')
return
}
await ElMessageBox.confirm(`确定删除工作流角色「${row.roleName}」吗?`, '提示', {
type: 'warning'
})
await fetchDeleteOaRole(row.id)
await loadData()
}
async function loadUserOptions() {
const pageSize = MAX_ADMIN_LIST_PAGE_SIZE
const raw: any[] = []
let page = 1
for (;;) {
const res = await fetchUserList({ page, pageSize, status: '1' })
const list = res?.list || []
raw.push(...list)
if (list.length < pageSize) break
if (typeof res?.total === 'number' && raw.length >= res.total) break
page += 1
}
userOptions.value = raw.map((u) => ({
id: u.id,
nickName: u.nickName || '',
userNo: u.userNo || ''
}))
}
async function handleMembers(row: any) {
memberRole.value = row
memberPickBuffer.value = ''
memberUserIds.value = []
memberVisible.value = true
memberLoading.value = true
try {
await loadUserOptions()
const res = await fetchOaRoleUsers(row.id)
memberUserIds.value = (res?.list || []).map((x: any) => x.userId)
} finally {
memberLoading.value = false
}
}
async function handleMemberSubmit() {
if (!memberRole.value?.id) return
memberSubmitLoading.value = true
try {
await fetchReplaceOaRoleUsers(memberRole.value.id, memberUserIds.value)
memberVisible.value = false
await loadData()
} finally {
memberSubmitLoading.value = false
}
}
watchDebounced(
searchForm,
() => {
loadData()
},
{ debounce: 300, deep: true }
)
onMounted(() => {
loadData()
})
</script>
<style scoped lang="scss">
.oa-role-dialog-form {
:deep(.el-form-item) {
margin-bottom: 0;
}
}
.member-picker {
width: 100%;
}
.member-chips {
display: flex;
flex-wrap: wrap;
gap: 8px;
min-height: 44px;
margin-top: 12px;
padding: 12px;
background: #f8fafc;
border: 1px dashed #cbd5e1;
border-radius: 8px;
&.is-empty {
align-items: center;
justify-content: center;
color: var(--mint-text-muted, #94a3b8);
font-size: 13px;
}
}
.member-chip {
display: inline-flex;
gap: 8px;
align-items: center;
max-width: 100%;
padding: 4px 8px 4px 4px;
background: #fff;
border: 1px solid var(--mint-border, #e2e8f0);
border-radius: 999px;
}
.member-chip__name {
max-width: 120px;
overflow: hidden;
font-size: 13px;
font-weight: 500;
white-space: nowrap;
text-overflow: ellipsis;
}
.member-chip__rm {
display: grid;
flex-shrink: 0;
place-items: center;
width: 20px;
height: 20px;
padding: 0;
color: var(--mint-text-muted, #64748b);
font-size: 14px;
line-height: 1;
background: #f1f5f9;
border: 0;
border-radius: 50%;
cursor: pointer;
&:hover {
color: #dc2626;
background: #fee2e2;
}
}
.member-picked-count {
margin: 8px 0 0;
color: var(--mint-text-muted, #94a3b8);
font-size: 12px;
}
.member-avatar {
display: inline-flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
color: #fff;
font-size: 13px;
font-weight: 700;
line-height: 1;
text-align: center;
border-radius: 50%;
&--sm {
width: 28px;
height: 28px;
font-size: 11px;
}
}
</style>
<!-- 下拉挂 body,须非 scoped -->
<style lang="scss">
.oa-role-member-select-popper {
.el-select-dropdown__list {
padding: 8px;
}
.el-select-dropdown__item {
height: auto !important;
min-height: 56px;
margin-bottom: 8px;
padding: 10px 12px !important;
line-height: normal !important;
border-radius: 8px;
&:last-child {
margin-bottom: 0;
}
&.is-disabled {
opacity: 0.55;
}
&.hover,
&:hover {
background: var(--primary-bg, #ecfdf5);
}
}
.member-option {
display: flex;
gap: 12px;
align-items: center;
width: 100%;
min-height: 36px;
}
.member-option__meta {
display: flex;
flex: 1;
flex-direction: column;
gap: 2px;
justify-content: center;
min-width: 0;
}
.member-option__name {
overflow: hidden;
color: var(--mint-text, #0f172a);
font-size: 13px;
font-weight: 600;
white-space: nowrap;
text-overflow: ellipsis;
}
.member-option__sub {
overflow: hidden;
color: var(--mint-text-muted, #64748b);
font-size: 12px;
white-space: nowrap;
text-overflow: ellipsis;
}
.member-option__tag {
flex-shrink: 0;
margin-left: auto;
}
.member-avatar {
display: inline-flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
color: #fff;
font-size: 13px;
font-weight: 700;
line-height: 1;
text-align: center;
border-radius: 50%;
}
}
</style>
@@ -171,7 +171,7 @@
listLeaveKitBindings,
markLeaveDurationManual
} from '@/utils/oa-leave-kit-runtime'
import { ensureOvertimeKitRuleProps } from '@/utils/oa-overtime-kit-runtime'
import { applyOvertimeKitDefaults, ensureOvertimeKitRuleProps } from '@/utils/oa-overtime-kit-runtime'
import { applyResignationKitDefaults } from '@/utils/oa-resignation-kit-runtime'
import {
applyConfirmationKitDateLinkage,
@@ -395,6 +395,11 @@
data,
(userStore.info || userStore.getUserInfo) as any
)
data = applyOvertimeKitDefaults(
{ rule: formRule.value },
data,
(userStore.info || userStore.getUserInfo) as any
)
const linked = applyConfirmationKitDateLinkage({ rule: formRule.value }, data)
formData.value = linked.data
confirmationKitPrevSnapshot = { ...linked.data }
@@ -635,6 +640,11 @@
{ ...(old?.formDataJson || {}) },
(userStore.info || userStore.getUserInfo) as any
)
formData.value = applyOvertimeKitDefaults(
{ rule: formRule.value },
formData.value,
(userStore.info || userStore.getUserInfo) as any
)
} catch {
/* 预填失败仍可手工填 */
}
@@ -404,7 +404,7 @@
</el-form-item>
<el-form-item>
<template #label>
节点编号<span class="form-label-tip">可选,与名称共用序号</span>
节点编号<span class="form-label-tip">编号 = 前缀 + 序号 + 后缀;前缀后缀都空时 = 序号</span>
</template>
<div class="storage-name-compose">
<div class="storage-compose-field storage-compose-field--affix">
@@ -1585,7 +1585,7 @@
nameSuffix: '',
startNum: 1,
endNum: 10,
padWidth: 2,
padWidth: 0,
codePrefix: '',
codeSuffix: '',
nodeType: 'box',
@@ -1619,16 +1619,14 @@
if (count > 200) {
return { count: 0, samples: [] as Array<{ name: string; code: string }> }
}
const genCode = !!(batchChildForm.codePrefix.trim() || batchChildForm.codeSuffix.trim())
const samples: Array<{ name: string; code: string }> = []
const showMax = Math.min(count, 12)
for (let i = 0; i < showMax; i++) {
const num = start + i
const seq = formatBatchSeq(num, batchChildForm.padWidth)
const name = `${batchChildForm.namePrefix}${seq}${batchChildForm.nameSuffix}`.trim()
const code = genCode
? `${batchChildForm.codePrefix}${seq}${batchChildForm.codeSuffix}`.trim()
: ''
// 前缀、后缀都空时,节点编号即为序号(含补零)
const code = `${batchChildForm.codePrefix}${seq}${batchChildForm.codeSuffix}`.trim()
samples.push({ name: name || '(空名称)', code })
}
return { count, samples }
@@ -1685,7 +1683,7 @@
nameSuffix: '',
startNum: 1,
endNum: 10,
padWidth: 2,
padWidth: 0,
codePrefix: '',
codeSuffix: '',
nodeType: data.nodeType === 'facility' ? 'layer' : 'box',
@@ -1739,7 +1737,7 @@
nameSuffix: '',
startNum: 1,
endNum: 10,
padWidth: 2,
padWidth: 0,
codePrefix: '',
codeSuffix: '',
nodeType: 'box',
+124 -5
View File
@@ -103,17 +103,21 @@
</el-table-column>
<el-table-column
label="操作"
min-width="160"
min-width="320"
fixed="right"
align="center"
header-align="center"
>
<template #default="{ row }">
<div style="display: flex; justify-content: center; gap: 8px">
<div style="display: flex; justify-content: center; gap: 8px; flex-wrap: wrap">
<el-button class="btn-op-item primary" @click="handlePostBindUsers(row)">
<el-icon><User /></el-icon>
关联用户
</el-button>
<el-button class="btn-op-item" @click="handlePostBindRoles(row)">
<el-icon><Key /></el-icon>
角色配置
</el-button>
<el-dropdown trigger="hover" @command="(cmd: string) => handleDropdownCommand(cmd, row)">
<el-button class="btn-op-item">
<el-icon><More /></el-icon>
@@ -308,6 +312,58 @@
</template>
</el-dialog>
<!-- 角色配置 -->
<el-dialog
v-model="postRoleDialogVisible"
title="角色配置"
width="560px"
class="dialog-form-layout"
align-center
append-to-body
modal-class="protocol-dialog-mask"
destroy-on-close
:close-on-click-modal="false"
>
<DialogFormBody :loading="postRoleLoading">
<p v-if="postRolePostName" class="post-bind-subtitle">
职位:<strong>{{ postRolePostName }}</strong>
</p>
<el-form label-position="top">
<el-form-item label="关联角色">
<el-select
v-model="postRoleCheckedIds"
multiple
filterable
placeholder="请选择角色"
style="width: 100%"
>
<el-option
v-for="item in postRoleOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-form>
</DialogFormBody>
<template #footer>
<el-button class="btn-ghost" @click="postRoleDialogVisible = false">
<el-icon><Close /></el-icon>
取消
</el-button>
<el-button
class="btn-main"
type="primary"
@click="handlePostRoleSubmit"
:loading="postRoleSubmitLoading"
>
<el-icon><Check /></el-icon>
确定
</el-button>
</template>
</el-dialog>
<SystemViewDialog
v-model:visible="viewVisible"
:title="viewRow?.postName || '职位详情'"
@@ -328,6 +384,7 @@
Close,
Check,
User,
Key,
View,
Edit,
Delete,
@@ -349,7 +406,10 @@
fetchDeptTree,
fetchUserList,
fetchPostBoundUserIds,
fetchUpdatePostBoundUsers
fetchUpdatePostBoundUsers,
fetchPostBoundRoleIds,
fetchUpdatePostBoundRoles,
fetchRoleList
} from '@/api/admin'
defineOptions({ name: 'SystemPost' })
@@ -385,6 +445,7 @@
const viewVisible = ref(false)
const viewRow = ref<Api.Post.PostItem | null>(null)
const viewBoundUserNames = ref<string[]>([])
const viewBoundRoleNames = ref<string[]>([])
const viewSections = computed(() => {
const row = viewRow.value
if (!row) return []
@@ -404,6 +465,12 @@
]
}
]
if (viewBoundRoleNames.value.length > 0) {
sections.push({
title: '关联角色',
fields: [{ label: '已关联角色', value: viewBoundRoleNames.value.join('、'), span: true }]
})
}
if (viewBoundUserNames.value.length > 0) {
sections.push({
title: '关联用户',
@@ -415,16 +482,68 @@
async function handleView(row: Api.Post.PostItem) {
viewRow.value = row
viewBoundUserNames.value = []
viewBoundRoleNames.value = []
viewVisible.value = true
try {
const [boundRes] = await Promise.all([fetchPostBoundUserIds(row.id), fetchDeptTree()])
const [boundRes, roleRes] = await Promise.all([
fetchPostBoundUserIds(row.id),
fetchPostBoundRoleIds(row.id)
])
const roleIds = roleRes?.roleIds || []
if (roleIds.length > 0) {
const roleListRes = await fetchRoleList({ page: 1, pageSize: 100 })
const idToName = new Map(
(roleListRes?.list || []).map((r: any) => [r.id, r.roleName || r.id])
)
viewBoundRoleNames.value = roleIds.map((id: string) => idToName.get(id) || id)
}
const boundIds = boundRes?.userIds || []
if (boundIds.length === 0) return
const users = await fetchAllUsersForPostBind()
const idToName = new Map(users.map((u) => [u.id, u.nickName || u.userNo || u.id]))
viewBoundUserNames.value = boundIds.map((id: string) => idToName.get(id) || id)
} catch (e) {
console.error('加载关联用户失败:', e)
console.error('加载职位关联信息失败:', e)
}
}
// ---- 角色配置弹窗 ----
const postRoleDialogVisible = ref(false)
const postRoleLoading = ref(false)
const postRoleSubmitLoading = ref(false)
const postRolePostId = ref('')
const postRolePostName = ref('')
const postRoleCheckedIds = ref<string[]>([])
const postRoleOptions = ref<Array<{ label: string; value: string }>>([])
async function handlePostBindRoles(row: Api.Post.PostItem) {
postRolePostId.value = row.id
postRolePostName.value = row.postName || row.postCode || ''
postRoleCheckedIds.value = []
postRoleDialogVisible.value = true
postRoleLoading.value = true
try {
const [boundRes, roleListRes] = await Promise.all([
fetchPostBoundRoleIds(row.id),
fetchRoleList({ page: 1, pageSize: 100 })
])
postRoleCheckedIds.value = [...(boundRes?.roleIds || [])]
postRoleOptions.value = (roleListRes?.list || []).map((r: any) => ({
label: r.roleName || r.id,
value: r.id
}))
} finally {
postRoleLoading.value = false
}
}
async function handlePostRoleSubmit() {
postRoleSubmitLoading.value = true
try {
await fetchUpdatePostBoundRoles(postRolePostId.value, [...postRoleCheckedIds.value])
postRoleDialogVisible.value = false
} finally {
postRoleSubmitLoading.value = false
}
}
+51 -4
View File
@@ -361,6 +361,7 @@
<el-select
v-model="formData.roleIds"
multiple
filterable
placeholder="请选择角色"
style="width: 100%"
>
@@ -372,6 +373,22 @@
/>
</el-select>
</el-form-item>
<el-form-item label="职位" style="grid-column: 1 / -1">
<el-select
v-model="formData.postIds"
multiple
filterable
placeholder="请选择职位"
style="width: 100%"
>
<el-option
v-for="item in postOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="备注" style="grid-column: 1 / -1">
<el-input v-model="formData.remark" type="textarea" :rows="2" placeholder="可选" />
</el-form-item>
@@ -426,12 +443,14 @@
fetchDeleteUser,
fetchResetPassword,
fetchDeptTree,
fetchRoleOptions
fetchRoleOptions,
fetchPostList
} from '@/api/admin'
import { buildPathLabelMapFromTreeRoots } from '@/utils/tree-path'
import { resolveUserAvatarFromInfo } from '@/utils/user-avatar'
const roleOptions = ref<Array<{ label: string; value: string }>>([])
const postOptions = ref<Array<{ label: string; value: string }>>([])
async function loadRoleOptions() {
try {
@@ -441,6 +460,18 @@
}
}
async function loadPostOptions() {
try {
const res = await fetchPostList({ page: 1, pageSize: 100 })
postOptions.value = (res?.list || []).map((p) => ({
label: p.postName || p.postCode || p.id,
value: p.id
}))
} catch {
postOptions.value = []
}
}
defineOptions({ name: 'SystemUser' })
const deptKeyword = ref('')
@@ -489,6 +520,15 @@
return labels.length ? labels.join('、') : '—'
}
function formatUserPostDisplay(row: Api.User.UserItem) {
const ids = row.postIds || []
if (!ids.length) return '—'
const labels = ids
.map((id) => postOptions.value.find((o) => o.value === id)?.label)
.filter((name): name is string => Boolean(name))
return labels.length ? labels.join('、') : '—'
}
const searchForm = reactive<{ keyword: string; status: string }>({ keyword: '', status: '' })
const tableData = ref<Api.User.UserItem[]>([])
const selectedRows = ref<Api.User.UserItem[]>([])
@@ -518,7 +558,8 @@
status: '1',
orderNum: 0,
remark: '',
roleIds: [] as string[]
roleIds: [] as string[],
postIds: [] as string[]
})
const supervisorUserOptions = ref<Api.User.UserItem[]>([])
@@ -627,6 +668,7 @@
formData.orderNum = 0
formData.remark = ''
formData.roleIds = []
formData.postIds = []
supervisorUserOptions.value = []
editingId.value = null
}
@@ -667,6 +709,7 @@
formData.orderNum = detail.orderNum ?? 0
formData.remark = detail.remark || ''
formData.roleIds = detail.roleIds ? [...detail.roleIds] : []
formData.postIds = detail.postIds ? [...detail.postIds] : []
if (formData.supervisorUserId) {
await remoteSearchSupervisorUsers(detail.nickName || '')
if (!supervisorUserOptions.value.some((u) => u.id === formData.supervisorUserId)) {
@@ -701,7 +744,8 @@
status: formData.status,
orderNum: formData.orderNum,
remark: formData.remark?.trim() || undefined,
roleIds: [...formData.roleIds]
roleIds: [...formData.roleIds],
postIds: [...formData.postIds]
})
} else {
await fetchCreateUser({
@@ -719,7 +763,8 @@
status: formData.status,
orderNum: formData.orderNum,
remark: formData.remark?.trim() || undefined,
roleIds: formData.roleIds.length ? formData.roleIds : undefined
roleIds: formData.roleIds.length ? formData.roleIds : undefined,
postIds: formData.postIds.length ? formData.postIds : undefined
})
}
dialogVisible.value = false
@@ -838,6 +883,7 @@
tagType: row.status === '1' ? 'success' : 'info'
},
{ label: '角色', value: formatUserRoleDisplay(row), span: true },
{ label: '职位', value: formatUserPostDisplay(row), span: true },
{ label: '创建时间', value: row.createTime },
{ label: '备注', value: row.remark, span: true }
]
@@ -868,6 +914,7 @@
loadDeptTree()
loadData()
loadRoleOptions()
loadPostOptions()
})
</script>