fix(admin-jd): 类目计数未就绪时不画树,消掉首帧闪出别店快照树

首帧 /categories 还没回(categoryOptions 空)时,侧栏按回落快照把整棵服饰树
画了出来(徽标全 0、「全部商品 0」),计数到达后再收成「本店无匹配」一行——
用户看到的是「原本这样过一会变那样」。页面投影 categoryOptionsReady(失败回空
也算就绪),侧栏 catalogReady=false 时只留一行加载提示、总数显示「—」。

- props.categoriesReady 用 withDefaults 显式默认 true(Vue 把 Boolean 缺省强转
  false,不写默认值会让所有老调用点永远停在加载行)
- 判据:jd-category-sidebar.mount.test.ts +2(未就绪不画树/就绪后切出树与计数)
- 后管 node --test 1979 绿、vitest 253 绿、vue-tsc rc=0,快检四面绿
This commit is contained in:
2026-11-24 13:18:29 +08:00
parent 9538c1c646
commit 10fb52d0e9
3 changed files with 81 additions and 7 deletions
@@ -98,6 +98,10 @@ const ownerGroupId = ref(0)
const groupOptions = ref<JdProductGroup[]>([])
/** 类目计数行(京麦末级类目+商品数):侧栏商品目录树的徽标数据源;失败静默回空。 */
const categoryOptions = ref<JdProductCategoryOption[]>([])
/** 类目计数是否已取过(成功或失败回空都算就绪):侧栏据此区分「还没到」与「确实没有」,
* 首帧未就绪时不画树——否则先把回落快照的别店类目整棵树(徽标全 0、「全部商品 0」)
* 画出来,计数到达后再收成「本店无匹配」一行,用户会看到一次莫名的闪变。 */
const categoryOptionsReady = ref(false)
const detailItem = ref<JdProductItem | null>(null)
const detailVisible = ref(false)
/** 归类对话框(2026-17 替代下线的店铺分类弹窗,工具栏「归入分类」打开)。 */
@@ -386,6 +390,9 @@ async function loadCategoryOptions(): Promise<void> {
categoryOptions.value = await fetchJdProductCategories()
} catch {
categoryOptions.value = []
} finally {
// 失败也算就绪:回空=「确实没有类目」,不能永远停在加载行(否则整棵树下线)。
categoryOptionsReady.value = true
}
}
@@ -864,6 +871,7 @@ onMounted(async () => {
:selected-group-id="selectedGroupIdNum"
:selected-shop-name="filter.shopName"
:category-tree="activeCategoryTree"
:categories-ready="categoryOptionsReady"
@select-category="onSelectCategory"
@select-group="onSelectGroup"
@select-shop="onSelectShop"