npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

bmc-common-resource

v1.1.162

Published

通用枚举、常量和资源的npm包

Readme

bmc-common-resource

这是一个npm包,用于定义多个项目共用的枚举、常量、资源和数据模型。通过集中管理这些公共资源,可以确保在不同项目中保持一致性,减少代码重复,并简化维护工作。

安装

npm install bmc-common-resource --save

主要功能

1. 枚举和常量

包含系统中使用的各种枚举和对应的选项数组,确保各项目中使用相同的枚举值。

2. 空间配置模块

提供房间、分组、分类等数据配置和关联关系的定义,支持空间配置的统一管理。

3. 数据模型

提供统一的前端数据模型定义,如报价单项等,确保数据结构一致性。

4. 工具函数

提供各种业务相关的工具函数,如UUID生成、价格计算等。

使用示例

报价清单状态 (solution_status)

import { solution_status, solution_status_options } from 'bmc-common-resource';

// 使用枚举
const status = solution_status.DRAFT;

// 使用选项数组(适用于下拉菜单等UI组件)
console.log(solution_status_options);
// 输出:[{name: '草稿', value: 'DRAFT'}, ...]

货币单位 (CURRENCY_UNIT_ENUM)

import { CURRENCY_UNIT_ENUM, CURRENCY_UNIT_OPTIONS } from 'bmc-common-resource';

// 使用枚举
const currency = CURRENCY_UNIT_ENUM.CNY;

// 使用选项数组
console.log(CURRENCY_UNIT_OPTIONS);
// 输出:[{name: '人民币', value: 'CNY'}, ...]

产品供货模式 (supply_mode)

import { supply_mode, supply_mode_options } from 'bmc-common-resource';

// 使用枚举
const mode = supply_mode.own_production;

// 使用选项数组
console.log(supply_mode_options);
// 输出:[{name: '自制生产', value: 'own_production'}, ...]

价格标识 (price_flag)

import { 
  price_flag, 
  price_flag_options, 
  ListType, 
  getPriceFlagOptionsByListType, 
  isPriceFlagValidForListType 
} from 'bmc-common-resource';

// 使用枚举
const flag = price_flag.stdConf;

// 使用完整选项数组
console.log(price_flag_options);
// 输出:[{name: '标配', value: 'stdConf'}, ...]

// 根据清单类型获取可用的价格标识选项
const salesOptions = getPriceFlagOptionsByListType(ListType.SALES);
console.log(salesOptions);
// 输出: 销售清单可用的价格标识选项数组

// 检查价格标识是否适用于某类清单
const isValid = isPriceFlagValidForListType(price_flag.gift, ListType.PURCHASE);
console.log(isValid); // 输出: true,因为赠品适用于采购清单

舍入规则 (rounding_rule)

import { rounding_rule, rounding_rule_options } from 'bmc-common-resource';

// 使用枚举
const rule = rounding_rule.SINGLE_SET_EIGHT;

// 使用选项数组
console.log(rounding_rule_options);
// 输出:[{name: '个位四舍五入', value: 'SINGLE_SET_EIGHT'}, ...]

// 在价格计算场景中使用
function applyRoundingRule(price: number, rule: rounding_rule): number {
  switch (rule) {
    case rounding_rule.SINGLE_ROUND:
      return Math.round(price);
    case rounding_rule.SINGLE_SET_EIGHT:
      return Math.floor(price / 10) * 10 + 8;
    case rounding_rule.SINGLE_SET_NINE:
      return Math.floor(price / 10) * 10 + 9;
    case rounding_rule.SINGLE_SET_TEN:
      return Math.ceil(price / 10) * 10;
    // ... 其他规则实现
    default:
      return price;
  }
}

// 应用舍入规则示例
const originalPrice = 1234.56;
const roundedPrice = applyRoundingRule(originalPrice, rounding_rule.SINGLE_SET_NINE);
console.log(roundedPrice); // 输出: 1239

报价产品项 (QuotationItem)

import { QuotationItem } from 'bmc-common-resource';

// 创建新的报价产品项
const item = new QuotationItem({
  uuid: 'abc-123',
  productId: 'prod001',
  spuName: '悬浮式电视柜-XWSTDSG34804752600',
  unitPrice: 1299,
  roomName: '客厅',
  roomCode: 'drawing',
  width: 1200,
  height: 400,
  depth: 500
});

// 设置价格信息
item.priceFlag = 'positive';
item.standardPrice = item.unitPrice * item.measure * item.count;  // 计算标准金额
item.itemDiscount = 85;  // 85折

console.log(item);

空间配置 (solution模块)

