fix: some
This commit is contained in:
810
src/views/settings/h5-popup-configuration/index.vue
Normal file
810
src/views/settings/h5-popup-configuration/index.vue
Normal file
@@ -0,0 +1,810 @@
|
||||
<template>
|
||||
<ArtTableFullScreen>
|
||||
<div class="h5-popup-configuration-page" id="table-full-screen">
|
||||
<ArtSearchBar
|
||||
v-model:filter="searchForm"
|
||||
:items="searchFormItems"
|
||||
label-width="110"
|
||||
:show-expand="false"
|
||||
@reset="handleReset"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
|
||||
<ElCard shadow="never" class="art-table-card">
|
||||
<ArtTableHeader
|
||||
:columnList="columnOptions"
|
||||
v-model:columns="columnChecks"
|
||||
@refresh="handleRefresh"
|
||||
>
|
||||
<template #actions>
|
||||
<ElButton v-if="canCreate" type="primary" :icon="Plus" @click="openCreateDialog">
|
||||
新增配置
|
||||
</ElButton>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
<ArtTable
|
||||
:loading="loading"
|
||||
:data="configurationList"
|
||||
:currentPage="pagination.page"
|
||||
:pageSize="pagination.pageSize"
|
||||
:total="pagination.total"
|
||||
:marginTop="10"
|
||||
:actions="getActions"
|
||||
:actionsWidth="200"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
>
|
||||
<template #default>
|
||||
<ElTableColumn v-for="col in columns" :key="col.prop || col.type" v-bind="col" />
|
||||
</template>
|
||||
</ArtTable>
|
||||
</ElCard>
|
||||
</div>
|
||||
|
||||
<!-- 创建 / 编辑 -->
|
||||
<ElDialog
|
||||
v-model="formDialogVisible"
|
||||
:title="formMode === 'create' ? '新增运营弹窗配置' : '编辑运营弹窗配置'"
|
||||
width="680px"
|
||||
:close-on-click-modal="false"
|
||||
destroy-on-close
|
||||
@closed="resetForm"
|
||||
>
|
||||
<ElForm ref="formRef" :model="form" :rules="formRules" label-width="110px">
|
||||
<ElFormItem label="弹窗标题" prop="title">
|
||||
<ElInput
|
||||
v-model="form.title"
|
||||
maxlength="100"
|
||||
show-word-limit
|
||||
placeholder="请输入弹窗标题(1~100 字符)"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="弹窗正文" prop="content">
|
||||
<ElInput
|
||||
v-model="form.content"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
maxlength="2000"
|
||||
show-word-limit
|
||||
placeholder="请输入弹窗正文(1~2000 字符,不接受 HTML、URL 或前端路由)"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="命中页面" prop="pages">
|
||||
<ElCheckboxGroup v-model="form.pages">
|
||||
<ElCheckbox v-for="item in PAGE_OPTIONS" :key="item.value" :label="item.value">
|
||||
{{ item.label }}
|
||||
</ElCheckbox>
|
||||
</ElCheckboxGroup>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="投放频率" prop="frequency">
|
||||
<ElSelect v-model="form.frequency" placeholder="请选择投放频率" style="width: 100%">
|
||||
<ElOption
|
||||
v-for="item in FREQUENCY_OPTIONS"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="生效时间" prop="timeRange">
|
||||
<ElDatePicker
|
||||
v-model="form.timeRange"
|
||||
type="datetimerange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始时间"
|
||||
end-placeholder="结束时间"
|
||||
value-format="YYYY-MM-DDTHH:mm:ssZ"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="优先级" prop="priority">
|
||||
<ElInputNumber
|
||||
v-model="form.priority"
|
||||
:min="0"
|
||||
:max="1000000"
|
||||
:controls="false"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="是否启用" prop="enabled">
|
||||
<ElSwitch v-model="form.enabled" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="受控动作" prop="action_type">
|
||||
<ElSelect v-model="form.action_type" placeholder="无" style="width: 100%">
|
||||
<ElOption
|
||||
v-for="item in ACTION_TYPE_OPTIONS"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="店铺范围" prop="shop_ids">
|
||||
<ElSelect
|
||||
v-model="form.shop_ids"
|
||||
multiple
|
||||
filterable
|
||||
remote
|
||||
:remote-method="searchShops"
|
||||
:loading="shopLoading"
|
||||
placeholder="选择店铺(不选表示全量投放)"
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption
|
||||
v-for="shop in shopOptions"
|
||||
:key="shop.id"
|
||||
:label="shop.shop_name"
|
||||
:value="shop.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="设备类型范围" prop="device_types">
|
||||
<ElSelect
|
||||
v-model="form.device_types"
|
||||
multiple
|
||||
filterable
|
||||
allow-create
|
||||
default-first-option
|
||||
placeholder="选择或输入设备类型(不选表示全量投放)"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="卡类型范围" prop="card_types">
|
||||
<ElSelect
|
||||
v-model="form.card_types"
|
||||
multiple
|
||||
filterable
|
||||
placeholder="选择卡类型(不选表示全量投放)"
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in CARD_TYPE_OPTIONS"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<ElButton @click="formDialogVisible = false">取消</ElButton>
|
||||
<ElButton type="primary" :loading="formLoading" @click="handleSubmit">
|
||||
{{ formMode === 'create' ? '创建' : '保存' }}
|
||||
</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 { ElMessage, ElMessageBox, ElTag, FormInstance, FormRules } from 'element-plus'
|
||||
import { Plus } from '@element-plus/icons-vue'
|
||||
import { H5PopupConfigurationService, ShopService } from '@/api/modules'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { useCheckedColumns } from '@/composables/useCheckedColumns'
|
||||
import { formatDateTime } from '@/utils/business/format'
|
||||
import { normalizeApiError } from '@/utils/business/apiError'
|
||||
import { AUGUST_PERMISSIONS } from '@/config/constants'
|
||||
import type { SearchFormItem } from '@/types'
|
||||
import type {
|
||||
H5PopupActionType,
|
||||
H5PopupCardType,
|
||||
H5PopupConfiguration,
|
||||
H5PopupFrequency,
|
||||
H5PopupPage
|
||||
} from '@/types/api'
|
||||
|
||||
defineOptions({ name: 'H5PopupConfiguration' })
|
||||
|
||||
const { hasAuth } = useAuth()
|
||||
const perms = AUGUST_PERMISSIONS.h5PopupConfiguration
|
||||
|
||||
const canCreate = computed(() => hasAuth(perms.create))
|
||||
const canUpdate = computed(() => hasAuth(perms.update))
|
||||
const canEnable = computed(() => hasAuth(perms.enable))
|
||||
const canDisable = computed(() => hasAuth(perms.disable))
|
||||
|
||||
const PAGE_NAMES: Record<H5PopupPage, string> = {
|
||||
home: '首页',
|
||||
asset_detail: '资产详情',
|
||||
package_purchase: '套餐购买',
|
||||
asset_wallet_recharge: '资产钱包充值'
|
||||
}
|
||||
const PAGE_OPTIONS: Array<{ label: string; value: H5PopupPage }> = [
|
||||
{ label: '首页', value: 'home' },
|
||||
{ label: '资产详情', value: 'asset_detail' },
|
||||
{ label: '套餐购买', value: 'package_purchase' },
|
||||
{ label: '资产钱包充值', value: 'asset_wallet_recharge' }
|
||||
]
|
||||
const FREQUENCY_NAMES: Record<H5PopupFrequency, string> = {
|
||||
once: '每客户每配置版本仅一次',
|
||||
daily: '每客户每配置版本每个上海自然日一次'
|
||||
}
|
||||
const FREQUENCY_OPTIONS: Array<{ label: string; value: H5PopupFrequency }> = [
|
||||
{ label: '仅一次(每配置版本)', value: 'once' },
|
||||
{ label: '每个上海自然日一次(每配置版本)', value: 'daily' }
|
||||
]
|
||||
const ACTION_TYPE_NAMES: Record<string, string> = {
|
||||
'': '无',
|
||||
package_purchase: '套餐购买',
|
||||
asset_wallet_recharge: '资产钱包充值'
|
||||
}
|
||||
const ACTION_TYPE_OPTIONS: Array<{ label: string; value: string }> = [
|
||||
{ label: '无', value: '' },
|
||||
{ label: '套餐购买', value: 'package_purchase' },
|
||||
{ label: '资产钱包充值', value: 'asset_wallet_recharge' }
|
||||
]
|
||||
const CARD_TYPE_NAMES: Record<H5PopupCardType, string> = {
|
||||
CMCC: '中国移动',
|
||||
CUCC: '中国联通',
|
||||
CTCC: '中国电信',
|
||||
CBN: '中国广电'
|
||||
}
|
||||
const CARD_TYPE_OPTIONS: Array<{ label: string; value: H5PopupCardType }> = [
|
||||
{ label: '中国移动', value: 'CMCC' },
|
||||
{ label: '中国联通', value: 'CUCC' },
|
||||
{ label: '中国电信', value: 'CTCC' },
|
||||
{ label: '中国广电', value: 'CBN' }
|
||||
]
|
||||
|
||||
const loading = ref(false)
|
||||
const configurationList = ref<H5PopupConfiguration[]>([])
|
||||
const pagination = reactive({ page: 1, pageSize: 20, total: 0 })
|
||||
|
||||
const initialSearchState = {
|
||||
enabled: undefined as number | undefined
|
||||
}
|
||||
const searchForm = reactive({ ...initialSearchState })
|
||||
|
||||
const statusOptions = [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '停用', value: 0 }
|
||||
]
|
||||
const searchFormItems: SearchFormItem[] = [
|
||||
{
|
||||
label: '启停状态',
|
||||
prop: 'enabled',
|
||||
type: 'select',
|
||||
config: { clearable: true, placeholder: '全部' },
|
||||
options: () => statusOptions
|
||||
}
|
||||
]
|
||||
|
||||
const columnOptions = [
|
||||
{ label: '标题', prop: 'title' },
|
||||
{ label: '命中页面', prop: 'pages' },
|
||||
{ label: '范围', prop: 'scope' },
|
||||
{ label: '优先级', prop: 'priority' },
|
||||
{ label: '频率', prop: 'frequency_text' },
|
||||
{ label: '启停状态', prop: 'enabled' },
|
||||
{ label: '受控动作', prop: 'action_type' },
|
||||
{ label: '生效时间', prop: 'effective_time' },
|
||||
{ label: '版本', prop: 'version' },
|
||||
{ label: '创建人', prop: 'creator' },
|
||||
{ label: '最近更新人', prop: 'updater' },
|
||||
{ label: '最近更新时间', prop: 'updated_at' }
|
||||
]
|
||||
|
||||
const formatPages = (pages: H5PopupPage[] | null | undefined): string => {
|
||||
if (!pages || pages.length === 0) return '全部'
|
||||
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('、')
|
||||
}
|
||||
|
||||
const formatScopeColumn = (row: H5PopupConfiguration): string => {
|
||||
const parts: string[] = []
|
||||
parts.push(`店铺:${row.shop_ids?.length ? `${row.shop_ids.length}家` : '全部'}`)
|
||||
parts.push(
|
||||
`设备:${
|
||||
row.device_types?.length
|
||||
? row.device_types.slice(0, 3).join('、') + (row.device_types.length > 3 ? ' 等' : '')
|
||||
: '全部'
|
||||
}`
|
||||
)
|
||||
parts.push(`卡型:${formatCardTypes(row.card_types)}`)
|
||||
return parts.join(';')
|
||||
}
|
||||
|
||||
const { columnChecks, columns } = useCheckedColumns(() => [
|
||||
{ prop: 'title', label: '标题', minWidth: 180, showOverflowTooltip: true },
|
||||
{
|
||||
prop: 'pages',
|
||||
label: '命中页面',
|
||||
minWidth: 180,
|
||||
showOverflowTooltip: true,
|
||||
formatter: (row: H5PopupConfiguration) => formatPages(row.pages)
|
||||
},
|
||||
{
|
||||
prop: 'scope',
|
||||
label: '范围',
|
||||
minWidth: 200,
|
||||
showOverflowTooltip: true,
|
||||
formatter: (row: H5PopupConfiguration) => formatScopeColumn(row)
|
||||
},
|
||||
{ prop: 'priority', label: '优先级', width: 90 },
|
||||
{
|
||||
prop: 'frequency_text',
|
||||
label: '频率',
|
||||
minWidth: 150,
|
||||
showOverflowTooltip: true,
|
||||
formatter: (row: H5PopupConfiguration) =>
|
||||
row.frequency_text || FREQUENCY_NAMES[row.frequency] || row.frequency
|
||||
},
|
||||
{
|
||||
prop: 'enabled',
|
||||
label: '启停状态',
|
||||
width: 90,
|
||||
formatter: (row: H5PopupConfiguration) =>
|
||||
h(
|
||||
ElTag,
|
||||
{ type: row.enabled ? 'success' : 'info' },
|
||||
() => row.enabled_text || (row.enabled ? '启用' : '停用')
|
||||
)
|
||||
},
|
||||
{
|
||||
prop: 'action_type',
|
||||
label: '受控动作',
|
||||
width: 120,
|
||||
formatter: (row: H5PopupConfiguration) => ACTION_TYPE_NAMES[row.action_type] || '无'
|
||||
},
|
||||
{
|
||||
prop: 'effective_time',
|
||||
label: '生效时间',
|
||||
minWidth: 170,
|
||||
formatter: (row: H5PopupConfiguration) =>
|
||||
`${formatDateTime(row.starts_at)} ~ ${formatDateTime(row.ends_at)}`
|
||||
},
|
||||
{ prop: 'version', label: '版本', width: 70 },
|
||||
{
|
||||
prop: 'creator',
|
||||
label: '创建人',
|
||||
width: 90,
|
||||
formatter: (row: H5PopupConfiguration) => String(row.creator || 0)
|
||||
},
|
||||
{
|
||||
prop: 'updater',
|
||||
label: '最近更新人',
|
||||
width: 110,
|
||||
formatter: (row: H5PopupConfiguration) => String(row.updater || 0)
|
||||
},
|
||||
{
|
||||
prop: 'updated_at',
|
||||
label: '最近更新时间',
|
||||
minWidth: 170,
|
||||
formatter: (row: H5PopupConfiguration) => formatDateTime(row.updated_at)
|
||||
}
|
||||
])
|
||||
|
||||
// ========== 列表数据 ==========
|
||||
|
||||
const getTableData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await H5PopupConfigurationService.getConfigurations({
|
||||
page: pagination.page,
|
||||
page_size: pagination.pageSize,
|
||||
enabled:
|
||||
searchForm.enabled === undefined || searchForm.enabled === null
|
||||
? undefined
|
||||
: searchForm.enabled === 1
|
||||
})
|
||||
if (res.code === 0 && res.data) {
|
||||
configurationList.value = res.data.items || []
|
||||
pagination.total = res.data.total || 0
|
||||
} else {
|
||||
ElMessage.error(res.msg || '获取运营弹窗配置列表失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取运营弹窗配置列表失败:', error)
|
||||
ElMessage.error(normalizeApiError(error).message || '获取运营弹窗配置列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleReset = () => {
|
||||
Object.assign(searchForm, { ...initialSearchState })
|
||||
pagination.page = 1
|
||||
getTableData()
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
pagination.page = 1
|
||||
getTableData()
|
||||
}
|
||||
|
||||
const handleRefresh = () => {
|
||||
getTableData()
|
||||
}
|
||||
|
||||
const handleSizeChange = (pageSize: number) => {
|
||||
pagination.pageSize = pageSize
|
||||
getTableData()
|
||||
}
|
||||
|
||||
const handleCurrentChange = (page: number) => {
|
||||
pagination.page = page
|
||||
getTableData()
|
||||
}
|
||||
|
||||
const refreshRow = (updated: H5PopupConfiguration) => {
|
||||
const index = configurationList.value.findIndex((item) => item.id === updated.id)
|
||||
if (index >= 0) {
|
||||
configurationList.value.splice(index, 1, updated)
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 行操作 ==========
|
||||
|
||||
const getActions = (row: H5PopupConfiguration) => {
|
||||
const actions: any[] = [
|
||||
{ label: '详情', handler: () => openDetailDialog(row), type: 'primary' }
|
||||
]
|
||||
if (canUpdate.value) {
|
||||
actions.push({ label: '编辑', handler: () => openEditDialog(row) })
|
||||
}
|
||||
if (canEnable.value && !row.enabled) {
|
||||
actions.push({ label: '启用', handler: () => handleEnable(row), type: 'success' })
|
||||
}
|
||||
if (canDisable.value && row.enabled) {
|
||||
actions.push({ label: '停用', handler: () => handleDisable(row), type: 'danger' })
|
||||
}
|
||||
return actions
|
||||
}
|
||||
|
||||
const handleEnable = async (row: H5PopupConfiguration) => {
|
||||
try {
|
||||
const res = await H5PopupConfigurationService.enableConfiguration(row.id)
|
||||
if (res.code === 0 && res.data) {
|
||||
refreshRow(res.data)
|
||||
ElMessage.success('启用后参与候选匹配')
|
||||
} else {
|
||||
ElMessage.error(res.msg || '启用失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('启用运营弹窗配置失败:', error)
|
||||
ElMessage.error(normalizeApiError(error).message || '启用失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleDisable = async (row: H5PopupConfiguration) => {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
'停用后停止新投放,历史通知在展示期内仍可见。确认停用该配置吗?',
|
||||
'停用确认',
|
||||
{ type: 'warning', confirmButtonText: '确认停用', cancelButtonText: '取消' }
|
||||
)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await H5PopupConfigurationService.disableConfiguration(row.id)
|
||||
if (res.code === 0 && res.data) {
|
||||
refreshRow(res.data)
|
||||
ElMessage.success('停用后停止新投放,历史通知在展示期内仍可见')
|
||||
} else {
|
||||
ElMessage.error(res.msg || '停用失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('停用运营弹窗配置失败:', error)
|
||||
ElMessage.error(normalizeApiError(error).message || '停用失败')
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 详情 ==========
|
||||
|
||||
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)
|
||||
const formLoading = ref(false)
|
||||
const formMode = ref<'create' | 'edit'>('create')
|
||||
const formRef = ref<FormInstance>()
|
||||
const shopOptions = ref<Array<{ id: number; shop_name: string }>>([])
|
||||
const shopLoading = ref(false)
|
||||
|
||||
const emptyForm = (): {
|
||||
id: number
|
||||
title: string
|
||||
content: string
|
||||
pages: H5PopupPage[]
|
||||
priority: number
|
||||
frequency: H5PopupFrequency
|
||||
enabled: boolean
|
||||
action_type: H5PopupActionType
|
||||
shop_ids: number[]
|
||||
device_types: string[]
|
||||
card_types: H5PopupCardType[]
|
||||
timeRange: string[]
|
||||
} => ({
|
||||
id: 0,
|
||||
title: '',
|
||||
content: '',
|
||||
pages: [],
|
||||
priority: 0,
|
||||
frequency: 'once',
|
||||
enabled: true,
|
||||
action_type: '',
|
||||
shop_ids: [],
|
||||
device_types: [],
|
||||
card_types: [],
|
||||
timeRange: []
|
||||
})
|
||||
|
||||
const form = reactive(emptyForm())
|
||||
|
||||
const resetForm = () => {
|
||||
Object.assign(form, emptyForm())
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
const toPickerTime = (iso: string): string => {
|
||||
if (!iso) return ''
|
||||
const date = new Date(iso)
|
||||
if (Number.isNaN(date.getTime())) return iso
|
||||
const pad = (value: number) => String(value).padStart(2, '0')
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(
|
||||
date.getHours()
|
||||
)}:${pad(date.getMinutes())}:${pad(date.getSeconds())}+08:00`
|
||||
}
|
||||
|
||||
const searchShops = async (query: string = '') => {
|
||||
shopLoading.value = true
|
||||
try {
|
||||
const res = await ShopService.getShops({
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
shop_name: query || undefined
|
||||
})
|
||||
if (res.code === 0) {
|
||||
shopOptions.value = res.data.items || []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('搜索店铺失败:', error)
|
||||
} finally {
|
||||
shopLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadShopNames = async (ids: number[]) => {
|
||||
const missing = ids.filter((id) => !shopOptions.value.some((shop) => shop.id === id))
|
||||
if (missing.length === 0) return
|
||||
await Promise.all(
|
||||
missing.slice(0, 50).map(async (id) => {
|
||||
try {
|
||||
const res = await ShopService.getShops({ id, page: 1, page_size: 1 })
|
||||
if (res.code === 0 && res.data.items?.length) {
|
||||
shopOptions.value = [...shopOptions.value, res.data.items[0]]
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取店铺信息失败:', error)
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
const formRules: FormRules = {
|
||||
title: [
|
||||
{ required: true, message: '请输入弹窗标题', trigger: 'blur' },
|
||||
{ min: 1, max: 100, message: '弹窗标题长度为 1~100 字符', trigger: 'blur' }
|
||||
],
|
||||
content: [
|
||||
{ required: true, message: '请输入弹窗正文', trigger: 'blur' },
|
||||
{ min: 1, max: 2000, message: '弹窗正文长度为 1~2000 字符', trigger: 'blur' }
|
||||
],
|
||||
pages: [
|
||||
{
|
||||
validator: (_rule, value: H5PopupPage[], callback) => {
|
||||
if (!value || value.length === 0) callback(new Error('请至少选择一个命中页面'))
|
||||
else callback()
|
||||
},
|
||||
trigger: 'change'
|
||||
}
|
||||
],
|
||||
frequency: [{ required: true, message: '请选择投放频率', trigger: 'change' }],
|
||||
timeRange: [
|
||||
{
|
||||
validator: (_rule, value: string[] | null, callback) => {
|
||||
if (!value || value.length !== 2) {
|
||||
callback(new Error('请选择生效时间'))
|
||||
return
|
||||
}
|
||||
if (new Date(value[1]).getTime() < new Date(value[0]).getTime()) {
|
||||
callback(new Error('生效结束时间不得早于开始时间'))
|
||||
return
|
||||
}
|
||||
callback()
|
||||
},
|
||||
trigger: 'change'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const openCreateDialog = () => {
|
||||
formMode.value = 'create'
|
||||
resetForm()
|
||||
formDialogVisible.value = true
|
||||
shopOptions.value = []
|
||||
searchShops('')
|
||||
}
|
||||
|
||||
const openEditDialog = async (row: H5PopupConfiguration) => {
|
||||
formMode.value = 'edit'
|
||||
Object.assign(form, {
|
||||
id: row.id,
|
||||
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,
|
||||
shop_ids: [...(row.shop_ids || [])],
|
||||
device_types: [...(row.device_types || [])],
|
||||
card_types: [...(row.card_types || [])],
|
||||
timeRange: [toPickerTime(row.starts_at), toPickerTime(row.ends_at)]
|
||||
})
|
||||
formDialogVisible.value = true
|
||||
shopOptions.value = []
|
||||
await Promise.all([searchShops(''), loadShopNames(form.shop_ids)])
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!(await formRef.value?.validate().catch(() => false))) return
|
||||
formLoading.value = true
|
||||
const payload = {
|
||||
title: form.title.trim(),
|
||||
content: form.content.trim(),
|
||||
pages: [...form.pages],
|
||||
priority: form.priority,
|
||||
frequency: form.frequency,
|
||||
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)
|
||||
if (res.code === 0 && res.data) {
|
||||
ElMessage.success('创建成功')
|
||||
formDialogVisible.value = false
|
||||
getTableData()
|
||||
} else {
|
||||
ElMessage.error(res.msg || '创建失败')
|
||||
}
|
||||
} else {
|
||||
const res = await H5PopupConfigurationService.updateConfiguration(form.id, {
|
||||
id: form.id,
|
||||
...payload
|
||||
})
|
||||
if (res.code === 0 && res.data) {
|
||||
ElMessage.success(
|
||||
'保存成功:每次更新版本递增,旧版本通知保留原快照,新版本可向原命中客户按频率重新投放一次'
|
||||
)
|
||||
formDialogVisible.value = false
|
||||
getTableData()
|
||||
} else {
|
||||
ElMessage.error(res.msg || '保存失败')
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存运营弹窗配置失败:', error)
|
||||
ElMessage.error(normalizeApiError(error).message || '保存失败')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getTableData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.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>
|
||||
@@ -15,7 +15,7 @@
|
||||
@refresh="loadMerchants"
|
||||
>
|
||||
<template #left>
|
||||
<ElButton v-if="canManage" type="primary" :icon="Plus" @click="showCreateDrawer">
|
||||
<ElButton v-if="canCreateMerchant" type="primary" :icon="Plus" @click="showCreateDrawer">
|
||||
新增支付商户
|
||||
</ElButton>
|
||||
</template>
|
||||
@@ -31,7 +31,7 @@
|
||||
:total="pagination.total"
|
||||
:marginTop="10"
|
||||
:actions="getActions"
|
||||
:actionsWidth="160"
|
||||
:actionsWidth="120"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
>
|
||||
@@ -48,7 +48,7 @@
|
||||
destroy-on-close
|
||||
@closed="clearSensitiveForm"
|
||||
>
|
||||
<ElForm ref="formRef" :model="form" :rules="formRules" label-width="120px">
|
||||
<ElForm ref="formRef" :model="form" :rules="formRules" label-width="100px">
|
||||
<ElFormItem label="商户名称" prop="name">
|
||||
<ElInput v-model="form.name" maxlength="100" placeholder="请输入商户名称" />
|
||||
</ElFormItem>
|
||||
@@ -146,6 +146,32 @@
|
||||
</div>
|
||||
</div>
|
||||
<ElButton type="primary" plain :icon="Plus" @click="addCredential">添加凭证字段</ElButton>
|
||||
<template v-if="form.provider_type === 'wechat_v2'">
|
||||
<ElDivider content-position="left">退款专用可选凭证(原路退款)</ElDivider>
|
||||
<div class="refund-credential-fields">
|
||||
<ElFormItem label="客户端证书内容">
|
||||
<ElInput
|
||||
:model-value="refundCredentialValue('wx_client_cert_content')"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="选填,PEM 格式客户端证书内容(仅原路退款需要)"
|
||||
@update:model-value="setRefundCredentialValue('wx_client_cert_content', $event)"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="客户端私钥内容">
|
||||
<ElInput
|
||||
:model-value="refundCredentialValue('wx_client_key_content')"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="选填,PEM 格式客户端私钥内容(仅原路退款需要)"
|
||||
@update:model-value="setRefundCredentialValue('wx_client_key_content', $event)"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
<div v-if="refundCredentialIncomplete" class="credential-tip">
|
||||
提示:仅填写证书或私钥其一,该商户暂不可用于原路退款,不影响支付/查单/回调。
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="credentialError" class="field-error" role="alert">
|
||||
{{ credentialError }}
|
||||
</div>
|
||||
@@ -156,7 +182,7 @@
|
||||
<ElButton
|
||||
type="primary"
|
||||
:loading="submitLoading"
|
||||
:disabled="!canManage"
|
||||
:disabled="formMode === 'create' ? !canCreateMerchant : !canEditMerchant"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
@@ -174,7 +200,8 @@
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { PaymentMerchantPoolsService } from '@/api/modules'
|
||||
import { useCheckedColumns } from '@/composables/useCheckedColumns'
|
||||
import { usePermission } from '@/composables/usePermission'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { PAYMENT_MERCHANT_POOL_PERMISSIONS } from '@/config/constants/paymentMerchantPools'
|
||||
import type { SearchFormItem } from '@/types/component'
|
||||
import {
|
||||
PAYMENT_METHOD_OPTIONS,
|
||||
@@ -198,16 +225,24 @@
|
||||
|
||||
type FilterVo = string | number | undefined | null | unknown[]
|
||||
|
||||
const { isPlatformAccount } = usePermission()
|
||||
const router = useRouter()
|
||||
const canManage = computed(() => isPlatformAccount.value)
|
||||
const { hasAuth } = useAuth()
|
||||
|
||||
const canCreateMerchant = computed(() =>
|
||||
hasAuth(PAYMENT_MERCHANT_POOL_PERMISSIONS.merchantCreate)
|
||||
)
|
||||
const canEditMerchant = computed(() => hasAuth(PAYMENT_MERCHANT_POOL_PERMISSIONS.merchantEdit))
|
||||
const canToggleMerchant = computed(() =>
|
||||
hasAuth(PAYMENT_MERCHANT_POOL_PERMISSIONS.merchantToggle)
|
||||
)
|
||||
const canDeleteMerchant = computed(() =>
|
||||
hasAuth(PAYMENT_MERCHANT_POOL_PERMISSIONS.merchantDelete)
|
||||
)
|
||||
const canViewMerchantDetail = computed(() =>
|
||||
hasAuth(PAYMENT_MERCHANT_POOL_PERMISSIONS.merchantDetail)
|
||||
)
|
||||
|
||||
const handleNameClick = (row: PaymentMerchant) => {
|
||||
if (!canManage.value) {
|
||||
ElMessage.warning('您没有查看支付商户详情的权限')
|
||||
return
|
||||
}
|
||||
|
||||
router.push({
|
||||
path: `${RoutesAlias.PaymentMerchantPoolsDetail}/${row.id}`
|
||||
})
|
||||
@@ -262,17 +297,19 @@
|
||||
minWidth: 180,
|
||||
showOverflowTooltip: true,
|
||||
formatter: (row: PaymentMerchant) =>
|
||||
h(
|
||||
'span',
|
||||
{
|
||||
style: 'color: var(--el-color-primary); cursor: pointer; text-decoration: underline;',
|
||||
onClick: (event: MouseEvent) => {
|
||||
event.stopPropagation()
|
||||
handleNameClick(row)
|
||||
}
|
||||
},
|
||||
row.name
|
||||
)
|
||||
canViewMerchantDetail.value
|
||||
? h(
|
||||
'span',
|
||||
{
|
||||
style: 'color: var(--el-color-primary); cursor: pointer; text-decoration: underline;',
|
||||
onClick: (event: MouseEvent) => {
|
||||
event.stopPropagation()
|
||||
handleNameClick(row)
|
||||
}
|
||||
},
|
||||
row.name
|
||||
)
|
||||
: row.name
|
||||
},
|
||||
{
|
||||
label: '支付方式',
|
||||
@@ -322,7 +359,6 @@
|
||||
|
||||
// 列表加载
|
||||
const loadMerchants = async () => {
|
||||
if (!canManage.value) return
|
||||
loading.value = true
|
||||
try {
|
||||
const params: PaymentMerchantQueryParams = {
|
||||
@@ -458,7 +494,7 @@
|
||||
}
|
||||
|
||||
const showCreateDrawer = () => {
|
||||
if (!canManage.value) return
|
||||
if (!canCreateMerchant.value) return
|
||||
Object.assign(form, initialFormState())
|
||||
credentialTemplateKeys.value = []
|
||||
formDrawerVisible.value = true
|
||||
@@ -468,7 +504,7 @@
|
||||
}
|
||||
|
||||
const startCredentialReplacement = () => {
|
||||
if (!canManage.value) return
|
||||
if (!canEditMerchant.value) return
|
||||
form.credentials = []
|
||||
if (credentialTemplateKeys.value.length > 0) {
|
||||
form.credentials = credentialTemplateKeys.value.map((key) => ({
|
||||
@@ -490,6 +526,33 @@
|
||||
form.credentials.splice(index, 1)
|
||||
}
|
||||
|
||||
const refundCredentialValue = (key: string): string => {
|
||||
return form.credentials.find((entry) => entry.key === key)?.value || ''
|
||||
}
|
||||
|
||||
const setRefundCredentialValue = (key: string, value: string) => {
|
||||
const index = form.credentials.findIndex((entry) => entry.key === key)
|
||||
const trimmed = value.trim()
|
||||
if (index >= 0) {
|
||||
if (trimmed) {
|
||||
form.credentials[index].value = trimmed
|
||||
} else {
|
||||
form.credentials.splice(index, 1)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (trimmed) {
|
||||
form.credentials.push({ localId: generateLocalId(), key, value: trimmed })
|
||||
}
|
||||
}
|
||||
|
||||
const refundCredentialIncomplete = computed(() => {
|
||||
if (form.provider_type !== 'wechat_v2') return false
|
||||
const cert = refundCredentialValue('wx_client_cert_content')
|
||||
const key = refundCredentialValue('wx_client_key_content')
|
||||
return Boolean(cert) !== Boolean(key)
|
||||
})
|
||||
|
||||
const handlePaymentMethodChange = (value: PaymentMerchantMethod) => {
|
||||
form.payment_method = value
|
||||
const firstMatch = PAYMENT_PROVIDER_OPTIONS.find((option) => option.paymentMethod === value)
|
||||
@@ -499,7 +562,7 @@
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!canManage.value) return
|
||||
if (formMode.value === 'create' ? !canCreateMerchant.value : !canEditMerchant.value) return
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
@@ -532,6 +595,9 @@
|
||||
})
|
||||
ElMessage.success('支付凭证更新成功')
|
||||
}
|
||||
if (refundCredentialIncomplete.value) {
|
||||
ElMessage.warning('该商户退款凭证不完整,不可用于原路退款(不影响支付/查单/回调)')
|
||||
}
|
||||
formDrawerVisible.value = false
|
||||
clearSensitiveForm()
|
||||
await loadMerchants()
|
||||
@@ -565,7 +631,7 @@
|
||||
const tableRef = ref()
|
||||
|
||||
const openEditDrawer = async (id: number) => {
|
||||
if (!canManage.value) return
|
||||
if (!canEditMerchant.value) return
|
||||
try {
|
||||
const res = await PaymentMerchantPoolsService.getPaymentMerchantById(id)
|
||||
if (res.code !== 0) return
|
||||
@@ -589,7 +655,7 @@
|
||||
}
|
||||
|
||||
const toggleEnabled = async (merchant: PaymentMerchant) => {
|
||||
if (!canManage.value) return
|
||||
if (!canToggleMerchant.value) return
|
||||
const target = !merchant.enabled
|
||||
const action = target ? '启用' : '停用'
|
||||
try {
|
||||
@@ -613,7 +679,7 @@
|
||||
}
|
||||
|
||||
const confirmDeleteMerchant = async (merchant: PaymentMerchant) => {
|
||||
if (!canManage.value) return
|
||||
if (!canDeleteMerchant.value) return
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确认删除支付商户 “${merchant.name}”?该操作不可恢复。`,
|
||||
@@ -642,26 +708,24 @@
|
||||
label: '编辑',
|
||||
type: 'primary' as const,
|
||||
handler: () => openEditDrawer(row.id),
|
||||
permission: canManage.value ? '' : 'hidden'
|
||||
permission: canEditMerchant.value ? '' : 'hidden'
|
||||
},
|
||||
{
|
||||
label: row.enabled ? '停用' : '启用',
|
||||
type: 'primary' as const,
|
||||
handler: () => toggleEnabled(row),
|
||||
permission: canManage.value ? '' : 'hidden'
|
||||
permission: canToggleMerchant.value ? '' : 'hidden'
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'danger' as const,
|
||||
handler: () => confirmDeleteMerchant(row),
|
||||
permission: canManage.value ? '' : 'hidden'
|
||||
permission: canDeleteMerchant.value ? '' : 'hidden'
|
||||
}
|
||||
]
|
||||
|
||||
onMounted(() => {
|
||||
if (canManage.value) {
|
||||
loadMerchants()
|
||||
}
|
||||
loadMerchants()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
@@ -700,6 +764,13 @@
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.refund-credential-fields {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.field-error {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
@refresh="loadPools"
|
||||
>
|
||||
<template #left>
|
||||
<ElButton v-if="canManage" type="primary" :icon="Plus" @click="showCreateDrawer">
|
||||
<ElButton v-if="canCreatePool" type="primary" :icon="Plus" @click="showCreateDrawer">
|
||||
新增商户池
|
||||
</ElButton>
|
||||
</template>
|
||||
@@ -31,7 +31,7 @@
|
||||
:total="pagination.total"
|
||||
:marginTop="10"
|
||||
:actions="getActions"
|
||||
:actionsWidth="220"
|
||||
:actionsWidth="120"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
>
|
||||
@@ -195,7 +195,7 @@
|
||||
<ElButton
|
||||
type="primary"
|
||||
:loading="submitLoading"
|
||||
:disabled="!canManage"
|
||||
:disabled="formMode === 'create' ? !canCreatePool : !canEditPool"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
@@ -214,7 +214,8 @@
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { PaymentMerchantPoolsService } from '@/api/modules'
|
||||
import { useCheckedColumns } from '@/composables/useCheckedColumns'
|
||||
import { usePermission } from '@/composables/usePermission'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { PAYMENT_MERCHANT_POOL_PERMISSIONS } from '@/config/constants/paymentMerchantPools'
|
||||
import type { SearchFormItem } from '@/types/component'
|
||||
import {
|
||||
PAYMENT_METHOD_OPTIONS,
|
||||
@@ -239,16 +240,15 @@
|
||||
|
||||
type FilterVo = string | number | undefined | null | unknown[]
|
||||
|
||||
const { isPlatformAccount } = usePermission()
|
||||
const router = useRouter()
|
||||
const canManage = computed(() => isPlatformAccount.value)
|
||||
const { hasAuth } = useAuth()
|
||||
|
||||
const canCreatePool = computed(() => hasAuth(PAYMENT_MERCHANT_POOL_PERMISSIONS.poolCreate))
|
||||
const canEditPool = computed(() => hasAuth(PAYMENT_MERCHANT_POOL_PERMISSIONS.poolEdit))
|
||||
const canTogglePool = computed(() => hasAuth(PAYMENT_MERCHANT_POOL_PERMISSIONS.poolToggle))
|
||||
const canViewPoolDetail = computed(() => hasAuth(PAYMENT_MERCHANT_POOL_PERMISSIONS.poolDetail))
|
||||
|
||||
const handleNameClick = (row: PaymentMerchantPool) => {
|
||||
if (!canManage.value) {
|
||||
ElMessage.warning('您没有查看商户池详情的权限')
|
||||
return
|
||||
}
|
||||
|
||||
router.push({ path: `${RoutesAlias.PaymentMerchantPoolDetail}/${row.id}` })
|
||||
}
|
||||
|
||||
@@ -282,17 +282,19 @@
|
||||
minWidth: 180,
|
||||
showOverflowTooltip: true,
|
||||
formatter: (row: PaymentMerchantPool) =>
|
||||
h(
|
||||
'span',
|
||||
{
|
||||
style: 'color: var(--el-color-primary); cursor: pointer; text-decoration: underline;',
|
||||
onClick: (event: MouseEvent) => {
|
||||
event.stopPropagation()
|
||||
handleNameClick(row)
|
||||
}
|
||||
},
|
||||
row.name
|
||||
)
|
||||
canViewPoolDetail.value
|
||||
? h(
|
||||
'span',
|
||||
{
|
||||
style: 'color: var(--el-color-primary); cursor: pointer; text-decoration: underline;',
|
||||
onClick: (event: MouseEvent) => {
|
||||
event.stopPropagation()
|
||||
handleNameClick(row)
|
||||
}
|
||||
},
|
||||
row.name
|
||||
)
|
||||
: row.name
|
||||
},
|
||||
{
|
||||
label: '支付方式',
|
||||
@@ -357,7 +359,6 @@
|
||||
}
|
||||
|
||||
const loadPools = async () => {
|
||||
if (!canManage.value) return
|
||||
loading.value = true
|
||||
try {
|
||||
const params = {
|
||||
@@ -674,7 +675,7 @@
|
||||
}
|
||||
|
||||
const showCreateDrawer = async () => {
|
||||
if (!canManage.value) return
|
||||
if (!canCreatePool.value) return
|
||||
Object.assign(form, initialFormState())
|
||||
formDrawerVisible.value = true
|
||||
formMode.value = 'create'
|
||||
@@ -682,7 +683,7 @@
|
||||
}
|
||||
|
||||
const openEditDrawer = async (pool: PaymentMerchantPool) => {
|
||||
if (!canManage.value) return
|
||||
if (!canEditPool.value) return
|
||||
await loadAvailableMerchants(pool.payment_method)
|
||||
Object.assign(form, initialFormState(), {
|
||||
id: pool.id,
|
||||
@@ -711,7 +712,7 @@
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!canManage.value) return
|
||||
if (formMode.value === 'create' ? !canCreatePool.value : !canEditPool.value) return
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
@@ -741,7 +742,7 @@
|
||||
const tableRef = ref()
|
||||
|
||||
const toggleEnabled = async (pool: PaymentMerchantPool) => {
|
||||
if (!canManage.value) return
|
||||
if (!canTogglePool.value) return
|
||||
const target = !pool.enabled
|
||||
const action = target ? '启用' : '停用'
|
||||
try {
|
||||
@@ -769,20 +770,18 @@
|
||||
label: '编辑',
|
||||
type: 'primary' as const,
|
||||
handler: () => openEditDrawer(row),
|
||||
permission: canManage.value ? '' : 'hidden'
|
||||
permission: canEditPool.value ? '' : 'hidden'
|
||||
},
|
||||
{
|
||||
label: row.enabled ? '停用' : '启用',
|
||||
type: 'primary' as const,
|
||||
handler: () => toggleEnabled(row),
|
||||
permission: canManage.value ? '' : 'hidden'
|
||||
permission: canTogglePool.value ? '' : 'hidden'
|
||||
}
|
||||
]
|
||||
|
||||
onMounted(() => {
|
||||
if (canManage.value) {
|
||||
loadPools()
|
||||
}
|
||||
loadPools()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="wechat-authorization-management">
|
||||
<ElCard v-if="canManage" shadow="never" class="art-table-card">
|
||||
<ElCard v-if="canEditWechatAuth" shadow="never" class="art-table-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span class="card-title">微信授权配置</span>
|
||||
@@ -93,7 +93,8 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { PaymentMerchantPoolsService } from '@/api/modules'
|
||||
import { usePermission } from '@/composables/usePermission'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import { PAYMENT_MERCHANT_POOL_PERMISSIONS } from '@/config/constants/paymentMerchantPools'
|
||||
import type {
|
||||
UpdateWechatAuthorizationRequest,
|
||||
WechatAuthorizationConfig
|
||||
@@ -101,8 +102,10 @@
|
||||
|
||||
defineOptions({ name: 'WechatAuthorizationManagement' })
|
||||
|
||||
const { isPlatformAccount } = usePermission()
|
||||
const canManage = computed(() => isPlatformAccount.value)
|
||||
const { hasAuth } = useAuth()
|
||||
const canEditWechatAuth = computed(() =>
|
||||
hasAuth(PAYMENT_MERCHANT_POOL_PERMISSIONS.wechatAuthEdit)
|
||||
)
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const submitLoading = ref(false)
|
||||
@@ -139,7 +142,6 @@
|
||||
})
|
||||
|
||||
const loadConfig = async () => {
|
||||
if (!canManage.value) return
|
||||
try {
|
||||
const res = await PaymentMerchantPoolsService.getWechatAuthorization()
|
||||
if (res.code === 0) {
|
||||
@@ -151,7 +153,7 @@
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!canManage.value) return
|
||||
if (!canEditWechatAuth.value) return
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
@@ -201,7 +203,7 @@
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (canManage.value) {
|
||||
if (canEditWechatAuth.value) {
|
||||
loadConfig()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -215,6 +215,16 @@
|
||||
label: '支付密钥',
|
||||
prop: 'wx_key_content',
|
||||
formatter: (value) => getPaymentConfigStatus(value)
|
||||
},
|
||||
{
|
||||
label: '客户端证书内容',
|
||||
prop: 'wx_client_cert_content',
|
||||
formatter: (value) => getPaymentConfigStatus(value)
|
||||
},
|
||||
{
|
||||
label: '客户端私钥内容',
|
||||
prop: 'wx_client_key_content',
|
||||
formatter: (value) => getPaymentConfigStatus(value)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -288,6 +288,28 @@
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
<ElRow :gutter="20">
|
||||
<ElCol :span="12">
|
||||
<ElFormItem label="客户端证书内容" prop="wx_client_cert_content">
|
||||
<ElInput
|
||||
v-model="form.wx_client_cert_content"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="选填,PEM 格式客户端证书内容,仅原路退款需要"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
<ElCol :span="12">
|
||||
<ElFormItem label="客户端私钥内容" prop="wx_client_key_content">
|
||||
<ElInput
|
||||
v-model="form.wx_client_key_content"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="选填,PEM 格式客户端私钥内容,仅原路退款需要"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
</ElRow>
|
||||
</template>
|
||||
|
||||
<template v-if="form.provider_type === 'fuiou'">
|
||||
@@ -405,6 +427,8 @@
|
||||
wx_serial_no: string
|
||||
wx_cert_content: string
|
||||
wx_key_content: string
|
||||
wx_client_cert_content: string
|
||||
wx_client_key_content: string
|
||||
ali_app_id: string
|
||||
ali_private_key: string
|
||||
ali_public_key: string
|
||||
@@ -448,6 +472,8 @@
|
||||
'wx_api_v3_key',
|
||||
'wx_cert_content',
|
||||
'wx_key_content',
|
||||
'wx_client_cert_content',
|
||||
'wx_client_key_content',
|
||||
'ali_private_key',
|
||||
'ali_public_key',
|
||||
'fy_private_key',
|
||||
@@ -486,6 +512,8 @@
|
||||
wx_serial_no: '',
|
||||
wx_cert_content: '',
|
||||
wx_key_content: '',
|
||||
wx_client_cert_content: '',
|
||||
wx_client_key_content: '',
|
||||
ali_app_id: '',
|
||||
ali_private_key: '',
|
||||
ali_public_key: '',
|
||||
|
||||
@@ -65,6 +65,10 @@
|
||||
<ElOption label="退款审批" value="refund_approval" />
|
||||
<ElOption label="线下代充值审批" value="offline_recharge_approval" />
|
||||
<ElOption label="员工代收款审批" value="employee_collection_approval" />
|
||||
|
||||
<ElOption label="代理扫码分销注册审批" value="agent_distribution_approval" />
|
||||
<ElOption label="提现资料资格审批" value="withdrawal_qualification_approval" />
|
||||
<ElOption label="佣金提现终审" value="commission_withdrawal_approval" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElCol>
|
||||
|
||||
Reference in New Issue
Block a user