This commit is contained in:
226
src/views/settings/h5-popup-configuration/detail.vue
Normal file
226
src/views/settings/h5-popup-configuration/detail.vue
Normal file
@@ -0,0 +1,226 @@
|
||||
<template>
|
||||
<div class="h5-popup-configuration-detail-page">
|
||||
<ElCard shadow="never">
|
||||
<div class="detail-header">
|
||||
<ElButton @click="handleBack">
|
||||
<template #icon>
|
||||
<ElIcon><ArrowLeft /></ElIcon>
|
||||
</template>
|
||||
返回
|
||||
</ElButton>
|
||||
<h2 class="detail-title">H5运营弹窗配置详情</h2>
|
||||
</div>
|
||||
|
||||
<DetailPage v-if="configuration" :sections="detailSections" :data="configuration" />
|
||||
|
||||
<div v-if="loading" class="loading-container">
|
||||
<ElIcon class="is-loading"><Loading /></ElIcon>
|
||||
<span>加载中...</span>
|
||||
</div>
|
||||
|
||||
<ElEmpty v-else-if="!configuration" description="未找到运营弹窗配置" />
|
||||
</ElCard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, h, onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElButton, ElCard, ElIcon, ElMessage, ElTag } from 'element-plus'
|
||||
import { ArrowLeft, Loading } from '@element-plus/icons-vue'
|
||||
import DetailPage from '@/components/common/DetailPage.vue'
|
||||
import type { DetailSection } from '@/components/common/DetailPage.vue'
|
||||
import { H5PopupConfigurationService } from '@/api/modules'
|
||||
import type { H5PopupConfiguration, H5PopupPage, H5PopupType } from '@/types/api'
|
||||
import { RoutesAlias } from '@/router/routesAlias'
|
||||
import { formatDateTime } from '@/utils/business/format'
|
||||
import { getErrorMessage } from '@/utils/business'
|
||||
|
||||
defineOptions({ name: 'H5PopupConfigurationDetail' })
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
const configuration = ref<H5PopupConfiguration | null>(null)
|
||||
|
||||
const popupTypeNames: Record<H5PopupType, string> = {
|
||||
promotion: '套餐政策推广',
|
||||
announcement: '通用公告'
|
||||
}
|
||||
const pageNames: Record<H5PopupPage, string> = {
|
||||
home: '首页',
|
||||
asset_detail: '资产详情',
|
||||
package_purchase: '套餐购买',
|
||||
asset_wallet_recharge: '资产钱包充值'
|
||||
}
|
||||
const frequencyNames = {
|
||||
once: '每客户每配置版本仅一次',
|
||||
daily: '每客户每配置版本每个上海自然日一次'
|
||||
}
|
||||
const actionTypeNames: Record<string, string> = {
|
||||
package_purchase: '套餐购买',
|
||||
asset_wallet_recharge: '资产钱包充值'
|
||||
}
|
||||
const cardTypeNames: Record<string, string> = {
|
||||
CMCC: '中国移动',
|
||||
CUCC: '中国联通',
|
||||
CTCC: '中国电信',
|
||||
CBN: '中国广电'
|
||||
}
|
||||
|
||||
const formatList = (
|
||||
values: Array<string | number> | null | undefined,
|
||||
formatter?: (value: string) => string
|
||||
) => {
|
||||
if (!values?.length) return '全部'
|
||||
return values.map((value) => formatter?.(String(value)) || String(value)).join('、')
|
||||
}
|
||||
|
||||
const detailSections = computed((): DetailSection[] => [
|
||||
{
|
||||
title: '基础信息',
|
||||
fields: [
|
||||
{ label: '配置ID', prop: 'id' },
|
||||
{ label: '版本', prop: 'version' },
|
||||
{
|
||||
label: '弹窗类型',
|
||||
render: (data: H5PopupConfiguration) =>
|
||||
h(
|
||||
ElTag,
|
||||
{ type: 'primary' },
|
||||
() => data.popup_type_text || popupTypeNames[data.popup_type]
|
||||
)
|
||||
},
|
||||
{
|
||||
label: '启停状态',
|
||||
render: (data: H5PopupConfiguration) =>
|
||||
h(
|
||||
ElTag,
|
||||
{ type: data.enabled ? 'success' : 'info' },
|
||||
() => data.enabled_text || (data.enabled ? '启用' : '停用')
|
||||
)
|
||||
},
|
||||
{ label: '标题', prop: 'title', fullWidth: true },
|
||||
{ label: '正文', prop: 'content', fullWidth: true }
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '投放配置',
|
||||
fields: [
|
||||
{
|
||||
label: '命中页面',
|
||||
formatter: (_value: unknown, data: H5PopupConfiguration) =>
|
||||
formatList(data.pages, (value) => pageNames[value as H5PopupPage] || value),
|
||||
fullWidth: true
|
||||
},
|
||||
{ label: '优先级', prop: 'priority' },
|
||||
{
|
||||
label: '投放频率',
|
||||
formatter: (_value: unknown, data: H5PopupConfiguration) =>
|
||||
data.frequency_text || frequencyNames[data.frequency] || data.frequency
|
||||
},
|
||||
{
|
||||
label: '受控动作',
|
||||
formatter: (_value: unknown, data: H5PopupConfiguration) =>
|
||||
actionTypeNames[data.action_type || ''] || '无'
|
||||
},
|
||||
{
|
||||
label: '生效开始',
|
||||
formatter: (_value: unknown, data: H5PopupConfiguration) => formatDateTime(data.starts_at)
|
||||
},
|
||||
{
|
||||
label: '生效结束',
|
||||
formatter: (_value: unknown, data: H5PopupConfiguration) => formatDateTime(data.ends_at)
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '投放范围与审计信息',
|
||||
fields: [
|
||||
{
|
||||
label: '店铺范围',
|
||||
formatter: (_value: unknown, data: H5PopupConfiguration) => formatList(data.shop_ids),
|
||||
fullWidth: true
|
||||
},
|
||||
{
|
||||
label: '设备类型范围',
|
||||
formatter: (_value: unknown, data: H5PopupConfiguration) => formatList(data.device_types),
|
||||
fullWidth: true
|
||||
},
|
||||
{
|
||||
label: '卡类型范围',
|
||||
formatter: (_value: unknown, data: H5PopupConfiguration) =>
|
||||
formatList(data.card_types, (value) => cardTypeNames[value] || value),
|
||||
fullWidth: true
|
||||
},
|
||||
{ label: '创建人', prop: 'creator' },
|
||||
{
|
||||
label: '创建时间',
|
||||
formatter: (_value: unknown, data: H5PopupConfiguration) =>
|
||||
formatDateTime(data.created_at)
|
||||
},
|
||||
{ label: '最近更新人', prop: 'updater' },
|
||||
{
|
||||
label: '最近更新时间',
|
||||
formatter: (_value: unknown, data: H5PopupConfiguration) =>
|
||||
formatDateTime(data.updated_at)
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
|
||||
const loadDetail = async () => {
|
||||
const id = Number(route.params.id)
|
||||
if (!id) {
|
||||
ElMessage.error('无效的配置ID')
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await H5PopupConfigurationService.getConfiguration(id)
|
||||
if (res.code === 0) configuration.value = res.data
|
||||
else ElMessage.error(res.msg || '获取运营弹窗配置详情失败')
|
||||
} catch (error) {
|
||||
ElMessage.error(getErrorMessage(error, '获取运营弹窗配置详情失败'))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleBack = () => {
|
||||
router.push(RoutesAlias.H5PopupConfigurations)
|
||||
}
|
||||
|
||||
onMounted(() => void loadDetail())
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.h5-popup-configuration-detail-page {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 16px;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.detail-title {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 240px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
</style>
|
||||
@@ -52,6 +52,16 @@
|
||||
@closed="resetForm"
|
||||
>
|
||||
<ElForm ref="formRef" :model="form" :rules="formRules" label-width="110px">
|
||||
<ElFormItem label="弹窗类型" prop="popup_type">
|
||||
<ElSelect v-model="form.popup_type" placeholder="请选择弹窗类型" style="width: 100%">
|
||||
<ElOption
|
||||
v-for="item in POPUP_TYPE_OPTIONS"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="弹窗标题" prop="title">
|
||||
<ElInput
|
||||
v-model="form.title"
|
||||
@@ -174,60 +184,12 @@
|
||||
</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
|
||||
<!-- 详情 -->
|
||||
<ElDialog v-model="detailDialogVisible" title="运营弹窗配置详情" width="680px">
|
||||
<div v-if="detailLoading" class="detail-loading">加载中...</div>
|
||||
<ElDescriptions v-else-if="detail" :column="2" border>
|
||||
<ElDescriptionsItem label="配置ID">{{ detail.id }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="版本">{{ detail.version }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="标题" :span="2">{{ detail.title }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="正文" :span="2">
|
||||
<span class="detail-content">{{ detail.content }}</span>
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="命中页面" :span="2">
|
||||
{{ formatPages(detail.pages) }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="店铺范围">
|
||||
{{ formatScope(detail.shop_ids) }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="设备类型范围">
|
||||
{{ formatScope(detail.device_types) }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="卡类型范围">
|
||||
{{ formatCardTypes(detail.card_types) }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="优先级">{{ detail.priority }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="投放频率">
|
||||
{{ detail.frequency_text || FREQUENCY_NAMES[detail.frequency] || detail.frequency }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="启停状态">
|
||||
{{ detail.enabled_text || (detail.enabled ? '启用' : '停用') }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="受控动作">
|
||||
{{ ACTION_TYPE_NAMES[detail.action_type] || '无' }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="生效开始" :span="2">
|
||||
{{ formatDateTime(detail.starts_at) }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="生效结束" :span="2">
|
||||
{{ formatDateTime(detail.ends_at) }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="创建人">{{ detail.creator }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="创建时间">{{
|
||||
formatDateTime(detail.created_at)
|
||||
}}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="最近更新人">{{ detail.updater }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="最近更新时间">{{
|
||||
formatDateTime(detail.updated_at)
|
||||
}}</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
</ElDialog>
|
||||
</ArtTableFullScreen>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, h, onMounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox, ElTag, FormInstance, FormRules } from 'element-plus'
|
||||
import { Plus } from '@element-plus/icons-vue'
|
||||
import { H5PopupConfigurationService, ShopService } from '@/api/modules'
|
||||
@@ -242,12 +204,14 @@
|
||||
H5PopupCardType,
|
||||
H5PopupConfiguration,
|
||||
H5PopupFrequency,
|
||||
H5PopupPage
|
||||
H5PopupPage,
|
||||
H5PopupType
|
||||
} from '@/types/api'
|
||||
|
||||
defineOptions({ name: 'H5PopupConfiguration' })
|
||||
|
||||
const { hasAuth } = useAuth()
|
||||
const router = useRouter()
|
||||
const perms = AUGUST_PERMISSIONS.h5PopupConfiguration
|
||||
|
||||
const canCreate = computed(() => hasAuth(perms.create))
|
||||
@@ -267,6 +231,14 @@
|
||||
{ label: '套餐购买', value: 'package_purchase' },
|
||||
{ label: '资产钱包充值', value: 'asset_wallet_recharge' }
|
||||
]
|
||||
const POPUP_TYPE_NAMES: Record<H5PopupType, string> = {
|
||||
promotion: '套餐政策推广',
|
||||
announcement: '通用公告'
|
||||
}
|
||||
const POPUP_TYPE_OPTIONS: Array<{ label: string; value: H5PopupType }> = [
|
||||
{ label: '套餐政策推广', value: 'promotion' },
|
||||
{ label: '通用公告', value: 'announcement' }
|
||||
]
|
||||
const FREQUENCY_NAMES: Record<H5PopupFrequency, string> = {
|
||||
once: '每客户每配置版本仅一次',
|
||||
daily: '每客户每配置版本每个上海自然日一次'
|
||||
@@ -322,6 +294,7 @@
|
||||
]
|
||||
|
||||
const columnOptions = [
|
||||
{ label: '弹窗类型', prop: 'popup_type' },
|
||||
{ label: '标题', prop: 'title' },
|
||||
{ label: '命中页面', prop: 'pages' },
|
||||
{ label: '范围', prop: 'scope' },
|
||||
@@ -341,15 +314,6 @@
|
||||
return pages.map((page) => PAGE_NAMES[page] || page).join('、')
|
||||
}
|
||||
|
||||
const formatScope = (values: string[] | number[] | null | undefined): string => {
|
||||
if (!values || values.length === 0) return '全部'
|
||||
const text = values
|
||||
.slice(0, 3)
|
||||
.map((item) => (typeof item === 'number' && item !== 0 ? `#${item}` : String(item)))
|
||||
.join('、')
|
||||
return values.length > 3 ? `${text} 等${values.length}项` : text
|
||||
}
|
||||
|
||||
const formatCardTypes = (values: H5PopupCardType[] | null | undefined): string => {
|
||||
if (!values || values.length === 0) return '全部'
|
||||
return values.map((item) => CARD_TYPE_NAMES[item] || item).join('、')
|
||||
@@ -370,7 +334,31 @@
|
||||
}
|
||||
|
||||
const { columnChecks, columns } = useCheckedColumns(() => [
|
||||
{ prop: 'title', label: '标题', minWidth: 180, showOverflowTooltip: true },
|
||||
{
|
||||
prop: 'popup_type',
|
||||
label: '弹窗类型',
|
||||
width: 120,
|
||||
formatter: (row: H5PopupConfiguration) =>
|
||||
row.popup_type_text || POPUP_TYPE_NAMES[row.popup_type] || row.popup_type
|
||||
},
|
||||
{
|
||||
prop: 'title',
|
||||
label: '标题',
|
||||
minWidth: 180,
|
||||
showOverflowTooltip: true,
|
||||
formatter: (row: H5PopupConfiguration) =>
|
||||
h(
|
||||
'span',
|
||||
{
|
||||
style: 'color: var(--el-color-primary); cursor: pointer; text-decoration: underline;',
|
||||
onClick: (event: MouseEvent) => {
|
||||
event.stopPropagation()
|
||||
goDetail(row)
|
||||
}
|
||||
},
|
||||
row.title
|
||||
)
|
||||
},
|
||||
{
|
||||
prop: 'pages',
|
||||
label: '命中页面',
|
||||
@@ -409,7 +397,7 @@
|
||||
prop: 'action_type',
|
||||
label: '受控动作',
|
||||
width: 120,
|
||||
formatter: (row: H5PopupConfiguration) => ACTION_TYPE_NAMES[row.action_type] || '无'
|
||||
formatter: (row: H5PopupConfiguration) => ACTION_TYPE_NAMES[row.action_type || ''] || '无'
|
||||
},
|
||||
{
|
||||
prop: 'effective_time',
|
||||
@@ -500,10 +488,15 @@
|
||||
|
||||
// ========== 行操作 ==========
|
||||
|
||||
const goDetail = (row: H5PopupConfiguration) => {
|
||||
router.push({
|
||||
name: 'H5PopupConfigurationDetail',
|
||||
params: { id: String(row.id) }
|
||||
})
|
||||
}
|
||||
|
||||
const getActions = (row: H5PopupConfiguration) => {
|
||||
const actions: any[] = [
|
||||
{ label: '详情', handler: () => openDetailDialog(row), type: 'primary' }
|
||||
]
|
||||
const actions: any[] = []
|
||||
if (canUpdate.value) {
|
||||
actions.push({ label: '编辑', handler: () => openEditDialog(row) })
|
||||
}
|
||||
@@ -555,33 +548,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 详情 ==========
|
||||
|
||||
const detailDialogVisible = ref(false)
|
||||
const detailLoading = ref(false)
|
||||
const detail = ref<H5PopupConfiguration | null>(null)
|
||||
|
||||
const openDetailDialog = async (row: H5PopupConfiguration) => {
|
||||
detail.value = null
|
||||
detailDialogVisible.value = true
|
||||
detailLoading.value = true
|
||||
try {
|
||||
const res = await H5PopupConfigurationService.getConfiguration(row.id)
|
||||
if (res.code === 0 && res.data) {
|
||||
detail.value = res.data
|
||||
} else {
|
||||
ElMessage.error(res.msg || '获取配置详情失败')
|
||||
detailDialogVisible.value = false
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取运营弹窗配置详情失败:', error)
|
||||
ElMessage.error(normalizeApiError(error).message || '获取配置详情失败')
|
||||
detailDialogVisible.value = false
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 创建 / 编辑 ==========
|
||||
|
||||
const formDialogVisible = ref(false)
|
||||
@@ -593,19 +559,21 @@
|
||||
|
||||
const emptyForm = (): {
|
||||
id: number
|
||||
popup_type: H5PopupType
|
||||
title: string
|
||||
content: string
|
||||
pages: H5PopupPage[]
|
||||
priority: number
|
||||
frequency: H5PopupFrequency
|
||||
enabled: boolean
|
||||
action_type: H5PopupActionType
|
||||
action_type: H5PopupActionType | ''
|
||||
shop_ids: number[]
|
||||
device_types: string[]
|
||||
card_types: H5PopupCardType[]
|
||||
timeRange: string[]
|
||||
} => ({
|
||||
id: 0,
|
||||
popup_type: 'promotion',
|
||||
title: '',
|
||||
content: '',
|
||||
pages: [],
|
||||
@@ -672,6 +640,7 @@
|
||||
}
|
||||
|
||||
const formRules: FormRules = {
|
||||
popup_type: [{ required: true, message: '请选择弹窗类型', trigger: 'change' }],
|
||||
title: [
|
||||
{ required: true, message: '请输入弹窗标题', trigger: 'blur' },
|
||||
{ min: 1, max: 100, message: '弹窗标题长度为 1~100 字符', trigger: 'blur' }
|
||||
@@ -720,13 +689,14 @@
|
||||
formMode.value = 'edit'
|
||||
Object.assign(form, {
|
||||
id: row.id,
|
||||
popup_type: row.popup_type,
|
||||
title: row.title,
|
||||
content: row.content,
|
||||
pages: [...(row.pages || [])],
|
||||
priority: row.priority,
|
||||
frequency: row.frequency,
|
||||
enabled: row.enabled,
|
||||
action_type: (row.action_type || '') as H5PopupActionType,
|
||||
action_type: row.action_type || '',
|
||||
shop_ids: [...(row.shop_ids || [])],
|
||||
device_types: [...(row.device_types || [])],
|
||||
card_types: [...(row.card_types || [])],
|
||||
@@ -741,6 +711,7 @@
|
||||
if (!(await formRef.value?.validate().catch(() => false))) return
|
||||
formLoading.value = true
|
||||
const payload = {
|
||||
popup_type: form.popup_type,
|
||||
title: form.title.trim(),
|
||||
content: form.content.trim(),
|
||||
pages: [...form.pages],
|
||||
@@ -749,14 +720,16 @@
|
||||
starts_at: form.timeRange[0],
|
||||
ends_at: form.timeRange[1],
|
||||
enabled: form.enabled,
|
||||
action_type: form.action_type,
|
||||
shop_ids: [...form.shop_ids],
|
||||
device_types: [...form.device_types],
|
||||
card_types: [...form.card_types]
|
||||
}
|
||||
try {
|
||||
if (formMode.value === 'create') {
|
||||
const res = await H5PopupConfigurationService.createConfiguration(payload)
|
||||
const res = await H5PopupConfigurationService.createConfiguration({
|
||||
...payload,
|
||||
action_type: form.action_type || null
|
||||
})
|
||||
if (res.code === 0 && res.data) {
|
||||
ElMessage.success('创建成功')
|
||||
formDialogVisible.value = false
|
||||
@@ -767,7 +740,8 @@
|
||||
} else {
|
||||
const res = await H5PopupConfigurationService.updateConfiguration(form.id, {
|
||||
id: form.id,
|
||||
...payload
|
||||
...payload,
|
||||
action_type: form.action_type
|
||||
})
|
||||
if (res.code === 0 && res.data) {
|
||||
ElMessage.success(
|
||||
@@ -796,15 +770,4 @@
|
||||
.h5-popup-configuration-page {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.detail-loading {
|
||||
padding: 24px 0;
|
||||
text-align: center;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.detail-content {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user