<template>
|
<div class="config-page art-full-height">
|
<ArtSearchBar
|
v-model="searchForm"
|
:items="searchItems"
|
:showExpand="false"
|
@search="handleSearch"
|
@reset="handleReset"
|
/>
|
|
<ElCard class="art-table-card">
|
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
<template #left>
|
<ElSpace wrap>
|
<ElButton v-auth="'add'" @click="showDialog('add')" v-ripple>新增配置</ElButton>
|
<ElButton
|
v-auth="'delete'"
|
type="danger"
|
:disabled="selectedRows.length === 0"
|
@click="handleBatchDelete"
|
v-ripple
|
>
|
批量删除
|
</ElButton>
|
</ElSpace>
|
</template>
|
</ArtTableHeader>
|
|
<ArtTable
|
:loading="loading"
|
:data="data"
|
:columns="columns"
|
:pagination="pagination"
|
@selection-change="handleSelectionChange"
|
@pagination:size-change="handleSizeChange"
|
@pagination:current-change="handleCurrentChange"
|
/>
|
|
<ConfigDialog
|
v-model:visible="dialogVisible"
|
:config-data="currentConfigData"
|
@submit="handleDialogSubmit"
|
/>
|
|
<ConfigDetailDrawer
|
v-model:visible="detailDrawerVisible"
|
:loading="detailLoading"
|
:detail-data="detailData"
|
/>
|
</ElCard>
|
</div>
|
</template>
|
|
<script setup>
|
import { ElMessage } from 'element-plus'
|
import { useAuth } from '@/hooks/core/useAuth'
|
import { useTable } from '@/hooks/core/useTable'
|
import { useCrudPage } from '@/views/system/common/useCrudPage'
|
import {
|
fetchConfigPage,
|
fetchDeleteConfig,
|
fetchGetConfigDetail,
|
fetchSaveConfig,
|
fetchUpdateConfig
|
} from '@/api/system-manage'
|
import ConfigDialog from './modules/config-dialog.vue'
|
import ConfigDetailDrawer from './modules/config-detail-drawer.vue'
|
import { createConfigTableColumns } from './configTable.columns'
|
import {
|
buildConfigDialogModel,
|
buildConfigPageQueryParams,
|
buildConfigSavePayload,
|
buildConfigSearchParams,
|
createConfigSearchState,
|
getConfigPaginationKey,
|
getConfigTypeOptions,
|
normalizeConfigListRow
|
} from './configPage.helpers'
|
|
defineOptions({ name: 'Config' })
|
|
const { hasAuth } = useAuth()
|
const searchForm = ref(createConfigSearchState())
|
const detailDrawerVisible = ref(false)
|
const detailLoading = ref(false)
|
const detailData = ref({})
|
let handleDeleteAction = null
|
|
const searchItems = computed(() => [
|
{
|
label: '关键字',
|
key: 'condition',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入配置名称'
|
}
|
},
|
{
|
label: '标识',
|
key: 'flag',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入配置标识'
|
}
|
},
|
{
|
label: '类型',
|
key: 'type',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: getConfigTypeOptions()
|
}
|
},
|
{
|
label: '状态',
|
key: 'status',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
}
|
])
|
|
async function openDetail(row) {
|
detailDrawerVisible.value = true
|
detailLoading.value = true
|
try {
|
detailData.value = normalizeConfigListRow(await fetchGetConfigDetail(row.id))
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || '获取配置详情失败')
|
} finally {
|
detailLoading.value = false
|
}
|
}
|
|
async function openEditDialog(row) {
|
try {
|
currentConfigData.value = buildConfigDialogModel(await fetchGetConfigDetail(row.id))
|
dialogVisible.value = true
|
dialogType.value = 'edit'
|
} catch (error) {
|
ElMessage.error(error?.message || '获取配置详情失败')
|
}
|
}
|
|
const {
|
columns,
|
columnChecks,
|
data,
|
loading,
|
pagination,
|
getData,
|
replaceSearchParams,
|
resetSearchParams,
|
handleSizeChange,
|
handleCurrentChange,
|
refreshData,
|
refreshCreate,
|
refreshUpdate,
|
refreshRemove
|
} = useTable({
|
core: {
|
apiFn: fetchConfigPage,
|
apiParams: buildConfigPageQueryParams(searchForm.value),
|
paginationKey: getConfigPaginationKey(),
|
columnsFactory: () =>
|
createConfigTableColumns({
|
handleView: openDetail,
|
handleEdit: openEditDialog,
|
handleDelete: hasAuth('delete') ? (row) => handleDeleteAction?.(row) : null
|
})
|
},
|
transform: {
|
dataTransformer: (records) => {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((item) => normalizeConfigListRow(item))
|
}
|
}
|
})
|
|
const {
|
dialogVisible,
|
dialogType,
|
currentRecord: currentConfigData,
|
selectedRows,
|
handleSelectionChange,
|
showDialog,
|
handleDialogSubmit,
|
handleDelete,
|
handleBatchDelete
|
} = useCrudPage({
|
createEmptyModel: () => buildConfigDialogModel(),
|
buildEditModel: (record) => buildConfigDialogModel(record),
|
buildSavePayload: (formData) => buildConfigSavePayload(formData),
|
saveRequest: fetchSaveConfig,
|
updateRequest: fetchUpdateConfig,
|
deleteRequest: fetchDeleteConfig,
|
entityName: '配置',
|
resolveRecordLabel: (record) => record?.name || record?.flag || record?.id,
|
refreshCreate,
|
refreshUpdate,
|
refreshRemove
|
})
|
handleDeleteAction = handleDelete
|
|
function handleSearch(params) {
|
replaceSearchParams(buildConfigSearchParams(params))
|
getData()
|
}
|
|
function handleReset() {
|
Object.assign(searchForm.value, createConfigSearchState())
|
resetSearchParams()
|
}
|
</script>
|