提交
This commit is contained in:
1 parent
246ad2228e
commit
8e2dd8b9f0
186 files changed
+38821
-2571
No files matched your search
@@ -57,6 +57,7 @@
|
||||
stripe
|
||||
row-key="id"
|
||||
@selection-change="handleSelectionChange"
|
||||
@row-dblclick="handleView"
|
||||
>
|
||||
<el-table-column type="selection" width="55" align="center" header-align="center" />
|
||||
<el-table-column
|
||||
@@ -76,10 +77,14 @@
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="orderNum" label="排序" width="80" align="center" header-align="center" />
|
||||
<el-table-column prop="createTime" label="创建时间" min-width="160" align="center" header-align="center" />
|
||||
<el-table-column label="操作" width="260" fixed="right" align="center" header-align="center">
|
||||
<el-table-column prop="createTime" label="创建时间" min-width="180" align="center" header-align="center" />
|
||||
<el-table-column label="操作" width="480" fixed="right" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button class="btn-op-item" @click="handleView(row)"><el-icon><View /></el-icon>查看</el-button>
|
||||
<el-button class="btn-op-item primary" @click="handlePostBindUsers(row)">
|
||||
<el-icon><User /></el-icon>
|
||||
关联用户
|
||||
</el-button>
|
||||
<el-button class="btn-op-item primary" @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button class="btn-op-item" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
@@ -133,17 +138,6 @@
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序">
|
||||
<div class="sort-field">
|
||||
<el-input-number
|
||||
v-model="formData.orderNum"
|
||||
:min="0"
|
||||
:max="9999"
|
||||
controls-position="right"
|
||||
/>
|
||||
<span class="form-tip">数值越小越靠前</span>
|
||||
</div>
|
||||
</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>
|
||||
@@ -160,20 +154,138 @@
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 关联用户(布局对齐角色管理「数据权限」自定义范围) -->
|
||||
<el-dialog
|
||||
v-model="postBindDialogVisible"
|
||||
title="关联用户"
|
||||
width="1120px"
|
||||
class="dialog-form-layout"
|
||||
align-center
|
||||
destroy-on-close
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<div v-loading="postBindLoading" class="post-bind-dialog-body">
|
||||
<p v-if="postBindPostName" class="post-bind-subtitle">
|
||||
职位:<strong>{{ postBindPostName }}</strong>
|
||||
</p>
|
||||
<el-form label-position="top" class="data-scope-form">
|
||||
<el-form-item label="绑定用户" class="data-scope-custom-form-item">
|
||||
<div class="data-scope-custom-grid">
|
||||
<div class="data-scope-custom-col">
|
||||
<div>
|
||||
<div class="data-scope-col-title">选择部门</div>
|
||||
<div class="data-scope-col-tip">点击部门名称可按该部门及子部门筛选右侧用户</div>
|
||||
</div>
|
||||
<div class="data-scope-tree-wrap">
|
||||
<el-tree
|
||||
ref="postBindDeptTreeRef"
|
||||
:data="postBindDeptTreeData"
|
||||
highlight-current
|
||||
node-key="id"
|
||||
:props="{ label: 'deptName', children: 'children' }"
|
||||
default-expand-all
|
||||
:expand-on-click-node="false"
|
||||
@node-click="handlePostBindDeptNodeClick"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="data-scope-custom-col">
|
||||
<div class="data-scope-col-head-row">
|
||||
<span class="data-scope-col-title">选择用户</span>
|
||||
<el-button
|
||||
v-if="postBindUserFilterDeptId"
|
||||
class="btn-ghost"
|
||||
size="small"
|
||||
@click="clearPostBindUserDeptFilter"
|
||||
>
|
||||
清除部门筛选
|
||||
</el-button>
|
||||
</div>
|
||||
<el-input
|
||||
v-model="postBindUserKeyword"
|
||||
class="data-scope-user-filter"
|
||||
clearable
|
||||
placeholder="按姓名、账号过滤"
|
||||
/>
|
||||
<div class="data-scope-user-list-wrap">
|
||||
<el-checkbox-group
|
||||
v-if="postBindFilteredUsers.length > 0"
|
||||
v-model="postBindUserCheckedKeys"
|
||||
>
|
||||
<div
|
||||
v-for="u in postBindFilteredUsers"
|
||||
:key="u.id"
|
||||
class="data-scope-user-row"
|
||||
>
|
||||
<el-checkbox :value="u.id">{{ postBindUserOptionLabel(u) }}</el-checkbox>
|
||||
</div>
|
||||
</el-checkbox-group>
|
||||
<el-empty v-else :description="postBindUserEmptyDesc" :image-size="40" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="data-scope-selection-summary">
|
||||
<template v-if="postBindSelectedUserSummaries.length > 0">
|
||||
<div class="data-scope-summary-block">
|
||||
<div class="data-scope-summary-heading">已选用户</div>
|
||||
<ul class="data-scope-summary-list">
|
||||
<li v-for="row in postBindSelectedUserSummaries" :key="'u-' + row.id">
|
||||
{{ row.label }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
<p v-else class="data-scope-summary-empty">暂未勾选用户</p>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button class="btn-ghost" @click="postBindDialogVisible = false">
|
||||
<el-icon><Close /></el-icon>
|
||||
取消
|
||||
</el-button>
|
||||
<el-button
|
||||
class="btn-main"
|
||||
type="primary"
|
||||
@click="handlePostBindSubmit"
|
||||
:loading="postBindSubmitLoading"
|
||||
>
|
||||
<el-icon><Check /></el-icon>
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<SystemViewDialog
|
||||
v-model:visible="viewVisible"
|
||||
:title="viewRow?.postName || '职位详情'"
|
||||
:icon="Briefcase"
|
||||
:meta="`职位编码:${viewRow?.postCode || ''}${viewRow?.createTime ? ' · ' + viewRow.createTime : ''}`"
|
||||
:sections="viewSections"
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ref, reactive, computed, onMounted, nextTick } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus, Close, Check } from '@element-plus/icons-vue'
|
||||
import { Plus, Close, Check, User, View, Briefcase } from '@element-plus/icons-vue'
|
||||
import SystemViewDialog from '@/components/business/system-view-dialog/index.vue'
|
||||
import { MAX_ADMIN_LIST_PAGE_SIZE } from '@/utils/fetch-paged-list'
|
||||
import { withFullscreenLoading, fullscreenLoadingText } from '@/utils/fullscreen-loading'
|
||||
import {
|
||||
fetchPostList,
|
||||
fetchCreatePost,
|
||||
fetchUpdatePost,
|
||||
fetchDeletePost,
|
||||
fetchDictDataOptions
|
||||
fetchDictDataOptions,
|
||||
fetchDeptTree,
|
||||
fetchUserList,
|
||||
fetchPostBoundUserIds,
|
||||
fetchUpdatePostBoundUsers
|
||||
} from '@/api/admin'
|
||||
|
||||
defineOptions({ name: 'SystemPost' })
|
||||
@@ -205,6 +317,221 @@
|
||||
|
||||
const statusOptions = ref<Api.Dict.DictDataOption[]>([])
|
||||
|
||||
// ---- 查看弹窗 ----
|
||||
const viewVisible = ref(false)
|
||||
const viewRow = ref<Api.Post.PostItem | null>(null)
|
||||
const viewBoundUserNames = ref<string[]>([])
|
||||
const viewSections = computed(() => {
|
||||
const row = viewRow.value
|
||||
if (!row) return []
|
||||
const sections: any[] = [
|
||||
{
|
||||
title: '基本信息',
|
||||
fields: [
|
||||
{ label: '职位名称', value: row.postName },
|
||||
{ label: '职位编码', value: row.postCode },
|
||||
{ label: '状态', value: row.status === '1' ? '正常' : '停用' },
|
||||
{ label: '创建时间', value: row.createTime },
|
||||
{ label: '备注', value: row.remark, span: true }
|
||||
]
|
||||
}
|
||||
]
|
||||
if (viewBoundUserNames.value.length > 0) {
|
||||
sections.push({
|
||||
title: '关联用户',
|
||||
fields: [
|
||||
{ label: '已关联用户', value: viewBoundUserNames.value.join('、'), span: true }
|
||||
]
|
||||
})
|
||||
}
|
||||
return sections
|
||||
})
|
||||
async function handleView(row: Api.Post.PostItem) {
|
||||
viewRow.value = row
|
||||
viewBoundUserNames.value = []
|
||||
viewVisible.value = true
|
||||
try {
|
||||
const [boundRes] = await Promise.all([
|
||||
fetchPostBoundUserIds(row.id),
|
||||
fetchDeptTree()
|
||||
])
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 关联用户弹窗(布局对齐角色管理「数据权限」自定义范围)----
|
||||
const postBindDialogVisible = ref(false)
|
||||
const postBindLoading = ref(false)
|
||||
const postBindSubmitLoading = ref(false)
|
||||
const postBindPostId = ref('')
|
||||
const postBindPostName = ref('')
|
||||
const postBindDeptTreeRef = ref()
|
||||
const postBindDeptTreeData = ref<Api.Dept.DeptItem[]>([])
|
||||
const postBindAllUsers = ref<
|
||||
Array<{ id: string; nickName: string; userNo: string; deptId: string; deptName?: string }>
|
||||
>([])
|
||||
const postBindUserCheckedKeys = ref<string[]>([])
|
||||
const postBindUserFilterDeptId = ref<string | null>(null)
|
||||
const postBindUserKeyword = ref('')
|
||||
|
||||
function findPostBindDeptNodeById(nodes: Api.Dept.DeptItem[], id: string): Api.Dept.DeptItem | null {
|
||||
for (const n of nodes) {
|
||||
if (n.id === id) return n
|
||||
if (n.children?.length) {
|
||||
const found = findPostBindDeptNodeById(n.children, id)
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function collectPostBindDeptSubtreeIds(node: Api.Dept.DeptItem): string[] {
|
||||
const ids = [node.id]
|
||||
for (const c of node.children || []) ids.push(...collectPostBindDeptSubtreeIds(c))
|
||||
return ids
|
||||
}
|
||||
|
||||
function collectAllPostBindDeptIds(nodes: Api.Dept.DeptItem[]): string[] {
|
||||
const ids: string[] = []
|
||||
const walk = (list: Api.Dept.DeptItem[]) => {
|
||||
for (const n of list) {
|
||||
ids.push(n.id)
|
||||
if (n.children?.length) walk(n.children)
|
||||
}
|
||||
}
|
||||
walk(nodes)
|
||||
return ids
|
||||
}
|
||||
|
||||
async function expandPostBindDeptTree() {
|
||||
await nextTick()
|
||||
const tree = postBindDeptTreeRef.value
|
||||
const keys = collectAllPostBindDeptIds(postBindDeptTreeData.value)
|
||||
if (tree && keys.length && typeof tree.setExpandedKeys === 'function') {
|
||||
tree.setExpandedKeys(keys)
|
||||
}
|
||||
}
|
||||
|
||||
const postBindDeptFilterIdSet = computed(() => {
|
||||
const id = postBindUserFilterDeptId.value
|
||||
if (!id) return null
|
||||
const node = findPostBindDeptNodeById(postBindDeptTreeData.value, id)
|
||||
if (!node) return new Set<string>([id])
|
||||
return new Set(collectPostBindDeptSubtreeIds(node))
|
||||
})
|
||||
|
||||
const postBindFilteredUsers = computed(() => {
|
||||
const kw = postBindUserKeyword.value.trim().toLowerCase()
|
||||
const deptSet = postBindDeptFilterIdSet.value
|
||||
return postBindAllUsers.value.filter((u) => {
|
||||
if (deptSet && !deptSet.has(u.deptId)) return false
|
||||
if (!kw) return true
|
||||
const name = (u.nickName || '').toLowerCase()
|
||||
const no = (u.userNo || '').toLowerCase()
|
||||
return name.includes(kw) || no.includes(kw)
|
||||
})
|
||||
})
|
||||
|
||||
const postBindUserEmptyDesc = computed(() => {
|
||||
if (postBindAllUsers.value.length === 0) return '暂无用户数据'
|
||||
const hasDept = Boolean(postBindUserFilterDeptId.value)
|
||||
const kw = postBindUserKeyword.value.trim()
|
||||
if (hasDept && kw) return '该部门下无匹配用户'
|
||||
if (hasDept) return '该部门下暂无用户'
|
||||
if (kw) return '无匹配用户'
|
||||
return '无匹配用户'
|
||||
})
|
||||
|
||||
const postBindSelectedUserSummaries = computed(() =>
|
||||
postBindUserCheckedKeys.value.map((id) => {
|
||||
const u = postBindAllUsers.value.find((x) => x.id === id)
|
||||
return { id, label: u ? postBindUserOptionLabel(u) : id }
|
||||
})
|
||||
)
|
||||
|
||||
function postBindUserOptionLabel(u: {
|
||||
id: string
|
||||
nickName: string
|
||||
userNo: string
|
||||
deptName?: string
|
||||
}) {
|
||||
const base = u.nickName || u.userNo || u.id
|
||||
if (u.deptName) return `${base}(${u.deptName})`
|
||||
return base
|
||||
}
|
||||
|
||||
function handlePostBindDeptNodeClick(data: Api.Dept.DeptItem) {
|
||||
postBindUserFilterDeptId.value = data.id
|
||||
postBindDeptTreeRef.value?.setCurrentKey?.(data.id)
|
||||
}
|
||||
|
||||
function clearPostBindUserDeptFilter() {
|
||||
postBindUserFilterDeptId.value = null
|
||||
postBindDeptTreeRef.value?.setCurrentKey?.(null)
|
||||
}
|
||||
|
||||
async function fetchAllUsersForPostBind(): Promise<
|
||||
Array<{ id: string; nickName: string; userNo: string; deptId: string; deptName?: string }>
|
||||
> {
|
||||
const pageSize = MAX_ADMIN_LIST_PAGE_SIZE
|
||||
const raw: any[] = []
|
||||
let page = 1
|
||||
for (;;) {
|
||||
const res = await fetchUserList({ page, pageSize })
|
||||
const list = res?.list || []
|
||||
raw.push(...list)
|
||||
if (list.length < pageSize) break
|
||||
if (typeof res?.total === 'number' && raw.length >= res.total) break
|
||||
page += 1
|
||||
}
|
||||
return raw.map((u: any) => ({
|
||||
id: u.id,
|
||||
deptId: u.deptId || '',
|
||||
nickName: u.nickName || u.realName || '',
|
||||
userNo: u.userNo || '',
|
||||
deptName: u.deptName
|
||||
}))
|
||||
}
|
||||
|
||||
async function handlePostBindUsers(row: Api.Post.PostItem) {
|
||||
postBindPostId.value = row.id
|
||||
postBindPostName.value = row.postName || row.postCode || ''
|
||||
postBindUserCheckedKeys.value = []
|
||||
postBindUserFilterDeptId.value = null
|
||||
postBindUserKeyword.value = ''
|
||||
postBindDialogVisible.value = true
|
||||
postBindLoading.value = true
|
||||
try {
|
||||
const [boundRes, deptTree, users] = await Promise.all([
|
||||
fetchPostBoundUserIds(row.id),
|
||||
fetchDeptTree(),
|
||||
fetchAllUsersForPostBind()
|
||||
])
|
||||
postBindUserCheckedKeys.value = [...(boundRes?.userIds || [])]
|
||||
postBindDeptTreeData.value = deptTree || []
|
||||
postBindAllUsers.value = users
|
||||
await expandPostBindDeptTree()
|
||||
} finally {
|
||||
postBindLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePostBindSubmit() {
|
||||
postBindSubmitLoading.value = true
|
||||
try {
|
||||
await fetchUpdatePostBoundUsers(postBindPostId.value, [...postBindUserCheckedKeys.value])
|
||||
postBindDialogVisible.value = false
|
||||
} finally {
|
||||
postBindSubmitLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadDictOptions = async () => {
|
||||
try {
|
||||
const bmzt = await fetchDictDataOptions('bmzt')
|
||||
@@ -311,11 +638,14 @@
|
||||
const ids = selectedRows.value.map((r) => r.id)
|
||||
if (!ids.length) return
|
||||
await ElMessageBox.confirm(`确定删除选中的 ${ids.length} 个职位吗?`, '提示', { type: 'warning' })
|
||||
for (const id of ids) {
|
||||
await fetchDeletePost(id)
|
||||
}
|
||||
selectedRows.value = []
|
||||
await loadData()
|
||||
await withFullscreenLoading(async () => {
|
||||
for (const id of ids) {
|
||||
await fetchDeletePost(id)
|
||||
}
|
||||
ElMessage.success('批量删除成功')
|
||||
selectedRows.value = []
|
||||
await loadData()
|
||||
}, fullscreenLoadingText.batchDelete)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@@ -329,13 +659,142 @@
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.el-form-item__label) {
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
color: var(--mint-text-muted);
|
||||
padding: 0 0 4px;
|
||||
line-height: 1.2;
|
||||
.post-bind-dialog-body {
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
.post-bind-subtitle {
|
||||
margin: 0 0 12px;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
|
||||
.data-scope-form {
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.data-scope-custom-form-item {
|
||||
margin-top: 0;
|
||||
|
||||
:deep(.el-form-item__content) {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.data-scope-custom-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.data-scope-custom-col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.data-scope-col-title {
|
||||
padding-left: 10px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-regular);
|
||||
border-left: 3px solid #10b981;
|
||||
}
|
||||
|
||||
.data-scope-col-tip {
|
||||
margin-top: 4px;
|
||||
font-size: 11px;
|
||||
line-height: 1.45;
|
||||
color: var(--mint-text-muted, var(--el-text-color-secondary));
|
||||
}
|
||||
|
||||
.data-scope-col-head-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.data-scope-tree-wrap {
|
||||
max-height: 280px;
|
||||
padding: 8px;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.data-scope-user-filter {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.data-scope-user-list-wrap {
|
||||
max-height: 236px;
|
||||
padding: 8px;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.data-scope-user-row {
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.data-scope-selection-summary {
|
||||
margin-top: 12px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 8px;
|
||||
background: var(--el-fill-color-blank);
|
||||
}
|
||||
|
||||
.data-scope-summary-block + .data-scope-summary-block {
|
||||
margin-top: 10px;
|
||||
padding-top: 10px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.data-scope-summary-heading {
|
||||
margin-bottom: 6px;
|
||||
padding-left: 10px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-regular);
|
||||
border-left: 3px solid #10b981;
|
||||
}
|
||||
|
||||
.data-scope-summary-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 8px 12px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
font-size: 12px;
|
||||
line-height: 1.45;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
|
||||
.data-scope-summary-list li {
|
||||
min-width: 0;
|
||||
padding: 6px 8px;
|
||||
overflow-wrap: anywhere;
|
||||
word-break: break-word;
|
||||
border-radius: 6px;
|
||||
background: var(--el-fill-color-light);
|
||||
}
|
||||
|
||||
.data-scope-summary-empty {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--mint-text-muted, var(--el-text-color-secondary));
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user