operationPopup.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import request from '@/utils/request'
  2. const BASE = '/setting/operationPopup/v1'
  3. export type OperationPopupDisplayMode =
  4. | 'IMAGE_H'
  5. | 'IMAGE_V'
  6. | 'CARD'
  7. | 'COUPON_PACK'
  8. | 'ACTIVITY'
  9. const DISPLAY_MODE_VALUES: OperationPopupDisplayMode[] = [
  10. 'IMAGE_H',
  11. 'IMAGE_V',
  12. 'CARD',
  13. 'COUPON_PACK',
  14. 'ACTIVITY'
  15. ]
  16. /** 详情/列表 VO 归一化展示方式(兼容 display_mode、大小写) */
  17. export function resolveOperationPopupDisplayMode(raw: unknown): OperationPopupDisplayMode {
  18. if (raw == null || raw === '') return 'IMAGE_H'
  19. const normalized = String(raw).trim().toUpperCase()
  20. if (DISPLAY_MODE_VALUES.includes(normalized as OperationPopupDisplayMode)) {
  21. return normalized as OperationPopupDisplayMode
  22. }
  23. return 'IMAGE_H'
  24. }
  25. /** 解析 info 接口响应体(兼容 AjaxResult 与字段平铺) */
  26. export function unwrapOperationPopupVo(res: unknown): Record<string, any> {
  27. if (!res || typeof res !== 'object') return {}
  28. const root = res as Record<string, any>
  29. const data = root.data
  30. if (data && typeof data === 'object' && !Array.isArray(data)) {
  31. if (data.id != null || data.displayMode != null || data.display_mode != null || data.title != null) {
  32. return data
  33. }
  34. if (data.data && typeof data.data === 'object') {
  35. return data.data
  36. }
  37. }
  38. if (root.id != null || root.displayMode != null || root.display_mode != null) {
  39. return root
  40. }
  41. return {}
  42. }
  43. export const OPERATION_POPUP_DISPLAY_MODE_LABEL: Record<OperationPopupDisplayMode, string> = {
  44. IMAGE_H: '横版海报',
  45. IMAGE_V: '竖版纯图',
  46. CARD: '图文卡片',
  47. COUPON_PACK: '券包到账',
  48. ACTIVITY: '营销活动'
  49. }
  50. export function operationPopupDisplayModeLabel(raw: unknown): string {
  51. const mode = resolveOperationPopupDisplayMode(raw)
  52. return OPERATION_POPUP_DISPLAY_MODE_LABEL[mode]
  53. }
  54. export interface OperationPopupExtConfig {
  55. couponSource?: string
  56. templateIds?: string[]
  57. maxShow?: number
  58. moreText?: string
  59. moreLinkPath?: string
  60. ctaText?: string
  61. activityId?: string
  62. showCountdown?: boolean
  63. hideShellText?: boolean
  64. frequency?: string
  65. }
  66. export interface OperationPopupQueryVO {
  67. pageNo?: number
  68. pageSize?: number
  69. platform?: string
  70. status?: number
  71. title?: string
  72. }
  73. export interface OperationPopupSaveDTO {
  74. id?: string
  75. platform: string
  76. title?: string
  77. subtitle?: string
  78. displayMode?: OperationPopupDisplayMode
  79. extConfig?: string
  80. imageUrl?: string
  81. linkPath?: string
  82. closable: number
  83. displayBegin?: string
  84. displayEnd?: string
  85. sortOrder?: number
  86. status?: number
  87. }
  88. export function getOperationPopupInfo(id: string) {
  89. return request.get(`${BASE}/info`, { params: { id } })
  90. }
  91. export function getOperationPopupList(data: OperationPopupQueryVO) {
  92. return request.post(`${BASE}/list`, data)
  93. }
  94. export function saveOperationPopup(data: OperationPopupSaveDTO) {
  95. return request.post(`${BASE}/save`, data)
  96. }
  97. export function deleteOperationPopup(ids: string) {
  98. return request.get(`${BASE}/delete`, { params: { ids } })
  99. }