import { 
  ROOM_TYPES, 
  CLASSIFY_TYPES,
  GROUP_TYPES,
  PRODUCT_CATEGORIES,
  getProductCategoriesByGroupType,
  getClassifyRoomsAndGroups,
  getSortedRoomTypes
} from 'bmc-common-resource';

// 获取所有房间类型,并按排序
const roomTypes = getSortedRoomTypes();
console.log(roomTypes);
// 输出: [{name: '全屋', order: 0}, {name: '客厅', order: 1}, ...]

// 获取分组下的产品分类
const cabinetCategories = getProductCategoriesByGroupType('CABINET_TYPE');
console.log(cabinetCategories);
// 输出: [{categoryName: '厅柜', categoryCode: 'HALL_CABINET'}, ...]

// 获取定制家具品项的所有房间和分组
const roomsAndGroups = getClassifyRoomsAndGroups('CUSTOM_FURNITURE');
console.log(roomsAndGroups);

生成UUID

import { generateUUID } from 'bmc-common-resource';

const id = generateUUID();
console.log(id); // 输出: 例如 "f47ac10b-58cc-4372-a567-0e02b2c3d479"

价格计算工具

import { calcStandardPrice, calcActualPrice, price_flag } from 'bmc-common-resource';

// 计算标准金额(计量 * 数量 * 单价)
const standardPrice = calcStandardPrice(
  1.5,   // 计量
  2,     // 数量
  1000,  // 单价
  price_flag.positive // 价格标识
);
console.log(standardPrice); // 输出: 3000

// 计算实际金额(标准金额 * 非标系数 * 折扣率)
const actualPrice = calcActualPrice(
  standardPrice,  // 标准金额
  1.2,            // 非标系数
  85,             // 折扣率(85%)
  price_flag.positive
);
console.log(actualPrice); // 输出: 3060

枚举值说明

solution_status (报价清单状态)

| 值 | 说明 | |----|------| | DRAFT | 草稿 | | ACTIVE | 可用 | | LOCKED | 锁定 | | REVOKED | 已作废 | | PRE_SIGNED | 预签 | | SIGNED | 已签 | | SIGNED_REVOKED | 已签作废 |

CURRENCY_UNIT_ENUM (货币单位)

| 值 | 说明 | |----|------| | CNY | 人民币 | | USD | 美元 | | EUR | 欧元 | | GBP | 英镑 | | HKD | 港币 |

supply_mode (产品供货模式)

| 值 | 说明 | |----|------| | own_production | 自制生产 | | brand_agency | 品牌代理 | | wholesale_procur | 批发采购 | | cross_border_pro | 跨境采购 | | oem_contract | OEM代工 |

price_flag (价格标识)

| 值 | 说明 | |----|------| | stdConf | 标配 | | gift | 赠品 | | present | 礼品 | | package | 套餐 | | positive | 正价 | | specialPrice | 特价 | | fixPrice | 定价 | | returnedPurchase | 退货 | | refund | 退款 | | sample | 样品 | | returning_inventory | 退库 | | backup_warehouse | 备库 | | sec_kill_product | 秒杀品 | | activity_product | 活动产品 | | product_stock | 库存产品 |

rounding_rule (舍入规则)

| 值 | 说明 | |----|------| | SINGLE_ROUND | 个位四舍五入 | | SINGLE_SET_EIGHT | 个位凑"8" | | SINGLE_SET_NINE | 个位凑"9" | | SINGLE_SET_TEN | 个位进十 | | SINGLE_PLUS_ONE | 个位替换 "4"或"7" (加 "1") | | TEN_PLUS_ONE | 十位替换 "4"或"7" (加 "1") | | SINGLE_TEN_PLUS_ONE | 个位和十位替换 "4"或"7" (加 "1") |

ListType (清单类型)

| 值 | 说明 | |----|------| | PURCHASE | 采购清单 | | SALES | 销售清单 | | INVENTORY | 库存清单 | | RETURN | 退货清单 | | OTHER | 其他清单 |

空间配置模块说明

空间配置模块提供了一套完整的房间、分组和产品分类的关联关系定义,主要包含以下内容:

房间类型 (ROOM_TYPES)

定义了系统支持的所有房间类型,如客厅、卧室、厨房等,每种类型包含名称、排序值等属性。

分组类型 (GROUP_TYPES)

定义了产品的功能分组,如柜类、功能五金、配套电器等,每种分组可包含多个产品分类。

产品分类 (PRODUCT_CATEGORIES)

定义了具体的产品分类,如厅柜、书柜、抽屉等,用于组织和筛选产品。

品项定义 (CLASSIFY_TYPES)

定义了顶层的产品品项归类,如定制家具等,一个品项可涵盖多种房间和分组。

关联关系

