chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,391 @@
|
||||
<template>
|
||||
<div class="org-center-page">
|
||||
<!-- 页头与知识库/企业培训同构:资源图标 + 页面名称 + 副标题 -->
|
||||
<header class="org-header">
|
||||
<div class="org-title-row">
|
||||
<div class="org-title-group">
|
||||
<h2>
|
||||
<ResourceIcon type="training" :size="24" />
|
||||
组织架构
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
<p class="org-subtitle">部门与员工档案(租户共享),业务模块(企业培训/图纸标注等)按需引用</p>
|
||||
</header>
|
||||
|
||||
<!-- 3/7 分栏:左侧部门,右侧员工档案 -->
|
||||
<div class="org-body">
|
||||
<div class="org-layout">
|
||||
<div class="panel-box org-layout__depts">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">部门</span>
|
||||
<t-button theme="primary" @click="openCreateDept">新增部门</t-button>
|
||||
</div>
|
||||
<t-table :data="depts" :columns="deptColumns" row-key="id" size="small">
|
||||
<template #op="{ row }">
|
||||
<div class="op-group">
|
||||
<t-button variant="text" theme="primary" size="small" @click="onEditDept(row)">修改</t-button>
|
||||
<t-button variant="text" theme="danger" size="small" @click="onDeleteDept(row)">删除</t-button>
|
||||
</div>
|
||||
</template>
|
||||
</t-table>
|
||||
</div>
|
||||
|
||||
<div class="panel-box org-layout__employees">
|
||||
<div class="panel-box__header">
|
||||
<span class="panel-box__title">员工档案</span>
|
||||
<div style="display: flex; gap: 8px">
|
||||
<t-button variant="outline" @click="openPicker">从平台用户添加</t-button>
|
||||
<t-button theme="primary" @click="importVisible = true">批量导入</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<t-table :data="employees" :columns="employeeColumns" row-key="id" size="small" :loading="loading">
|
||||
<template #user_name="{ row }">
|
||||
<t-tooltip :content="employeeName(row)" :disabled="!employeeName(row)">
|
||||
<span class="employee-name">{{ employeeName(row) || '-' }}</span>
|
||||
</t-tooltip>
|
||||
</template>
|
||||
<template #dept_name="{ row }">{{ row.dept_name || '-' }}</template>
|
||||
<template #status="{ row }">
|
||||
<t-tag v-if="row.status === 'active'" theme="success" variant="light" size="small">在职</t-tag>
|
||||
<t-tag v-else theme="default" variant="light" size="small">{{ row.status || '-' }}</t-tag>
|
||||
</template>
|
||||
</t-table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 部门新增/修改弹窗 -->
|
||||
<t-dialog v-model:visible="deptFormVisible" :header="deptForm.id ? '修改部门' : '新增部门'" width="420">
|
||||
<t-form label-width="80">
|
||||
<t-form-item label="部门名称" required>
|
||||
<t-input v-model="deptForm.name" />
|
||||
</t-form-item>
|
||||
<t-form-item label="部门编码">
|
||||
<t-input v-model="deptForm.code" />
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<template #footer>
|
||||
<t-button theme="primary" :loading="saving" @click="onSaveDept">保存</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
|
||||
<!-- 批量导入:每行 用户ID,工号,部门,岗位 -->
|
||||
<t-dialog v-model:visible="importVisible" header="批量导入员工(每行:用户ID,工号,部门,岗位)" width="560">
|
||||
<t-textarea
|
||||
v-model="importText"
|
||||
:autosize="{ minRows: 8 }"
|
||||
placeholder="user-uuid-1,26010003,生产一部,设备技师"
|
||||
/>
|
||||
<div class="form-hint">
|
||||
部门为必填,支持填左侧部门的名称 / 编码 / ID,未维护的部门将整批拒绝导入。
|
||||
工号可留空,留空时自动取平台账号。
|
||||
</div>
|
||||
<template #footer>
|
||||
<t-button theme="primary" :loading="saving" @click="onImport">导入</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
|
||||
<!-- 从平台用户添加:选择用户 → 指定部门/岗位(工号自动取平台账号) -->
|
||||
<t-dialog v-model:visible="pickerVisible" header="从平台用户添加员工档案" width="520">
|
||||
<t-form label-width="80">
|
||||
<t-form-item label="选择用户" required>
|
||||
<t-select v-model="pickerUserIds" multiple filterable placeholder="选择平台账号(可多选)" style="width: 100%">
|
||||
<t-option
|
||||
v-for="u in platformUsers"
|
||||
:key="u.id"
|
||||
:value="u.id"
|
||||
:label="`${u.username}(${u.display_name?.trim() || u.email})${u.in_roster ? ' · 已在名册' : ''}`"
|
||||
:disabled="u.in_roster"
|
||||
/>
|
||||
</t-select>
|
||||
</t-form-item>
|
||||
<t-form-item label="部门" required>
|
||||
<t-select v-model="pickerDeptId" filterable placeholder="必选,请从左侧部门中选择" style="width: 100%">
|
||||
<t-option v-for="d in depts" :key="d.id" :value="d.id" :label="d.name" />
|
||||
</t-select>
|
||||
</t-form-item>
|
||||
<t-form-item label="岗位">
|
||||
<t-input v-model="pickerPost" placeholder="如 设备技师" />
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<div class="form-hint">工号无需填写,添加时自动取平台账号(下拉里展示的编号)。</div>
|
||||
<template #footer>
|
||||
<t-button theme="primary" :loading="saving" :disabled="!pickerUserIds.length || !pickerDeptId" @click="onPickImport">添加到名册</t-button>
|
||||
</template>
|
||||
</t-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import {
|
||||
deleteDept,
|
||||
importEmployees,
|
||||
listDepts,
|
||||
listEmployees,
|
||||
listPlatformUsers,
|
||||
saveDept,
|
||||
type OrgDept,
|
||||
type OrgEmployee,
|
||||
type OrgPlatformUser,
|
||||
} from '@/api/org-center'
|
||||
import { unwrap } from '@/api/training'
|
||||
import ResourceIcon from '@/components/icons/ResourceIcon.vue'
|
||||
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const depts = ref<OrgDept[]>([])
|
||||
const employees = ref<OrgEmployee[]>([])
|
||||
const platformUsers = ref<OrgPlatformUser[]>([])
|
||||
|
||||
const deptFormVisible = ref(false)
|
||||
const importVisible = ref(false)
|
||||
// id 为空表示新增,否则为修改(后端 saveDept 的 upsert 语义)。
|
||||
const deptForm = ref({ id: '', parent_id: '', sort: 0, name: '', code: '' })
|
||||
const importText = ref('')
|
||||
|
||||
// 用户选择器导入
|
||||
const pickerVisible = ref(false)
|
||||
const pickerUserIds = ref<string[]>([])
|
||||
const pickerDeptId = ref('')
|
||||
const pickerPost = ref('')
|
||||
|
||||
const deptColumns = [
|
||||
{ colKey: 'name', title: '部门名称' },
|
||||
{ colKey: 'code', title: '编码', width: 140 },
|
||||
{ colKey: 'op', title: '操作', width: 140 },
|
||||
]
|
||||
|
||||
const employeeColumns = [
|
||||
{ colKey: 'employee_no', title: '工号', width: 100 },
|
||||
{ colKey: 'user_name', title: '姓名' },
|
||||
{ colKey: 'dept_name', title: '部门', width: 120 },
|
||||
{ colKey: 'post', title: '岗位', width: 150 },
|
||||
{ colKey: 'status', title: '状态', width: 80 },
|
||||
]
|
||||
|
||||
// 姓名 = 真实姓名(来自 OIDC displayName claim):优先取后端联查的 user_name,
|
||||
// 再用平台用户表的 display_name / username 兜底;都取不到展示「-」,不回退展示用户ID。
|
||||
const userNameMap = computed(() => {
|
||||
const m: Record<string, string> = {}
|
||||
for (const u of platformUsers.value) m[u.id] = u.display_name?.trim() || u.username
|
||||
return m
|
||||
})
|
||||
const employeeName = (row: OrgEmployee) => row.user_name || userNameMap.value[row.user_id] || ''
|
||||
|
||||
const loadAll = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
// 平台用户一并拉取,用于姓名兜底联查(user_id → 用户名)。
|
||||
const [d, e, u] = await Promise.all([
|
||||
listDepts(),
|
||||
listEmployees({ page_size: 500 }),
|
||||
listPlatformUsers().catch(() => null),
|
||||
])
|
||||
depts.value = unwrap(d) || []
|
||||
employees.value = unwrap(e)?.items || []
|
||||
platformUsers.value = unwrap(u) || []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const openCreateDept = () => {
|
||||
deptForm.value = { id: '', parent_id: '', sort: 0, name: '', code: '' }
|
||||
deptFormVisible.value = true
|
||||
}
|
||||
|
||||
const onSaveDept = async () => {
|
||||
if (!deptForm.value.name) {
|
||||
MessagePlugin.warning('请填写部门名称')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
await saveDept(deptForm.value)
|
||||
MessagePlugin.success(deptForm.value.id ? '部门已更新' : '部门已保存')
|
||||
deptFormVisible.value = false
|
||||
deptForm.value = { id: '', parent_id: '', sort: 0, name: '', code: '' }
|
||||
loadAll()
|
||||
} catch {
|
||||
MessagePlugin.error('保存失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 修改部门:回填当前行(带 id 走更新,并透传 parent_id/sort 防止被清空)。
|
||||
const onEditDept = (row: OrgDept) => {
|
||||
deptForm.value = {
|
||||
id: row.id,
|
||||
parent_id: row.parent_id || '',
|
||||
sort: row.sort || 0,
|
||||
name: row.name,
|
||||
code: row.code || '',
|
||||
}
|
||||
deptFormVisible.value = true
|
||||
}
|
||||
|
||||
const onDeleteDept = async (row: OrgDept) => {
|
||||
if (!window.confirm(`确认删除部门「${row.name}」?`)) return
|
||||
try {
|
||||
await deleteDept(row.id)
|
||||
MessagePlugin.success('已删除')
|
||||
loadAll()
|
||||
} catch {
|
||||
MessagePlugin.error('删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
const openPicker = async () => {
|
||||
pickerVisible.value = true
|
||||
try {
|
||||
const res = await listPlatformUsers()
|
||||
platformUsers.value = unwrap(res) || []
|
||||
if (!depts.value.length) {
|
||||
const d = await listDepts()
|
||||
depts.value = unwrap(d) || []
|
||||
}
|
||||
} catch {
|
||||
platformUsers.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const onPickImport = async () => {
|
||||
if (!pickerUserIds.value.length) return
|
||||
// 部门必填:必须归属已维护的部门。
|
||||
if (!pickerDeptId.value) {
|
||||
MessagePlugin.warning('请选择部门')
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
// 工号 = 平台账号(username,员工编号型 IdP 同步而来),不再前缀自增生成。
|
||||
const usernameMap = new Map(platformUsers.value.map((u) => [u.id, u.username]))
|
||||
const items = pickerUserIds.value.map((uid) => ({
|
||||
user_id: uid,
|
||||
employee_no: usernameMap.get(uid) || '',
|
||||
dept_id: pickerDeptId.value,
|
||||
post: pickerPost.value,
|
||||
}))
|
||||
await importEmployees(items)
|
||||
MessagePlugin.success(`已添加 ${items.length} 名员工到名册`)
|
||||
pickerVisible.value = false
|
||||
pickerUserIds.value = []
|
||||
pickerDeptId.value = ''
|
||||
loadAll()
|
||||
} catch {
|
||||
MessagePlugin.error('添加失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 按名称/编码/ID 把导入行里的部门解析成部门列表的 dept id。
|
||||
const resolveDeptId = (raw?: string) => {
|
||||
const key = (raw || '').trim()
|
||||
if (!key) return ''
|
||||
const hit = depts.value.find((d) => d.id === key || d.code === key || d.name === key)
|
||||
return hit?.id || ''
|
||||
}
|
||||
|
||||
const onImport = async () => {
|
||||
const lines = importText.value.split('\n').map((l) => l.trim()).filter(Boolean)
|
||||
if (!lines.length) {
|
||||
MessagePlugin.warning('请粘贴员工行')
|
||||
return
|
||||
}
|
||||
const items: { user_id: string; employee_no: string; dept_id: string; post: string }[] = []
|
||||
const badRows: string[] = []
|
||||
lines.forEach((line, i) => {
|
||||
// 兼容中英文逗号(\uFF0C)与制表符拆分:用户ID,工号,部门,岗位
|
||||
const [user_id, employee_no, deptRaw, post] = line.split(/[,\uFF0C\t]/).map((s) => s.trim())
|
||||
const dept_id = resolveDeptId(deptRaw)
|
||||
// 部门必填,且必须命中左侧部门(名称/编码/ID 均可)。
|
||||
if (!user_id || !dept_id) {
|
||||
badRows.push(`第 ${i + 1} 行${!user_id ? '缺少用户ID' : ''}${!user_id && !dept_id ? '、' : ''}${!dept_id ? '部门未匹配到已维护部门' : ''}`)
|
||||
return
|
||||
}
|
||||
items.push({ user_id, employee_no: employee_no || '', dept_id, post: post || '' })
|
||||
})
|
||||
if (badRows.length) {
|
||||
MessagePlugin.error(badRows.slice(0, 3).join(';') + (badRows.length > 3 ? ` 等 ${badRows.length} 行不合法` : ',请检查后重试'))
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const res = await importEmployees(items)
|
||||
MessagePlugin.success(`已导入 ${unwrap(res)?.imported ?? 0} 名员工`)
|
||||
importVisible.value = false
|
||||
importText.value = ''
|
||||
loadAll()
|
||||
} catch {
|
||||
MessagePlugin.error('导入失败,请检查部门是否为已维护部门')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadAll)
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import (reference) '../training/training.less';
|
||||
|
||||
// 页面容器与页头沿用企业培训的视觉规范(知识库/工具箱同款)
|
||||
.org-center-page {
|
||||
.training-page-frame();
|
||||
}
|
||||
|
||||
.org-header {
|
||||
.training-header();
|
||||
}
|
||||
|
||||
.org-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: var(--app-space-3) 0 var(--app-space-6);
|
||||
}
|
||||
|
||||
// 3/7 分栏:部门列占 3,员工档案列占 7;窄屏退化为单列
|
||||
.org-layout {
|
||||
display: grid;
|
||||
grid-template-columns: 3fr 7fr;
|
||||
gap: 12px;
|
||||
align-items: start;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.panel-box {
|
||||
.training-panel-box();
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
margin-top: 8px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
// 部门行内操作按钮组
|
||||
.op-group {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
// 姓名列:最多展示 2 行,超出省略(悬停 tooltip 看全名)
|
||||
.employee-name {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
word-break: break-all;
|
||||
line-height: 1.4;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user