分组优化

This commit is contained in:
Qi 2025-06-09 22:54:03 +08:00
parent 02df9af20b
commit 84a94783ba
4 changed files with 296 additions and 304 deletions

View File

@ -1,17 +1,17 @@
import {BasicColumn} from '/@/components/Table'; import { BasicColumn } from '/@/components/Table';
import {FormSchema} from '/@/components/Table'; import { FormSchema } from '/@/components/Table';
import { rules} from '/@/utils/helper/validator'; import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils'; import { render } from '/@/utils/common/renderUtils';
import { usePermission } from '/@/hooks/web/usePermission'; import { usePermission } from '/@/hooks/web/usePermission';
const { hasPermission } = usePermission(); const { hasPermission } = usePermission();
export const columns: BasicColumn[] = [ export const columns: BasicColumn[] = [
{ {
title: '组名', title: '组名',
align:"center", align: 'center',
dataIndex: 'name', dataIndex: 'name',
width: 150 width: 150,
}, },
// { // {
// title: '分组', // title: '分组',
// align: 'center', // align: 'center',
@ -36,10 +36,10 @@ export const columns: BasicColumn[] = [
}, },
{ {
title: '评卷地点', title: '评卷地点',
align: "center", align: 'center',
dataIndex: 'markingLocation', dataIndex: 'markingLocation',
width: 200 width: 200,
} },
// { // {
// title: '专业id', // title: '专业id',
// align:"center", // align:"center",
@ -74,7 +74,7 @@ export const searchFormSchema: FormSchema[] = [
label: '评卷地点', label: '评卷地点',
field: 'markingLocation', field: 'markingLocation',
component: 'Input', component: 'Input',
} },
]; ];
//表单数据 //表单数据
export const formSchema: FormSchema[] = [ export const formSchema: FormSchema[] = [
@ -82,11 +82,9 @@ export const formSchema: FormSchema[] = [
label: '组名', label: '组名',
field: 'name', field: 'name',
component: 'Input', component: 'Input',
dynamicRules: ({model,schema}) => { dynamicRules: ({ model, schema }) => {
return [ return [{ required: true, message: '请输入分组名!' }];
{ required: true, message: '请输入分组名!'}, },
];
},
}, },
{ {
label: '学科', label: '学科',
@ -100,40 +98,42 @@ export const formSchema: FormSchema[] = [
{ label: '政治', value: 8 }, { label: '政治', value: 8 },
], ],
}, },
dynamicRules: ({model,schema}) => { dynamicRules: ({ model, schema }) => {
return [ if (!hasPermission('majorId:edit')) {
{ required: true, message: '请选择学科!'}, // 没有权限,不添加校验规则
]; return [];
}
return [{ required: true, message: '请选择学科!' }];
}, },
show: ({ values }) => { show: ({ values }) => {
return hasPermission('majorId:edit'); return hasPermission('majorId:edit');
} },
}, },
{ {
label: '评卷地点', label: '评卷地点',
field: 'markingLocation', field: 'markingLocation',
component: 'Input', component: 'Input',
}, },
// TODO 主键隐藏字段目前写死为ID // TODO 主键隐藏字段目前写死为ID
{ {
label: '', label: '',
field: 'id', field: 'id',
component: 'Input', component: 'Input',
show: false show: false,
}, },
]; ];
// 高级查询数据 // 高级查询数据
export const superQuerySchema = { export const superQuerySchema = {
name: {title: '组名',order: 0,view: 'text', type: 'string',}, name: { title: '组名', order: 0, view: 'text', type: 'string' },
majorId: {title: '专业id',order: 1,view: 'number', type: 'number',}, majorId: { title: '专业id', order: 1, view: 'number', type: 'number' },
}; };
/** /**
* formSchema * formSchema
* @param param * @param param
*/ */
export function getBpmFormSchema(_formData): FormSchema[]{ export function getBpmFormSchema(_formData): FormSchema[] {
// 默认和原始表单保持一致 如果流程中配置了权限数据这里需要单独处理formSchema // 默认和原始表单保持一致 如果流程中配置了权限数据这里需要单独处理formSchema
return formSchema; return formSchema;
} }

View File