通过CLASSIFY_ROOM_GROUP_MAP定义了品项、房间和分组之间的多层关联,支持灵活的产品筛选和分类展示。

数据模型说明

QuotationItem

报价产品项类,用于统一定义前端报价单产品项的数据结构,包含以下主要维度:

  1. 基础信息: uuid, productId, unitPrice等
  2. 产品维度: spuName, spuId, brandId, categoryCode等
  3. 空间维度: roomName, roomCode, groupName, groupCode等
  4. 物理维度: width, height, depth, moveDirection等
  5. 业务维度: measureUnit, measure, priceFlag, standardPrice等
  6. 价格体系: productCoefficient, itemDiscount等
  7. 可视化数据: picture等
  8. 层级关系: children, components等

各清单类型对应的价格标识:

  1. 采购清单 (PURCHASE)

    • 标配 (stdConf)
    • 赠品 (gift)
    • 样品 (sample)
    • 正价 (positive)
    • 特价 (specialPrice)
    • 定价 (fixPrice)
  2. 销售清单 (SALES)

    • 标配 (stdConf)
    • 赠品 (gift)
    • 礼品 (present)
    • 套餐 (package)
    • 正价 (positive)
    • 特价 (specialPrice)
    • 定价 (fixPrice)
    • 秒杀品 (sec_kill_product)
    • 活动产品 (activity_product)
  3. 库存清单 (INVENTORY)

    • 标配 (stdConf)
    • 备库 (backup_warehouse)
    • 库存产品 (product_stock)
  4. 退货清单 (RETURN)

    • 退货 (returnedPurchase)
    • 退款 (refund)
    • 退库 (returning_inventory)
  5. 其他清单 (OTHER)

    • 标配 (stdConf)
    • 正价 (positive)
    • 样品 (sample)

开发说明

添加新的枚举或常量

  1. src/enums 目录下创建新文件
  2. src/enums/index.ts 中导出
  3. 如需选项数组,在 src/constants 目录下创建对应的选项文件
  4. 运行 npm run build 构建

添加新的数据模型

  1. 在相应的 src/modules/xxx/models 目录下创建新文件
  2. 在对应的 models/index.ts 中导出
  3. 确保 scripts/generate-exports.js 脚本可以正确识别和导出该模型
  4. 运行 npm run build 构建

添加工具函数

  1. src/utils 目录下的相应文件中添加函数
  2. 确保在 utils/index.ts 中导出
  3. 运行 npm run build 构建

使用说明

所有枚举、常量、工具函数和数据模型都可以直接从包的根路径导入:

import { 
  // 枚举和常量
  solution_status, 
  CURRENCY_UNIT_ENUM,
  supply_mode,
  price_flag,
  ListType,
  
  // 对应的选项数组
  solution_status_options,
  CURRENCY_UNIT_OPTIONS,
  supply_mode_options,
  price_flag_options,
  
  // 工具函数
  getPriceFlagOptionsByListType,
  generateUUID,
  calcStandardPrice,
  calcActualPrice,
  
  // 空间配置
  ROOM_TYPES,
  GROUP_TYPES,
  PRODUCT_CATEGORIES,
  CLASSIFY_TYPES,
  
  // 数据模型
  QuotationItem
} from 'bmc-common-resource';

字典类型定义说明

概述

本项目中的字典类型定义用于管理系统中的各种选项数据,如客户来源、进程阶段等。所有字典选项都遵循统一的类型定义规范,确保类型安全和使用一致性。

核心类型定义

基础接口

interface DictionaryOption<T = string> {
    /** 标签 */
    label: string;
    /** 值 */
    value: T;
}

这是一个泛型接口,用于定义所有字典选项的基础结构:

  • label: 选项的显示文本
  • value: 选项的值,使用泛型参数 T 来指定具体类型

字典标识枚举

enum DICTIONARY_IDENTIFY_ENUM {
    /** 客户来源 */
    CUSTOMER_SOURCE = 'CUSTOMER_SOURCE',
    /** 进程阶段 */
    PROCESS_STAGE = 'PROCESS_STAGE'
}

定义了系统中所有字典类型的标识。

特定字典选项接口

// 客户来源选项
interface CustomerSourceOption extends DictionaryOption<CustomerSourceType> {}

// 进程阶段选项
interface ProcessStageOption extends DictionaryOption<ProcessStageType> {}

这些接口继承自基础 DictionaryOption 接口,并指定了具体的值类型。

使用注意事项

  1. 所有字典选项都应该是平级的,不包含嵌套结构
  2. 每个选项必须包含 labelvalue 两个属性
  3. value 的类型必须与对应的枚举类型匹配
  4. 字典标识必须使用 DICTIONARY_IDENTIFY_ENUM 中定义的值