<template>
|
<div class="wave-rule-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>{{ t('pages.manager.waveRule.actions.add') }}</ElButton>
|
<ElButton
|
v-auth="'delete'"
|
type="danger"
|
:disabled="selectedRows.length === 0"
|
@click="handleBatchDelete"
|
v-ripple
|
>
|
{{ t('common.actions.batchDelete') }}
|
</ElButton>
|
</ElSpace>
|
</template>
|
</ArtTableHeader>
|
|
<ArtTable
|
:loading="loading"
|
:data="data"
|
:columns="columns"
|
:pagination="pagination"
|
@selection-change="handleSelectionChange"
|
@pagination:size-change="handleSizeChange"
|
@pagination:current-change="handleCurrentChange"
|
/>
|
|
<WaveRuleDialog
|
v-model:visible="dialogVisible"
|
:wave-rule-data="currentWaveRuleData"
|
:type-options="typeOptions"
|
@submit="handleDialogSubmit"
|
/>
|
|
<WaveRuleDetailDrawer
|
v-model:visible="detailDrawerVisible"
|
:loading="detailLoading"
|
:detail-data="detailData"
|
/>
|
</ElCard>
|
</div>
|
</template>
|
|
<script setup>
|
import { ElMessage } from 'element-plus'
|
import { useI18n } from 'vue-i18n'
|
import { guardRequestWithMessage } from '@/utils/sys/requestGuard'
|
import { useAuth } from '@/hooks/core/useAuth'
|
import { useTable } from '@/hooks/core/useTable'
|
import { useCrudPage } from '@/views/system/common/useCrudPage'
|
import {
|
fetchDeleteWaveRule,
|
fetchDictDataPage,
|
fetchGetWaveRuleDetail,
|
fetchSaveWaveRule,
|
fetchUpdateWaveRule,
|
fetchWaveRulePage
|
} from '@/api/system-manage'
|
import WaveRuleDialog from './modules/wave-rule-dialog.vue'
|
import WaveRuleDetailDrawer from './modules/wave-rule-detail-drawer.vue'
|
import { createWaveRuleTableColumns } from './waveRuleTable.columns'
|
import {
|
buildWaveRuleDialogModel,
|
buildWaveRulePageQueryParams,
|
buildWaveRuleSavePayload,
|
buildWaveRuleSearchParams,
|
buildWaveRuleTypeOptions,
|
createWaveRuleSearchState,
|
getWaveRuleDictTypeCode,
|
getWaveRulePaginationKey,
|
normalizeWaveRuleListRow
|
} from './waveRulePage.helpers'
|
|
defineOptions({ name: 'WaveRule' })
|
const { t } = useI18n()
|
|
const { hasAuth } = useAuth()
|
const searchForm = ref(createWaveRuleSearchState())
|
const detailDrawerVisible = ref(false)
|
const detailLoading = ref(false)
|
const detailData = ref({})
|
const typeOptions = ref([])
|
let handleDeleteAction = null
|
|
const searchItems = computed(() => [
|
{
|
label: t('table.keyword'),
|
key: 'condition',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: t('pages.manager.waveRule.search.conditionPlaceholder')
|
}
|
},
|
{
|
label: t('table.code'),
|
key: 'code',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: t('pages.manager.waveRule.search.codePlaceholder')
|
}
|
},
|
{
|
label: t('pages.manager.waveRule.table.type'),
|
key: 'type',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: typeOptions.value
|
}
|
},
|
{
|
label: t('table.name'),
|
key: 'name',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: t('pages.manager.waveRule.search.namePlaceholder')
|
}
|
}
|
])
|
|
async function loadTypeOptions() {
|
const records = await guardRequestWithMessage(
|
fetchDictDataPage({
|
current: 1,
|
pageSize: 200,
|
dictTypeCode: getWaveRuleDictTypeCode(),
|
status: 1
|
}),
|
[],
|
{
|
timeoutMessage: t('pages.manager.waveRule.messages.typeTimeout')
|
}
|
)
|
typeOptions.value = buildWaveRuleTypeOptions(Array.isArray(records?.records) ? records.records : records?.list || records || [])
|
}
|
|
async function openDetail(row) {
|
detailDrawerVisible.value = true
|
detailLoading.value = true
|
try {
|
detailData.value = normalizeWaveRuleListRow(await fetchGetWaveRuleDetail(row.id))
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || t('pages.manager.waveRule.messages.detailFailed'))
|
} finally {
|
detailLoading.value = false
|
}
|
}
|
|
async function openEditDialog(row) {
|
try {
|
currentWaveRuleData.value = buildWaveRuleDialogModel(await fetchGetWaveRuleDetail(row.id))
|
dialogVisible.value = true
|
dialogType.value = 'edit'
|
} catch (error) {
|
ElMessage.error(error?.message || t('pages.manager.waveRule.messages.detailFailed'))
|
}
|
}
|
|
const {
|
columns,
|
columnChecks,
|
data,
|
loading,
|
pagination,
|
getData,
|
replaceSearchParams,
|
resetSearchParams,
|
handleSizeChange,
|
handleCurrentChange,
|
refreshData,
|
refreshCreate,
|
refreshUpdate,
|
refreshRemove
|
} = useTable({
|
core: {
|
apiFn: fetchWaveRulePage,
|
apiParams: buildWaveRulePageQueryParams(searchForm.value),
|
paginationKey: getWaveRulePaginationKey(),
|
columnsFactory: () =>
|
createWaveRuleTableColumns({
|
handleView: openDetail,
|
handleEdit: openEditDialog,
|
handleDelete: hasAuth('delete') ? (row) => handleDeleteAction?.(row) : null
|
})
|
},
|
transform: {
|
dataTransformer: (records) => {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((item) => normalizeWaveRuleListRow(item))
|
}
|
}
|
})
|
|
const {
|
dialogVisible,
|
dialogType,
|
currentRecord: currentWaveRuleData,
|
selectedRows,
|
handleSelectionChange,
|
showDialog,
|
handleDialogSubmit,
|
handleDelete,
|
handleBatchDelete
|
} = useCrudPage({
|
createEmptyModel: () => buildWaveRuleDialogModel(),
|
buildEditModel: (record) => buildWaveRuleDialogModel(record),
|
buildSavePayload: (formData) => buildWaveRuleSavePayload(formData),
|
saveRequest: fetchSaveWaveRule,
|
updateRequest: fetchUpdateWaveRule,
|
deleteRequest: fetchDeleteWaveRule,
|
entityName: t('pages.manager.waveRule.entity'),
|
resolveRecordLabel: (record) => record?.name || record?.code || record?.id,
|
refreshCreate,
|
refreshUpdate,
|
refreshRemove
|
})
|
handleDeleteAction = handleDelete
|
|
onMounted(() => {
|
loadTypeOptions()
|
})
|
|
function handleSearch(params) {
|
replaceSearchParams(buildWaveRuleSearchParams(params))
|
getData()
|
}
|
|
function handleReset() {
|
Object.assign(searchForm.value, createWaveRuleSearchState())
|
resetSearchParams()
|
}
|
</script>
|