@ -7,8 +7,7 @@
<a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button> <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
<a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button> <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
<j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button> <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
<a-button type="primary" @click="batchHandleDelete" v-if="hasPermission('group:batchDelete')">批量删除 <a-button type="primary" @click="batchHandleDelete" v-if="hasPermission('group:batchDelete')">批量删除 </a-button>
</a-button>
<!-- 高级查询 --> <!-- 高级查询 -->
<super-query :config="superQueryConfig" @search="handleSuperQuery" /> <super-query :config="superQueryConfig" @search="handleSuperQuery" />
</template> </template>
@ -20,11 +19,10 @@
<TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" /> <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
</template> </template>
<!--字段回显插槽--> <!--字段回显插槽-->
<template v-slot:bodyCell="{ column, record, index, text }"> <template #bodyCell="{ column, record, index, text }"> </template>
</template>
</BasicTable> </BasicTable>
<!-- 表单区域 --> <!-- 表单区域 -->
<CeesGroupModal @register="registerModal" @success="handleSuccess"></CeesGroupModal> <CeesGroupModal @register="registerModal" @success="handleSuccess" />
<!-- 分组对话框 --> <!-- 分组对话框 -->
<!--<CeesGroupTransferModal v-model:visible="groupDialogVisible" :groupDialogTitle="groupDialogTitle" <!--<CeesGroupTransferModal v-model:visible="groupDialogVisible" :groupDialogTitle="groupDialogTitle"
:groupTitle="groupTitle" :dataSource="transferData" show-search @search="handleSearch" :targetKeys="targetKeys" :groupTitle="groupTitle" :dataSource="transferData" show-search @search="handleSearch" :targetKeys="targetKeys"
@ -33,165 +31,159 @@
</template> </template>
<script lang="ts" name="cees-ceesGroup" setup> <script lang="ts" name="cees-ceesGroup" setup>
import { ref, reactive, computed, unref, onMounted } from 'vue'; import { ref, reactive, computed, unref, onMounted } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table'; import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal'; import { useModal } from '/@/components/Modal';
import CeesGroupTransferModal from './components/CeesGroupTransferModal.vue' import CeesGroupTransferModal from './components/CeesGroupTransferModal.vue';
import { useListPage } from '/@/hooks/system/useListPage' import { useListPage } from '/@/hooks/system/useListPage';
import CeesGroupModal from './components/CeesGroupModal.vue' import CeesGroupModal from './components/CeesGroupModal.vue';
import { columns, searchFormSchema, superQuerySchema } from './CeesGroup.data'; import { columns, searchFormSchema, superQuerySchema } from './CeesGroup.data';
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl, getRowUser, addGroupMembers, removeGroupMembers } from './CeesGroup.api'; import { list, deleteOne, batchDelete, getImportUrl, getExportUrl, getRowUser, addGroupMembers, removeGroupMembers } from './CeesGroup.api';
import { downloadFile } from '/@/utils/common/renderUtils'; import { downloadFile } from '/@/utils/common/renderUtils';
import { useUserStore } from '/@/store/modules/user'; import { useUserStore } from '/@/store/modules/user';
import { usePermission } from '/@/hooks/web/usePermission'; import { usePermission } from '/@/hooks/web/usePermission';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
const { hasPermission } = usePermission(); const { hasPermission } = usePermission();
const queryParam = reactive<any>({}); const queryParam = reactive<any>({});
const checkedKeys = ref<Array<string | number>>([]); const checkedKeys = ref<Array<string | number>>([]);
const userStore = useUserStore(); const userStore = useUserStore();
//model //model
const [registerModal, { openModal }] = useModal(); const [registerModal, { openModal }] = useModal();
//table //table
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({ const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
tableProps: { tableProps: {
title: '分组表', title: '分组表',
api: list, api: list,
columns, columns,
canResize: false, canResize: false,
formConfig: { formConfig: {
//labelWidth: 120, //labelWidth: 120,
schemas: searchFormSchema, schemas: searchFormSchema,
autoSubmitOnEnter: true, autoSubmitOnEnter: true,
showAdvancedButton: true, showAdvancedButton: true,
fieldMapToNumber: [ fieldMapToNumber: [],
], fieldMapToTime: [],
fieldMapToTime: [ },
], actionColumn: {
width: 120,
fixed: 'right',
},
beforeFetch: (params) => {
return Object.assign(params, queryParam);
},
}, },
actionColumn: { exportConfig: {
width: 120, name: '分组表',
fixed: 'right' url: getExportUrl,
params: queryParam,
}, },
beforeFetch: (params) => { importConfig: {
return Object.assign(params, queryParam); url: getImportUrl,
success: handleSuccess,
}, },
},
exportConfig: {
name: "分组表",
url: getExportUrl,
params: queryParam,
},
importConfig: {
url: getImportUrl,
success: handleSuccess
},
})
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext
//
const superQueryConfig = reactive(superQuerySchema);
/**
* 高级查询事件
*/
function handleSuperQuery(params) {
Object.keys(params).map((k) => {
queryParam[k] = params[k];
}); });
reload();
} const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
/**
* 新增事件 //
*/ const superQueryConfig = reactive(superQuerySchema);
function handleAdd() {
openModal(true, { /**
isUpdate: false, * 高级查询事件
showFooter: true, */
}); function handleSuperQuery(params) {
} Object.keys(params).map((k) => {
/** queryParam[k] = params[k];
* 编辑事件 });
*/ reload();
function handleEdit(record: Recordable) {
openModal(true, {
record,
isUpdate: true,
showFooter: true,
});
}
/**
* 详情
*/
function handleDetail(record: Recordable) {
openModal(true, {
record,
isUpdate: true,
showFooter: false,
});
}
/**
* 删除事件
*/
async function handleDelete(record) {
await deleteOne({ id: record.id }, handleSuccess);
}
/**
* 批量删除事件
*/
async function batchHandleDelete() {
if (selectedRowKeys.value.length < 1) {
message.warning('请至少选择一个用户!');
return;
} }
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess); /**
} * 新增事件
/** */
* 成功回调 function handleAdd() {
*/ openModal(true, {
function handleSuccess() { isUpdate: false,
(selectedRowKeys.value = []) && reload(); showFooter: true,
} });
/** }
/**
* 编辑事件
*/
function handleEdit(record: Recordable) {
openModal(true, {
record,
isUpdate: true,
showFooter: true,
});
}
/**
* 详情
*/
function handleDetail(record: Recordable) {
openModal(true, {
record,
isUpdate: true,
showFooter: false,
});
}
/**
* 删除事件
*/
async function handleDelete(record) {
await deleteOne({ id: record.id }, handleSuccess);
}
/**
* 批量删除事件
*/
async function batchHandleDelete() {
if (selectedRowKeys.value.length < 1) {
message.warning('请至少选择一个用户!');
return;
}
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
}
/**
* 成功回调
*/
function handleSuccess() {
(selectedRowKeys.value = []) && reload();
}
/**
* 操作栏 * 操作栏
*/ */
function getTableAction(record) { function getTableAction(record) {
const actions = [ const actions = [
{ {
label: '编辑', label: '编辑',
onClick: handleEdit.bind(null, record), onClick: handleEdit.bind(null, record),
}, },
]; ];
return actions; return actions;
} }
/** /**
* 下拉操作栏 * 下拉操作栏
*/ */
function getDropDownAction(record) { function getDropDownAction(record) {
return [ return [
{ {
label: '详情', label: '详情',
onClick: handleDetail.bind(null, record), onClick: handleDetail.bind(null, record),
},
{
label: '删除',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
placement: 'topLeft',
}, },
ifShow: () => { {
return hasPermission('group:delete'); label: '删除',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
placement: 'topLeft',
},
ifShow: () => {
return hasPermission('group:delete');
},
}, },
}, ];
]; }
}
</script> </script>
<style scoped></style> <style scoped></style>

View File

@ -1,70 +1,70 @@
<template> <template>
<div style="min-height: 400px"> <div style="min-height: 400px">
<BasicForm @register="registerForm"></BasicForm> <BasicForm @register="registerForm" />
<div style="width: 100%;text-align: center" v-if="!formDisabled"> <div style="width: 100%; text-align: center" v-if="!formDisabled">
<a-button @click="submitForm" pre-icon="ant-design:check" type="primary"> </a-button> <a-button @click="submitForm" pre-icon="ant-design:check" type="primary"> </a-button>
</div>
</div> </div>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
import {BasicForm, useForm} from '/@/components/Form/index'; import { BasicForm, useForm } from '/@/components/Form/index';
import {computed, defineComponent} from 'vue'; import { computed, defineComponent } from 'vue';
import {defHttp} from '/@/utils/http/axios'; import { defHttp } from '/@/utils/http/axios';
import { propTypes } from '/@/utils/propTypes'; import { propTypes } from '/@/utils/propTypes';
import {getBpmFormSchema} from '../CeesGroup.data'; import { getBpmFormSchema } from '../CeesGroup.data';
import {saveOrUpdate} from '../CeesGroup.api'; import { saveOrUpdate } from '../CeesGroup.api';
export default defineComponent({
name: "CeesGroupForm",
components:{
BasicForm
},
props:{
formData: propTypes.object.def({}),
formBpm: propTypes.bool.def(true),
},
setup(props){
const [registerForm, { setFieldsValue, setProps, getFieldsValue }] = useForm({
labelWidth: 150,
schemas: getBpmFormSchema(props.formData),
showActionButtonGroup: false,
baseColProps: {span: 24}
});
const formDisabled = computed(()=>{ export default defineComponent({
if(props.formData.disabled === false){ name: 'CeesGroupForm',
return false; components: {
} BasicForm,
return true; },
}); props: {
formData: propTypes.object.def({}),
formBpm: propTypes.bool.def(true),
},
setup(props) {
const [registerForm, { setFieldsValue, setProps, getFieldsValue }] = useForm({
labelWidth: 150,
schemas: getBpmFormSchema(props.formData),
showActionButtonGroup: false,
baseColProps: { span: 24 },
});
let formData = {}; const formDisabled = computed(() => {
const queryByIdUrl = '/cees/ceesGroup/queryById'; if (props.formData.disabled === false) {
async function initFormData(){ return false;
let params = {id: props.formData.dataId};
const data = await defHttp.get({url: queryByIdUrl, params});
formData = {...data}
//
await setFieldsValue(formData);
//
await setProps({disabled: formDisabled.value})
}
async function submitForm() {
let data = getFieldsValue();
let params = Object.assign({}, formData, data);
console.log('表单数据', params)
await saveOrUpdate(params, true)
}
initFormData();
return {
registerForm,
formDisabled,
submitForm,
}
} }
}); return true;
</script> });
let formData = {};
const queryByIdUrl = '/cees/ceesGroup/queryById';
async function initFormData() {
let params = { id: props.formData.dataId };
const data = await defHttp.get({ url: queryByIdUrl, params });
formData = { ...data };
//
await setFieldsValue(formData);
//
await setProps({ disabled: formDisabled.value });
}
async function submitForm() {
let data = getFieldsValue();
let params = Object.assign({}, formData, data);
console.log('表单数据', params);
await saveOrUpdate(params, true);
}
initFormData();
return {
registerForm,
formDisabled,
submitForm,
};
},
});
</script>

View File

@ -1,66 +1,66 @@
<template> <template>
<BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit"> <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit">
<BasicForm @register="registerForm"/> <BasicForm @register="registerForm" />
</BasicModal> </BasicModal>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import {ref, computed, unref} from 'vue'; import { ref, computed, unref } from 'vue';
import {BasicModal, useModalInner} from '/@/components/Modal'; import { BasicModal, useModalInner } from '/@/components/Modal';
import {BasicForm, useForm} from '/@/components/Form/index'; import { BasicForm, useForm } from '/@/components/Form/index';
import {formSchema} from '../CeesGroup.data'; import { formSchema } from '../CeesGroup.data';
import {saveOrUpdate} from '../CeesGroup.api'; import { saveOrUpdate } from '../CeesGroup.api';
// Emits // Emits
const emit = defineEmits(['register','success']); const emit = defineEmits(['register', 'success']);
const isUpdate = ref(true); const isUpdate = ref(true);
// //
const [registerForm, {setProps,resetFields, setFieldsValue, validate}] = useForm({ const [registerForm, { setProps, resetFields, setFieldsValue, validate }] = useForm({
//labelWidth: 150, //labelWidth: 150,
schemas: formSchema, schemas: formSchema,
showActionButtonGroup: false, showActionButtonGroup: false,
baseColProps: {span: 24} baseColProps: { span: 24 },
}); });
// //
const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => { const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
// //
await resetFields(); await resetFields();
setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter}); setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter });
isUpdate.value = !!data?.isUpdate; isUpdate.value = !!data?.isUpdate;
if (unref(isUpdate)) { if (unref(isUpdate)) {
// //
await setFieldsValue({ await setFieldsValue({
...data.record, ...data.record,
}); });
}
//
setProps({ disabled: !data?.showFooter })
});
//
const title = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));
//
async function handleSubmit(v) {
try {
let values = await validate();
setModalProps({confirmLoading: true});
//
await saveOrUpdate(values, isUpdate.value);
//
closeModal();
//
emit('success');
} finally {
setModalProps({confirmLoading: false});
}
} }
//
setProps({ disabled: !data?.showFooter });
});
//
const title = computed(() => (!unref(isUpdate) ? '新增' : '编辑'));
//
async function handleSubmit(v) {
try {
let values = await validate();
setModalProps({ confirmLoading: true });
//
await saveOrUpdate(values, isUpdate.value);
//
closeModal();
//
emit('success');
} finally {
setModalProps({ confirmLoading: false });
}
}
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
/** 时间和数字输入框样式 */ /** 时间和数字输入框样式 */
:deep(.ant-input-number){ :deep(.ant-input-number) {
width: 100% width: 100%;
} }
:deep(.ant-calendar-picker){ :deep(.ant-calendar-picker) {
width: 100% width: 100%;
} }
</style> </style>