From 208583e14c56a9d7947ae96e9ac4e6d3965121ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Fri, 23 Oct 2026 21:56:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(common-tools):=20=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=8F=B0=E6=96=B0=E5=A2=9E=E5=B8=B8=E7=94=A8=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=88=86=E7=B1=BB=EF=BC=8C=E4=B8=89=E4=B8=AA=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=BD=91=E9=A1=B5=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tool-catalog 最前插入「常用工具」组(brand_common_tools,23 工具·4 大分类), 三工具各自权限键:pricing-calc / five-asin / keyword-share - /pricing-calc:站点(英 GBP÷9、德法 EUR÷8)+ 买货价/运费 → 营业额/利润/ 利润率/换算汇率,公式与精度照抄桌面版,纯函数 node --test 钉住 - /five-asin:五国常量 + ASIN 10 位校验 → 亚马逊商品链接,window.open 与 :href 出口全部过 safeHttpUrl(url-outlet 棘轮),邮编一键复制 - /keyword-share:筛选/四级类目级联/统计卡/表格分页 200/标记与取消使用/ 添加/删除/随机抽词/共享记录,对接 keywordshare 后端九端点 - 顶栏与 BrandTopBar 导航同步;router 注册三路由;补 test:mount 脚本 (vitest mount 套件入口,与后管同口径) --- frontend-vue/package.json | 3 +- .../src/pages/amazon/AmazonConsolePage.vue | 16 +- .../amazon/components/AmazonToolPageShell.vue | 3 +- .../pages/amazon/components/AmazonTopBar.vue | 8 +- frontend-vue/src/pages/amazon/tool-catalog.ts | 45 +- .../pages/brand/components/BrandTopBar.vue | 9 + .../src/pages/common/FiveAsinPage.vue | 306 ++++++ .../src/pages/common/KeywordSharePage.vue | 911 ++++++++++++++++++ .../src/pages/common/PricingCalcPage.vue | 342 +++++++ frontend-vue/src/pages/common/five-asin.ts | 55 ++ frontend-vue/src/pages/common/pricing-calc.ts | 95 ++ frontend-vue/src/router/index.ts | 16 + frontend-vue/src/shared/api/java-modules.ts | 1 + .../shared/api/types/modules/keyword-share.ts | 290 ++++++ .../tests/amazon-tool-catalog.test.ts | 49 +- frontend-vue/tests/five-asin.test.ts | 48 + .../mount/keyword-share-page.mount.test.ts | 160 +++ frontend-vue/tests/pricing-calc.test.ts | 84 ++ 18 files changed, 2424 insertions(+), 17 deletions(-) create mode 100644 frontend-vue/src/pages/common/FiveAsinPage.vue create mode 100644 frontend-vue/src/pages/common/KeywordSharePage.vue create mode 100644 frontend-vue/src/pages/common/PricingCalcPage.vue create mode 100644 frontend-vue/src/pages/common/five-asin.ts create mode 100644 frontend-vue/src/pages/common/pricing-calc.ts create mode 100644 frontend-vue/src/shared/api/types/modules/keyword-share.ts create mode 100644 frontend-vue/tests/five-asin.test.ts create mode 100644 frontend-vue/tests/mount/keyword-share-page.mount.test.ts create mode 100644 frontend-vue/tests/pricing-calc.test.ts diff --git a/frontend-vue/package.json b/frontend-vue/package.json index 50795ef1e..1123d4a9c 100644 --- a/frontend-vue/package.json +++ b/frontend-vue/package.json @@ -7,7 +7,8 @@ "dev": "vite --host --port 5173", "build": "vue-tsc --noEmit && vite build", "preview": "vite preview", - "test": "node --test --test-force-exit --test-timeout=180000 tests/*.test.ts" + "test": "node --test --test-force-exit --test-timeout=180000 tests/*.test.ts", + "test:mount": "vitest run" }, "dependencies": { "axios": "^1.13.6", diff --git a/frontend-vue/src/pages/amazon/AmazonConsolePage.vue b/frontend-vue/src/pages/amazon/AmazonConsolePage.vue index 8781f7773..c09a9ebed 100644 --- a/frontend-vue/src/pages/amazon/AmazonConsolePage.vue +++ b/frontend-vue/src/pages/amazon/AmazonConsolePage.vue @@ -12,15 +12,15 @@ 运营辅助 · 数据安全 · 高效跟价

让亚马逊运营,更清晰高效

- 从采集、去重、查品到上架跟价,20 个工具按「前端 · 运营 · 后勤」三线组织,每条工具一句话讲清用途,标准流程一步不缺。 + 从换算、查询、采集、去重到上架跟价,23 个工具按「常用 · 前端 · 运营 · 后勤」四线组织,每条工具一句话讲清用途,标准流程一步不缺。

- 20 + 23 个工具
- 3 + 4 大分类
@@ -128,7 +128,7 @@ import AmazonFooterBar from '@/pages/amazon/components/AmazonFooterBar.vue' import ToolIcon from '@/pages/amazon/components/ToolIcon.vue' import { TUTORIAL_DOWNLOAD_URL, resolveTutorialDownloadUrl } from '@/pages/amazon/download-btn' import { filterGroupsByPermission, filterWorkflowByPermission, TOOL_GROUPS, TOOL_MAP } from '@/pages/amazon/tool-catalog' -import type { ToolGroup, ToolInfo, VisibleGroup, WorkflowStep } from '@/pages/amazon/tool-catalog' +import type { ToolGroup, ToolGroupKey, ToolInfo, VisibleGroup, WorkflowStep } from '@/pages/amazon/tool-catalog' import { resolvePageHref } from '@/shared/page-prefix' import { isHttpUrl, safeHttpUrl } from '@/shared/utils/safe-url' import { prefetchRouteChunk } from '@/shared/route-prefetch' @@ -143,7 +143,7 @@ const visibleGroups = ref(TOOL_GROUPS.map((group) => ({ ...group const permissionUnavailable = ref(false) const statusText = ref('') const statusType = ref<'normal' | 'error'>('normal') -const activeCat = ref<'front' | 'ops' | 'logi'>('front') +const activeCat = ref('front') let statusTimer: number | undefined const currentGroup = computed(() => visibleGroups.value.find((g) => g.key === activeCat.value) ?? visibleGroups.value[0]) @@ -249,15 +249,15 @@ async function onDownloadClick() { window.open(safeHttpUrl(url), '_blank', 'noopener') } -function onCatChange(key: 'front' | 'ops' | 'logi') { +function onCatChange(key: ToolGroupKey) { activeCat.value = key history.replaceState(null, '', `#group-${key}`) } function parseHashGroup() { const hash = window.location.hash.replace('#', '') - const m = /^group-(front|ops|logi)$/.exec(hash) - if (m) activeCat.value = m[1] as 'front' | 'ops' | 'logi' + const m = /^group-(common|front|ops|logi)$/.exec(hash) + if (m) activeCat.value = m[1] as ToolGroupKey } onMounted(async () => { diff --git a/frontend-vue/src/pages/amazon/components/AmazonToolPageShell.vue b/frontend-vue/src/pages/amazon/components/AmazonToolPageShell.vue index 37db8307d..b150df5ed 100644 --- a/frontend-vue/src/pages/amazon/components/AmazonToolPageShell.vue +++ b/frontend-vue/src/pages/amazon/components/AmazonToolPageShell.vue @@ -35,6 +35,7 @@ import AmazonTopBar from '@/pages/amazon/components/AmazonTopBar.vue' import AmazonFooterBar from '@/pages/amazon/components/AmazonFooterBar.vue' import DownloadProgressPanel from '@/shared/components/DownloadProgressPanel.vue' import { TOOL_DETAILS, TOOL_GROUPS, TOOL_MAP } from '@/pages/amazon/tool-catalog' +import type { ToolGroupKey } from '@/pages/amazon/tool-catalog' import { resolvePageHref } from '@/shared/page-prefix' /** Aliprice 注册推广链接(对齐 gemini-code 工具页头 Aliprice 按钮) */ @@ -48,7 +49,7 @@ const props = defineProps<{ const tool = computed(() => TOOL_MAP.get(props.toolId)) const group = computed(() => TOOL_GROUPS.find((g) => g.tools.some((t) => t.id === props.toolId))) -const groupKey = computed(() => group.value?.key ?? 'front') +const groupKey = computed(() => group.value?.key ?? 'front') const detailText = computed(() => { if (!tool.value) return '' return TOOL_DETAILS[tool.value.id] ?? tool.value.desc diff --git a/frontend-vue/src/pages/amazon/components/AmazonTopBar.vue b/frontend-vue/src/pages/amazon/components/AmazonTopBar.vue index ac5f4f824..a9fccbe14 100644 --- a/frontend-vue/src/pages/amazon/components/AmazonTopBar.vue +++ b/frontend-vue/src/pages/amazon/components/AmazonTopBar.vue @@ -42,21 +42,21 @@ import { computed, onMounted, ref } from 'vue' import BrandApiSecretSettingsButton from '@/pages/brand/components/BrandApiSecretSettingsButton.vue' import NotificationBell from '@/shared/components/NotificationBell.vue' import { filterGroupsByPermission, TOOL_GROUPS } from '@/pages/amazon/tool-catalog' -import type { VisibleGroup } from '@/pages/amazon/tool-catalog' +import type { ToolGroupKey, VisibleGroup } from '@/pages/amazon/tool-catalog' import { resolvePageHref } from '@/shared/page-prefix' import { getCurrentUserAppColumnKeys } from '@/shared/api/permission' const props = withDefaults( defineProps<{ /** 当前工具所属分类(功能页高亮对应 tab;工具台首页不传) */ - activeCat?: 'front' | 'ops' | 'logi' + activeCat?: ToolGroupKey }>(), { activeCat: undefined, }, ) -const emit = defineEmits<{ change: [key: 'front' | 'ops' | 'logi'] }>() +const emit = defineEmits<{ change: [key: ToolGroupKey] }>() const activeCat = computed(() => props.activeCat) const visibleCats = ref(TOOL_GROUPS.map((group) => ({ ...group, tools: [...group.tools] }))) @@ -67,7 +67,7 @@ const toolbarHref = resolvePageHref('/new_web_source/amazon-console.html') /** 返回桌面入口首页(亚马逊/视频/图片入口) */ const homeHref = resolvePageHref('/new_web_source/home.html') -function onTabClick(key: 'front' | 'ops' | 'logi') { +function onTabClick(key: ToolGroupKey) { emit('change', key) } diff --git a/frontend-vue/src/pages/amazon/tool-catalog.ts b/frontend-vue/src/pages/amazon/tool-catalog.ts index 60f69129e..d69ce6a68 100644 --- a/frontend-vue/src/pages/amazon/tool-catalog.ts +++ b/frontend-vue/src/pages/amazon/tool-catalog.ts @@ -29,8 +29,11 @@ export type WorkflowStep = { toolId?: string } +/** 工具分组键(常用工具组排在最前) */ +export type ToolGroupKey = 'common' | 'front' | 'ops' | 'logi' + export type ToolGroup = { - key: 'front' | 'ops' | 'logi' + key: ToolGroupKey /** 菜单权限组键(与 BrandTopBar 一致) */ columnKey: string name: string @@ -48,6 +51,37 @@ export type ToolGroup = { } export const TOOL_GROUPS: ReadonlyArray = [ + { + key: 'common', + columnKey: 'brand_common_tools', + name: '常用工具', + desc: '换算 · 查询 · 词库共享,高频小工具', + color: '#F59E0B', + weak: '#3A2A10', + tools: [ + { + id: 'pricing-calc', + name: '定价利润换算', + desc: '输入售价、运费、成本,自动换算利润与毛利,多币种同步', + href: '/pricing-calc', + permissionKeys: ['pricing-calc'], + }, + { + id: 'five-asin', + name: '五国ASIN快速查询', + desc: '按国家输入ASIN,自动生成带邮编与汇率的链接,跳转谷歌直达', + href: '/five-asin', + permissionKeys: ['five-asin'], + }, + { + id: 'keyword-share', + name: '五国关键词共享', + desc: '词库跨账户共享、已使用标记、操作记录留痕,防重复使用', + href: '/keyword-share', + permissionKeys: ['keyword-share'], + }, + ], + }, { key: 'front', columnKey: 'brand_front_tools', @@ -260,6 +294,9 @@ export const TOOL_GROUPS: ReadonlyArray = [ /** 图标渐变背景(照 icons.py ICON_COLORS 转 CSS) */ export const TOOL_ICON_GRADIENTS: Record = { + 'pricing-calc': 'linear-gradient(180deg, #FCD34D, #F59E0B)', + 'five-asin': 'linear-gradient(180deg, #FDBA74, #F97316)', + 'keyword-share': 'linear-gradient(180deg, #86EFAC, #22C55E)', collect: 'linear-gradient(180deg, #5EEAD4, #14B8A6)', variant: 'linear-gradient(180deg, #93C5FD, #3B82F6)', dedupe: 'linear-gradient(180deg, #C4B5FD, #8B5CF6)', @@ -287,6 +324,12 @@ export const TOOL_ICON_GRADIENTS: Record = { * 默认描边 stroke:#fff width:3(方头 butt),实心填充 shape 用 .fill 标记 */ export const TOOL_ICON_SHAPES: Record = { + // 定价利润换算:计算器(屏+按键) + 'pricing-calc': '', + // 五国ASIN快速查询:地球+放大镜 + 'five-asin': '', + // 五国关键词共享:分享三节点 + 'keyword-share': '', // 采集数据:圆角方框+向下箭头 collect: '', // ASIN变体采集:两个重叠方框 diff --git a/frontend-vue/src/pages/brand/components/BrandTopBar.vue b/frontend-vue/src/pages/brand/components/BrandTopBar.vue index f90f922dc..32df1bf27 100644 --- a/frontend-vue/src/pages/brand/components/BrandTopBar.vue +++ b/frontend-vue/src/pages/brand/components/BrandTopBar.vue @@ -94,6 +94,15 @@ const showActions = props.showActions const allowedColumnKeys = ref([]) const navGroups: ReadonlyArray = [ + { + columnKey: 'brand_common_tools', + label: '常用工具', + items: [ + { key: 'pricing-calc', label: '定价利润换算', href: '/pricing-calc' }, + { key: 'five-asin', label: '五国ASIN快速查询', href: '/five-asin' }, + { key: 'keyword-share', label: '五国关键词共享', href: '/keyword-share' }, + ], + }, { columnKey: 'brand_front_tools', label: '前端工具', diff --git a/frontend-vue/src/pages/common/FiveAsinPage.vue b/frontend-vue/src/pages/common/FiveAsinPage.vue new file mode 100644 index 000000000..03f6411b4 --- /dev/null +++ b/frontend-vue/src/pages/common/FiveAsinPage.vue @@ -0,0 +1,306 @@ + + + + + diff --git a/frontend-vue/src/pages/common/KeywordSharePage.vue b/frontend-vue/src/pages/common/KeywordSharePage.vue new file mode 100644 index 000000000..f3767f11b --- /dev/null +++ b/frontend-vue/src/pages/common/KeywordSharePage.vue @@ -0,0 +1,911 @@ + + + + + diff --git a/frontend-vue/src/pages/common/PricingCalcPage.vue b/frontend-vue/src/pages/common/PricingCalcPage.vue new file mode 100644 index 000000000..b4ca63c9e --- /dev/null +++ b/frontend-vue/src/pages/common/PricingCalcPage.vue @@ -0,0 +1,342 @@ + + + + + diff --git a/frontend-vue/src/pages/common/five-asin.ts b/frontend-vue/src/pages/common/five-asin.ts new file mode 100644 index 000000000..6873736f6 --- /dev/null +++ b/frontend-vue/src/pages/common/five-asin.ts @@ -0,0 +1,55 @@ +/** + * 五国ASIN快速查询 · 纯逻辑(网页化桌面版五国ASIN工具)。 + * + * 五国站点数据写死为常量(域名 / 默认邮编 / 币种 / 国旗),与桌面版一致; + * ASIN 规范化:strip + 大写 + 去掉非字母数字,规范化后必须 10 位。 + * 桌面版的自动填邮编 / 切币种(Playwright 驱动 Chrome)网页版明确不做。 + * 本模块不依赖 Vue / DOM,供 node --test 直接单测。 + */ + +export interface FiveAsinCountry { + /** 站点代号(页面内部 key) */ + code: string + /** 国家显示名 */ + name: string + /** 国旗 emoji */ + flag: string + /** 亚马逊站点域名(不带协议) */ + domain: string + /** 默认邮编 */ + postcode: string + /** 邮编所在城市 */ + city: string + /** 币种代码 */ + currency: string +} + +export const FIVE_ASIN_COUNTRIES: ReadonlyArray = [ + { code: 'uk', name: '英国', flag: '🇬🇧', domain: 'www.amazon.co.uk', postcode: 'SW1A 1AA', city: '伦敦', currency: '英镑' }, + { code: 'de', name: '德国', flag: '🇩🇪', domain: 'www.amazon.de', postcode: '10115', city: '柏林', currency: '欧元' }, + { code: 'fr', name: '法国', flag: '🇫🇷', domain: 'www.amazon.fr', postcode: '75001', city: '巴黎', currency: '欧元' }, + { code: 'es', name: '西班牙', flag: '🇪🇸', domain: 'www.amazon.es', postcode: '28001', city: '马德里', currency: '欧元' }, + { code: 'it', name: '意大利', flag: '🇮🇹', domain: 'www.amazon.it', postcode: '20121', city: '米兰', currency: '欧元' }, +] + +export const FIVE_ASIN_COUNTRY_MAP: ReadonlyMap = new Map( + FIVE_ASIN_COUNTRIES.map((country) => [country.code, country] as const), +) + +/** ASIN 规范化:strip + 大写 + 去掉所有非字母数字字符 */ +export function normalizeAsin(raw: string): string { + return String(raw ?? '') + .trim() + .toUpperCase() + .replace(/[^A-Z0-9]/g, '') +} + +/** 规范化后的 ASIN 是否合法(必须恰好 10 位字母数字) */ +export function isValidAsin(asin: string): boolean { + return /^[A-Z0-9]{10}$/.test(String(asin ?? '')) +} + +/** 由站点域名与 ASIN 生成商品页地址:https://{domain}/dp/{asin} */ +export function buildAmazonProductUrl(domain: string, asin: string): string { + return `https://${domain}/dp/${asin}` +} diff --git a/frontend-vue/src/pages/common/pricing-calc.ts b/frontend-vue/src/pages/common/pricing-calc.ts new file mode 100644 index 000000000..e6613ceaf --- /dev/null +++ b/frontend-vue/src/pages/common/pricing-calc.ts @@ -0,0 +1,95 @@ +/** + * 定价利润换算 · 纯计算逻辑(网页化桌面版定价换算工具)。 + * + * 口径照抄桌面版:站点分 英国(英镑 GBP,换算除数 9)与 德国·法国(欧元 EUR,除数 8); + * 成本 = 买货价 + 运费;营业额 = 成本 ÷ 0.5;平台费 = 营业额 × 20%; + * 利润 = 营业额 − 成本 − 平台费;利润率 = 利润 ÷ 营业额;换算汇率 = 营业额 ÷ 除数。 + * + * 金额输入允许带货币符号(¥/¥)与千分位逗号,解析时先剥离再 parseFloat。 + * 本模块不依赖 Vue / DOM,供 node --test 直接单测。 + */ + +export type PricingStationKey = 'uk' | 'eu' + +export interface PricingStation { + key: PricingStationKey + /** 站点显示名 */ + name: string + /** 币种代码 */ + currency: string + /** 营业额反推外币单价的换算除数 */ + divisor: number +} + +export const PRICING_STATIONS: ReadonlyArray = [ + { key: 'uk', name: '英国', currency: 'GBP', divisor: 9 }, + { key: 'eu', name: '德国·法国', currency: 'EUR', divisor: 8 }, +] + +export const PRICING_STATION_MAP: ReadonlyMap = new Map( + PRICING_STATIONS.map((station) => [station.key, station] as const), +) + +/** 目标毛利率分母:营业额 = 成本 ÷ PROFIT_TARGET */ +const PROFIT_TARGET = 0.5 +/** 平台佣金比例:平台费 = 营业额 × PLATFORM_FEE_RATE */ +const PLATFORM_FEE_RATE = 0.2 + +/** + * 解析金额输入:剥离 ¥/¥/千分位逗号/空白后再 parseFloat。 + * 合法返回非负数值;空串、非纯数字(含尾部残渣如 12abc)、负数一律返回 null + * (由页面给出非法提示)。 + */ +export function parseMoneyInput(raw: string): number | null { + const text = String(raw ?? '') + .replace(/[¥¥,\s]/g, '') + .trim() + if (!text || !/^\d*\.?\d+$/.test(text)) return null + const value = Number.parseFloat(text) + if (!Number.isFinite(value) || value < 0) return null + return value +} + +export interface PricingResult { + /** 成本(买货价 + 运费) */ + cost: number + /** 营业额(成本 ÷ 0.5) */ + revenue: number + /** 平台费(营业额 × 20%) */ + platformFee: number + /** 利润(营业额 − 成本 − 平台费) */ + profit: number + /** 利润率(利润 ÷ 营业额;营业额为 0 时记 0) */ + profitRate: number + /** 换算汇率(营业额 ÷ 站点除数,反推外币单价) */ + converted: number +} + +/** 按站点口径换算利润(入参必须是已通过 parseMoneyInput 的非负数值) */ +export function calcPricing(purchasePrice: number, freight: number, station: PricingStation): PricingResult { + const cost = purchasePrice + freight + const revenue = cost / PROFIT_TARGET + const platformFee = revenue * PLATFORM_FEE_RATE + const profit = revenue - cost - platformFee + const profitRate = revenue > 0 ? profit / revenue : 0 + const converted = revenue / station.divisor + return { cost, revenue, platformFee, profit, profitRate, converted } +} + +/** 金额格式化:千分位 + 固定 2 位小数 */ +export function formatMoney(value: number): string { + return Number(value ?? 0).toLocaleString('en-US', { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }) +} + +/** 利润率格式化:百分比 + 固定 1 位小数 */ +export function formatProfitRate(value: number): string { + return `${(Number(value ?? 0) * 100).toFixed(1)}%` +} + +/** 换算汇率格式化:固定 4 位小数 */ +export function formatExchangeRate(value: number): string { + return Number(value ?? 0).toFixed(4) +} diff --git a/frontend-vue/src/router/index.ts b/frontend-vue/src/router/index.ts index 31cf587dc..bf0932919 100644 --- a/frontend-vue/src/router/index.ts +++ b/frontend-vue/src/router/index.ts @@ -122,6 +122,22 @@ const routes = [ name: 'withdraw', component: () => import('@/pages/brand/components/BrandWithdrawTab.vue'), }, + // ---- 常用工具(网页化的桌面小工具;权限键与 tool-catalog / BrandTopBar 一致)---- + { + path: '/pricing-calc', + name: 'pricing-calc', + component: () => import('@/pages/common/PricingCalcPage.vue'), + }, + { + path: '/five-asin', + name: 'five-asin', + component: () => import('@/pages/common/FiveAsinPage.vue'), + }, + { + path: '/keyword-share', + name: 'keyword-share', + component: () => import('@/pages/common/KeywordSharePage.vue'), + }, // ---- 兜底:未匹配路径回首页(保持与 MPA 时代"未知页 404 后回首页"一致体验)---- { path: '/:pathMatch(.*)*', redirect: '/home' }, ] diff --git a/frontend-vue/src/shared/api/java-modules.ts b/frontend-vue/src/shared/api/java-modules.ts index 137384fd8..fa788b851 100644 --- a/frontend-vue/src/shared/api/java-modules.ts +++ b/frontend-vue/src/shared/api/java-modules.ts @@ -15,6 +15,7 @@ export * from "./types/modules/brand.ts"; export * from "./types/modules/permission.ts"; export * from "./types/modules/user-secret.ts"; export * from "./types/modules/digital-human.ts"; +export * from "./types/modules/keyword-share.ts"; export * from "./progress-light.ts"; export * from "./upload.ts"; export * from "./download-url.ts"; diff --git a/frontend-vue/src/shared/api/types/modules/keyword-share.ts b/frontend-vue/src/shared/api/types/modules/keyword-share.ts new file mode 100644 index 000000000..d8273fd30 --- /dev/null +++ b/frontend-vue/src/shared/api/types/modules/keyword-share.ts @@ -0,0 +1,290 @@ +import { del, get, post, type JavaApiResponse, unwrapJavaResponse } from '../../http.ts' +import { JAVA_API_PREFIX } from '../../url.ts' + +/** + * 五国关键词共享 API(/api/keyword-share,后端并行实现,契约以本文档字段为准)。 + * + * companyId 服务端取;鉴权与错误折叠统一走 shared/api/http 的请求封装。 + * 所有函数返回 unwrapJavaResponse 拆包后的业务数据;失败时向调用方抛错 + * (页面用 ElMessage 提示,不白屏)。 + */ + +export type KeywordShareStatusFilter = 'all' | 'used' | 'unused' +export type KeywordShareLogType = 'usage' | 'add' | 'delete' +/** 已使用时间筛选:0=全部(不传参),1=今天,7/30/90/180/360=近 N 天 */ +export type KeywordShareUsedDays = 0 | 1 | 7 | 30 | 90 | 180 | 360 + +export interface KeywordShareRow { + id: number | string + country: string + keyword: string + chinese?: string | null + category?: string | null + subCategory?: string | null + categoryL3?: string | null + categoryL4?: string | null + used?: boolean + usedTime?: string | null + usedUser?: string | null +} + +export interface KeywordShareStats { + /** 命中总数 */ + hit: number + used: number + unused: number + /** 跨国重复 */ + dup: number +} + +export interface KeywordShareListVo { + total: number + rows: KeywordShareRow[] + stats: KeywordShareStats +} + +export interface KeywordShareCategoryL3 { + name: string + l4: string[] +} + +export interface KeywordShareSubCategory { + name: string + l3: KeywordShareCategoryL3[] +} + +export interface KeywordShareCategory { + name: string + subs: KeywordShareSubCategory[] +} + +export interface KeywordShareFiltersVo { + countries: string[] + categories: KeywordShareCategory[] +} + +export interface KeywordShareAddItem { + country: string + keyword: string + chinese?: string +} + +export interface KeywordShareAddVo { + added: number + skipped: number +} + +export interface KeywordShareDeleteVo { + deleted: number +} + +export interface KeywordShareMarkVo { + marked: number +} + +export interface KeywordShareUnmarkVo { + unmarked: number +} + +export interface KeywordShareLogRow { + id?: number | string + /** usage=标记使用 / add=添加 / delete=删除 */ + type?: KeywordShareLogType | string + country?: string | null + keyword?: string | null + chinese?: string | null + operator?: string | null + createdAt?: string | null + detail?: string | null +} + +export interface KeywordShareLogsVo { + total: number + rows: KeywordShareLogRow[] +} + +export interface KeywordShareListQuery { + country?: string + /** 一级类目 */ + category?: string + subCategory?: string + categoryL3?: string + categoryL4?: string + /** 关键词 / 中文模糊搜索 */ + search?: string + status?: KeywordShareStatusFilter + /** 0=全部(不传参) */ + usedDays?: KeywordShareUsedDays + /** 仅看我使用 */ + onlyMine?: boolean + page?: number + size?: number +} + +export interface KeywordShareLogsQuery { + type?: KeywordShareLogType + country?: string + page?: number + size?: number +} + +/** 列表查询参数拼装:空值与「全部」不传,避免后端把空串当条件 */ +export function buildKeywordShareListParams(query: KeywordShareListQuery): Record { + const params: Record = { + page: query.page ?? 1, + size: query.size ?? 200, + } + const text = (value?: string | null) => { + const trimmed = String(value ?? '').trim() + return trimmed ? trimmed : undefined + } + params.country = text(query.country) + params.category = text(query.category) + params.subCategory = text(query.subCategory) + params.categoryL3 = text(query.categoryL3) + params.categoryL4 = text(query.categoryL4) + params.search = text(query.search) + if (query.status && query.status !== 'all') { + params.status = query.status + } + if (query.usedDays && query.usedDays > 0) { + params.usedDays = query.usedDays + } + if (query.onlyMine) { + params.onlyMine = true + } + return params +} + +export function fetchKeywordShareKeywords(query: KeywordShareListQuery) { + return unwrapJavaResponse( + get>(`${JAVA_API_PREFIX}/keyword-share/keywords`, { + params: buildKeywordShareListParams(query), + }), + ) +} + +export function fetchKeywordShareFilters() { + return unwrapJavaResponse( + get>(`${JAVA_API_PREFIX}/keyword-share/filters`), + ) +} + +export function fetchKeywordShareStatsGrouped() { + return unwrapJavaResponse( + get>(`${JAVA_API_PREFIX}/keyword-share/stats-grouped`), + ) +} + +export function addKeywordShareKeywords(items: KeywordShareAddItem[]) { + return unwrapJavaResponse( + post, { items: KeywordShareAddItem[] }>( + `${JAVA_API_PREFIX}/keyword-share/keywords`, + { items }, + ), + ) +} + +export function deleteKeywordShareKeywords(ids: Array) { + return unwrapJavaResponse( + del>( + `${JAVA_API_PREFIX}/keyword-share/keywords`, + { data: { ids } }, + ), + ) +} + +export interface KeywordShareUsageItem { + country: string + keyword: string +} + +export function markKeywordShareUsage(items: KeywordShareUsageItem[]) { + return unwrapJavaResponse( + post, { items: KeywordShareUsageItem[] }>( + `${JAVA_API_PREFIX}/keyword-share/usage/mark`, + { items }, + ), + ) +} + +export function unmarkKeywordShareUsage(items: KeywordShareUsageItem[]) { + return unwrapJavaResponse( + post, { items: KeywordShareUsageItem[] }>( + `${JAVA_API_PREFIX}/keyword-share/usage/unmark`, + { items }, + ), + ) +} + +export function fetchKeywordShareLogs(query: KeywordShareLogsQuery) { + return unwrapJavaResponse( + get>(`${JAVA_API_PREFIX}/keyword-share/logs`, { + params: { + type: query.type, + country: query.country || undefined, + page: query.page ?? 1, + size: query.size ?? 20, + }, + }), + ) +} + +export function fetchKeywordShareRandom(count = 10) { + return unwrapJavaResponse( + get>(`${JAVA_API_PREFIX}/keyword-share/random`, { + params: { count }, + }), + ) +} + +export interface KeywordStatsGroupedRow { + country: string + category: string + count: number +} + +/** + * 词库统计弹窗的兼容映射:/stats-grouped 的返回结构按后端实现演进, + * 这里把已知形状统一拍平成「国家 × 一级类目 → 计数」行: + * ① { rows: [{country, category, count}] }; + * ② [{country, category, count}] 数组; + * ③ { 国家: { 类目: 数值 } } 二层映射。 + * 其余形状返回空数组(弹窗显示「暂无数据」,不报错)。 + */ +export function normalizeKeywordStatsGrouped(raw: unknown): KeywordStatsGroupedRow[] { + const rows: KeywordStatsGroupedRow[] = [] + + const pushRow = (country: unknown, category: unknown, count: unknown) => { + const c = String(country ?? '').trim() + const cat = String(category ?? '').trim() + const n = Number(count) + if (!c || !cat || !Number.isFinite(n)) return + rows.push({ country: c, category: cat, count: n }) + } + + if (Array.isArray(raw)) { + for (const item of raw) { + if (item && typeof item === 'object') { + const record = item as Record + pushRow(record.country, record.category, record.count) + } + } + return rows + } + + if (raw && typeof raw === 'object') { + const record = raw as Record + if (Array.isArray(record.rows)) { + return normalizeKeywordStatsGrouped(record.rows) + } + for (const [country, value] of Object.entries(record)) { + if (!value || typeof value !== 'object' || Array.isArray(value)) continue + for (const [category, count] of Object.entries(value as Record)) { + pushRow(country, category, count) + } + } + } + + return rows +} diff --git a/frontend-vue/tests/amazon-tool-catalog.test.ts b/frontend-vue/tests/amazon-tool-catalog.test.ts index 0d5e4f54b..992e9ef7d 100644 --- a/frontend-vue/tests/amazon-tool-catalog.test.ts +++ b/frontend-vue/tests/amazon-tool-catalog.test.ts @@ -11,9 +11,9 @@ import { TOOL_MAP, } from '../src/pages/amazon/tool-catalog.ts' -test('工具目录:20 个工具 id 唯一且每个都有图标与渐变配色', () => { +test('工具目录:23 个工具 id 唯一且每个都有图标与渐变配色', () => { const ids = TOOL_GROUPS.flatMap((g) => g.tools.map((t) => t.id)) - assert.equal(ids.length, 20, '工具总数应为 20(前端8 + 运营10 + 后勤2)') + assert.equal(ids.length, 23, '工具总数应为 23(常用3 + 前端8 + 运营10 + 后勤2)') assert.equal(new Set(ids).size, ids.length, '工具 id 不应重复') for (const id of ids) { assert.ok(TOOL_ICON_SHAPES[id], `图标形状缺失: ${id}`) @@ -22,6 +22,51 @@ test('工具目录:20 个工具 id 唯一且每个都有图标与渐变配色' } }) +test('工具目录:常用工具分组排在最前且三个工具都有页面与权限键', () => { + const common = TOOL_GROUPS[0] + assert.equal(common.key, 'common', '常用工具组应在 TOOL_GROUPS 最前') + assert.equal(common.columnKey, 'brand_common_tools') + assert.equal(common.name, '常用工具') + assert.equal(common.desc, '换算 · 查询 · 词库共享,高频小工具') + assert.ok(common.color, '常用工具组应有主色') + assert.equal(common.workflow, undefined, '常用工具组没有标准工作流') + + const byId = new Map(common.tools.map((tool) => [tool.id, tool])) + assert.deepEqual( + [...byId.keys()], + ['pricing-calc', 'five-asin', 'keyword-share'], + '常用工具组的三个工具顺序固定', + ) + assert.equal(byId.get('pricing-calc')?.href, '/pricing-calc') + assert.equal(byId.get('five-asin')?.href, '/five-asin') + assert.equal(byId.get('keyword-share')?.href, '/keyword-share') + assert.deepEqual(byId.get('pricing-calc')?.permissionKeys, ['pricing-calc']) + assert.deepEqual(byId.get('five-asin')?.permissionKeys, ['five-asin']) + assert.deepEqual(byId.get('keyword-share')?.permissionKeys, ['keyword-share']) +}) + +test('权限过滤:常用工具组整组 / 单工具键都按口径过滤', () => { + // 组键命中:整组保留且排在最前 + const withCommon = filterGroupsByPermission(TOOL_GROUPS, ['brand_common_tools']) + const common = withCommon.find((group) => group.key === 'common') + assert.ok(common, '组键 brand_common_tools 命中时常用工具组应整组可见') + assert.deepEqual(common.tools.map((tool) => tool.id), ['pricing-calc', 'five-asin', 'keyword-share']) + + // 只给单个工具权限键:常用组只留命中工具,不整组放行 + const partial = filterGroupsByPermission(TOOL_GROUPS, ['pricing-calc', 'keyword-share']) + const partialCommon = partial.find((group) => group.key === 'common') + assert.ok(partialCommon, '有可见工具时常用组不应整体隐藏') + assert.deepEqual(partialCommon.tools.map((tool) => tool.id), ['pricing-calc', 'keyword-share']) + assert.equal(partialCommon.tools.some((tool) => tool.id === 'five-asin'), false, '无权限的 five-asin 不应混入') + + // 无任何常用权限:常用组整体隐藏 + const none = filterGroupsByPermission(TOOL_GROUPS, ['brand_front_tools']) + assert.equal(none.some((group) => group.key === 'common'), false, '无常用权限时常用组应隐藏') + + // 无任何权限:全部隐藏 + assert.equal(filterGroupsByPermission(TOOL_GROUPS, []).length, 0) +}) + test('工具目录:无页面的工具应在 catalog 里标记为未开通(无 href)', () => { const pending = TOOL_GROUPS.flatMap((g) => g.tools).filter((t) => !t.href) const pendingIds = pending.map((t) => t.id).sort() diff --git a/frontend-vue/tests/five-asin.test.ts b/frontend-vue/tests/five-asin.test.ts new file mode 100644 index 000000000..b3c1d5fa5 --- /dev/null +++ b/frontend-vue/tests/five-asin.test.ts @@ -0,0 +1,48 @@ +import test from 'node:test' +import assert from 'node:assert/strict' + +import { + buildAmazonProductUrl, + FIVE_ASIN_COUNTRIES, + FIVE_ASIN_COUNTRY_MAP, + isValidAsin, + normalizeAsin, +} from '../src/pages/common/five-asin.ts' + +test('五国站点常量:域名 / 邮编 / 城市与桌面版一致', () => { + assert.equal(FIVE_ASIN_COUNTRIES.length, 5) + const byCode = new Map(FIVE_ASIN_COUNTRIES.map((c) => [c.code, c])) + assert.deepEqual(byCode.get('uk'), { + code: 'uk', name: '英国', flag: '🇬🇧', domain: 'www.amazon.co.uk', postcode: 'SW1A 1AA', city: '伦敦', currency: '英镑', + }) + assert.equal(byCode.get('de')?.postcode, '10115') + assert.equal(byCode.get('fr')?.postcode, '75001') + assert.equal(byCode.get('es')?.postcode, '28001') + assert.equal(byCode.get('it')?.postcode, '20121') + // 五国域名唯一且都带 https 之外的裸域名形状 + assert.equal(new Set(FIVE_ASIN_COUNTRIES.map((c) => c.domain)).size, 5) + for (const country of FIVE_ASIN_COUNTRIES) { + assert.equal(FIVE_ASIN_COUNTRY_MAP.get(country.code), country, 'code→country 映射应完整') + } +}) + +test('ASIN 规范化:strip + 大写 + 去非字母数字', () => { + assert.equal(normalizeAsin(' b0c1234abc '), 'B0C1234ABC') + assert.equal(normalizeAsin('B0C-1234 abc'), 'B0C1234ABC') + assert.equal(normalizeAsin('asin/1234?5'), 'ASIN12345') + assert.equal(normalizeAsin(''), '') +}) + +test('ASIN 校验:规范化后必须恰好 10 位字母数字', () => { + assert.equal(isValidAsin('B0C1234ABC'), true) + assert.equal(isValidAsin(normalizeAsin(' b0c1234abc ')), true, '页面先规范化再校验,小写输入规范化后应合法') + assert.equal(isValidAsin('B0C1234AB'), false, '9 位应判不合法') + assert.equal(isValidAsin('B0C1234ABCD'), false, '11 位应判不合法') + assert.equal(isValidAsin(''), false) + assert.equal(isValidAsin('B0C1234AB!'), false, '非字母数字应判不合法') +}) + +test('商品页链接:https://{domain}/dp/{asin}', () => { + assert.equal(buildAmazonProductUrl('www.amazon.co.uk', 'B0C1234ABC'), 'https://www.amazon.co.uk/dp/B0C1234ABC') + assert.equal(buildAmazonProductUrl('www.amazon.de', 'B0C1234ABC'), 'https://www.amazon.de/dp/B0C1234ABC') +}) diff --git a/frontend-vue/tests/mount/keyword-share-page.mount.test.ts b/frontend-vue/tests/mount/keyword-share-page.mount.test.ts new file mode 100644 index 000000000..63c2b0b24 --- /dev/null +++ b/frontend-vue/tests/mount/keyword-share-page.mount.test.ts @@ -0,0 +1,160 @@ +/** + * 五国关键词共享页挂载用例(2026-10-21 常用工具网页化)。 + * + * 两件事都要判,缺一条就是假绿: + * ① 首屏真实走 API:列表行、统计卡都来自 /keywords 返回,页面不得自带假数据; + * ② 行内「标记已使用」真实打到 POST /usage/mark,且载荷是 country+keyword、 + * 成功后重拉列表(防"点了没反应")。 + * + * 跑法:cd frontend-vue && npx vitest run tests/mount/keyword-share-page.mount.test.ts + * (tests/mount/** 由 vitest.config.ts 收,node --test 的 glob 抓不到这里。) + */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { flushPromises, mount, type VueWrapper } from '@vue/test-utils' +import ElementPlus from 'element-plus' + +import KeywordSharePage from '@/pages/common/KeywordSharePage.vue' + +// API 层整模块 mock:纯函数(normalizeKeywordStatsGrouped)保留真实现, +// 网络函数按用例给桩。页面经 shared/api/types/modules/keyword-share 调用。 +const api = vi.hoisted(() => ({ + fetchKeywordShareFilters: vi.fn(), + fetchKeywordShareKeywords: vi.fn(), + fetchKeywordShareStatsGrouped: vi.fn(), + addKeywordShareKeywords: vi.fn(), + deleteKeywordShareKeywords: vi.fn(), + markKeywordShareUsage: vi.fn(), + unmarkKeywordShareUsage: vi.fn(), + fetchKeywordShareLogs: vi.fn(), + fetchKeywordShareRandom: vi.fn(), +})) + +vi.mock('@/shared/api/types/modules/keyword-share', async (importOriginal) => ({ + ...(await importOriginal()), + ...api, +})) + +vi.mock('@/shared/api/permission', () => ({ + getCurrentUserAppColumnKeys: vi.fn().mockResolvedValue([]), +})) + +const ROWS = [ + { + id: 1, + country: '英国', + keyword: 'wireless charger', + chinese: '无线充电器', + category: '电子', + subCategory: '配件', + categoryL3: '充电', + categoryL4: '无线充', + used: false, + usedTime: null, + usedUser: null, + }, + { + id: 2, + country: '德国', + keyword: 'handtuch wärmer', + chinese: '毛巾架', + category: '家居', + subCategory: '浴室', + categoryL3: '毛巾架', + categoryL4: '加热', + used: true, + usedTime: '2026-10-20 10:00:00', + usedUser: '张三', + }, +] + +const LIST_VO = { + total: 2, + rows: ROWS, + stats: { hit: 2, used: 1, unused: 1, dup: 0 }, +} + +// happy-dom 没有ResizeObserver 时 el-table 会挂不上,补一个最小桩 +class ResizeObserverStub { + observe() {} + unobserve() {} + disconnect() {} +} + +let wrapper: VueWrapper | null = null + +async function mountPage() { + wrapper = mount(KeywordSharePage, { + global: { + plugins: [ElementPlus], + stubs: { + RouterLink: true, + 'router-link': true, + NotificationBell: true, + BrandApiSecretSettingsButton: true, + DownloadProgressPanel: true, + AmazonFooterBar: true, + }, + }, + }) + await flushPromises() + await flushPromises() + return wrapper +} + +function findButtonByText(text: string) { + const buttons = wrapper?.findAll('button') ?? [] + return buttons.find((button) => button.text().trim() === text) +} + +describe('五国关键词共享页', () => { + beforeEach(() => { + if (!(globalThis as Record).ResizeObserver) { + ;(globalThis as Record).ResizeObserver = ResizeObserverStub + } + api.fetchKeywordShareFilters.mockResolvedValue({ countries: ['英国', '德国'], categories: [] }) + api.fetchKeywordShareKeywords.mockResolvedValue(LIST_VO) + api.markKeywordShareUsage.mockResolvedValue({ marked: 1 }) + api.unmarkKeywordShareUsage.mockResolvedValue({ unmarked: 1 }) + }) + + afterEach(() => { + wrapper?.unmount() + wrapper = null + vi.clearAllMocks() + }) + + it('首屏渲染 API 返回的关键词行与统计卡(无假数据)', async () => { + const w = await mountPage() + expect(api.fetchKeywordShareKeywords).toHaveBeenCalledTimes(1) + const text = w.text() + expect(text, '行数据来自 /keywords 返回').toContain('wireless charger') + expect(text).toContain('handtuch wärmer') + expect(text).toContain('✓已使用·2026-10-20 10:00:00·张三') + expect(text).toContain('未使用') + // 统计卡四格来自返回的 stats + expect(text).toContain('命中总数') + expect(w.findAll('.stat-card .stat-value').map((node) => node.text())).toEqual(['2', '1', '1', '0']) + }) + + it('行内「标记已使用」打到 POST /usage/mark(country+keyword 载荷)并重拉列表', async () => { + await mountPage() + expect(api.markKeywordShareUsage).not.toHaveBeenCalled() + const markBtn = findButtonByText('标记已使用') + expect(markBtn, '未使用行应显示「标记已使用」').toBeTruthy() + await markBtn!.trigger('click') + await flushPromises() + expect(api.markKeywordShareUsage).toHaveBeenCalledTimes(1) + expect(api.markKeywordShareUsage).toHaveBeenCalledWith([{ country: '英国', keyword: 'wireless charger' }]) + expect(api.fetchKeywordShareKeywords, '标记成功后应重拉列表').toHaveBeenCalledTimes(2) + }) + + it('已使用行的行内按钮是「标记未使用」,点击走 POST /usage/unmark', async () => { + await mountPage() + const unmarkBtn = findButtonByText('标记未使用') + expect(unmarkBtn, '已使用行应显示「标记未使用」').toBeTruthy() + await unmarkBtn!.trigger('click') + await flushPromises() + expect(api.unmarkKeywordShareUsage).toHaveBeenCalledWith([{ country: '德国', keyword: 'handtuch wärmer' }]) + expect(api.markKeywordShareUsage).not.toHaveBeenCalled() + }) +}) diff --git a/frontend-vue/tests/pricing-calc.test.ts b/frontend-vue/tests/pricing-calc.test.ts new file mode 100644 index 000000000..7dfc5f508 --- /dev/null +++ b/frontend-vue/tests/pricing-calc.test.ts @@ -0,0 +1,84 @@ +import test from 'node:test' +import assert from 'node:assert/strict' + +import { + calcPricing, + formatExchangeRate, + formatMoney, + formatProfitRate, + parseMoneyInput, + PRICING_STATIONS, + PRICING_STATION_MAP, +} from '../src/pages/common/pricing-calc.ts' + +test('站点配置:英国 GBP 除数 9,德国·法国 EUR 除数 8', () => { + assert.deepEqual(PRICING_STATIONS.map((s) => s.key), ['uk', 'eu']) + assert.equal(PRICING_STATION_MAP.get('uk')?.currency, 'GBP') + assert.equal(PRICING_STATION_MAP.get('uk')?.divisor, 9) + assert.equal(PRICING_STATION_MAP.get('eu')?.currency, 'EUR') + assert.equal(PRICING_STATION_MAP.get('eu')?.divisor, 8) +}) + +test('金额解析:剥离 ¥/¥/千分位逗号/空白后 parseFloat', () => { + assert.equal(parseMoneyInput('25'), 25) + assert.equal(parseMoneyInput('¥1,280'), 1280) + assert.equal(parseMoneyInput('¥3.5'), 3.5) + assert.equal(parseMoneyInput(' 1,234.56 '), 1234.56) + assert.equal(parseMoneyInput('0'), 0) + assert.ok(parseMoneyInput('0.001') !== null) +}) + +test('金额解析:空串、非数字、负数一律判非法(返回 null)', () => { + assert.equal(parseMoneyInput(''), null) + assert.equal(parseMoneyInput(' '), null) + assert.equal(parseMoneyInput('abc'), null) + assert.equal(parseMoneyInput('12abc'), null) + assert.equal(parseMoneyInput('-5'), null) + assert.equal(parseMoneyInput('¥-5'), null) +}) + +test('计算口径:英国站逐项对上桌面版公式', () => { + const uk = PRICING_STATION_MAP.get('uk') + assert.ok(uk) + // 成本=100+10=110;营业额=110/0.5=220;平台费=44;利润=66;利润率=0.3;换算=220/9 + const result = calcPricing(100, 10, uk) + assert.equal(result.cost, 110) + assert.equal(result.revenue, 220) + assert.equal(result.platformFee, 44) + assert.equal(result.profit, 66) + assert.ok(Math.abs(result.profitRate - 0.3) < 1e-12) + assert.ok(Math.abs(result.converted - 220 / 9) < 1e-12) +}) + +test('计算口径:德国·法国站按除数 8 反推', () => { + const eu = PRICING_STATION_MAP.get('eu') + assert.ok(eu) + const result = calcPricing(80, 0, eu) + assert.equal(result.cost, 80) + assert.equal(result.revenue, 160) + assert.equal(result.platformFee, 32) + assert.equal(result.profit, 48) + assert.equal(result.converted, 20) +}) + +test('计算边界:买货价与运费都为 0 时结果全 0,利润率不出现 NaN', () => { + const uk = PRICING_STATION_MAP.get('uk') + assert.ok(uk) + const result = calcPricing(0, 0, uk) + assert.equal(result.cost, 0) + assert.equal(result.revenue, 0) + assert.equal(result.platformFee, 0) + assert.equal(result.profit, 0) + assert.equal(result.profitRate, 0, '营业额为 0 时利润率应记 0 而不是 NaN') + assert.equal(result.converted, 0) +}) + +test('展示格式:金额千分位 2 位 / 利润率 1 位百分比 / 汇率 4 位小数', () => { + assert.equal(formatMoney(220), '220.00') + assert.equal(formatMoney(1234567.891), '1,234,567.89') + assert.equal(formatMoney(0), '0.00') + assert.equal(formatProfitRate(0.3), '30.0%') + assert.equal(formatProfitRate(0), '0.0%') + assert.equal(formatExchangeRate(220 / 9), (220 / 9).toFixed(4)) + assert.equal(formatExchangeRate(20), '20.0000') +})