const NEWS_DETAIL_CACHE_PREFIX = 'news_detail_payload_'

/** 列表进详情前写入完整条目，避免 query 长度截断简介等字段 */
export function putNewsDetailPayload(payload) {
  const key = NEWS_DETAIL_CACHE_PREFIX + Date.now() + '_' + Math.random().toString(36).slice(2, 10)
  try {
    uni.setStorageSync(key, payload || {})
  } catch (e) {
    return ''
  }
  return key
}

export function takeNewsDetailPayload(cacheKey) {
  if (!cacheKey) {
    return null
  }
  try {
    const data = uni.getStorageSync(cacheKey)
    uni.removeStorageSync(cacheKey)
    return data && typeof data === 'object' ? data : null
  } catch (e) {
    return null
  }
}
