后台系统配置列表现在只返回当前真实使用的配置项
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
export interface SystemConfigOption {
|
||||
label: string
|
||||
value: string
|
||||
}
|
||||
|
||||
const shortTimeoutOptions: SystemConfigOption[] = [
|
||||
{ label: '不限时', value: '0' },
|
||||
{ label: '5 分钟', value: '5' },
|
||||
{ label: '10 分钟', value: '10' },
|
||||
{ label: '15 分钟', value: '15' },
|
||||
{ label: '30 分钟', value: '30' },
|
||||
{ label: '45 分钟', value: '45' },
|
||||
{ label: '60 分钟', value: '60' },
|
||||
{ label: '90 分钟', value: '90' },
|
||||
{ label: '120 分钟', value: '120' },
|
||||
]
|
||||
|
||||
const longTimeoutOptions: SystemConfigOption[] = [
|
||||
{ label: '不限时', value: '0' },
|
||||
{ label: '30 分钟', value: '30' },
|
||||
{ label: '60 分钟', value: '60' },
|
||||
{ label: '120 分钟', value: '120' },
|
||||
{ label: '180 分钟', value: '180' },
|
||||
{ label: '240 分钟', value: '240' },
|
||||
{ label: '360 分钟', value: '360' },
|
||||
{ label: '12 小时', value: '720' },
|
||||
{ label: '24 小时', value: '1440' },
|
||||
{ label: '48 小时', value: '2880' },
|
||||
]
|
||||
|
||||
const booleanOptions: SystemConfigOption[] = [
|
||||
{ label: '开启', value: 'true' },
|
||||
{ label: '关闭', value: 'false' },
|
||||
]
|
||||
|
||||
export const systemConfigSelectOptions: Record<string, SystemConfigOption[]> = {
|
||||
'handoff.owner_submit_timeout_minutes': shortTimeoutOptions,
|
||||
'handoff.renter_confirm_timeout_minutes': shortTimeoutOptions,
|
||||
'handoff.owner_return_confirm_timeout_minutes': longTimeoutOptions,
|
||||
'order.pending_payment_timeout_minutes': shortTimeoutOptions,
|
||||
'order.return_overdue_grace_minutes': [
|
||||
{ label: '无宽限', value: '0' },
|
||||
{ label: '5 分钟', value: '5' },
|
||||
{ label: '10 分钟', value: '10' },
|
||||
{ label: '15 分钟', value: '15' },
|
||||
{ label: '30 分钟', value: '30' },
|
||||
{ label: '60 分钟', value: '60' },
|
||||
{ label: '120 分钟', value: '120' },
|
||||
],
|
||||
'listing.review_required': booleanOptions,
|
||||
'chat.default_support_admin_id': [
|
||||
{ label: '管理员 ID 1', value: '1' },
|
||||
{ label: '管理员 ID 2', value: '2' },
|
||||
{ label: '管理员 ID 3', value: '3' },
|
||||
],
|
||||
}
|
||||
|
||||
export function getSystemConfigSelectOptions(key: string) {
|
||||
return systemConfigSelectOptions[key] || null
|
||||
}
|
||||
|
||||
export function formatSystemConfigSelectValue(key: string, value: string) {
|
||||
const option = getSystemConfigSelectOptions(key)?.find((item) => item.value === value)
|
||||
return option?.label || null
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
import { fetchSystemConfigs, type SystemConfig } from '@/api/systemConfigs'
|
||||
import { formatDateTime } from '@/utils/time'
|
||||
import { safeParseJSON } from '@/utils/json'
|
||||
import { formatSystemConfigSelectValue } from '@/utils/systemConfigOptions'
|
||||
|
||||
// 导入重构后的 Dialog 子组件
|
||||
import PublishOptionsDialog from './components/PublishOptionsDialog.vue'
|
||||
@@ -154,6 +155,10 @@ function formatConfigValue(row: SystemConfig) {
|
||||
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
||||
return 'JSON 配置'
|
||||
}
|
||||
const selectedLabel = formatSystemConfigSelectValue(row.key, row.value)
|
||||
if (selectedLabel) {
|
||||
return selectedLabel
|
||||
}
|
||||
return row.value
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ElMessage } from 'element-plus'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
|
||||
import { updateSystemConfig, type SystemConfig } from '@/api/systemConfigs'
|
||||
import { getSystemConfigSelectOptions, type SystemConfigOption } from '@/utils/systemConfigOptions'
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
@@ -34,6 +35,15 @@ const isStructuredConfig = computed(() => {
|
||||
return trimmed.startsWith('{') || trimmed.startsWith('[')
|
||||
})
|
||||
|
||||
const selectOptions = computed<SystemConfigOption[] | null>(() => {
|
||||
const options = getSystemConfigSelectOptions(props.config.key)
|
||||
if (!options) return null
|
||||
if (!value.value || options.some((item) => item.value === value.value)) {
|
||||
return options
|
||||
}
|
||||
return [{ label: `当前值:${value.value}`, value: value.value }, ...options]
|
||||
})
|
||||
|
||||
async function handleSave() {
|
||||
submitting.value = true
|
||||
try {
|
||||
@@ -73,6 +83,16 @@ function readError(error: unknown, fallback: string) {
|
||||
<el-form-item v-if="isStructuredConfig" label="配置值 (JSON)" class="full-control">
|
||||
<el-input v-model="value" type="textarea" :rows="12" placeholder="配置值 JSON" />
|
||||
</el-form-item>
|
||||
<el-form-item v-else-if="selectOptions" label="配置值" class="full-control">
|
||||
<el-select v-model="value" class="full-select" placeholder="请选择配置值">
|
||||
<el-option
|
||||
v-for="option in selectOptions"
|
||||
:key="option.value"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-else label="配置值" class="full-control">
|
||||
<el-input v-model="value" placeholder="配置值" />
|
||||
</el-form-item>
|
||||
@@ -103,6 +123,10 @@ function readError(error: unknown, fallback: string) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.full-select {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.desc-item {
|
||||
margin-top: 14px;
|
||||
margin-bottom: 0;
|
||||
|
||||
Reference in New Issue
Block a user