Files
one-pipe-system/src/views/settings/asset-wallet-auto-renewal/index.vue
luo c136f68ab8
All checks were successful
构建并部署前端到测试环境 / deploy (push) Successful in 55s
feat: 代理商注册列表
2026-09-21 18:07:36 +08:00

272 lines
8.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<ArtTableFullScreen>
<div class="asset-wallet-auto-renewal-page" id="table-full-screen">
<ElCard shadow="never" class="art-table-card">
<ElResult
v-if="loadError"
icon="error"
title="配置加载失败"
sub-title="无权限操作该资源或资源不存在"
>
<template #extra>
<ElButton type="primary" @click="loadConfig">重新加载</ElButton>
</template>
</ElResult>
<template v-else>
<ElForm
ref="formRef"
v-loading="loading"
:model="form"
:rules="formRules"
label-width="140px"
class="config-form"
>
<ElFormItem label="总开关" prop="enabled">
<ElSwitch v-model="form.enabled" :active-value="1" :inactive-value="0" />
<span class="form-tip">{{ form.enabled === 1 ? '开启' : '关闭' }}</span>
</ElFormItem>
<ElFormItem label="适用范围" prop="scope">
<ElRadioGroup v-model="form.scope">
<ElRadio value="all">全部主套餐</ElRadio>
<ElRadio value="specified">指定主套餐</ElRadio>
</ElRadioGroup>
</ElFormItem>
<ElFormItem v-if="form.scope === 'specified'" label="指定主套餐" prop="package_ids">
<ElSelect
v-model="form.package_ids"
multiple
filterable
:loading="packageLoading"
placeholder="请选择主套餐"
style="width: 100%"
>
<ElOption
v-for="pkg in packageOptions"
:key="pkg.id"
:label="pkg.package_name"
:value="pkg.id"
/>
</ElSelect>
<span class="form-tip">仅支持选择当前可售主套餐</span>
</ElFormItem>
<ElFormItem label="到期前天数" prop="days_before_expiry">
<ElInputNumber
v-model="form.days_before_expiry"
:min="1"
:max="90"
controls-position="right"
style="width: 200px"
/>
<span class="form-tip">到期前 N 天开始扫描并自动续费(1-90)</span>
</ElFormItem>
</ElForm>
<div class="config-meta">
<span>总开关:{{ config?.enabled_name || '-' }}</span>
<span>适用范围:{{ config?.scope_name || '-' }}</span>
<span>配置版本:v{{ config?.config_version ?? '-' }}</span>
<span>最近保存:{{ config?.updater || '-' }}</span>
<span>{{ config?.updated_at ? formatDateTime(config.updated_at) : '-' }}</span>
</div>
<div class="form-actions">
<ElButton v-if="canUpdate" type="primary" :loading="saving" @click="handleSave">
保存配置
</ElButton>
<ElButton :disabled="saving" @click="loadConfig">重新加载</ElButton>
</div>
</template>
</ElCard>
</div>
</ArtTableFullScreen>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
import { AssetWalletService, PackageManageService } from '@/api/modules'
import type {
AssetAutoRenewalConfig,
AssetAutoRenewalScope,
UpdateAssetAutoRenewalConfigRequest
} from '@/types/api'
import { formatDateTime } from '@/utils/business/format'
import { usePermission } from '@/composables/usePermission'
import { useAuth } from '@/composables/useAuth'
import { AUGUST_PERMISSIONS } from '@/config/constants/augustIteration'
defineOptions({ name: 'AssetWalletAutoRenewal' })
const { isPlatformAccount } = usePermission()
const { hasAuth } = useAuth()
const canUpdate = computed(() => hasAuth(AUGUST_PERMISSIONS.assetWalletAutoRenewal.update))
const formRef = ref<FormInstance>()
const loading = ref(false)
const saving = ref(false)
const loadError = ref(false)
const config = ref<AssetAutoRenewalConfig | null>(null)
const form = reactive({
enabled: 1 as 0 | 1,
scope: 'all' as AssetAutoRenewalScope,
package_ids: [] as number[],
days_before_expiry: 30
})
const formRules: FormRules = {
enabled: [{ required: true, message: '请选择总开关状态', trigger: 'change' }],
scope: [{ required: true, message: '请选择适用范围', trigger: 'change' }],
package_ids: [
{
validator: (_rule, value, callback) => {
if (form.scope === 'specified' && (!value || value.length === 0)) {
callback(new Error('请至少选择一个主套餐'))
} else {
callback()
}
},
trigger: 'change'
}
],
days_before_expiry: [
{ required: true, message: '请输入到期前天数', trigger: 'change' },
{
validator: (_rule, value, callback) => {
if (value === null || value === undefined) {
callback(new Error('请输入到期前天数'))
} else if (Number(value) < 1 || Number(value) > 90) {
callback(new Error('到期前天数必须在 1-90 之间'))
} else {
callback()
}
},
trigger: 'change'
}
]
}
const packageLoading = ref(false)
const packageOptions = ref<Array<{ id: number; package_name: string }>>([])
const loadPackages = async () => {
packageLoading.value = true
try {
const { data } = await PackageManageService.getPackages({
page: 1,
page_size: 200,
package_type: 'formal',
shelf_status: 1,
status: 1
})
packageOptions.value = (data.items || []).map((pkg) => ({
id: pkg.id,
package_name: pkg.package_name
}))
} catch (error) {
console.error('加载可售主套餐失败', error)
} finally {
packageLoading.value = false
}
}
const applyConfig = (data: AssetAutoRenewalConfig) => {
config.value = data
form.enabled = data.enabled
form.scope = data.scope
form.package_ids = data.package_ids || []
form.days_before_expiry = data.days_before_expiry
}
const loadConfig = async () => {
if (!isPlatformAccount.value) {
loadError.value = true
return
}
loading.value = true
loadError.value = false
try {
const res = await AssetWalletService.getAutoRenewalConfig()
if (res.code === 0 && res.data) {
applyConfig(res.data)
} else if (res.code !== 0) {
ElMessage.error(res.msg || '配置加载失败')
loadError.value = true
}
} catch (error) {
console.error('加载自动续费配置失败', error)
loadError.value = true
} finally {
loading.value = false
}
}
const handleSave = async () => {
if (!formRef.value) return
const valid = await formRef.value.validate().catch(() => false)
if (!valid) return
const payload: UpdateAssetAutoRenewalConfigRequest = {
enabled: form.enabled,
scope: form.scope,
package_ids: form.scope === 'all' ? [] : form.package_ids,
days_before_expiry: form.days_before_expiry
}
saving.value = true
try {
const res = await AssetWalletService.saveAutoRenewalConfig(payload)
if (res.code === 0 && res.data) {
applyConfig(res.data)
ElMessage.success('自动续费配置保存成功')
} else {
ElMessage.error(res.msg || '自动续费配置保存失败')
}
} catch (error) {
console.error('保存自动续费配置失败', error)
} finally {
saving.value = false
}
}
onMounted(() => {
loadConfig()
loadPackages()
})
</script>
<style scoped lang="scss">
.asset-wallet-auto-renewal-page {
height: 100%;
.config-form {
max-width: 720px;
padding-top: 10px;
}
.form-tip {
margin-left: 12px;
font-size: 12px;
color: var(--art-gray-600);
}
.config-meta {
display: flex;
gap: 24px;
padding: 12px 0 0 140px;
font-size: 13px;
color: var(--art-gray-600);
}
.form-actions {
display: flex;
gap: 12px;
padding: 20px 0 10px 140px;
}
}
</style>