8fdf0b1(R3) 基于 a13e380 却用旧工作区副本覆盖了 R2 域文件,导致终版
(feat/r1-catalog) 上 R2 功能丢失。本提交在不改动 R1/R3 域文件的前提下恢复:
- 整文件恢复(纯 R2 域):diy/index.tsx+scss(批次①②③全部修正)、
stickerEdit(批次③)、api/address.ts(region 转换收口)、
store/design.ts+address.ts(缓存层语义文档)、address 页(真机验收版)
- 手工合并:api/design.ts(R2 契约实现为基底 + R3 需要的 fetchDesign)、
types/index.ts(DesignDataV1.category 收窄 {id,mask,tone}、productIcon
optional、AddressItem.createdAt 恢复;保留 R1 ProductCategory 扩展与
R3 OrderItem 扩展)、designList 页(缓存优先 load + processing 徽标)
- 保留不动(其他链路域):checkout/orders/orderDetail/shop/index/profile、
api/order.ts、api/product.ts、productAdapter、request.ts(R3 构建期注入)、
keys.ts(R3 mock 处理)、product 页(R1 已实现等价服务端写入)
验证:build:weapp 通过;tsc 错误集合与恢复前对比,R1/R3 文件零变化。
Co-Authored-By: Claude <noreply@anthropic.com>
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
/**
|
|
* 设计清单本地存储 —— R2 后降级为「离线兜底缓存」层(按 openid 隔离,见 keys.ts)。
|
|
* 真实 CRUD 已走 utils/api/design.ts;本层职责:
|
|
* - 页面 API 成功 → 回写缓存,供冷启动先展示与未迁移页面(checkout 等)读取;
|
|
* - API 失败/断网 → 页面读缓存正常浏览;
|
|
* - 联网刷新以服务端为准覆盖缓存,旧本地数据不做自动合并(route-r2 风险节:默认忽略)。
|
|
*/
|
|
import Taro from '@tarojs/taro'
|
|
import type { DesignItem } from '../../types'
|
|
import { assetUrl } from '../asset'
|
|
import { PRODUCT_ICON_MAP } from '../productConfig'
|
|
import { key, keyFor } from './keys'
|
|
|
|
/** 跨用户读取指定 openid 的设计清单(账号管理用) */
|
|
export function getDesignListFor(openid: string): DesignItem[] {
|
|
try { return Taro.getStorageSync(keyFor('design_list', openid)) || [] } catch { return [] }
|
|
}
|
|
|
|
// ---------- 设计清单 ----------
|
|
|
|
export function getDesignList(): DesignItem[] {
|
|
try { return Taro.getStorageSync(key('design_list')) || [] } catch { return [] }
|
|
}
|
|
|
|
export function setDesignList(list: DesignItem[]) {
|
|
Taro.setStorageSync(key('design_list'), list)
|
|
}
|
|
|
|
export function addDesign(product: any, count: number): DesignItem {
|
|
const list = getDesignList()
|
|
const iconImg = assetUrl(product?.iconImg || PRODUCT_ICON_MAP[product?.id] || '/icon/四角星.svg')
|
|
const item: DesignItem = {
|
|
id: 'DSG' + Date.now(),
|
|
productId: product.id,
|
|
productName: product.name,
|
|
productIcon: iconImg,
|
|
unitPrice: product.price,
|
|
count,
|
|
status: 'undesigned',
|
|
createdAt: new Date().toISOString().slice(0, 10)
|
|
}
|
|
setDesignList([...list, item])
|
|
return item
|
|
}
|
|
|
|
export function updateDesign(id: string, patch: Partial<DesignItem>) {
|
|
const list = getDesignList()
|
|
const idx = list.findIndex(d => d.id === id)
|
|
if (idx === -1) return
|
|
list[idx] = { ...list[idx], ...patch }
|
|
setDesignList(list)
|
|
}
|
|
|
|
/** 批量删除设计条目 */
|
|
export function removeDesigns(ids: string[]) {
|
|
const list = getDesignList().filter(d => !ids.includes(d.id))
|
|
setDesignList(list)
|
|
}
|
|
|
|
/** 根据ID删除单条设计 */
|
|
export function removeDesign(id: string) {
|
|
const list = getDesignList().filter(d => d.id !== id)
|
|
setDesignList(list)
|
|
}
|