<template>
|
<LoadingLayout :loading="state.loading">
|
<AppContainer>
|
<ProTableQueryFilterBar @on-reset="handleReset">
|
<template #query>
|
<QueryFilterItem>
|
<FieldSelect
|
v-model="extraParamState.categoryId"
|
@change="getList()"
|
:value-enum="dictionaryCategoryList"
|
placeholder="请选择所属类别"
|
></FieldSelect>
|
</QueryFilterItem>
|
<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">
|
<template #isDisabled="{ row }">
|
<FieldSwitch
|
v-model="row.isDisabled"
|
active-text="启用"
|
inactive-text="禁用"
|
:active-value="false"
|
:inactive-value="true"
|
:before-change="() => setCategoryVis(row)"
|
/>
|
</template>
|
</ProTableV2>
|
</AppContainer>
|
<AddOrEditDictionaryDialog v-bind="dialogProps" />
|
</LoadingLayout>
|
</template>
|
|
<script setup lang="ts">
|
import {
|
ProTableQueryFilterBar,
|
OperationBtnType,
|
ProTableV2,
|
SearchInput,
|
LoadingLayout,
|
AppContainer,
|
QueryFilterItem,
|
useTable,
|
useFormDialog,
|
UploadUserFile,
|
FieldSwitch,
|
FieldSelect,
|
} from '@bole-core/components';
|
import { useAccess, useDictionaryDataSelect, useGetDictionaryCategorySelect } from '@/hooks';
|
import { Message } from '@bole-core/core';
|
import AddOrEditDictionaryDialog from './components/AddOrEditDictionaryDialog.vue';
|
import { convertApi2FormUrl, convertApi2FormUrlOnlyOne } from '@/utils';
|
import * as dictionaryServices from '@/services/api/dictionary';
|
import { CategoryCode } from '@/constants';
|
|
defineOptions({
|
name: 'DataDictionary',
|
});
|
|
const operationBtnMap: Record<string, OperationBtnType> = {
|
editBtn: { emits: { onClick: (role) => openDialog(role) } },
|
};
|
|
const { checkSubModuleItemShow, column, operationBtns } = useAccess({
|
operationBtnMap,
|
});
|
|
const { dictionaryCategoryList, ensureQueryData } = useGetDictionaryCategorySelect();
|
|
const { getDictionaryDataNameByCode, updateDictionaryDataSelect } = useDictionaryDataSelect({
|
categoryCode: CategoryCode.IndustryCategory,
|
});
|
|
const BaseState = {
|
loading: true,
|
};
|
const state = reactive({ ...BaseState });
|
|
onMounted(async () => {
|
const dictionaryCategoryList = await ensureQueryData();
|
if (dictionaryCategoryList.length > 0) {
|
extraParamState.categoryId = dictionaryCategoryList[0].value;
|
}
|
await getList();
|
state.loading = false;
|
});
|
|
const {
|
getDataSource: getList,
|
proTableProps,
|
paginationState,
|
extraParamState,
|
reset,
|
} = useTable(
|
async ({ pageIndex, pageSize }, extraParamState) => {
|
try {
|
let params: API.GetDictionaryDatasQuery = {
|
pageModel: {
|
rows: pageSize,
|
page: pageIndex,
|
orderInput: extraParamState.orderInput,
|
},
|
categoryId: extraParamState.categoryId,
|
keywords: extraParamState.keywords,
|
};
|
let res = await dictionaryServices.getDictionaryDatas(params, {
|
showLoading: !state.loading,
|
});
|
return res;
|
} catch (error) {
|
console.log('error: ', error);
|
}
|
},
|
{
|
defaultExtraParams: {
|
categoryId: '',
|
keywords: '',
|
orderInput: [{ property: 'sort', order: EnumPagedListOrder.Asc }],
|
},
|
queryKey: ['dictionaryServices/getDictionaryDatas'],
|
columnsRenderProps: {
|
field1: {
|
formatter(row: API.GetDictionaryDatasQueryResultItem) {
|
return row.categoryCode == CategoryCode.Position
|
? getDictionaryDataNameByCode(row.field1)
|
: '';
|
},
|
},
|
},
|
}
|
);
|
|
function openDialog(row?: API.GetDictionaryDatasQueryResultItem) {
|
if (row) {
|
handleEdit({
|
id: row.id,
|
categoryId: row.categoryId,
|
code: row.code,
|
content: row.content,
|
sort: row.sort,
|
isDisabled: row.isDisabled,
|
field1: row.field1,
|
field2: convertApi2FormUrlOnlyOne(row.field2),
|
});
|
} else {
|
handleAdd({
|
categoryId: extraParamState.categoryId,
|
});
|
}
|
}
|
|
const { dialogProps, handleAdd, handleEdit, editForm, dialogState } = useFormDialog({
|
onConfirm: handleAddOrEdit,
|
defaultFormParams: {
|
id: '',
|
categoryId: '',
|
code: '',
|
content: '',
|
sort: 0,
|
isDisabled: false,
|
field1: '',
|
field2: [] as UploadUserFile[],
|
title: '新增字典',
|
},
|
editTitle: '编辑字典',
|
});
|
|
async function handleAddOrEdit() {
|
try {
|
let params: API.SaveDictionaryDataCommand = {
|
categoryId: editForm.categoryId,
|
code: editForm.code,
|
sort: editForm.sort,
|
content: editForm.content,
|
isDisabled: editForm.isDisabled,
|
field1: editForm.field1,
|
field2: editForm.field2?.[0]?.path ?? '',
|
};
|
if (editForm.id) {
|
params.id = editForm.id;
|
}
|
let res = await dictionaryServices.saveDictionaryData(params);
|
if (res) {
|
Message.successMessage('操作成功');
|
updateDictionaryDataSelect(editForm.categoryId);
|
getList(paginationState.pageIndex);
|
dialogState.dialogVisible = false;
|
}
|
} catch (error) {}
|
}
|
|
async function setCategoryVis(row: API.GetDictionaryDatasQueryResultItem) {
|
try {
|
await Message.tipMessage(`确认要${row.isDisabled ? '启用' : '禁用'}吗?`);
|
let params: API.SetDictionaryDataIsDisabledCommand = {
|
ids: [row.id],
|
isDisabled: !row.isDisabled,
|
};
|
let res = await dictionaryServices.setDictionaryDataIsDisabled(params);
|
updateDictionaryDataSelect(row.categoryId);
|
getList(paginationState.pageIndex);
|
return !!res;
|
} catch (error) {}
|
}
|
|
async function handleReset() {
|
try {
|
const dictionaryCategoryList = await ensureQueryData();
|
reset({ categoryId: dictionaryCategoryList[0].value });
|
} catch (error) {}
|
}
|
</script>
|