feat: dynamic assets banner management trading closed message price source cathode label and accounting notes
This commit is contained in:
+55
-2
@@ -49,6 +49,8 @@ function parseLegacySlider(value: string | null | undefined): IBenefits[] {
|
||||
}
|
||||
}
|
||||
|
||||
export const ASSETS_BANNER_CONST_KEY = 'assets_banner'
|
||||
|
||||
export type AppBannersConstState = {
|
||||
/** فقط وقتی رکورد واقعاً با key=app_banners است؛ وگرنه null تا create شود */
|
||||
id: number | null
|
||||
@@ -71,6 +73,20 @@ async function loadLegacySliderInto(merged: AppBannersValue): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAssetsBannerInto(merged: AppBannersValue): Promise<void> {
|
||||
try {
|
||||
const res = await useAxios.get<Const | Const[]>(
|
||||
`/api/const/key/${ASSETS_BANNER_CONST_KEY}`
|
||||
)
|
||||
const row = pickConstRow(res)
|
||||
if (!row) return
|
||||
const items = parseLegacySlider(row.value)
|
||||
if (items.length) merged.assetsBanner = items
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
async function loadLegacyThemeBanners(): Promise<AppBannersValue> {
|
||||
try {
|
||||
const themeRes = await useAxios.get<Const | Const[]>(
|
||||
@@ -102,7 +118,7 @@ export async function loadAppBannersConst(): Promise<AppBannersConstState> {
|
||||
let healedFromLegacy = false
|
||||
|
||||
// رکورد پوچ app_banners روی URLهای واقعی legacy سایه نیندازد
|
||||
if (isThemeBannersEmpty(data) || !data.slider.length) {
|
||||
if (isThemeBannersEmpty(data) || !data.slider.length || !(data.assetsBanner ?? []).length) {
|
||||
const before = serializeAppBanners(data)
|
||||
if (isThemeBannersEmpty(data)) {
|
||||
const legacyTheme = await loadLegacyThemeBanners()
|
||||
@@ -111,6 +127,9 @@ export async function loadAppBannersConst(): Promise<AppBannersConstState> {
|
||||
if (!data.slider.length) {
|
||||
await loadLegacySliderInto(data)
|
||||
}
|
||||
if (!(data.assetsBanner ?? []).length) {
|
||||
await loadAssetsBannerInto(data)
|
||||
}
|
||||
healedFromLegacy = serializeAppBanners(data) !== before
|
||||
}
|
||||
|
||||
@@ -125,8 +144,9 @@ export async function loadAppBannersConst(): Promise<AppBannersConstState> {
|
||||
const legacyTheme = await loadLegacyThemeBanners()
|
||||
Object.assign(merged, mergeAppBannersFromLegacy(merged, legacyTheme))
|
||||
await loadLegacySliderInto(merged)
|
||||
await loadAssetsBannerInto(merged)
|
||||
|
||||
const hasLegacy = !isThemeBannersEmpty(merged) || merged.slider.length > 0
|
||||
const hasLegacy = !isThemeBannersEmpty(merged) || merged.slider.length > 0 || (merged.assetsBanner ?? []).length > 0
|
||||
return { id: null, data: merged, healedFromLegacy: hasLegacy }
|
||||
}
|
||||
|
||||
@@ -192,5 +212,38 @@ export async function saveAppBannersConst(
|
||||
console.error('همگامسازی header_banner ناموفق بود:', error)
|
||||
}
|
||||
|
||||
try {
|
||||
await syncAssetsBannerConst(data.assetsBanner ?? [])
|
||||
} catch (error) {
|
||||
console.error('همگامسازی assets_banner ناموفق بود:', error)
|
||||
}
|
||||
|
||||
return nextId
|
||||
}
|
||||
|
||||
export async function syncAssetsBannerConst(items: IBenefits[]): Promise<void> {
|
||||
const value = JSON.stringify(items ?? [])
|
||||
const payload = {
|
||||
key: ASSETS_BANNER_CONST_KEY,
|
||||
value,
|
||||
title_fa: 'بنر صفحه داراییها',
|
||||
is_active: true,
|
||||
description: 'بنر صفحهٔ داراییهای اپ مشتری (زیر نمودار)',
|
||||
}
|
||||
|
||||
try {
|
||||
const existingRes = await useAxios.get<Const | Const[]>(
|
||||
`/api/const/key/${ASSETS_BANNER_CONST_KEY}`
|
||||
)
|
||||
const existing = pickConstRow(existingRes)
|
||||
const existingId = existing?.id ?? existing?.const_id ?? null
|
||||
if (existingId) {
|
||||
await useAxios.put<Const>(`/admin/const/${existingId}`, { id: existingId, ...payload })
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
// create below
|
||||
}
|
||||
|
||||
await useAxios.post<Const>(`/admin/const`, { id: 0, ...payload })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user