|
@@ -1,4 +1,4 @@
|
|
|
-import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, dict, UserPageQuery,compute } from '@fast-crud/fast-crud';
|
|
|
|
|
|
|
+import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, dict, UserPageQuery, compute, InfoReq, EditReq, DelReq } from '@fast-crud/fast-crud';
|
|
|
import * as api from './api';
|
|
import * as api from './api';
|
|
|
import { auth } from '/@/utils/authFunction';
|
|
import { auth } from '/@/utils/authFunction';
|
|
|
|
|
|
|
@@ -301,31 +301,66 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp
|
|
|
title: '组织架构',
|
|
title: '组织架构',
|
|
|
type: "dict-cascader",
|
|
type: "dict-cascader",
|
|
|
column: {
|
|
column: {
|
|
|
- show:false
|
|
|
|
|
- }
|
|
|
|
|
- /* dict: dict({
|
|
|
|
|
- isTree: true,
|
|
|
|
|
- url: "/api/system/organization/tree/",
|
|
|
|
|
- value: 'id',
|
|
|
|
|
- label: 'name'
|
|
|
|
|
- }),
|
|
|
|
|
- form: {
|
|
|
|
|
- component: {
|
|
|
|
|
- filterable: true,
|
|
|
|
|
- clearable: true,
|
|
|
|
|
- placeholder: '请选择组织架构',
|
|
|
|
|
- // props下配置属性跟配置在component下是一样的效果,而el-cascade下也有一个叫props的属性,所以需要配置两层
|
|
|
|
|
- props: {
|
|
|
|
|
- props: {
|
|
|
|
|
- checkStrictly: true,
|
|
|
|
|
- value: 'id',
|
|
|
|
|
- label: 'name',
|
|
|
|
|
- children: 'children'
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ show: false,
|
|
|
|
|
+ },
|
|
|
|
|
+ // 学生类型表单的级联选择依赖于 index.vue 中的 _college_id/_major_id/_grade_id
|
|
|
|
|
+ // 这里通过 valueBuilder 在打开编辑/查看表单时,将 organization_detail.parent_chain 回显到这三个临时字段
|
|
|
|
|
+ // 同时通过 valueResolve 在提交时将最终选择写回 organization_ref(学生为年级ID,其它类型为学院ID)
|
|
|
|
|
+ valueBuilder({ form, value }) {
|
|
|
|
|
+ // 保留后端原始值
|
|
|
|
|
+ form.organization_ref = value;
|
|
|
|
|
+ // 仅学生类型需要拆分层级进行回显
|
|
|
|
|
+ const od = (form as any).organization_detail;
|
|
|
|
|
+ if ((form as any).user_type === 0 && od && Array.isArray(od.parent_chain)) {
|
|
|
|
|
+ // 期望 parent_chain: [学校, 学院, 专业, 年级] 或至少包含 [学院, 专业, 年级]
|
|
|
|
|
+ const chain = od.parent_chain;
|
|
|
|
|
+ // 按长度精确映射,避免把学校ID当作学院ID
|
|
|
|
|
+ if (chain.length >= 4) {
|
|
|
|
|
+ // [学校, 学院, 专业, 年级]
|
|
|
|
|
+ (form as any)._college_id = chain[1]?.id;
|
|
|
|
|
+ (form as any)._major_id = chain[2]?.id;
|
|
|
|
|
+ (form as any)._grade_id = od?.id;
|
|
|
|
|
+ } else if (chain.length === 3) {
|
|
|
|
|
+ // 常见后端:含学校,无年级 -> [学校, 学院, 专业]
|
|
|
|
|
+ (form as any)._college_id = chain[1]?.id;
|
|
|
|
|
+ (form as any)._major_id = chain[2]?.id;
|
|
|
|
|
+ (form as any)._grade_id = od?.id;
|
|
|
|
|
+ } else if (chain.length === 2) {
|
|
|
|
|
+ // [学院, 专业]
|
|
|
|
|
+ (form as any)._college_id = chain[0]?.id;
|
|
|
|
|
+ (form as any)._major_id = chain[1]?.id;
|
|
|
|
|
+ (form as any)._grade_id = od?.id;
|
|
|
|
|
+ } else if (chain.length === 1) {
|
|
|
|
|
+ // [学院]
|
|
|
|
|
+ (form as any)._college_id = chain[0]?.id;
|
|
|
|
|
+ (form as any)._major_id = undefined;
|
|
|
|
|
+ (form as any)._grade_id = od?.id;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ (form as any)._college_id = undefined;
|
|
|
|
|
+ (form as any)._major_id = undefined;
|
|
|
|
|
+ (form as any)._grade_id = od?.id;
|
|
|
}
|
|
}
|
|
|
- },
|
|
|
|
|
- rules: [{ required: false, message: '请选择组织架构' }]
|
|
|
|
|
- } */
|
|
|
|
|
|
|
+ // 学生模式下,不直接把 organization_ref 设为学院,保持由 index.vue 的联动逻辑在变更时再写入
|
|
|
|
|
+ } else if ((form as any).user_type === 1 || (form as any).user_type === 3) {
|
|
|
|
|
+ // 教师/学院领导:直接以当前组织ID为学院选择
|
|
|
|
|
+ if (od && od.id) {
|
|
|
|
|
+ (form as any).organization_ref = od.id;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ valueResolve({ form, value }) {
|
|
|
|
|
+ // 非学生:提交学院ID
|
|
|
|
|
+ if ((form as any).user_type !== 0) {
|
|
|
|
|
+ (form as any).organization_ref = value ?? (form as any).organization_ref;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 学生:当选择了年级,则以年级ID为最终 organization_ref
|
|
|
|
|
+ if ((form as any)._grade_id) {
|
|
|
|
|
+ (form as any).organization_ref = (form as any)._grade_id;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 兜底:若仅选择到专业或学院,不改变已有值(让上层联动 onGradeChange 来写入)
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
organization:{
|
|
organization:{
|
|
|
title: '学院',
|
|
title: '学院',
|
|
@@ -337,14 +372,24 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp
|
|
|
show: true,
|
|
show: true,
|
|
|
minWidth: 200,
|
|
minWidth: 200,
|
|
|
formatter: ({ row, value }: { row: any; value: any }) => {
|
|
formatter: ({ row, value }: { row: any; value: any }) => {
|
|
|
- // 如果有 organization_detail 对象,显示 parent_chain 的第二项(专业)
|
|
|
|
|
- if (row.organization_detail && row.organization_detail.parent_chain && row.organization_detail.parent_chain.length >= 2) {
|
|
|
|
|
- if(!row.organization_detail.parent_chain[0]) return
|
|
|
|
|
- const major = row.organization_detail.parent_chain[0]; // 第二项是专业
|
|
|
|
|
- return major.name || major.code || '';
|
|
|
|
|
|
|
+ // 根据用户类型显示不同内容
|
|
|
|
|
+ if(row.user_type !== 0) {
|
|
|
|
|
+ // 教师、学院领导:显示学院名称
|
|
|
|
|
+ if (row.organization_detail && row.organization_detail.name) {
|
|
|
|
|
+ return row.organization_detail.name;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 否则显示原始值
|
|
|
|
|
+ return value || '';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 学生:显示专业信息
|
|
|
|
|
+ if (row.organization_detail && row.organization_detail.parent_chain && row.organization_detail.parent_chain.length >= 2) {
|
|
|
|
|
+ if(!row.organization_detail.parent_chain[1]) return
|
|
|
|
|
+ const major = row.organization_detail.parent_chain[1]; // 第二项是专业
|
|
|
|
|
+ return major.name || major.code || '';
|
|
|
|
|
+ }
|
|
|
|
|
+ // 否则显示原始值
|
|
|
|
|
+ return value || row.sub_organization;
|
|
|
}
|
|
}
|
|
|
- // 否则显示原始值
|
|
|
|
|
- return value || row.sub_organization;
|
|
|
|
|
},
|
|
},
|
|
|
/* formatter: ({ row, value }: { row: any; value: any }) => {
|
|
/* formatter: ({ row, value }: { row: any; value: any }) => {
|
|
|
// 如果有 organization_detail 对象,显示 full_path
|
|
// 如果有 organization_detail 对象,显示 full_path
|
|
@@ -356,9 +401,12 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp
|
|
|
}, */
|
|
}, */
|
|
|
},
|
|
},
|
|
|
form: {
|
|
form: {
|
|
|
- show:false,
|
|
|
|
|
- component: { placeholder: '请填写学院' },
|
|
|
|
|
- rules: [{ required: false, message: '请填写学院' }],
|
|
|
|
|
|
|
+ show: compute((row:any)=>{
|
|
|
|
|
+ // 学生、教师、学院领导:在表单中显示"学院"
|
|
|
|
|
+ return row.user_type === 0 || row.user_type === 1 || row.user_type === 3
|
|
|
|
|
+ }),
|
|
|
|
|
+ component: { placeholder: '请选择学院' },
|
|
|
|
|
+ rules: [{ required: false, message: '请选择学院' }],
|
|
|
},
|
|
},
|
|
|
viewForm:{
|
|
viewForm:{
|
|
|
component: { placeholder: '' },
|
|
component: { placeholder: '' },
|
|
@@ -371,13 +419,16 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp
|
|
|
show:false
|
|
show:false
|
|
|
},
|
|
},
|
|
|
column: {
|
|
column: {
|
|
|
- show: true,
|
|
|
|
|
|
|
+ show: compute(({ row }) => {
|
|
|
|
|
+ // 只有学生类型才显示专业列
|
|
|
|
|
+ return row && row.user_type === 0;
|
|
|
|
|
+ }),
|
|
|
minWidth: 120,
|
|
minWidth: 120,
|
|
|
formatter: ({ row, value }: { row: any; value: any }) => {
|
|
formatter: ({ row, value }: { row: any; value: any }) => {
|
|
|
// 如果有 organization_detail 对象,显示 parent_chain 的第二项(专业)
|
|
// 如果有 organization_detail 对象,显示 parent_chain 的第二项(专业)
|
|
|
if (row.organization_detail && row.organization_detail.parent_chain && row.organization_detail.parent_chain.length >= 2) {
|
|
if (row.organization_detail && row.organization_detail.parent_chain && row.organization_detail.parent_chain.length >= 2) {
|
|
|
- if(!row.organization_detail.parent_chain[1]) return
|
|
|
|
|
- const major = row.organization_detail.parent_chain[1]; // 第二项是专业
|
|
|
|
|
|
|
+ if(!row.organization_detail.parent_chain[2]) return
|
|
|
|
|
+ const major = row.organization_detail.parent_chain[2]; // 第二项是专业
|
|
|
return major.name || major.code || '';
|
|
return major.name || major.code || '';
|
|
|
}
|
|
}
|
|
|
// 否则显示原始值
|
|
// 否则显示原始值
|
|
@@ -385,7 +436,10 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
form: {
|
|
form: {
|
|
|
- show:false,
|
|
|
|
|
|
|
+ show: compute(({ form }) => {
|
|
|
|
|
+ // 只有当选择了学院时才显示专业选择
|
|
|
|
|
+ return form && form.user_type == 0;
|
|
|
|
|
+ }),
|
|
|
component: { placeholder: '请填写专业' },
|
|
component: { placeholder: '请填写专业' },
|
|
|
rules: [{ required: false, message: '请填写专业' }],
|
|
rules: [{ required: false, message: '请填写专业' }],
|
|
|
},
|
|
},
|
|
@@ -400,21 +454,25 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp
|
|
|
show:false
|
|
show:false
|
|
|
},
|
|
},
|
|
|
column: {
|
|
column: {
|
|
|
- show: true,
|
|
|
|
|
|
|
+ show: compute(({ row }) => {
|
|
|
|
|
+ // 只有学生类型才显示年级列
|
|
|
|
|
+ return row && row.user_type === 0;
|
|
|
|
|
+ }),
|
|
|
minWidth: 120,
|
|
minWidth: 120,
|
|
|
formatter: ({ row, value }: { row: any; value: any }) => {
|
|
formatter: ({ row, value }: { row: any; value: any }) => {
|
|
|
- // 如果有 organization_detail 对象,显示 parent_chain 的第二项(专业)
|
|
|
|
|
- if (row.organization_detail && row.organization_detail.parent_chain && row.organization_detail.parent_chain.length >= 2) {
|
|
|
|
|
- if(!row.organization_detail.parent_chain[2]) return
|
|
|
|
|
- const major = row.organization_detail.parent_chain[2]; // 第二项是专业
|
|
|
|
|
- return major.name || major.code || '';
|
|
|
|
|
|
|
+ // 如果有 organization_detail 对象,显示 name
|
|
|
|
|
+ if (row.organization_detail && row.organization_detail.name) {
|
|
|
|
|
+ return row.organization_detail.name;
|
|
|
}
|
|
}
|
|
|
// 否则显示原始值
|
|
// 否则显示原始值
|
|
|
- return value || row.grade_or_level;
|
|
|
|
|
|
|
+ return value || row.class_or_group;
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
form: {
|
|
form: {
|
|
|
- show:false,
|
|
|
|
|
|
|
+ show: compute(({ form }) => {
|
|
|
|
|
+ // 只有当选择了专业时才显示年级选择
|
|
|
|
|
+ return form && form.user_type == 0;
|
|
|
|
|
+ }),
|
|
|
component: { placeholder: '请填写年级' },
|
|
component: { placeholder: '请填写年级' },
|
|
|
rules: [{ required: false, message: '请填写年级' }],
|
|
rules: [{ required: false, message: '请填写年级' }],
|
|
|
},
|
|
},
|
|
@@ -429,7 +487,10 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp
|
|
|
show:false
|
|
show:false
|
|
|
},
|
|
},
|
|
|
column: {
|
|
column: {
|
|
|
- show: true,
|
|
|
|
|
|
|
+ show: compute(({ row }) => {
|
|
|
|
|
+ // 只有学生类型才显示班级列
|
|
|
|
|
+ return row && row.user_type === 0;
|
|
|
|
|
+ }),
|
|
|
minWidth: 120,
|
|
minWidth: 120,
|
|
|
formatter: ({ row, value }: { row: any; value: any }) => {
|
|
formatter: ({ row, value }: { row: any; value: any }) => {
|
|
|
// 如果有 organization_detail 对象,显示 name
|
|
// 如果有 organization_detail 对象,显示 name
|