<template>
|
<LoadingLayout :loading="state.loading">
|
<AppContainer>
|
<ProTableQueryFilterBar @on-reset="reset">
|
<template #query>
|
<QueryFilterItem>
|
<SearchInput
|
v-model="extraParamState.keywords"
|
style="width: 200px"
|
placeholder="名称/编号"
|
@on-click-search="getList"
|
@keyup.enter="getList()"
|
>
|
</SearchInput>
|
</QueryFilterItem>
|
</template>
|
<template #btn>
|
<el-button
|
v-if="checkSubModuleItemShow('pageButton', 'addBtn')"
|
@click="openDialog()"
|
icon="Plus"
|
type="primary"
|
>新增</el-button
|
>
|
</template>
|
</ProTableQueryFilterBar>
|
<ProTableV2 v-bind="proTableProps" :columns="column" :operationBtns="operationBtns">
|
</ProTableV2>
|
</AppContainer>
|
<AddOrEditDictionaryCategory v-bind="dialogProps" />
|
</LoadingLayout>
|
</template>
|
|
<script setup lang="ts">
|
import {
|
ProTableQueryFilterBar,
|
OperationBtnType,
|
ProTableV2,
|
SearchInput,
|
LoadingLayout,
|
AppContainer,
|
QueryFilterItem,
|
useTable,
|
useFormDialog,
|
} from '@bole-core/components';
|
import { useAccess } from '@/hooks';
|
import { Message } from '@bole-core/core';
|
import AddOrEditDictionaryCategory from './components/AddOrEditDictionaryCategory.vue';
|
import { useQueryClient } from '@tanstack/vue-query';
|
import * as dictionaryServices from '@/services/api/dictionary';
|
|
defineOptions({
|
name: 'DictionaryCategoryManage',
|
});
|
|
const operationBtnMap: Record<string, OperationBtnType> = {
|
editBtn: { emits: { onClick: (role) => openDialog(role) } },
|
delBtn: { emits: { onClick: (role) => handleDel(role) }, props: { type: 'danger' } },
|
};
|
|
const { checkSubModuleItemShow, column, operationBtns } = useAccess({
|
operationBtnMap,
|
});
|
|
const { updateDictionaryCategorySelect } = useGetDictionaryCategorySelect();
|
const BaseState = {
|
loading: true,
|
};
|
const state = reactive({ ...BaseState });
|
|
onMounted(async () => {
|
await getList();
|
state.loading = false;
|
});
|
|
const {
|
getDataSource: getList,
|
proTableProps,
|
paginationState,
|
extraParamState,
|
reset,
|
} = useTable(
|
async ({ pageIndex, pageSize }, extraParamState) => {
|
try {
|
let params: API.GetDictionaryCategoriesQuery = {
|
pageModel: {
|
rows: pageSize,
|
page: pageIndex,
|
orderInput: extraParamState.orderInput,
|
},
|
keywords: extraParamState.keywords,
|
};
|
let res = await dictionaryServices.getDictionaryCategories(params, {
|
showLoading: !state.loading,
|
});
|
return res;
|
} catch (error) {
|
console.log('error: ', error);
|
}
|
},
|
{
|
defaultExtraParams: {
|
keywords: '',
|
orderInput: [{ property: 'sort', order: EnumPagedListOrder.Asc }],
|
},
|
queryKey: ['dictionaryServices/getDictionaryCategories'],
|
columnsRenderProps: {},
|
}
|
);
|
|
function openDialog(row?: API.GetDictionaryCategoriesQueryResultItem) {
|
if (row) {
|
handleEdit({
|
id: row.id,
|
name: row.name,
|
sort: row.sort,
|
code: row.code,
|
fieldNames: row.fieldNames,
|
});
|
} else {
|
handleAdd();
|
}
|
}
|
|
const { dialogProps, handleAdd, handleEdit, editForm, dialogState } = useFormDialog({
|
onConfirm: handleAddOrEdit,
|
defaultFormParams: {
|
id: '',
|
name: '',
|
code: '',
|
fieldNames: '',
|
sort: 0,
|
},
|
});
|
|
async function handleAddOrEdit() {
|
try {
|
let params: API.SaveDictionaryCategoryCommand = {
|
code: editForm.code,
|
name: editForm.name,
|
sort: editForm.sort,
|
fieldNames: editForm.fieldNames,
|
};
|
if (editForm.id) {
|
params.id = editForm.id;
|
}
|
let res = await dictionaryServices.saveDictionaryCategory(params);
|
if (res) {
|
Message.successMessage('操作成功');
|
updateDictionaryCategorySelect();
|
getList(paginationState.pageIndex);
|
dialogState.dialogVisible = false;
|
}
|
} catch (error) {}
|
}
|
|
async function handleDel(row: API.GetDictionaryCategoriesQueryResultItem) {
|
try {
|
await Message.tipMessage('确认要删除该类别吗?');
|
let params: API.DeleteDictionaryCategoryCommand = { ids: [row.id] };
|
let res = await dictionaryServices.deleteDictionaryCategory(params);
|
if (res) {
|
Message.successMessage('操作成功');
|
updateDictionaryCategorySelect();
|
getList(paginationState.pageIndex);
|
}
|
} catch (error) {}
|
}
|
</script>
|