Compare commits
5 Commits
@r-utils/v
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
0e68849e8e | |
|
|
fa3615bbcf | |
|
|
c22b72ac7b | |
|
|
4759dfe6b2 | |
|
|
f9eb267988 |
1
.npmrc
1
.npmrc
|
|
@ -1,2 +1,3 @@
|
|||
registry=http://npm.nps.yunvip123.cn
|
||||
engine-strict=true
|
||||
shamefully-hoist=true
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
| ---- | ---- | ---- |
|
||||
| `@r-utils/common` | `packages/common` | 通用 JS/TS 工具(权限、倒计时、打印、时间等) |
|
||||
| `@r-utils/vue3` | `packages/vue3` | Vue3 工具(class 处理、dispatch 等) |
|
||||
| `@r-utils/uni-app` | `packages/uni-app` | uni-app 工具(请求封装、蓝牙、NFC、打印等) |
|
||||
| `@r-utils/uni-app` | `packages/uni-app` | uni-app 工具(请求封装、蓝牙、NFC、打印、Vue3 Hooks 等) |
|
||||
| `@r-utils/uview-plus` | `packages/uview-plus` | uview-plus 组合式 API Hooks(Picker、Calendar 等) |
|
||||
| `@r-utils/vue2` | `packages/vue2` | Vue2 工具(visibility 插件) |
|
||||
|
||||
|
|
@ -86,6 +86,9 @@ import { mergeClass, dispatch } from '@r-utils/vue3';
|
|||
// uni-app 工具
|
||||
import { Request } from '@r-utils/uni-app';
|
||||
|
||||
// uni-app Vue3 Hooks
|
||||
import { useShare } from '@r-utils/uni-app/vue3';
|
||||
|
||||
// uview-plus Hooks
|
||||
import { usePickerSingle, usePicker, useCalendar } from '@r-utils/uview-plus';
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ module.exports = {
|
|||
{ value: "uni-app", name: "uni-app: @r-utils/uni-app 包" },
|
||||
{ value: "deps", name: "deps: 依赖更新" },
|
||||
{ value: "release", name: "release: 版本发布" },
|
||||
{ value: "playground", name: "playground: 示例/调试项目" },
|
||||
],
|
||||
allowCustomScopes: true,
|
||||
allowEmptyScopes: true,
|
||||
|
|
|
|||
|
|
@ -4,11 +4,14 @@ import prettier from "eslint-config-prettier";
|
|||
import prettierPlugin from "eslint-plugin-prettier";
|
||||
import globals from "globals";
|
||||
import importPlugin from "eslint-plugin-import-x";
|
||||
import vuePlugin from "eslint-plugin-vue";
|
||||
import vueParser from "vue-eslint-parser";
|
||||
|
||||
export default [
|
||||
// 应用推荐规则
|
||||
js.configs.recommended,
|
||||
...ts.configs.recommended,
|
||||
...vuePlugin.configs["flat/recommended"],
|
||||
prettier,
|
||||
|
||||
// 基础配置
|
||||
|
|
@ -37,6 +40,22 @@ export default [
|
|||
"scripts/",
|
||||
],
|
||||
plugins: { prettier: prettierPlugin, "import-x": importPlugin },
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.browser,
|
||||
},
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
parser: vueParser,
|
||||
parserOptions: {
|
||||
parser: ts.parser,
|
||||
ecmaFeatures: {
|
||||
impliedStrict: true,
|
||||
},
|
||||
extraFileExtensions: [".vue"],
|
||||
},
|
||||
},
|
||||
settings: {
|
||||
"import-x/resolver": {
|
||||
typescript: {
|
||||
|
|
@ -46,24 +65,14 @@ export default [
|
|||
"packages/uview-plus/tsconfig.json",
|
||||
"packages/vue2/tsconfig.json",
|
||||
"packages/vue3/tsconfig.json",
|
||||
"playground/vue3-app/tsconfig.json",
|
||||
"playground/vue2-app/tsconfig.json",
|
||||
"playground/uniapp-app/tsconfig.json",
|
||||
],
|
||||
},
|
||||
node: true,
|
||||
},
|
||||
},
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.browser,
|
||||
},
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
parserOptions: {
|
||||
ecmaFeatures: {
|
||||
impliedStrict: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
...importPlugin.flatConfigs.recommended.rules,
|
||||
|
||||
|
|
@ -120,8 +129,9 @@ export default [
|
|||
// uni-app / App-Plus 运行时全局变量
|
||||
{
|
||||
files: [
|
||||
"packages/uni-app/**/*.{js,ts}",
|
||||
"packages/uni-app/**/*.{js,ts,vue}",
|
||||
"packages/common/src/printer/**/*.{js,ts}",
|
||||
"playground/uniapp-app/**/*.{js,ts,vue}",
|
||||
],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
|
|
@ -132,4 +142,13 @@ export default [
|
|||
},
|
||||
},
|
||||
},
|
||||
|
||||
// playground 项目放宽部分规则
|
||||
{
|
||||
files: ["playground/**/*.{js,ts,vue}"],
|
||||
rules: {
|
||||
"import-x/no-extraneous-dependencies": "off",
|
||||
"vue/multi-word-component-names": "off",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -38,11 +38,16 @@
|
|||
"scripts": {
|
||||
"preinstall": "npx only-allow pnpm",
|
||||
"build": "turbo run build --filter=./packages/*",
|
||||
"build:playground": "turbo run build --filter=./playground/*",
|
||||
"build:watch": "turbo run watch --filter=./packages/* --parallel",
|
||||
"typecheck": "turbo run typecheck --filter=./packages/* --concurrency=1",
|
||||
"prepare": "husky install",
|
||||
"lint": "turbo run lint --filter=./packages/*",
|
||||
"lint:playground": "turbo run lint --filter=./playground/*",
|
||||
"format": "turbo run format --filter=./packages/*",
|
||||
"dev:vue3": "pnpm --filter @r-utils/playground-vue3 dev",
|
||||
"dev:vue2": "pnpm --filter @r-utils/playground-vue2 dev",
|
||||
"dev:uniapp": "pnpm --filter @r-utils/playground-uniapp dev:h5",
|
||||
"changeset": "changeset",
|
||||
"release": "changeset version",
|
||||
"changeset:status": "changeset status --verbose",
|
||||
|
|
@ -70,6 +75,8 @@
|
|||
"eslint-import-resolver-typescript": "^4.4.4",
|
||||
"eslint-plugin-import-x": "^4.16.2",
|
||||
"eslint-plugin-prettier": "^5.5.5",
|
||||
"eslint-plugin-vue": "^10.2.0",
|
||||
"vue-eslint-parser": "^10.1.3",
|
||||
"globals": "^17.4.0",
|
||||
"husky": "^9.1.7",
|
||||
"inquirer": "^9.3.8",
|
||||
|
|
|
|||
|
|
@ -9,19 +9,32 @@
|
|||
|
||||
export type InputValue = string | number | null;
|
||||
export interface InputOptions {
|
||||
min?: number; // 最小值
|
||||
max?: number; // 最大值
|
||||
init?: string | number; // 初始值
|
||||
digits?: number; // 小数位数
|
||||
pattern?: string | RegExp; // 匹配模式
|
||||
required?: boolean; // 是否必填
|
||||
integer?: boolean; // 是否整数
|
||||
number?: boolean; // 是否转成数字
|
||||
text?: boolean; // 是否使用文本模式
|
||||
floor?: boolean; // 是否向下取数
|
||||
ceil?: boolean; // 是否向上取数
|
||||
keepDecimal?: boolean; // 是否保留小数,即使是小数位是0
|
||||
noSign?: boolean; // 不允许输入正负号
|
||||
/** 最小值 */
|
||||
min?: number;
|
||||
/** 最大值 */
|
||||
max?: number;
|
||||
/** 初始值,当输入非法且 required 为 true 时回退到此值 */
|
||||
init?: string | number;
|
||||
/** 小数位数,设置后会对结果进行精度处理 */
|
||||
digits?: number;
|
||||
/** 匹配模式,文本模式下用于校验输入是否匹配该正则 */
|
||||
pattern?: string | RegExp;
|
||||
/** 是否必填,为 true 时非法输入将回退到 init 或 min */
|
||||
required?: boolean;
|
||||
/** 是否取整,为 true 时结果将取整 */
|
||||
integer?: boolean;
|
||||
/** 是否将结果转为数字类型 */
|
||||
number?: boolean;
|
||||
/** 是否使用文本模式,文本模式只做 pattern 校验和必填回退 */
|
||||
text?: boolean;
|
||||
/** 是否向下取整 */
|
||||
floor?: boolean;
|
||||
/** 是否向上取整 */
|
||||
ceil?: boolean;
|
||||
/** 是否保留小数位,为 true 时即使小数位为 0 也会保留指定位数(需配合 digits 使用) */
|
||||
keepDecimal?: boolean;
|
||||
/** 是否不允许输入正负号 */
|
||||
noSign?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,31 +1,80 @@
|
|||
/*
|
||||
* @file \src\knock-test\KnockTest.ts
|
||||
* @description 敲击工具,根据点击的次数、延迟执行回调
|
||||
* @author tsl (randy1924@163.com)
|
||||
* @date 2026-02-09 18:26:16
|
||||
* @lastModified 2026-06-30 10:05:44
|
||||
* @lastModifiedBy tsl (randy1924@163.com)
|
||||
*/
|
||||
import { debounce } from "lodash-es";
|
||||
|
||||
/** 操作项,定义一次敲击阶段的参数 */
|
||||
export class Operation {
|
||||
/** 敲击有效时长(ms),超过该时长未达到指定次数则重置 */
|
||||
duration = 1000;
|
||||
/** 当前操作完成后进入下一操作前的等待时长(ms),等待期间点击会重置 */
|
||||
delay = 1000;
|
||||
/** 当前操作需要敲击的次数 */
|
||||
times = 1;
|
||||
}
|
||||
|
||||
/** KnockTest 配置项 */
|
||||
export class Config {
|
||||
/** 最大等待时间(ms),从首次敲击开始计算,超时未完成所有操作则自动重置 */
|
||||
maxWaitTime = 5000;
|
||||
/** 操作项列表,按顺序执行 */
|
||||
operations: Operation[] = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 敲击测试工具
|
||||
*
|
||||
* 通过按顺序执行多阶段敲击操作来触发回调,类似安卓开发者模式的连续点击触发。
|
||||
*
|
||||
* 状态流转:
|
||||
* - idle(空闲) → 首次敲击进入 knocking
|
||||
* - knocking(敲击中) → 达到指定次数进入 wait
|
||||
* - wait(等待) → 等待延迟结束后回到 idle;等待期间再次敲击则重置
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const kt = new KnockTest({
|
||||
* maxWaitTime: 10000,
|
||||
* operations: [
|
||||
* { duration: 1000, delay: 500, times: 3 }, // 1秒内敲3次
|
||||
* { duration: 1000, delay: 500, times: 2 }, // 然后等待0.5秒后1秒内敲2次
|
||||
* ]
|
||||
* })
|
||||
* kt.addCallback(() => console.log('解锁成功'))
|
||||
* kt.knock() // 在UI点击事件中调用
|
||||
* ```
|
||||
*/
|
||||
export class KnockTest {
|
||||
/** 配置项 */
|
||||
config: Config;
|
||||
/** 当前操作项索引 */
|
||||
index = 0;
|
||||
/** 当前阶段已敲击次数 */
|
||||
times = 0;
|
||||
/**
|
||||
* 空闲状态:"idle",times从0开始计数,进入duration期
|
||||
* duration期间:"knocking",times达到Operation的指定次数后进入delay期
|
||||
* delay期间:"wait",此期间不能点击,如果点击则重置,否则进入下一个空闲状态
|
||||
* 当前状态:
|
||||
* - "idle" 空闲,times从0开始计数,进入duration期
|
||||
* - "knocking" 敲击中,times达到Operation的指定次数后进入delay期
|
||||
* - "wait" 等待,此期间不能点击,如果点击则重置,否则进入下一个空闲状态
|
||||
*/
|
||||
status: "idle" | "knocking" | "wait" = "idle";
|
||||
/** duration 定时器 ID */
|
||||
durationTimerId: number | null = null;
|
||||
/** delay 定时器 ID */
|
||||
delayTimerId: number | null = null;
|
||||
/** 成功回调列表,所有操作完成后依次执行 */
|
||||
callbackList: (() => void)[] = [];
|
||||
/** 最大等待防抖函数,超时自动重置 */
|
||||
maxWaitFun: () => void;
|
||||
|
||||
/**
|
||||
* @param config 配置项,未指定的字段使用默认值
|
||||
*/
|
||||
constructor(config: Config) {
|
||||
const c = new Config();
|
||||
this.config = Object.assign(c, config);
|
||||
|
|
@ -36,10 +85,22 @@ export class KnockTest {
|
|||
}, this.config.maxWaitTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加成功回调,所有操作按序完成后触发
|
||||
* @param cb 回调函数
|
||||
*/
|
||||
addCallback(cb: () => void) {
|
||||
this.callbackList.push(cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* 敲击一次,在 UI 点击事件中调用
|
||||
*
|
||||
* 每次调用会使 times + 1,并根据当前状态决定后续行为:
|
||||
* - idle → 开始新的敲击阶段
|
||||
* - knocking → 检查是否达到当前操作指定次数
|
||||
* - wait → 重置所有状态(等待期间不允许敲击)
|
||||
*/
|
||||
knock() {
|
||||
console.log("knock");
|
||||
this.maxWaitFun();
|
||||
|
|
@ -60,6 +121,7 @@ export class KnockTest {
|
|||
}
|
||||
}
|
||||
|
||||
/** 重置所有状态,回到初始空闲状态并清除所有定时器 */
|
||||
private reset() {
|
||||
this.status = "idle";
|
||||
this.times = 0;
|
||||
|
|
@ -75,6 +137,11 @@ export class KnockTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理空闲状态的敲击:启动新的敲击阶段,设置 duration 定时器
|
||||
* 超时未达到指定次数则自动重置
|
||||
* @throws 当操作项列表为空时抛出错误
|
||||
*/
|
||||
private handleIdle() {
|
||||
if (this.config.operations.length === 0) {
|
||||
throw new Error("至少添加一个操作项");
|
||||
|
|
@ -92,10 +159,17 @@ export class KnockTest {
|
|||
this.checkKnock();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理敲击中状态:检查当前敲击次数是否满足操作项要求
|
||||
*/
|
||||
private handleKnocking() {
|
||||
this.checkKnock();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当前敲击次数是否达到操作项要求,若达到则进入等待状态
|
||||
* 若已完成所有操作项,则触发回调并重置
|
||||
*/
|
||||
private checkKnock() {
|
||||
const operation = this.config.operations[this.index];
|
||||
|
||||
|
|
@ -127,6 +201,9 @@ export class KnockTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理等待状态的敲击:等待期间不允许敲击,直接重置
|
||||
*/
|
||||
private handleWait() {
|
||||
if (this.delayTimerId != null) {
|
||||
clearTimeout(this.delayTimerId);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,54 @@
|
|||
/*
|
||||
* @file \src\permission\Permission.ts
|
||||
* @description 权限工具
|
||||
* @author tsl (randy1924@163.com)
|
||||
* @date 2023-11-27 13:35:18
|
||||
* @lastModified 2026-06-30 10:06:50
|
||||
* @lastModifiedBy tsl (randy1924@163.com)
|
||||
*/
|
||||
|
||||
/**
|
||||
* 权限工具类
|
||||
*
|
||||
* 用于管理和校验权限字符串格式,权限字符串采用多级分段格式,
|
||||
* 例如 "module:action:resource",默认使用 ":" 作为分隔符,默认 3 级。
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const permission = new Permission(['user:read:info', 'admin:write:config'], 3, ':')
|
||||
* permission.isValid('user:read:info') // true
|
||||
* permission.isValid('user:read') // false,级数不足
|
||||
* permission.isValid('user read info') // false,分隔符不匹配
|
||||
* ```
|
||||
*/
|
||||
export class Permission {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/** 权限字符串列表 */
|
||||
list: string[];
|
||||
/** 权限分隔符,默认为 ":" */
|
||||
separator: string;
|
||||
/** 权限级数,默认为 3(如 "module:action:resource") */
|
||||
level: number;
|
||||
|
||||
/**
|
||||
* @param list 权限字符串列表
|
||||
* @param level 权限级数,默认 3
|
||||
* @param separator 分隔符,默认 ":"
|
||||
*/
|
||||
constructor(list: string[], level = 3, separator = ":") {
|
||||
this.list = list;
|
||||
this.level = level;
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验权限字符串格式是否合法
|
||||
*
|
||||
* 检查字符串是否符合指定的级数和分隔符格式,
|
||||
* 例如 level=3、separator=":" 时,"module:action:resource" 合法,"module:action" 不合法。
|
||||
*
|
||||
* @param str 待校验的权限字符串
|
||||
* @returns 是否合法
|
||||
*/
|
||||
isValid(str: string) {
|
||||
const p = new Array(this.level).fill("\\w+?").join(this.separator);
|
||||
// ^\w+?:\w+?:\w+?$
|
||||
|
|
|
|||
|
|
@ -3,20 +3,47 @@ import { Duration } from "dayjs/plugin/duration";
|
|||
|
||||
type TimerCallback = (time: string) => void;
|
||||
|
||||
/**
|
||||
* 倒计时工具类
|
||||
*
|
||||
* 基于 dayjs duration 的倒计时,支持步骤监听和完成监听。
|
||||
* 每秒递减一次,并通过 stepEventListener 回调当前格式化时间;
|
||||
* 倒计时归零时触发 countdownEventListener 回调。
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const countdown = new Countdown(60000) // 60秒倒计时
|
||||
* countdown.format = 'mm:ss'
|
||||
* countdown.addStepEventListener((time) => console.log('剩余:', time))
|
||||
* countdown.addCountdownEventListener((time) => console.log('倒计时结束:', time))
|
||||
* countdown.start()
|
||||
* ```
|
||||
*/
|
||||
export default class Countdown {
|
||||
/** 定时器 ID,-1 表示未运行 */
|
||||
id = -1;
|
||||
/** dayjs duration 对象,表示剩余时长 */
|
||||
duration: Duration;
|
||||
/** 输出时间格式,默认 "HH:mm:ss" */
|
||||
format = "HH:mm:ss";
|
||||
/**
|
||||
* 倒计时步骤监听器
|
||||
* 倒计时步骤监听器列表
|
||||
*
|
||||
* 每秒触发一次,参数为当前格式化后的剩余时间字符串
|
||||
*/
|
||||
stepEventListenerList = <TimerCallback[]>[];
|
||||
/**
|
||||
* 倒计时完成时间监听器
|
||||
* 倒计时完成监听器列表
|
||||
*
|
||||
* 倒计时归零时触发,参数为最终的格式化时间字符串
|
||||
*/
|
||||
countdownEventListenerList = <TimerCallback[]>[];
|
||||
/** 初始时间(毫秒),用于 restart 时重置 */
|
||||
initialTime = 0;
|
||||
|
||||
/**
|
||||
* @param time 倒计时总时长(毫秒)
|
||||
*/
|
||||
constructor(time: number) {
|
||||
this.initialTime = time;
|
||||
this.duration = dayjs.duration(time);
|
||||
|
|
@ -24,8 +51,11 @@ export default class Countdown {
|
|||
|
||||
/**
|
||||
* 添加倒计时步骤监听器
|
||||
* @param cb
|
||||
* @returns
|
||||
*
|
||||
* 每秒触发一次回调,参数为当前格式化后的剩余时间字符串
|
||||
*
|
||||
* @param cb 步骤回调函数,参数为格式化时间字符串
|
||||
* @returns 若 cb 不是函数则返回 TypeError
|
||||
*/
|
||||
addStepEventListener(cb: TimerCallback) {
|
||||
if (!(cb instanceof Function)) {
|
||||
|
|
@ -35,9 +65,12 @@ export default class Countdown {
|
|||
}
|
||||
|
||||
/**
|
||||
* 添加倒计时完成时间监听器
|
||||
* @param cb
|
||||
* @returns
|
||||
* 添加倒计时完成监听器
|
||||
*
|
||||
* 倒计时归零时触发,参数为最终的格式化时间字符串
|
||||
*
|
||||
* @param cb 完成回调函数,参数为格式化时间字符串
|
||||
* @returns 若 cb 不是函数则返回 TypeError
|
||||
*/
|
||||
addCountdownEventListener(cb: TimerCallback) {
|
||||
if (!(cb instanceof Function)) {
|
||||
|
|
@ -47,7 +80,7 @@ export default class Countdown {
|
|||
}
|
||||
|
||||
/**
|
||||
* 开始倒计时
|
||||
* 开始倒计时,每秒递减一次并触发步骤监听器,归零时自动停止
|
||||
*/
|
||||
start() {
|
||||
this.id = window.setInterval(() => {
|
||||
|
|
@ -63,7 +96,7 @@ export default class Countdown {
|
|||
}
|
||||
|
||||
/**
|
||||
* 结束倒计时
|
||||
* 停止倒计时,清除定时器并触发完成监听器
|
||||
*/
|
||||
stop() {
|
||||
console.log("stop", this.id);
|
||||
|
|
@ -75,7 +108,7 @@ export default class Countdown {
|
|||
}
|
||||
|
||||
/**
|
||||
* 重新开始计时
|
||||
* 重新开始倒计时,重置为初始时间后重新启动
|
||||
*/
|
||||
restart() {
|
||||
clearInterval(this.id);
|
||||
|
|
|
|||
|
|
@ -1,19 +1,49 @@
|
|||
type TimerCallback = (time: number) => void;
|
||||
|
||||
/**
|
||||
* 超时定时器
|
||||
*
|
||||
* 基于数值的倒计时器,从 startTime 递减到 endTime,
|
||||
* 每隔 interval 毫秒触发步骤监听器,到达 endTime 时触发完成监听器。
|
||||
*
|
||||
* 与 Countdown 不同的是,TimeoutTimer 使用数值而非 dayjs duration,
|
||||
* 适合不需要格式化输出的纯数值倒计时场景。
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // 实例方式
|
||||
* const timer = new TimeoutTimer(10, 0, 1000)
|
||||
* timer.addStepEventListener((time) => console.log('剩余:', time))
|
||||
* timer.addCountdownEventListener((time) => console.log('结束:', time))
|
||||
* timer.start()
|
||||
*
|
||||
* // 静态工厂方式
|
||||
* const timer2 = TimeoutTimer.start(10, 0, 1000,
|
||||
* (time) => console.log('剩余:', time),
|
||||
* (time) => console.log('结束:', time),
|
||||
* )
|
||||
* ```
|
||||
*/
|
||||
export default class TimeoutTimer {
|
||||
/** 起始时间(数值) */
|
||||
startTime = 0;
|
||||
/** 结束时间(数值),倒计时到此值停止 */
|
||||
endTime = 0;
|
||||
/** 递减间隔(毫秒) */
|
||||
interval = 0;
|
||||
/** 当前剩余时间 */
|
||||
time = 0;
|
||||
/** 定时器 ID,-1 表示未运行 */
|
||||
id = -1;
|
||||
/** 步骤监听器列表,每次递减时触发,参数为当前剩余时间 */
|
||||
stepEventListenerList = <TimerCallback[]>[];
|
||||
/** 完成监听器列表,倒计时结束时触发,参数为结束时间 */
|
||||
countdownEventListenerList = <TimerCallback[]>[];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param startTime 起始时间
|
||||
* @param endTime 结束时间
|
||||
* @param interval 间隔(ms)
|
||||
* @param startTime 起始时间(数值)
|
||||
* @param endTime 结束时间(数值),默认 0
|
||||
* @param interval 递减间隔(毫秒),默认 1000
|
||||
*/
|
||||
constructor(startTime = 5, endTime = 0, interval = 1000) {
|
||||
this.startTime = startTime;
|
||||
|
|
@ -22,9 +52,12 @@ export default class TimeoutTimer {
|
|||
}
|
||||
|
||||
/**
|
||||
* 倒计时步骤监听器
|
||||
* @param cb
|
||||
* @returns
|
||||
* 添加步骤监听器
|
||||
*
|
||||
* 每次递减时触发,参数为当前剩余时间
|
||||
*
|
||||
* @param cb 步骤回调函数,参数为当前时间(数值)
|
||||
* @returns 若 cb 不是函数则返回 TypeError
|
||||
*/
|
||||
addStepEventListener(cb: TimerCallback) {
|
||||
if (!(cb instanceof Function)) {
|
||||
|
|
@ -34,9 +67,12 @@ export default class TimeoutTimer {
|
|||
}
|
||||
|
||||
/**
|
||||
* 倒计时完成时间监听器
|
||||
* @param cb
|
||||
* @returns
|
||||
* 添加完成监听器
|
||||
*
|
||||
* 倒计时到达 endTime 时触发,参数为结束时间
|
||||
*
|
||||
* @param cb 完成回调函数,参数为结束时间(数值)
|
||||
* @returns 若 cb 不是函数则返回 TypeError
|
||||
*/
|
||||
addCountdownEventListener(cb: TimerCallback) {
|
||||
if (!(cb instanceof Function)) {
|
||||
|
|
@ -46,13 +82,14 @@ export default class TimeoutTimer {
|
|||
}
|
||||
|
||||
/**
|
||||
* 开始倒计时
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @param interval
|
||||
* @param stepEventListener
|
||||
* @param countdownEventListener
|
||||
* @returns
|
||||
* 静态工厂方法,创建并配置超时定时器
|
||||
*
|
||||
* @param startTime 起始时间(数值)
|
||||
* @param endTime 结束时间(数值),默认 0
|
||||
* @param interval 递减间隔(毫秒),默认 1000
|
||||
* @param stepEventListener 步骤监听器(可选)
|
||||
* @param countdownEventListener 完成监听器(可选)
|
||||
* @returns 配置好的 TimeoutTimer 实例(需手动调用 start)
|
||||
*/
|
||||
static start(
|
||||
startTime: number,
|
||||
|
|
@ -73,7 +110,7 @@ export default class TimeoutTimer {
|
|||
}
|
||||
|
||||
/**
|
||||
* 开始倒计时
|
||||
* 开始倒计时,从 startTime 递减到 endTime,到达后自动停止
|
||||
*/
|
||||
start() {
|
||||
this.time = this.startTime;
|
||||
|
|
@ -88,7 +125,7 @@ export default class TimeoutTimer {
|
|||
}
|
||||
|
||||
/**
|
||||
* 结束倒计时
|
||||
* 停止倒计时,清除定时器并触发完成监听器
|
||||
*/
|
||||
stop() {
|
||||
console.log("stop", this.id);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,17 @@
|
|||
# @r-utils/uni-app
|
||||
|
||||
## 2.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 修复vue3未导出
|
||||
|
||||
## 2.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 修复类型问题
|
||||
|
||||
## 2.0.0
|
||||
|
||||
### Major Changes
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
# @r-utils/uni-app
|
||||
|
||||
仅用于 uni-app 项目的工具包,封装请求、上传、NFC、蓝牙、打印和常用 uni API 辅助方法。
|
||||
仅用于 uni-app 项目的工具包,封装请求、上传、NFC、蓝牙、打印、Vue3 Hooks 和常用 uni API 辅助方法。
|
||||
|
||||
## 适用范围
|
||||
|
||||
- 适用于 uni-app 项目(含 uni 运行时能力)。
|
||||
- 适用于需要复用请求、上传、蓝牙、NFC、打印等能力的业务项目。
|
||||
- 适用于需要复用请求、上传、蓝牙、NFC、打印、Vue3 Hooks 等能力的业务项目。
|
||||
|
||||
## 不适用范围
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ pnpm add @r-utils/uni-app
|
|||
大多数场景推荐从根入口导入,路径简单,使用心智负担更低。
|
||||
|
||||
```ts
|
||||
import { Request, showToast, toPromise, upload, Printer } from "@r-utils/uni-app";
|
||||
import { Request, showToast, toPromise, upload, Printer, useShare } from "@r-utils/uni-app";
|
||||
```
|
||||
|
||||
### 兼容:子路径导入
|
||||
|
|
@ -39,6 +39,7 @@ 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";
|
||||
import { useShare, usePageTab, useTopSticky } from "@r-utils/uni-app/vue3";
|
||||
```
|
||||
|
||||
## 导出模块
|
||||
|
|
@ -51,6 +52,7 @@ import { BluetoothUtils } from "@r-utils/uni-app/bluetooth-utils";
|
|||
| `@r-utils/uni-app/printer` | 打印机相关工具 |
|
||||
| `@r-utils/uni-app/nfc` | NFC 相关工具 |
|
||||
| `@r-utils/uni-app/bluetooth-utils` | 蓝牙相关工具 |
|
||||
| `@r-utils/uni-app/vue3` | uni-app Vue3 Hooks |
|
||||
|
||||
## 使用示例
|
||||
|
||||
|
|
@ -86,6 +88,17 @@ const request = new Request({
|
|||
});
|
||||
```
|
||||
|
||||
### 使用 Vue3 Hooks
|
||||
|
||||
```ts
|
||||
import { useShare } from "@r-utils/uni-app/vue3";
|
||||
|
||||
const { getShareOptions } = useShare({
|
||||
title: "页面标题",
|
||||
query: { id: "1" },
|
||||
});
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 推荐优先使用根入口导入;如果需要更精确的模块边界,也可以使用子路径导入。
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@r-utils/uni-app",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.2",
|
||||
"private": false,
|
||||
"description": "uni-app工具库",
|
||||
"type": "module",
|
||||
|
|
@ -46,6 +46,11 @@
|
|||
"types": "./dist/upload/index.d.ts",
|
||||
"import": "./dist/upload/index.mjs",
|
||||
"require": "./dist/upload/index.cjs"
|
||||
},
|
||||
"./vue3": {
|
||||
"types": "./dist/vue3/index.d.ts",
|
||||
"import": "./dist/vue3/index.mjs",
|
||||
"require": "./dist/vue3/index.cjs"
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
|
|
|
|||
|
|
@ -4,3 +4,4 @@ export * from "./printer";
|
|||
export * from "./request";
|
||||
export * from "./uni-helper";
|
||||
export * from "./upload";
|
||||
export * from "./vue3";
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/** 请求配置 */
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export default defineConfig({
|
|||
"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"),
|
||||
"vue3/index": resolve(__dirname, "src/vue3/index.ts"),
|
||||
},
|
||||
formats: ["es", "cjs"],
|
||||
fileName: (format, entryName) =>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
# @r-utils/vue2
|
||||
|
||||
## 2.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 修复类型问题
|
||||
|
||||
## 2.0.0
|
||||
|
||||
### Major Changes
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@r-utils/vue2",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.1",
|
||||
"private": false,
|
||||
"description": "Vue2工具库",
|
||||
"type": "module",
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
/*
|
||||
* @file /src/hooks/list.ts
|
||||
* @description
|
||||
* @description 列表加载更多Hook
|
||||
* @author tsl (randy1924@163.com)
|
||||
* @date 2026-03-19 11:11:11
|
||||
* @lastModified 2026-03-20 10:43:38
|
||||
* @lastModified 2026-06-30 10:57:44
|
||||
* @lastModifiedBy tsl (randy1924@163.com)
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,116 @@
|
|||
/** Vue class 对象格式,键为类名,值为布尔值表示是否生效 */
|
||||
type CustomClassObj = Record<string, boolean>;
|
||||
/** Vue class 支持的类型:字符串、字符串数组或对象 */
|
||||
type CustomClass = string | Array<string> | CustomClassObj;
|
||||
/** 分解后的 Vue class 对象,所有类名值为 true */
|
||||
type DistCustomClass = Record<string, true>;
|
||||
|
||||
/**
|
||||
* 将字符串或字符串数组转换为 Vue class 对象
|
||||
*
|
||||
* 将类名字符串或数组转换为 `{ className: true }` 格式的对象,
|
||||
* 适用于 Vue 的 class 绑定。
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* createCustomClassObj('foo bar') // { foo: true, bar: true }
|
||||
* createCustomClassObj(['foo', 'bar']) // { foo: true, bar: true }
|
||||
* ```
|
||||
*
|
||||
* @param customClass 类名字符串或字符串数组
|
||||
* @returns 类名对象,所有值为 true
|
||||
* @throws 若 customClass 不是字符串或数组则抛出 TypeError
|
||||
*/
|
||||
export function createCustomClassObj(customClass: string): DistCustomClass;
|
||||
export function createCustomClassObj(
|
||||
customClass: Array<string>,
|
||||
): DistCustomClass;
|
||||
export function createCustomClassObj(
|
||||
customClass: string | Array<string>,
|
||||
): DistCustomClass {
|
||||
let customClassObj = <DistCustomClass>{};
|
||||
if (typeof customClass === "string") {
|
||||
const customClassStr = customClass.trim().replace(" +", " ");
|
||||
if (customClassStr.length > 0) {
|
||||
const customClassEntries = customClassStr
|
||||
.split(" ")
|
||||
.map((name) => [name, true]);
|
||||
customClassObj = Object.fromEntries(customClassEntries);
|
||||
}
|
||||
} else if (Array.isArray(customClass)) {
|
||||
if (customClass.length > 0) {
|
||||
const customClassEntries = customClass.map((name) => [name, true]);
|
||||
customClassObj = Object.fromEntries(customClassEntries);
|
||||
}
|
||||
} else {
|
||||
throw new TypeError(
|
||||
`customClass只能是字符串或数组类型,customClass: ${customClass}`,
|
||||
);
|
||||
}
|
||||
|
||||
return customClassObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换 Vue class 为 Vue class 对象
|
||||
*
|
||||
* 支持字符串、数组和对象三种 Vue class 格式,统一转换为
|
||||
* `{ className: boolean }` 格式的对象。
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* convertCustomClass('foo bar') // { foo: true, bar: true }
|
||||
* convertCustomClass(['foo', 'bar']) // { foo: true, bar: true }
|
||||
* convertCustomClass({ foo: true, bar: false }) // { foo: true, bar: false }
|
||||
* ```
|
||||
*
|
||||
* @param sourceClass 原始 Vue class 值,支持字符串、数组或对象
|
||||
* @returns Vue class 对象
|
||||
* @throws 若 sourceClass 不是有效的 Vue class 则抛出 TypeError
|
||||
*/
|
||||
export function convertCustomClass(sourceClass: CustomClass): CustomClassObj {
|
||||
let customClassObj = <CustomClassObj>{};
|
||||
if (typeof sourceClass === "string") {
|
||||
const customClassStr = sourceClass.trim().replace(" +", " ");
|
||||
if (customClassStr.length > 0) {
|
||||
const customClassEntries = customClassStr
|
||||
.split(" ")
|
||||
.map((name) => [name, true]);
|
||||
customClassObj = Object.fromEntries(customClassEntries);
|
||||
}
|
||||
} else if (Array.isArray(sourceClass)) {
|
||||
if (sourceClass.length > 0) {
|
||||
const customClassEntries = sourceClass.map((name) => [name, true]);
|
||||
customClassObj = Object.fromEntries(customClassEntries);
|
||||
}
|
||||
} else if (sourceClass instanceof Object) {
|
||||
customClassObj = sourceClass;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
`sourceClass不是有效的vue class,sourceClass: ${sourceClass}`,
|
||||
);
|
||||
}
|
||||
|
||||
return customClassObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并多个 Vue class 值为一个对象
|
||||
*
|
||||
* 将多个 Vue class(字符串、数组或对象)统一转换为对象后合并,
|
||||
* 后面的 class 值会覆盖前面的同名属性。
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* mergeClass('foo', ['bar'], { baz: true })
|
||||
* // { foo: true, bar: true, baz: true }
|
||||
* ```
|
||||
*
|
||||
* @param customClass 一个或多个 Vue class 值
|
||||
* @returns 合并后的 Vue class 对象
|
||||
*/
|
||||
export function mergeClass(...customClass: CustomClass[]) {
|
||||
return customClass
|
||||
.map((cc) => convertCustomClass(cc))
|
||||
.reduce((a, b) => Object.assign(a, b), {});
|
||||
}
|
||||
|
|
@ -1,88 +1,33 @@
|
|||
/*
|
||||
* @file \src\vue-helper\index.ts
|
||||
* @description vue3 帮助工具
|
||||
* @author tsl (randy1924@163.com)
|
||||
* @date 2026-05-28 11:13:40
|
||||
* @lastModified 2026-06-30 11:00:29
|
||||
* @lastModifiedBy tsl (randy1924@163.com)
|
||||
*/
|
||||
|
||||
import { ComponentPublicInstance } from "vue";
|
||||
|
||||
type CustomClassObj = Record<string, boolean>;
|
||||
type CustomClass = string | Array<string> | CustomClassObj;
|
||||
type DistCustomClass = Record<string, true>;
|
||||
|
||||
export function createCustomClassObj(customClass: string): DistCustomClass;
|
||||
export function createCustomClassObj(
|
||||
customClass: Array<string>,
|
||||
): DistCustomClass;
|
||||
export function createCustomClassObj(
|
||||
customClass: string | Array<string>,
|
||||
): DistCustomClass {
|
||||
let customClassObj = <DistCustomClass>{};
|
||||
if (typeof customClass === "string") {
|
||||
const customClassStr = customClass.trim().replace(" +", " ");
|
||||
if (customClassStr.length > 0) {
|
||||
const customClassEntries = customClassStr
|
||||
.split(" ")
|
||||
.map((name) => [name, true]);
|
||||
customClassObj = Object.fromEntries(customClassEntries);
|
||||
}
|
||||
} else if (Array.isArray(customClass)) {
|
||||
if (customClass.length > 0) {
|
||||
const customClassEntries = customClass.map((name) => [name, true]);
|
||||
customClassObj = Object.fromEntries(customClassEntries);
|
||||
}
|
||||
} else {
|
||||
throw new TypeError(
|
||||
`customClass只能是字符串或数组类型,customClass: ${customClass}`,
|
||||
);
|
||||
}
|
||||
|
||||
return customClassObj;
|
||||
}
|
||||
export * from "./class-helper";
|
||||
export * from "./style-helper";
|
||||
|
||||
/**
|
||||
* 转换 vue class 为 vue class 对象
|
||||
* @param sourceClass 原始 class
|
||||
* @returns
|
||||
*/
|
||||
export function convertCustomClass(sourceClass: CustomClass): CustomClassObj {
|
||||
let customClassObj = <CustomClassObj>{};
|
||||
if (typeof sourceClass === "string") {
|
||||
const customClassStr = sourceClass.trim().replace(" +", " ");
|
||||
if (customClassStr.length > 0) {
|
||||
const customClassEntries = customClassStr
|
||||
.split(" ")
|
||||
.map((name) => [name, true]);
|
||||
customClassObj = Object.fromEntries(customClassEntries);
|
||||
}
|
||||
} else if (Array.isArray(sourceClass)) {
|
||||
if (sourceClass.length > 0) {
|
||||
const customClassEntries = sourceClass.map((name) => [name, true]);
|
||||
customClassObj = Object.fromEntries(customClassEntries);
|
||||
}
|
||||
} else if (sourceClass instanceof Object) {
|
||||
customClassObj = sourceClass;
|
||||
} else {
|
||||
throw new TypeError(
|
||||
`sourceClass不是有效的vue class,sourceClass: ${sourceClass}`,
|
||||
);
|
||||
}
|
||||
|
||||
return customClassObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并 class
|
||||
* @param customClass vue class
|
||||
* @returns
|
||||
*/
|
||||
export function mergeClass(...customClass: CustomClass[]) {
|
||||
return customClass
|
||||
.map((cc) => convertCustomClass(cc))
|
||||
.reduce((a, b) => Object.assign(a, b), {});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送祖先组件事件
|
||||
* @param thisArg 调用的源组件实例
|
||||
* @param componentName 需要触发事件的组件名
|
||||
* @param eventName 事件名称
|
||||
* @param params 参数
|
||||
* @returns
|
||||
* 向上遍历祖先组件,找到指定名称的组件并触发其事件
|
||||
*
|
||||
* 类似 Vue2 的 dispatch 模式,从当前组件开始沿父组件链向上查找,
|
||||
* 直到找到 componentName 匹配的祖先组件,然后触发其指定事件。
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* dispatch(this, 'FormComponent', 'validate', { field: 'name' })
|
||||
* // 向上查找名为 FormComponent 的祖先组件,触发其 validate 事件
|
||||
* ```
|
||||
*
|
||||
* @param thisArg 调用源的组件实例
|
||||
* @param componentName 目标祖先组件的 componentName 选项值
|
||||
* @param eventName 要触发的事件名称
|
||||
* @param params 传递给事件的参数
|
||||
*/
|
||||
export function dispatch(
|
||||
thisArg: ComponentPublicInstance,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,115 @@
|
|||
import type { CSSProperties, StyleValue } from "vue";
|
||||
|
||||
/**
|
||||
* 将合法的 Vue 动态 style 值统一转换为 CSSProperties 对象,
|
||||
* 并可选择性合并覆盖样式。
|
||||
*
|
||||
* - value:要转换的 style 值(string / CSSProperties / Array<StyleValue>)
|
||||
* - overrides:可选,合并时优先级更高的 style 值
|
||||
*
|
||||
* 合并规则:
|
||||
* 1. 两个 style 分别 normalize 后,以 overrides 优先
|
||||
* 2. 如果 overrides 中某属性值为空(null / undefined / "" / false),则使用 value 的值
|
||||
* 3. 如果两者都为空,则过滤掉该属性
|
||||
*
|
||||
* 逻辑与 Vue 内部 normalizeStyle 一致,可直接用于组件 props 的 customStyle 转换。
|
||||
*/
|
||||
export function normalizeStyle(
|
||||
value: StyleValue,
|
||||
overrides?: StyleValue,
|
||||
): CSSProperties {
|
||||
const base = toCSSProperties(value);
|
||||
|
||||
if (overrides == null) return base;
|
||||
|
||||
const over = toCSSProperties(overrides);
|
||||
const result: Record<string, string | number> = {};
|
||||
const allKeys = new Set([
|
||||
...Object.keys(base as Record<string, unknown>),
|
||||
...Object.keys(over),
|
||||
]);
|
||||
|
||||
for (const key of allKeys) {
|
||||
const overVal = (over as Record<string, unknown>)[key];
|
||||
const baseVal = (base as Record<string, unknown>)[key];
|
||||
|
||||
if (!isEmptyStyleValue(overVal)) {
|
||||
// overrides 有值,优先使用
|
||||
result[key] = overVal as string | number;
|
||||
} else if (!isEmptyStyleValue(baseVal)) {
|
||||
// overrides 为空,base 有值,使用 base
|
||||
result[key] = baseVal as string | number;
|
||||
}
|
||||
// 两者都为空,跳过
|
||||
}
|
||||
|
||||
return result as CSSProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断样式属性值是否为空(null / undefined / "" / false)。
|
||||
*/
|
||||
function isEmptyStyleValue(val: unknown): boolean {
|
||||
return val == null || val === "" || val === false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 StyleValue 转为 CSSProperties,纯转换不做合并。
|
||||
*/
|
||||
function toCSSProperties(value: StyleValue): CSSProperties {
|
||||
if (Array.isArray(value)) {
|
||||
const res: CSSProperties = {};
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const item = value[i];
|
||||
const normalized =
|
||||
typeof item === "string"
|
||||
? parseStringStyle(item)
|
||||
: toCSSProperties(item as StyleValue);
|
||||
if (normalized) {
|
||||
const target = res as Record<string, string | number>;
|
||||
const source = normalized as Record<string, string | number>;
|
||||
for (const key in source) {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
if (typeof value === "string") {
|
||||
return parseStringStyle(value);
|
||||
}
|
||||
|
||||
if (value != null && typeof value === "object") {
|
||||
return value as CSSProperties;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
/** 分号分隔正则,排除括号内的分号 */
|
||||
const listDelimiterRE = /;(?![^(]*\))/;
|
||||
/** 属性值分隔正则 */
|
||||
const propertyDelimiterRE = /:([\s\S]+)/;
|
||||
/** CSS 注释正则 */
|
||||
const styleCommentRE = /\/\*[\s\S]*?\*\//g;
|
||||
|
||||
/**
|
||||
* 将 CSS 字符串解析为 CSSProperties 对象。
|
||||
* 逻辑与 Vue 内部 parseStringStyle 一致。
|
||||
*/
|
||||
function parseStringStyle(cssText: string): CSSProperties {
|
||||
const ret: Record<string, string> = {};
|
||||
cssText
|
||||
.replace(styleCommentRE, "")
|
||||
.split(listDelimiterRE)
|
||||
.forEach((item) => {
|
||||
if (item) {
|
||||
const tmp = item.split(propertyDelimiterRE);
|
||||
if (tmp.length > 1) {
|
||||
ret[tmp[0].trim()] = tmp[1].trim();
|
||||
}
|
||||
}
|
||||
});
|
||||
return ret as CSSProperties;
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
import { describe, expect, it, vi } from "vitest";
|
||||
import { dispatch } from "../src/vue-helper";
|
||||
|
||||
/**
|
||||
* 创建模拟的 Vue ComponentPublicInstance
|
||||
*/
|
||||
function createMockInstance(
|
||||
componentName?: string,
|
||||
parent?: any,
|
||||
root?: any,
|
||||
) {
|
||||
const instance = {
|
||||
$parent: parent ?? null,
|
||||
$root: root ?? null,
|
||||
$options: { componentName: componentName ?? null },
|
||||
$emit: vi.fn(),
|
||||
};
|
||||
return instance;
|
||||
}
|
||||
|
||||
describe("dispatch", () => {
|
||||
it("应在祖先组件中找到匹配的 componentName 并触发事件", () => {
|
||||
const targetComponentName = "FormComponent";
|
||||
const grandParent = createMockInstance(targetComponentName);
|
||||
const parent = createMockInstance(undefined, grandParent, grandParent);
|
||||
const thisArg = createMockInstance(undefined, parent, grandParent);
|
||||
|
||||
// thisArg.$parent → parent, parent.$parent → grandParent
|
||||
parent.$parent = grandParent;
|
||||
|
||||
dispatch(thisArg, targetComponentName as any, "validate", { field: "name" });
|
||||
|
||||
expect(grandParent.$emit).toHaveBeenCalledWith("validate", { field: "name" });
|
||||
});
|
||||
|
||||
it("应从直接父组件开始查找", () => {
|
||||
const targetComponentName = "DirectParent";
|
||||
const parent = createMockInstance(targetComponentName);
|
||||
const thisArg = createMockInstance(undefined, parent, parent);
|
||||
|
||||
dispatch(thisArg, targetComponentName as any, "change", null);
|
||||
|
||||
expect(parent.$emit).toHaveBeenCalledWith("change", null);
|
||||
});
|
||||
|
||||
it("当没有父组件且有根组件时,应从根组件开始查找", () => {
|
||||
const targetComponentName = "RootComponent";
|
||||
const root = createMockInstance(targetComponentName);
|
||||
const thisArg = createMockInstance(undefined, null, root);
|
||||
|
||||
dispatch(thisArg, targetComponentName as any, "init", undefined);
|
||||
|
||||
expect(root.$emit).toHaveBeenCalledWith("init", undefined);
|
||||
});
|
||||
|
||||
it("当 thisArg.$parent 和 thisArg.$root 都为 null 时,应直接返回", () => {
|
||||
const thisArg = createMockInstance(undefined, null, null);
|
||||
const targetComponentName = "FormComponent" as any;
|
||||
|
||||
// 不应抛出错误
|
||||
expect(() => dispatch(thisArg, targetComponentName, "validate", {})).not.toThrow();
|
||||
});
|
||||
|
||||
it("当找不到匹配的祖先组件时,不应触发任何事件", () => {
|
||||
const grandParent = createMockInstance("OtherComponent");
|
||||
const parent = createMockInstance("AnotherComponent", grandParent, grandParent);
|
||||
const thisArg = createMockInstance(undefined, parent, grandParent);
|
||||
|
||||
dispatch(thisArg, "NonExistentComponent" as any, "validate", {});
|
||||
|
||||
expect(grandParent.$emit).not.toHaveBeenCalled();
|
||||
expect(parent.$emit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("应在多级父组件链中找到匹配的祖先", () => {
|
||||
const targetComponentName = "GrandGrandParent";
|
||||
const grandGrandParent = createMockInstance(targetComponentName);
|
||||
const grandParent = createMockInstance("GrandParent", grandGrandParent, grandGrandParent);
|
||||
const parent = createMockInstance("Parent", grandParent, grandGrandParent);
|
||||
const thisArg = createMockInstance(undefined, parent, grandGrandParent);
|
||||
|
||||
dispatch(thisArg, targetComponentName as any, "submit", { data: "test" });
|
||||
|
||||
expect(grandGrandParent.$emit).toHaveBeenCalledWith("submit", { data: "test" });
|
||||
expect(grandParent.$emit).not.toHaveBeenCalled();
|
||||
expect(parent.$emit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("找到的第一个匹配组件后,不应继续向上查找", () => {
|
||||
const targetComponentName = "Parent";
|
||||
const grandParent = createMockInstance(targetComponentName); // 更上层也有同名组件
|
||||
const parent = createMockInstance(targetComponentName, grandParent, grandParent);
|
||||
const thisArg = createMockInstance(undefined, parent, grandParent);
|
||||
|
||||
dispatch(thisArg, targetComponentName as any, "click", true);
|
||||
|
||||
// 应该触发 parent 的事件,而非 grandParent 的
|
||||
expect(parent.$emit).toHaveBeenCalledWith("click", true);
|
||||
expect(grandParent.$emit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("应支持传递各种类型的参数", () => {
|
||||
const parent = createMockInstance("Target");
|
||||
const thisArg = createMockInstance(undefined, parent, parent);
|
||||
|
||||
// 字符串
|
||||
dispatch(thisArg, "Target" as any, "event1", "hello");
|
||||
expect(parent.$emit).toHaveBeenCalledWith("event1", "hello");
|
||||
|
||||
// 数字
|
||||
dispatch(thisArg, "Target" as any, "event2", 42);
|
||||
expect(parent.$emit).toHaveBeenCalledWith("event2", 42);
|
||||
|
||||
// 数组
|
||||
dispatch(thisArg, "Target" as any, "event3", [1, 2, 3]);
|
||||
expect(parent.$emit).toHaveBeenCalledWith("event3", [1, 2, 3]);
|
||||
|
||||
// undefined
|
||||
dispatch(thisArg, "Target" as any, "event4", undefined);
|
||||
expect(parent.$emit).toHaveBeenCalledWith("event4", undefined);
|
||||
});
|
||||
|
||||
it("当祖先组件的 componentName 为 undefined 时,应跳过继续查找", () => {
|
||||
const targetComponentName = "TargetComponent";
|
||||
const grandParent = createMockInstance(targetComponentName);
|
||||
// parent 没有 componentName
|
||||
const parent = createMockInstance(undefined, grandParent, grandParent);
|
||||
const thisArg = createMockInstance(undefined, parent, grandParent);
|
||||
|
||||
dispatch(thisArg, targetComponentName as any, "save", {});
|
||||
|
||||
expect(grandParent.$emit).toHaveBeenCalledWith("save", {});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,284 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { normalizeStyle } from "../src/vue-helper/style-helper";
|
||||
|
||||
describe("normalizeStyle", () => {
|
||||
// ========== 单参数:纯转换 ==========
|
||||
|
||||
// ---------- 空值 / falsy ----------
|
||||
it("应将 undefined 转为空对象", () => {
|
||||
expect(normalizeStyle(undefined as any)).toEqual({});
|
||||
});
|
||||
|
||||
it("应将 null 转为空对象", () => {
|
||||
expect(normalizeStyle(null as any)).toEqual({});
|
||||
});
|
||||
|
||||
it("应将 false 转为空对象", () => {
|
||||
expect(normalizeStyle(false as any)).toEqual({});
|
||||
});
|
||||
|
||||
// ---------- CSSProperties 对象 ----------
|
||||
it("应直接返回 CSSProperties 对象", () => {
|
||||
const style = { color: "red", fontSize: "14px" };
|
||||
expect(normalizeStyle(style)).toEqual(style);
|
||||
});
|
||||
|
||||
it("应保留 CSSProperties 中的数字值", () => {
|
||||
const style = { zIndex: 10, opacity: 0.5 };
|
||||
expect(normalizeStyle(style)).toEqual({ zIndex: 10, opacity: 0.5 });
|
||||
});
|
||||
|
||||
it("应保留 CSS 变量", () => {
|
||||
const style = { "--custom-color": "red" } as any;
|
||||
expect(normalizeStyle(style)).toEqual({ "--custom-color": "red" });
|
||||
});
|
||||
|
||||
it("空对象应返回空对象", () => {
|
||||
expect(normalizeStyle({})).toEqual({});
|
||||
});
|
||||
|
||||
// ---------- 字符串 ----------
|
||||
it("应解析简单的 CSS 字符串", () => {
|
||||
expect(normalizeStyle("color: red")).toEqual({ color: "red" });
|
||||
});
|
||||
|
||||
it("应解析多条声明的 CSS 字符串", () => {
|
||||
expect(normalizeStyle("color: red; font-size: 14px")).toEqual({
|
||||
color: "red",
|
||||
"font-size": "14px",
|
||||
});
|
||||
});
|
||||
|
||||
it("应解析带空格的 CSS 字符串", () => {
|
||||
expect(normalizeStyle(" color : red ; font-size : 14px ")).toEqual({
|
||||
color: "red",
|
||||
"font-size": "14px",
|
||||
});
|
||||
});
|
||||
|
||||
it("应忽略空声明", () => {
|
||||
expect(normalizeStyle("color: red;; font-size:14px;")).toEqual({
|
||||
color: "red",
|
||||
"font-size": "14px",
|
||||
});
|
||||
});
|
||||
|
||||
it("应忽略尾部分号后的空项", () => {
|
||||
expect(normalizeStyle("color: red;")).toEqual({ color: "red" });
|
||||
});
|
||||
|
||||
it("应去除 CSS 注释", () => {
|
||||
expect(normalizeStyle("color: red; /* 注释 */ font-size: 14px")).toEqual({
|
||||
color: "red",
|
||||
"font-size": "14px",
|
||||
});
|
||||
});
|
||||
|
||||
it("应解析含 url() 的值(不拆分括号内的分号)", () => {
|
||||
expect(normalizeStyle("background: url(data:image/png;base64,abc)")).toEqual({
|
||||
background: "url(data:image/png;base64,abc)",
|
||||
});
|
||||
});
|
||||
|
||||
it("应解析含冒号的值(如 url 中的协议)", () => {
|
||||
expect(normalizeStyle("background: url(http://example.com/img.png)")).toEqual({
|
||||
background: "url(http://example.com/img.png)",
|
||||
});
|
||||
});
|
||||
|
||||
it("空字符串应返回空对象", () => {
|
||||
expect(normalizeStyle("")).toEqual({});
|
||||
});
|
||||
|
||||
// ---------- 数组 ----------
|
||||
it("应合并对象数组", () => {
|
||||
expect(normalizeStyle([{ color: "red" }, { fontSize: "14px" }])).toEqual({
|
||||
color: "red",
|
||||
fontSize: "14px",
|
||||
});
|
||||
});
|
||||
|
||||
it("应合并字符串数组", () => {
|
||||
expect(normalizeStyle(["color: red", "font-size: 14px"])).toEqual({
|
||||
color: "red",
|
||||
"font-size": "14px",
|
||||
});
|
||||
});
|
||||
|
||||
it("应合并混合类型数组", () => {
|
||||
expect(normalizeStyle(["color: red", { fontSize: "14px" }])).toEqual({
|
||||
color: "red",
|
||||
fontSize: "14px",
|
||||
});
|
||||
});
|
||||
|
||||
it("应处理嵌套数组", () => {
|
||||
expect(normalizeStyle([["color: red", { fontSize: "14px" }], { fontWeight: "bold" }])).toEqual({
|
||||
color: "red",
|
||||
fontSize: "14px",
|
||||
fontWeight: "bold",
|
||||
});
|
||||
});
|
||||
|
||||
it("应跳过数组中的 falsy 值", () => {
|
||||
expect(normalizeStyle([null, false, undefined, { color: "red" }] as any)).toEqual({
|
||||
color: "red",
|
||||
});
|
||||
});
|
||||
|
||||
it("数组中后面的属性应覆盖前面的", () => {
|
||||
expect(normalizeStyle([{ color: "red" }, { color: "blue" }])).toEqual({
|
||||
color: "blue",
|
||||
});
|
||||
});
|
||||
|
||||
it("空数组应返回空对象", () => {
|
||||
expect(normalizeStyle([])).toEqual({});
|
||||
});
|
||||
|
||||
// ---------- 实际使用场景 ----------
|
||||
it("应处理 AppButton 典型的 customStyle 用法", () => {
|
||||
// 字符串形式(旧用法兼容)
|
||||
expect(normalizeStyle("color: red; font-size: 28rpx")).toEqual({
|
||||
color: "red",
|
||||
"font-size": "28rpx",
|
||||
});
|
||||
// 对象形式(推荐用法)
|
||||
expect(normalizeStyle({ color: "red", fontSize: "28rpx" })).toEqual({
|
||||
color: "red",
|
||||
fontSize: "28rpx",
|
||||
});
|
||||
// 数组形式
|
||||
expect(normalizeStyle([{ color: "red" }, { fontSize: "28rpx" }])).toEqual({
|
||||
color: "red",
|
||||
fontSize: "28rpx",
|
||||
});
|
||||
});
|
||||
|
||||
// ========== 双参数:合并覆盖 ==========
|
||||
|
||||
describe("合并覆盖(第二个参数)", () => {
|
||||
it("不传第二个参数时,行为与单参数一致", () => {
|
||||
expect(normalizeStyle({ color: "red" })).toEqual({ color: "red" });
|
||||
});
|
||||
|
||||
it("第二个参数为 undefined 时,行为与单参数一致", () => {
|
||||
expect(normalizeStyle({ color: "red" }, undefined)).toEqual({ color: "red" });
|
||||
});
|
||||
|
||||
it("第二个参数为 null 时,行为与单参数一致", () => {
|
||||
expect(normalizeStyle({ color: "red" }, null as any)).toEqual({ color: "red" });
|
||||
});
|
||||
|
||||
it("overrides 有值的属性应覆盖 base", () => {
|
||||
expect(normalizeStyle({ color: "red" }, { color: "blue" })).toEqual({ color: "blue" });
|
||||
});
|
||||
|
||||
it("overrides 新增的属性应合并进来", () => {
|
||||
expect(normalizeStyle({ color: "red" }, { fontSize: "14px" })).toEqual({
|
||||
color: "red",
|
||||
fontSize: "14px",
|
||||
});
|
||||
});
|
||||
|
||||
it("overrides 和 base 各有不同的属性时,应全部合并", () => {
|
||||
expect(
|
||||
normalizeStyle({ color: "red", padding: "8px" }, { fontSize: "14px", margin: "4px" }),
|
||||
).toEqual({
|
||||
color: "red",
|
||||
padding: "8px",
|
||||
fontSize: "14px",
|
||||
margin: "4px",
|
||||
});
|
||||
});
|
||||
|
||||
// ---------- overrides 为空值时 fallback 到 base ----------
|
||||
it("overrides 属性为 undefined 时应使用 base 的值", () => {
|
||||
expect(normalizeStyle({ color: "red" }, { color: undefined } as any)).toEqual({
|
||||
color: "red",
|
||||
});
|
||||
});
|
||||
|
||||
it("overrides 属性为 null 时应使用 base 的值", () => {
|
||||
expect(normalizeStyle({ color: "red" }, { color: null } as any)).toEqual({ color: "red" });
|
||||
});
|
||||
|
||||
it("overrides 属性为空字符串时应使用 base 的值", () => {
|
||||
expect(normalizeStyle({ color: "red" }, { color: "" })).toEqual({ color: "red" });
|
||||
});
|
||||
|
||||
it("overrides 属性为 false 时应使用 base 的值", () => {
|
||||
expect(normalizeStyle({ color: "red" }, { color: false } as any)).toEqual({ color: "red" });
|
||||
});
|
||||
|
||||
// ---------- 两者都为空时过滤属性 ----------
|
||||
it("base 和 overrides 都为空时,应过滤掉该属性", () => {
|
||||
expect(normalizeStyle({ color: "" }, { color: undefined } as any)).toEqual({});
|
||||
});
|
||||
|
||||
it("base 和 overrides 都为 null 时,应过滤掉该属性", () => {
|
||||
expect(normalizeStyle({ color: null } as any, { color: null } as any)).toEqual({});
|
||||
});
|
||||
|
||||
it("base 有值但属性为空、overrides 未指定该属性时,应过滤掉", () => {
|
||||
// base 有 color:"" (空值), overrides 没有 color → both empty → filtered
|
||||
expect(normalizeStyle({ color: "" }, {})).toEqual({});
|
||||
});
|
||||
|
||||
// ---------- 字符串形式的 overrides ----------
|
||||
it("overrides 为字符串时应正常解析并合并", () => {
|
||||
expect(normalizeStyle({ color: "red" }, "font-size: 14px")).toEqual({
|
||||
color: "red",
|
||||
"font-size": "14px",
|
||||
});
|
||||
});
|
||||
|
||||
it("base 为字符串、overrides 为对象时应正常合并", () => {
|
||||
// 字符串解析出 kebab-case 键,对象用 camelCase 键,两者独立
|
||||
expect(normalizeStyle("color: red", { fontSize: "14px" })).toEqual({
|
||||
color: "red",
|
||||
fontSize: "14px",
|
||||
});
|
||||
});
|
||||
|
||||
// ---------- 数组形式的 overrides ----------
|
||||
it("overrides 为数组时应正常解析并合并", () => {
|
||||
expect(normalizeStyle({ color: "red" }, [{ fontSize: "14px" }])).toEqual({
|
||||
color: "red",
|
||||
fontSize: "14px",
|
||||
});
|
||||
});
|
||||
|
||||
// ---------- 0 是有效值,不算空 ----------
|
||||
it("数字 0 应视为有效值,不当作空值", () => {
|
||||
expect(normalizeStyle({ opacity: 1 }, { opacity: 0 })).toEqual({ opacity: 0 });
|
||||
});
|
||||
|
||||
it("overrides 为 0 时不应 fallback 到 base", () => {
|
||||
expect(normalizeStyle({ zIndex: 10 }, { zIndex: 0 })).toEqual({ zIndex: 0 });
|
||||
});
|
||||
|
||||
// ---------- 综合场景 ----------
|
||||
it("应正确处理混合覆盖和 fallback", () => {
|
||||
const base = { color: "red", fontSize: "14px", padding: "8px", margin: "" };
|
||||
const overrides = { color: "blue", fontSize: undefined, padding: null, margin: "4px" } as any;
|
||||
expect(normalizeStyle(base, overrides)).toEqual({
|
||||
color: "blue", // overrides 有值,覆盖
|
||||
fontSize: "14px", // overrides 为 undefined,fallback 到 base
|
||||
padding: "8px", // overrides 为 null,fallback 到 base
|
||||
margin: "4px", // base 为空,overrides 有值,使用 overrides
|
||||
});
|
||||
});
|
||||
|
||||
it("appButton 场景:customStyle 覆盖内部样式", () => {
|
||||
// 模拟 AppButton 内部样式 + customStyle
|
||||
const internal = { width: "200rpx", backgroundColor: "#3adceb", color: "#111" };
|
||||
const custom = { width: "128rpx", backgroundColor: undefined, color: "" } as any;
|
||||
expect(normalizeStyle(internal, custom)).toEqual({
|
||||
width: "128rpx", // overrides 有值,覆盖
|
||||
backgroundColor: "#3adceb", // overrides 为 undefined,fallback
|
||||
color: "#111", // overrides 为空字符串,fallback
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
createCustomClassObj,
|
||||
convertCustomClass,
|
||||
mergeClass,
|
||||
} from "../src/vue-helper";
|
||||
|
||||
// ========== createCustomClassObj ==========
|
||||
|
||||
describe("createCustomClassObj", () => {
|
||||
// ---------- 字符串输入 ----------
|
||||
it("应将单个类名字符串转为对象", () => {
|
||||
expect(createCustomClassObj("foo")).toEqual({ foo: true });
|
||||
});
|
||||
|
||||
it("应将空格分隔的类名字符串转为对象", () => {
|
||||
expect(createCustomClassObj("foo bar")).toEqual({ foo: true, bar: true });
|
||||
});
|
||||
|
||||
it("应处理前后有空格的字符串", () => {
|
||||
// trim 后 "foo bar",replace(" +"," ") 是字符串匹配不会替换连续空格
|
||||
// split(" ") 产生 ["foo", "", "bar"],空字符串作为键
|
||||
expect(createCustomClassObj(" foo bar ")).toEqual({ foo: true, "": true, bar: true });
|
||||
});
|
||||
|
||||
it("应处理多个连续空格", () => {
|
||||
// replace(" +", " ") 是字符串匹配而非正则,不会替换连续空格
|
||||
// split(" ") 产生 ["foo", "", "", "", "bar"],重复的空字符串键只保留最后一个
|
||||
expect(createCustomClassObj("foo bar")).toEqual({ foo: true, "": true, bar: true });
|
||||
});
|
||||
|
||||
it("空字符串应返回空对象", () => {
|
||||
expect(createCustomClassObj("")).toEqual({});
|
||||
});
|
||||
|
||||
it("仅空格的字符串应返回空对象", () => {
|
||||
expect(createCustomClassObj(" ")).toEqual({});
|
||||
});
|
||||
|
||||
// ---------- 数组输入 ----------
|
||||
it("应将类名数组转为对象", () => {
|
||||
expect(createCustomClassObj(["foo", "bar"])).toEqual({ foo: true, bar: true });
|
||||
});
|
||||
|
||||
it("应将单个元素的数组转为对象", () => {
|
||||
expect(createCustomClassObj(["foo"])).toEqual({ foo: true });
|
||||
});
|
||||
|
||||
it("空数组应返回空对象", () => {
|
||||
expect(createCustomClassObj([])).toEqual({});
|
||||
});
|
||||
|
||||
// ---------- 异常输入 ----------
|
||||
it("传入对象应抛出 TypeError", () => {
|
||||
expect(() => createCustomClassObj({} as any)).toThrow(TypeError);
|
||||
});
|
||||
|
||||
it("传入数字应抛出 TypeError", () => {
|
||||
expect(() => createCustomClassObj(123 as any)).toThrow(TypeError);
|
||||
});
|
||||
|
||||
it("传入 null 应抛出 TypeError", () => {
|
||||
expect(() => createCustomClassObj(null as any)).toThrow(TypeError);
|
||||
});
|
||||
|
||||
it("传入 undefined 应抛出 TypeError", () => {
|
||||
expect(() => createCustomClassObj(undefined as any)).toThrow(TypeError);
|
||||
});
|
||||
});
|
||||
|
||||
// ========== convertCustomClass ==========
|
||||
|
||||
describe("convertCustomClass", () => {
|
||||
// ---------- 字符串输入 ----------
|
||||
it("应将字符串转为类名对象", () => {
|
||||
expect(convertCustomClass("foo bar")).toEqual({ foo: true, bar: true });
|
||||
});
|
||||
|
||||
it("应将单个类名字符串转为对象", () => {
|
||||
expect(convertCustomClass("foo")).toEqual({ foo: true });
|
||||
});
|
||||
|
||||
it("空字符串应返回空对象", () => {
|
||||
expect(convertCustomClass("")).toEqual({});
|
||||
});
|
||||
|
||||
// ---------- 数组输入 ----------
|
||||
it("应将类名数组转为对象", () => {
|
||||
expect(convertCustomClass(["foo", "bar"])).toEqual({ foo: true, bar: true });
|
||||
});
|
||||
|
||||
it("空数组应返回空对象", () => {
|
||||
expect(convertCustomClass([])).toEqual({});
|
||||
});
|
||||
|
||||
// ---------- 对象输入 ----------
|
||||
it("应直接返回对象", () => {
|
||||
const obj = { foo: true, bar: false };
|
||||
expect(convertCustomClass(obj)).toEqual(obj);
|
||||
});
|
||||
|
||||
it("应保留对象中值为 false 的属性", () => {
|
||||
const obj = { foo: true, bar: false };
|
||||
const result = convertCustomClass(obj);
|
||||
expect(result).toHaveProperty("bar", false);
|
||||
});
|
||||
|
||||
// ---------- 异常输入 ----------
|
||||
it("传入数字应抛出 TypeError", () => {
|
||||
expect(() => convertCustomClass(123 as any)).toThrow(TypeError);
|
||||
});
|
||||
|
||||
it("传入 null 应抛出 TypeError", () => {
|
||||
expect(() => convertCustomClass(null as any)).toThrow(TypeError);
|
||||
});
|
||||
|
||||
it("传入 undefined 应抛出 TypeError", () => {
|
||||
expect(() => convertCustomClass(undefined as any)).toThrow(TypeError);
|
||||
});
|
||||
|
||||
it("传入布尔值应抛出 TypeError", () => {
|
||||
expect(() => convertCustomClass(true as any)).toThrow(TypeError);
|
||||
});
|
||||
});
|
||||
|
||||
// ========== mergeClass ==========
|
||||
|
||||
describe("mergeClass", () => {
|
||||
it("应合并多个字符串类名", () => {
|
||||
expect(mergeClass("foo", "bar")).toEqual({ foo: true, bar: true });
|
||||
});
|
||||
|
||||
it("应合并字符串和数组", () => {
|
||||
expect(mergeClass("foo", ["bar"])).toEqual({ foo: true, bar: true });
|
||||
});
|
||||
|
||||
it("应合并字符串、数组和对象", () => {
|
||||
expect(mergeClass("foo", ["bar"], { baz: true })).toEqual({
|
||||
foo: true,
|
||||
bar: true,
|
||||
baz: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("后面的值应覆盖前面的同名属性", () => {
|
||||
expect(mergeClass({ foo: true }, { foo: false })).toEqual({ foo: false });
|
||||
});
|
||||
|
||||
it("字符串形式的类名应覆盖前面的", () => {
|
||||
// "foo" → { foo: true },后者覆盖前者
|
||||
expect(mergeClass("foo", "foo")).toEqual({ foo: true });
|
||||
});
|
||||
|
||||
it("单个参数应正常工作", () => {
|
||||
expect(mergeClass("foo")).toEqual({ foo: true });
|
||||
});
|
||||
|
||||
it("应处理空字符串参数", () => {
|
||||
expect(mergeClass("")).toEqual({});
|
||||
});
|
||||
|
||||
it("应处理空数组参数", () => {
|
||||
expect(mergeClass([])).toEqual({});
|
||||
});
|
||||
|
||||
it("应处理空对象参数", () => {
|
||||
expect(mergeClass({})).toEqual({});
|
||||
});
|
||||
|
||||
it("应合并多个对象类名", () => {
|
||||
expect(
|
||||
mergeClass({ color: true }, { size: true }, { weight: true }),
|
||||
).toEqual({ color: true, size: true, weight: true });
|
||||
});
|
||||
|
||||
it("实际使用场景:Vue 组件中合并 class", () => {
|
||||
// 模拟组件内部 class + 传入 class
|
||||
const internal = "btn primary";
|
||||
const custom = { active: true, disabled: false };
|
||||
expect(mergeClass(internal, custom)).toEqual({
|
||||
btn: true,
|
||||
primary: true,
|
||||
active: true,
|
||||
disabled: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
public-hoist-pattern[]=*dcloudio*
|
||||
shamefully-hoist=false
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<script>
|
||||
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
|
||||
CSS.supports('top: constant(a)'))
|
||||
document.write(
|
||||
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
|
||||
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
|
||||
</script>
|
||||
<title></title>
|
||||
<!--preload-links-->
|
||||
<!--app-context-->
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"><!--app-html--></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
"name": "@r-utils/playground-uniapp",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"dev:custom": "uni -p",
|
||||
"dev:h5": "uni",
|
||||
"dev:h5:ssr": "uni --ssr",
|
||||
"dev:mp-alipay": "uni -p mp-alipay",
|
||||
"dev:mp-baidu": "uni -p mp-baidu",
|
||||
"dev:mp-jd": "uni -p mp-jd",
|
||||
"dev:mp-kuaishou": "uni -p mp-kuaishou",
|
||||
"dev:mp-lark": "uni -p mp-lark",
|
||||
"dev:mp-qq": "uni -p mp-qq",
|
||||
"dev:mp-toutiao": "uni -p mp-toutiao",
|
||||
"dev:mp-harmony": "uni -p mp-harmony",
|
||||
"dev:mp-weixin": "uni -p mp-weixin",
|
||||
"dev:mp-xhs": "uni -p mp-xhs",
|
||||
"dev:quickapp-webview": "uni -p quickapp-webview",
|
||||
"dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei",
|
||||
"dev:quickapp-webview-union": "uni -p quickapp-webview-union",
|
||||
"build:custom": "uni build -p",
|
||||
"build:h5": "uni build",
|
||||
"build:h5:ssr": "uni build --ssr",
|
||||
"build:mp-alipay": "uni build -p mp-alipay",
|
||||
"build:mp-baidu": "uni build -p mp-baidu",
|
||||
"build:mp-jd": "uni build -p mp-jd",
|
||||
"build:mp-kuaishou": "uni build -p mp-kuaishou",
|
||||
"build:mp-lark": "uni build -p mp-lark",
|
||||
"build:mp-qq": "uni build -p mp-qq",
|
||||
"build:mp-toutiao": "uni build -p mp-toutiao",
|
||||
"build:mp-harmony": "uni build -p mp-harmony",
|
||||
"build:mp-weixin": "uni build -p mp-weixin",
|
||||
"build:mp-xhs": "uni build -p mp-xhs",
|
||||
"build:quickapp-webview": "uni build -p quickapp-webview",
|
||||
"build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
|
||||
"build:quickapp-webview-union": "uni build -p quickapp-webview-union",
|
||||
"type-check": "vue-tsc --noEmit",
|
||||
"lint": "eslint . --fix",
|
||||
"format": "prettier --write src"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dcloudio/uni-app": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-app-harmony": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-app-plus": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-components": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-h5": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-mp-alipay": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-mp-baidu": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-mp-harmony": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-mp-jd": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-mp-kuaishou": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-mp-lark": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-mp-qq": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-mp-toutiao": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-mp-weixin": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-mp-xhs": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-quickapp-webview": "3.0.0-4080420251103001",
|
||||
"@r-utils/uni-app": "workspace:^",
|
||||
"@r-utils/uview-plus": "workspace:^",
|
||||
"@r-utils/common": "workspace:^",
|
||||
"vue": "^3.4.21",
|
||||
"vue-i18n": "^9.1.9",
|
||||
"vue-router": "^4.4.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@dcloudio/types": "^3.4.8",
|
||||
"@dcloudio/uni-automator": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-cli-shared": "3.0.0-4080420251103001",
|
||||
"@dcloudio/uni-stacktracey": "3.0.0-4080420251103001",
|
||||
"@dcloudio/vite-plugin-uni": "3.0.0-4080420251103001",
|
||||
"@vue/runtime-core": "^3.4.21",
|
||||
"@vue/tsconfig": "^0.1.3",
|
||||
"typescript": "^4.9.4",
|
||||
"vite": "5.2.8",
|
||||
"vue-tsc": "^1.0.24"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
/// <reference types='@dcloudio/types' />
|
||||
import 'vue'
|
||||
|
||||
declare module '@vue/runtime-core' {
|
||||
type Hooks = App.AppInstance & Page.PageInstance;
|
||||
|
||||
interface ComponentCustomOptions extends Hooks {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<script setup lang="ts">
|
||||
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
||||
onLaunch(() => {
|
||||
console.log("App Launch");
|
||||
});
|
||||
onShow(() => {
|
||||
console.log("App Show");
|
||||
});
|
||||
onHide(() => {
|
||||
console.log("App Hide");
|
||||
});
|
||||
</script>
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
/// <reference types="vite/client" />
|
||||
|
||||
declare module '*.vue' {
|
||||
import { DefineComponent } from 'vue'
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import { createSSRApp } from "vue";
|
||||
import App from "./App.vue";
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App);
|
||||
return {
|
||||
app,
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
{
|
||||
"name" : "",
|
||||
"appid" : "",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.0",
|
||||
"versionCode" : "100",
|
||||
"transformPx" : false,
|
||||
/* 5+App特有相关 */
|
||||
"app-plus" : {
|
||||
"usingComponents" : true,
|
||||
"nvueStyleCompiler" : "uni-app",
|
||||
"compilerVersion" : 3,
|
||||
"splashscreen" : {
|
||||
"alwaysShowBeforeRender" : true,
|
||||
"waiting" : true,
|
||||
"autoclose" : true,
|
||||
"delay" : 0
|
||||
},
|
||||
/* 模块配置 */
|
||||
"modules" : {},
|
||||
/* 应用发布信息 */
|
||||
"distribute" : {
|
||||
/* android打包配置 */
|
||||
"android" : {
|
||||
"permissions" : [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
||||
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||
]
|
||||
},
|
||||
/* ios打包配置 */
|
||||
"ios" : {},
|
||||
/* SDK配置 */
|
||||
"sdkConfigs" : {}
|
||||
}
|
||||
},
|
||||
/* 快应用特有相关 */
|
||||
"quickapp" : {},
|
||||
/* 小程序特有相关 */
|
||||
"mp-weixin" : {
|
||||
"appid" : "",
|
||||
"setting" : {
|
||||
"urlCheck" : false
|
||||
},
|
||||
"usingComponents" : true
|
||||
},
|
||||
"mp-alipay" : {
|
||||
"usingComponents" : true
|
||||
},
|
||||
"mp-baidu" : {
|
||||
"usingComponents" : true
|
||||
},
|
||||
"mp-toutiao" : {
|
||||
"usingComponents" : true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion" : "3"
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/index/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "@r-utils Playground"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/request/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "Request Demo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/uni-helper/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "UniHelper Demo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/bluetooth/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "Bluetooth Demo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/nfc/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "NFC Demo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/upload/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "Upload Demo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/permission/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "Permission Demo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/countdown/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "Countdown Demo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/wait/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "Wait Demo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/knock-test/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "KnockTest Demo"
|
||||
}
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarTitleText": "uni-app",
|
||||
"navigationBarBackgroundColor": "#F8F8F8",
|
||||
"backgroundColor": "#F8F8F8"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<template>
|
||||
<view class="page">
|
||||
<view class="section-title">BluetoothUtils 蓝牙工具 Demo</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">蓝牙功能说明</text>
|
||||
<text class="desc">BluetoothUtils 提供了蓝牙设备搜索、连接、数据传输等功能。需要在真机上运行(App 或小程序环境)。</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">搜索设备</text>
|
||||
<text class="code">BluetoothUtils.getDevices(cb, 3000)</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">绑定设备</text>
|
||||
<text class="code">BluetoothUtils.bindDevice(device, async () => { ... })</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">发送数据</text>
|
||||
<text class="code">BluetoothUtils.sendData(device, [0x1B, 0x40])</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">获取 MTU</text>
|
||||
<text class="code">BluetoothUtils.getBLEMTU(device)</text>
|
||||
</view>
|
||||
|
||||
<view class="notice">
|
||||
<text>⚠️ 蓝牙功能需要在真机环境下测试,H5 模拟器不支持</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { padding: 30rpx; }
|
||||
.section-title { font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #42b883; }
|
||||
.demo-block { margin-bottom: 24rpx; padding: 20rpx; background: #f9f9f9; border-radius: 8rpx; }
|
||||
.label { font-size: 28rpx; font-weight: bold; display: block; margin-bottom: 8rpx; }
|
||||
.desc { font-size: 26rpx; color: #666; }
|
||||
.code { font-size: 24rpx; color: #42b883; font-family: monospace; }
|
||||
.notice { margin-top: 20rpx; padding: 16rpx; background: #fff3e0; border-radius: 8rpx; font-size: 24rpx; color: #e65100; }
|
||||
</style>
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
<template>
|
||||
<view class="page">
|
||||
<view class="section-title">Countdown 倒计时 Demo</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">倒计时: {{ timeDisplay }} ({{ status }})</text>
|
||||
<view class="btn-group">
|
||||
<button :disabled="status === 'running'" @click="start" size="mini">开始</button>
|
||||
<button :disabled="status !== 'running'" @click="stop" size="mini">停止</button>
|
||||
<button :disabled="status !== 'running'" @click="restart" size="mini">重新开始</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onUnmounted } from 'vue'
|
||||
import { Countdown } from '@r-utils/common'
|
||||
|
||||
const timeDisplay = ref('00:00:10')
|
||||
const status = ref<'idle' | 'running' | 'stopped'>('idle')
|
||||
let countdown: Countdown | null = null
|
||||
|
||||
function start() {
|
||||
countdown = new Countdown(10)
|
||||
countdown.addStepEventListener((t) => { timeDisplay.value = t })
|
||||
countdown.addCountdownEventListener(() => { status.value = 'stopped' })
|
||||
countdown.start()
|
||||
status.value = 'running'
|
||||
}
|
||||
|
||||
function stop() {
|
||||
countdown?.stop()
|
||||
status.value = 'stopped'
|
||||
}
|
||||
|
||||
function restart() {
|
||||
countdown?.restart()
|
||||
status.value = 'running'
|
||||
}
|
||||
|
||||
onUnmounted(() => { stop() })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { padding: 30rpx; }
|
||||
.section-title { font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #42b883; }
|
||||
.demo-block { margin-bottom: 24rpx; padding: 20rpx; background: #f9f9f9; border-radius: 8rpx; }
|
||||
.label { font-size: 28rpx; font-weight: bold; display: block; margin-bottom: 12rpx; }
|
||||
.btn-group { display: flex; gap: 16rpx; margin-top: 12rpx; }
|
||||
</style>
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
<template>
|
||||
<view class="content">
|
||||
<view class="title">@r-utils/uni-app & @r-utils/common Playground</view>
|
||||
<view class="desc">以下是各模块的使用示例,点击进入独立页面</view>
|
||||
|
||||
<view class="section-title">@r-utils/uni-app</view>
|
||||
<view class="nav-list">
|
||||
<navigator url="/pages/request/index" class="nav-item">
|
||||
<text class="nav-label">Request — 请求封装</text>
|
||||
<text class="nav-desc">类 axios 的 uni.request 封装,支持拦截器</text>
|
||||
</navigator>
|
||||
<navigator url="/pages/uni-helper/index" class="nav-item">
|
||||
<text class="nav-label">UniHelper — 常用工具</text>
|
||||
<text class="nav-desc">rpxToPx、showToast、getCurrentPage 等</text>
|
||||
</navigator>
|
||||
<navigator url="/pages/bluetooth/index" class="nav-item">
|
||||
<text class="nav-label">BluetoothUtils — 蓝牙工具</text>
|
||||
<text class="nav-desc">蓝牙设备搜索、连接、数据传输</text>
|
||||
</navigator>
|
||||
<navigator url="/pages/nfc/index" class="nav-item">
|
||||
<text class="nav-label">NFC — NFC 功能</text>
|
||||
<text class="nav-desc">NFC 标签读写</text>
|
||||
</navigator>
|
||||
<navigator url="/pages/upload/index" class="nav-item">
|
||||
<text class="nav-label">Upload — 文件上传</text>
|
||||
<text class="nav-desc">uni.uploadFile 封装</text>
|
||||
</navigator>
|
||||
</view>
|
||||
|
||||
<view class="section-title" style="margin-top: 30rpx;">@r-utils/common</view>
|
||||
<view class="nav-list">
|
||||
<navigator url="/pages/permission/index" class="nav-item">
|
||||
<text class="nav-label">Permission — 权限校验</text>
|
||||
<text class="nav-desc">权限字符串格式校验</text>
|
||||
</navigator>
|
||||
<navigator url="/pages/countdown/index" class="nav-item">
|
||||
<text class="nav-label">Countdown — 倒计时</text>
|
||||
<text class="nav-desc">基于 dayjs 的倒计时类</text>
|
||||
</navigator>
|
||||
<navigator url="/pages/wait/index" class="nav-item">
|
||||
<text class="nav-label">wait — 等待函数</text>
|
||||
<text class="nav-desc">异步等待指定时间</text>
|
||||
</navigator>
|
||||
<navigator url="/pages/knock-test/index" class="nav-item">
|
||||
<text class="nav-label">KnockTest — 敲击测试</text>
|
||||
<text class="nav-desc">顺序敲击触发回调的状态机</text>
|
||||
</navigator>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.content {
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #42b883;
|
||||
margin-bottom: 20rpx;
|
||||
padding-bottom: 8rpx;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.nav-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
padding: 20rpx 24rpx;
|
||||
background: #fff;
|
||||
border-radius: 12rpx;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.nav-label {
|
||||
display: block;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 6rpx;
|
||||
}
|
||||
|
||||
.nav-desc {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
color: #888;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<template>
|
||||
<view class="page">
|
||||
<view class="section-title">KnockTest 敲击测试 Demo</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">{{ message }}</text>
|
||||
<text class="desc">成功次数: {{ successCount }}</text>
|
||||
<button @click="knock" size="mini" style="margin-top: 12rpx">敲击 (Knock)</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { KnockTest } from '@r-utils/common'
|
||||
|
||||
const config = {
|
||||
maxWaitTime: 5000,
|
||||
operations: [
|
||||
{ duration: 1000, delay: 500, times: 2 },
|
||||
{ duration: 1000, delay: 500, times: 3 },
|
||||
],
|
||||
}
|
||||
|
||||
const knockTest = new KnockTest(config)
|
||||
const message = ref('点击按钮按顺序触发敲击(2次 → 等待 → 3次)')
|
||||
const successCount = ref(0)
|
||||
|
||||
knockTest.addCallback(() => {
|
||||
successCount.value++
|
||||
message.value = `🎉 敲击测试成功!(${successCount.value}次)`
|
||||
})
|
||||
|
||||
function knock() {
|
||||
message.value = '敲击中...'
|
||||
knockTest.knock()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { padding: 30rpx; }
|
||||
.section-title { font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #42b883; }
|
||||
.demo-block { margin-bottom: 24rpx; padding: 20rpx; background: #f9f9f9; border-radius: 8rpx; }
|
||||
.label { font-size: 28rpx; font-weight: bold; display: block; margin-bottom: 8rpx; }
|
||||
.desc { font-size: 26rpx; color: #666; }
|
||||
</style>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<template>
|
||||
<view class="page">
|
||||
<view class="section-title">NFC 功能 Demo</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">NFC 功能说明</text>
|
||||
<text class="desc">NFC 模块提供标签读写等功能,需要在支持 NFC 的真机上运行。</text>
|
||||
</view>
|
||||
|
||||
<view class="notice">
|
||||
<text>⚠️ NFC 功能需要在真机环境下测试</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { padding: 30rpx; }
|
||||
.section-title { font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #42b883; }
|
||||
.demo-block { margin-bottom: 24rpx; padding: 20rpx; background: #f9f9f9; border-radius: 8rpx; }
|
||||
.label { font-size: 28rpx; font-weight: bold; display: block; margin-bottom: 8rpx; }
|
||||
.desc { font-size: 26rpx; color: #666; }
|
||||
.notice { margin-top: 20rpx; padding: 16rpx; background: #fff3e0; border-radius: 8rpx; font-size: 24rpx; color: #e65100; }
|
||||
</style>
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<template>
|
||||
<view class="page">
|
||||
<view class="section-title">Permission 权限校验 Demo</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">格式: module:action:resource (三级,冒号分隔)</text>
|
||||
<input v-model="input" type="text" placeholder="输入权限字符串" class="input" @input="check" />
|
||||
<text :style="{ color: isValid ? '#4caf50' : '#f44336' }" class="result">
|
||||
{{ isValid ? '✓ 有效' : '✗ 无效' }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { Permission } from '@r-utils/common'
|
||||
|
||||
const permissionList = ['user:read:profile', 'admin:write:config', 'invalid']
|
||||
const permission = new Permission(permissionList)
|
||||
|
||||
const input = ref('user:read:profile')
|
||||
const isValid = ref(permission.isValid(input.value))
|
||||
|
||||
function check() {
|
||||
isValid.value = permission.isValid(input.value)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { padding: 30rpx; }
|
||||
.section-title { font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #42b883; }
|
||||
.demo-block { margin-bottom: 24rpx; padding: 20rpx; background: #f9f9f9; border-radius: 8rpx; }
|
||||
.label { font-size: 28rpx; font-weight: bold; display: block; margin-bottom: 12rpx; }
|
||||
.input { border: 1px solid #ddd; border-radius: 8rpx; padding: 12rpx; margin-bottom: 12rpx; font-size: 28rpx; }
|
||||
.result { display: block; margin-top: 8rpx; font-size: 26rpx; }
|
||||
</style>
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
<template>
|
||||
<view class="page">
|
||||
<view class="section-title">Request 请求封装 Demo</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">创建 Request 实例:</text>
|
||||
<text class="code">const request = new Request({ baseURL: '/api' })</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">添加请求拦截器:</text>
|
||||
<text class="code">request.interceptors.request.add(config => { config.header.token = 'xxx'; return config })</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">添加响应拦截器:</text>
|
||||
<text class="code">request.interceptors.response.add(res => { return res.data })</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">发送请求:</text>
|
||||
<text class="code">const res = await request.get('/users')</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<button @click="sendRequest" :disabled="loading">
|
||||
{{ loading ? '请求中...' : '发送 GET 请求' }}
|
||||
</button>
|
||||
<view v-if="response" class="result">
|
||||
<text>响应结果: {{ response }}</text>
|
||||
</view>
|
||||
<view v-if="error" class="error">
|
||||
<text>请求失败: {{ error }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { Request } from '@r-utils/uni-app'
|
||||
|
||||
const loading = ref(false)
|
||||
const response = ref('')
|
||||
const error = ref('')
|
||||
|
||||
const request = new Request({
|
||||
baseURL: 'https://jsonplaceholder.typicode.com',
|
||||
})
|
||||
|
||||
request.interceptors.request.add((config) => {
|
||||
console.log('请求拦截器:', config.url)
|
||||
return config
|
||||
})
|
||||
|
||||
request.interceptors.response.add((res) => {
|
||||
console.log('响应拦截器:', res)
|
||||
return res
|
||||
})
|
||||
|
||||
async function sendRequest() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
response.value = ''
|
||||
try {
|
||||
const res = await request.get('/todos/1')
|
||||
response.value = JSON.stringify(res)
|
||||
} catch (e) {
|
||||
error.value = String(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 30rpx;
|
||||
color: #42b883;
|
||||
}
|
||||
|
||||
.demo-block {
|
||||
margin-bottom: 24rpx;
|
||||
padding: 20rpx;
|
||||
background: #f9f9f9;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
display: block;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.code {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.result {
|
||||
margin-top: 16rpx;
|
||||
padding: 16rpx;
|
||||
background: #e8f5e9;
|
||||
border-radius: 8rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin-top: 16rpx;
|
||||
padding: 16rpx;
|
||||
background: #ffebee;
|
||||
border-radius: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: #c62828;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
<template>
|
||||
<view class="page">
|
||||
<view class="section-title">UniHelper 工具 Demo</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">rpxToPx — rpx 转 px</text>
|
||||
<input v-model="rpxValue" type="number" placeholder="输入 rpx 值" class="input" />
|
||||
<text class="result">{{ rpxValue }}rpx = {{ pxResult }}px</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">pxToRpx — px 转 rpx</text>
|
||||
<input v-model="pxValue" type="number" placeholder="输入 px 值" class="input" />
|
||||
<text class="result">{{ pxValue }}px = {{ rpxResult }}rpx</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">showToast — 显示提示</text>
|
||||
<view class="btn-group">
|
||||
<button @click="showSuccessToast" size="mini">成功提示</button>
|
||||
<button @click="showErrorToast" size="mini">错误提示</button>
|
||||
<button @click="showNoneToast" size="mini">普通提示</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">getCurrentPage — 获取当前页面</text>
|
||||
<text class="result">当前页面路由: {{ currentPageRoute }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { rpxToPx, pxToRpx, showToast, getCurrentPage } from '@r-utils/uni-app'
|
||||
|
||||
const rpxValue = ref('100')
|
||||
const pxResult = computed(() => {
|
||||
try {
|
||||
return rpxToPx(Number(rpxValue.value))
|
||||
} catch {
|
||||
return '-'
|
||||
}
|
||||
})
|
||||
|
||||
const pxValue = ref('50')
|
||||
const rpxResult = computed(() => {
|
||||
try {
|
||||
return pxToRpx(Number(pxValue.value))
|
||||
} catch {
|
||||
return '-'
|
||||
}
|
||||
})
|
||||
|
||||
const currentPageRoute = computed(() => {
|
||||
try {
|
||||
const page = getCurrentPage()
|
||||
return (page as any)?.route ?? '未知'
|
||||
} catch {
|
||||
return 'H5 模式下可能无法获取'
|
||||
}
|
||||
})
|
||||
|
||||
function showSuccessToast() {
|
||||
showToast('操作成功', 'success')
|
||||
}
|
||||
|
||||
function showErrorToast() {
|
||||
showToast('操作失败', 'error')
|
||||
}
|
||||
|
||||
function showNoneToast() {
|
||||
showToast('这是一条提示')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { padding: 30rpx; }
|
||||
.section-title { font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #42b883; }
|
||||
.demo-block { margin-bottom: 24rpx; padding: 20rpx; background: #f9f9f9; border-radius: 8rpx; }
|
||||
.label { font-size: 28rpx; font-weight: bold; display: block; margin-bottom: 12rpx; }
|
||||
.input { border: 1px solid #ddd; border-radius: 8rpx; padding: 12rpx; margin-bottom: 12rpx; font-size: 28rpx; }
|
||||
.result { display: block; margin-top: 8rpx; font-size: 26rpx; color: #42b883; }
|
||||
.btn-group { display: flex; gap: 16rpx; }
|
||||
</style>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<template>
|
||||
<view class="page">
|
||||
<view class="section-title">Upload 文件上传 Demo</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">上传功能说明</text>
|
||||
<text class="desc">upload 函数封装了 uni.uploadFile,支持自动解析响应数据。</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">示例代码</text>
|
||||
<text class="code">import { upload } from '@r-utils/uni-app'</text>
|
||||
<text class="code">const result = await upload({ url, filePath, name })</text>
|
||||
</view>
|
||||
|
||||
<view class="notice">
|
||||
<text>⚠️ 文件上传需要在真机环境下测试,且需要后端服务支持</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { padding: 30rpx; }
|
||||
.section-title { font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #42b883; }
|
||||
.demo-block { margin-bottom: 24rpx; padding: 20rpx; background: #f9f9f9; border-radius: 8rpx; }
|
||||
.label { font-size: 28rpx; font-weight: bold; display: block; margin-bottom: 8rpx; }
|
||||
.desc { font-size: 26rpx; color: #666; }
|
||||
.code { display: block; font-size: 24rpx; color: #42b883; font-family: monospace; margin-bottom: 4rpx; }
|
||||
.notice { margin-top: 20rpx; padding: 16rpx; background: #fff3e0; border-radius: 8rpx; font-size: 24rpx; color: #e65100; }
|
||||
</style>
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<template>
|
||||
<view class="page">
|
||||
<view class="section-title">wait 等待函数 Demo</view>
|
||||
|
||||
<view class="demo-block">
|
||||
<text class="label">等待时间: {{ waitTime }}ms</text>
|
||||
<input v-model.number="waitTime" type="number" :min="100" :step="100" class="input" />
|
||||
<button :disabled="waiting" @click="handleWait" size="mini">
|
||||
{{ waiting ? '等待中...' : `等待 ${waitTime}ms` }}
|
||||
</button>
|
||||
<text v-if="waitDone" class="result">✓ 等待完成</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { wait } from '@r-utils/common'
|
||||
|
||||
const waiting = ref(false)
|
||||
const waitDone = ref(false)
|
||||
const waitTime = ref(2000)
|
||||
|
||||
async function handleWait() {
|
||||
waiting.value = true
|
||||
waitDone.value = false
|
||||
await wait(waitTime.value)
|
||||
waiting.value = false
|
||||
waitDone.value = true
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { padding: 30rpx; }
|
||||
.section-title { font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #42b883; }
|
||||
.demo-block { margin-bottom: 24rpx; padding: 20rpx; background: #f9f9f9; border-radius: 8rpx; }
|
||||
.label { font-size: 28rpx; font-weight: bold; display: block; margin-bottom: 12rpx; }
|
||||
.input { border: 1px solid #ddd; border-radius: 8rpx; padding: 12rpx; margin-bottom: 12rpx; font-size: 28rpx; }
|
||||
.result { display: block; margin-top: 8rpx; font-size: 26rpx; color: #4caf50; }
|
||||
</style>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
export {}
|
||||
|
||||
declare module "vue" {
|
||||
type Hooks = App.AppInstance & Page.PageInstance;
|
||||
interface ComponentCustomOptions extends Hooks {}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
|
||||
/* 颜色变量 */
|
||||
|
||||
/* 行为相关颜色 */
|
||||
$uni-color-primary: #007aff;
|
||||
$uni-color-success: #4cd964;
|
||||
$uni-color-warning: #f0ad4e;
|
||||
$uni-color-error: #dd524d;
|
||||
|
||||
/* 文字基本颜色 */
|
||||
$uni-text-color: #333; // 基本色
|
||||
$uni-text-color-inverse: #fff; // 反色
|
||||
$uni-text-color-grey: #999; // 辅助灰色,如加载更多的提示信息
|
||||
$uni-text-color-placeholder: #808080;
|
||||
$uni-text-color-disable: #c0c0c0;
|
||||
|
||||
/* 背景颜色 */
|
||||
$uni-bg-color: #fff;
|
||||
$uni-bg-color-grey: #f8f8f8;
|
||||
$uni-bg-color-hover: #f1f1f1; // 点击状态颜色
|
||||
$uni-bg-color-mask: rgba(0, 0, 0, 0.4); // 遮罩颜色
|
||||
|
||||
/* 边框颜色 */
|
||||
$uni-border-color: #c8c7cc;
|
||||
|
||||
/* 尺寸变量 */
|
||||
|
||||
/* 文字尺寸 */
|
||||
$uni-font-size-sm: 12px;
|
||||
$uni-font-size-base: 14px;
|
||||
$uni-font-size-lg: 16;
|
||||
|
||||
/* 图片尺寸 */
|
||||
$uni-img-size-sm: 20px;
|
||||
$uni-img-size-base: 26px;
|
||||
$uni-img-size-lg: 40px;
|
||||
|
||||
/* Border Radius */
|
||||
$uni-border-radius-sm: 2px;
|
||||
$uni-border-radius-base: 3px;
|
||||
$uni-border-radius-lg: 6px;
|
||||
$uni-border-radius-circle: 50%;
|
||||
|
||||
/* 水平间距 */
|
||||
$uni-spacing-row-sm: 5px;
|
||||
$uni-spacing-row-base: 10px;
|
||||
$uni-spacing-row-lg: 15px;
|
||||
|
||||
/* 垂直间距 */
|
||||
$uni-spacing-col-sm: 4px;
|
||||
$uni-spacing-col-base: 8px;
|
||||
$uni-spacing-col-lg: 12px;
|
||||
|
||||
/* 透明度 */
|
||||
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度
|
||||
|
||||
/* 文章场景相关 */
|
||||
$uni-color-title: #2c405a; // 文章标题颜色
|
||||
$uni-font-size-title: 20px;
|
||||
$uni-color-subtitle: #555; // 二级标题颜色
|
||||
$uni-font-size-subtitle: 18px;
|
||||
$uni-color-paragraph: #3f536e; // 文章段落颜色
|
||||
$uni-font-size-paragraph: 15px;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"sourceMap": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
},
|
||||
"lib": ["esnext", "dom"],
|
||||
"types": ["@dcloudio/types"]
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import { defineConfig } from "vite";
|
||||
import uni from "@dcloudio/vite-plugin-uni";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [uni()],
|
||||
});
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/// <reference types="vite/client" />
|
||||
|
||||
declare module "*.vue" {
|
||||
import type { DefineComponent } from "vue";
|
||||
const component: DefineComponent<object, object, unknown>;
|
||||
export default component;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@r-utils/vue2 Playground</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "@r-utils/playground-vue2",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc -b && vite build",
|
||||
"preview": "vite preview",
|
||||
"lint": "eslint . --fix",
|
||||
"format": "prettier --write src"
|
||||
},
|
||||
"dependencies": {
|
||||
"@r-utils/vue2": "workspace:^",
|
||||
"vue": "^2.7.16",
|
||||
"vue-router": "^3.6.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue2": "^2.0.1",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "^5.4.0",
|
||||
"vue-tsc": "^2.2.8"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFBD4F"></stop><stop offset="100%" stop-color="#FF9640"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
|
|
@ -0,0 +1,62 @@
|
|||
<template>
|
||||
<div class="app">
|
||||
<header class="header">
|
||||
<router-link to="/" class="logo">@r-utils/vue2</router-link>
|
||||
</header>
|
||||
<main class="main">
|
||||
<router-view />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
|
||||
Ubuntu, Cantarell, sans-serif;
|
||||
background: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.app {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: #fff;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding: 12px 24px;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #42b883;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.logo:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.main {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
code {
|
||||
background: #f0f0f0;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
font-size: 13px;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import Vue from "vue";
|
||||
import { VisibilityPlugin } from "@r-utils/vue2";
|
||||
import App from "./App.vue";
|
||||
import router from "./router";
|
||||
|
||||
Vue.use(VisibilityPlugin);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
new Vue({
|
||||
router,
|
||||
render: (h: any) => h(App),
|
||||
} as any).$mount("#app");
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import Vue from "vue";
|
||||
import VueRouter from "vue-router";
|
||||
|
||||
Vue.use(VueRouter);
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: "/",
|
||||
name: "index",
|
||||
component: () => import("@/views/IndexPage.vue"),
|
||||
},
|
||||
{
|
||||
path: "/visibility-plugin",
|
||||
name: "visibilityPlugin",
|
||||
component: () => import("@/views/VisibilityPluginDemo.vue"),
|
||||
},
|
||||
];
|
||||
|
||||
const router = new VueRouter({
|
||||
mode: "history",
|
||||
routes,
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>Playground</h1>
|
||||
<p class="desc">以下是 @r-utils/vue2 各模块的使用示例,点击进入独立页面</p>
|
||||
|
||||
<section class="section">
|
||||
<h2>@r-utils/vue2</h2>
|
||||
<ul class="nav-list">
|
||||
<li><router-link to="/visibility-plugin">VisibilityPlugin — 页面可见性生命周期</router-link></li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from "vue";
|
||||
export default Vue.extend({});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
margin-bottom: 8px;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.desc {
|
||||
color: #666;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.section h2 {
|
||||
font-size: 16px;
|
||||
margin-bottom: 12px;
|
||||
color: #42b883;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.nav-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.nav-list li {
|
||||
background: #fff;
|
||||
border-radius: 6px;
|
||||
padding: 12px 16px;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
|
||||
transition: box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.nav-list li:hover {
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.nav-list a {
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.nav-list a:hover {
|
||||
color: #42b883;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">VisibilityPlugin — onShow / onHide</h2>
|
||||
<p class="demo-desc">为 Vue2 组件提供 onShow / onHide 生命周期钩子,监听页面可见性变化</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>切换浏览器标签页可以触发 onShow / onHide 钩子</p>
|
||||
<p>当前状态: <code :style="{ color: visible ? 'green' : 'red' }">{{ visible ? '✓ 可见' : '✗ 隐藏' }}</code></p>
|
||||
<p>onShow 触发次数: <code>{{ showCount }}</code></p>
|
||||
<p>onHide 触发次数: <code>{{ hideCount }}</code></p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from "vue";
|
||||
|
||||
export default Vue.extend({
|
||||
name: "VisibilityPluginDemo",
|
||||
data() {
|
||||
return {
|
||||
visible: true,
|
||||
showCount: 0,
|
||||
hideCount: 0,
|
||||
};
|
||||
},
|
||||
// VisibilityPlugin 注入的自定义生命周期钩子
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
onShow(this: any) {
|
||||
this.visible = true;
|
||||
this.showCount++;
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
onHide(this: any) {
|
||||
this.visible = false;
|
||||
this.hideCount++;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.demo-block {
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
},
|
||||
"types": ["vite/client"]
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.vue", "env.d.ts"]
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"root":["./src/main.ts","./src/router/index.ts","./src/app.vue","./src/views/indexpage.vue","./src/views/visibilityplugindemo.vue","./env.d.ts"],"version":"5.9.3"}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue2";
|
||||
import { resolve } from "path";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": resolve(__dirname, "src"),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/// <reference types="vite/client" />
|
||||
|
||||
declare module "*.vue" {
|
||||
import type { DefineComponent } from "vue";
|
||||
const component: DefineComponent<object, object, unknown>;
|
||||
export default component;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@r-utils/vue3 Playground</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "@r-utils/playground-vue3",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc -b && vite build",
|
||||
"preview": "vite preview",
|
||||
"lint": "eslint . --fix",
|
||||
"format": "prettier --write src"
|
||||
},
|
||||
"dependencies": {
|
||||
"@r-utils/common": "workspace:^",
|
||||
"@r-utils/vue3": "workspace:^",
|
||||
"vue": "^3.5.13",
|
||||
"vue-router": "^4.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^6.0.0",
|
||||
"typescript": "^5.9.3",
|
||||
"vite": "catalog:",
|
||||
"vue-tsc": "^2.2.8"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFBD4F"></stop><stop offset="100%" stop-color="#FF9640"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
|
|
@ -0,0 +1,106 @@
|
|||
<script setup lang="ts">
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="app">
|
||||
<header class="header">
|
||||
<router-link to="/" class="logo">@r-utils/vue3 & @r-utils/common</router-link>
|
||||
</header>
|
||||
<main class="main">
|
||||
<router-view />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
|
||||
Ubuntu, Cantarell, sans-serif;
|
||||
background: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.app {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: #fff;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding: 12px 24px;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #42b883;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.logo:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.main {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 6px 14px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: #42b883;
|
||||
color: #fff;
|
||||
border-color: #42b883;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
input {
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
input:focus {
|
||||
border-color: #42b883;
|
||||
}
|
||||
|
||||
code {
|
||||
background: #f0f0f0;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.result {
|
||||
margin-top: 8px;
|
||||
padding: 8px 12px;
|
||||
background: #f9f9f9;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import { createApp } from "vue";
|
||||
import App from "./App.vue";
|
||||
import router from "./router";
|
||||
import "./style.css";
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(router);
|
||||
app.mount("#app");
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
import { createRouter, createWebHistory } from "vue-router";
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: "/",
|
||||
name: "index",
|
||||
component: () => import("@/views/IndexPage.vue"),
|
||||
},
|
||||
// @r-utils/vue3
|
||||
{
|
||||
path: "/vue3/use-load-more",
|
||||
name: "useLoadMore",
|
||||
component: () => import("@/views/vue3/UseLoadMoreDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/vue3/use-timer",
|
||||
name: "useTimer",
|
||||
component: () => import("@/views/vue3/UseTimerDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/vue3/use-number-string",
|
||||
name: "useNumberString",
|
||||
component: () => import("@/views/vue3/UseNumberStringDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/vue3/use-value-of-rule",
|
||||
name: "useValueOfRule",
|
||||
component: () => import("@/views/vue3/UseValueOfRuleDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/vue3/merge-class",
|
||||
name: "mergeClass",
|
||||
component: () => import("@/views/vue3/MergeClassDemo.vue"),
|
||||
},
|
||||
// @r-utils/common
|
||||
{
|
||||
path: "/common/permission",
|
||||
name: "permission",
|
||||
component: () => import("@/views/common/PermissionDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/common/countdown",
|
||||
name: "countdown",
|
||||
component: () => import("@/views/common/CountdownDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/common/timeout-timer",
|
||||
name: "timeoutTimer",
|
||||
component: () => import("@/views/common/TimeoutTimerDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/common/knock-test",
|
||||
name: "knockTest",
|
||||
component: () => import("@/views/common/KnockTestDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/common/wait",
|
||||
name: "wait",
|
||||
component: () => import("@/views/common/WaitDemo.vue"),
|
||||
},
|
||||
{
|
||||
path: "/common/slowly-scroll",
|
||||
name: "slowlyScroll",
|
||||
component: () => import("@/views/common/SlowlyScrollDemo.vue"),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/* Demo 页面公共样式 */
|
||||
.demo-page {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.demo-title {
|
||||
font-size: 20px;
|
||||
margin-bottom: 8px;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.demo-desc {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.demo-block {
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>Playground</h1>
|
||||
<p class="desc">以下是 @r-utils/vue3 和 @r-utils/common 各模块的使用示例,点击进入独立页面</p>
|
||||
|
||||
<section class="section">
|
||||
<h2>@r-utils/vue3</h2>
|
||||
<ul class="nav-list">
|
||||
<li><router-link to="/vue3/use-load-more">useLoadMore — 列表加载更多</router-link></li>
|
||||
<li><router-link to="/vue3/use-timer">useTimer — 倒计时</router-link></li>
|
||||
<li><router-link to="/vue3/use-number-string">useNumber / useString — 响应式类型转换</router-link></li>
|
||||
<li><router-link to="/vue3/use-value-of-rule">useValueOfRule — 按规则转换输入</router-link></li>
|
||||
<li><router-link to="/vue3/merge-class">mergeClass / createCustomClassObj — Vue Class 合并</router-link></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section class="section">
|
||||
<h2>@r-utils/common</h2>
|
||||
<ul class="nav-list">
|
||||
<li><router-link to="/common/permission">Permission — 权限字符串校验</router-link></li>
|
||||
<li><router-link to="/common/countdown">Countdown — 倒计时</router-link></li>
|
||||
<li><router-link to="/common/timeout-timer">TimeoutTimer — 超时计时器</router-link></li>
|
||||
<li><router-link to="/common/knock-test">KnockTest — 顺序敲击测试</router-link></li>
|
||||
<li><router-link to="/common/wait">wait — 等待函数</router-link></li>
|
||||
<li><router-link to="/common/slowly-scroll">slowlyScroll — 缓动滚动</router-link></li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
margin-bottom: 8px;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.desc {
|
||||
color: #666;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.section h2 {
|
||||
font-size: 16px;
|
||||
margin-bottom: 12px;
|
||||
color: #42b883;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.nav-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.nav-list li {
|
||||
background: #fff;
|
||||
border-radius: 6px;
|
||||
padding: 12px 16px;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
|
||||
transition: box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.nav-list li:hover {
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.nav-list a {
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.nav-list a:hover {
|
||||
color: #42b883;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<script setup lang="ts">
|
||||
import { Countdown } from "@r-utils/common";
|
||||
import { ref, onUnmounted } from "vue";
|
||||
|
||||
const timeDisplay = ref("00:00:10");
|
||||
const status = ref<"idle" | "running" | "stopped">("idle");
|
||||
let countdown: Countdown | null = null;
|
||||
|
||||
function start() {
|
||||
countdown = new Countdown(10);
|
||||
countdown.addStepEventListener((t) => {
|
||||
timeDisplay.value = t;
|
||||
});
|
||||
countdown.addCountdownEventListener(() => {
|
||||
status.value = "stopped";
|
||||
});
|
||||
countdown.start();
|
||||
status.value = "running";
|
||||
}
|
||||
|
||||
function stop() {
|
||||
countdown?.stop();
|
||||
status.value = "stopped";
|
||||
}
|
||||
|
||||
function restart() {
|
||||
countdown?.restart();
|
||||
status.value = "running";
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
stop();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">Countdown — 倒计时</h2>
|
||||
<p class="demo-desc">基于 dayjs 的倒计时类,支持步骤监听和完成监听</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>倒计时: <code>{{ timeDisplay }}</code> ({{ status }})</p>
|
||||
<div style="margin-top: 8px; display: flex; gap: 8px">
|
||||
<button :disabled="status === 'running'" @click="start">开始</button>
|
||||
<button :disabled="status !== 'running'" @click="stop">停止</button>
|
||||
<button :disabled="status !== 'running'" @click="restart">重新开始</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<script setup lang="ts">
|
||||
import { KnockTest } from "@r-utils/common";
|
||||
import { ref } from "vue";
|
||||
|
||||
const config = {
|
||||
maxWaitTime: 5000,
|
||||
operations: [
|
||||
{ duration: 1000, delay: 500, times: 2 },
|
||||
{ duration: 1000, delay: 500, times: 3 },
|
||||
],
|
||||
};
|
||||
|
||||
const knockTest = new KnockTest(config);
|
||||
const message = ref("点击按钮按顺序触发敲击(2次 → 等待 → 3次)");
|
||||
const successCount = ref(0);
|
||||
|
||||
knockTest.addCallback(() => {
|
||||
successCount.value++;
|
||||
message.value = `🎉 敲击测试成功!(${successCount.value}次)`;
|
||||
});
|
||||
|
||||
function knock() {
|
||||
message.value = "敲击中...";
|
||||
knockTest.knock();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">KnockTest — 顺序敲击测试</h2>
|
||||
<p class="demo-desc">按指定顺序敲击/点击触发回调的状态机,可用于隐藏入口等场景</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>{{ message }}</p>
|
||||
<p>成功次数: {{ successCount }}</p>
|
||||
<button style="margin-top: 8px" @click="knock">敲击 (Knock)</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<script setup lang="ts">
|
||||
import { Permission } from "@r-utils/common";
|
||||
import { ref } from "vue";
|
||||
|
||||
const permissionList = ["user:read:profile", "admin:write:config", "invalid"];
|
||||
const permission = new Permission(permissionList);
|
||||
|
||||
const input = ref("user:read:profile");
|
||||
const isValid = ref(permission.isValid(input.value));
|
||||
|
||||
function check() {
|
||||
isValid.value = permission.isValid(input.value);
|
||||
}
|
||||
check();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">Permission — 权限字符串校验</h2>
|
||||
<p class="demo-desc">校验权限字符串是否符合指定格式(如 module:action:resource)</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>格式: <code>module:action:resource</code> (三级,冒号分隔)</p>
|
||||
<p>
|
||||
输入权限字符串:
|
||||
<input v-model="input" type="text" @input="check" />
|
||||
</p>
|
||||
<div class="result">
|
||||
<p>
|
||||
校验结果:
|
||||
<code :style="{ color: isValid ? 'green' : 'red' }">
|
||||
{{ isValid ? "✓ 有效" : "✗ 无效" }}
|
||||
</code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<script setup lang="ts">
|
||||
import { slowlyScroll } from "@r-utils/common";
|
||||
import { ref } from "vue";
|
||||
|
||||
const currentValue = ref(0);
|
||||
const isAnimating = ref(false);
|
||||
|
||||
async function animate() {
|
||||
isAnimating.value = true;
|
||||
await slowlyScroll(0, 500, 1000, (v) => {
|
||||
currentValue.value = Math.round(v);
|
||||
});
|
||||
isAnimating.value = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">slowlyScroll — 缓动滚动</h2>
|
||||
<p class="demo-desc">使用缓动函数(easeOutSine)从起始值缓动到结束值</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>当前值: <code>{{ currentValue }}</code></p>
|
||||
<div class="progress-bar">
|
||||
<div class="progress-fill" :style="{ width: (currentValue / 500) * 100 + '%' }"></div>
|
||||
</div>
|
||||
<button style="margin-top: 8px" :disabled="isAnimating" @click="animate">
|
||||
{{ isAnimating ? '动画中...' : '开始缓动 (0 → 500)' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.progress-bar {
|
||||
height: 20px;
|
||||
background: #f0f0f0;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #42b883, #35495e);
|
||||
border-radius: 10px;
|
||||
transition: width 0.016s linear;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<script setup lang="ts">
|
||||
import { TimeoutTimer } from "@r-utils/common";
|
||||
import { ref, onUnmounted } from "vue";
|
||||
|
||||
const timeDisplay = ref("5");
|
||||
const status = ref<"idle" | "running" | "stopped">("idle");
|
||||
let timer: TimeoutTimer | null = null;
|
||||
|
||||
function start() {
|
||||
timer = TimeoutTimer.start(
|
||||
5,
|
||||
0,
|
||||
1000,
|
||||
(t) => {
|
||||
timeDisplay.value = String(t);
|
||||
},
|
||||
() => {
|
||||
status.value = "stopped";
|
||||
timeDisplay.value = "0";
|
||||
},
|
||||
);
|
||||
timer.start();
|
||||
status.value = "running";
|
||||
}
|
||||
|
||||
function stop() {
|
||||
timer?.stop();
|
||||
status.value = "stopped";
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
stop();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">TimeoutTimer — 超时计时器</h2>
|
||||
<p class="demo-desc">可配置起始/结束时间和间隔的计时器,支持静态创建</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>剩余: <code>{{ timeDisplay }}</code> ({{ status }})</p>
|
||||
<div style="margin-top: 8px; display: flex; gap: 8px">
|
||||
<button :disabled="status === 'running'" @click="start">开始 (5s)</button>
|
||||
<button :disabled="status !== 'running'" @click="stop">停止</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<script setup lang="ts">
|
||||
import { wait } from "@r-utils/common";
|
||||
import { ref } from "vue";
|
||||
|
||||
const waiting = ref(false);
|
||||
const waitDone = ref(false);
|
||||
const waitTime = ref(2000);
|
||||
|
||||
async function handleWait() {
|
||||
waiting.value = true;
|
||||
waitDone.value = false;
|
||||
await wait(waitTime.value);
|
||||
waiting.value = false;
|
||||
waitDone.value = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">wait — 等待函数</h2>
|
||||
<p class="demo-desc">返回一个在指定时间后 resolve 的 Promise,用于异步等待</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>
|
||||
等待时间(ms):
|
||||
<input v-model.number="waitTime" type="number" :min="100" :step="100" />
|
||||
</p>
|
||||
<button style="margin-top: 8px" :disabled="waiting" @click="handleWait">
|
||||
{{ waiting ? `等待 ${waitTime}ms 中...` : `等待 ${waitTime}ms` }}
|
||||
</button>
|
||||
<p v-if="waitDone" class="result">✓ 等待完成</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
<script setup lang="ts">
|
||||
import { mergeClass, createCustomClassObj } from "@r-utils/vue3";
|
||||
import { ref } from "vue";
|
||||
|
||||
const classStr = ref("active primary");
|
||||
const classArr = ref(["bold", "underline"]);
|
||||
|
||||
const merged = ref<Record<string, boolean>>({});
|
||||
const customObj = ref<Record<string, true>>({});
|
||||
|
||||
function handleMerge() {
|
||||
merged.value = mergeClass(classStr.value, classArr.value);
|
||||
}
|
||||
|
||||
function handleCreate() {
|
||||
customObj.value = createCustomClassObj(classStr.value);
|
||||
}
|
||||
|
||||
handleMerge();
|
||||
handleCreate();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">mergeClass / createCustomClassObj — Vue Class 合并</h2>
|
||||
<p class="demo-desc">将字符串/数组形式的 Vue Class 合并为对象形式</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>
|
||||
class 字符串:
|
||||
<input v-model="classStr" type="text" />
|
||||
</p>
|
||||
<p>
|
||||
class 数组 (逗号分隔):
|
||||
<input
|
||||
:value="classArr.join(',')"
|
||||
type="text"
|
||||
@input="
|
||||
classArr = ($event.target as HTMLInputElement).value.split(',')
|
||||
"
|
||||
/>
|
||||
</p>
|
||||
<div style="margin-top: 8px; display: flex; gap: 8px">
|
||||
<button @click="handleMerge">mergeClass</button>
|
||||
<button @click="handleCreate">createCustomClassObj</button>
|
||||
</div>
|
||||
<div class="result">
|
||||
<p>mergeClass: <code>{{ JSON.stringify(merged) }}</code></p>
|
||||
<p>createCustomClassObj: <code>{{ JSON.stringify(customObj) }}</code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
<script setup lang="ts">
|
||||
import { useLoadMore } from "@r-utils/vue3";
|
||||
|
||||
// 模拟分页请求
|
||||
const mockFetch = (pageNum: number, pageSize: number) => {
|
||||
return new Promise<{ total: number; list: string[] }>((resolve) => {
|
||||
setTimeout(() => {
|
||||
const total = 35;
|
||||
const start = (pageNum - 1) * pageSize;
|
||||
const end = Math.min(start + pageSize, total);
|
||||
const list = Array.from({ length: end - start }, (_, i) =>
|
||||
`Item ${start + i + 1}`,
|
||||
);
|
||||
resolve({ total, list });
|
||||
}, 500);
|
||||
});
|
||||
};
|
||||
|
||||
const { list, total, status, isLoading, isFinished, loadMore, initList } =
|
||||
useLoadMore(mockFetch, { pageSize: 10 });
|
||||
|
||||
// 首次加载
|
||||
initList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">useLoadMore — 列表加载更多</h2>
|
||||
<p class="demo-desc">分页加载列表数据的组合式 API,支持加载更多、重置、加载状态管理</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>总数: {{ total }},当前: {{ list.length }} 条</p>
|
||||
<p>状态: {{ status }},加载中: {{ isLoading }},已完成: {{ isFinished }}</p>
|
||||
|
||||
<ul class="list">
|
||||
<li v-for="(item, index) in list" :key="index">{{ item }}</li>
|
||||
</ul>
|
||||
|
||||
<div style="margin-top: 8px; display: flex; gap: 8px">
|
||||
<button :disabled="isLoading" @click="loadMore">加载更多</button>
|
||||
<button @click="initList">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.list li {
|
||||
padding: 4px 0;
|
||||
font-size: 14px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<script setup lang="ts">
|
||||
import { useNumber, useString } from "@r-utils/vue3";
|
||||
import { ref } from "vue";
|
||||
|
||||
const rawValue = ref("42.5");
|
||||
const { number, int, float } = useNumber(rawValue);
|
||||
const { string } = useString(rawValue);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">useNumber / useString — 响应式类型转换</h2>
|
||||
<p class="demo-desc">将响应式变量在 number 和 string 之间双向转换</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>
|
||||
原始值:
|
||||
<input v-model="rawValue" type="text" />
|
||||
</p>
|
||||
<div class="result">
|
||||
<p>useNumber — number: <code>{{ number }}</code></p>
|
||||
<p>useNumber — int: <code>{{ int }}</code></p>
|
||||
<p>useNumber — float: <code>{{ float }}</code></p>
|
||||
<p>useString — string: <code>{{ string }}</code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<script setup lang="ts">
|
||||
import { useTimer } from "@r-utils/vue3";
|
||||
import { ref } from "vue";
|
||||
|
||||
const initTime = ref(10);
|
||||
const { time, start, restart, stop } = useTimer(initTime.value);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">useTimer — 倒计时</h2>
|
||||
<p class="demo-desc">简单的倒计时 Hook,支持开始、重新开始、停止</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>倒计时: <code>{{ time }}s</code></p>
|
||||
<div style="margin-top: 8px; display: flex; gap: 8px">
|
||||
<button @click="start">开始</button>
|
||||
<button @click="restart">重新开始</button>
|
||||
<button @click="stop">停止</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<script setup lang="ts">
|
||||
import { useValueOfRule } from "@r-utils/vue3";
|
||||
import { ref } from "vue";
|
||||
|
||||
const inputValue = ref("42.5");
|
||||
const rule = ref({ min: 0, max: 99999.99, digits: 2, required: true });
|
||||
|
||||
const { value, rule: ruleRef, handleChange } = useValueOfRule({
|
||||
value: inputValue,
|
||||
rule: rule.value,
|
||||
});
|
||||
|
||||
function apply() {
|
||||
handleChange();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="demo-page">
|
||||
<h2 class="demo-title">useValueOfRule — 按规则转换输入</h2>
|
||||
<p class="demo-desc">根据自定义规则(min/max/digits/integer 等)限制和转换输入值</p>
|
||||
|
||||
<div class="demo-block">
|
||||
<p>
|
||||
输入值:
|
||||
<input v-model="inputValue" type="text" @blur="apply" />
|
||||
</p>
|
||||
<p style="margin-top: 8px; font-size: 13px; color: #666">
|
||||
规则: min=0, max=99999.99, digits=2, required=true
|
||||
</p>
|
||||
<button style="margin-top: 8px" @click="apply">应用规则</button>
|
||||
<div class="result">
|
||||
<p>转换结果: <code>{{ value }}</code></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
},
|
||||
"types": ["vite/client"]
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "env.d.ts"]
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"root":["./src/main.ts","./src/router/index.ts","./src/app.vue","./src/views/indexpage.vue","./src/views/common/countdowndemo.vue","./src/views/common/knocktestdemo.vue","./src/views/common/permissiondemo.vue","./src/views/common/slowlyscrolldemo.vue","./src/views/common/timeouttimerdemo.vue","./src/views/common/waitdemo.vue","./src/views/vue3/mergeclassdemo.vue","./src/views/vue3/useloadmoredemo.vue","./src/views/vue3/usenumberstringdemo.vue","./src/views/vue3/usetimerdemo.vue","./src/views/vue3/usevalueofruledemo.vue","./env.d.ts"],"version":"5.9.3"}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import { resolve } from "path";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": resolve(__dirname, "src"),
|
||||
},
|
||||
},
|
||||
});
|
||||
6648
pnpm-lock.yaml
6648
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
|
@ -1,5 +1,6 @@
|
|||
packages:
|
||||
- packages/**
|
||||
- playground/**
|
||||
|
||||
catalog:
|
||||
"webpack": ^5.80.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue