修改完善这个专利部分

This commit is contained in:
super
2026-05-15 16:06:12 +08:00
parent e4e01c1686
commit 14db1e0cb1
45 changed files with 2842 additions and 2554 deletions
@@ -1680,31 +1680,6 @@ export function getAppearancePatentResultDownloadUrl(resultId: number) {
// ========== 货源查询 ==========
export interface ProductCategoryItemVo {
id: number;
parentId?: number | null;
name: string;
categoryKey?: string;
sortOrder?: number;
description?: string;
isBuiltin?: boolean;
childCount?: number;
level?: number;
path?: string;
children?: ProductCategoryItemVo[];
}
export interface ProductCategoryListVo {
tree: ProductCategoryItemVo[];
items: ProductCategoryItemVo[];
}
export function listProductCategories() {
return unwrapJavaResponse(
get<JavaApiResponse<ProductCategoryListVo>>(`${JAVA_API_PREFIX}/admin/product-categories`),
);
}
export interface SimilarAsinFilterConditionVo {
id: number;
conditionText: string;
@@ -1,4 +1,4 @@
export type ApiSecretModuleKey = 'appearance-patent' | 'similar-asin'
type LegacyApiSecretModuleKey = 'appearance-patent' | 'similar-asin'
export type ApiSecretRetention = 'session' | '1d' | '7d' | '30d' | 'forever'
@@ -18,17 +18,19 @@ export type ApiSecretSnapshot = {
}
const STORAGE_PREFIX = 'brand:api-secret'
const COMMON_SECRET_KEY = 'common'
const LEGACY_SECRET_KEYS: LegacyApiSecretModuleKey[] = ['appearance-patent', 'similar-asin']
function currentUserStorageId() {
if (typeof window === 'undefined') return '0'
return window.localStorage.getItem('uid') || '0'
}
function buildStorageKey(moduleKey: ApiSecretModuleKey) {
function buildStorageKey(moduleKey: string) {
return `${STORAGE_PREFIX}:${currentUserStorageId()}:${moduleKey}`
}
function readStorageRecord(storage: Storage, moduleKey: ApiSecretModuleKey): ApiSecretRecord | null {
function readStorageRecord(storage: Storage, moduleKey: string): ApiSecretRecord | null {
const raw = storage.getItem(buildStorageKey(moduleKey))
if (!raw) return null
try {
@@ -81,11 +83,11 @@ function isExpired(record: ApiSecretRecord) {
return record.expiresAt != null && record.expiresAt <= Date.now()
}
function clearStorageRecord(storage: Storage, moduleKey: ApiSecretModuleKey) {
function clearStorageRecord(storage: Storage, moduleKey: string) {
storage.removeItem(buildStorageKey(moduleKey))
}
function getLiveRecord(moduleKey: ApiSecretModuleKey): ApiSecretRecord | null {
function getLiveRecordFromKey(moduleKey: string): ApiSecretRecord | null {
if (typeof window === 'undefined') return null
const sessionRecord = readStorageRecord(window.sessionStorage, moduleKey)
@@ -102,12 +104,42 @@ function getLiveRecord(moduleKey: ApiSecretModuleKey): ApiSecretRecord | null {
return localRecord
}
export function getStoredApiSecret(moduleKey: ApiSecretModuleKey) {
return getLiveRecord(moduleKey)?.value || ''
function clearLegacyStoredApiSecrets() {
if (typeof window === 'undefined') return
for (const moduleKey of LEGACY_SECRET_KEYS) {
clearStorageRecord(window.sessionStorage, moduleKey)
clearStorageRecord(window.localStorage, moduleKey)
}
}
export function getStoredApiSecretSnapshot(moduleKey: ApiSecretModuleKey): ApiSecretSnapshot {
const record = getLiveRecord(moduleKey)
function migrateLegacyRecord(record: ApiSecretRecord) {
if (typeof window === 'undefined') return
const storage = record.retention === 'session' ? window.sessionStorage : window.localStorage
storage.setItem(buildStorageKey(COMMON_SECRET_KEY), JSON.stringify(record))
clearLegacyStoredApiSecrets()
}
function getLiveRecord(): ApiSecretRecord | null {
const commonRecord = getLiveRecordFromKey(COMMON_SECRET_KEY)
if (commonRecord) return commonRecord
for (const moduleKey of LEGACY_SECRET_KEYS) {
const legacyRecord = getLiveRecordFromKey(moduleKey)
if (legacyRecord) {
migrateLegacyRecord(legacyRecord)
return legacyRecord
}
}
return null
}
export function getStoredApiSecret() {
return getLiveRecord()?.value || ''
}
export function getStoredApiSecretSnapshot(): ApiSecretSnapshot {
const record = getLiveRecord()
if (!record) {
return {
value: '',
@@ -127,14 +159,13 @@ export function getStoredApiSecretSnapshot(moduleKey: ApiSecretModuleKey): ApiSe
}
export function saveStoredApiSecret(
moduleKey: ApiSecretModuleKey,
value: string,
retention: ApiSecretRetention,
) {
if (typeof window === 'undefined') return
const trimmedValue = value.trim()
clearStoredApiSecret(moduleKey)
clearStoredApiSecret()
if (!trimmedValue) return
const now = Date.now()
@@ -146,11 +177,12 @@ export function saveStoredApiSecret(
}
const storage = retention === 'session' ? window.sessionStorage : window.localStorage
storage.setItem(buildStorageKey(moduleKey), JSON.stringify(record))
storage.setItem(buildStorageKey(COMMON_SECRET_KEY), JSON.stringify(record))
}
export function clearStoredApiSecret(moduleKey: ApiSecretModuleKey) {
export function clearStoredApiSecret() {
if (typeof window === 'undefined') return
clearStorageRecord(window.sessionStorage, moduleKey)
clearStorageRecord(window.localStorage, moduleKey)
clearStorageRecord(window.sessionStorage, COMMON_SECRET_KEY)
clearStorageRecord(window.localStorage, COMMON_SECRET_KEY)
clearLegacyStoredApiSecrets()
}