diff --git a/README.md b/README.md index 10d14de..d55a139 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ | ---- | ---- | ---- | | `@r-utils/common` | `packages/common` | 通用 JS/TS 工具(权限、倒计时、打印、时间等) | | `@r-utils/vue3` | `packages/vue3` | Vue3 工具(class 处理、dispatch 等) | -| `@r-utils/uni-app` | `packages/uni-app` | uni-app 工具(请求封装、蓝牙、NFC、打印等) | +| `@r-utils/uni-app` | `packages/uni-app` | uni-app 工具(请求封装、蓝牙、NFC、打印、Vue3 Hooks 等) | | `@r-utils/uview-plus` | `packages/uview-plus` | uview-plus 组合式 API Hooks(Picker、Calendar 等) | | `@r-utils/vue2` | `packages/vue2` | Vue2 工具(visibility 插件) | @@ -86,6 +86,9 @@ import { mergeClass, dispatch } from '@r-utils/vue3'; // uni-app 工具 import { Request } from '@r-utils/uni-app'; +// uni-app Vue3 Hooks +import { useShare } from '@r-utils/uni-app/vue3'; + // uview-plus Hooks import { usePickerSingle, usePicker, useCalendar } from '@r-utils/uview-plus'; diff --git a/packages/uni-app/README.md b/packages/uni-app/README.md index 4959b9e..d0db9b6 100644 --- a/packages/uni-app/README.md +++ b/packages/uni-app/README.md @@ -1,11 +1,11 @@ # @r-utils/uni-app -仅用于 uni-app 项目的工具包,封装请求、上传、NFC、蓝牙、打印和常用 uni API 辅助方法。 +仅用于 uni-app 项目的工具包,封装请求、上传、NFC、蓝牙、打印、Vue3 Hooks 和常用 uni API 辅助方法。 ## 适用范围 - 适用于 uni-app 项目(含 uni 运行时能力)。 -- 适用于需要复用请求、上传、蓝牙、NFC、打印等能力的业务项目。 +- 适用于需要复用请求、上传、蓝牙、NFC、打印、Vue3 Hooks 等能力的业务项目。 ## 不适用范围 @@ -25,7 +25,7 @@ pnpm add @r-utils/uni-app 大多数场景推荐从根入口导入,路径简单,使用心智负担更低。 ```ts -import { Request, showToast, toPromise, upload, Printer } from "@r-utils/uni-app"; +import { Request, showToast, toPromise, upload, Printer, useShare } from "@r-utils/uni-app"; ``` ### 兼容:子路径导入 @@ -39,6 +39,7 @@ import { upload } from "@r-utils/uni-app/upload"; import { Printer } from "@r-utils/uni-app/printer"; import { nfcScan } from "@r-utils/uni-app/nfc"; import { BluetoothUtils } from "@r-utils/uni-app/bluetooth-utils"; +import { useShare, usePageTab, useTopSticky } from "@r-utils/uni-app/vue3"; ``` ## 导出模块 @@ -51,6 +52,7 @@ import { BluetoothUtils } from "@r-utils/uni-app/bluetooth-utils"; | `@r-utils/uni-app/printer` | 打印机相关工具 | | `@r-utils/uni-app/nfc` | NFC 相关工具 | | `@r-utils/uni-app/bluetooth-utils` | 蓝牙相关工具 | +| `@r-utils/uni-app/vue3` | uni-app Vue3 Hooks | ## 使用示例 @@ -86,6 +88,17 @@ const request = new Request({ }); ``` +### 使用 Vue3 Hooks + +```ts +import { useShare } from "@r-utils/uni-app/vue3"; + +const { getShareOptions } = useShare({ + title: "页面标题", + query: { id: "1" }, +}); +``` + ## 注意事项 - 推荐优先使用根入口导入;如果需要更精确的模块边界,也可以使用子路径导入。 diff --git a/packages/uni-app/package.json b/packages/uni-app/package.json index 2d76eb0..0ee59fa 100644 --- a/packages/uni-app/package.json +++ b/packages/uni-app/package.json @@ -46,6 +46,11 @@ "types": "./dist/upload/index.d.ts", "import": "./dist/upload/index.mjs", "require": "./dist/upload/index.cjs" + }, + "./vue3": { + "types": "./dist/vue3/index.d.ts", + "import": "./dist/vue3/index.mjs", + "require": "./dist/vue3/index.cjs" } }, "keywords": [ diff --git a/packages/uni-app/src/index.ts b/packages/uni-app/src/index.ts index 6c43afa..236cd35 100644 --- a/packages/uni-app/src/index.ts +++ b/packages/uni-app/src/index.ts @@ -4,3 +4,4 @@ export * from "./printer"; export * from "./request"; export * from "./uni-helper"; export * from "./upload"; +export * from "./vue3"; diff --git a/packages/uni-app/vite.config.ts b/packages/uni-app/vite.config.ts index 91ca066..ecea23c 100644 --- a/packages/uni-app/vite.config.ts +++ b/packages/uni-app/vite.config.ts @@ -19,6 +19,7 @@ export default defineConfig({ "request/index": resolve(__dirname, "src/request/index.ts"), "uni-helper/index": resolve(__dirname, "src/uni-helper/index.ts"), "upload/index": resolve(__dirname, "src/upload/index.ts"), + "vue3/index": resolve(__dirname, "src/vue3/index.ts"), }, formats: ["es", "cjs"], fileName: (format, entryName) =>