feat(playground): ✨ 新增示例项目
This commit is contained in:
parent
4759dfe6b2
commit
c22b72ac7b
1
.npmrc
1
.npmrc
|
|
@ -1,2 +1,3 @@
|
||||||
registry=http://npm.nps.yunvip123.cn
|
registry=http://npm.nps.yunvip123.cn
|
||||||
engine-strict=true
|
engine-strict=true
|
||||||
|
shamefully-hoist=true
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,14 @@ import prettier from "eslint-config-prettier";
|
||||||
import prettierPlugin from "eslint-plugin-prettier";
|
import prettierPlugin from "eslint-plugin-prettier";
|
||||||
import globals from "globals";
|
import globals from "globals";
|
||||||
import importPlugin from "eslint-plugin-import-x";
|
import importPlugin from "eslint-plugin-import-x";
|
||||||
|
import vuePlugin from "eslint-plugin-vue";
|
||||||
|
import vueParser from "vue-eslint-parser";
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
// 应用推荐规则
|
// 应用推荐规则
|
||||||
js.configs.recommended,
|
js.configs.recommended,
|
||||||
...ts.configs.recommended,
|
...ts.configs.recommended,
|
||||||
|
...vuePlugin.configs["flat/recommended"],
|
||||||
prettier,
|
prettier,
|
||||||
|
|
||||||
// 基础配置
|
// 基础配置
|
||||||
|
|
@ -37,6 +40,22 @@ export default [
|
||||||
"scripts/",
|
"scripts/",
|
||||||
],
|
],
|
||||||
plugins: { prettier: prettierPlugin, "import-x": importPlugin },
|
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: {
|
settings: {
|
||||||
"import-x/resolver": {
|
"import-x/resolver": {
|
||||||
typescript: {
|
typescript: {
|
||||||
|
|
@ -46,24 +65,14 @@ export default [
|
||||||
"packages/uview-plus/tsconfig.json",
|
"packages/uview-plus/tsconfig.json",
|
||||||
"packages/vue2/tsconfig.json",
|
"packages/vue2/tsconfig.json",
|
||||||
"packages/vue3/tsconfig.json",
|
"packages/vue3/tsconfig.json",
|
||||||
|
"playground/vue3-app/tsconfig.json",
|
||||||
|
"playground/vue2-app/tsconfig.json",
|
||||||
|
"playground/uniapp-app/tsconfig.json",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
node: true,
|
node: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
languageOptions: {
|
|
||||||
globals: {
|
|
||||||
...globals.node,
|
|
||||||
...globals.browser,
|
|
||||||
},
|
|
||||||
ecmaVersion: "latest",
|
|
||||||
sourceType: "module",
|
|
||||||
parserOptions: {
|
|
||||||
ecmaFeatures: {
|
|
||||||
impliedStrict: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
rules: {
|
rules: {
|
||||||
...importPlugin.flatConfigs.recommended.rules,
|
...importPlugin.flatConfigs.recommended.rules,
|
||||||
|
|
||||||
|
|
@ -120,8 +129,9 @@ export default [
|
||||||
// uni-app / App-Plus 运行时全局变量
|
// uni-app / App-Plus 运行时全局变量
|
||||||
{
|
{
|
||||||
files: [
|
files: [
|
||||||
"packages/uni-app/**/*.{js,ts}",
|
"packages/uni-app/**/*.{js,ts,vue}",
|
||||||
"packages/common/src/printer/**/*.{js,ts}",
|
"packages/common/src/printer/**/*.{js,ts}",
|
||||||
|
"playground/uniapp-app/**/*.{js,ts,vue}",
|
||||||
],
|
],
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
globals: {
|
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": {
|
"scripts": {
|
||||||
"preinstall": "npx only-allow pnpm",
|
"preinstall": "npx only-allow pnpm",
|
||||||
"build": "turbo run build --filter=./packages/*",
|
"build": "turbo run build --filter=./packages/*",
|
||||||
|
"build:playground": "turbo run build --filter=./playground/*",
|
||||||
"build:watch": "turbo run watch --filter=./packages/* --parallel",
|
"build:watch": "turbo run watch --filter=./packages/* --parallel",
|
||||||
"typecheck": "turbo run typecheck --filter=./packages/* --concurrency=1",
|
"typecheck": "turbo run typecheck --filter=./packages/* --concurrency=1",
|
||||||
"prepare": "husky install",
|
"prepare": "husky install",
|
||||||
"lint": "turbo run lint --filter=./packages/*",
|
"lint": "turbo run lint --filter=./packages/*",
|
||||||
|
"lint:playground": "turbo run lint --filter=./playground/*",
|
||||||
"format": "turbo run format --filter=./packages/*",
|
"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",
|
"changeset": "changeset",
|
||||||
"release": "changeset version",
|
"release": "changeset version",
|
||||||
"changeset:status": "changeset status --verbose",
|
"changeset:status": "changeset status --verbose",
|
||||||
|
|
@ -70,6 +75,8 @@
|
||||||
"eslint-import-resolver-typescript": "^4.4.4",
|
"eslint-import-resolver-typescript": "^4.4.4",
|
||||||
"eslint-plugin-import-x": "^4.16.2",
|
"eslint-plugin-import-x": "^4.16.2",
|
||||||
"eslint-plugin-prettier": "^5.5.5",
|
"eslint-plugin-prettier": "^5.5.5",
|
||||||
|
"eslint-plugin-vue": "^10.2.0",
|
||||||
|
"vue-eslint-parser": "^10.1.3",
|
||||||
"globals": "^17.4.0",
|
"globals": "^17.4.0",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"inquirer": "^9.3.8",
|
"inquirer": "^9.3.8",
|
||||||
|
|
|
||||||
|
|
@ -9,19 +9,32 @@
|
||||||
|
|
||||||
export type InputValue = string | number | null;
|
export type InputValue = string | number | null;
|
||||||
export interface InputOptions {
|
export interface InputOptions {
|
||||||
min?: number; // 最小值
|
/** 最小值 */
|
||||||
max?: number; // 最大值
|
min?: number;
|
||||||
init?: string | number; // 初始值
|
/** 最大值 */
|
||||||
digits?: number; // 小数位数
|
max?: number;
|
||||||
pattern?: string | RegExp; // 匹配模式
|
/** 初始值,当输入非法且 required 为 true 时回退到此值 */
|
||||||
required?: boolean; // 是否必填
|
init?: string | number;
|
||||||
integer?: boolean; // 是否整数
|
/** 小数位数,设置后会对结果进行精度处理 */
|
||||||
number?: boolean; // 是否转成数字
|
digits?: number;
|
||||||
text?: boolean; // 是否使用文本模式
|
/** 匹配模式,文本模式下用于校验输入是否匹配该正则 */
|
||||||
floor?: boolean; // 是否向下取数
|
pattern?: string | RegExp;
|
||||||
ceil?: boolean; // 是否向上取数
|
/** 是否必填,为 true 时非法输入将回退到 init 或 min */
|
||||||
keepDecimal?: boolean; // 是否保留小数,即使是小数位是0
|
required?: boolean;
|
||||||
noSign?: 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";
|
import { debounce } from "lodash-es";
|
||||||
|
|
||||||
|
/** 操作项,定义一次敲击阶段的参数 */
|
||||||
export class Operation {
|
export class Operation {
|
||||||
|
/** 敲击有效时长(ms),超过该时长未达到指定次数则重置 */
|
||||||
duration = 1000;
|
duration = 1000;
|
||||||
|
/** 当前操作完成后进入下一操作前的等待时长(ms),等待期间点击会重置 */
|
||||||
delay = 1000;
|
delay = 1000;
|
||||||
|
/** 当前操作需要敲击的次数 */
|
||||||
times = 1;
|
times = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** KnockTest 配置项 */
|
||||||
export class Config {
|
export class Config {
|
||||||
|
/** 最大等待时间(ms),从首次敲击开始计算,超时未完成所有操作则自动重置 */
|
||||||
maxWaitTime = 5000;
|
maxWaitTime = 5000;
|
||||||
|
/** 操作项列表,按顺序执行 */
|
||||||
operations: Operation[] = [];
|
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 {
|
export class KnockTest {
|
||||||
|
/** 配置项 */
|
||||||
config: Config;
|
config: Config;
|
||||||
|
/** 当前操作项索引 */
|
||||||
index = 0;
|
index = 0;
|
||||||
|
/** 当前阶段已敲击次数 */
|
||||||
times = 0;
|
times = 0;
|
||||||
/**
|
/**
|
||||||
* 空闲状态:"idle",times从0开始计数,进入duration期
|
* 当前状态:
|
||||||
* duration期间:"knocking",times达到Operation的指定次数后进入delay期
|
* - "idle" 空闲,times从0开始计数,进入duration期
|
||||||
* delay期间:"wait",此期间不能点击,如果点击则重置,否则进入下一个空闲状态
|
* - "knocking" 敲击中,times达到Operation的指定次数后进入delay期
|
||||||
|
* - "wait" 等待,此期间不能点击,如果点击则重置,否则进入下一个空闲状态
|
||||||
*/
|
*/
|
||||||
status: "idle" | "knocking" | "wait" = "idle";
|
status: "idle" | "knocking" | "wait" = "idle";
|
||||||
|
/** duration 定时器 ID */
|
||||||
durationTimerId: number | null = null;
|
durationTimerId: number | null = null;
|
||||||
|
/** delay 定时器 ID */
|
||||||
delayTimerId: number | null = null;
|
delayTimerId: number | null = null;
|
||||||
|
/** 成功回调列表,所有操作完成后依次执行 */
|
||||||
callbackList: (() => void)[] = [];
|
callbackList: (() => void)[] = [];
|
||||||
|
/** 最大等待防抖函数,超时自动重置 */
|
||||||
maxWaitFun: () => void;
|
maxWaitFun: () => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param config 配置项,未指定的字段使用默认值
|
||||||
|
*/
|
||||||
constructor(config: Config) {
|
constructor(config: Config) {
|
||||||
const c = new Config();
|
const c = new Config();
|
||||||
this.config = Object.assign(c, config);
|
this.config = Object.assign(c, config);
|
||||||
|
|
@ -36,10 +85,22 @@ export class KnockTest {
|
||||||
}, this.config.maxWaitTime);
|
}, this.config.maxWaitTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加成功回调,所有操作按序完成后触发
|
||||||
|
* @param cb 回调函数
|
||||||
|
*/
|
||||||
addCallback(cb: () => void) {
|
addCallback(cb: () => void) {
|
||||||
this.callbackList.push(cb);
|
this.callbackList.push(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 敲击一次,在 UI 点击事件中调用
|
||||||
|
*
|
||||||
|
* 每次调用会使 times + 1,并根据当前状态决定后续行为:
|
||||||
|
* - idle → 开始新的敲击阶段
|
||||||
|
* - knocking → 检查是否达到当前操作指定次数
|
||||||
|
* - wait → 重置所有状态(等待期间不允许敲击)
|
||||||
|
*/
|
||||||
knock() {
|
knock() {
|
||||||
console.log("knock");
|
console.log("knock");
|
||||||
this.maxWaitFun();
|
this.maxWaitFun();
|
||||||
|
|
@ -60,6 +121,7 @@ export class KnockTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 重置所有状态,回到初始空闲状态并清除所有定时器 */
|
||||||
private reset() {
|
private reset() {
|
||||||
this.status = "idle";
|
this.status = "idle";
|
||||||
this.times = 0;
|
this.times = 0;
|
||||||
|
|
@ -75,6 +137,11 @@ export class KnockTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理空闲状态的敲击:启动新的敲击阶段,设置 duration 定时器
|
||||||
|
* 超时未达到指定次数则自动重置
|
||||||
|
* @throws 当操作项列表为空时抛出错误
|
||||||
|
*/
|
||||||
private handleIdle() {
|
private handleIdle() {
|
||||||
if (this.config.operations.length === 0) {
|
if (this.config.operations.length === 0) {
|
||||||
throw new Error("至少添加一个操作项");
|
throw new Error("至少添加一个操作项");
|
||||||
|
|
@ -92,10 +159,17 @@ export class KnockTest {
|
||||||
this.checkKnock();
|
this.checkKnock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理敲击中状态:检查当前敲击次数是否满足操作项要求
|
||||||
|
*/
|
||||||
private handleKnocking() {
|
private handleKnocking() {
|
||||||
this.checkKnock();
|
this.checkKnock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查当前敲击次数是否达到操作项要求,若达到则进入等待状态
|
||||||
|
* 若已完成所有操作项,则触发回调并重置
|
||||||
|
*/
|
||||||
private checkKnock() {
|
private checkKnock() {
|
||||||
const operation = this.config.operations[this.index];
|
const operation = this.config.operations[this.index];
|
||||||
|
|
||||||
|
|
@ -127,6 +201,9 @@ export class KnockTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理等待状态的敲击:等待期间不允许敲击,直接重置
|
||||||
|
*/
|
||||||
private handleWait() {
|
private handleWait() {
|
||||||
if (this.delayTimerId != null) {
|
if (this.delayTimerId != null) {
|
||||||
clearTimeout(this.delayTimerId);
|
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 {
|
export class Permission {
|
||||||
/**
|
/** 权限字符串列表 */
|
||||||
*
|
|
||||||
*/
|
|
||||||
list: string[];
|
list: string[];
|
||||||
|
/** 权限分隔符,默认为 ":" */
|
||||||
separator: string;
|
separator: string;
|
||||||
|
/** 权限级数,默认为 3(如 "module:action:resource") */
|
||||||
level: number;
|
level: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list 权限字符串列表
|
||||||
|
* @param level 权限级数,默认 3
|
||||||
|
* @param separator 分隔符,默认 ":"
|
||||||
|
*/
|
||||||
constructor(list: string[], level = 3, separator = ":") {
|
constructor(list: string[], level = 3, separator = ":") {
|
||||||
this.list = list;
|
this.list = list;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.separator = separator;
|
this.separator = separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验权限字符串格式是否合法
|
||||||
|
*
|
||||||
|
* 检查字符串是否符合指定的级数和分隔符格式,
|
||||||
|
* 例如 level=3、separator=":" 时,"module:action:resource" 合法,"module:action" 不合法。
|
||||||
|
*
|
||||||
|
* @param str 待校验的权限字符串
|
||||||
|
* @returns 是否合法
|
||||||
|
*/
|
||||||
isValid(str: string) {
|
isValid(str: string) {
|
||||||
const p = new Array(this.level).fill("\\w+?").join(this.separator);
|
const p = new Array(this.level).fill("\\w+?").join(this.separator);
|
||||||
// ^\w+?:\w+?:\w+?$
|
// ^\w+?:\w+?:\w+?$
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,47 @@ import { Duration } from "dayjs/plugin/duration";
|
||||||
|
|
||||||
type TimerCallback = (time: string) => void;
|
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 {
|
export default class Countdown {
|
||||||
|
/** 定时器 ID,-1 表示未运行 */
|
||||||
id = -1;
|
id = -1;
|
||||||
|
/** dayjs duration 对象,表示剩余时长 */
|
||||||
duration: Duration;
|
duration: Duration;
|
||||||
|
/** 输出时间格式,默认 "HH:mm:ss" */
|
||||||
format = "HH:mm:ss";
|
format = "HH:mm:ss";
|
||||||
/**
|
/**
|
||||||
* 倒计时步骤监听器
|
* 倒计时步骤监听器列表
|
||||||
|
*
|
||||||
|
* 每秒触发一次,参数为当前格式化后的剩余时间字符串
|
||||||
*/
|
*/
|
||||||
stepEventListenerList = <TimerCallback[]>[];
|
stepEventListenerList = <TimerCallback[]>[];
|
||||||
/**
|
/**
|
||||||
* 倒计时完成时间监听器
|
* 倒计时完成监听器列表
|
||||||
|
*
|
||||||
|
* 倒计时归零时触发,参数为最终的格式化时间字符串
|
||||||
*/
|
*/
|
||||||
countdownEventListenerList = <TimerCallback[]>[];
|
countdownEventListenerList = <TimerCallback[]>[];
|
||||||
|
/** 初始时间(毫秒),用于 restart 时重置 */
|
||||||
initialTime = 0;
|
initialTime = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param time 倒计时总时长(毫秒)
|
||||||
|
*/
|
||||||
constructor(time: number) {
|
constructor(time: number) {
|
||||||
this.initialTime = time;
|
this.initialTime = time;
|
||||||
this.duration = dayjs.duration(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) {
|
addStepEventListener(cb: TimerCallback) {
|
||||||
if (!(cb instanceof Function)) {
|
if (!(cb instanceof Function)) {
|
||||||
|
|
@ -35,9 +65,12 @@ export default class Countdown {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加倒计时完成时间监听器
|
* 添加倒计时完成监听器
|
||||||
* @param cb
|
*
|
||||||
* @returns
|
* 倒计时归零时触发,参数为最终的格式化时间字符串
|
||||||
|
*
|
||||||
|
* @param cb 完成回调函数,参数为格式化时间字符串
|
||||||
|
* @returns 若 cb 不是函数则返回 TypeError
|
||||||
*/
|
*/
|
||||||
addCountdownEventListener(cb: TimerCallback) {
|
addCountdownEventListener(cb: TimerCallback) {
|
||||||
if (!(cb instanceof Function)) {
|
if (!(cb instanceof Function)) {
|
||||||
|
|
@ -47,7 +80,7 @@ export default class Countdown {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始倒计时
|
* 开始倒计时,每秒递减一次并触发步骤监听器,归零时自动停止
|
||||||
*/
|
*/
|
||||||
start() {
|
start() {
|
||||||
this.id = window.setInterval(() => {
|
this.id = window.setInterval(() => {
|
||||||
|
|
@ -63,7 +96,7 @@ export default class Countdown {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结束倒计时
|
* 停止倒计时,清除定时器并触发完成监听器
|
||||||
*/
|
*/
|
||||||
stop() {
|
stop() {
|
||||||
console.log("stop", this.id);
|
console.log("stop", this.id);
|
||||||
|
|
@ -75,7 +108,7 @@ export default class Countdown {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重新开始计时
|
* 重新开始倒计时,重置为初始时间后重新启动
|
||||||
*/
|
*/
|
||||||
restart() {
|
restart() {
|
||||||
clearInterval(this.id);
|
clearInterval(this.id);
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,49 @@
|
||||||
type TimerCallback = (time: number) => void;
|
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 {
|
export default class TimeoutTimer {
|
||||||
|
/** 起始时间(数值) */
|
||||||
startTime = 0;
|
startTime = 0;
|
||||||
|
/** 结束时间(数值),倒计时到此值停止 */
|
||||||
endTime = 0;
|
endTime = 0;
|
||||||
|
/** 递减间隔(毫秒) */
|
||||||
interval = 0;
|
interval = 0;
|
||||||
|
/** 当前剩余时间 */
|
||||||
time = 0;
|
time = 0;
|
||||||
|
/** 定时器 ID,-1 表示未运行 */
|
||||||
id = -1;
|
id = -1;
|
||||||
|
/** 步骤监听器列表,每次递减时触发,参数为当前剩余时间 */
|
||||||
stepEventListenerList = <TimerCallback[]>[];
|
stepEventListenerList = <TimerCallback[]>[];
|
||||||
|
/** 完成监听器列表,倒计时结束时触发,参数为结束时间 */
|
||||||
countdownEventListenerList = <TimerCallback[]>[];
|
countdownEventListenerList = <TimerCallback[]>[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @param startTime 起始时间(数值)
|
||||||
* @param startTime 起始时间
|
* @param endTime 结束时间(数值),默认 0
|
||||||
* @param endTime 结束时间
|
* @param interval 递减间隔(毫秒),默认 1000
|
||||||
* @param interval 间隔(ms)
|
|
||||||
*/
|
*/
|
||||||
constructor(startTime = 5, endTime = 0, interval = 1000) {
|
constructor(startTime = 5, endTime = 0, interval = 1000) {
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
|
|
@ -22,9 +52,12 @@ export default class TimeoutTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 倒计时步骤监听器
|
* 添加步骤监听器
|
||||||
* @param cb
|
*
|
||||||
* @returns
|
* 每次递减时触发,参数为当前剩余时间
|
||||||
|
*
|
||||||
|
* @param cb 步骤回调函数,参数为当前时间(数值)
|
||||||
|
* @returns 若 cb 不是函数则返回 TypeError
|
||||||
*/
|
*/
|
||||||
addStepEventListener(cb: TimerCallback) {
|
addStepEventListener(cb: TimerCallback) {
|
||||||
if (!(cb instanceof Function)) {
|
if (!(cb instanceof Function)) {
|
||||||
|
|
@ -34,9 +67,12 @@ export default class TimeoutTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 倒计时完成时间监听器
|
* 添加完成监听器
|
||||||
* @param cb
|
*
|
||||||
* @returns
|
* 倒计时到达 endTime 时触发,参数为结束时间
|
||||||
|
*
|
||||||
|
* @param cb 完成回调函数,参数为结束时间(数值)
|
||||||
|
* @returns 若 cb 不是函数则返回 TypeError
|
||||||
*/
|
*/
|
||||||
addCountdownEventListener(cb: TimerCallback) {
|
addCountdownEventListener(cb: TimerCallback) {
|
||||||
if (!(cb instanceof Function)) {
|
if (!(cb instanceof Function)) {
|
||||||
|
|
@ -46,13 +82,14 @@ export default class TimeoutTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始倒计时
|
* 静态工厂方法,创建并配置超时定时器
|
||||||
* @param startTime
|
*
|
||||||
* @param endTime
|
* @param startTime 起始时间(数值)
|
||||||
* @param interval
|
* @param endTime 结束时间(数值),默认 0
|
||||||
* @param stepEventListener
|
* @param interval 递减间隔(毫秒),默认 1000
|
||||||
* @param countdownEventListener
|
* @param stepEventListener 步骤监听器(可选)
|
||||||
* @returns
|
* @param countdownEventListener 完成监听器(可选)
|
||||||
|
* @returns 配置好的 TimeoutTimer 实例(需手动调用 start)
|
||||||
*/
|
*/
|
||||||
static start(
|
static start(
|
||||||
startTime: number,
|
startTime: number,
|
||||||
|
|
@ -73,7 +110,7 @@ export default class TimeoutTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始倒计时
|
* 开始倒计时,从 startTime 递减到 endTime,到达后自动停止
|
||||||
*/
|
*/
|
||||||
start() {
|
start() {
|
||||||
this.time = this.startTime;
|
this.time = this.startTime;
|
||||||
|
|
@ -88,7 +125,7 @@ export default class TimeoutTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结束倒计时
|
* 停止倒计时,清除定时器并触发完成监听器
|
||||||
*/
|
*/
|
||||||
stop() {
|
stop() {
|
||||||
console.log("stop", this.id);
|
console.log("stop", this.id);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
# @r-utils/uni-app
|
# @r-utils/uni-app
|
||||||
|
|
||||||
|
## 2.0.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 修复vue3未导出
|
||||||
|
|
||||||
## 2.0.1
|
## 2.0.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@r-utils/uni-app",
|
"name": "@r-utils/uni-app",
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "uni-app工具库",
|
"description": "uni-app工具库",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
|
||||||
|
|
@ -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 { wait } from "@r-utils/common";
|
||||||
import { BluetoothUtils, Device } from "@/bluetooth-utils";
|
import { BluetoothUtils, Device } from "@/bluetooth-utils";
|
||||||
|
|
||||||
|
/** 蓝牙设备完整数据,包含设备信息和所有必需的特征值 ID */
|
||||||
type DeviceData = Required<Device>;
|
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 {
|
export class Printer {
|
||||||
|
/** 蓝牙设备信息,包含 deviceId、服务 ID 和特征值 ID 等 */
|
||||||
device: DeviceData;
|
device: DeviceData;
|
||||||
|
/** 每次写入 BLE 的最大字节数,默认 80 */
|
||||||
size = 0;
|
size = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param device 蓝牙设备完整数据(必须包含所有特征值 ID)
|
||||||
|
* @param size 每次写入的最大字节数,默认 80
|
||||||
|
*/
|
||||||
constructor(device: DeviceData, { size = 80 } = {}) {
|
constructor(device: DeviceData, { size = 80 } = {}) {
|
||||||
this.device = device;
|
this.device = device;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送打印数据
|
||||||
|
*
|
||||||
|
* 根据平台自动选择发送方式:
|
||||||
|
* - 安卓 App 端:使用 BluetoothUtils.sendDataAndroid 原生发送
|
||||||
|
* - 其他平台:通过 BLE 写入特征值发送
|
||||||
|
*
|
||||||
|
* @param data ESC/POS 打印指令数组
|
||||||
|
* @returns 发送结果
|
||||||
|
*/
|
||||||
async print(data: number[]) {
|
async print(data: number[]) {
|
||||||
console.log(
|
console.log(
|
||||||
data.length,
|
data.length,
|
||||||
|
|
@ -32,6 +71,14 @@ export class Printer {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 BLE 写入特征值分包发送打印数据(内部方法)
|
||||||
|
*
|
||||||
|
* 将数据按 size 分包,每包创建 ArrayBuffer 写入 BLE 特征值,
|
||||||
|
* 包间等待 30ms 确保传输稳定,递归发送直到所有数据写完。
|
||||||
|
*
|
||||||
|
* @param data 剩余待发送的打印数据
|
||||||
|
*/
|
||||||
async _print(data: number[]): Promise<void> {
|
async _print(data: number[]): Promise<void> {
|
||||||
const size = Math.min(data.length, this.size);
|
const size = Math.min(data.length, this.size);
|
||||||
if (size === 0) {
|
if (size === 0) {
|
||||||
|
|
|
||||||
|
|
@ -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;
|
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 = {
|
type UploadResponseData = {
|
||||||
originalFileName: string;
|
originalFileName: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* @file /src/vue3/hooks/components.ts
|
* @file /src/vue3/hooks/components.ts
|
||||||
* @description
|
* @description uniapp组件hook
|
||||||
* @author tsl (randy1924@163.com)
|
* @author tsl (randy1924@163.com)
|
||||||
* @date 2026-03-19 11:11:11
|
* @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)
|
* @lastModifiedBy tsl (randy1924@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* @file /src/hooks/list.ts
|
* @file /src/hooks/list.ts
|
||||||
* @description
|
* @description 列表加载更多Hook
|
||||||
* @author tsl (randy1924@163.com)
|
* @author tsl (randy1924@163.com)
|
||||||
* @date 2026-03-19 11:11:11
|
* @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)
|
* @lastModifiedBy tsl (randy1924@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,37 @@
|
||||||
|
/*
|
||||||
|
* @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";
|
import { ComponentPublicInstance } from "vue";
|
||||||
|
|
||||||
|
/** Vue class 对象格式,键为类名,值为布尔值表示是否生效 */
|
||||||
type CustomClassObj = Record<string, boolean>;
|
type CustomClassObj = Record<string, boolean>;
|
||||||
|
/** Vue class 支持的类型:字符串、字符串数组或对象 */
|
||||||
type CustomClass = string | Array<string> | CustomClassObj;
|
type CustomClass = string | Array<string> | CustomClassObj;
|
||||||
|
/** 分解后的 Vue class 对象,所有类名值为 true */
|
||||||
type DistCustomClass = Record<string, 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: string): DistCustomClass;
|
||||||
export function createCustomClassObj(
|
export function createCustomClassObj(
|
||||||
customClass: Array<string>,
|
customClass: Array<string>,
|
||||||
|
|
@ -35,9 +63,21 @@ export function createCustomClassObj(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换 vue class 为 vue class 对象
|
* 转换 Vue class 为 Vue class 对象
|
||||||
* @param sourceClass 原始 class
|
*
|
||||||
* @returns
|
* 支持字符串、数组和对象三种 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 {
|
export function convertCustomClass(sourceClass: CustomClass): CustomClassObj {
|
||||||
let customClassObj = <CustomClassObj>{};
|
let customClassObj = <CustomClassObj>{};
|
||||||
|
|
@ -66,9 +106,19 @@ export function convertCustomClass(sourceClass: CustomClass): CustomClassObj {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合并 class
|
* 合并多个 Vue class 值为一个对象
|
||||||
* @param customClass vue class
|
*
|
||||||
* @returns
|
* 将多个 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[]) {
|
export function mergeClass(...customClass: CustomClass[]) {
|
||||||
return customClass
|
return customClass
|
||||||
|
|
@ -77,12 +127,21 @@ export function mergeClass(...customClass: CustomClass[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送祖先组件事件
|
* 向上遍历祖先组件,找到指定名称的组件并触发其事件
|
||||||
* @param thisArg 调用的源组件实例
|
*
|
||||||
* @param componentName 需要触发事件的组件名
|
* 类似 Vue2 的 dispatch 模式,从当前组件开始沿父组件链向上查找,
|
||||||
* @param eventName 事件名称
|
* 直到找到 componentName 匹配的祖先组件,然后触发其指定事件。
|
||||||
* @param params 参数
|
*
|
||||||
* @returns
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* dispatch(this, 'FormComponent', 'validate', { field: 'name' })
|
||||||
|
* // 向上查找名为 FormComponent 的祖先组件,触发其 validate 事件
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param thisArg 调用源的组件实例
|
||||||
|
* @param componentName 目标祖先组件的 componentName 选项值
|
||||||
|
* @param eventName 要触发的事件名称
|
||||||
|
* @param params 传递给事件的参数
|
||||||
*/
|
*/
|
||||||
export function dispatch(
|
export function dispatch(
|
||||||
thisArg: ComponentPublicInstance,
|
thisArg: ComponentPublicInstance,
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
- packages/**
|
- packages/**
|
||||||
|
- playground/**
|
||||||
|
|
||||||
catalog:
|
catalog:
|
||||||
"webpack": ^5.80.0
|
"webpack": ^5.80.0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue