更新后端
This commit is contained in:
@@ -0,0 +1,285 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 组织架构相关接口
|
||||||
|
|
||||||
|
// 获取组织架构列表
|
||||||
|
export function getOrganizationList(params) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/getOrganization',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取组织架构详情
|
||||||
|
export function getOrganizationDetail(id) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/getOrganizationDetail/${id}`,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建组织架构
|
||||||
|
export function createOrganization(data) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/createOrganization',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新组织架构
|
||||||
|
export function updateOrganization(id, data) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/editOrganization/${id}`,
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除组织架构
|
||||||
|
export function deleteOrganization(id) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/deleteOrganization/${id}`,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取企业单位列表
|
||||||
|
export function getCompanyList(params) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/getCompanys',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取部门列表
|
||||||
|
export function getDepartmentList(params) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/getDepartments',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 员工相关接口
|
||||||
|
|
||||||
|
// 获取员工列表
|
||||||
|
export function getEmployeeList(params) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/getEmployee',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取员工详情
|
||||||
|
export function getEmployeeDetail(id) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/getEmployeeDetail/${id}`,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建员工
|
||||||
|
export function createEmployee(data) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/createEmployee',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新员工
|
||||||
|
export function updateEmployee(id, data) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/editEmployee/${id}`,
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除员工
|
||||||
|
export function deleteEmployee(id) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/deleteEmployee/${id}`,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 职位相关接口
|
||||||
|
|
||||||
|
// 获取职位列表
|
||||||
|
export function getPositionList(params) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/getPosition',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取职位详情
|
||||||
|
export function getPositionDetail(id) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/getPositionDetail/${id}`,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建职位
|
||||||
|
export function createPosition(data) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/createPosition',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新职位
|
||||||
|
export function updatePosition(id, data) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/editPosition/${id}`,
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除职位
|
||||||
|
export function deletePosition(id) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/deletePosition/${id}`,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组织设置相关接口
|
||||||
|
|
||||||
|
// 获取组织设置
|
||||||
|
export function getOrgSettings() {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/getOrgSettings',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存组织设置
|
||||||
|
export function saveOrgSettings(data) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/saveOrgSettings',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组织架构导出
|
||||||
|
export function exportOrganization(params) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/exportOrganization',
|
||||||
|
method: 'get',
|
||||||
|
params,
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组织架构导入
|
||||||
|
export function importOrganization(data) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/importOrganization',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量操作组织
|
||||||
|
export function batchOrganizeOrganizations(ids, action) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/batchOrganizeOrganizations',
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
ids,
|
||||||
|
action
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取组织架构统计信息
|
||||||
|
export function getOrganizationStats() {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/getOrganizationStats',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取组织架构树形结构
|
||||||
|
export function getOrganizationTree(params) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/getOrganizationTree',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搜索组织架构
|
||||||
|
export function searchOrganizations(keyword) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/searchOrganizations',
|
||||||
|
method: 'get',
|
||||||
|
params: { keyword }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取组织架构下的所有员工
|
||||||
|
export function getOrganizationEmployees(orgId) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/getOrganizationEmployees/${orgId}`,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移动员工到其他组织
|
||||||
|
export function moveEmployeeToOrg(employeeId, orgId) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/moveEmployeeToOrg',
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
employee_id: employeeId,
|
||||||
|
org_id: orgId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取组织架构层级关系
|
||||||
|
export function getOrganizationHierarchy(orgId) {
|
||||||
|
return request({
|
||||||
|
url: `/backend/erp/getOrganizationHierarchy/${orgId}`,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证组织编码唯一性
|
||||||
|
export function checkOrgCodeUnique(orgCode, excludeId) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/checkOrgCodeUnique',
|
||||||
|
method: 'get',
|
||||||
|
params: {
|
||||||
|
org_code: orgCode,
|
||||||
|
exclude_id: excludeId || ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证员工账号唯一性
|
||||||
|
export function checkEmployeeAccountUnique(account, excludeId) {
|
||||||
|
return request({
|
||||||
|
url: '/backend/erp/checkEmployeeAccountUnique',
|
||||||
|
method: 'get',
|
||||||
|
params: {
|
||||||
|
account,
|
||||||
|
exclude_id: excludeId || ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -69,6 +69,13 @@ const staticMainChildren = [
|
|||||||
component: () => import("@/views/user/userProfile.vue"),
|
component: () => import("@/views/user/userProfile.vue"),
|
||||||
meta: { requiresAuth: true, title: "用户中心" }
|
meta: { requiresAuth: true, title: "用户中心" }
|
||||||
},
|
},
|
||||||
|
// OA 组织架构
|
||||||
|
{
|
||||||
|
path: "/apps/oa/organization",
|
||||||
|
name: "Organization",
|
||||||
|
component: () => import("@/views/apps/oa/organization/index.vue"),
|
||||||
|
meta: { requiresAuth: true, title: "组织架构", modulePath: "/apps/oa" }
|
||||||
|
},
|
||||||
// 兼容拼写错误的路径重定向
|
// 兼容拼写错误的路径重定向
|
||||||
{
|
{
|
||||||
path: "/apps/erp/dashborad",
|
path: "/apps/erp/dashborad",
|
||||||
|
|||||||
@@ -0,0 +1,383 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
v-model="visible"
|
||||||
|
:title="title"
|
||||||
|
width="600px"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
@close="handleClose"
|
||||||
|
>
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="form"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<el-form-item label="姓名" prop="name">
|
||||||
|
<el-input
|
||||||
|
v-model="form.name"
|
||||||
|
placeholder="请输入姓名"
|
||||||
|
maxlength="30"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="账号" prop="account">
|
||||||
|
<el-input
|
||||||
|
v-model="form.account"
|
||||||
|
placeholder="请输入账号"
|
||||||
|
maxlength="50"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
账号用于登录系统,建议使用英文或数字
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="密码" prop="password">
|
||||||
|
<el-input
|
||||||
|
v-model="form.password"
|
||||||
|
type="password"
|
||||||
|
placeholder="请输入密码"
|
||||||
|
maxlength="64"
|
||||||
|
show-word-limit
|
||||||
|
v-if="!isEdit"
|
||||||
|
/>
|
||||||
|
<el-input
|
||||||
|
v-model="form.password"
|
||||||
|
type="password"
|
||||||
|
placeholder="留空表示不修改密码"
|
||||||
|
maxlength="64"
|
||||||
|
show-word-limit
|
||||||
|
v-else
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="性别" prop="gender">
|
||||||
|
<el-radio-group v-model="form.gender">
|
||||||
|
<el-radio :label="1">男</el-radio>
|
||||||
|
<el-radio :label="2">女</el-radio>
|
||||||
|
<el-radio :label="0">未知</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="生日" prop="birthday">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="form.birthday"
|
||||||
|
type="date"
|
||||||
|
placeholder="请选择生日"
|
||||||
|
style="width: 100%"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="所属单位" prop="affiliate_unit">
|
||||||
|
<el-tree-select
|
||||||
|
v-model="form.affiliate_unit"
|
||||||
|
:data="orgOptions"
|
||||||
|
:props="treeProps"
|
||||||
|
placeholder="请选择所属单位"
|
||||||
|
clearable
|
||||||
|
check-strictly
|
||||||
|
style="width: 100%"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="所属部门" prop="department">
|
||||||
|
<el-tree-select
|
||||||
|
v-model="form.department"
|
||||||
|
:data="orgOptions"
|
||||||
|
:props="treeProps"
|
||||||
|
placeholder="请选择所属部门"
|
||||||
|
clearable
|
||||||
|
check-strictly
|
||||||
|
style="width: 100%"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="职位" prop="position">
|
||||||
|
<el-input
|
||||||
|
v-model="form.position"
|
||||||
|
placeholder="请输入职位"
|
||||||
|
maxlength="50"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="学历" prop="education">
|
||||||
|
<el-select
|
||||||
|
v-model="form.education"
|
||||||
|
placeholder="请选择学历"
|
||||||
|
clearable
|
||||||
|
style="width: 100%"
|
||||||
|
>
|
||||||
|
<el-option label="博士" value="博士" />
|
||||||
|
<el-option label="硕士" value="硕士" />
|
||||||
|
<el-option label="本科" value="本科" />
|
||||||
|
<el-option label="专科" value="专科" />
|
||||||
|
<el-option label="高中" value="高中" />
|
||||||
|
<el-option label="其他" value="其他" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="民族" prop="nation">
|
||||||
|
<el-input
|
||||||
|
v-model="form.nation"
|
||||||
|
placeholder="请输入民族"
|
||||||
|
maxlength="20"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="电话" prop="phone">
|
||||||
|
<el-input
|
||||||
|
v-model="form.phone"
|
||||||
|
placeholder="请输入电话"
|
||||||
|
maxlength="20"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="微信" prop="wechat">
|
||||||
|
<el-input
|
||||||
|
v-model="form.wechat"
|
||||||
|
placeholder="请输入微信"
|
||||||
|
maxlength="50"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="邮箱" prop="email">
|
||||||
|
<el-input
|
||||||
|
v-model="form.email"
|
||||||
|
placeholder="请输入邮箱"
|
||||||
|
maxlength="100"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="家庭住址" prop="home_address">
|
||||||
|
<el-input
|
||||||
|
v-model="form.home_address"
|
||||||
|
placeholder="请输入家庭住址"
|
||||||
|
maxlength="255"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="状态" prop="account_status">
|
||||||
|
<el-radio-group v-model="form.account_status">
|
||||||
|
<el-radio :label="1">正常</el-radio>
|
||||||
|
<el-radio :label="0">禁用</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button @click="handleClose">取消</el-button>
|
||||||
|
<el-button type="primary" @click="handleSubmit" :loading="loading">
|
||||||
|
{{ isEdit ? '保存' : '创建' }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { getOrganizationList } from '@/api/organization'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
formData: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
|
},
|
||||||
|
isEdit: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:modelValue', 'save'])
|
||||||
|
|
||||||
|
const visible = computed({
|
||||||
|
get: () => props.modelValue,
|
||||||
|
set: (value) => emit('update:modelValue', value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const formRef = ref()
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
const treeProps = {
|
||||||
|
value: 'id',
|
||||||
|
label: 'org_name',
|
||||||
|
children: 'children'
|
||||||
|
}
|
||||||
|
|
||||||
|
const orgOptions = ref([])
|
||||||
|
|
||||||
|
const emptyForm = () => ({
|
||||||
|
name: '',
|
||||||
|
account: '',
|
||||||
|
gender: 0,
|
||||||
|
birthday: '',
|
||||||
|
affiliate_unit: '',
|
||||||
|
department: '',
|
||||||
|
position: '',
|
||||||
|
education: '',
|
||||||
|
nation: '',
|
||||||
|
phone: '',
|
||||||
|
wechat: '',
|
||||||
|
email: '',
|
||||||
|
home_address: '',
|
||||||
|
account_status: 1
|
||||||
|
})
|
||||||
|
|
||||||
|
const form = ref(emptyForm())
|
||||||
|
|
||||||
|
const rules = {
|
||||||
|
name: [
|
||||||
|
{ required: true, message: '请输入姓名', trigger: 'blur' },
|
||||||
|
{ min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
account: [
|
||||||
|
{ required: true, message: '请输入账号', trigger: 'blur' },
|
||||||
|
{ min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' },
|
||||||
|
{ pattern: /^[a-zA-Z0-9_-]+$/, message: '只能包含英文、数字、下划线和横线', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
gender: [
|
||||||
|
{ required: true, message: '请选择性别', trigger: 'change' }
|
||||||
|
],
|
||||||
|
birthday: [
|
||||||
|
{ required: false }
|
||||||
|
],
|
||||||
|
affiliate_unit: [
|
||||||
|
{ required: false }
|
||||||
|
],
|
||||||
|
department: [
|
||||||
|
{ required: false }
|
||||||
|
],
|
||||||
|
position: [
|
||||||
|
{ required: false }
|
||||||
|
],
|
||||||
|
education: [
|
||||||
|
{ required: false }
|
||||||
|
],
|
||||||
|
nation: [
|
||||||
|
{ required: false }
|
||||||
|
],
|
||||||
|
phone: [
|
||||||
|
{ required: false },
|
||||||
|
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
wechat: [
|
||||||
|
{ required: false }
|
||||||
|
],
|
||||||
|
email: [
|
||||||
|
{ required: false },
|
||||||
|
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
home_address: [
|
||||||
|
{ required: false }
|
||||||
|
],
|
||||||
|
account_status: [
|
||||||
|
{ required: true, message: '请选择状态', trigger: 'change' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = computed(() => props.isEdit ? '编辑员工' : '新建员工')
|
||||||
|
|
||||||
|
const loadOrgOptions = async () => {
|
||||||
|
try {
|
||||||
|
const data = await getOrganizationList()
|
||||||
|
orgOptions.value = buildOrgTree(data)
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(error?.message || '加载组织列表失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const buildOrgTree = (data) => {
|
||||||
|
const tree = []
|
||||||
|
const map = {}
|
||||||
|
|
||||||
|
// 创建映射
|
||||||
|
data.forEach(item => {
|
||||||
|
map[item.id] = { ...item, children: [] }
|
||||||
|
})
|
||||||
|
|
||||||
|
// 构建树形结构
|
||||||
|
data.forEach(item => {
|
||||||
|
const node = map[item.id]
|
||||||
|
if (item.parent_id === 0) {
|
||||||
|
tree.push(node)
|
||||||
|
} else {
|
||||||
|
const parent = map[item.parent_id]
|
||||||
|
if (parent) {
|
||||||
|
parent.children.push(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return tree
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (!formRef.value) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await formRef.value.validate()
|
||||||
|
loading.value = true
|
||||||
|
|
||||||
|
const formData = { ...form.value }
|
||||||
|
|
||||||
|
emit('save', formData)
|
||||||
|
loading.value = false
|
||||||
|
} catch (error) {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
visible.value = false
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
form.value = emptyForm()
|
||||||
|
}
|
||||||
|
|
||||||
|
const initForm = () => {
|
||||||
|
if (props.isEdit && props.formData) {
|
||||||
|
form.value = {
|
||||||
|
...props.formData
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
form.value = emptyForm()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(() => props.modelValue, (newVal) => {
|
||||||
|
if (newVal) {
|
||||||
|
initForm()
|
||||||
|
loadOrgOptions()
|
||||||
|
}
|
||||||
|
}, { immediate: true })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.form-tip {
|
||||||
|
margin-top: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,301 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
v-model="visible"
|
||||||
|
:title="title"
|
||||||
|
width="600px"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
@close="handleClose"
|
||||||
|
>
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="form"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<el-form-item label="组织名称" prop="org_name">
|
||||||
|
<el-input
|
||||||
|
v-model="form.org_name"
|
||||||
|
placeholder="请输入组织名称"
|
||||||
|
maxlength="50"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="组织编码" prop="org_code">
|
||||||
|
<el-input
|
||||||
|
v-model="form.org_code"
|
||||||
|
placeholder="请输入组织编码"
|
||||||
|
maxlength="20"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
组织编码用于系统内部标识,建议使用英文或数字
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="上级组织" prop="parent_id">
|
||||||
|
<el-tree-select
|
||||||
|
v-model="form.parent_id"
|
||||||
|
:data="orgOptions"
|
||||||
|
:props="treeProps"
|
||||||
|
placeholder="请选择上级组织"
|
||||||
|
clearable
|
||||||
|
check-strictly
|
||||||
|
style="width: 100%"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
选择上级组织,顶级组织请留空
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="组织类型" prop="is_company">
|
||||||
|
<el-radio-group v-model="form.is_company">
|
||||||
|
<el-radio :label="1">企业单位</el-radio>
|
||||||
|
<el-radio :label="0">部门</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="负责人" prop="leader_id">
|
||||||
|
<el-select
|
||||||
|
v-model="form.leader_id"
|
||||||
|
placeholder="请选择负责人"
|
||||||
|
clearable
|
||||||
|
style="width: 100%"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="employee in employeeOptions"
|
||||||
|
:key="employee.id"
|
||||||
|
:label="employee.name"
|
||||||
|
:value="employee.id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="排序" prop="sort">
|
||||||
|
<el-input-number
|
||||||
|
v-model="form.sort"
|
||||||
|
:min="0"
|
||||||
|
:max="9999"
|
||||||
|
placeholder="请输入排序值"
|
||||||
|
style="width: 100%"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
数字越小,排序越靠前
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-radio-group v-model="form.status">
|
||||||
|
<el-radio :label="1">启用</el-radio>
|
||||||
|
<el-radio :label="0">禁用</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="备注" prop="remark">
|
||||||
|
<el-input
|
||||||
|
v-model="form.remark"
|
||||||
|
type="textarea"
|
||||||
|
:rows="3"
|
||||||
|
placeholder="请输入备注信息"
|
||||||
|
maxlength="500"
|
||||||
|
show-word-limit
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button @click="handleClose">取消</el-button>
|
||||||
|
<el-button type="primary" @click="handleSubmit" :loading="loading">
|
||||||
|
{{ isEdit ? '保存' : '创建' }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
import { getOrganizationList, getEmployeeList } from '@/api/organization'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
formData: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
|
},
|
||||||
|
isEdit: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:modelValue', 'save'])
|
||||||
|
|
||||||
|
const visible = computed({
|
||||||
|
get: () => props.modelValue,
|
||||||
|
set: (value) => emit('update:modelValue', value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const formRef = ref()
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
const treeProps = {
|
||||||
|
value: 'id',
|
||||||
|
label: 'org_name',
|
||||||
|
children: 'children'
|
||||||
|
}
|
||||||
|
|
||||||
|
const orgOptions = ref([])
|
||||||
|
const employeeOptions = ref([])
|
||||||
|
|
||||||
|
const emptyForm = () => ({
|
||||||
|
org_name: '',
|
||||||
|
org_code: '',
|
||||||
|
parent_id: null,
|
||||||
|
leader_id: null,
|
||||||
|
is_company: 0,
|
||||||
|
sort: 0,
|
||||||
|
status: 1,
|
||||||
|
remark: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
const form = ref(emptyForm())
|
||||||
|
|
||||||
|
const rules = {
|
||||||
|
org_name: [
|
||||||
|
{ required: true, message: '请输入组织名称', trigger: 'blur' },
|
||||||
|
{ min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
org_code: [
|
||||||
|
{ required: true, message: '请输入组织编码', trigger: 'blur' },
|
||||||
|
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' },
|
||||||
|
{ pattern: /^[a-zA-Z0-9_-]+$/, message: '只能包含英文、数字、下划线和横线', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
parent_id: [
|
||||||
|
{ required: true, message: '请选择上级组织', trigger: 'change' }
|
||||||
|
],
|
||||||
|
is_company: [
|
||||||
|
{ required: true, message: '请选择组织类型', trigger: 'change' }
|
||||||
|
],
|
||||||
|
sort: [
|
||||||
|
{ required: true, message: '请输入排序值', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
status: [
|
||||||
|
{ required: true, message: '请选择状态', trigger: 'change' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = computed(() => props.isEdit ? '编辑组织' : '新建组织')
|
||||||
|
|
||||||
|
const loadOrgOptions = async () => {
|
||||||
|
try {
|
||||||
|
const data = await getOrganizationList()
|
||||||
|
orgOptions.value = buildOrgTree(data)
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(error?.message || '加载组织列表失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadEmployeeOptions = async () => {
|
||||||
|
try {
|
||||||
|
const data = await getEmployeeList()
|
||||||
|
employeeOptions.value = data.map(item => ({
|
||||||
|
id: item.id,
|
||||||
|
name: item.name
|
||||||
|
}))
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(error?.message || '加载员工列表失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const buildOrgTree = (data) => {
|
||||||
|
const tree = []
|
||||||
|
const map = {}
|
||||||
|
|
||||||
|
// 创建映射
|
||||||
|
data.forEach(item => {
|
||||||
|
map[item.id] = { ...item, children: [] }
|
||||||
|
})
|
||||||
|
|
||||||
|
// 构建树形结构
|
||||||
|
data.forEach(item => {
|
||||||
|
const node = map[item.id]
|
||||||
|
if (item.parent_id === 0) {
|
||||||
|
tree.push(node)
|
||||||
|
} else {
|
||||||
|
const parent = map[item.parent_id]
|
||||||
|
if (parent) {
|
||||||
|
parent.children.push(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return tree
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (!formRef.value) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await formRef.value.validate()
|
||||||
|
loading.value = true
|
||||||
|
|
||||||
|
const formData = { ...form.value }
|
||||||
|
if (formData.parent_id === 0) {
|
||||||
|
formData.parent_id = null
|
||||||
|
}
|
||||||
|
|
||||||
|
emit('save', formData)
|
||||||
|
loading.value = false
|
||||||
|
} catch (error) {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
visible.value = false
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
form.value = emptyForm()
|
||||||
|
}
|
||||||
|
|
||||||
|
const initForm = () => {
|
||||||
|
if (props.isEdit && props.formData) {
|
||||||
|
form.value = {
|
||||||
|
...props.formData,
|
||||||
|
parent_id: props.formData.parent_id || null,
|
||||||
|
leader_id: props.formData.leader_id || null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
form.value = emptyForm()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(() => props.modelValue, (newVal) => {
|
||||||
|
if (newVal) {
|
||||||
|
initForm()
|
||||||
|
loadOrgOptions()
|
||||||
|
loadEmployeeOptions()
|
||||||
|
}
|
||||||
|
}, { immediate: true })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.form-tip {
|
||||||
|
margin-top: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,259 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
v-model="visible"
|
||||||
|
title="组织设置"
|
||||||
|
width="600px"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
@close="handleClose"
|
||||||
|
>
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="form"
|
||||||
|
:rules="rules"
|
||||||
|
label-width="120px"
|
||||||
|
label-position="right"
|
||||||
|
>
|
||||||
|
<el-form-item label="默认组织类型" prop="default_org_type">
|
||||||
|
<el-radio-group v-model="form.default_org_type">
|
||||||
|
<el-radio :label="1">企业单位</el-radio>
|
||||||
|
<el-radio :label="0">部门</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
<div class="form-tip">
|
||||||
|
设置新建组织时的默认类型
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="自动生成编码" prop="auto_generate_code">
|
||||||
|
<el-switch
|
||||||
|
v-model="form.auto_generate_code"
|
||||||
|
active-text="开启"
|
||||||
|
inactive-text="关闭"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
开启后系统将自动生成组织编码
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="编码前缀" prop="code_prefix">
|
||||||
|
<el-input
|
||||||
|
v-model="form.code_prefix"
|
||||||
|
placeholder="请输入编码前缀"
|
||||||
|
maxlength="10"
|
||||||
|
show-word-limit
|
||||||
|
:disabled="!form.auto_generate_code"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
自动生成编码时的前缀,如:ORG、DEPT等
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="编码长度" prop="code_length">
|
||||||
|
<el-input-number
|
||||||
|
v-model="form.code_length"
|
||||||
|
:min="4"
|
||||||
|
:max="20"
|
||||||
|
placeholder="请输入编码长度"
|
||||||
|
:disabled="!form.auto_generate_code"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
自动生成编码时的长度,包含前缀
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="默认排序" prop="default_sort">
|
||||||
|
<el-input-number
|
||||||
|
v-model="form.default_sort"
|
||||||
|
:min="0"
|
||||||
|
:max="9999"
|
||||||
|
placeholder="请输入默认排序值"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
新建组织时的默认排序值
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="默认状态" prop="default_status">
|
||||||
|
<el-radio-group v-model="form.default_status">
|
||||||
|
<el-radio :label="1">启用</el-radio>
|
||||||
|
<el-radio :label="0">禁用</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="显示层级" prop="max_level">
|
||||||
|
<el-input-number
|
||||||
|
v-model="form.max_level"
|
||||||
|
:min="1"
|
||||||
|
:max="10"
|
||||||
|
placeholder="请输入最大显示层级"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
组织树形结构最多显示的层级数
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="批量操作" prop="batch_operations">
|
||||||
|
<el-switch
|
||||||
|
v-model="form.batch_operations"
|
||||||
|
active-text="开启"
|
||||||
|
inactive-text="关闭"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
开启后支持批量操作组织
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="导出功能" prop="export_enabled">
|
||||||
|
<el-switch
|
||||||
|
v-model="form.export_enabled"
|
||||||
|
active-text="开启"
|
||||||
|
inactive-text="关闭"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
开启后支持导出组织架构数据
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="导入功能" prop="import_enabled">
|
||||||
|
<el-switch
|
||||||
|
v-model="form.import_enabled"
|
||||||
|
active-text="开启"
|
||||||
|
inactive-text="关闭"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
开启后支持导入组织架构数据
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="同步员工" prop="sync_employee">
|
||||||
|
<el-switch
|
||||||
|
v-model="form.sync_employee"
|
||||||
|
active-text="开启"
|
||||||
|
inactive-text="关闭"
|
||||||
|
/>
|
||||||
|
<div class="form-tip">
|
||||||
|
开启后创建组织时自动同步员工信息
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button @click="handleClose">取消</el-button>
|
||||||
|
<el-button type="primary" @click="handleSubmit" :loading="loading">
|
||||||
|
保存设置
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:modelValue', 'changed'])
|
||||||
|
|
||||||
|
const visible = computed({
|
||||||
|
get: () => props.modelValue,
|
||||||
|
set: (value) => emit('update:modelValue', value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const formRef = ref()
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
const emptyForm = () => ({
|
||||||
|
default_org_type: 1,
|
||||||
|
auto_generate_code: true,
|
||||||
|
code_prefix: 'ORG',
|
||||||
|
code_length: 8,
|
||||||
|
default_sort: 0,
|
||||||
|
default_status: 1,
|
||||||
|
max_level: 5,
|
||||||
|
batch_operations: true,
|
||||||
|
export_enabled: true,
|
||||||
|
import_enabled: true,
|
||||||
|
sync_employee: false
|
||||||
|
})
|
||||||
|
|
||||||
|
const form = ref(emptyForm())
|
||||||
|
|
||||||
|
const rules = {
|
||||||
|
default_org_type: [
|
||||||
|
{ required: true, message: '请选择默认组织类型', trigger: 'change' }
|
||||||
|
],
|
||||||
|
auto_generate_code: [
|
||||||
|
{ required: true, message: '请选择是否自动生成编码', trigger: 'change' }
|
||||||
|
],
|
||||||
|
code_prefix: [
|
||||||
|
{ required: true, message: '请输入编码前缀', trigger: 'blur' },
|
||||||
|
{ min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
code_length: [
|
||||||
|
{ required: true, message: '请输入编码长度', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
default_sort: [
|
||||||
|
{ required: true, message: '请输入默认排序值', trigger: 'blur' }
|
||||||
|
],
|
||||||
|
default_status: [
|
||||||
|
{ required: true, message: '请选择默认状态', trigger: 'change' }
|
||||||
|
],
|
||||||
|
max_level: [
|
||||||
|
{ required: true, message: '请输入最大显示层级', trigger: 'blur' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (!formRef.value) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await formRef.value.validate()
|
||||||
|
loading.value = true
|
||||||
|
|
||||||
|
// 这里可以调用API保存设置
|
||||||
|
// await saveOrgSettings(form.value)
|
||||||
|
|
||||||
|
ElMessage.success('设置保存成功')
|
||||||
|
emit('changed')
|
||||||
|
loading.value = false
|
||||||
|
visible.value = false
|
||||||
|
} catch (error) {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
visible.value = false
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
form.value = emptyForm()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听自动生成编码开关
|
||||||
|
watch(() => form.value.auto_generate_code, (newVal) => {
|
||||||
|
if (!newVal) {
|
||||||
|
form.value.code_prefix = ''
|
||||||
|
form.value.code_length = 8
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.form-tip {
|
||||||
|
margin-top: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,696 @@
|
|||||||
|
<template>
|
||||||
|
<div class="organization-page">
|
||||||
|
<div class="page-header">
|
||||||
|
<div>
|
||||||
|
<h2>组织架构</h2>
|
||||||
|
<p>管理企业组织架构、部门设置和人员信息</p>
|
||||||
|
</div>
|
||||||
|
<div class="header-actions">
|
||||||
|
<el-button :icon="Setting" @click="openOrgSettings">组织设置</el-button>
|
||||||
|
<el-button type="primary" :icon="Plus" @click="openCreateOrg">新建组织</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="organization-container">
|
||||||
|
<!-- 左侧树形结构 -->
|
||||||
|
<div class="org-tree-container">
|
||||||
|
<div class="tree-header">
|
||||||
|
<h3>组织架构图</h3>
|
||||||
|
<div class="tree-actions">
|
||||||
|
<el-button :icon="Refresh" @click="loadOrgTree" circle />
|
||||||
|
<el-button :icon="Expand" @click="expandAll" circle />
|
||||||
|
<el-button :icon="Fold" @click="collapseAll" circle />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="org-tree">
|
||||||
|
<el-tree
|
||||||
|
ref="orgTreeRef"
|
||||||
|
:data="orgTreeData"
|
||||||
|
:props="treeProps"
|
||||||
|
node-key="id"
|
||||||
|
default-expand-all
|
||||||
|
highlight-current
|
||||||
|
@node-click="handleNodeClick"
|
||||||
|
@node-expand="handleNodeExpand"
|
||||||
|
@node-collapse="handleNodeCollapse"
|
||||||
|
>
|
||||||
|
<template #default="{ data }">
|
||||||
|
<div class="tree-node">
|
||||||
|
<div class="node-content">
|
||||||
|
<span class="node-icon">
|
||||||
|
<el-icon v-if="data.is_company">
|
||||||
|
<Office />
|
||||||
|
</el-icon>
|
||||||
|
<el-icon v-else>
|
||||||
|
<Folder />
|
||||||
|
</el-icon>
|
||||||
|
</span>
|
||||||
|
<span class="node-label">{{ data.org_name }}</span>
|
||||||
|
<span class="node-code">{{ data.org_code }}</span>
|
||||||
|
<span class="node-status">
|
||||||
|
<el-tag :type="data.status === 1 ? 'success' : 'danger'" size="small">
|
||||||
|
{{ data.status === 1 ? '启用' : '禁用' }}
|
||||||
|
</el-tag>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="node-actions">
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
size="small"
|
||||||
|
@click.stop="editOrg(data)"
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
size="small"
|
||||||
|
@click.stop="addChildOrg(data)"
|
||||||
|
>
|
||||||
|
添加子组织
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="danger"
|
||||||
|
size="small"
|
||||||
|
@click.stop="deleteOrg(data)"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-tree>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 右侧详情面板 -->
|
||||||
|
<div class="org-detail-container">
|
||||||
|
<div class="detail-header">
|
||||||
|
<h3>组织详情</h3>
|
||||||
|
<div class="detail-actions">
|
||||||
|
<el-button
|
||||||
|
v-if="selectedOrg"
|
||||||
|
type="primary"
|
||||||
|
:icon="Plus"
|
||||||
|
@click="openCreateEmployee"
|
||||||
|
>
|
||||||
|
添加员工
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="selectedOrg" class="org-detail">
|
||||||
|
<!-- 基本信息 -->
|
||||||
|
<div class="detail-section">
|
||||||
|
<h4>基本信息</h4>
|
||||||
|
<el-descriptions :column="2" border>
|
||||||
|
<el-descriptions-item label="组织名称">{{ selectedOrg.org_name }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="组织编码">{{ selectedOrg.org_code }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="上级组织">{{ selectedOrg.parent_name || '无' }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="排序">{{ selectedOrg.sort }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="组织类型">
|
||||||
|
<el-tag :type="selectedOrg.is_company ? 'primary' : 'success'">
|
||||||
|
{{ selectedOrg.is_company ? '企业单位' : '部门' }}
|
||||||
|
</el-tag>
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="状态">
|
||||||
|
<el-tag :type="selectedOrg.status === 1 ? 'success' : 'danger'">
|
||||||
|
{{ selectedOrg.status === 1 ? '启用' : '禁用' }}
|
||||||
|
</el-tag>
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="负责人" v-if="selectedOrg.leader_name">
|
||||||
|
{{ selectedOrg.leader_name }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="创建时间">
|
||||||
|
{{ formatDate(selectedOrg.create_time) }}
|
||||||
|
</el-descriptions-item>
|
||||||
|
</el-descriptions>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 备注信息 -->
|
||||||
|
<div class="detail-section">
|
||||||
|
<h4>备注信息</h4>
|
||||||
|
<div class="remark-content">
|
||||||
|
{{ selectedOrg.remark || '无备注' }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 员工列表 -->
|
||||||
|
<div class="detail-section">
|
||||||
|
<h4>员工列表</h4>
|
||||||
|
<div class="employee-list">
|
||||||
|
<el-table :data="employeeList" stripe>
|
||||||
|
<el-table-column prop="name" label="姓名" width="120" />
|
||||||
|
<el-table-column prop="account" label="账号" width="150" />
|
||||||
|
<el-table-column prop="department" label="部门" width="150" />
|
||||||
|
<el-table-column prop="position" label="职位" width="150" />
|
||||||
|
<el-table-column prop="phone" label="电话" width="120" />
|
||||||
|
<el-table-column prop="email" label="邮箱" />
|
||||||
|
<el-table-column label="状态" width="80">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag :type="row.account_status === 1 ? 'success' : 'danger'" size="small">
|
||||||
|
{{ row.account_status === 1 ? '正常' : '禁用' }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" width="150">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-button link type="primary" @click="editEmployee(row)">编辑</el-button>
|
||||||
|
<el-button link type="danger" @click="deleteEmployee(row)">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="empty-detail">
|
||||||
|
<el-empty description="请选择一个组织查看详情" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 组织编辑对话框 -->
|
||||||
|
<OrgEditDialog
|
||||||
|
v-model="orgEditVisible"
|
||||||
|
:form-data="orgFormData"
|
||||||
|
:is-edit="orgEditMode"
|
||||||
|
@save="saveOrg"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- 员工编辑对话框 -->
|
||||||
|
<EmployeeEditDialog
|
||||||
|
v-model="employeeEditVisible"
|
||||||
|
:form-data="employeeFormData"
|
||||||
|
:is-edit="employeeEditMode"
|
||||||
|
@save="saveEmployee"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- 组织设置对话框 -->
|
||||||
|
<OrgSettingsDialog
|
||||||
|
v-model="orgSettingsVisible"
|
||||||
|
@changed="loadOrgTree"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed, onMounted, reactive, ref } from "vue";
|
||||||
|
import { ElMessage, ElMessageBox } from "element-plus";
|
||||||
|
import {
|
||||||
|
Plus,
|
||||||
|
Refresh,
|
||||||
|
Setting,
|
||||||
|
Office,
|
||||||
|
Folder,
|
||||||
|
Expand,
|
||||||
|
Fold
|
||||||
|
} from "@element-plus/icons-vue";
|
||||||
|
import OrgEditDialog from "./components/orgEditDialog.vue";
|
||||||
|
import EmployeeEditDialog from "./components/employeeEditDialog.vue";
|
||||||
|
import OrgSettingsDialog from "./components/orgSettingsDialog.vue";
|
||||||
|
import {
|
||||||
|
getOrganizationList,
|
||||||
|
getOrganizationDetail,
|
||||||
|
createOrganization,
|
||||||
|
updateOrganization,
|
||||||
|
deleteOrganization,
|
||||||
|
getEmployeeList,
|
||||||
|
createEmployee,
|
||||||
|
updateEmployee,
|
||||||
|
deleteEmployee,
|
||||||
|
getOrgSettings
|
||||||
|
} from "@/api/organization";
|
||||||
|
|
||||||
|
const orgTreeRef = ref();
|
||||||
|
const orgTreeData = ref([]);
|
||||||
|
const selectedOrg = ref(null);
|
||||||
|
const employeeList = ref([]);
|
||||||
|
const orgEditVisible = ref(false);
|
||||||
|
const employeeEditVisible = ref(false);
|
||||||
|
const orgSettingsVisible = ref(false);
|
||||||
|
const orgEditMode = ref(false);
|
||||||
|
const employeeEditMode = ref(false);
|
||||||
|
|
||||||
|
const treeProps = {
|
||||||
|
children: 'children',
|
||||||
|
label: 'org_name'
|
||||||
|
};
|
||||||
|
|
||||||
|
const emptyOrgForm = () => ({
|
||||||
|
org_name: '',
|
||||||
|
org_code: '',
|
||||||
|
parent_id: 0,
|
||||||
|
leader_id: null,
|
||||||
|
is_company: 0,
|
||||||
|
sort: 0,
|
||||||
|
status: 1,
|
||||||
|
remark: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const orgFormData = reactive(emptyOrgForm());
|
||||||
|
|
||||||
|
const emptyEmployeeForm = () => ({
|
||||||
|
name: '',
|
||||||
|
account: '',
|
||||||
|
gender: 0,
|
||||||
|
birthday: '',
|
||||||
|
affiliate_unit: '',
|
||||||
|
department: '',
|
||||||
|
position: '',
|
||||||
|
education: '',
|
||||||
|
nation: '',
|
||||||
|
phone: '',
|
||||||
|
wechat: '',
|
||||||
|
email: '',
|
||||||
|
home_address: '',
|
||||||
|
account_status: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
const employeeFormData = reactive(emptyEmployeeForm());
|
||||||
|
|
||||||
|
const loadOrgTree = async () => {
|
||||||
|
try {
|
||||||
|
const data = await getOrganizationList();
|
||||||
|
orgTreeData.value = buildTreeData(data);
|
||||||
|
if (orgTreeData.value.length > 0 && !selectedOrg.value) {
|
||||||
|
selectedOrg.value = orgTreeData.value[0];
|
||||||
|
await loadEmployeeList(selectedOrg.value.id);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(error?.message || '加载组织架构失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const buildTreeData = (data) => {
|
||||||
|
const tree = [];
|
||||||
|
const map = {};
|
||||||
|
|
||||||
|
// 创建映射
|
||||||
|
data.forEach(item => {
|
||||||
|
map[item.id] = { ...item, children: [] };
|
||||||
|
});
|
||||||
|
|
||||||
|
// 构建树形结构
|
||||||
|
data.forEach(item => {
|
||||||
|
const node = map[item.id];
|
||||||
|
if (item.parent_id === 0) {
|
||||||
|
tree.push(node);
|
||||||
|
} else {
|
||||||
|
const parent = map[item.parent_id];
|
||||||
|
if (parent) {
|
||||||
|
parent.children.push(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return tree;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNodeClick = async (data) => {
|
||||||
|
selectedOrg.value = data;
|
||||||
|
await loadEmployeeList(data.id);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNodeExpand = (data) => {
|
||||||
|
console.log('Node expanded:', data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNodeCollapse = (data) => {
|
||||||
|
console.log('Node collapsed:', data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const expandAll = () => {
|
||||||
|
orgTreeRef.value?.expandAll();
|
||||||
|
};
|
||||||
|
|
||||||
|
const collapseAll = () => {
|
||||||
|
orgTreeRef.value?.collapseAll();
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadEmployeeList = async (orgId) => {
|
||||||
|
try {
|
||||||
|
const data = await getEmployeeList({ org_id: orgId });
|
||||||
|
employeeList.value = data || [];
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(error?.message || '加载员工列表失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openCreateOrg = () => {
|
||||||
|
orgEditMode.value = false;
|
||||||
|
Object.assign(orgFormData, emptyOrgForm());
|
||||||
|
orgFormData.parent_id = selectedOrg.value ? selectedOrg.value.id : 0;
|
||||||
|
orgFormData.is_company = selectedOrg.value ? 0 : 1;
|
||||||
|
orgEditVisible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const editOrg = (data) => {
|
||||||
|
orgEditMode.value = true;
|
||||||
|
Object.assign(orgFormData, {
|
||||||
|
id: data.id,
|
||||||
|
org_name: data.org_name,
|
||||||
|
org_code: data.org_code,
|
||||||
|
parent_id: data.parent_id,
|
||||||
|
leader_id: data.leader_id,
|
||||||
|
is_company: data.is_company,
|
||||||
|
sort: data.sort,
|
||||||
|
status: data.status,
|
||||||
|
remark: data.remark
|
||||||
|
});
|
||||||
|
orgEditVisible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const addChildOrg = (data) => {
|
||||||
|
orgEditMode.value = false;
|
||||||
|
Object.assign(orgFormData, emptyOrgForm());
|
||||||
|
orgFormData.parent_id = data.id;
|
||||||
|
orgFormData.is_company = 0;
|
||||||
|
orgEditVisible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteOrg = async (data) => {
|
||||||
|
try {
|
||||||
|
await ElMessageBox.confirm('确认删除这个组织吗?删除后将无法恢复。', '删除确认', {
|
||||||
|
type: 'warning',
|
||||||
|
});
|
||||||
|
await deleteOrganization(data.id);
|
||||||
|
ElMessage.success('删除成功');
|
||||||
|
await loadOrgTree();
|
||||||
|
} catch (error) {
|
||||||
|
if (error !== 'cancel' && error !== 'close') {
|
||||||
|
ElMessage.error(error?.message || '删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveOrg = async (payload) => {
|
||||||
|
try {
|
||||||
|
if (orgEditMode.value) {
|
||||||
|
await updateOrganization(orgFormData.id, payload);
|
||||||
|
ElMessage.success('更新成功');
|
||||||
|
} else {
|
||||||
|
await createOrganization(payload);
|
||||||
|
ElMessage.success('创建成功');
|
||||||
|
}
|
||||||
|
orgEditVisible.value = false;
|
||||||
|
await loadOrgTree();
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(error?.message || '保存失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openCreateEmployee = () => {
|
||||||
|
employeeEditMode.value = false;
|
||||||
|
Object.assign(employeeFormData, emptyEmployeeForm());
|
||||||
|
employeeFormData.affiliate_unit = selectedOrg.value ? selectedOrg.value.id.toString() : '';
|
||||||
|
employeeFormData.department = selectedOrg.value ? selectedOrg.value.id.toString() : '';
|
||||||
|
employeeEditVisible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const editEmployee = (data) => {
|
||||||
|
employeeEditMode.value = true;
|
||||||
|
Object.assign(employeeFormData, {
|
||||||
|
id: data.id,
|
||||||
|
name: data.name,
|
||||||
|
account: data.account,
|
||||||
|
gender: data.gender,
|
||||||
|
birthday: data.birthday,
|
||||||
|
affiliate_unit: data.affiliate_unit,
|
||||||
|
department: data.department,
|
||||||
|
position: data.position,
|
||||||
|
education: data.education,
|
||||||
|
nation: data.nation,
|
||||||
|
phone: data.phone,
|
||||||
|
wechat: data.wechat,
|
||||||
|
email: data.email,
|
||||||
|
home_address: data.home_address,
|
||||||
|
account_status: data.account_status
|
||||||
|
});
|
||||||
|
employeeEditVisible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteEmployee = async (data) => {
|
||||||
|
try {
|
||||||
|
await ElMessageBox.confirm('确认删除这个员工吗?删除后将无法恢复。', '删除确认', {
|
||||||
|
type: 'warning',
|
||||||
|
});
|
||||||
|
await deleteEmployee(data.id);
|
||||||
|
ElMessage.success('删除成功');
|
||||||
|
await loadEmployeeList(selectedOrg.value.id);
|
||||||
|
} catch (error) {
|
||||||
|
if (error !== 'cancel' && error !== 'close') {
|
||||||
|
ElMessage.error(error?.message || '删除失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveEmployee = async (payload) => {
|
||||||
|
try {
|
||||||
|
if (employeeEditMode.value) {
|
||||||
|
await updateEmployee(employeeFormData.id, payload);
|
||||||
|
ElMessage.success('更新成功');
|
||||||
|
} else {
|
||||||
|
await createEmployee(payload);
|
||||||
|
ElMessage.success('创建成功');
|
||||||
|
}
|
||||||
|
employeeEditVisible.value = false;
|
||||||
|
await loadEmployeeList(selectedOrg.value.id);
|
||||||
|
} catch (error) {
|
||||||
|
ElMessage.error(error?.message || '保存失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openOrgSettings = () => {
|
||||||
|
orgSettingsVisible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDate = (value) => {
|
||||||
|
if (!value) return '-';
|
||||||
|
return new Date(value).toLocaleString('zh-CN', { hour12: false });
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadOrgTree();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.organization-page {
|
||||||
|
min-height: calc(100vh - 84px);
|
||||||
|
background: #f5f7fa;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-header h2 {
|
||||||
|
margin: 0 0 8px;
|
||||||
|
color: #303133;
|
||||||
|
font-size: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-header p {
|
||||||
|
margin: 0;
|
||||||
|
color: #909399;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.organization-container {
|
||||||
|
display: flex;
|
||||||
|
gap: 16px;
|
||||||
|
height: calc(100vh - 140px);
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.org-tree-container {
|
||||||
|
width: 350px;
|
||||||
|
border-right: 1px solid #e4e7ed;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-header {
|
||||||
|
padding: 16px;
|
||||||
|
border-bottom: 1px solid #e4e7ed;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-header h3 {
|
||||||
|
margin: 0;
|
||||||
|
color: #303133;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.org-tree {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-node {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-node:hover {
|
||||||
|
background-color: #f5f7fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node-icon {
|
||||||
|
color: #409eff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node-label {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #303133;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node-code {
|
||||||
|
color: #909399;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node-status {
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 4px;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-node:hover .node-actions {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.org-detail-container {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-header {
|
||||||
|
padding: 16px;
|
||||||
|
border-bottom: 1px solid #e4e7ed;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-header h3 {
|
||||||
|
margin: 0;
|
||||||
|
color: #303133;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.org-detail {
|
||||||
|
flex: 1;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-section {
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-section h4 {
|
||||||
|
margin: 0 0 16px 0;
|
||||||
|
color: #303133;
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.remark-content {
|
||||||
|
padding: 12px;
|
||||||
|
background: #f5f7fa;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: #606266;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.employee-list {
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-detail {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.organization-page {
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.organization-container {
|
||||||
|
flex-direction: column;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.org-tree-container {
|
||||||
|
width: 100%;
|
||||||
|
height: 300px;
|
||||||
|
border-right: none;
|
||||||
|
border-bottom: 1px solid #e4e7ed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.org-tree {
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-header {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-actions {
|
||||||
|
width: 100%;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1076,3 +1076,353 @@ func hashEmployeePassword(plain string) string {
|
|||||||
sum := sha256.Sum256([]byte(plain))
|
sum := sha256.Sum256([]byte(plain))
|
||||||
return hex.EncodeToString(sum[:])
|
return hex.EncodeToString(sum[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOrgSettings 获取组织架构设置
|
||||||
|
// GET /backend/erp/getOrgSettings
|
||||||
|
func (c *BackendErpController) GetOrgSettings() {
|
||||||
|
tid, _ := c.GetInt("tid")
|
||||||
|
|
||||||
|
settings := map[string]interface{}{
|
||||||
|
"org_code_prefix": "ORG",
|
||||||
|
"employee_code_prefix": "EMP",
|
||||||
|
"position_code_prefix": "POS",
|
||||||
|
"auto_generate_codes": true,
|
||||||
|
"allow_duplicate_codes": false,
|
||||||
|
"max_org_levels": 10,
|
||||||
|
"max_org_children": 50,
|
||||||
|
"tid": tid,
|
||||||
|
}
|
||||||
|
|
||||||
|
c.jsonOK(settings)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveOrgSettings 保存组织架构设置
|
||||||
|
// POST /backend/erp/saveOrgSettings
|
||||||
|
func (c *BackendErpController) SaveOrgSettings() {
|
||||||
|
_ = c.parseJSONBody()
|
||||||
|
|
||||||
|
settings := map[string]interface{}{
|
||||||
|
"org_code_prefix": "ORG",
|
||||||
|
"employee_code_prefix": "EMP",
|
||||||
|
"position_code_prefix": "POS",
|
||||||
|
"auto_generate_codes": true,
|
||||||
|
"allow_duplicate_codes": false,
|
||||||
|
"max_org_levels": 10,
|
||||||
|
"max_org_children": 50,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 这里可以添加保存到数据库的逻辑
|
||||||
|
// 目前只是返回成功响应
|
||||||
|
|
||||||
|
c.jsonOK(settings)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOrganizationTree 获取组织架构树形结构
|
||||||
|
// GET /backend/erp/getOrganizationTree
|
||||||
|
func (c *BackendErpController) GetOrganizationTree() {
|
||||||
|
tid, _ := c.GetInt("tid")
|
||||||
|
|
||||||
|
qs := models.Orm.QueryTable(new(models.BackendErpOrganization)).
|
||||||
|
Filter("delete_time__isnull", true).
|
||||||
|
Exclude("status", 0)
|
||||||
|
if tid > 0 {
|
||||||
|
qs = qs.Filter("tid", tid)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows []models.BackendErpOrganization
|
||||||
|
_, err := qs.OrderBy("sort", "id").All(&rows)
|
||||||
|
if err != nil {
|
||||||
|
c.jsonError(500, "查询组织机构失败: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建树形结构
|
||||||
|
tree := buildOrganizationTree(rows)
|
||||||
|
c.jsonOK(tree)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SearchOrganizations 搜索组织机构
|
||||||
|
// GET /backend/erp/searchOrganizations
|
||||||
|
func (c *BackendErpController) SearchOrganizations() {
|
||||||
|
tid, _ := c.GetInt("tid")
|
||||||
|
keyword := c.GetString("keyword")
|
||||||
|
|
||||||
|
qs := models.Orm.QueryTable(new(models.BackendErpOrganization)).
|
||||||
|
Filter("delete_time__isnull", true).
|
||||||
|
Exclude("status", 0)
|
||||||
|
if tid > 0 {
|
||||||
|
qs = qs.Filter("tid", tid)
|
||||||
|
}
|
||||||
|
|
||||||
|
if keyword != "" {
|
||||||
|
qs = qs.Filter("org_name__icontains", keyword)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows []models.BackendErpOrganization
|
||||||
|
_, err := qs.OrderBy("sort", "id").All(&rows)
|
||||||
|
if err != nil {
|
||||||
|
c.jsonError(500, "查询组织机构失败: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]erpOrganizationDTO, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
list = append(list, c.organizationDTO(row))
|
||||||
|
}
|
||||||
|
|
||||||
|
c.jsonOK(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOrganizationEmployees 获取指定组织下的员工列表
|
||||||
|
// GET /backend/erp/getOrganizationEmployees/:org_id
|
||||||
|
func (c *BackendErpController) GetOrganizationEmployees() {
|
||||||
|
orgID, ok := c.pathUint64(":org_id")
|
||||||
|
if !ok {
|
||||||
|
c.jsonError(400, "无效组织ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tid, _ := c.GetInt("tid")
|
||||||
|
|
||||||
|
// 获取该组织及其所有子组织的ID
|
||||||
|
var orgIDs []uint64
|
||||||
|
orgIDs = append(orgIDs, orgID)
|
||||||
|
|
||||||
|
// 递归获取子组织ID
|
||||||
|
getChildOrgIDs(orgID, &orgIDs)
|
||||||
|
|
||||||
|
qs := models.Orm.QueryTable(new(models.BackendErpEmployee)).
|
||||||
|
Filter("delete_time__isnull", true)
|
||||||
|
if tid > 0 {
|
||||||
|
qs = qs.Filter("tid", tid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询属于这些组织的员工
|
||||||
|
if len(orgIDs) > 0 {
|
||||||
|
qs = qs.Filter("department__in", orgIDs)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows []models.BackendErpEmployee
|
||||||
|
_, err := qs.OrderBy("-id").All(&rows)
|
||||||
|
if err != nil {
|
||||||
|
c.jsonError(500, "查询员工失败: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]erpEmployeeDTO, 0, len(rows))
|
||||||
|
for _, row := range rows {
|
||||||
|
list = append(list, c.employeeDTO(row))
|
||||||
|
}
|
||||||
|
|
||||||
|
c.jsonOK(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MoveEmployeeToOrg 移动员工到指定组织
|
||||||
|
// POST /backend/erp/moveEmployeeToOrg
|
||||||
|
func (c *BackendErpController) MoveEmployeeToOrg() {
|
||||||
|
body := c.parseJSONBody()
|
||||||
|
|
||||||
|
employeeID, hasEmployee := c.getUintValue(body, "employee_id")
|
||||||
|
orgID, hasOrg := c.getUint64Value(body, "org_id")
|
||||||
|
|
||||||
|
if !hasEmployee || !hasOrg {
|
||||||
|
c.jsonError(400, "员工ID和组织ID不能为空")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新员工的部门信息
|
||||||
|
update := orm.Params{"department": orgID}
|
||||||
|
num, err := models.Orm.QueryTable(new(models.BackendErpEmployee)).
|
||||||
|
Filter("id", employeeID).
|
||||||
|
Filter("delete_time__isnull", true).
|
||||||
|
Update(update)
|
||||||
|
if err != nil {
|
||||||
|
c.jsonError(500, "移动员工失败: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if num == 0 {
|
||||||
|
c.jsonError(404, "员工不存在")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.jsonOK(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOrganizationHierarchy 获取组织层级结构
|
||||||
|
// GET /backend/erp/getOrganizationHierarchy/:org_id
|
||||||
|
func (c *BackendErpController) GetOrganizationHierarchy() {
|
||||||
|
orgID, ok := c.pathUint64(":org_id")
|
||||||
|
if !ok {
|
||||||
|
c.jsonError(400, "无效组织ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取指定组织的信息
|
||||||
|
var org models.BackendErpOrganization
|
||||||
|
err := models.Orm.QueryTable(new(models.BackendErpOrganization)).
|
||||||
|
Filter("id", orgID).
|
||||||
|
Filter("delete_time__isnull", true).
|
||||||
|
One(&org)
|
||||||
|
if err != nil {
|
||||||
|
c.jsonError(404, "组织不存在")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取所有子组织
|
||||||
|
var children []models.BackendErpOrganization
|
||||||
|
_, err = models.Orm.QueryTable(new(models.BackendErpOrganization)).
|
||||||
|
Filter("parent_id", orgID).
|
||||||
|
Filter("delete_time__isnull", true).
|
||||||
|
OrderBy("sort", "id").
|
||||||
|
All(&children)
|
||||||
|
if err != nil {
|
||||||
|
c.jsonError(500, "查询子组织失败: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
hierarchy := map[string]interface{}{
|
||||||
|
"current": c.organizationDTO(org),
|
||||||
|
"children": make([]erpOrganizationDTO, 0, len(children)),
|
||||||
|
}
|
||||||
|
|
||||||
|
childList := make([]erpOrganizationDTO, len(children))
|
||||||
|
for i, child := range children {
|
||||||
|
childList[i] = c.organizationDTO(child)
|
||||||
|
}
|
||||||
|
hierarchy["children"] = childList
|
||||||
|
|
||||||
|
c.jsonOK(hierarchy)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckOrgCodeUnique 检查组织编码唯一性
|
||||||
|
// GET /backend/erp/checkOrgCodeUnique
|
||||||
|
func (c *BackendErpController) CheckOrgCodeUnique() {
|
||||||
|
tid, _ := c.GetInt("tid")
|
||||||
|
orgCode := c.GetString("org_code")
|
||||||
|
orgID, _ := c.GetUint64("org_id")
|
||||||
|
|
||||||
|
if orgCode == "" {
|
||||||
|
c.jsonError(400, "组织编码不能为空")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
qs := models.Orm.QueryTable(new(models.BackendErpOrganization)).
|
||||||
|
Filter("org_code", orgCode).
|
||||||
|
Filter("delete_time__isnull", true)
|
||||||
|
if tid > 0 {
|
||||||
|
qs = qs.Filter("tid", tid)
|
||||||
|
}
|
||||||
|
if orgID > 0 {
|
||||||
|
qs = qs.Exclude("id", orgID)
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err := qs.Count()
|
||||||
|
if err != nil {
|
||||||
|
c.jsonError(500, "检查编码唯一性失败: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.jsonOK(map[string]interface{}{
|
||||||
|
"unique": count == 0,
|
||||||
|
"message": func() string {
|
||||||
|
if count == 0 {
|
||||||
|
return "编码可用"
|
||||||
|
}
|
||||||
|
return "编码已存在"
|
||||||
|
}(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckEmployeeAccountUnique 检查员工账号唯一性
|
||||||
|
// GET /backend/erp/checkEmployeeAccountUnique
|
||||||
|
func (c *BackendErpController) CheckEmployeeAccountUnique() {
|
||||||
|
tid, _ := c.GetInt("tid")
|
||||||
|
account := c.GetString("account")
|
||||||
|
employeeID, _ := c.GetInt("employee_id")
|
||||||
|
|
||||||
|
if account == "" {
|
||||||
|
c.jsonError(400, "员工账号不能为空")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
qs := models.Orm.QueryTable(new(models.BackendErpEmployee)).
|
||||||
|
Filter("account", account).
|
||||||
|
Filter("delete_time__isnull", true)
|
||||||
|
if tid > 0 {
|
||||||
|
qs = qs.Filter("tid", tid)
|
||||||
|
}
|
||||||
|
if employeeID > 0 {
|
||||||
|
qs = qs.Exclude("id", employeeID)
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err := qs.Count()
|
||||||
|
if err != nil {
|
||||||
|
c.jsonError(500, "检查账号唯一性失败: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.jsonOK(map[string]interface{}{
|
||||||
|
"unique": count == 0,
|
||||||
|
"message": func() string {
|
||||||
|
if count == 0 {
|
||||||
|
return "账号可用"
|
||||||
|
}
|
||||||
|
return "账号已存在"
|
||||||
|
}(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildOrganizationTree 构建组织树形结构
|
||||||
|
func buildOrganizationTree(rows []models.BackendErpOrganization) []map[string]interface{} {
|
||||||
|
tree := make([]map[string]interface{}, 0)
|
||||||
|
nodeMap := make(map[uint64]map[string]interface{})
|
||||||
|
|
||||||
|
// 创建节点映射
|
||||||
|
for _, row := range rows {
|
||||||
|
node := map[string]interface{}{
|
||||||
|
"id": row.ID,
|
||||||
|
"tid": row.Tid,
|
||||||
|
"org_name": row.OrgName,
|
||||||
|
"org_code": row.OrgCode,
|
||||||
|
"parent_id": row.ParentID,
|
||||||
|
"sort": row.Sort,
|
||||||
|
"is_company": row.IsCompany,
|
||||||
|
"status": row.Status,
|
||||||
|
"leader_id": row.LeaderID,
|
||||||
|
"remark": row.Remark,
|
||||||
|
"children": make([]map[string]interface{}, 0),
|
||||||
|
}
|
||||||
|
nodeMap[row.ID] = node
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建树形结构
|
||||||
|
for _, row := range rows {
|
||||||
|
node := nodeMap[row.ID]
|
||||||
|
if row.ParentID == 0 {
|
||||||
|
tree = append(tree, node)
|
||||||
|
} else {
|
||||||
|
if parent, exists := nodeMap[row.ParentID]; exists {
|
||||||
|
parent["children"] = append(parent["children"].([]map[string]interface{}), node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tree
|
||||||
|
}
|
||||||
|
|
||||||
|
// getChildOrgIDs 递归获取子组织ID
|
||||||
|
func getChildOrgIDs(parentID uint64, orgIDs *[]uint64) {
|
||||||
|
var children []models.BackendErpOrganization
|
||||||
|
_, err := models.Orm.QueryTable(new(models.BackendErpOrganization)).
|
||||||
|
Filter("parent_id", parentID).
|
||||||
|
Filter("delete_time__isnull", true).
|
||||||
|
All(&children)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, child := range children {
|
||||||
|
*orgIDs = append(*orgIDs, child.ID)
|
||||||
|
getChildOrgIDs(child.ID, orgIDs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -115,6 +115,17 @@ func RegisterAuthRoutes() {
|
|||||||
beego.Router("/backend/erp/editPosition/:id", &controllers.BackendErpController{}, "post:EditPosition")
|
beego.Router("/backend/erp/editPosition/:id", &controllers.BackendErpController{}, "post:EditPosition")
|
||||||
beego.Router("/backend/erp/deletePosition/:id", &controllers.BackendErpController{}, "delete:DeletePosition")
|
beego.Router("/backend/erp/deletePosition/:id", &controllers.BackendErpController{}, "delete:DeletePosition")
|
||||||
|
|
||||||
|
// 新增组织架构接口
|
||||||
|
beego.Router("/backend/erp/getOrgSettings", &controllers.BackendErpController{}, "get:GetOrgSettings")
|
||||||
|
beego.Router("/backend/erp/saveOrgSettings", &controllers.BackendErpController{}, "post:SaveOrgSettings")
|
||||||
|
beego.Router("/backend/erp/getOrganizationTree", &controllers.BackendErpController{}, "get:GetOrganizationTree")
|
||||||
|
beego.Router("/backend/erp/searchOrganizations", &controllers.BackendErpController{}, "get:SearchOrganizations")
|
||||||
|
beego.Router("/backend/erp/getOrganizationEmployees/:org_id", &controllers.BackendErpController{}, "get:GetOrganizationEmployees")
|
||||||
|
beego.Router("/backend/erp/moveEmployeeToOrg", &controllers.BackendErpController{}, "post:MoveEmployeeToOrg")
|
||||||
|
beego.Router("/backend/erp/getOrganizationHierarchy/:org_id", &controllers.BackendErpController{}, "get:GetOrganizationHierarchy")
|
||||||
|
beego.Router("/backend/erp/checkOrgCodeUnique", &controllers.BackendErpController{}, "get:CheckOrgCodeUnique")
|
||||||
|
beego.Router("/backend/erp/checkEmployeeAccountUnique", &controllers.BackendErpController{}, "get:CheckEmployeeAccountUnique")
|
||||||
|
|
||||||
// 文章管理
|
// 文章管理
|
||||||
beego.Router("/backend/articlesList", &controllers.BackendArticleController{}, "get:List")
|
beego.Router("/backend/articlesList", &controllers.BackendArticleController{}, "get:List")
|
||||||
beego.Router("/backend/contentstats", &controllers.BackendArticleController{}, "get:ContentStats")
|
beego.Router("/backend/contentstats", &controllers.BackendArticleController{}, "get:ContentStats")
|
||||||
|
|||||||
Reference in New Issue
Block a user