fix(distribution): 修复分站跑马灯公告把配置 JSON 原文展示出来
分销站公告存在 distribution_sites.announcements_json 的是 { title, content } 对象数组
(分销后台品牌装修写入),而前台跑马灯组件按字符串数组渲染。Vue 对对象会做
JSON.stringify,配合 no-wrap 样式,前台就显示成
{"title":"天域商行专注AWM子弹回收、高比例!不排队!秒结算!","content":""}。
- 新增 shared/utils/announcements.ts:把公告条目归一化为展示文本,兼容纯文本、
{ title, content } 对象,以及被字符串化的对象(历史脏数据)与标题为空回退内容
- distributionSite store 解析 announcements_json 时归一化,跑马灯组件内部再兜底一次
- 首页配置 mergeHomeConfig 同样接受对象形态,主站/移动端公告入口口径统一
- 分销后台装修预览的跑马灯示例按同一口径取值(只有内容时不再空白)
- 补 9 条单测覆盖对象、字符串化对象、普通花括号文案、混排去重与空输入
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
import type { ApiResponse } from '@/shared/types/types'
|
||||
import { normalizeAnnouncements } from '@/shared/utils/announcements'
|
||||
|
||||
export interface DistributionBanner {
|
||||
image_url: string
|
||||
@@ -160,7 +161,9 @@ export const useDistributionSiteStore = defineStore('distributionSite', {
|
||||
|
||||
if (info.announcements_json) {
|
||||
try {
|
||||
this.announcements = JSON.parse(info.announcements_json)
|
||||
// 站点公告存的是 { title, content } 对象数组,跑马灯只认文本,必须先归一化,
|
||||
// 否则 Vue 会把对象 stringify 成 {"title":"…","content":""} 原文展示。
|
||||
this.announcements = normalizeAnnouncements(JSON.parse(info.announcements_json))
|
||||
} catch {
|
||||
this.announcements = []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user