feat(playground): 新增示例项目

This commit is contained in:
2026-06-30 11:21:16 +08:00
parent 4759dfe6b2
commit c22b72ac7b
78 changed files with 9058 additions and 213 deletions
+6
View File
@@ -1,5 +1,11 @@
# @r-utils/uni-app
## 2.0.2
### Patch Changes
- 修复vue3未导出
## 2.0.1
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@r-utils/uni-app",
"version": "2.0.1",
"version": "2.0.2",
"private": false,
"description": "uni-app工具库",
"type": "module",
+47
View File
@@ -1,17 +1,56 @@
/*
* @file \src\printer\index.ts
* @description 蓝牙打印工具,最后打印的一步,组合蓝牙信息与打印数据发送
* @author tsl (randy1924@163.com)
* @date 2026-05-28 11:13:40
* @lastModified 2026-06-30 11:02:16
* @lastModifiedBy tsl (randy1924@163.com)
*/
import { wait } from "@r-utils/common";
import { BluetoothUtils, Device } from "@/bluetooth-utils";
/** 蓝牙设备完整数据,包含设备信息和所有必需的特征值 ID */
type DeviceData = Required<Device>;
/**
* 蓝牙打印机工具类
*
* 将蓝牙设备信息与打印数据组合,通过 BLE 写入特征值发送 ESC/POS 打印指令。
* 支持安卓原生发送和通用 BLE 写入两种方式,自动根据平台选择。
* 打印数据会按 size 分包发送,每包之间等待 30ms 以确保数据传输稳定。
*
* @example
* ```ts
* const printer = new Printer(device, { size: 80 })
* await printer.print(escData) // escData 为 ESC/POS 指令的 number 数组
* ```
*/
export class Printer {
/** 蓝牙设备信息,包含 deviceId、服务 ID 和特征值 ID 等 */
device: DeviceData;
/** 每次写入 BLE 的最大字节数,默认 80 */
size = 0;
/**
* @param device 蓝牙设备完整数据(必须包含所有特征值 ID)
* @param size 每次写入的最大字节数,默认 80
*/
constructor(device: DeviceData, { size = 80 } = {}) {
this.device = device;
this.size = size;
}
/**
* 发送打印数据
*
* 根据平台自动选择发送方式:
* - 安卓 App 端:使用 BluetoothUtils.sendDataAndroid 原生发送
* - 其他平台:通过 BLE 写入特征值发送
*
* @param data ESC/POS 打印指令数组
* @returns 发送结果
*/
async print(data: number[]) {
console.log(
data.length,
@@ -32,6 +71,14 @@ export class Printer {
return res;
}
/**
* 通过 BLE 写入特征值分包发送打印数据(内部方法)
*
* 将数据按 size 分包,每包创建 ArrayBuffer 写入 BLE 特征值,
* 包间等待 30ms 确保传输稳定,递归发送直到所有数据写完。
*
* @param data 剩余待发送的打印数据
*/
async _print(data: number[]): Promise<void> {
const size = Math.min(data.length, this.size);
if (size === 0) {
+9
View File
@@ -1,3 +1,12 @@
/*
* @file \src\request\Request.ts
* @description uniapp请求类。建议改用 alova[https://alova.js.org/zh-CN/]
* @author tsl (randy1924@163.com)
* @date 2026-05-28 11:13:40
* @lastModified 2026-06-30 10:14:09
* @lastModifiedBy tsl (randy1924@163.com)
*/
export type DataType = string | AnyObject | ArrayBuffer;
/** 请求配置 */
+9
View File
@@ -1,3 +1,12 @@
/*
* @file \src\upload\index.ts
* @description uniapp上传文件工具
* @author tsl (randy1924@163.com)
* @date 2026-05-28 11:13:40
* @lastModified 2026-06-30 10:54:55
* @lastModifiedBy tsl (randy1924@163.com)
*/
type UploadResponseData = {
originalFileName: string;
url: string;
@@ -1,9 +1,9 @@
/*
* @file /src/vue3/hooks/components.ts
* @description
* @description uniapp组件hook
* @author tsl (randy1924@163.com)
* @date 2026-03-19 11:11:11
* @lastModified 2026-03-26 09:16:44
* @lastModified 2026-06-30 10:55:21
* @lastModifiedBy tsl (randy1924@163.com)
*/