feat(all): ✨ 新增工具
This commit is contained in:
parent
5dbedcaf0f
commit
3a55edfafc
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Changesets
|
||||||
|
|
||||||
|
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
||||||
|
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
||||||
|
find the full documentation for it [in our repository](https://github.com/changesets/changesets).
|
||||||
|
|
||||||
|
We have a quick list of common questions to get you started engaging with this project in
|
||||||
|
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md).
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://unpkg.com/@changesets/config@3.1.4/schema.json",
|
||||||
|
"changelog": "@changesets/cli/changelog",
|
||||||
|
"commit": false,
|
||||||
|
"fixed": [],
|
||||||
|
"linked": [],
|
||||||
|
"access": "restricted",
|
||||||
|
"baseBranch": "master",
|
||||||
|
"updateInternalDependencies": "patch",
|
||||||
|
"ignore": []
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
coverage
|
coverage
|
||||||
|
.turbo
|
||||||
|
.changeset/pre.json
|
||||||
*.bak
|
*.bak
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
# the name by which the project can be referenced within Serena
|
# the name by which the project can be referenced within Serena
|
||||||
project_name: "r-util-js"
|
project_name: "r-util-js"
|
||||||
|
|
||||||
|
|
||||||
# list of languages for which language servers are started; choose from:
|
# list of languages for which language servers are started; choose from:
|
||||||
# al bash clojure cpp csharp
|
# al bash clojure cpp csharp
|
||||||
# csharp_omnisharp dart elixir elm erlang
|
# csharp_omnisharp dart elixir elm erlang
|
||||||
|
|
@ -26,7 +25,7 @@ project_name: "r-util-js"
|
||||||
# The first language is the default language and the respective language server will be used as a fallback.
|
# The first language is the default language and the respective language server will be used as a fallback.
|
||||||
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
|
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
|
||||||
languages:
|
languages:
|
||||||
- typescript
|
- typescript
|
||||||
|
|
||||||
# the encoding used by text files in the project
|
# the encoding used by text files in the project
|
||||||
# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
|
# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
|
||||||
|
|
@ -67,7 +66,7 @@ read_only: false
|
||||||
# This extends the existing exclusions (e.g. from the global configuration)
|
# This extends the existing exclusions (e.g. from the global configuration)
|
||||||
#
|
#
|
||||||
# Below is the complete list of tools for convenience.
|
# Below is the complete list of tools for convenience.
|
||||||
# To make sure you have the latest list of tools, and to view their descriptions,
|
# To make sure you have the latest list of tools, and to view their descriptions,
|
||||||
# execute `uv run scripts/print_tool_overview.py`.
|
# execute `uv run scripts/print_tool_overview.py`.
|
||||||
#
|
#
|
||||||
# * `activate_project`: Activates a project by name.
|
# * `activate_project`: Activates a project by name.
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"bumpFiles": [
|
|
||||||
{ "filename": "package.json", "type": "json" },
|
|
||||||
{ "filename": "packages/common/package.json", "type": "json" },
|
|
||||||
{ "filename": "packages/vue3/package.json", "type": "json" },
|
|
||||||
{ "filename": "packages/uni-app/package.json", "type": "json" },
|
|
||||||
{ "filename": "packages/vue2/package.json", "type": "json" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"psioniq.psi-header",
|
"psioniq.psi-header",
|
||||||
"aaron-bond.better-comments",
|
"aaron-bond.better-comments",
|
||||||
"streetsidesoftware.code-spell-checker",
|
"streetsidesoftware.code-spell-checker",
|
||||||
"dbaeumer.vscode-eslint",
|
"dbaeumer.vscode-eslint",
|
||||||
"esbenp.prettier-vscode",
|
"esbenp.prettier-vscode",
|
||||||
"editorconfig.editorconfig"
|
"editorconfig.editorconfig"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"workbench.editor.limit.value": 3,
|
"workbench.editor.limit.value": 3,
|
||||||
"cSpell.words": [
|
"cSpell.words": ["Codice", "commitlint", "dcloudio", "Fabbrica"],
|
||||||
"Codice",
|
|
||||||
"commitlint",
|
|
||||||
"dcloudio",
|
|
||||||
"Fabbrica"
|
|
||||||
],
|
|
||||||
"js/ts.tsdk.path": "node_modules\\typescript\\lib"
|
"js/ts.tsdk.path": "node_modules\\typescript\\lib"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
# AGENTS.md
|
||||||
|
|
||||||
|
This file provides guidance to Codex (Codex.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## 项目概述
|
||||||
|
|
||||||
|
这是一个前端工具库 monorepo,使用 **pnpm workspace + turbo** 管理,包含以下子包:
|
||||||
|
|
||||||
|
| 包名 | 路径 | 描述 |
|
||||||
|
|------|------|------|
|
||||||
|
| `@r-utils/common` | `packages/common` | 通用 JS/TS 工具库(不依赖框架) |
|
||||||
|
| `@r-utils/vue3` | `packages/vue3` | Vue3 专用工具 |
|
||||||
|
| `@r-utils/uni-app` | `packages/uni-app` | uni-app 专用工具 |
|
||||||
|
| `@r-utils/vue2` | `packages/vue2` | Vue2 专用工具 |
|
||||||
|
|
||||||
|
## 常用命令
|
||||||
|
|
||||||
|
### 构建
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 构建所有包
|
||||||
|
pnpm build
|
||||||
|
|
||||||
|
# 构建单个包(Turbo filter)
|
||||||
|
pnpm build -- --filter=@r-utils/common
|
||||||
|
|
||||||
|
# 构建单个包(在包目录内)
|
||||||
|
cd packages/common && pnpm build
|
||||||
|
```
|
||||||
|
|
||||||
|
> `@r-utils/common` 同时有 `webpack.config.js` 和 `rollup.config.js`,当前 `build` 脚本使用 webpack;rollup 配置备用。
|
||||||
|
|
||||||
|
### 测试
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 在根目录运行所有测试
|
||||||
|
pnpm test
|
||||||
|
|
||||||
|
# 运行单个测试文件
|
||||||
|
pnpm vitest run packages/common/test/permission.test.ts
|
||||||
|
```
|
||||||
|
|
||||||
|
测试文件位于各包的 `test/` 目录下,使用 Vitest。
|
||||||
|
|
||||||
|
### 代码检查与格式化
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Lint(从根目录,仅检查 src 目录)
|
||||||
|
pnpm lint
|
||||||
|
|
||||||
|
# 格式化
|
||||||
|
pnpm format
|
||||||
|
```
|
||||||
|
|
||||||
|
ESLint 使用 v9 flat config(`eslint.config.js`),已整合 TypeScript 和 Prettier 规则。
|
||||||
|
|
||||||
|
### Git 提交
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 使用 commitizen 提交(遵循 conventional commits 规范)
|
||||||
|
pnpm commit
|
||||||
|
```
|
||||||
|
|
||||||
|
**注意**:提交时 husky pre-commit 钩子会自动运行 lint-staged 和 `pnpm test`,commit-msg 钩子会用 commitlint 校验提交信息格式。
|
||||||
|
|
||||||
|
### 发布
|
||||||
|
|
||||||
|
发布分四步:先记录 changeset,再校验与构建、更新版本,最后通过 `package.json` 命令发布。
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. 记录变更
|
||||||
|
pnpm changeset
|
||||||
|
|
||||||
|
# 2. 质量检查与构建
|
||||||
|
pnpm release:check
|
||||||
|
|
||||||
|
# 3. 版本管理(更新受影响包版本号 + 生成 CHANGELOG)
|
||||||
|
pnpm release
|
||||||
|
|
||||||
|
# 4. 发布到 npm
|
||||||
|
pnpm release:publish
|
||||||
|
```
|
||||||
|
|
||||||
|
也可以使用一键命令:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm release:all
|
||||||
|
```
|
||||||
|
|
||||||
|
changesets 配置见 `.changeset/config.json`,完整发布说明见 `docs/RELEASE.md`。
|
||||||
|
|
||||||
|
## 架构说明
|
||||||
|
|
||||||
|
### Monorepo 结构
|
||||||
|
|
||||||
|
- 根 `package.json` 定义 devDependencies(构建工具、ESLint、Vitest 等),各子包在自身 `package.json` 中声明运行时依赖
|
||||||
|
- `@r-utils/uni-app` 通过 `workspace:^` 依赖 `@r-utils/common`;其他包目前通过 `file:` 本地路径引用
|
||||||
|
- 每个包均输出 ES 模块格式,入口为 `dist/index.js`,类型声明在 `dist/index.d.ts`
|
||||||
|
|
||||||
|
### 构建工具
|
||||||
|
|
||||||
|
- 各包使用 **webpack 5** + **ts-loader** 进行构建,输出 ES module(`experiments.outputModule: true`)
|
||||||
|
- TypeScript 配置:`target: esnext`、`strict: true`、路径别名 `@` 指向 `src/`
|
||||||
|
|
||||||
|
### `@r-utils/common` 模块结构
|
||||||
|
|
||||||
|
```
|
||||||
|
src/
|
||||||
|
├── permission/ Permission 类:权限字符串格式校验(如 "module:action:resource")
|
||||||
|
├── timer/ Countdown(倒计时)、TimeoutTimer
|
||||||
|
├── printer/ ESC 打印工具,PrintUtil 继承自 JpPrinter(esc.js)
|
||||||
|
├── knock-test/ KnockTest:按顺序敲击/点击触发回调的状态机
|
||||||
|
└── time/ 时间工具函数
|
||||||
|
```
|
||||||
|
|
||||||
|
### `@r-utils/uni-app` 主要模块
|
||||||
|
|
||||||
|
- `request/Request.ts`:类 axios 的 uni.request 封装,支持请求/响应拦截器
|
||||||
|
- `uni-helper.ts`:uni-app 常用工具(scanCode、toPromise、rpxToPx、pathToBase64、Canvas 工具等)
|
||||||
|
- `bluetooth-utils/`、`nfc/`、`printer/`:蓝牙、NFC、打印机功能
|
||||||
|
|
||||||
|
### `@r-utils/vue3`
|
||||||
|
|
||||||
|
- `vue-helper.ts`:Vue class 处理工具(`mergeClass`、`createCustomClassObj`)、`dispatch` 祖先组件事件
|
||||||
|
|
||||||
|
### `@r-utils/vue2`
|
||||||
|
|
||||||
|
- `plugins/visibility.js`:Vue2 mixin 插件,为组件提供 `onShow`/`onHide` 生命周期钩子
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. Versioning is managed by `changesets`.
|
||||||
|
|
||||||
## [1.3.0](https://gitee.com/codice_fabbrica/r-util-js/compare/v1.2.1...v1.3.0) (2026-04-20)
|
## [1.3.0](https://gitee.com/codice_fabbrica/r-util-js/compare/v1.2.1...v1.3.0) (2026-04-20)
|
||||||
|
|
||||||
|
|
|
||||||
39
CLAUDE.md
39
CLAUDE.md
|
|
@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
||||||
|
|
||||||
## 项目概述
|
## 项目概述
|
||||||
|
|
||||||
这是一个前端工具库 monorepo,使用 **pnpm workspace** 管理,包含以下子包:
|
这是一个前端工具库 monorepo,使用 **pnpm workspace + turbo** 管理,包含以下子包:
|
||||||
|
|
||||||
| 包名 | 路径 | 描述 |
|
| 包名 | 路径 | 描述 |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
|
|
@ -21,6 +21,9 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
||||||
# 构建所有包
|
# 构建所有包
|
||||||
pnpm build
|
pnpm build
|
||||||
|
|
||||||
|
# 构建单个包(Turbo filter)
|
||||||
|
pnpm build -- --filter=@r-utils/common
|
||||||
|
|
||||||
# 构建单个包(在包目录内)
|
# 构建单个包(在包目录内)
|
||||||
cd packages/common && pnpm build
|
cd packages/common && pnpm build
|
||||||
```
|
```
|
||||||
|
|
@ -34,10 +37,10 @@ cd packages/common && pnpm build
|
||||||
pnpm test
|
pnpm test
|
||||||
|
|
||||||
# 运行单个测试文件
|
# 运行单个测试文件
|
||||||
npx jest packages/common/test/permission.test.ts
|
pnpm vitest run packages/common/test/permission.test.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
测试文件位于各包的 `test/` 目录下,使用 Jest + Babel。
|
测试文件位于各包的 `test/` 目录下,使用 Vitest。
|
||||||
|
|
||||||
### 代码检查与格式化
|
### 代码检查与格式化
|
||||||
|
|
||||||
|
|
@ -58,29 +61,39 @@ ESLint 使用 v9 flat config(`eslint.config.js`),已整合 TypeScript 和
|
||||||
pnpm commit
|
pnpm commit
|
||||||
```
|
```
|
||||||
|
|
||||||
**注意**:提交时 husky pre-commit 钩子会自动运行 lint-staged 和 jest 测试,commit-msg 钩子会用 commitlint 校验提交信息格式。
|
**注意**:提交时 husky pre-commit 钩子会自动运行 lint-staged 和 `pnpm test`,commit-msg 钩子会用 commitlint 校验提交信息格式。
|
||||||
|
|
||||||
### 发布
|
### 发布
|
||||||
|
|
||||||
发布分两步:先用 `standard-version` 管理版本,再用脚本构建和发布。
|
发布分四步:先记录 changeset,再校验与构建、更新版本,最后通过 `package.json` 命令发布。
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 1. 版本管理(更新版本号 + 生成 CHANGELOG + git commit/tag)
|
# 1. 记录变更
|
||||||
pnpm release # 默认 patch
|
pnpm changeset
|
||||||
npx standard-version --release-as minor # 指定版本类型
|
|
||||||
|
|
||||||
# 2. 构建并发布到 npm
|
# 2. 质量检查与构建
|
||||||
bash scripts/publish.sh # Linux/macOS
|
pnpm release:check
|
||||||
powershell scripts/publish.ps1 # Windows
|
|
||||||
|
# 3. 版本管理(更新受影响包版本号 + 生成 CHANGELOG)
|
||||||
|
pnpm release
|
||||||
|
|
||||||
|
# 4. 发布到 npm
|
||||||
|
pnpm release:publish
|
||||||
```
|
```
|
||||||
|
|
||||||
版本配置见 `.versionrc.json`,会同步更新根包和所有子包的版本号。
|
也可以使用一键命令:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm release:all
|
||||||
|
```
|
||||||
|
|
||||||
|
changesets 配置见 `.changeset/config.json`,完整发布说明见 `docs/RELEASE.md`。
|
||||||
|
|
||||||
## 架构说明
|
## 架构说明
|
||||||
|
|
||||||
### Monorepo 结构
|
### Monorepo 结构
|
||||||
|
|
||||||
- 根 `package.json` 定义 devDependencies(构建工具、ESLint、Jest 等),各子包在自身 `package.json` 中声明运行时依赖
|
- 根 `package.json` 定义 devDependencies(构建工具、ESLint、Vitest 等),各子包在自身 `package.json` 中声明运行时依赖
|
||||||
- `@r-utils/uni-app` 通过 `workspace:^` 依赖 `@r-utils/common`;其他包目前通过 `file:` 本地路径引用
|
- `@r-utils/uni-app` 通过 `workspace:^` 依赖 `@r-utils/common`;其他包目前通过 `file:` 本地路径引用
|
||||||
- 每个包均输出 ES 模块格式,入口为 `dist/index.js`,类型声明在 `dist/index.d.ts`
|
- 每个包均输出 ES 模块格式,入口为 `dist/index.js`,类型声明在 `dist/index.d.ts`
|
||||||
|
|
||||||
|
|
|
||||||
60
README.md
60
README.md
|
|
@ -1,6 +1,6 @@
|
||||||
# r-utils
|
# r-utils
|
||||||
|
|
||||||
前端工具库 monorepo,使用 pnpm workspace 管理,Vite 构建。
|
前端工具库 monorepo,使用 pnpm workspace + Turbo 管理任务,Vite 构建。
|
||||||
|
|
||||||
## 包列表
|
## 包列表
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
## 环境要求
|
## 环境要求
|
||||||
|
|
||||||
- Node.js >= 18.12.0
|
- Node.js >= 18.12.0
|
||||||
- pnpm >= 8.15.6
|
- pnpm >= 10.0.0
|
||||||
|
|
||||||
## 安装依赖
|
## 安装依赖
|
||||||
|
|
||||||
|
|
@ -31,6 +31,14 @@ pnpm install
|
||||||
pnpm build
|
pnpm build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Turbo 会自动按依赖拓扑排序构建(例如 `@r-utils/common` 会先于依赖它的包构建),并复用缓存加速重复任务。
|
||||||
|
|
||||||
|
### 构建单个包(Turbo 过滤)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm build -- --filter=@r-utils/common
|
||||||
|
```
|
||||||
|
|
||||||
### 构建单个包
|
### 构建单个包
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
@ -52,8 +60,11 @@ dist/
|
||||||
### 监听模式
|
### 监听模式
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd packages/common
|
# 监听所有包
|
||||||
pnpm watch
|
pnpm build:watch
|
||||||
|
|
||||||
|
# 仅监听单个包
|
||||||
|
pnpm build:watch -- --filter=@r-utils/common
|
||||||
```
|
```
|
||||||
|
|
||||||
## 使用方式
|
## 使用方式
|
||||||
|
|
@ -114,7 +125,7 @@ const { Permission } = require('@r-utils/common');
|
||||||
pnpm test
|
pnpm test
|
||||||
|
|
||||||
# 运行单个测试文件
|
# 运行单个测试文件
|
||||||
npx jest packages/common/test/permission.test.ts
|
pnpm vitest run packages/common/test/permission.test.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
### 代码检查与格式化
|
### 代码检查与格式化
|
||||||
|
|
@ -136,50 +147,27 @@ pnpm commit
|
||||||
提交时 husky 会自动运行:
|
提交时 husky 会自动运行:
|
||||||
|
|
||||||
- `lint-staged` - 代码检查和格式化
|
- `lint-staged` - 代码检查和格式化
|
||||||
- `jest` - 单元测试
|
- `pnpm test`(Vitest) - 单元测试
|
||||||
- `commitlint` - 提交信息格式校验
|
- `commitlint` - 提交信息格式校验
|
||||||
|
|
||||||
详细说明请参考 [提交规范指南](./docs/COMMIT_GUIDE.md)。
|
详细说明请参考 [提交规范指南](./docs/COMMIT_GUIDE.md)。
|
||||||
|
|
||||||
## 发布
|
## 发布
|
||||||
|
|
||||||
### 1. 版本管理(standard-version)
|
发布流程已提取到独立文档:[发布流程](./docs/RELEASE.md)。
|
||||||
|
|
||||||
使用 `standard-version` 更新版本号、生成 CHANGELOG、创建 Git commit 和 tag。版本配置见 `.versionrc.json`,会同步更新根包和所有子包的版本号。
|
常用命令:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 默认 patch 版本
|
pnpm changeset # 记录变更
|
||||||
pnpm release
|
pnpm release:check # 测试 + 构建
|
||||||
|
pnpm release # 更新版本号与 CHANGELOG
|
||||||
# 指定版本类型
|
pnpm release:publish # 发布到 npm 仓库
|
||||||
npx standard-version --release-as minor # 1.0.0 -> 1.1.0
|
pnpm release:all # 一键执行检查 + 版本更新 + 发布
|
||||||
npx standard-version --release-as major # 1.0.0 -> 2.0.0
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. 构建并发布到私有 npm 仓库
|
|
||||||
|
|
||||||
项目已配置发布到私有 npm 仓库 `http://npm.nps.yunvip123.cn`。
|
项目已配置发布到私有 npm 仓库 `http://npm.nps.yunvip123.cn`。
|
||||||
|
|
||||||
#### Windows (PowerShell)
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
powershell scripts/publish.ps1
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Linux/macOS (Bash)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bash scripts/publish.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
发布脚本会自动执行以下步骤:
|
|
||||||
|
|
||||||
1. 检查 Git 工作区状态
|
|
||||||
2. 运行测试(确保代码质量)
|
|
||||||
3. 构建所有子包
|
|
||||||
4. 依次发布 `@r-utils/common`、`@r-utils/vue3`、`@r-utils/uni-app`、`@r-utils/vue2`
|
|
||||||
5. 询问是否推送到远程仓库
|
|
||||||
|
|
||||||
### 安装已发布的包
|
### 安装已发布的包
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,10 @@ module.exports = {
|
||||||
prompt: {
|
prompt: {
|
||||||
useEmoji: true,
|
useEmoji: true,
|
||||||
emojiAlign: "center",
|
emojiAlign: "center",
|
||||||
allowCustomIssuePrefix: false,
|
allowCustomIssuePrefix: true,
|
||||||
allowEmptyIssuePrefix: false,
|
allowEmptyIssuePrefix: true,
|
||||||
|
emptyIssuePrefixAlias: "跳过",
|
||||||
|
customIssuePrefixAlias: "自定义",
|
||||||
// 定义 scope 选项
|
// 定义 scope 选项
|
||||||
scopes: [
|
scopes: [
|
||||||
{ value: "common", name: "common: @r-utils/common 包" },
|
{ value: "common", name: "common: @r-utils/common 包" },
|
||||||
|
|
@ -75,39 +77,67 @@ module.exports = {
|
||||||
// 破坏性变更默认跳过;如需声明可手动在提交信息中添加 BREAKING CHANGE
|
// 破坏性变更默认跳过;如需声明可手动在提交信息中添加 BREAKING CHANGE
|
||||||
allowBreakingChanges: [],
|
allowBreakingChanges: [],
|
||||||
messages: {
|
messages: {
|
||||||
type: '选择你要提交的类型:',
|
type: "选择你要提交的类型:",
|
||||||
scope: '选择一个提交范围(可选):',
|
scope: "选择一个提交范围(可选):",
|
||||||
customScope: '请输入自定义范围:',
|
customScope: "请输入自定义范围:",
|
||||||
subject: '请简短描述这次改动:\n',
|
subject: "请简短描述这次改动:\n",
|
||||||
body: '请详细描述这次改动(可选,用 "|" 换行):\n',
|
body: '请详细描述这次改动(可选,用 "|" 换行):\n',
|
||||||
breaking: '是否有破坏性变更(可选,用 "|" 换行):\n',
|
breaking: '是否有破坏性变更(可选,用 "|" 换行):\n',
|
||||||
footerPrefixesSelect: '选择关联的 ISSUE 类型(可选):',
|
footerPrefixesSelect: "选择关联的 ISSUE 类型(可选):",
|
||||||
customFooterPrefix: '输入 ISSUE 前缀:',
|
customFooterPrefix: "输入 ISSUE 前缀:",
|
||||||
footer: '列出关联的 ISSUE,如: #31, #34:\n',
|
footer: "列出关联的 ISSUE,如: #31, #34:\n",
|
||||||
generatingByAI: '正在通过 AI 生成提交信息...',
|
generatingByAI: "正在通过 AI 生成提交信息...",
|
||||||
generatedSelectByAI: '选择一个 AI 生成的 subject:',
|
generatedSelectByAI: "选择一个 AI 生成的 subject:",
|
||||||
confirmCommit: '是否确认提交以上信息?',
|
confirmCommit: "是否确认提交以上信息?",
|
||||||
},
|
},
|
||||||
// subject 最小长度提示(中文化 "[x more chars needed]")
|
// subject 最小长度提示(中文化 "[x more chars needed]")
|
||||||
minSubjectLength: 4,
|
minSubjectLength: 4,
|
||||||
defaultSubject: '',
|
defaultSubject: "",
|
||||||
types: [
|
types: [
|
||||||
{ value: 'feat', name: 'feat: 新增功能', emoji: ':sparkles:' },
|
{ value: "feat", name: "feat: 新增功能", emoji: ":sparkles:" },
|
||||||
{ value: 'fix', name: 'fix: 修复缺陷', emoji: ':bug:' },
|
{ value: "fix", name: "fix: 修复缺陷", emoji: ":bug:" },
|
||||||
{ value: 'docs', name: 'docs: 文档变更', emoji: ':memo:' },
|
{ value: "docs", name: "docs: 文档变更", emoji: ":memo:" },
|
||||||
{ value: 'style', name: 'style: 代码格式(不影响逻辑)', emoji: ':lipstick:' },
|
{
|
||||||
{ value: 'refactor', name: 'refactor: 重构(既非新功能,也不是修 bug)', emoji: ':recycle:' },
|
value: "style",
|
||||||
{ value: 'perf', name: 'perf: 性能优化', emoji: ':zap:' },
|
name: "style: 代码格式(不影响逻辑)",
|
||||||
{ value: 'test', name: 'test: 添加或修改测试', emoji: ':white_check_mark:' },
|
emoji: ":lipstick:",
|
||||||
{ value: 'build', name: 'build: 构建系统或外部依赖变更', emoji: ':package:' },
|
},
|
||||||
{ value: 'ci', name: 'ci: CI 配置文件和脚本变更', emoji: ':ferris_wheel:' },
|
{
|
||||||
{ value: 'chore', name: 'chore: 其它不修改 src 或测试的改动', emoji: ':hammer:' },
|
value: "refactor",
|
||||||
{ value: 'revert', name: 'revert: 回退之前的 commit', emoji: ':rewind:' },
|
name: "refactor: 重构(既非新功能,也不是修 bug)",
|
||||||
|
emoji: ":recycle:",
|
||||||
|
},
|
||||||
|
{ value: "perf", name: "perf: 性能优化", emoji: ":zap:" },
|
||||||
|
{
|
||||||
|
value: "test",
|
||||||
|
name: "test: 添加或修改测试",
|
||||||
|
emoji: ":white_check_mark:",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "build",
|
||||||
|
name: "build: 构建系统或外部依赖变更",
|
||||||
|
emoji: ":package:",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "ci",
|
||||||
|
name: "ci: CI 配置文件和脚本变更",
|
||||||
|
emoji: ":ferris_wheel:",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "chore",
|
||||||
|
name: "chore: 其它不修改 src 或测试的改动",
|
||||||
|
emoji: ":hammer:",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "revert",
|
||||||
|
name: "revert: 回退之前的 commit",
|
||||||
|
emoji: ":rewind:",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
// issue 前缀也可以用中文说明
|
// issue 前缀也可以用中文说明
|
||||||
issuePrefixs: [
|
issuePrefixs: [
|
||||||
{ value: 'link', name: 'link: 关联 ISSUE' },
|
{ value: "link", name: "link: 关联 ISSUE" },
|
||||||
{ value: 'close', name: 'close: 关闭 ISSUE' },
|
{ value: "close", name: "close: 关闭 ISSUE" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
## 开发环境要求
|
## 开发环境要求
|
||||||
|
|
||||||
- Node.js >= 18.12.0
|
- Node.js >= 18.12.0
|
||||||
- pnpm 8.15.6
|
- pnpm >= 10.0.0
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ git checkout -b fix/your-bug-fix
|
||||||
### 3. 开发与测试
|
### 3. 开发与测试
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 构建所有包
|
# 构建所有包(Turbo)
|
||||||
pnpm build
|
pnpm build
|
||||||
|
|
||||||
# 运行测试
|
# 运行测试
|
||||||
|
|
@ -162,7 +162,7 @@ git push origin feat/your-feature-name
|
||||||
### JavaScript/TypeScript
|
### JavaScript/TypeScript
|
||||||
|
|
||||||
- 使用 ESLint + Prettier 进行代码检查和格式化
|
- 使用 ESLint + Prettier 进行代码检查和格式化
|
||||||
- 遵循项目的 `.eslintrc` 配置
|
- 遵循项目的 `eslint.config.js`(ESLint Flat Config)
|
||||||
- 提交前运行 `pnpm lint` 和 `pnpm format`
|
- 提交前运行 `pnpm lint` 和 `pnpm format`
|
||||||
|
|
||||||
### 测试
|
### 测试
|
||||||
|
|
@ -170,7 +170,7 @@ git push origin feat/your-feature-name
|
||||||
- 为新功能编写单元测试
|
- 为新功能编写单元测试
|
||||||
- 确保所有测试通过: `pnpm test`
|
- 确保所有测试通过: `pnpm test`
|
||||||
- 测试文件放在各包的 `test/` 目录下
|
- 测试文件放在各包的 `test/` 目录下
|
||||||
- 使用 Jest 作为测试框架
|
- 使用 Vitest 作为测试框架
|
||||||
|
|
||||||
### 文档
|
### 文档
|
||||||
|
|
||||||
|
|
@ -187,20 +187,20 @@ r-util-js/
|
||||||
│ ├── vue3/ # Vue3 工具
|
│ ├── vue3/ # Vue3 工具
|
||||||
│ ├── vue2/ # Vue2 工具
|
│ ├── vue2/ # Vue2 工具
|
||||||
│ └── uni-app/ # uni-app 工具
|
│ └── uni-app/ # uni-app 工具
|
||||||
├── scripts/ # 构建和发布脚本
|
|
||||||
└── docs/ # 文档
|
└── docs/ # 文档
|
||||||
```
|
```
|
||||||
|
|
||||||
## 发布流程
|
## 发布流程
|
||||||
|
|
||||||
发布由维护者负责,使用 `standard-version` 自动生成版本号和 CHANGELOG:
|
发布由维护者负责,详细流程请查看 [发布流程文档](./RELEASE.md)。
|
||||||
|
|
||||||
|
常用命令:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 生成版本和 CHANGELOG
|
pnpm changeset
|
||||||
|
pnpm release:check
|
||||||
pnpm release
|
pnpm release
|
||||||
|
pnpm release:publish
|
||||||
# 发布到 npm
|
|
||||||
pnpm publish -r
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 需要帮助?
|
## 需要帮助?
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
# 发布流程
|
||||||
|
|
||||||
|
本文档描述维护者发布 `@r-utils` monorepo 包的标准流程。
|
||||||
|
|
||||||
|
## 前置条件
|
||||||
|
|
||||||
|
- Node.js >= 18.12.0
|
||||||
|
- pnpm >= 10.0.0
|
||||||
|
- 已登录目标 npm 仓库(默认使用各包 `publishConfig.registry`)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install
|
||||||
|
```
|
||||||
|
|
||||||
|
## 推荐发布流程(分步)
|
||||||
|
|
||||||
|
### 1. 记录变更(changeset)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm changeset
|
||||||
|
pnpm changeset:status
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 质量检查与构建
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm release:check
|
||||||
|
```
|
||||||
|
|
||||||
|
`release:check` 会依次执行:
|
||||||
|
|
||||||
|
- `pnpm test`
|
||||||
|
- `pnpm build`
|
||||||
|
|
||||||
|
### 3. 更新版本号与 CHANGELOG
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm release
|
||||||
|
```
|
||||||
|
|
||||||
|
该命令等价于 `changeset version`,会更新受影响包版本及 changelog。
|
||||||
|
|
||||||
|
### 4. 发布到 npm 仓库
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm release:publish
|
||||||
|
```
|
||||||
|
|
||||||
|
该命令等价于 `changeset publish`。
|
||||||
|
|
||||||
|
## 一键发布(维护者)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm release:all
|
||||||
|
```
|
||||||
|
|
||||||
|
`release:all` 会按顺序执行:
|
||||||
|
|
||||||
|
1. `pnpm release:check`
|
||||||
|
2. `pnpm release`
|
||||||
|
3. `pnpm release:publish`
|
||||||
|
|
||||||
|
## 发布后建议
|
||||||
|
|
||||||
|
发布完成后,手动提交并推送版本相关变更与 tag。
|
||||||
|
|
@ -6,7 +6,7 @@ import globals from "globals";
|
||||||
import importPlugin from "eslint-plugin-import-x";
|
import importPlugin from "eslint-plugin-import-x";
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
// 应用推荐规则
|
// 应用推荐规则
|
||||||
js.configs.recommended,
|
js.configs.recommended,
|
||||||
...ts.configs.recommended,
|
...ts.configs.recommended,
|
||||||
prettier,
|
prettier,
|
||||||
|
|
@ -40,7 +40,13 @@ export default [
|
||||||
settings: {
|
settings: {
|
||||||
"import-x/resolver": {
|
"import-x/resolver": {
|
||||||
typescript: {
|
typescript: {
|
||||||
project: "tsconfig.eslint.json",
|
project: [
|
||||||
|
"packages/common/tsconfig.json",
|
||||||
|
"packages/uni-app/tsconfig.json",
|
||||||
|
"packages/uview-plus/tsconfig.json",
|
||||||
|
"packages/vue2/tsconfig.json",
|
||||||
|
"packages/vue3/tsconfig.json",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
node: true,
|
node: true,
|
||||||
},
|
},
|
||||||
|
|
@ -61,7 +67,7 @@ export default [
|
||||||
rules: {
|
rules: {
|
||||||
...importPlugin.flatConfigs.recommended.rules,
|
...importPlugin.flatConfigs.recommended.rules,
|
||||||
|
|
||||||
// Prettier 规则
|
// Prettier 规则
|
||||||
"prettier/prettier": "warn",
|
"prettier/prettier": "warn",
|
||||||
|
|
||||||
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
|
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
|
||||||
|
|
@ -110,4 +116,20 @@ export default [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// uni-app / App-Plus 运行时全局变量
|
||||||
|
{
|
||||||
|
files: [
|
||||||
|
"packages/uni-app/**/*.{js,ts}",
|
||||||
|
"packages/common/src/printer/**/*.{js,ts}",
|
||||||
|
],
|
||||||
|
languageOptions: {
|
||||||
|
globals: {
|
||||||
|
uni: "readonly",
|
||||||
|
plus: "readonly",
|
||||||
|
wx: "readonly",
|
||||||
|
getCurrentPages: "readonly",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
22
package.json
22
package.json
|
|
@ -37,11 +37,18 @@
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"preinstall": "npx only-allow pnpm",
|
"preinstall": "npx only-allow pnpm",
|
||||||
"build": "pnpm -r run build",
|
"build": "turbo run build --filter=./packages/*",
|
||||||
|
"build:watch": "turbo run watch --filter=./packages/* --parallel",
|
||||||
|
"typecheck": "turbo run typecheck --filter=./packages/* --concurrency=1",
|
||||||
"prepare": "husky install",
|
"prepare": "husky install",
|
||||||
"lint": "eslint --fix packages/*/src",
|
"lint": "turbo run lint --filter=./packages/*",
|
||||||
"format": "prettier --write packages/*/src",
|
"format": "turbo run format --filter=./packages/*",
|
||||||
"release": "standard-version",
|
"changeset": "changeset",
|
||||||
|
"release": "changeset version",
|
||||||
|
"changeset:status": "changeset status --verbose",
|
||||||
|
"release:check": "pnpm test && pnpm build",
|
||||||
|
"release:publish": "changeset publish",
|
||||||
|
"release:all": "pnpm release:check && pnpm release && pnpm release:publish",
|
||||||
"commit": "cz",
|
"commit": "cz",
|
||||||
"lint-staged": "lint-staged",
|
"lint-staged": "lint-staged",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
|
|
@ -49,6 +56,7 @@
|
||||||
"test:coverage": "vitest run --coverage"
|
"test:coverage": "vitest run --coverage"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@changesets/cli": "^2.31.0",
|
||||||
"@commitlint/config-conventional": "^20.5.0",
|
"@commitlint/config-conventional": "^20.5.0",
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint/js": "^10.0.1",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.57.1",
|
"@typescript-eslint/eslint-plugin": "^8.57.1",
|
||||||
|
|
@ -66,14 +74,14 @@
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"inquirer": "^9.3.8",
|
"inquirer": "^9.3.8",
|
||||||
"lint-staged": "^16.4.0",
|
"lint-staged": "^16.4.0",
|
||||||
"vitest": "catalog:",
|
|
||||||
"prettier": "^3.8.1",
|
"prettier": "^3.8.1",
|
||||||
"standard-version": "^9.5.0",
|
|
||||||
"tslib": "^2.8.1",
|
"tslib": "^2.8.1",
|
||||||
|
"turbo": "^2.9.6",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"typescript-eslint": "^8.57.1",
|
"typescript-eslint": "^8.57.1",
|
||||||
"vite": "^8.0.0",
|
"vite": "^8.0.0",
|
||||||
"vite-plugin-dts": "^4.5.4"
|
"vite-plugin-dts": "^4.5.4",
|
||||||
|
"vitest": "catalog:"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"@types/lodash": "4.17.16",
|
"@types/lodash": "4.17.16",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
# @r-utils/common
|
||||||
|
|
||||||
|
## 1.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 添加工具
|
||||||
|
|
@ -0,0 +1,184 @@
|
||||||
|
# @r-utils/common
|
||||||
|
|
||||||
|
与框架无关的通用 JS/TS 工具库,适用于任意前端项目,也可在具备对应运行时 API 的环境中使用。
|
||||||
|
|
||||||
|
## 特性
|
||||||
|
|
||||||
|
- 不依赖 Vue、uni-app 或 uview-plus。
|
||||||
|
- 支持 ESM / CJS 双格式产物。
|
||||||
|
- 支持根入口导入和子路径按需导入。
|
||||||
|
- 标记 `sideEffects: false`,方便业务打包器进行 tree-shaking。
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm add @r-utils/common
|
||||||
|
```
|
||||||
|
|
||||||
|
## 导入方式
|
||||||
|
|
||||||
|
### 推荐:根入口导入
|
||||||
|
|
||||||
|
大多数场景推荐从根入口导入,使用心智负担更低,现代打包器仍可结合 ESM 和 `sideEffects: false` 做 tree-shaking。
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
Permission,
|
||||||
|
wait,
|
||||||
|
Countdown,
|
||||||
|
TimeoutTimer,
|
||||||
|
getValueOfRule,
|
||||||
|
} from "@r-utils/common";
|
||||||
|
```
|
||||||
|
|
||||||
|
### 兼容:子路径按需导入
|
||||||
|
|
||||||
|
如果你希望导入路径更精确,也可以使用子路径导入。两种方式都支持,按团队习惯选择即可。
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Permission } from "@r-utils/common/permission";
|
||||||
|
import { wait } from "@r-utils/common/time";
|
||||||
|
import { Countdown, TimeoutTimer } from "@r-utils/common/timer";
|
||||||
|
import { getValueOfRule } from "@r-utils/common/input-rule";
|
||||||
|
```
|
||||||
|
|
||||||
|
## 导出模块
|
||||||
|
|
||||||
|
| 子路径 | 说明 |
|
||||||
|
| --- | --- |
|
||||||
|
| `@r-utils/common/permission` | 权限字符串格式校验 |
|
||||||
|
| `@r-utils/common/time` | 时间相关工具 |
|
||||||
|
| `@r-utils/common/timer` | 倒计时、超时计时器 |
|
||||||
|
| `@r-utils/common/input-rule` | 输入值规则处理 |
|
||||||
|
| `@r-utils/common/knock-test` | 连续敲击/点击触发器 |
|
||||||
|
| `@r-utils/common/ui` | 与框架无关的 UI 计算工具 |
|
||||||
|
| `@r-utils/common/printer` | ESC/TSC 打印相关工具 |
|
||||||
|
|
||||||
|
## 使用示例
|
||||||
|
|
||||||
|
### 权限字符串校验
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Permission } from "@r-utils/common";
|
||||||
|
|
||||||
|
const permission = new Permission([], 3, ":");
|
||||||
|
|
||||||
|
permission.isValid("user:create:button"); // true
|
||||||
|
permission.isValid("user:create"); // false
|
||||||
|
```
|
||||||
|
|
||||||
|
### 等待指定时间
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { wait } from "@r-utils/common";
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
await wait(300);
|
||||||
|
console.log("继续执行");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 倒计时
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Countdown } from "@r-utils/common";
|
||||||
|
|
||||||
|
const countdown = new Countdown(10 * 1000);
|
||||||
|
|
||||||
|
countdown.addStepEventListener((time) => {
|
||||||
|
console.log("剩余时间:", time);
|
||||||
|
});
|
||||||
|
|
||||||
|
countdown.addCountdownEventListener(() => {
|
||||||
|
console.log("倒计时结束");
|
||||||
|
});
|
||||||
|
|
||||||
|
countdown.start();
|
||||||
|
```
|
||||||
|
|
||||||
|
### 简单数值倒计时
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { TimeoutTimer } from "@r-utils/common";
|
||||||
|
|
||||||
|
const timer = new TimeoutTimer(5000, 0, 1000);
|
||||||
|
|
||||||
|
timer.addStepEventListener((time) => {
|
||||||
|
console.log("剩余毫秒:", time);
|
||||||
|
});
|
||||||
|
|
||||||
|
timer.addCountdownEventListener(() => {
|
||||||
|
console.log("完成");
|
||||||
|
});
|
||||||
|
|
||||||
|
timer.start();
|
||||||
|
```
|
||||||
|
|
||||||
|
### 输入值规则处理
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { getValueOfRule } from "@r-utils/common";
|
||||||
|
|
||||||
|
const value = getValueOfRule("12.345", {
|
||||||
|
min: 0,
|
||||||
|
max: 99999.99,
|
||||||
|
required: true,
|
||||||
|
digits: 2,
|
||||||
|
keepDecimal: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(value); // "12.35"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 禁止正负号并转成数字
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { getValueOfRule } from "@r-utils/common";
|
||||||
|
|
||||||
|
const value = getValueOfRule("-12", {
|
||||||
|
min: 0,
|
||||||
|
required: true,
|
||||||
|
noSign: true,
|
||||||
|
number: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(value); // 0
|
||||||
|
```
|
||||||
|
|
||||||
|
### 连续敲击触发回调
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { KnockTest } from "@r-utils/common";
|
||||||
|
|
||||||
|
const knockTest = new KnockTest({
|
||||||
|
maxWaitTime: 5000,
|
||||||
|
operations: [
|
||||||
|
{ times: 3, duration: 1000, delay: 500 },
|
||||||
|
{ times: 2, duration: 1000, delay: 500 },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
knockTest.addCallback(() => {
|
||||||
|
console.log("触发隐藏功能");
|
||||||
|
});
|
||||||
|
|
||||||
|
button.addEventListener("click", () => {
|
||||||
|
knockTest.knock();
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### 缓动滚动计算
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { slowlyScroll } from "@r-utils/common";
|
||||||
|
|
||||||
|
await slowlyScroll(0, 300, 500, (value) => {
|
||||||
|
window.scrollTo(0, value);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
- `Countdown`、`TimeoutTimer` 和 `KnockTest` 内部使用 `window.setInterval` / `window.setTimeout`,更适合浏览器或类浏览器环境。
|
||||||
|
- 推荐优先使用根入口导入;如果需要更精确的模块边界,也可以使用子路径导入。
|
||||||
|
- 打印相关模块通常依赖具体设备和业务场景,建议在真实设备环境中验证。
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@r-utils/common",
|
"name": "@r-utils/common",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "js通用工具库",
|
"description": "js通用工具库",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
@ -8,13 +8,50 @@
|
||||||
"module": "dist/index.mjs",
|
"module": "dist/index.mjs",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./dist/index.mjs",
|
"import": "./dist/index.mjs",
|
||||||
"require": "./dist/index.cjs"
|
"require": "./dist/index.cjs"
|
||||||
},
|
},
|
||||||
"./*": "./*"
|
"./input-rule": {
|
||||||
|
"types": "./dist/input-rule/index.d.ts",
|
||||||
|
"import": "./dist/input-rule/index.mjs",
|
||||||
|
"require": "./dist/input-rule/index.cjs"
|
||||||
|
},
|
||||||
|
"./knock-test": {
|
||||||
|
"types": "./dist/knock-test/index.d.ts",
|
||||||
|
"import": "./dist/knock-test/index.mjs",
|
||||||
|
"require": "./dist/knock-test/index.cjs"
|
||||||
|
},
|
||||||
|
"./permission": {
|
||||||
|
"types": "./dist/permission/index.d.ts",
|
||||||
|
"import": "./dist/permission/index.mjs",
|
||||||
|
"require": "./dist/permission/index.cjs"
|
||||||
|
},
|
||||||
|
"./printer": {
|
||||||
|
"types": "./dist/printer/index.d.ts",
|
||||||
|
"import": "./dist/printer/index.mjs",
|
||||||
|
"require": "./dist/printer/index.cjs"
|
||||||
|
},
|
||||||
|
"./time": {
|
||||||
|
"types": "./dist/time/index.d.ts",
|
||||||
|
"import": "./dist/time/index.mjs",
|
||||||
|
"require": "./dist/time/index.cjs"
|
||||||
|
},
|
||||||
|
"./timer": {
|
||||||
|
"types": "./dist/timer/index.d.ts",
|
||||||
|
"import": "./dist/timer/index.mjs",
|
||||||
|
"require": "./dist/timer/index.cjs"
|
||||||
|
},
|
||||||
|
"./ui": {
|
||||||
|
"types": "./dist/ui/index.d.ts",
|
||||||
|
"import": "./dist/ui/index.mjs",
|
||||||
|
"require": "./dist/ui/index.cjs"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"utils",
|
"utils",
|
||||||
|
|
@ -44,9 +81,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"watch": "vite build --watch",
|
"watch": "vite build --watch",
|
||||||
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||||
"lint": "eslint --ext .js,ts --fix src",
|
"lint": "eslint --ext .js,ts --fix src",
|
||||||
"format": "prettier --write src",
|
"format": "prettier --write src",
|
||||||
"release": "standard-version",
|
|
||||||
"commit": "cz",
|
"commit": "cz",
|
||||||
"lint-staged": "lint-staged",
|
"lint-staged": "lint-staged",
|
||||||
"test": "vitest run"
|
"test": "vitest run"
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,10 @@ export function getValueOfRule(
|
||||||
/**
|
/**
|
||||||
* 根据输入的获取处理后值-文本类型
|
* 根据输入的获取处理后值-文本类型
|
||||||
*/
|
*/
|
||||||
function getTextTargetValue(innerValue: InputValue, options: InputOptions): InputValue {
|
function getTextTargetValue(
|
||||||
|
innerValue: InputValue,
|
||||||
|
options: InputOptions,
|
||||||
|
): InputValue {
|
||||||
const { required, init, pattern, number } = options;
|
const { required, init, pattern, number } = options;
|
||||||
|
|
||||||
innerValue ??= "";
|
innerValue ??= "";
|
||||||
|
|
@ -143,7 +146,10 @@ function applyPrecision(num: number, options: InputOptions): number {
|
||||||
/**
|
/**
|
||||||
* 根据输入的获取处理后值-数字类型
|
* 根据输入的获取处理后值-数字类型
|
||||||
*/
|
*/
|
||||||
function getNumberTargetValue(innerValue: InputValue, options: InputOptions): InputValue {
|
function getNumberTargetValue(
|
||||||
|
innerValue: InputValue,
|
||||||
|
options: InputOptions,
|
||||||
|
): InputValue {
|
||||||
const { number, keepDecimal, noSign, digits } = options;
|
const { number, keepDecimal, noSign, digits } = options;
|
||||||
const strValue = String(innerValue ?? "");
|
const strValue = String(innerValue ?? "");
|
||||||
|
|
||||||
|
|
@ -127,7 +127,7 @@ export class JpPrinter {
|
||||||
addText(content) {
|
addText(content) {
|
||||||
content = String(content);
|
content = String(content);
|
||||||
|
|
||||||
let code = [];
|
let code;
|
||||||
if (isAndroidApp) {
|
if (isAndroidApp) {
|
||||||
code = plus.android.invoke(content, "getBytes", "gbk");
|
code = plus.android.invoke(content, "getBytes", "gbk");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -254,8 +254,8 @@ export class JpPrinter {
|
||||||
let code = new TextEncoder("gb18030", {
|
let code = new TextEncoder("gb18030", {
|
||||||
NONSTANDARD_allowLegacyEncoding: true,
|
NONSTANDARD_allowLegacyEncoding: true,
|
||||||
}).encode(content);
|
}).encode(content);
|
||||||
const pL = parseInt((code.length + 3) % 256);
|
// const pL = parseInt((code.length + 3) % 256);
|
||||||
const pH = parseInt((code.length + 3) / 256);
|
// const pH = parseInt((code.length + 3) / 256);
|
||||||
this.data.push(29, 40, 107, 3, 0, 49, 69, ...code);
|
this.data.push(29, 40, 107, 3, 0, 49, 69, ...code);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -740,6 +740,7 @@ export class JpPrinter {
|
||||||
let ch = 0;
|
let ch = 0;
|
||||||
text.split("").forEach((c) => {
|
text.split("").forEach((c) => {
|
||||||
// 是否是汉字,汉字两倍宽
|
// 是否是汉字,汉字两倍宽
|
||||||
|
// eslint-disable-next-line no-control-regex
|
||||||
const isChinese = /[^\x00-\xff]/.test(c);
|
const isChinese = /[^\x00-\xff]/.test(c);
|
||||||
if (isChinese) {
|
if (isChinese) {
|
||||||
ch += 2;
|
ch += 2;
|
||||||
|
|
@ -984,10 +985,12 @@ export class JpPrinter {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
setBarcodeContent(t, content) {
|
setBarcodeContent(t) {
|
||||||
let ty = 73;
|
let ty = 73;
|
||||||
this.data.push(29);
|
this.data.push(29);
|
||||||
this.data.push(107);
|
this.data.push(107);
|
||||||
|
const bar = JpPrinter.bar;
|
||||||
|
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case bar[0]:
|
case bar[0]:
|
||||||
ty = 65;
|
ty = 65;
|
||||||
|
|
@ -1031,12 +1034,16 @@ export class JpPrinter {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Query {
|
export class Query {
|
||||||
|
constructor() {
|
||||||
|
this.queryStatus = new Query();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询打印机实时状态
|
* 查询打印机实时状态
|
||||||
* @param {*} n
|
* @param {*} n
|
||||||
* @param {*} device
|
* @param {*} device
|
||||||
*/
|
*/
|
||||||
getRealtimeStatusTransmission(n, device) {
|
getRealtimeStatusTransmission(n) {
|
||||||
/*
|
/*
|
||||||
n = 1:传送打印机状态
|
n = 1:传送打印机状态
|
||||||
n = 2:传送脱机状态
|
n = 2:传送脱机状态
|
||||||
|
|
@ -1048,7 +1055,7 @@ export class Query {
|
||||||
dateView.setUint8(0, 16);
|
dateView.setUint8(0, 16);
|
||||||
dateView.setUint8(1, 4);
|
dateView.setUint8(1, 4);
|
||||||
dateView.setUint8(2, n);
|
dateView.setUint8(2, n);
|
||||||
queryStatus.query(buf);
|
this.queryStatus.query(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
addGeneratePlus(n, m, t, device) {
|
addGeneratePlus(n, m, t, device) {
|
||||||
|
|
@ -1059,7 +1066,7 @@ export class Query {
|
||||||
dateView.setUint8(2, n);
|
dateView.setUint8(2, n);
|
||||||
dateView.setUint8(3, m);
|
dateView.setUint8(3, m);
|
||||||
dateView.setUint8(4, t);
|
dateView.setUint8(4, t);
|
||||||
queryStatus.query(buf, device);
|
this.queryStatus.query(buf, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
query(buf, device) {
|
query(buf, device) {
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,7 @@ export class TSCPlus extends TSC {
|
||||||
let ch = 0;
|
let ch = 0;
|
||||||
text.split("").forEach((c) => {
|
text.split("").forEach((c) => {
|
||||||
// 是否是汉字,汉字两倍宽
|
// 是否是汉字,汉字两倍宽
|
||||||
|
// eslint-disable-next-line no-control-regex
|
||||||
const isChinese = /[^\x00-\xff]/.test(c);
|
const isChinese = /[^\x00-\xff]/.test(c);
|
||||||
if (isChinese) {
|
if (isChinese) {
|
||||||
ch += 2;
|
ch += 2;
|
||||||
|
|
|
||||||
|
|
@ -417,7 +417,7 @@ export class TSC {
|
||||||
for (x = 0; x < w; x++) {
|
for (x = 0; x < w; x++) {
|
||||||
var color = bitmapData[(y * w + x) * 4 + 1];
|
var color = bitmapData[(y * w + x) * 4 + 1];
|
||||||
if (color <= 128) {
|
if (color <= 128) {
|
||||||
bits[parseInt(y * pitch + x / 8)] |= 0x80 >> x % 8;
|
bits[parseInt(y * pitch + x / 8)] |= 0x80 >> (x % 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,9 @@ describe("getValueOfRule - 文本模式 (text: true)", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("required + init:非数字文本回退到 init", () => {
|
test("required + init:非数字文本回退到 init", () => {
|
||||||
expect(getValueOfRule("abc", { ...textOpts, required: true, init: "默认" })).toBe("默认");
|
expect(
|
||||||
|
getValueOfRule("abc", { ...textOpts, required: true, init: "默认" }),
|
||||||
|
).toBe("默认");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("required 无 init:非数字文本保持原值", () => {
|
test("required 无 init:非数字文本保持原值", () => {
|
||||||
|
|
@ -29,7 +31,9 @@ describe("getValueOfRule - 文本模式 (text: true)", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("pattern 匹配成功返回原值", () => {
|
test("pattern 匹配成功返回原值", () => {
|
||||||
expect(getValueOfRule("123", { ...textOpts, pattern: "^\\d+$" })).toBe("123");
|
expect(getValueOfRule("123", { ...textOpts, pattern: "^\\d+$" })).toBe(
|
||||||
|
"123",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -107,7 +111,9 @@ describe("getValueOfRule - digits 小数位数", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("keepDecimal + number 返回数字类型", () => {
|
test("keepDecimal + number 返回数字类型", () => {
|
||||||
expect(getValueOfRule("3.10", { digits: 2, keepDecimal: true, number: true })).toBe(3.1);
|
expect(
|
||||||
|
getValueOfRule("3.10", { digits: 2, keepDecimal: true, number: true }),
|
||||||
|
).toBe(3.1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -127,11 +133,15 @@ describe("getValueOfRule - integer 整数模式", () => {
|
||||||
|
|
||||||
describe("getValueOfRule - noSign 不允许正负号", () => {
|
describe("getValueOfRule - noSign 不允许正负号", () => {
|
||||||
test("带正号的输入被视为非法", () => {
|
test("带正号的输入被视为非法", () => {
|
||||||
expect(getValueOfRule("+5", { noSign: true, required: true, init: 0 })).toBe("0");
|
expect(
|
||||||
|
getValueOfRule("+5", { noSign: true, required: true, init: 0 }),
|
||||||
|
).toBe("0");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("带负号的输入被视为非法", () => {
|
test("带负号的输入被视为非法", () => {
|
||||||
expect(getValueOfRule("-5", { noSign: true, required: true, init: 0 })).toBe("0");
|
expect(
|
||||||
|
getValueOfRule("-5", { noSign: true, required: true, init: 0 }),
|
||||||
|
).toBe("0");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("无符号数字正常通过", () => {
|
test("无符号数字正常通过", () => {
|
||||||
|
|
@ -142,25 +152,45 @@ describe("getValueOfRule - noSign 不允许正负号", () => {
|
||||||
describe("getValueOfRule - callback", () => {
|
describe("getValueOfRule - callback", () => {
|
||||||
test("callback 接收最终处理后的值", () => {
|
test("callback 接收最终处理后的值", () => {
|
||||||
let received: unknown;
|
let received: unknown;
|
||||||
getValueOfRule("42", { number: true }, (v) => { received = v; });
|
getValueOfRule("42", { number: true }, (v) => {
|
||||||
|
received = v;
|
||||||
|
});
|
||||||
expect(received).toBe(42);
|
expect(received).toBe(42);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getValueOfRule - 综合场景", () => {
|
describe("getValueOfRule - 综合场景", () => {
|
||||||
test("限制输入 min:0, max:99999.99, required, digits:2", () => {
|
test("限制输入 min:0, max:99999.99, required, digits:2", () => {
|
||||||
expect(getValueOfRule("100.456", { min: 0, max: 99999.99, required: true, digits: 2 })).toBe("100.46");
|
expect(
|
||||||
|
getValueOfRule("100.456", {
|
||||||
|
min: 0,
|
||||||
|
max: 99999.99,
|
||||||
|
required: true,
|
||||||
|
digits: 2,
|
||||||
|
}),
|
||||||
|
).toBe("100.46");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("超出 max 时截断到 max", () => {
|
test("超出 max 时截断到 max", () => {
|
||||||
expect(getValueOfRule("100000", { min: 0, max: 99999.99, required: true, digits: 2 })).toBe("99999.99");
|
expect(
|
||||||
|
getValueOfRule("100000", {
|
||||||
|
min: 0,
|
||||||
|
max: 99999.99,
|
||||||
|
required: true,
|
||||||
|
digits: 2,
|
||||||
|
}),
|
||||||
|
).toBe("99999.99");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("空输入 required 回退到 min", () => {
|
test("空输入 required 回退到 min", () => {
|
||||||
expect(getValueOfRule("", { min: 0, max: 99999.99, required: true, digits: 2 })).toBe("0");
|
expect(
|
||||||
|
getValueOfRule("", { min: 0, max: 99999.99, required: true, digits: 2 }),
|
||||||
|
).toBe("0");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("负数输入限制到 min:0", () => {
|
test("负数输入限制到 min:0", () => {
|
||||||
expect(getValueOfRule("-5", { min: 0, max: 100, required: true })).toBe("0");
|
expect(getValueOfRule("-5", { min: 0, max: 100, required: true })).toBe(
|
||||||
|
"0",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.base.json",
|
||||||
"exclude": ["node_modules", "dist"],
|
"exclude": ["node_modules", "dist"],
|
||||||
"include": ["src/**/*.ts"],
|
"include": ["src/**/*.ts", "types/**/*.d.ts"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,338 @@
|
||||||
|
export function row2col(arr: any): any;
|
||||||
|
/**
|
||||||
|
* NOTE 打印机普通文本最大宽度32个数字,16个汉字超出换行
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export class JpPrinter {
|
||||||
|
static bar: string[];
|
||||||
|
/**
|
||||||
|
* 获取文本宽度点数
|
||||||
|
* @param {string} text
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static getTextDots(text: string): number;
|
||||||
|
/**
|
||||||
|
* 根据最大点数获取文本
|
||||||
|
* @param {string} text
|
||||||
|
* @param {number} maxDots
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
static getMaxText(text?: string, maxDots?: number): string;
|
||||||
|
/**
|
||||||
|
* 分割字符
|
||||||
|
* "123456789" => ["1234", "5678", "9"]
|
||||||
|
* @param {string} str
|
||||||
|
* @param {number} maxDots
|
||||||
|
* @return {string[]}
|
||||||
|
*/
|
||||||
|
static splitString(str: string, maxDots: number): string[];
|
||||||
|
static createDefaultPrinter(): JpPrinter;
|
||||||
|
static getQuery(): Query;
|
||||||
|
constructor(width?: number, dpi?: number);
|
||||||
|
name: string;
|
||||||
|
data: any[];
|
||||||
|
align: string;
|
||||||
|
bold: boolean;
|
||||||
|
lineSpacing: number;
|
||||||
|
fontSize: number;
|
||||||
|
/** 有效打印宽度 */
|
||||||
|
width: number;
|
||||||
|
dpi: number;
|
||||||
|
_layout: null;
|
||||||
|
storeLayout(): this;
|
||||||
|
restoreLayout(): this;
|
||||||
|
getXDots(): number;
|
||||||
|
/** 初始化打印机 */
|
||||||
|
init(): this;
|
||||||
|
/**
|
||||||
|
* 添加文本内容
|
||||||
|
* @param {string} content
|
||||||
|
*/
|
||||||
|
addText(content: string): this;
|
||||||
|
/**
|
||||||
|
* GS ! 选择字符大小
|
||||||
|
* @param {number} n 放大倍数
|
||||||
|
* */
|
||||||
|
setFontSize(n?: number): this;
|
||||||
|
/**
|
||||||
|
* ESC E 选择/取消加粗模式
|
||||||
|
* @param {boolean} bold
|
||||||
|
* */
|
||||||
|
setBold(bold: boolean): this;
|
||||||
|
/**
|
||||||
|
* ESC – 选择/取消下划线模式
|
||||||
|
* 根据 n 的值选择或取消下划线模式:
|
||||||
|
* • 下划线可加在所有字符下(包括右间距),但不包括 HT 设置的空格。
|
||||||
|
* • 下划线不能作用在顺时针旋转 90°和反色的字符下。
|
||||||
|
* • 当取消下划线模式时,后面的字符不加下划线,下划线的宽度不改变。默认宽度是一点宽。
|
||||||
|
* • 改变字符大小不影响当前下划线宽度。
|
||||||
|
* • 下划线选择取消也可以由 ESC !来设置,最后执行的命令有效。
|
||||||
|
* • 该命令不影响汉字字符的设定。
|
||||||
|
* @param {number} n
|
||||||
|
* 0, 48 取消下划线模式
|
||||||
|
* 1, 49 选择下划线模式(1 点宽)
|
||||||
|
* 2, 50 选择下划线模式(2 点宽)
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
setUnderline(n?: number): this;
|
||||||
|
/**
|
||||||
|
* FS - 选择/取消汉字下划线模式
|
||||||
|
* 根据 n 的值,选择或取消汉字的下划线
|
||||||
|
* • 打印机能对所有字符加下划线,包括左右间距。但不能对由 HT 命令(横向跳格)引起的空格加下划线,也不对顺时针旋转 90 度的字符加下划线。
|
||||||
|
* • 消下划线模式后,不再执行下划线打印,但原先设置的下划线线宽不会改变。默认下划线线宽为 1 点。
|
||||||
|
* • 即使改变字符大小,设定的下划线线宽也不会改变。
|
||||||
|
* • 用 FS !也可选择或取消下划线模式,最后一条命令有效。
|
||||||
|
* @param {*} n
|
||||||
|
* 0, 48 取消汉字下划线
|
||||||
|
* 1, 49 选择汉字下划线(1 点宽)
|
||||||
|
* 2, 50 选择汉字下划线(2 点宽
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
setUnderlineChinese(n?: any): this;
|
||||||
|
/**
|
||||||
|
* 设置二维码大小
|
||||||
|
* @param {*} n
|
||||||
|
* @see {JpPrinter#setQRCodeSize}
|
||||||
|
*/
|
||||||
|
setSelectSizeOfModuleForQRCode(n: any): this;
|
||||||
|
/**
|
||||||
|
* 设置 QRCode 模块大小为 n dot
|
||||||
|
* @param {number} n
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
setQRCodeSize(n: number): this;
|
||||||
|
/**
|
||||||
|
* 选择 QRCode 纠错等级
|
||||||
|
* @see {JpPrinter#setQRCodeErrorCorrectionLevel}
|
||||||
|
*/
|
||||||
|
setSelectErrorCorrectionLevelForQRCode(n: any): this;
|
||||||
|
/**
|
||||||
|
* 选择 QRCode 纠错等级
|
||||||
|
* n 功能 纠错能力
|
||||||
|
* 48 选择纠错等级 L 7
|
||||||
|
* 49 选择纠错等级 M 15
|
||||||
|
* 50 选择纠错等级 Q 25
|
||||||
|
* 51 选择纠错等级 H 30
|
||||||
|
* @see
|
||||||
|
*/
|
||||||
|
setQRCodeErrorCorrectionLevel(n: any): this;
|
||||||
|
/** 设置二维码内容 */
|
||||||
|
setStoreQRCodeData(content: any): this;
|
||||||
|
/**
|
||||||
|
* 打印二维码
|
||||||
|
* @deprecated
|
||||||
|
* @see {JpPrinter#printQRCode}
|
||||||
|
* */
|
||||||
|
setPrintQRCode(): this;
|
||||||
|
/** 打印二维码 */
|
||||||
|
printQRCode(): this;
|
||||||
|
addQrCodeByUrl(url: any, width: any, height: any): this;
|
||||||
|
addImageByUrl(url: any, width: any, height: any): this;
|
||||||
|
addQrCodeByText(contents: any, width: any, height: any): this;
|
||||||
|
/**
|
||||||
|
* HT 水平定位
|
||||||
|
* 移动打印位置到下一个水平定位点的位置。
|
||||||
|
* @deprecated
|
||||||
|
* @see {JpPrinter#addHorTab}
|
||||||
|
*/
|
||||||
|
setHorTab(): this;
|
||||||
|
/**
|
||||||
|
* HT 水平定位
|
||||||
|
* 移动打印位置到下一个水平定位点的位置。
|
||||||
|
*/
|
||||||
|
addHorTab(): this;
|
||||||
|
/**
|
||||||
|
* ESC $ 设置绝对打印位置
|
||||||
|
* @param {number} where
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
setAbsolutePrintPosition(where: number): this;
|
||||||
|
/**
|
||||||
|
* ESC \ 设置相对横向打印位置
|
||||||
|
* 安卓无法传入超过127的数
|
||||||
|
*
|
||||||
|
* @param {number} where
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
setRelativePrintPosition(where: number): this;
|
||||||
|
/**
|
||||||
|
* ESC a 选择对齐方式
|
||||||
|
* @param {number} n
|
||||||
|
* 0, 48 左对齐
|
||||||
|
* 1, 49 中间对齐
|
||||||
|
* 2, 50 右对齐
|
||||||
|
*/
|
||||||
|
setSelectJustification(n: number): this;
|
||||||
|
/**
|
||||||
|
* 设置对齐方式
|
||||||
|
* @param {string} align
|
||||||
|
* "l" 左对齐
|
||||||
|
* "m" 中间对齐
|
||||||
|
* "r" 右对齐
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
setAlign(align: string): this;
|
||||||
|
/**
|
||||||
|
* ESC D 设置横向跳格位
|
||||||
|
* @param {number} n
|
||||||
|
* @deprecated
|
||||||
|
* @see {}
|
||||||
|
*/
|
||||||
|
space(...nk: any[]): this;
|
||||||
|
/**
|
||||||
|
* ESC D 设置横向跳格位
|
||||||
|
* @param {number} n
|
||||||
|
*/
|
||||||
|
addSpace(...nk: any[]): this;
|
||||||
|
/**
|
||||||
|
* GS L 设置左边距
|
||||||
|
* @param {number} n
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
setLeftMargin(n: number): this;
|
||||||
|
textMarginRight(n: any): this;
|
||||||
|
/**
|
||||||
|
* ESC 3 设置行间距
|
||||||
|
* @deprecated
|
||||||
|
* @see {JpPrinter#setLineSpacing}
|
||||||
|
* */
|
||||||
|
rowSpace(n: any): this;
|
||||||
|
/**
|
||||||
|
* ESC 3 设置行间距
|
||||||
|
* */
|
||||||
|
setLineSpacing(n: any): this;
|
||||||
|
/**
|
||||||
|
* GS W 设置打印区域宽度
|
||||||
|
* @param {number} width
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
setPrintingAreaWidth(width: number): this;
|
||||||
|
setSound(n: any, t: any): this;
|
||||||
|
setBitmap(res: any): this;
|
||||||
|
/**
|
||||||
|
* 添加位图 GS v 0
|
||||||
|
* */
|
||||||
|
addBitmap(m: any, xL: any, xH: any, yL: any, yH: any, ...data: any[]): this;
|
||||||
|
/**
|
||||||
|
* 添加位图
|
||||||
|
* @param {Uint8ClampedArray} imgData
|
||||||
|
* @param {number} width
|
||||||
|
* @param {number} height
|
||||||
|
*/
|
||||||
|
addBitmapHelper(imgData: Uint8ClampedArray, width: number, height: number): this;
|
||||||
|
/**
|
||||||
|
* 打印并换行
|
||||||
|
* */
|
||||||
|
addLF(): this;
|
||||||
|
/**
|
||||||
|
* ESC J 打印并走纸 n 个单位
|
||||||
|
* @param {number} n
|
||||||
|
* @see {JpPrinter#addPrintAndFeed}
|
||||||
|
*/
|
||||||
|
setPrintAndFeed(n: number): this;
|
||||||
|
/**
|
||||||
|
* ESC J 打印并走纸 n 个单位
|
||||||
|
* @param {number} n
|
||||||
|
*/
|
||||||
|
addPrintAndFeed(n: number): this;
|
||||||
|
/**
|
||||||
|
* ESC d 打印并走纸 n 行
|
||||||
|
* @param {number} n
|
||||||
|
* @see {JpPrinter#addPrintAndFeedRow}
|
||||||
|
*/
|
||||||
|
setPrintAndFeedRow(n: number): this;
|
||||||
|
/**
|
||||||
|
* ESC d 打印并走纸 n 行
|
||||||
|
* @param {number} n
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
addPrintAndFeedRow(n: number): this;
|
||||||
|
/**
|
||||||
|
* 添加 n 行
|
||||||
|
* @param {number} n
|
||||||
|
* @see {JpPrinter#addPrintAndFeedRow}
|
||||||
|
*/
|
||||||
|
addRow(n: number): this;
|
||||||
|
/**
|
||||||
|
* 添加打印指令数据
|
||||||
|
* @param {number[]} data
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
addData(...data: number[]): this;
|
||||||
|
/**
|
||||||
|
* 获取打印指令数据
|
||||||
|
*/
|
||||||
|
getData(): any[];
|
||||||
|
/*********************** 自增 ***********************/
|
||||||
|
/**
|
||||||
|
* 计算文字位置
|
||||||
|
* @param {*} value
|
||||||
|
* @param {*} width
|
||||||
|
* @deprecated
|
||||||
|
* @see {JpPrinter#getTextDots}
|
||||||
|
*/
|
||||||
|
siteText(value: any, width: any): number;
|
||||||
|
/**
|
||||||
|
* 计算数字位置
|
||||||
|
* @param {*} value
|
||||||
|
* @param {*} width
|
||||||
|
* @deprecated
|
||||||
|
* @see {JpPrinter#getTextDots}
|
||||||
|
*/
|
||||||
|
siteNumber(value: any, width: any): number;
|
||||||
|
/**
|
||||||
|
* 左对齐文字
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
alignLeft(name: any, text: any, arr: any): this;
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* @see {JpPrinter.getTextDots}
|
||||||
|
*/
|
||||||
|
getTextDots(text: any): number;
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* @see {JpPrinter.getMaxText}
|
||||||
|
*/
|
||||||
|
getMaxText(text?: string, maxDots?: number): string;
|
||||||
|
/**
|
||||||
|
* 添加两端对齐的文字
|
||||||
|
*/
|
||||||
|
addTextJustifyAlign(text1: any, text2: any): this;
|
||||||
|
/**
|
||||||
|
* 添加分割线
|
||||||
|
*/
|
||||||
|
addDivider(): this;
|
||||||
|
/**
|
||||||
|
* 添加表格
|
||||||
|
* @param {Object} table
|
||||||
|
* @param {Array} table.header
|
||||||
|
* @param {Array} table.data
|
||||||
|
* @param {number[]} [table.columns] 每列百分比
|
||||||
|
*/
|
||||||
|
addTable({ header, data, columns }: {
|
||||||
|
header: any[];
|
||||||
|
data: any[];
|
||||||
|
columns?: number[] | undefined;
|
||||||
|
}): this;
|
||||||
|
/**
|
||||||
|
* 分割符
|
||||||
|
* @deprecated
|
||||||
|
* @see {JpPrinter#addDivider}
|
||||||
|
*/
|
||||||
|
separator(width: any): this;
|
||||||
|
setBarcodeWidth(width: any): this;
|
||||||
|
setBarcodeHeight(height: any): this;
|
||||||
|
setBarcodeContent(t: any): this;
|
||||||
|
}
|
||||||
|
export class Query {
|
||||||
|
queryStatus: Query;
|
||||||
|
/**
|
||||||
|
* 查询打印机实时状态
|
||||||
|
* @param {*} n
|
||||||
|
* @param {*} device
|
||||||
|
*/
|
||||||
|
getRealtimeStatusTransmission(n: any): void;
|
||||||
|
addGeneratePlus(n: any, m: any, t: any, device: any): void;
|
||||||
|
query(buf: any, device: any): void;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
export class TSCPlus extends TSC {
|
||||||
|
static MILLIMETERS_PER_INCH: number;
|
||||||
|
static getLetterWidthDot(font: any): number;
|
||||||
|
static getFontLineHeightDot(font: any, lineHeight: any): any;
|
||||||
|
/**
|
||||||
|
* 获取文本宽度点数
|
||||||
|
* @param {string} text
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
static getTextDots(text: string, letterDots?: number): number;
|
||||||
|
/**
|
||||||
|
* 根据最大点数获取文本
|
||||||
|
* @param {string} text
|
||||||
|
* @param {number} maxDots
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
static getMaxText(text?: string, maxDots?: number): string;
|
||||||
|
/**
|
||||||
|
* 分割字符串
|
||||||
|
* "123456789" => ["1234", "5678", "9"]
|
||||||
|
* @param {string} str
|
||||||
|
* @param {number} maxDots
|
||||||
|
* @return {string[]}
|
||||||
|
*/
|
||||||
|
static splitString(str: string, maxDots: number): string[];
|
||||||
|
font: string;
|
||||||
|
lineHeight: string;
|
||||||
|
dpi: number;
|
||||||
|
nextX: number;
|
||||||
|
nextY: number;
|
||||||
|
widthDot: number;
|
||||||
|
heightDot: number;
|
||||||
|
paddingTopDot: number;
|
||||||
|
paddingLeftDot: number;
|
||||||
|
paddingRightDot: number;
|
||||||
|
paddingBottomDot: number;
|
||||||
|
/**
|
||||||
|
* 设置内边距
|
||||||
|
* @param {number} paddingTopDot
|
||||||
|
* @param {number} paddingRightDot
|
||||||
|
* @param {number} paddingBottomDot
|
||||||
|
* @param {number} paddingLeftDot
|
||||||
|
*/
|
||||||
|
setPadding(paddingTopDot: number, paddingRightDot: number, paddingBottomDot: number, paddingLeftDot: number): void;
|
||||||
|
mmToDot(mm: any): number;
|
||||||
|
setDpi(dpi: any): void;
|
||||||
|
setSize(w: any, h: any): TSC;
|
||||||
|
setSizeMM(w: any, h: any): TSC;
|
||||||
|
setSizeDot(w: any, h: any): TSC;
|
||||||
|
/**
|
||||||
|
* 设置字体
|
||||||
|
* @param {string} font
|
||||||
|
*/
|
||||||
|
setFont(font: string): void;
|
||||||
|
/**
|
||||||
|
* 设置行高
|
||||||
|
* @param {string|number} lineHeight
|
||||||
|
*/
|
||||||
|
setLineHeight(lineHeight: string | number): void;
|
||||||
|
addTextLn(text: any, options?: {}): this;
|
||||||
|
addAddBarCode(content: any, options?: {}): this;
|
||||||
|
}
|
||||||
|
import { TSC } from "./tsc.js";
|
||||||
|
|
@ -0,0 +1,369 @@
|
||||||
|
export class TSC {
|
||||||
|
static LINE_BREAK: string;
|
||||||
|
constructor(data?: any[]);
|
||||||
|
data: any[];
|
||||||
|
addData(...data: any[]): void;
|
||||||
|
addDataArray(dataArray: any): void;
|
||||||
|
addCode(code: any): this;
|
||||||
|
getData: () => any;
|
||||||
|
/**
|
||||||
|
* 该指令用于设定卷标纸的宽度和长度
|
||||||
|
* @param {number|string} w 标签宽度 单位英寸inch
|
||||||
|
* @param {number|string} h 标签高度 单位英寸inch
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setSize(w: number | string, h: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于设定卷标纸的宽度和长度
|
||||||
|
* @param {number|string} w 标签宽度 单位毫米mm
|
||||||
|
* @param {number|string} h 标签高度 单位毫米mm
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setSizeMM(w: number | string, h: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于定义两张卷标纸间的垂直间距距离
|
||||||
|
* @param {number|string} m 两标签纸中间的垂直距离 单位英寸inch
|
||||||
|
* @param {number|string} n 垂直间距偏移 单位英寸inch
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setGap(m?: number | string, n?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于定义两张卷标纸间的垂直间距距离
|
||||||
|
* @param {number|string} m 两标签纸中间的垂直距离 单位毫米mm
|
||||||
|
* @param {number|string} n 垂直间距偏移 单位毫米mm
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setGapMM(m?: number | string, n?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于设定黑标高度及定义标签印完后标签额外送出的长度
|
||||||
|
* @param {number|string} m 黑标高度 单位英寸inch
|
||||||
|
* @param {number|string} n 额外送出纸张长度 单位英寸inch
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setBLine(m?: number | string, n?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于控制在剥离模式时(peel-off mode)每张卷标停止的位置,
|
||||||
|
* 在打印下一张时打印机会将原先多推出或少推出的部分以回拉方式补偿回来。
|
||||||
|
* 该指令仅适用于剥离模式。
|
||||||
|
* @param {number|string} m 纸张停止的距离 单位英寸inch
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setOffset(offset?: number): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于控制打印速度
|
||||||
|
* @param {number|string} speed 打印速度
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setSpeed(speed?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于控制打印时的浓度
|
||||||
|
* @param {number|string} density 打印浓度
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setDensity(density?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于定义打印时出纸和打印字体的方向
|
||||||
|
* @param {number|string} direction
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setDirection(direction?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于定义卷标的参考坐标原点。坐标原点位置和打印方向有关
|
||||||
|
* @param {number|string} x 水平方向的坐标位置,单位dot
|
||||||
|
* @param {number|string} y 垂直方向的坐标位置,单位dot
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setReference(x?: number | string, y?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令表示标签打印偏移量多少设置
|
||||||
|
* @param {number|string} n 打印偏移量
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setShift(n?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于选择对应的国际字符集
|
||||||
|
* 001:USA
|
||||||
|
* 002:French
|
||||||
|
* 003:Latin America
|
||||||
|
* 034:Spanish
|
||||||
|
* 039:Italian
|
||||||
|
* 044:United Kingdom
|
||||||
|
* 046:Swedish
|
||||||
|
* 047:Norwegian
|
||||||
|
* 049:German
|
||||||
|
* @param {number|string} country 字符集
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setCountry(country?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于选择对应的国际代码页
|
||||||
|
* 8-bit codepage 字符集代表
|
||||||
|
* 437:United States
|
||||||
|
* 850:Multilingual
|
||||||
|
* 852:Slavic
|
||||||
|
* 860:Portuguese
|
||||||
|
* 863:Canadian/French
|
||||||
|
* 865:Nordic
|
||||||
|
*
|
||||||
|
* Windows code page
|
||||||
|
* 1250:Central Europe
|
||||||
|
* 1252:Latin I
|
||||||
|
* 1253:Greek
|
||||||
|
* 1254:Turkish
|
||||||
|
*
|
||||||
|
* 以下代码页仅限于12×24 dot 英数字体
|
||||||
|
* WestEurope:WestEurope
|
||||||
|
* Greek:Greek
|
||||||
|
* Hebrew:Hebrew
|
||||||
|
* EastEurope:EastEurope
|
||||||
|
* Iran:Iran
|
||||||
|
* IranII:IranII
|
||||||
|
* Latvian:Latvian
|
||||||
|
* Arabic:Arabic
|
||||||
|
* Vietnam:Vietnam
|
||||||
|
* Uygur:Uygur
|
||||||
|
* Thai:Thai
|
||||||
|
* 1252:Latin I
|
||||||
|
* 1257:WPC1257
|
||||||
|
* 1251:WPC1251
|
||||||
|
* 866:Cyrillic
|
||||||
|
* 858:PC858
|
||||||
|
* 747:PC747
|
||||||
|
* 864:PC864
|
||||||
|
* 1001:PC1001
|
||||||
|
* @param {number|string} n 代码页
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setCodepage(n?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于清除图像缓冲区(image buffer)的数据
|
||||||
|
* 注:此项指令必须置于 SIZE 指令之后
|
||||||
|
* @param {number|string} n 代码页
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setCls(): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于将标签纸向前推送指定的长度
|
||||||
|
* 打印机分辨率200 DPI:1 mm = 8 dots
|
||||||
|
* 打印机分辨率300 DPI:1 mm = 12 dots
|
||||||
|
* @param {number|string} n 1≤n≤9999,单位dot
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setFeed(n: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于将标签纸向前推送指定的长度
|
||||||
|
* 打印机分辨率200 DPI:1 mm = 8 dots
|
||||||
|
* 打印机分辨率300 DPI:1 mm = 12 dots
|
||||||
|
* @param {number|string} n 1≤n≤9999,单位dot
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setBackFeed(n: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于将标签纸向前推送指定的长度
|
||||||
|
* 打印机分辨率200 DPI:1 mm = 8 dots
|
||||||
|
* 打印机分辨率300 DPI:1 mm = 12 dots
|
||||||
|
* @param {number|string} n 1≤n≤9999,单位dot
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setBackUp(n: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于控制打印机进一张标签纸
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setFromFeed(): TSC;
|
||||||
|
/**
|
||||||
|
* 在使用含有间隙或黑标的标签纸时,
|
||||||
|
* 若不能确定第一张标签纸是否在正确打印位置时,
|
||||||
|
* 此指令可将标签纸向前推送至下一张标签纸的起点开始打印。
|
||||||
|
* 标签尺寸和间隙需要在本条指令前设置
|
||||||
|
* 注:使用该指令时,纸张高度大于或等于30 mm
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setHome(): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于打印出存储于影像缓冲区内的数据
|
||||||
|
* @param {number|string} m 指定打印的份数(set)
|
||||||
|
* @param {number|string} n 每张标签需重复打印的张数
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setPrint(m?: number | string, n?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于控制蜂鸣器的频率,可设定10阶的声音,
|
||||||
|
* 频率,可设定10阶的声音,每阶声音的长短由第二个参数控制
|
||||||
|
* @param {number|string} m 指定打印的份数(set)
|
||||||
|
* @param {number|string} n 每张标签需重复打印的张数
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setSound(level?: number, interval?: number): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于设定打印机进纸时,若经过所设定的长度仍无法侦测到垂直间距,
|
||||||
|
* 则打印机在连续纸模式工作。
|
||||||
|
* @param {number|string} limit 英制系统(inch)
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setLimitFeed(limit?: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 不经自测动作,直接打印自检页信息。
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setSelfTest(): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于在标签上画线
|
||||||
|
* @param {number|string} x 线条左上角X坐标,单位dot
|
||||||
|
* @param {number|string} y 线条左上角Y坐标,单位dot
|
||||||
|
* @param {number|string} width 线宽,单位dot
|
||||||
|
* @param {number|string} height 线高,单位dot
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setBar(x: number | string, y: number | string, width: number | string, height: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于在标签上画线
|
||||||
|
* @param {number|string} x 线条左上角X坐标,单位dot
|
||||||
|
* @param {number|string} y 线条左上角Y坐标,单位dot
|
||||||
|
* @param {number|string} codeType 线宽,单位dot
|
||||||
|
* @param {number|string} height 条形码高度,以点(dot)表示
|
||||||
|
* @param {number|string} readable 0 表示人眼不可识,1表示人眼可识
|
||||||
|
* @param {number|string} rotation 条形码旋转角度,顺时针方向
|
||||||
|
* @param {number|string} narrow 窄bar宽度,以点(dot)表示
|
||||||
|
* @param {number|string} wide 宽bar宽度,以点(dot)表示
|
||||||
|
* @param {number|string} content 内容
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setBarCode(x: number | string, y: number | string, codeType: number | string | undefined, height: number | string | undefined, readable: number | string | undefined, rotation: number | string | undefined, narrow: number | string | undefined, wide: number | string | undefined, content: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于在卷标上绘制矩形方框
|
||||||
|
* @param {number|string} x1 线条左上角X坐标,单位dot
|
||||||
|
* @param {number|string} y1 线条左上角Y坐标,单位dot
|
||||||
|
* @param {number|string} x2 方框右下角X坐标,单位dot
|
||||||
|
* @param {number|string} y2 方框右下角Y坐标,单位dot
|
||||||
|
* @param {number|string} thickness 方框线宽,单位dot
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setBox(x1: number | string, y1: number | string, x2: number | string, y2: number | string, thickness: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于在卷标上绘制位图(非BMP格式图档)
|
||||||
|
* @param {number|string} x 线条左上角X坐标,单位dot
|
||||||
|
* @param {number|string} y 线条左上角Y坐标,单位dot
|
||||||
|
* @param {number|string} width 方框右下角X坐标,单位dot
|
||||||
|
* @param {number|string} height 方框右下角Y坐标,单位dot
|
||||||
|
* @param {number|string} mode 方框线宽,单位dot
|
||||||
|
* @param {number|string} bitmapData 方框线宽,单位dot
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setBitmap(x: number | string, y: number | string, width: number | string, height: number | string, mode: number | string, bitmapData: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于清除影像缓冲区部分区域的数据
|
||||||
|
* @param {number|string} x 清除区域的左上角X座标,单位dot
|
||||||
|
* @param {number|string} y 清除区域的左上角Y座标,单位dot
|
||||||
|
* @param {number|string} width 清除区域宽度,单位dot
|
||||||
|
* @param {number|string} height 清除区域高度,单位dot
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setErase(x: number | string, y: number | string, width: number | string, height: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 将指定的区域反相打印
|
||||||
|
* @param {number|string} x 反相区域的左上角X座标,单位dot
|
||||||
|
* @param {number|string} y 反相区域的左上角Y座标,单位dot
|
||||||
|
* @param {number|string} width 反相区域宽度,单位dot
|
||||||
|
* @param {number|string} height 反相区域高度,单位dot
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setReverse(x: number | string, y: number | string, width: number | string, height: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用于打印字符串
|
||||||
|
* @param {number|string} x 文字X方向起始点坐标
|
||||||
|
* @param {number|string} y 文字Y方向起始点坐标
|
||||||
|
* @param {number|string} font 字体名称
|
||||||
|
* @param {number|string} sx X 方向放大倍率1-10
|
||||||
|
* @param {number|string} sy Y 方向放大倍率1-10
|
||||||
|
* @param {number|string} content 内容
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setText(x: number | string, y: number | string, font: number | string, rotation: any, sx: number | string, sy: number | string, content: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用来打印二维码
|
||||||
|
* @param {number|string} x 二维码水平方向起始点坐标
|
||||||
|
* @param {number|string} y 反相区域的左上角Y座标,单位dot
|
||||||
|
* @param {number|string} level 选择QRCODE纠错等级
|
||||||
|
* @param {number|string} width 二维码宽度1-10
|
||||||
|
* @param {number|string} mode 手动/自动编码
|
||||||
|
* @param {number|string} rotation 旋转角度(顺时针方向)
|
||||||
|
* @param {number|string} content 内容
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setQrcode(x: number | string, y: number | string, level: number | string, width: number | string, mode: number | string, rotation: number | string, content: number | string): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用来起动Key1 的预设功能
|
||||||
|
* 预设为进纸功能
|
||||||
|
* @param {"ON"|"OFF"} k 开启按键/关闭按键
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setKey1(k: "ON" | "OFF"): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用来起动Key2 的预设功能
|
||||||
|
* 预设为暂停功能
|
||||||
|
* @param {"ON"|"OFF"} k 开启按键/关闭按键
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setKey2(k: "ON" | "OFF"): TSC;
|
||||||
|
/**
|
||||||
|
* 该指令用来启动/关闭剥离模式,默认值为关闭
|
||||||
|
* @param {"ON"|"OFF"} k 开启按键/关闭按键
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setPeel(k: "ON" | "OFF"): TSC;
|
||||||
|
/**
|
||||||
|
* 此命令是用来启用/禁用撕纸位置走到撕纸处,此设置关掉电源后将保存在打印机内
|
||||||
|
* @param {"ON"|"OFF"} k 开启按键/关闭按键
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setTear(k: "ON" | "OFF"): TSC;
|
||||||
|
/**
|
||||||
|
* 此命令是用来启用/禁用撕纸位置走到撕纸处,此设置关掉电源后将保存在打印机内
|
||||||
|
* @param {"ON"|"OFF"} k 开启按键/关闭按键
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setStripper(k: "ON" | "OFF"): TSC;
|
||||||
|
/**
|
||||||
|
* 此设置用于启用/禁用打印头合盖传感器。如果禁用合盖传感器,打印机头被打开时,将不会传回错误信息。
|
||||||
|
* 此设置将保存在打印机内存。
|
||||||
|
* @param {"ON"|"OFF"} k 开启按键/关闭按键
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setHead(k: "ON" | "OFF"): TSC;
|
||||||
|
/**
|
||||||
|
* 此设置用于启用/禁用打印头合盖传感器。如果禁用合盖传感器,打印机头被打开时,将不会传回错误信息。
|
||||||
|
* 此设置将保存在打印机内存。
|
||||||
|
* @param {"ON"|"OFF"|"AUTO"|string|number} k 开启按键/关闭按键
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setHead2(k: "ON" | "OFF" | "AUTO" | string | number): TSC;
|
||||||
|
/**
|
||||||
|
* 此命令将禁用/启用标签机在无纸或开盖错误发生后,
|
||||||
|
* 上纸或合盖后重新打印一次标签内容
|
||||||
|
* @param {"ON"|"OFF"} k 开启按键/关闭按键
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setReprint(k: "ON" | "OFF"): TSC;
|
||||||
|
/**
|
||||||
|
* 设定开启/关闭碳带感应器,即切换热转式/热感印式打印。通常打印机于开启电源时,
|
||||||
|
* 碳带感应器即会自动检测打印机是否已装上碳带,并藉此决定使用热感式或热转式打印。
|
||||||
|
* 此项设定并不会存于打印机中。此方法仅适用于热转式机器。
|
||||||
|
* @param {"ON"|"OFF"} k 开启按键/关闭按键
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setRibbon(k: "ON" | "OFF"): TSC;
|
||||||
|
/**
|
||||||
|
* 此命令用于设置切刀状态,关闭打印机电源后,该设置将会被存储在打印机内存中。
|
||||||
|
* @param {"OFF"|"BATCH"|string|number} k 开启按键/关闭按键
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setCutter(k: "OFF" | "BATCH" | string | number): TSC;
|
||||||
|
/**
|
||||||
|
* 此指令用于设置打印机自动返回状态
|
||||||
|
* @param {"ON"|"OFF"|"BATCH"} k 开启按键/关闭按键
|
||||||
|
* @param {string} content
|
||||||
|
* @returns {TSC}
|
||||||
|
*/
|
||||||
|
setResponse(k: "ON" | "OFF" | "BATCH", content: string): TSC;
|
||||||
|
}
|
||||||
|
|
@ -5,15 +5,43 @@ import dts from "vite-plugin-dts";
|
||||||
|
|
||||||
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||||
|
|
||||||
|
const sharedOutput = {
|
||||||
|
preserveModules: true,
|
||||||
|
preserveModulesRoot: resolve(__dirname, "src"),
|
||||||
|
assetFileNames: "assets/[name]-[hash][extname]",
|
||||||
|
exports: "named",
|
||||||
|
} as const;
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
build: {
|
build: {
|
||||||
lib: {
|
lib: {
|
||||||
entry: resolve(__dirname, "src/index.ts"),
|
entry: {
|
||||||
formats: ["es", "cjs"],
|
index: resolve(__dirname, "src/index.ts"),
|
||||||
fileName: (format) => `index.${format === "es" ? "mjs" : "cjs"}`,
|
"input-rule/index": resolve(__dirname, "src/input-rule/index.ts"),
|
||||||
|
"knock-test/index": resolve(__dirname, "src/knock-test/index.ts"),
|
||||||
|
"permission/index": resolve(__dirname, "src/permission/index.ts"),
|
||||||
|
"printer/index": resolve(__dirname, "src/printer/index.ts"),
|
||||||
|
"time/index": resolve(__dirname, "src/time/index.ts"),
|
||||||
|
"timer/index": resolve(__dirname, "src/timer/index.ts"),
|
||||||
|
"ui/index": resolve(__dirname, "src/ui/index.ts"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rolldownOptions: {
|
||||||
external: ["dayjs", "lodash-es", "text-encoding", "tslib"],
|
external: ["dayjs", "lodash-es", "text-encoding", "tslib"],
|
||||||
|
output: [
|
||||||
|
{
|
||||||
|
...sharedOutput,
|
||||||
|
format: "es",
|
||||||
|
entryFileNames: "[name].mjs",
|
||||||
|
chunkFileNames: "chunks/[name]-[hash].mjs",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...sharedOutput,
|
||||||
|
format: "cjs",
|
||||||
|
entryFileNames: "[name].cjs",
|
||||||
|
chunkFileNames: "chunks/[name]-[hash].cjs",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
},
|
},
|
||||||
|
|
@ -24,7 +52,7 @@ export default defineConfig({
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
dts({
|
dts({
|
||||||
include: ["src"],
|
include: ["src", "types"],
|
||||||
outDir: "dist",
|
outDir: "dist",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
# @r-utils/uni-app
|
||||||
|
|
||||||
|
## 1.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 添加工具
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @r-utils/common@1.4.0
|
||||||
|
|
@ -0,0 +1,93 @@
|
||||||
|
# @r-utils/uni-app
|
||||||
|
|
||||||
|
仅用于 uni-app 项目的工具包,封装请求、上传、NFC、蓝牙、打印和常用 uni API 辅助方法。
|
||||||
|
|
||||||
|
## 适用范围
|
||||||
|
|
||||||
|
- 适用于 uni-app 项目(含 uni 运行时能力)。
|
||||||
|
- 适用于需要复用请求、上传、蓝牙、NFC、打印等能力的业务项目。
|
||||||
|
|
||||||
|
## 不适用范围
|
||||||
|
|
||||||
|
- 不适用于普通 Web Vue2/Vue3 项目。
|
||||||
|
- 不适用于没有 `uni` 运行时的纯 Node.js 环境。
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm add @r-utils/uni-app
|
||||||
|
```
|
||||||
|
|
||||||
|
## 导入方式
|
||||||
|
|
||||||
|
### 推荐:根入口导入
|
||||||
|
|
||||||
|
大多数场景推荐从根入口导入,路径简单,使用心智负担更低。
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Request, showToast, toPromise, upload, Printer } from "@r-utils/uni-app";
|
||||||
|
```
|
||||||
|
|
||||||
|
### 兼容:子路径导入
|
||||||
|
|
||||||
|
如果你希望模块边界更清晰,也可以使用子路径导入。两种方式都支持。
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Request } from "@r-utils/uni-app/request";
|
||||||
|
import { showToast, toPromise } from "@r-utils/uni-app/uni-helper";
|
||||||
|
import { upload } from "@r-utils/uni-app/upload";
|
||||||
|
import { Printer } from "@r-utils/uni-app/printer";
|
||||||
|
import { nfcScan } from "@r-utils/uni-app/nfc";
|
||||||
|
import { BluetoothUtils } from "@r-utils/uni-app/bluetooth-utils";
|
||||||
|
```
|
||||||
|
|
||||||
|
## 导出模块
|
||||||
|
|
||||||
|
| 子路径 | 说明 |
|
||||||
|
| --- | --- |
|
||||||
|
| `@r-utils/uni-app/request` | 类 axios 的 `uni.request` 封装 |
|
||||||
|
| `@r-utils/uni-app/uni-helper` | 常用 uni API 辅助函数 |
|
||||||
|
| `@r-utils/uni-app/upload` | 上传相关工具 |
|
||||||
|
| `@r-utils/uni-app/printer` | 打印机相关工具 |
|
||||||
|
| `@r-utils/uni-app/nfc` | NFC 相关工具 |
|
||||||
|
| `@r-utils/uni-app/bluetooth-utils` | 蓝牙相关工具 |
|
||||||
|
|
||||||
|
## 使用示例
|
||||||
|
|
||||||
|
### 请求封装
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Request } from "@r-utils/uni-app";
|
||||||
|
|
||||||
|
const request = new Request({
|
||||||
|
baseURL: "https://api.example.com",
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await request.get("/users", {
|
||||||
|
data: { pageNum: 1, pageSize: 10 },
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用 showToast
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { showToast } from "@r-utils/uni-app";
|
||||||
|
|
||||||
|
showToast("保存成功", "success");
|
||||||
|
```
|
||||||
|
|
||||||
|
### 子路径导入请求模块
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Request } from "@r-utils/uni-app/request";
|
||||||
|
|
||||||
|
const request = new Request({
|
||||||
|
baseURL: "https://api.example.com",
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
- 推荐优先使用根入口导入;如果需要更精确的模块边界,也可以使用子路径导入。
|
||||||
|
- 本包依赖 uni-app 运行时能力,需在真实 uni-app 环境中验证平台相关功能。
|
||||||
|
- NFC、蓝牙、打印功能通常依赖具体平台和设备能力,建议按目标端单独测试。
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@r-utils/uni-app",
|
"name": "@r-utils/uni-app",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "uni-app工具库",
|
"description": "uni-app工具库",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
@ -8,13 +8,45 @@
|
||||||
"module": "dist/index.mjs",
|
"module": "dist/index.mjs",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./dist/index.mjs",
|
"import": "./dist/index.mjs",
|
||||||
"require": "./dist/index.cjs"
|
"require": "./dist/index.cjs"
|
||||||
},
|
},
|
||||||
"./*": "./*"
|
"./bluetooth-utils": {
|
||||||
|
"types": "./dist/bluetooth-utils/index.d.ts",
|
||||||
|
"import": "./dist/bluetooth-utils/index.mjs",
|
||||||
|
"require": "./dist/bluetooth-utils/index.cjs"
|
||||||
|
},
|
||||||
|
"./nfc": {
|
||||||
|
"types": "./dist/nfc/index.d.ts",
|
||||||
|
"import": "./dist/nfc/index.mjs",
|
||||||
|
"require": "./dist/nfc/index.cjs"
|
||||||
|
},
|
||||||
|
"./printer": {
|
||||||
|
"types": "./dist/printer/index.d.ts",
|
||||||
|
"import": "./dist/printer/index.mjs",
|
||||||
|
"require": "./dist/printer/index.cjs"
|
||||||
|
},
|
||||||
|
"./request": {
|
||||||
|
"types": "./dist/request/index.d.ts",
|
||||||
|
"import": "./dist/request/index.mjs",
|
||||||
|
"require": "./dist/request/index.cjs"
|
||||||
|
},
|
||||||
|
"./uni-helper": {
|
||||||
|
"types": "./dist/uni-helper/index.d.ts",
|
||||||
|
"import": "./dist/uni-helper/index.mjs",
|
||||||
|
"require": "./dist/uni-helper/index.cjs"
|
||||||
|
},
|
||||||
|
"./upload": {
|
||||||
|
"types": "./dist/upload/index.d.ts",
|
||||||
|
"import": "./dist/upload/index.mjs",
|
||||||
|
"require": "./dist/upload/index.cjs"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"uni-app"
|
"uni-app"
|
||||||
|
|
@ -43,8 +75,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"watch": "vite build --watch",
|
"watch": "vite build --watch",
|
||||||
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||||
"lint": "eslint --ext .js,ts --fix src",
|
"lint": "eslint --ext .js,ts --fix src",
|
||||||
"release": "standard-version",
|
"format": "prettier --write src",
|
||||||
"commit": "cz",
|
"commit": "cz",
|
||||||
"lint-staged": "lint-staged",
|
"lint-staged": "lint-staged",
|
||||||
"test": "vitest run"
|
"test": "vitest run"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { toPromise, showToast } from "@/uni-helper";
|
/* eslint-disable no-useless-assignment, @typescript-eslint/no-unused-vars */
|
||||||
|
import { showToast } from "@/uni-helper";
|
||||||
|
|
||||||
const systemInfo = uni.getSystemInfoSync();
|
const systemInfo = uni.getSystemInfoSync();
|
||||||
const isAndroidApp =
|
const isAndroidApp =
|
||||||
|
|
@ -237,7 +238,7 @@ export class BluetoothUtils {
|
||||||
res = await cb();
|
res = await cb();
|
||||||
} else {
|
} else {
|
||||||
// 失败重连5次
|
// 失败重连5次
|
||||||
for (var i = 1; i <= 5; i++) {
|
for (let i = 1; i <= 5; i++) {
|
||||||
try {
|
try {
|
||||||
await uni.createBLEConnection({
|
await uni.createBLEConnection({
|
||||||
deviceId: device.deviceId,
|
deviceId: device.deviceId,
|
||||||
|
|
@ -397,12 +398,12 @@ export class BluetoothUtils {
|
||||||
private static async _getBLEMTU(device: Device) {
|
private static async _getBLEMTU(device: Device) {
|
||||||
console.log("_getBLEMTU", device);
|
console.log("_getBLEMTU", device);
|
||||||
// return new Promise<number>(async (resolve, reject) => {
|
// return new Promise<number>(async (resolve, reject) => {
|
||||||
return uni.getBLEMTU({
|
return uni.getBLEMTU({
|
||||||
deviceId: device.deviceId,
|
deviceId: device.deviceId,
|
||||||
// success: (res) => {
|
// success: (res) => {
|
||||||
// resolve(res.mtu);
|
// resolve(res.mtu);
|
||||||
// },
|
// },
|
||||||
});
|
});
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable no-useless-assignment, @typescript-eslint/no-unused-vars */
|
||||||
const systemInfo = uni.getSystemInfoSync();
|
const systemInfo = uni.getSystemInfoSync();
|
||||||
const isAndroid =
|
const isAndroid =
|
||||||
systemInfo.uniPlatform === "app" && systemInfo.osName === "android";
|
systemInfo.uniPlatform === "app" && systemInfo.osName === "android";
|
||||||
|
|
@ -195,12 +196,16 @@ export class AndroidNfcUtil {
|
||||||
|
|
||||||
static async scan() {
|
static async scan() {
|
||||||
const androidNfcUtil = new AndroidNfcUtil();
|
const androidNfcUtil = new AndroidNfcUtil();
|
||||||
return await new Promise(async (resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
await androidNfcUtil.startNfcScan();
|
androidNfcUtil
|
||||||
androidNfcUtil.addDiscoveredListener((res) => {
|
.startNfcScan()
|
||||||
androidNfcUtil.stopNfcScan();
|
.then(() => {
|
||||||
resolve(res);
|
androidNfcUtil.addDiscoveredListener((res) => {
|
||||||
});
|
androidNfcUtil.stopNfcScan();
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ export async function isNfcEnabled() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNFCUtil(){
|
export function getNFCUtil() {
|
||||||
if (isAndroidApp) {
|
if (isAndroidApp) {
|
||||||
return new AndroidNfcUtil();
|
return new AndroidNfcUtil();
|
||||||
} else if (isAndroidWeixin) {
|
} else if (isAndroidWeixin) {
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,15 @@ export async function startNfcScan() {
|
||||||
await nfcAdapter.startDiscovery();
|
await nfcAdapter.startDiscovery();
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
nfcAdapter.onDiscovered((res) => {
|
try {
|
||||||
console.log("onDiscovered", res);
|
nfcAdapter.onDiscovered((res) => {
|
||||||
const arr = Array.from(new Int8Array(res.id));
|
console.log("onDiscovered", res);
|
||||||
resolve(arr);
|
const arr = Array.from(new Int8Array(res.id));
|
||||||
});
|
resolve(arr);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,12 +71,16 @@ export class WeixinNfcUtil {
|
||||||
|
|
||||||
static async scan() {
|
static async scan() {
|
||||||
const weixinNfcUtil = new WeixinNfcUtil();
|
const weixinNfcUtil = new WeixinNfcUtil();
|
||||||
return await new Promise(async (resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
await weixinNfcUtil.startNfcScan();
|
weixinNfcUtil
|
||||||
weixinNfcUtil.addDiscoveredListener((res) => {
|
.startNfcScan()
|
||||||
weixinNfcUtil.stopNfcScan();
|
.then(() => {
|
||||||
resolve(res);
|
weixinNfcUtil.addDiscoveredListener((res) => {
|
||||||
});
|
weixinNfcUtil.stopNfcScan();
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { BluetoothUtils, Device } from "@/bluetooth-utils";
|
|
||||||
import { wait } from "@r-utils/common";
|
import { wait } from "@r-utils/common";
|
||||||
|
import { BluetoothUtils, Device } from "@/bluetooth-utils";
|
||||||
|
|
||||||
type DeviceData = Required<Device>;
|
type DeviceData = Required<Device>;
|
||||||
|
|
||||||
|
|
@ -17,9 +16,9 @@ export class Printer {
|
||||||
console.log(
|
console.log(
|
||||||
data.length,
|
data.length,
|
||||||
data.slice(0, 100),
|
data.slice(0, 100),
|
||||||
data.slice(data.length - 100, data.length)
|
data.slice(data.length - 100, data.length),
|
||||||
);
|
);
|
||||||
let res = null;
|
let res;
|
||||||
const systemInfo = uni.getSystemInfoSync();
|
const systemInfo = uni.getSystemInfoSync();
|
||||||
if (systemInfo.uniPlatform === "app" && systemInfo.osName === "android") {
|
if (systemInfo.uniPlatform === "app" && systemInfo.osName === "android") {
|
||||||
res = await BluetoothUtils.sendDataAndroid(this.device, data);
|
res = await BluetoothUtils.sendDataAndroid(this.device, data);
|
||||||
|
|
@ -33,7 +32,7 @@ export class Printer {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _print(data: number[]):Promise<any> {
|
async _print(data: number[]): Promise<void> {
|
||||||
const size = Math.min(data.length, this.size);
|
const size = Math.min(data.length, this.size);
|
||||||
if (size === 0) {
|
if (size === 0) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,57 @@
|
||||||
export type DataType = string | AnyObject | ArrayBuffer;
|
export type DataType = string | AnyObject | ArrayBuffer;
|
||||||
|
|
||||||
/** 请求配置 */
|
/** 请求配置 */
|
||||||
export interface Config<T extends DataType>
|
export interface Config<
|
||||||
extends Partial<UniApp.RequestOptions> {
|
T extends DataType,
|
||||||
|
> extends Partial<UniApp.RequestOptions> {
|
||||||
baseURL?: string;
|
baseURL?: string;
|
||||||
data?: T;
|
data?: T;
|
||||||
[key: string]: any;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 响应 */
|
/** 响应 */
|
||||||
export interface Response<
|
export interface Response<
|
||||||
T extends DataType,
|
T extends DataType,
|
||||||
D extends DataType,
|
D extends DataType,
|
||||||
C extends Config<D> = Config<D>
|
C extends Config<D> = Config<D>,
|
||||||
> extends UniApp.RequestSuccessCallbackResult {
|
>
|
||||||
|
extends UniApp.RequestSuccessCallbackResult {
|
||||||
data: T;
|
data: T;
|
||||||
errMsg?: string;
|
errMsg?: string;
|
||||||
config: C;
|
config: C;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 判断是否为绝对地址 */
|
||||||
|
const isAbsoluteUrl = (url: string): boolean =>
|
||||||
|
/^(?:[a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
||||||
|
|
||||||
|
/** 拼接基础地址 */
|
||||||
|
const joinBaseURL = (baseURL: string, url: string): string => {
|
||||||
|
if (!baseURL || isAbsoluteUrl(url)) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedBaseURL = baseURL.endsWith("/")
|
||||||
|
? baseURL.slice(0, -1)
|
||||||
|
: baseURL;
|
||||||
|
const normalizedUrl = url.startsWith("/") ? url : `/${url}`;
|
||||||
|
|
||||||
|
return `${normalizedBaseURL}${normalizedUrl}`;
|
||||||
|
};
|
||||||
|
|
||||||
/** 成功拦截器 */
|
/** 成功拦截器 */
|
||||||
type FulfilledInterceptor<R, T> = (res: R) => T | Promise<T>;
|
type FulfilledInterceptor<R, T> = (res: R) => T | Promise<T>;
|
||||||
/** 失败拦截器 */
|
/** 失败拦截器 */
|
||||||
type RejectedInterceptor = (error: any) => any;
|
type RejectedInterceptor = (error: unknown) => unknown | Promise<unknown>;
|
||||||
/** 拦截器管理 */
|
/** 拦截器管理 */
|
||||||
class InterceptorManager<R> {
|
class InterceptorManager<R> {
|
||||||
/** 拦截器列表 */
|
/** 拦截器列表 */
|
||||||
handlers: [FulfilledInterceptor<R, any>?, RejectedInterceptor?][] = [];
|
handlers: [FulfilledInterceptor<R, unknown>?, RejectedInterceptor?][] = [];
|
||||||
|
|
||||||
/** 添加拦截器 */
|
/** 添加拦截器 */
|
||||||
add<T = R>(
|
add<T = R>(
|
||||||
onFulfilled?: FulfilledInterceptor<R, T>,
|
onFulfilled?: FulfilledInterceptor<R, T>,
|
||||||
onRejected?: RejectedInterceptor
|
onRejected?: RejectedInterceptor,
|
||||||
): number {
|
): number {
|
||||||
this.handlers.push([onFulfilled, onRejected]);
|
this.handlers.push([onFulfilled, onRejected]);
|
||||||
return this.handlers.length - 1;
|
return this.handlers.length - 1;
|
||||||
|
|
@ -44,9 +64,9 @@ class InterceptorManager<R> {
|
||||||
|
|
||||||
forEach(
|
forEach(
|
||||||
fn: (
|
fn: (
|
||||||
onFulfilled?: FulfilledInterceptor<R, any>,
|
onFulfilled?: FulfilledInterceptor<R, unknown>,
|
||||||
onRejected?: RejectedInterceptor
|
onRejected?: RejectedInterceptor,
|
||||||
) => void
|
) => void,
|
||||||
) {
|
) {
|
||||||
this.handlers.forEach(([onFulfilled, onRejected]) => {
|
this.handlers.forEach(([onFulfilled, onRejected]) => {
|
||||||
fn(onFulfilled, onRejected);
|
fn(onFulfilled, onRejected);
|
||||||
|
|
@ -59,16 +79,16 @@ class InterceptorManager<R> {
|
||||||
*/
|
*/
|
||||||
export class Request {
|
export class Request {
|
||||||
/** 请求配置 */
|
/** 请求配置 */
|
||||||
config: Config<any>;
|
config: Config<DataType>;
|
||||||
/** 拦截器 */
|
/** 拦截器 */
|
||||||
interceptors: {
|
interceptors: {
|
||||||
/** 请求拦截器 */
|
/** 请求拦截器 */
|
||||||
request: InterceptorManager<Config<any>>;
|
request: InterceptorManager<Config<DataType>>;
|
||||||
/** 响应拦截器 */
|
/** 响应拦截器 */
|
||||||
response: InterceptorManager<any>;
|
response: InterceptorManager<unknown>;
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(config: Config<any> = { url: "" }) {
|
constructor(config: Config<DataType> = { url: "" }) {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.interceptors = {
|
this.interceptors = {
|
||||||
request: new InterceptorManager(),
|
request: new InterceptorManager(),
|
||||||
|
|
@ -76,79 +96,86 @@ export class Request {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 依次执行请求拦截器 */
|
||||||
|
private async runRequestInterceptors<REQD extends DataType>(
|
||||||
|
config: Config<REQD>,
|
||||||
|
): Promise<Config<REQD>> {
|
||||||
|
let currentConfig = config;
|
||||||
|
|
||||||
|
for (const [onFulfilled, onRejected] of this.interceptors.request
|
||||||
|
.handlers) {
|
||||||
|
try {
|
||||||
|
if (onFulfilled) {
|
||||||
|
currentConfig = (await onFulfilled(currentConfig)) as Config<REQD>;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (onRejected) {
|
||||||
|
currentConfig = (await onRejected(error)) as Config<REQD>;
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 依次执行响应拦截器 */
|
||||||
|
private async runResponseInterceptors<R>(response: R): Promise<R> {
|
||||||
|
let currentResponse = response;
|
||||||
|
|
||||||
|
for (const [onFulfilled, onRejected] of this.interceptors.response
|
||||||
|
.handlers) {
|
||||||
|
try {
|
||||||
|
if (onFulfilled) {
|
||||||
|
currentResponse = (await onFulfilled(currentResponse)) as R;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (onRejected) {
|
||||||
|
currentResponse = (await onRejected(error)) as R;
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentResponse;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求主方法
|
* 请求主方法
|
||||||
*/
|
*/
|
||||||
async request<
|
async request<
|
||||||
RESPD extends DataType,
|
RESPD extends DataType,
|
||||||
REQD extends DataType,
|
REQD extends DataType,
|
||||||
R = Response<RESPD, REQD>
|
R = Response<RESPD, REQD>,
|
||||||
>(config: Config<REQD>): Promise<R> {
|
>(config: Config<REQD>): Promise<R> {
|
||||||
// 合并方法配置 与 实例配置
|
// 合并方法配置 与 实例配置
|
||||||
let newConfig = Object.assign({}, this.config, config);
|
let newConfig = Object.assign({}, this.config, config) as Config<REQD>;
|
||||||
|
|
||||||
// 赋值默认URL
|
// 赋值默认URL
|
||||||
newConfig.url = newConfig.url ?? "";
|
newConfig.url = newConfig.url ?? "";
|
||||||
// 如果设置了 baseURL 并且 url 不是绝对路径,则拼接 baseURL
|
|
||||||
if (newConfig.baseURL && !/https?\/\//.test(newConfig.url)) {
|
|
||||||
newConfig.url = newConfig.baseURL + newConfig.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 执行请求拦截器
|
// 执行请求拦截器
|
||||||
this.interceptors.request.forEach((onFulfilled, onRejected) => {
|
newConfig = await this.runRequestInterceptors(newConfig);
|
||||||
try {
|
|
||||||
if (onFulfilled) {
|
// 如果设置了 baseURL 并且 url 不是绝对路径,则拼接 baseURL
|
||||||
newConfig = onFulfilled(newConfig);
|
newConfig.url = joinBaseURL(newConfig.baseURL ?? "", newConfig.url ?? "");
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (onRejected) {
|
|
||||||
throw onRejected(error);
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 发送请求
|
// 发送请求
|
||||||
// let responsePromise = await new Promise<Response<RESPD>>((resolve, reject) => {
|
let responsePromise = (await (uni.request({
|
||||||
// uni.request({
|
|
||||||
// ...newConfig,
|
|
||||||
// success(result) {
|
|
||||||
// resolve(result);
|
|
||||||
// },
|
|
||||||
// fail(result) {
|
|
||||||
// reject(result);
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
let responsePromise = await (<Promise<R>>uni.request({
|
|
||||||
...newConfig,
|
...newConfig,
|
||||||
url: newConfig.url,
|
url: newConfig.url,
|
||||||
}));
|
}) as Promise<R>)) as R;
|
||||||
|
|
||||||
// 替换新请求的配置
|
// 替换新请求的配置
|
||||||
responsePromise = {
|
responsePromise = {
|
||||||
...responsePromise,
|
...responsePromise,
|
||||||
config: newConfig,
|
config: newConfig as Config<REQD>,
|
||||||
};
|
} as R;
|
||||||
|
|
||||||
// 执行响应拦截器
|
// 执行响应拦截器
|
||||||
this.interceptors.response.forEach((onFulfilled, onRejected) => {
|
responsePromise = await this.runResponseInterceptors(responsePromise);
|
||||||
// this.interceptors?.response.handlers.forEach((handler) => {
|
|
||||||
// const [onFulfilled, onRejected] = handler;
|
|
||||||
// responsePromise = responsePromise.then(onFulfilled, onRejected);
|
|
||||||
try {
|
|
||||||
if (typeof onFulfilled !== "undefined") {
|
|
||||||
responsePromise = onFulfilled(responsePromise);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (typeof onRejected !== "undefined") {
|
|
||||||
onRejected(error);
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return responsePromise;
|
return responsePromise;
|
||||||
}
|
}
|
||||||
|
|
@ -156,7 +183,7 @@ export class Request {
|
||||||
/** GET 请求 */
|
/** GET 请求 */
|
||||||
get<RESPD extends DataType, REQD extends DataType, R = Response<RESPD, REQD>>(
|
get<RESPD extends DataType, REQD extends DataType, R = Response<RESPD, REQD>>(
|
||||||
url: string,
|
url: string,
|
||||||
config?: Config<REQD>
|
config?: Config<REQD>,
|
||||||
): Promise<R> {
|
): Promise<R> {
|
||||||
return this.request({ ...config, url, method: "GET" });
|
return this.request({ ...config, url, method: "GET" });
|
||||||
}
|
}
|
||||||
|
|
@ -165,17 +192,17 @@ export class Request {
|
||||||
post<
|
post<
|
||||||
RESPD extends DataType,
|
RESPD extends DataType,
|
||||||
REQD extends DataType,
|
REQD extends DataType,
|
||||||
R = Response<RESPD, REQD>
|
R = Response<RESPD, REQD>,
|
||||||
>(url: string, data?: REQD, config?: Config<REQD>): Promise<R> {
|
>(url: string, data?: REQD, config?: Config<REQD>): Promise<R> {
|
||||||
return this.request({ ...config, url, method: "POST", data });
|
return this.request({ ...config, url, method: "POST", data });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** PUT 请求 */
|
/** PUT 请求 */
|
||||||
put<
|
put<RESPD extends DataType, REQD extends DataType, R = Response<RESPD, REQD>>(
|
||||||
RESPD extends DataType,
|
url: string,
|
||||||
REQD extends DataType,
|
data?: REQD,
|
||||||
R = Response<RESPD, REQD>
|
config?: Config<REQD>,
|
||||||
>(url: string, data?: REQD, config?: Config<REQD>): Promise<R> {
|
): Promise<R> {
|
||||||
return this.request({ ...config, url, method: "PUT", data });
|
return this.request({ ...config, url, method: "PUT", data });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
type UploadResponseData = {
|
type UploadResponseData = {
|
||||||
originalFileName: string;
|
originalFileName: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|
@ -7,6 +7,6 @@
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,45 @@
|
||||||
|
export class AndroidNfcUtil {
|
||||||
|
/**
|
||||||
|
* 是否支持NFC
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
static isNfcSupported(): boolean;
|
||||||
|
/**
|
||||||
|
* 是否开启NFC
|
||||||
|
* @returns {boolean} true 已开启
|
||||||
|
*/
|
||||||
|
static isNfcEnabled(): Promise<boolean>;
|
||||||
|
static scan(): Promise<number[]>;
|
||||||
|
main: PlusAndroidInstanceObject | null;
|
||||||
|
nfcAdapter: PlusAndroidInstanceObject | null;
|
||||||
|
pendingIntent: PlusAndroidInstanceObject | null;
|
||||||
|
intentFiltersArray: PlusAndroidInstanceObject[] | null;
|
||||||
|
techListsArray: string[][] | null;
|
||||||
|
discoveredListenerList: Array<(id: number[]) => void>;
|
||||||
|
/**
|
||||||
|
* 内部发现处理器
|
||||||
|
*/
|
||||||
|
_discoveredHandler: (() => void) | null;
|
||||||
|
/**
|
||||||
|
* 内部恢复处理器
|
||||||
|
*/
|
||||||
|
_resumeHandler: (() => void) | null;
|
||||||
|
/**
|
||||||
|
* 添加NFC发现监听器
|
||||||
|
* @param cb 回调函数,接收读取到的NFC ID
|
||||||
|
*/
|
||||||
|
addDiscoveredListener(cb: (id: number[]) => void): void;
|
||||||
|
/**
|
||||||
|
* 开始NFC扫描
|
||||||
|
* @returns {Promise<number[]>}
|
||||||
|
*/
|
||||||
|
startNfcScan(): Promise<number[]>;
|
||||||
|
stopNfcScan(): Promise<void>;
|
||||||
|
/**
|
||||||
|
* 初始化NFC并开启监听
|
||||||
|
*/
|
||||||
|
init(): Promise<void>;
|
||||||
|
resumeHandler(): void;
|
||||||
|
discoveredHandler(): void;
|
||||||
|
readId(): number[];
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
import { AndroidNfcUtil } from "./android";
|
||||||
|
import { WeixinNfcUtil } from "./weixin";
|
||||||
|
|
||||||
|
export function nfcScan(): Promise<number[] | undefined>;
|
||||||
|
export function isNfcEnabled(): Promise<boolean | undefined>;
|
||||||
|
export function getNFCUtil(): AndroidNfcUtil | WeixinNfcUtil | undefined;
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
export function startNfcScan(): Promise<number[]>;
|
||||||
|
|
||||||
|
export class WeixinNfcUtil {
|
||||||
|
/**
|
||||||
|
* 是否开启NFC
|
||||||
|
* NOTE 微信无法判断是否开启
|
||||||
|
* @returns {boolean} true 已开启
|
||||||
|
*/
|
||||||
|
static isNfcEnabled(): Promise<boolean>;
|
||||||
|
static scan(): Promise<number[]>;
|
||||||
|
nfcAdapter: WechatMiniprogram.NFCAdapter | null;
|
||||||
|
discoveredListenerList: Array<(id: number[]) => void>;
|
||||||
|
/**
|
||||||
|
* 内部发现处理器
|
||||||
|
*/
|
||||||
|
_discoveredHandler:
|
||||||
|
| ((res: WechatMiniprogram.OnDiscoveredCallbackResult) => void)
|
||||||
|
| null;
|
||||||
|
discoveredHandler(res: WechatMiniprogram.OnDiscoveredCallbackResult): void;
|
||||||
|
/**
|
||||||
|
* 添加NFC发现监听器
|
||||||
|
* @param cb 回调函数,接收读取到的NFC ID
|
||||||
|
*/
|
||||||
|
addDiscoveredListener(cb: (id: number[]) => void): void;
|
||||||
|
startNfcScan(): Promise<WechatMiniprogram.NFCError>;
|
||||||
|
stopNfcScan(): Promise<WechatMiniprogram.NFCError>;
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import * as QQMapWX from "@jonny1994/qqmap-wx-jssdk";
|
import * as QQMapWX from "@jonny1994/qqmap-wx-jssdk";
|
||||||
|
|
||||||
export * from "@jonny1994/qqmap-wx-jssdk";
|
export * from "@jonny1994/qqmap-wx-jssdk";
|
||||||
/**
|
/**
|
||||||
* 行政区划列表
|
* 行政区划列表
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/// <reference types="@dcloudio/types" />
|
/// <reference types="@dcloudio/types" />
|
||||||
|
|
||||||
declare namespace UniNamespace {
|
declare namespace UniNamespace {
|
||||||
type LocaldataItem<T=string> = {
|
type LocaldataItem<T = string> = {
|
||||||
text: string;
|
text: string;
|
||||||
value: T;
|
value: T;
|
||||||
children?: LocaldataItem<T>[];
|
children?: LocaldataItem<T>[];
|
||||||
|
|
@ -111,7 +111,7 @@ interface PlusIo {
|
||||||
resolveLocalFileSystemURL(
|
resolveLocalFileSystemURL(
|
||||||
url?: string,
|
url?: string,
|
||||||
succesCB?: (result: PlusIoFileEntry) => void,
|
succesCB?: (result: PlusIoFileEntry) => void,
|
||||||
errorCB?: (result: any) => void,
|
errorCB?: (result: PlusIoDirectoryEntry) => void,
|
||||||
): void;
|
): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,47 @@
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from "vite";
|
||||||
import dts from 'vite-plugin-dts';
|
import dts from "vite-plugin-dts";
|
||||||
import { resolve } from 'node:path';
|
import { resolve } from "node:path";
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
build: {
|
build: {
|
||||||
lib: {
|
lib: {
|
||||||
entry: resolve(__dirname, 'src/index.ts'),
|
entry: {
|
||||||
formats: ['es', 'cjs'],
|
index: resolve(__dirname, "src/index.ts"),
|
||||||
fileName: (format) => `index.${format === 'es' ? 'mjs' : 'cjs'}`,
|
"bluetooth-utils/index": resolve(
|
||||||
|
__dirname,
|
||||||
|
"src/bluetooth-utils/index.ts",
|
||||||
|
),
|
||||||
|
"nfc/index": resolve(__dirname, "src/nfc/index.js"),
|
||||||
|
"printer/index": resolve(__dirname, "src/printer/index.ts"),
|
||||||
|
"request/index": resolve(__dirname, "src/request/index.ts"),
|
||||||
|
"uni-helper/index": resolve(__dirname, "src/uni-helper/index.ts"),
|
||||||
|
"upload/index": resolve(__dirname, "src/upload/index.ts"),
|
||||||
|
},
|
||||||
|
formats: ["es", "cjs"],
|
||||||
|
fileName: (format, entryName) =>
|
||||||
|
`${entryName}.${format === "es" ? "mjs" : "cjs"}`,
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
// uni / plus / wx 是 uni-app 运行时注入的全局变量,无需 external
|
external: ["vue", "lodash", /^@r-utils\/.*/],
|
||||||
external: ['vue', 'lodash', /^@r-utils\/.*/],
|
output: {
|
||||||
|
chunkFileNames: "chunks/[name]-[hash].js",
|
||||||
|
assetFileNames: "assets/[name]-[hash][extname]",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, 'src'),
|
"@": resolve(__dirname, "src"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
dts({
|
dts({
|
||||||
include: ['src', 'types'],
|
include: ["src", "types"],
|
||||||
outDir: 'dist',
|
outDir: "dist",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
# @r-utils/uview-plus
|
||||||
|
|
||||||
|
## 1.3.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 添加工具
|
||||||
|
|
@ -1,6 +1,16 @@
|
||||||
# @r-utils/uview-plus
|
# @r-utils/uview-plus
|
||||||
|
|
||||||
基于 [uview-plus](https://uview-plus.jiangruyi.com/) 的 Vue3 组合式 API 工具 Hooks,适用于 uni-app 项目。
|
在项目已使用 [uview-plus](https://uview-plus.jiangruyi.com/) 的前提下,提供适用于 uview-plus 组件的组合式 API Hooks。
|
||||||
|
|
||||||
|
## 适用范围
|
||||||
|
|
||||||
|
- 适用于已接入 `uview-plus` 的项目。
|
||||||
|
- 典型场景是 uni-app + Vue3 + uview-plus。
|
||||||
|
|
||||||
|
## 不适用范围
|
||||||
|
|
||||||
|
- 未使用 `uview-plus` 的项目不建议使用。
|
||||||
|
- 不适用于 Vue2 项目。
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
|
|
@ -8,102 +18,69 @@
|
||||||
pnpm add @r-utils/uview-plus
|
pnpm add @r-utils/uview-plus
|
||||||
```
|
```
|
||||||
|
|
||||||
## 使用
|
## 导入方式
|
||||||
|
|
||||||
|
### 推荐:根入口导入
|
||||||
|
|
||||||
|
大多数场景推荐从根入口导入,路径简单,使用心智负担更低。
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { usePickerSingle, usePicker, useCalendar } from '@r-utils/uview-plus'
|
import {
|
||||||
|
usePickerSingle,
|
||||||
|
usePicker,
|
||||||
|
useDateTimePicker,
|
||||||
|
useCalendar,
|
||||||
|
} from "@r-utils/uview-plus";
|
||||||
```
|
```
|
||||||
|
|
||||||
## API
|
### 兼容:子路径导入
|
||||||
|
|
||||||
### `usePickerSingle(options)`
|
如果你希望模块边界更清晰,也可以使用子路径导入。两种方式都支持。
|
||||||
|
|
||||||
单列 Picker 封装。
|
|
||||||
|
|
||||||
| 参数 | 类型 | 默认值 | 说明 |
|
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| `value` | `unknown \| Ref<unknown>` | `null` | 选中的值 |
|
|
||||||
| `show` | `boolean \| Ref<boolean>` | `false` | 是否显示 |
|
|
||||||
| `indexes` | `Array<number \| null> \| Ref<...>` | `[null]` | 选中的索引 |
|
|
||||||
| `list` | `PickerColumns[0] \| Ref<...>` | `[]` | 列数据 |
|
|
||||||
| `textName` | `string` | `'text'` | 显示字段名 |
|
|
||||||
| `valueName` | `string` | `'value'` | 值字段名 |
|
|
||||||
| `placeholder` | `string` | `'请选择'` | 占位文本 |
|
|
||||||
|
|
||||||
**返回值:**
|
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
{
|
import { usePickerSingle } from "@r-utils/uview-plus/picker-single";
|
||||||
value, show, indexes, columns, text, defaultIndex,
|
import { usePicker } from "@r-utils/uview-plus/picker";
|
||||||
showPicker, hidePicker, handleConfirm, handleClose
|
import { useDateTimePicker } from "@r-utils/uview-plus/datetime-picker";
|
||||||
}
|
import { useCalendar } from "@r-utils/uview-plus/calendar";
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
## 导出模块
|
||||||
|
|
||||||
### `usePicker(options)`
|
| 子路径 | 说明 |
|
||||||
|
| --- | --- |
|
||||||
|
| `@r-utils/uview-plus/picker-single` | 单列 picker Hook |
|
||||||
|
| `@r-utils/uview-plus/picker` | 多列 picker Hook |
|
||||||
|
| `@r-utils/uview-plus/datetime-picker` | 时间选择器 Hook |
|
||||||
|
| `@r-utils/uview-plus/calendar` | 日历选择器 Hook |
|
||||||
|
|
||||||
多列 Picker 封装。
|
## 使用示例
|
||||||
|
|
||||||
| 参数 | 类型 | 默认值 | 说明 |
|
### 单列选择器
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| `value` | `unknown[] \| Ref<unknown[]>` | `[]` | 选中的值数组 |
|
|
||||||
| `show` | `boolean \| Ref<boolean>` | `false` | 是否显示 |
|
|
||||||
| `indexes` | `Array<number \| null> \| Ref<...>` | `[]` | 选中的索引数组 |
|
|
||||||
| `columns` | `PickerColumns \| Ref<PickerColumns>` | `[]` | 列数据 |
|
|
||||||
| `textName` | `string` | `'text'` | 显示字段名 |
|
|
||||||
| `valueName` | `string` | `'value'` | 值字段名 |
|
|
||||||
| `placeholder` | `string` | `'请选择'` | 占位文本 |
|
|
||||||
| `separator` | `string` | `' '` | 多列值拼接分隔符 |
|
|
||||||
|
|
||||||
**返回值:**
|
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
{
|
import { usePickerSingle } from "@r-utils/uview-plus";
|
||||||
value, show, indexes, columns, text, defaultIndex,
|
|
||||||
showPicker, hidePicker, handleConfirm, handleClose
|
const picker = usePickerSingle({
|
||||||
}
|
list: [
|
||||||
|
{ text: "启用", value: 1 },
|
||||||
|
{ text: "禁用", value: 0 },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
picker.showPicker();
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
### 子路径导入
|
||||||
|
|
||||||
### `useCalendar(options)`
|
|
||||||
|
|
||||||
日历选择封装。
|
|
||||||
|
|
||||||
| 参数 | 类型 | 默认值 | 说明 |
|
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| `value` | `string \| string[] \| Ref<...>` | `null` | 选中的日期 |
|
|
||||||
| `show` | `boolean \| Ref<boolean>` | `false` | 是否显示 |
|
|
||||||
| `mode` | `'single' \| 'multiple' \| 'range' \| Ref<...>` | `'single'` | 日历模式 |
|
|
||||||
| `placeholder` | `string` | `'请选择'` | 占位文本 |
|
|
||||||
|
|
||||||
**返回值:**
|
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
{
|
import { usePicker } from "@r-utils/uview-plus/picker";
|
||||||
value, show, text,
|
|
||||||
showCalendar, hideCalendar, handleConfirm, handleClose
|
const picker = usePicker({
|
||||||
}
|
columns: [[{ text: "浙江", value: "zhejiang" }]],
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## 类型声明
|
## 注意事项
|
||||||
|
|
||||||
包内置了 `UViewPlus` namespace 类型声明,无需额外引入。
|
- 推荐优先使用根入口导入;如果需要更精确的模块边界,也可以使用子路径导入。
|
||||||
|
- 本包依赖 Vue3 和 uview-plus,请确保业务项目已安装并正确配置。
|
||||||
```ts
|
|
||||||
declare namespace UViewPlus {
|
|
||||||
type PickerColumns = any[][];
|
|
||||||
type PickerValue<T extends PickerColumns = PickerColumns> = T[number][number][];
|
|
||||||
type PickerConfirmEvent<T extends PickerColumns = PickerColumns> = {
|
|
||||||
indexs: number[];
|
|
||||||
value: PickerValue<T>;
|
|
||||||
values: T;
|
|
||||||
};
|
|
||||||
type CalendarConfirmEvent = string[];
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 许可证
|
|
||||||
|
|
||||||
ISC
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@r-utils/uview-plus",
|
"name": "@r-utils/uview-plus",
|
||||||
"version": "1.2.1",
|
"version": "1.3.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "uview-plus 组合式 API Hooks",
|
"description": "uview-plus 组合式 API Hooks",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
@ -8,13 +8,35 @@
|
||||||
"module": "dist/index.mjs",
|
"module": "dist/index.mjs",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./dist/index.mjs",
|
"import": "./dist/index.mjs",
|
||||||
"require": "./dist/index.cjs"
|
"require": "./dist/index.cjs"
|
||||||
},
|
},
|
||||||
"./*": "./*"
|
"./calendar": {
|
||||||
|
"types": "./dist/calendar/index.d.ts",
|
||||||
|
"import": "./dist/calendar/index.mjs",
|
||||||
|
"require": "./dist/calendar/index.cjs"
|
||||||
|
},
|
||||||
|
"./datetime-picker": {
|
||||||
|
"types": "./dist/datetime-picker/index.d.ts",
|
||||||
|
"import": "./dist/datetime-picker/index.mjs",
|
||||||
|
"require": "./dist/datetime-picker/index.cjs"
|
||||||
|
},
|
||||||
|
"./picker-single": {
|
||||||
|
"types": "./dist/picker-single/index.d.ts",
|
||||||
|
"import": "./dist/picker-single/index.mjs",
|
||||||
|
"require": "./dist/picker-single/index.cjs"
|
||||||
|
},
|
||||||
|
"./picker": {
|
||||||
|
"types": "./dist/picker/index.d.ts",
|
||||||
|
"import": "./dist/picker/index.mjs",
|
||||||
|
"require": "./dist/picker/index.cjs"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"vue3",
|
"vue3",
|
||||||
|
|
@ -46,11 +68,12 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"watch": "vite build --watch",
|
"watch": "vite build --watch",
|
||||||
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||||
"lint": "eslint --ext .js,ts --fix src",
|
"lint": "eslint --ext .js,ts --fix src",
|
||||||
"release": "standard-version",
|
"format": "prettier --write src",
|
||||||
"commit": "cz",
|
"commit": "cz",
|
||||||
"lint-staged": "lint-staged",
|
"lint-staged": "lint-staged",
|
||||||
"test": "jest"
|
"test": "vitest run"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"uview-plus": ">=3.0.0",
|
"uview-plus": ">=3.0.0",
|
||||||
|
|
@ -62,9 +85,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@jonny1994/qqmap-wx-jssdk": "^1.4.0",
|
||||||
"lodash-es": "catalog:"
|
"lodash-es": "catalog:"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@dcloudio/types": "^3.4.14",
|
||||||
"@types/lodash-es": "catalog:",
|
"@types/lodash-es": "catalog:",
|
||||||
"vite": "catalog:",
|
"vite": "catalog:",
|
||||||
"vite-plugin-dts": "catalog:",
|
"vite-plugin-dts": "catalog:",
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,10 @@ describe("useCalendar", () => {
|
||||||
test("单选模式:text 显示 value,无值时显示 placeholder", () => {
|
test("单选模式:text 显示 value,无值时显示 placeholder", () => {
|
||||||
const scope = effectScope();
|
const scope = effectScope();
|
||||||
scope.run(() => {
|
scope.run(() => {
|
||||||
const { value, text } = useCalendar({ mode: "single", placeholder: "请选日期" });
|
const { value, text } = useCalendar({
|
||||||
|
mode: "single",
|
||||||
|
placeholder: "请选日期",
|
||||||
|
});
|
||||||
expect(text.value).toBe("请选日期");
|
expect(text.value).toBe("请选日期");
|
||||||
value.value = "2024-01-15";
|
value.value = "2024-01-15";
|
||||||
expect(text.value).toBe("2024-01-15");
|
expect(text.value).toBe("2024-01-15");
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,9 @@ describe("useDateTimePicker", () => {
|
||||||
test("handleConfirm 关闭弹窗(不更新 value)", () => {
|
test("handleConfirm 关闭弹窗(不更新 value)", () => {
|
||||||
const scope = effectScope();
|
const scope = effectScope();
|
||||||
scope.run(() => {
|
scope.run(() => {
|
||||||
const { value, show, handleConfirm } = useDateTimePicker({ value: "2024-01-01" });
|
const { value, show, handleConfirm } = useDateTimePicker({
|
||||||
|
value: "2024-01-01",
|
||||||
|
});
|
||||||
show.value = true;
|
show.value = true;
|
||||||
const event = { indexs: [], value: [], values: [] } as any;
|
const event = { indexs: [], value: [], values: [] } as any;
|
||||||
handleConfirm(event);
|
handleConfirm(event);
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,11 @@ describe("usePicker", () => {
|
||||||
test("indexes 含 null 时 text 显示 placeholder", async () => {
|
test("indexes 含 null 时 text 显示 placeholder", async () => {
|
||||||
const scope = effectScope();
|
const scope = effectScope();
|
||||||
await scope.run(async () => {
|
await scope.run(async () => {
|
||||||
const { text } = usePicker({ indexes: [null, 1], columns, placeholder: "请选择地区" });
|
const { text } = usePicker({
|
||||||
|
indexes: [null, 1],
|
||||||
|
columns,
|
||||||
|
placeholder: "请选择地区",
|
||||||
|
});
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(text.value).toBe("请选择地区");
|
expect(text.value).toBe("请选择地区");
|
||||||
});
|
});
|
||||||
|
|
@ -71,7 +75,11 @@ describe("usePicker", () => {
|
||||||
const scope = effectScope();
|
const scope = effectScope();
|
||||||
await scope.run(async () => {
|
await scope.run(async () => {
|
||||||
const { indexes, value, handleConfirm } = usePicker({ columns });
|
const { indexes, value, handleConfirm } = usePicker({ columns });
|
||||||
handleConfirm({ indexs: [1, 0], value: ["pb", "ca"], values: columns } as any);
|
handleConfirm({
|
||||||
|
indexs: [1, 0],
|
||||||
|
value: ["pb", "ca"],
|
||||||
|
values: columns,
|
||||||
|
} as any);
|
||||||
expect(indexes.value).toEqual([1, 0]);
|
expect(indexes.value).toEqual([1, 0]);
|
||||||
await nextTick();
|
await nextTick();
|
||||||
expect(value.value).toEqual(["pb", "ca"]);
|
expect(value.value).toEqual(["pb", "ca"]);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,6 @@
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
import * as QQMapWX from "@jonny1994/qqmap-wx-jssdk";
|
||||||
|
export * from "@jonny1994/qqmap-wx-jssdk";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行政区划列表
|
||||||
|
* @example
|
||||||
|
* cidx: [103, 118]
|
||||||
|
* fullname: "张家口市"
|
||||||
|
* id: "130700"
|
||||||
|
* location: {lat: 40.82444, lng: 114.88755}
|
||||||
|
* name: "张家口"
|
||||||
|
* pinyin: ["zhang", "jia", "kou"]
|
||||||
|
*/
|
||||||
|
export interface GetCityListSuccessResultResult {
|
||||||
|
/**
|
||||||
|
* 行政区划唯一标识
|
||||||
|
* @example "110000"
|
||||||
|
*/
|
||||||
|
id: number;
|
||||||
|
/**
|
||||||
|
* 简称,如“内蒙古”
|
||||||
|
*/
|
||||||
|
name?: string;
|
||||||
|
/**
|
||||||
|
* 全称,如“内蒙古自治区”
|
||||||
|
* @example "北京市"
|
||||||
|
*/
|
||||||
|
fullname: string;
|
||||||
|
/**
|
||||||
|
* 中心点坐标
|
||||||
|
* @example {lat: 39.90469, lng: 116.40717}
|
||||||
|
*/
|
||||||
|
location: QQMapWX.ResultLocation;
|
||||||
|
/**
|
||||||
|
* 行政区划拼音,每一下标为一个字的全拼,如:[“nei”,“meng”,“gu”]
|
||||||
|
*/
|
||||||
|
pinyin: string[];
|
||||||
|
/**
|
||||||
|
* 子级行政区划在下级数组中的下标位置
|
||||||
|
* @example [0, 15]
|
||||||
|
*/
|
||||||
|
cidx?: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetCityListSuccessResult extends QQMapWX.CommonResult {
|
||||||
|
/**
|
||||||
|
* 结果数组,第0项,代表一级行政区划,第1项代表二级行政区划,以此类推;使用getchildren接口时,仅为指定父级行政区划的子级
|
||||||
|
*/
|
||||||
|
result: GetCityListSuccessResultResult[];
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
|
|
||||||
|
|
||||||
/// <reference types="uview-plus/types" />
|
/// <reference types="uview-plus/types" />
|
||||||
|
|
||||||
declare namespace UViewPlus {
|
declare namespace UViewPlus {
|
||||||
type PickerColumns = never[][];
|
type PickerColumns = never[][];
|
||||||
type PickerValue<T extends PickerColumns = PickerColumns> = T[number][number][];
|
type PickerValue<T extends PickerColumns = PickerColumns> =
|
||||||
|
T[number][number][];
|
||||||
|
|
||||||
type PickerConfirmEvent<T extends PickerColumns = PickerColumns> = {
|
type PickerConfirmEvent<T extends PickerColumns = PickerColumns> = {
|
||||||
indexs: number[];
|
indexs: number[];
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,48 @@
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from "vite";
|
||||||
import dts from 'vite-plugin-dts';
|
import dts from "vite-plugin-dts";
|
||||||
import { resolve } from 'node:path';
|
import { resolve } from "node:path";
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
build: {
|
build: {
|
||||||
lib: {
|
lib: {
|
||||||
entry: resolve(__dirname, 'src/index.ts'),
|
entry: {
|
||||||
formats: ['es', 'cjs'],
|
index: resolve(__dirname, "src/index.ts"),
|
||||||
fileName: (format) => `index.${format === 'es' ? 'mjs' : 'cjs'}`,
|
"calendar/index": resolve(__dirname, "src/calendar/index.ts"),
|
||||||
|
"datetime-picker/index": resolve(
|
||||||
|
__dirname,
|
||||||
|
"src/datetime-picker/index.ts",
|
||||||
|
),
|
||||||
|
"picker-single/index": resolve(
|
||||||
|
__dirname,
|
||||||
|
"src/picker-single/index.ts",
|
||||||
|
),
|
||||||
|
"picker/index": resolve(__dirname, "src/picker/index.ts"),
|
||||||
|
},
|
||||||
|
formats: ["es", "cjs"],
|
||||||
|
fileName: (format, entryName) =>
|
||||||
|
`${entryName}.${format === "es" ? "mjs" : "cjs"}`,
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ['vue', 'lodash-es'],
|
external: ["vue", "lodash-es"],
|
||||||
|
output: {
|
||||||
|
chunkFileNames: "chunks/[name]-[hash].js",
|
||||||
|
assetFileNames: "assets/[name]-[hash][extname]",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, 'src'),
|
"@": resolve(__dirname, "src"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
dts({
|
dts({
|
||||||
include: ['src', 'types'],
|
include: ["src", "types"],
|
||||||
outDir: 'dist',
|
outDir: "dist",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
# @r-utils/vue2
|
||||||
|
|
||||||
|
## 1.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 添加工具
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
# @r-utils/vue2
|
||||||
|
|
||||||
|
仅用于 Vue2 项目的工具包。
|
||||||
|
|
||||||
|
## 适用范围
|
||||||
|
|
||||||
|
- 适用于 Vue2 项目。
|
||||||
|
- 适用于需要根据页面可见性触发组件 `onShow` / `onHide` 的场景。
|
||||||
|
|
||||||
|
## 不适用范围
|
||||||
|
|
||||||
|
- 不适用于 Vue3 项目。
|
||||||
|
- 如果是 uni-app 专用能力,建议优先使用 `@r-utils/uni-app`。
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm add @r-utils/vue2
|
||||||
|
```
|
||||||
|
|
||||||
|
## 导入方式
|
||||||
|
|
||||||
|
### 推荐:根入口导入
|
||||||
|
|
||||||
|
大多数场景推荐从根入口导入,路径简单,使用心智负担更低。
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import Vue from "vue";
|
||||||
|
import { VisibilityPlugin } from "@r-utils/vue2";
|
||||||
|
|
||||||
|
Vue.use(VisibilityPlugin);
|
||||||
|
```
|
||||||
|
|
||||||
|
也可以使用默认导出:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import Vue from "vue";
|
||||||
|
import VisibilityPlugin from "@r-utils/vue2";
|
||||||
|
|
||||||
|
Vue.use(VisibilityPlugin);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 兼容:子路径导入
|
||||||
|
|
||||||
|
如果你希望模块边界更清晰,也可以使用子路径导入。两种方式都支持。
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import Vue from "vue";
|
||||||
|
import VisibilityPlugin from "@r-utils/vue2/plugins/visibility";
|
||||||
|
|
||||||
|
Vue.use(VisibilityPlugin);
|
||||||
|
```
|
||||||
|
|
||||||
|
## 当前能力
|
||||||
|
|
||||||
|
| 子路径 | 说明 |
|
||||||
|
| --- | --- |
|
||||||
|
| `@r-utils/vue2/plugins/visibility` | 基于页面可见性变更触发 `onShow` / `onHide` |
|
||||||
|
|
||||||
|
## 使用示例
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export default {
|
||||||
|
onShow() {
|
||||||
|
console.log("页面显示");
|
||||||
|
},
|
||||||
|
onHide() {
|
||||||
|
console.log("页面隐藏");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
- 推荐优先使用根入口导入;如果需要更精确的模块边界,也可以使用子路径导入。
|
||||||
|
- 本包依赖 Vue2,请确保业务项目已安装兼容版本的 `vue`。
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@r-utils/vue2",
|
"name": "@r-utils/vue2",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "Vue2工具库",
|
"description": "Vue2工具库",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
@ -8,13 +8,20 @@
|
||||||
"module": "dist/index.mjs",
|
"module": "dist/index.mjs",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./dist/index.mjs",
|
"import": "./dist/index.mjs",
|
||||||
"require": "./dist/index.cjs"
|
"require": "./dist/index.cjs"
|
||||||
},
|
},
|
||||||
"./*": "./*"
|
"./plugins/visibility": {
|
||||||
|
"types": "./dist/plugins/visibility/index.d.ts",
|
||||||
|
"import": "./dist/plugins/visibility/index.mjs",
|
||||||
|
"require": "./dist/plugins/visibility/index.cjs"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"vue2"
|
"vue2"
|
||||||
|
|
@ -43,8 +50,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"watch": "vite build --watch",
|
"watch": "vite build --watch",
|
||||||
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||||
"lint": "eslint --ext .js,ts --fix src",
|
"lint": "eslint --ext .js,ts --fix src",
|
||||||
"release": "standard-version",
|
"format": "prettier --write src",
|
||||||
"commit": "cz",
|
"commit": "cz",
|
||||||
"lint-staged": "lint-staged",
|
"lint-staged": "lint-staged",
|
||||||
"test": "vitest run"
|
"test": "vitest run"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
import type Vue from "vue";
|
||||||
|
import type { PluginObject, VueConstructor } from "vue";
|
||||||
|
|
||||||
|
declare module "vue/types/options" {
|
||||||
|
interface ComponentOptions<V extends Vue> {
|
||||||
|
/** 页面变为可见时触发的生命周期钩子 */
|
||||||
|
onShow?: (this: V) => void;
|
||||||
|
/** 页面变为隐藏时触发的生命周期钩子 */
|
||||||
|
onHide?: (this: V) => void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 安装页面可见性生命周期插件 */
|
||||||
|
export declare function install(Vue: VueConstructor): void;
|
||||||
|
|
||||||
|
/** 页面可见性生命周期插件 */
|
||||||
|
declare const VisibilityPlugin: PluginObject<never> & {
|
||||||
|
/** 安装页面可见性生命周期插件 */
|
||||||
|
install: typeof install;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default VisibilityPlugin;
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
/**
|
||||||
|
* 安装页面可见性生命周期插件
|
||||||
|
* @param {import("vue").VueConstructor} Vue Vue2 构造器
|
||||||
|
*/
|
||||||
function install(Vue) {
|
function install(Vue) {
|
||||||
Vue.mixin({
|
Vue.mixin({
|
||||||
created() {
|
created() {
|
||||||
|
|
@ -8,14 +12,14 @@ function install(Vue) {
|
||||||
this.visibilitychangeCallback();
|
this.visibilitychangeCallback();
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
"visibilitychange",
|
"visibilitychange",
|
||||||
this.visibilitychangeCallback
|
this.visibilitychangeCallback,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
destroyed() {
|
destroyed() {
|
||||||
document.removeEventListener(
|
document.removeEventListener(
|
||||||
"visibilitychange",
|
"visibilitychange",
|
||||||
this.visibilitychangeCallback
|
this.visibilitychangeCallback,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -6,6 +6,6 @@
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,43 @@
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from "vite";
|
||||||
import dts from 'vite-plugin-dts';
|
import dts from "vite-plugin-dts";
|
||||||
import { resolve } from 'node:path';
|
import { resolve } from "node:path";
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
build: {
|
build: {
|
||||||
lib: {
|
lib: {
|
||||||
entry: resolve(__dirname, 'src/index.ts'),
|
entry: {
|
||||||
formats: ['es', 'cjs'],
|
index: resolve(__dirname, "src/index.ts"),
|
||||||
fileName: (format) => `index.${format === 'es' ? 'mjs' : 'cjs'}`,
|
"plugins/visibility/index": resolve(
|
||||||
|
__dirname,
|
||||||
|
"src/plugins/visibility/index.js",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
formats: ["es", "cjs"],
|
||||||
|
fileName: (format, entryName) =>
|
||||||
|
`${entryName}.${format === "es" ? "mjs" : "cjs"}`,
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ['vue', 'lodash'],
|
external: ["vue", "lodash"],
|
||||||
|
output: {
|
||||||
|
chunkFileNames: "chunks/[name]-[hash].js",
|
||||||
|
assetFileNames: "assets/[name]-[hash][extname]",
|
||||||
|
exports: "named",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, 'src'),
|
"@": resolve(__dirname, "src"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
dts({
|
dts({
|
||||||
include: ['src'],
|
include: ["src"],
|
||||||
outDir: 'dist',
|
outDir: "dist",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
# @r-utils/vue3
|
||||||
|
|
||||||
|
## 1.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 添加工具
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @r-utils/common@1.4.0
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
# @r-utils/vue3
|
||||||
|
|
||||||
|
仅用于 Vue3 项目的工具包,提供 class 处理、组件事件派发和常用组合式 Hooks。
|
||||||
|
|
||||||
|
## 适用范围
|
||||||
|
|
||||||
|
- 适用于 Vue3 项目。
|
||||||
|
- 适用于需要复用 Vue3 class 处理、列表加载、表单输入值处理等能力的项目。
|
||||||
|
|
||||||
|
## 不适用范围
|
||||||
|
|
||||||
|
- 不适用于 Vue2 项目。
|
||||||
|
- 如果是 uni-app 专用能力,建议优先使用 `@r-utils/uni-app`。
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm add @r-utils/vue3
|
||||||
|
```
|
||||||
|
|
||||||
|
## 导入方式
|
||||||
|
|
||||||
|
### 推荐:根入口导入
|
||||||
|
|
||||||
|
大多数场景推荐从根入口导入,路径简单,使用心智负担更低。
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import {
|
||||||
|
mergeClass,
|
||||||
|
dispatch,
|
||||||
|
useLoadMore,
|
||||||
|
useTimer,
|
||||||
|
useValueOfRule,
|
||||||
|
} from "@r-utils/vue3";
|
||||||
|
```
|
||||||
|
|
||||||
|
### 兼容:子路径导入
|
||||||
|
|
||||||
|
如果你希望模块边界更清晰,也可以使用子路径导入。两种方式都支持。
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { mergeClass } from "@r-utils/vue3/vue-helper";
|
||||||
|
import { useLoadMore } from "@r-utils/vue3/hooks/list";
|
||||||
|
import { useTimer, useValueOfRule } from "@r-utils/vue3/hooks/utils";
|
||||||
|
```
|
||||||
|
|
||||||
|
## 导出模块
|
||||||
|
|
||||||
|
| 子路径 | 说明 |
|
||||||
|
| --- | --- |
|
||||||
|
| `@r-utils/vue3/vue-helper` | Vue class 合并、转换和祖先组件事件派发 |
|
||||||
|
| `@r-utils/vue3/hooks/list` | 列表分页加载 Hook |
|
||||||
|
| `@r-utils/vue3/hooks/utils` | 常用组合式工具 Hook |
|
||||||
|
|
||||||
|
## 使用示例
|
||||||
|
|
||||||
|
### 合并 class
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { mergeClass } from "@r-utils/vue3";
|
||||||
|
|
||||||
|
const cls = mergeClass("btn", ["btn-primary"], { active: true });
|
||||||
|
```
|
||||||
|
|
||||||
|
### 列表加载
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { useLoadMore } from "@r-utils/vue3";
|
||||||
|
|
||||||
|
const listState = useLoadMore(async (pageNum, pageSize) => {
|
||||||
|
return {
|
||||||
|
total: 100,
|
||||||
|
list: await fetchList(pageNum, pageSize),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
await listState.loadMore();
|
||||||
|
```
|
||||||
|
|
||||||
|
### 子路径导入 Hook
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { useTimer } from "@r-utils/vue3/hooks/utils";
|
||||||
|
|
||||||
|
const timer = useTimer(60);
|
||||||
|
timer.start();
|
||||||
|
```
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
- 推荐优先使用根入口导入;如果需要更精确的模块边界,也可以使用子路径导入。
|
||||||
|
- 本包依赖 Vue3,请确保业务项目已安装兼容版本的 `vue`。
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@r-utils/vue3",
|
"name": "@r-utils/vue3",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "Vue3 工具",
|
"description": "Vue3 工具",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
@ -8,13 +8,30 @@
|
||||||
"module": "dist/index.mjs",
|
"module": "dist/index.mjs",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./dist/index.mjs",
|
"import": "./dist/index.mjs",
|
||||||
"require": "./dist/index.cjs"
|
"require": "./dist/index.cjs"
|
||||||
},
|
},
|
||||||
"./*": "./*"
|
"./hooks/list": {
|
||||||
|
"types": "./dist/hooks/list/index.d.ts",
|
||||||
|
"import": "./dist/hooks/list/index.mjs",
|
||||||
|
"require": "./dist/hooks/list/index.cjs"
|
||||||
|
},
|
||||||
|
"./hooks/utils": {
|
||||||
|
"types": "./dist/hooks/utils/index.d.ts",
|
||||||
|
"import": "./dist/hooks/utils/index.mjs",
|
||||||
|
"require": "./dist/hooks/utils/index.cjs"
|
||||||
|
},
|
||||||
|
"./vue-helper": {
|
||||||
|
"types": "./dist/vue-helper/index.d.ts",
|
||||||
|
"import": "./dist/vue-helper/index.mjs",
|
||||||
|
"require": "./dist/vue-helper/index.cjs"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"vue3"
|
"vue3"
|
||||||
|
|
@ -42,8 +59,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"watch": "vite build --watch",
|
"watch": "vite build --watch",
|
||||||
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||||
"lint": "eslint --ext .js,ts --fix src",
|
"lint": "eslint --ext .js,ts --fix src",
|
||||||
"release": "standard-version",
|
"format": "prettier --write src",
|
||||||
"commit": "cz",
|
"commit": "cz",
|
||||||
"lint-staged": "lint-staged",
|
"lint-staged": "lint-staged",
|
||||||
"test": "vitest run"
|
"test": "vitest run"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import type { Ref } from "vue";
|
||||||
*/
|
*/
|
||||||
export function useTimer(initTime = 0) {
|
export function useTimer(initTime = 0) {
|
||||||
const time = ref(initTime);
|
const time = ref(initTime);
|
||||||
const timeInterval = ref();
|
const timeInterval = ref<ReturnType<typeof setInterval>>();
|
||||||
|
|
||||||
const start = () => {
|
const start = () => {
|
||||||
timeInterval.value = setInterval(() => {
|
timeInterval.value = setInterval(() => {
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
export * from "./vue-helper"
|
export * from "./vue-helper";
|
||||||
|
export * from "./hooks/list";
|
||||||
|
export * from "./hooks/utils";
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ type CustomClass = string | Array<string> | CustomClassObj;
|
||||||
type DistCustomClass = Record<string, true>;
|
type DistCustomClass = Record<string, true>;
|
||||||
export function createCustomClassObj(customClass: string): DistCustomClass;
|
export function createCustomClassObj(customClass: string): DistCustomClass;
|
||||||
export function createCustomClassObj(
|
export function createCustomClassObj(
|
||||||
customClass: Array<string>
|
customClass: Array<string>,
|
||||||
): DistCustomClass;
|
): DistCustomClass;
|
||||||
export function createCustomClassObj(
|
export function createCustomClassObj(
|
||||||
customClass: string | Array<string>
|
customClass: string | Array<string>,
|
||||||
): DistCustomClass {
|
): DistCustomClass {
|
||||||
let customClassObj = <DistCustomClass>{};
|
let customClassObj = <DistCustomClass>{};
|
||||||
if (typeof customClass === "string") {
|
if (typeof customClass === "string") {
|
||||||
|
|
@ -26,7 +26,7 @@ export function createCustomClassObj(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`customClass只能是字符串或数组类型,customClass: ${customClass}`
|
`customClass只能是字符串或数组类型,customClass: ${customClass}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ export function convertCustomClass(sourceClass: CustomClass): CustomClassObj {
|
||||||
customClassObj = sourceClass;
|
customClassObj = sourceClass;
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`sourceClass不是有效的vue class,sourceClass: ${sourceClass}`
|
`sourceClass不是有效的vue class,sourceClass: ${sourceClass}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ export function convertCustomClass(sourceClass: CustomClass): CustomClassObj {
|
||||||
export function mergeClass(...customClass: CustomClass[]) {
|
export function mergeClass(...customClass: CustomClass[]) {
|
||||||
return customClass
|
return customClass
|
||||||
.map((cc) => convertCustomClass(cc))
|
.map((cc) => convertCustomClass(cc))
|
||||||
.reduce((a, b) => Object.assign(a, b),{});
|
.reduce((a, b) => Object.assign(a, b), {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -87,7 +87,7 @@ export function dispatch(
|
||||||
thisArg: ComponentPublicInstance,
|
thisArg: ComponentPublicInstance,
|
||||||
componentName: ComponentPublicInstance,
|
componentName: ComponentPublicInstance,
|
||||||
eventName: string,
|
eventName: string,
|
||||||
params: unknown
|
params: unknown,
|
||||||
): void {
|
): void {
|
||||||
let parent = thisArg.$parent || thisArg.$root;
|
let parent = thisArg.$parent || thisArg.$root;
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
|
|
@ -6,6 +6,6 @@
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as QQMapWX from "@jonny1994/qqmap-wx-jssdk";
|
import * as QQMapWX from "@jonny1994/qqmap-wx-jssdk";
|
||||||
|
|
||||||
export * from "@jonny1994/qqmap-wx-jssdk";
|
export * from "@jonny1994/qqmap-wx-jssdk";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,41 @@
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from "vite";
|
||||||
import dts from 'vite-plugin-dts';
|
import dts from "vite-plugin-dts";
|
||||||
import { resolve } from 'node:path';
|
import { resolve } from "node:path";
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
build: {
|
build: {
|
||||||
lib: {
|
lib: {
|
||||||
entry: resolve(__dirname, 'src/index.ts'),
|
entry: {
|
||||||
formats: ['es', 'cjs'],
|
index: resolve(__dirname, "src/index.ts"),
|
||||||
fileName: (format) => `index.${format === 'es' ? 'mjs' : 'cjs'}`,
|
"hooks/list/index": resolve(__dirname, "src/hooks/list/index.ts"),
|
||||||
|
"hooks/utils/index": resolve(__dirname, "src/hooks/utils/index.ts"),
|
||||||
|
"vue-helper/index": resolve(__dirname, "src/vue-helper/index.ts"),
|
||||||
|
},
|
||||||
|
formats: ["es", "cjs"],
|
||||||
|
fileName: (format, entryName) =>
|
||||||
|
`${entryName}.${format === "es" ? "mjs" : "cjs"}`,
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: ['vue', 'lodash'],
|
external: ["vue", "lodash"],
|
||||||
|
output: {
|
||||||
|
chunkFileNames: "chunks/[name]-[hash].js",
|
||||||
|
assetFileNames: "assets/[name]-[hash][extname]",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, 'src'),
|
"@": resolve(__dirname, "src"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
dts({
|
dts({
|
||||||
include: ['src'],
|
include: ["src"],
|
||||||
outDir: 'dist',
|
outDir: "dist",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
||||||
1421
pnpm-lock.yaml
1421
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
|
@ -1,80 +0,0 @@
|
||||||
# 发布所有子包到私有 npm 仓库
|
|
||||||
# 使用方法: powershell scripts/publish.ps1
|
|
||||||
# 注意: 发布仓库地址使用各子包 package.json 中的 publishConfig.registry 配置
|
|
||||||
# 版本管理请先通过 pnpm release (standard-version) 完成,本脚本仅负责构建和发布
|
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
|
||||||
|
|
||||||
Write-Host "🚀 开始发布流程" -ForegroundColor Green
|
|
||||||
Write-Host ""
|
|
||||||
|
|
||||||
# 子包列表
|
|
||||||
$PACKAGES = @(
|
|
||||||
"packages/common",
|
|
||||||
"packages/vue3",
|
|
||||||
"packages/uni-app",
|
|
||||||
"packages/uview-plus",
|
|
||||||
"packages/vue2"
|
|
||||||
)
|
|
||||||
|
|
||||||
# 1. 检查工作区是否干净
|
|
||||||
Write-Host "🔍 检查 Git 工作区状态..." -ForegroundColor Cyan
|
|
||||||
$gitStatus = git status -s
|
|
||||||
if ($gitStatus) {
|
|
||||||
Write-Host "⚠️ 工作区有未提交的更改,请先提交或暂存" -ForegroundColor Yellow
|
|
||||||
git status -s
|
|
||||||
$continue = Read-Host "是否继续? (y/N)"
|
|
||||||
if ($continue -ne "y" -and $continue -ne "Y") {
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Write-Host ""
|
|
||||||
|
|
||||||
# 2. 运行测试
|
|
||||||
Write-Host "🧪 运行测试..." -ForegroundColor Cyan
|
|
||||||
pnpm test
|
|
||||||
if ($LASTEXITCODE -ne 0) {
|
|
||||||
Write-Host "❌ 测试失败,停止发布" -ForegroundColor Red
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
Write-Host ""
|
|
||||||
|
|
||||||
# 3. 构建所有包
|
|
||||||
Write-Host "📦 构建所有包..." -ForegroundColor Cyan
|
|
||||||
pnpm build
|
|
||||||
if ($LASTEXITCODE -ne 0) {
|
|
||||||
Write-Host "❌ 构建失败,停止发布" -ForegroundColor Red
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
Write-Host ""
|
|
||||||
|
|
||||||
# 获取当前版本号
|
|
||||||
$CURRENT_VERSION = node -p "require('./package.json').version"
|
|
||||||
Write-Host " 当前版本: v$CURRENT_VERSION" -ForegroundColor Gray
|
|
||||||
Write-Host ""
|
|
||||||
|
|
||||||
# 4. 发布每个包
|
|
||||||
Write-Host "📤 开始发布包到 npm..." -ForegroundColor Cyan
|
|
||||||
foreach ($package in $PACKAGES) {
|
|
||||||
if (Test-Path $package) {
|
|
||||||
Push-Location $package
|
|
||||||
$PACKAGE_NAME = node -p "require('./package.json').name"
|
|
||||||
$PACKAGE_VERSION = node -p "require('./package.json').version"
|
|
||||||
Write-Host "📤 发布 $PACKAGE_NAME@$PACKAGE_VERSION ..." -ForegroundColor Cyan
|
|
||||||
pnpm publish --no-git-checks
|
|
||||||
if ($LASTEXITCODE -ne 0) {
|
|
||||||
Pop-Location
|
|
||||||
Write-Host "❌ $package 发布失败,停止后续发布" -ForegroundColor Red
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
Pop-Location
|
|
||||||
Write-Host "✅ $PACKAGE_NAME@$PACKAGE_VERSION 发布成功" -ForegroundColor Green
|
|
||||||
Write-Host ""
|
|
||||||
} else {
|
|
||||||
Write-Host "⚠️ 跳过不存在的包: $package" -ForegroundColor Yellow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Write-Host "🎉 所有包发布完成!版本: v$CURRENT_VERSION" -ForegroundColor Green
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# 发布所有子包到私有 npm 仓库
|
|
||||||
# 使用方法: bash scripts/publish.sh
|
|
||||||
# 注意: 发布仓库地址使用各子包 package.json 中的 publishConfig.registry 配置
|
|
||||||
# 版本管理请先通过 pnpm release (standard-version) 完成,本脚本仅负责构建和发布
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "🚀 开始发布流程"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# 子包列表
|
|
||||||
PACKAGES=(
|
|
||||||
"packages/common"
|
|
||||||
"packages/vue3"
|
|
||||||
"packages/uni-app"
|
|
||||||
"packages/vue2"
|
|
||||||
)
|
|
||||||
|
|
||||||
# 1. 检查工作区是否干净
|
|
||||||
echo "🔍 检查 Git 工作区状态..."
|
|
||||||
if [[ -n $(git status -s) ]]; then
|
|
||||||
echo "⚠️ 工作区有未提交的更改,请先提交或暂存"
|
|
||||||
git status -s
|
|
||||||
read -p "是否继续? (y/N) " -n 1 -r
|
|
||||||
echo
|
|
||||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# 2. 运行测试
|
|
||||||
echo "🧪 运行测试..."
|
|
||||||
if ! pnpm test; then
|
|
||||||
echo "❌ 测试失败,停止发布"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# 3. 构建所有包
|
|
||||||
echo "📦 构建所有包..."
|
|
||||||
if ! pnpm build; then
|
|
||||||
echo "❌ 构建失败,停止发布"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# 获取当前版本号
|
|
||||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
|
||||||
echo " 当前版本: v$CURRENT_VERSION"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# 4. 发布每个包
|
|
||||||
echo "📤 开始发布包到 npm..."
|
|
||||||
for package in "${PACKAGES[@]}"; do
|
|
||||||
if [ -d "$package" ]; then
|
|
||||||
PACKAGE_NAME=$(node -p "require('./$package/package.json').name")
|
|
||||||
PACKAGE_VERSION=$(node -p "require('./$package/package.json').version")
|
|
||||||
echo "📤 发布 $PACKAGE_NAME@$PACKAGE_VERSION ..."
|
|
||||||
cd "$package"
|
|
||||||
if ! pnpm publish --no-git-checks; then
|
|
||||||
echo "❌ $package 发布失败,停止后续发布"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
cd - > /dev/null
|
|
||||||
echo "✅ $PACKAGE_NAME@$PACKAGE_VERSION 发布成功"
|
|
||||||
echo ""
|
|
||||||
else
|
|
||||||
echo "⚠️ 跳过不存在的包: $package"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# 5. 推送到远程仓库
|
|
||||||
echo "🔼 推送到远程仓库..."
|
|
||||||
read -p "是否推送到远程仓库? (y/N) " -n 1 -r
|
|
||||||
echo
|
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
||||||
git push origin master
|
|
||||||
git push origin --tags
|
|
||||||
echo "✅ 已推送到远程仓库"
|
|
||||||
else
|
|
||||||
echo "⚠️ 跳过推送,请手动执行:"
|
|
||||||
echo " git push origin master"
|
|
||||||
echo " git push origin --tags"
|
|
||||||
fi
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
echo "🎉 所有包发布完成!版本: v$CURRENT_VERSION"
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"lib": ["dom", "esnext"],
|
"lib": ["dom", "esnext"],
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"declaration": true,
|
"noEmit": true,
|
||||||
"skipLibCheck": true
|
"skipLibCheck": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,6 @@
|
||||||
{
|
{
|
||||||
"extends": "./tsconfig.base.json",
|
"extends": "./tsconfig.base.json",
|
||||||
"include": [
|
"include": ["vitest.config.ts", "packages/*/src/**/*.ts", "packages/*/src/**/*.js", "packages/*/types/**/*.d.ts"],
|
||||||
"vitest.config.ts",
|
|
||||||
"packages/*/src/**/*.ts",
|
|
||||||
"packages/*/src/**/*.js",
|
|
||||||
"packages/*/types/**/*.d.ts"
|
|
||||||
],
|
|
||||||
"exclude": ["**/node_modules/**", "**/dist/**"],
|
"exclude": ["**/node_modules/**", "**/dist/**"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"noEmit": true
|
"noEmit": true
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://turbo.build/schema.json",
|
||||||
|
"tasks": {
|
||||||
|
"build": {
|
||||||
|
"dependsOn": ["^build"],
|
||||||
|
"outputs": ["dist/**"]
|
||||||
|
},
|
||||||
|
"watch": {
|
||||||
|
"cache": false,
|
||||||
|
"persistent": true
|
||||||
|
},
|
||||||
|
"lint": {
|
||||||
|
"outputs": []
|
||||||
|
},
|
||||||
|
"format": {
|
||||||
|
"outputs": []
|
||||||
|
},
|
||||||
|
"typecheck": {
|
||||||
|
"outputs": []
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"dependsOn": ["^build"],
|
||||||
|
"outputs": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue