@cloudcome/utils-uni 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # 我的个人工具函数库
2
+
3
+ [![code-review](https://github.com/cloudcome/utils/actions/workflows/code-review.yml/badge.svg)](https://github.com/cloudcome/utils/actions/workflows/code-review.yml)
4
+ [![dependency-review](https://github.com/cloudcome/utils/actions/workflows/dependency-review.yml/badge.svg)](https://github.com/cloudcome/utils/actions/workflows/dependency-review.yml)
5
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/4fa1acaeb717469caddfe21a84c50bb2)](https://app.codacy.com/gh/cloudcome/utils/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
6
+ [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/4fa1acaeb717469caddfe21a84c50bb2)](https://app.codacy.com/gh/cloudcome/utils/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
7
+
8
+
9
+ | 名称 | 版本 | 描述 |
10
+ | --- | --- | --- |
11
+ | @cloudcome/utils-core | [![npm version](https://badge.fury.io/js/@cloudcome%2Futils-core.svg)](https://npmjs.com/package/@cloudcome/utils-core) | 核心工具库 |
12
+ | @cloudcome/utils-browser | [![npm version](https://badge.fury.io/js/@cloudcome%2Futils-browser.svg)](https://npmjs.com/package/@cloudcome/utils-browser) | 浏览器工具库 |
13
+ | @cloudcome/utils-node| [![npm version](https://badge.fury.io/js/@cloudcome%2Futils-node.svg)](https://npmjs.com/package/@cloudcome/utils-node) | Node.js 工具库 |
14
+ | @cloudcome/utils-vue| [![npm version](https://badge.fury.io/js/@cloudcome%2Futils-vue.svg)](https://npmjs.com/package/@cloudcome/utils-vue) | Vue 工具库 |
15
+ | @cloudcome/utils-react| [![npm version](https://badge.fury.io/js/@cloudcome%2Futils-react.svg)](https://npmjs.com/package/@cloudcome/utils-react) | React 工具库 |
16
+ | @cloudcome/utils-uni| [![npm version](https://badge.fury.io/js/@cloudcome%2Futils-uni.svg)](https://npmjs.com/package/@cloudcome/utils-uni) | UniApp 工具库 |
17
+
18
+
package/dist/cloud.cjs ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const request = require("@cloudcome/utils-vue/request");
4
+ function createUseCloudObject(objectName, options) {
5
+ const server = (options == null ? void 0 : options._mockServer) || uniCloud.importObject(objectName, options);
6
+ return function useCloudObject(caller, options2) {
7
+ return request.useRequest(async (...inputs) => {
8
+ const result = await caller(server, ...inputs);
9
+ if (!result.errCode) return result.data;
10
+ throw new Error(result.errMsg || "请求失败");
11
+ }, options2);
12
+ };
13
+ }
14
+ function useCloudDatabase(caller, options) {
15
+ const db = (options == null ? void 0 : options._mockDatabase) || uniCloud.database();
16
+ return request.useRequest(async (...inputs) => {
17
+ const { result } = await caller(db, ...inputs);
18
+ if (!result.errCode) return result;
19
+ throw new Error(result.errMsg || "请求失败");
20
+ }, options);
21
+ }
22
+ exports.createUseCloudObject = createUseCloudObject;
23
+ exports.useCloudDatabase = useCloudDatabase;
24
+ //# sourceMappingURL=cloud.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud.cjs","sources":["../src/cloud.ts"],"sourcesContent":["import type { AnyArray } from '@cloudcome/utils-core/types';\nimport { type UseRequestOptions, useRequest } from '@cloudcome/utils-vue/request';\n\ntype ImportObject = UniCloudNamespace.UniCloud['importObject'];\ntype ImportObjectArgs = Parameters<ImportObject>;\n\nexport type UniCloudObjectReturns<T> = {\n errCode?: number | string;\n errMsg?: string;\n data: T;\n};\n\ntype UniCloudObjectServer<I extends AnyArray, T> = (...inputs: I) => Promise<UniCloudObjectReturns<T>>;\n\nexport type CreateUseCloudObjectOptions = ImportObjectArgs[1] & {\n /**\n * 模拟云对象,用于单元测试\n * @private\n */\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n _mockServer?: any;\n};\n\n/**\n * 创建一个用于调用云对象的hook工厂函数\n * @param objectName 云对象名称,用于导入对应的云对象\n * @param options 导入云对象时的可选配置参数\n * @returns 返回一个函数,该函数可以用于创建云对象调用hook\n */\nexport function createUseCloudObject(objectName: ImportObjectArgs[0], options?: CreateUseCloudObjectOptions) {\n const server = options?._mockServer || uniCloud.importObject(objectName, options);\n\n /**\n * 创建云对象调用hook的函数\n * @param caller 调用云对象的函数,接收云对象服务和输入参数,返回Promise\n * @returns 返回一个请求hook,用于处理云对象调用\n */\n return function useCloudObject<I extends AnyArray, O>(\n caller: (server: UniCloudObjectServer<I, O>, ...inputs: I) => Promise<UniCloudObjectReturns<O>>,\n options?: UseRequestOptions<I, O>,\n ) {\n // 使用请求hook处理云对象调用\n return useRequest(async (...inputs: I) => {\n const result = await caller(server, ...inputs);\n if (!result.errCode) return result.data;\n throw new Error(result.errMsg || '请求失败');\n }, options);\n };\n}\n\nexport type UniCloudDatabaseReturns<T> = {\n result: T & {\n errCode?: number | string;\n errMsg?: string;\n };\n};\n\nexport type UseCloudDatabaseOptions<I extends AnyArray, O> = UseRequestOptions<I, O> & {\n /**\n * 模拟数据库,用于单元测试\n */\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n _mockDatabase?: any;\n};\n\n/**\n * 创建一个用于调用云数据库的hook\n * @param caller 调用云数据库的函数,接收数据库实例和输入参数,返回Promise\n * @param options 配置选项\n * @returns 返回一个请求hook,用于处理云数据库调用\n */\nexport function useCloudDatabase<I extends AnyArray, O>(\n caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniCloudDatabaseReturns<O>>,\n options?: UseCloudDatabaseOptions<I, O>,\n) {\n // 获取数据库实例,优先使用模拟数据库(用于测试),否则使用uniCloud数据库\n const db = options?._mockDatabase || uniCloud.database();\n return useRequest(async (...inputs: I) => {\n const { result } = await caller(db, ...inputs);\n if (!result.errCode) return result;\n throw new Error(result.errMsg || '请求失败');\n }, options);\n}\n"],"names":["options","useRequest"],"mappings":";;;AA6BgB,SAAA,qBAAqB,YAAiC,SAAuC;AAC3G,QAAM,UAAS,mCAAS,gBAAe,SAAS,aAAa,YAAY,OAAO;AAOzE,SAAA,SAAS,eACd,QACAA,UACA;AAEO,WAAAC,QAAA,WAAW,UAAU,WAAc;AACxC,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,MAAM;AAC7C,UAAI,CAAC,OAAO,QAAS,QAAO,OAAO;AACnC,YAAM,IAAI,MAAM,OAAO,UAAU,MAAM;AAAA,OACtCD,QAAO;AAAA,EACZ;AACF;AAuBgB,SAAA,iBACd,QACA,SACA;AAEA,QAAM,MAAK,mCAAS,kBAAiB,SAAS,SAAS;AAChD,SAAAC,QAAA,WAAW,UAAU,WAAc;AACxC,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,IAAI,GAAG,MAAM;AACzC,QAAA,CAAC,OAAO,QAAgB,QAAA;AAC5B,UAAM,IAAI,MAAM,OAAO,UAAU,MAAM;AAAA,KACtC,OAAO;AACZ;;;"}
@@ -0,0 +1,44 @@
1
+ import { AnyArray } from '@cloudcome/utils-core/types';
2
+ import { UseRequestOptions } from '@cloudcome/utils-vue/request';
3
+ type ImportObject = UniCloudNamespace.UniCloud['importObject'];
4
+ type ImportObjectArgs = Parameters<ImportObject>;
5
+ export type UniCloudObjectReturns<T> = {
6
+ errCode?: number | string;
7
+ errMsg?: string;
8
+ data: T;
9
+ };
10
+ type UniCloudObjectServer<I extends AnyArray, T> = (...inputs: I) => Promise<UniCloudObjectReturns<T>>;
11
+ export type CreateUseCloudObjectOptions = ImportObjectArgs[1] & {
12
+ /**
13
+ * 模拟云对象,用于单元测试
14
+ * @private
15
+ */
16
+ _mockServer?: any;
17
+ };
18
+ /**
19
+ * 创建一个用于调用云对象的hook工厂函数
20
+ * @param objectName 云对象名称,用于导入对应的云对象
21
+ * @param options 导入云对象时的可选配置参数
22
+ * @returns 返回一个函数,该函数可以用于创建云对象调用hook
23
+ */
24
+ export declare function createUseCloudObject(objectName: ImportObjectArgs[0], options?: CreateUseCloudObjectOptions): <I extends AnyArray, O>(caller: (server: UniCloudObjectServer<I, O>, ...inputs: I) => Promise<UniCloudObjectReturns<O>>, options?: UseRequestOptions<I, O>) => import('@cloudcome/utils-vue/request').UseRequestReturns<I, O>;
25
+ export type UniCloudDatabaseReturns<T> = {
26
+ result: T & {
27
+ errCode?: number | string;
28
+ errMsg?: string;
29
+ };
30
+ };
31
+ export type UseCloudDatabaseOptions<I extends AnyArray, O> = UseRequestOptions<I, O> & {
32
+ /**
33
+ * 模拟数据库,用于单元测试
34
+ */
35
+ _mockDatabase?: any;
36
+ };
37
+ /**
38
+ * 创建一个用于调用云数据库的hook
39
+ * @param caller 调用云数据库的函数,接收数据库实例和输入参数,返回Promise
40
+ * @param options 配置选项
41
+ * @returns 返回一个请求hook,用于处理云数据库调用
42
+ */
43
+ export declare function useCloudDatabase<I extends AnyArray, O>(caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniCloudDatabaseReturns<O>>, options?: UseCloudDatabaseOptions<I, O>): import('@cloudcome/utils-vue/request').UseRequestReturns<I, O>;
44
+ export {};
package/dist/cloud.mjs ADDED
@@ -0,0 +1,24 @@
1
+ import { useRequest } from "@cloudcome/utils-vue/request";
2
+ function createUseCloudObject(objectName, options) {
3
+ const server = (options == null ? void 0 : options._mockServer) || uniCloud.importObject(objectName, options);
4
+ return function useCloudObject(caller, options2) {
5
+ return useRequest(async (...inputs) => {
6
+ const result = await caller(server, ...inputs);
7
+ if (!result.errCode) return result.data;
8
+ throw new Error(result.errMsg || "请求失败");
9
+ }, options2);
10
+ };
11
+ }
12
+ function useCloudDatabase(caller, options) {
13
+ const db = (options == null ? void 0 : options._mockDatabase) || uniCloud.database();
14
+ return useRequest(async (...inputs) => {
15
+ const { result } = await caller(db, ...inputs);
16
+ if (!result.errCode) return result;
17
+ throw new Error(result.errMsg || "请求失败");
18
+ }, options);
19
+ }
20
+ export {
21
+ createUseCloudObject,
22
+ useCloudDatabase
23
+ };
24
+ //# sourceMappingURL=cloud.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloud.mjs","sources":["../src/cloud.ts"],"sourcesContent":["import type { AnyArray } from '@cloudcome/utils-core/types';\nimport { type UseRequestOptions, useRequest } from '@cloudcome/utils-vue/request';\n\ntype ImportObject = UniCloudNamespace.UniCloud['importObject'];\ntype ImportObjectArgs = Parameters<ImportObject>;\n\nexport type UniCloudObjectReturns<T> = {\n errCode?: number | string;\n errMsg?: string;\n data: T;\n};\n\ntype UniCloudObjectServer<I extends AnyArray, T> = (...inputs: I) => Promise<UniCloudObjectReturns<T>>;\n\nexport type CreateUseCloudObjectOptions = ImportObjectArgs[1] & {\n /**\n * 模拟云对象,用于单元测试\n * @private\n */\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n _mockServer?: any;\n};\n\n/**\n * 创建一个用于调用云对象的hook工厂函数\n * @param objectName 云对象名称,用于导入对应的云对象\n * @param options 导入云对象时的可选配置参数\n * @returns 返回一个函数,该函数可以用于创建云对象调用hook\n */\nexport function createUseCloudObject(objectName: ImportObjectArgs[0], options?: CreateUseCloudObjectOptions) {\n const server = options?._mockServer || uniCloud.importObject(objectName, options);\n\n /**\n * 创建云对象调用hook的函数\n * @param caller 调用云对象的函数,接收云对象服务和输入参数,返回Promise\n * @returns 返回一个请求hook,用于处理云对象调用\n */\n return function useCloudObject<I extends AnyArray, O>(\n caller: (server: UniCloudObjectServer<I, O>, ...inputs: I) => Promise<UniCloudObjectReturns<O>>,\n options?: UseRequestOptions<I, O>,\n ) {\n // 使用请求hook处理云对象调用\n return useRequest(async (...inputs: I) => {\n const result = await caller(server, ...inputs);\n if (!result.errCode) return result.data;\n throw new Error(result.errMsg || '请求失败');\n }, options);\n };\n}\n\nexport type UniCloudDatabaseReturns<T> = {\n result: T & {\n errCode?: number | string;\n errMsg?: string;\n };\n};\n\nexport type UseCloudDatabaseOptions<I extends AnyArray, O> = UseRequestOptions<I, O> & {\n /**\n * 模拟数据库,用于单元测试\n */\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n _mockDatabase?: any;\n};\n\n/**\n * 创建一个用于调用云数据库的hook\n * @param caller 调用云数据库的函数,接收数据库实例和输入参数,返回Promise\n * @param options 配置选项\n * @returns 返回一个请求hook,用于处理云数据库调用\n */\nexport function useCloudDatabase<I extends AnyArray, O>(\n caller: (db: UniCloud.Database, ...inputs: I) => Promise<UniCloudDatabaseReturns<O>>,\n options?: UseCloudDatabaseOptions<I, O>,\n) {\n // 获取数据库实例,优先使用模拟数据库(用于测试),否则使用uniCloud数据库\n const db = options?._mockDatabase || uniCloud.database();\n return useRequest(async (...inputs: I) => {\n const { result } = await caller(db, ...inputs);\n if (!result.errCode) return result;\n throw new Error(result.errMsg || '请求失败');\n }, options);\n}\n"],"names":["options"],"mappings":";AA6BgB,SAAA,qBAAqB,YAAiC,SAAuC;AAC3G,QAAM,UAAS,mCAAS,gBAAe,SAAS,aAAa,YAAY,OAAO;AAOzE,SAAA,SAAS,eACd,QACAA,UACA;AAEO,WAAA,WAAW,UAAU,WAAc;AACxC,YAAM,SAAS,MAAM,OAAO,QAAQ,GAAG,MAAM;AAC7C,UAAI,CAAC,OAAO,QAAS,QAAO,OAAO;AACnC,YAAM,IAAI,MAAM,OAAO,UAAU,MAAM;AAAA,OACtCA,QAAO;AAAA,EACZ;AACF;AAuBgB,SAAA,iBACd,QACA,SACA;AAEA,QAAM,MAAK,mCAAS,kBAAiB,SAAS,SAAS;AAChD,SAAA,WAAW,UAAU,WAAc;AACxC,UAAM,EAAE,OAAO,IAAI,MAAM,OAAO,IAAI,GAAG,MAAM;AACzC,QAAA,CAAC,OAAO,QAAgB,QAAA;AAC5B,UAAM,IAAI,MAAM,OAAO,UAAU,MAAM;AAAA,KACtC,OAAO;AACZ;"}
package/dist/index.cjs ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const VERSION = "1.1.2";
4
+ exports.VERSION = VERSION;
5
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["export const VERSION = PKG_VERSION;\n"],"names":[],"mappings":";;AAAO,MAAM,UAAU;;"}
@@ -0,0 +1 @@
1
+ export declare const VERSION: string;
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ const VERSION = "1.1.2";
2
+ export {
3
+ VERSION
4
+ };
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["export const VERSION = PKG_VERSION;\n"],"names":[],"mappings":"AAAO,MAAM,UAAU;"}
package/dist/page.cjs ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const uniApp = require("@dcloudio/uni-app");
4
+ const vue = require("vue");
5
+ function usePageQuery(onPageLoad) {
6
+ const query = vue.reactive({});
7
+ uniApp.onLoad((_query) => {
8
+ Object.assign(query, _query);
9
+ onPageLoad == null ? void 0 : onPageLoad(query);
10
+ });
11
+ return query;
12
+ }
13
+ exports.usePageQuery = usePageQuery;
14
+ //# sourceMappingURL=page.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.cjs","sources":["../src/page.ts"],"sourcesContent":["import type { AnyObject } from '@cloudcome/utils-core/types';\nimport { onLoad } from '@dcloudio/uni-app';\nimport { type Reactive, reactive, unref } from 'vue';\n\n/**\n * 用于获取页面参数的 hook 函数\n * @template T - 页面参数对象的类型,继承自 AnyObject\n * @param {function} [onPageLoad] - 页面加载时的回调函数\n * @param {T} onLoad.query - 页面参数对象\n * @returns {T} 响应式的页面参数对象\n * @example\n * // 基本用法\n * const query = usePageQuery();\n *\n * // 带回调的用法\n * const query = usePageQuery((query) => {\n * console.log('页面参数:', query);\n * });\n *\n * // 指定参数类型\n * interface PageParams {\n * id: string;\n * name?: string;\n * }\n * const query = usePageQuery<PageParams>();\n */\nexport function usePageQuery<T extends AnyObject>(onPageLoad?: (query: Reactive<T>) => void) {\n const query = reactive<T>({} as T);\n\n onLoad((_query) => {\n Object.assign(query, _query);\n onPageLoad?.(query);\n });\n\n return query;\n}\n"],"names":["reactive","onLoad"],"mappings":";;;;AA0BO,SAAS,aAAkC,YAA2C;AACrF,QAAA,QAAQA,IAAY,SAAA,EAAO;AAEjCC,SAAA,OAAO,CAAC,WAAW;AACV,WAAA,OAAO,OAAO,MAAM;AAC3B,6CAAa;AAAA,EAAK,CACnB;AAEM,SAAA;AACT;;"}
@@ -1,7 +1,5 @@
1
- import type { AnyObject } from '@cloudcome/utils-core/types';
2
- import { onLoad } from '@dcloudio/uni-app';
3
- import { type Reactive, reactive, unref } from 'vue';
4
-
1
+ import { AnyObject } from '@cloudcome/utils-core/types';
2
+ import { Reactive } from 'vue';
5
3
  /**
6
4
  * 用于获取页面参数的 hook 函数
7
5
  * @template T - 页面参数对象的类型,继承自 AnyObject
@@ -24,13 +22,4 @@ import { type Reactive, reactive, unref } from 'vue';
24
22
  * }
25
23
  * const query = usePageQuery<PageParams>();
26
24
  */
27
- export function usePageQuery<T extends AnyObject>(onPageLoad?: (query: Reactive<T>) => void) {
28
- const query = reactive<T>({} as T);
29
-
30
- onLoad((_query) => {
31
- Object.assign(query, _query);
32
- onPageLoad?.(query);
33
- });
34
-
35
- return query;
36
- }
25
+ export declare function usePageQuery<T extends AnyObject>(onPageLoad?: (query: Reactive<T>) => void): Reactive<T>;
package/dist/page.mjs ADDED
@@ -0,0 +1,14 @@
1
+ import { onLoad } from "@dcloudio/uni-app";
2
+ import { reactive } from "vue";
3
+ function usePageQuery(onPageLoad) {
4
+ const query = reactive({});
5
+ onLoad((_query) => {
6
+ Object.assign(query, _query);
7
+ onPageLoad == null ? void 0 : onPageLoad(query);
8
+ });
9
+ return query;
10
+ }
11
+ export {
12
+ usePageQuery
13
+ };
14
+ //# sourceMappingURL=page.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.mjs","sources":["../src/page.ts"],"sourcesContent":["import type { AnyObject } from '@cloudcome/utils-core/types';\nimport { onLoad } from '@dcloudio/uni-app';\nimport { type Reactive, reactive, unref } from 'vue';\n\n/**\n * 用于获取页面参数的 hook 函数\n * @template T - 页面参数对象的类型,继承自 AnyObject\n * @param {function} [onPageLoad] - 页面加载时的回调函数\n * @param {T} onLoad.query - 页面参数对象\n * @returns {T} 响应式的页面参数对象\n * @example\n * // 基本用法\n * const query = usePageQuery();\n *\n * // 带回调的用法\n * const query = usePageQuery((query) => {\n * console.log('页面参数:', query);\n * });\n *\n * // 指定参数类型\n * interface PageParams {\n * id: string;\n * name?: string;\n * }\n * const query = usePageQuery<PageParams>();\n */\nexport function usePageQuery<T extends AnyObject>(onPageLoad?: (query: Reactive<T>) => void) {\n const query = reactive<T>({} as T);\n\n onLoad((_query) => {\n Object.assign(query, _query);\n onPageLoad?.(query);\n });\n\n return query;\n}\n"],"names":[],"mappings":";;AA0BO,SAAS,aAAkC,YAA2C;AACrF,QAAA,QAAQ,SAAY,EAAO;AAEjC,SAAO,CAAC,WAAW;AACV,WAAA,OAAO,OAAO,MAAM;AAC3B,6CAAa;AAAA,EAAK,CACnB;AAEM,SAAA;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcome/utils-uni",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "cloudcome utils for uni-app",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -14,6 +14,11 @@
14
14
  "require": "./dist/index.cjs"
15
15
  },
16
16
  "./package.json": "./package.json",
17
+ "./cloud": {
18
+ "types": "./dist/cloud.d.ts",
19
+ "import": "./dist/cloud.mjs",
20
+ "require": "./dist/cloud.cjs"
21
+ },
17
22
  "./page": {
18
23
  "types": "./dist/page.d.ts",
19
24
  "import": "./dist/page.mjs",
@@ -22,6 +27,9 @@
22
27
  },
23
28
  "typesVersions": {
24
29
  "*": {
30
+ "cloud": [
31
+ "./dist/cloud.d.ts"
32
+ ],
25
33
  "page": [
26
34
  "./dist/page.d.ts"
27
35
  ]
@@ -30,12 +38,19 @@
30
38
  "main": "./dist/index.cjs",
31
39
  "module": "./dist/index.mjs",
32
40
  "types": "./dist/index.d.ts",
41
+ "files": [
42
+ "dist"
43
+ ],
33
44
  "dependencies": {
34
- "@cloudcome/utils-core": "1.1.1",
35
- "@dcloudio/uni-app": "3.0.0-4060620250520001",
45
+ "@cloudcome/utils-core": "~1.2.1",
46
+ "@cloudcome/utils-vue": "~1.4.0",
47
+ "@dcloudio/uni-app": "vue3",
36
48
  "vue": "^3.5.13"
37
49
  },
38
- "repository": "https://github.com/cloudcome/utils",
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/cloudcome/utils.git"
53
+ },
39
54
  "keywords": [
40
55
  "utils",
41
56
  "cloudcome",
package/CHANGELOG.md DELETED
@@ -1,14 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [1.1.1](https://github.com/cloudcome/utils/compare/@cloudcome/utils-uni@1.1.0...@cloudcome/utils-uni@1.1.1) (2025-08-30)
7
-
8
- **Note:** Version bump only for package @cloudcome/utils-uni
9
-
10
- # 1.1.0 (2025-08-27)
11
-
12
- ### Features
13
-
14
- * **utils-uni:** 添加 usePageQuery hook 函数 ([3e35818](https://github.com/cloudcome/utils/commit/3e358189ce0f68b538c95f710478f864a1cd0182))
@@ -1,27 +0,0 @@
1
- /**
2
- * @file global.d.ts
3
- */
4
-
5
- /**
6
- * package.json name
7
- */
8
- declare const PKG_NAME: string;
9
-
10
- /**
11
- * package.json version
12
- */
13
- declare const PKG_VERSION: string;
14
-
15
- /**
16
- * package.json description
17
- */
18
- declare const PKG_DESCRIPTION: string;
19
-
20
- declare const IS_TEST: string;
21
-
22
- interface TEST_MOCK {
23
- IS_BROWSER: boolean;
24
- IS_NODE: boolean;
25
- }
26
-
27
- declare const TEST_MOCK: TEST_MOCK;
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export const VERSION = PKG_VERSION;
@@ -1,6 +0,0 @@
1
- import { VERSION } from '@/index';
2
- import { expect, it } from 'vitest';
3
-
4
- it('version', () => {
5
- expect(VERSION).toEqual(PKG_VERSION);
6
- });
package/test/page.test.ts DELETED
@@ -1,53 +0,0 @@
1
- import { onLoad } from '@dcloudio/uni-app';
2
- import { describe, expect, it, vi } from 'vitest';
3
- import { isReactive } from 'vue';
4
- import { usePageQuery } from '../src/page';
5
-
6
- beforeAll(() => {
7
- vi.mock('@dcloudio/uni-app');
8
- });
9
-
10
- afterAll(() => {
11
- vi.restoreAllMocks();
12
- });
13
-
14
- describe('usePageQuery', () => {
15
- it('应该正确获取页面参数', () => {
16
- // 模拟 uni-app 的 onLoad 函数
17
- const mockOnLoad = vi.fn();
18
- vi.mocked(onLoad).mockImplementation(mockOnLoad);
19
-
20
- // 调用 hook
21
- const query = usePageQuery();
22
-
23
- // 触发模拟的 onLoad 回调
24
- const pageParams = { id: '123', name: 'test' };
25
- mockOnLoad.mock.calls[0][0](pageParams);
26
-
27
- // 验证结果
28
- expect(query).toEqual(pageParams);
29
- });
30
-
31
- it('应该正确执行传入的 onLoad 回调', () => {
32
- const mockCallback = vi.fn();
33
- const mockOnLoad = vi.fn();
34
- vi.mocked(onLoad).mockImplementation(mockOnLoad);
35
-
36
- // 调用 hook 并传入回调
37
- usePageQuery(mockCallback);
38
-
39
- // 触发模拟的 onLoad 回调
40
- const pageParams = { id: '123' };
41
- mockOnLoad.mock.calls[0][0](pageParams);
42
-
43
- // 验证回调被执行
44
- expect(mockCallback).toHaveBeenCalledWith(pageParams);
45
- });
46
-
47
- it('返回的 query 应该是响应式对象', () => {
48
- const query = usePageQuery();
49
-
50
- // 验证响应性
51
- expect(isReactive(query)).toBe(true);
52
- });
53
- });
package/tsconfig.json DELETED
@@ -1,31 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "jsx": "preserve",
4
- "jsxImportSource": "vue",
5
- "target": "ES2024",
6
- "module": "ESNext",
7
- "moduleResolution": "bundler",
8
-
9
- "strict": true,
10
- "noEmit": true,
11
- "allowJs": true,
12
- "sourceMap": true,
13
- "skipLibCheck": true,
14
- "esModuleInterop": true,
15
- "resolveJsonModule": true,
16
- "verbatimModuleSyntax": true,
17
- "allowImportingTsExtensions": false,
18
- "allowSyntheticDefaultImports": true,
19
- "forceConsistentCasingInFileNames": true,
20
-
21
- "lib": ["ES2024"],
22
- "types": ["node", "vite/client", "vitest/globals"],
23
- "plugins": [],
24
- "paths": {
25
- "@/*": ["./src/*"]
26
- }
27
- },
28
-
29
- "include": ["**/*.ts", "**/.*.ts", "**/*.mts", "**/*.tsx", "**/*.vue"],
30
- "exclude": []
31
- }
package/vite.config.mts DELETED
@@ -1,84 +0,0 @@
1
- /**
2
- * @file vite.config.mts
3
- * @ref https://vitejs.dev/
4
- */
5
-
6
- import dts from 'vite-plugin-dts';
7
- import { externalizeDeps } from 'vite-plugin-externalize-deps';
8
- import tsconfigPaths from 'vite-tsconfig-paths';
9
- import { defineConfig } from 'vitest/config';
10
- import pkg from './package.json';
11
-
12
- export default defineConfig((env) => {
13
- const isProd = env.mode === 'production';
14
- const isTest = env.mode === 'test';
15
-
16
- return {
17
- base: '/',
18
- server: {
19
- port: 15170,
20
- },
21
- preview: {
22
- port: 15171,
23
- },
24
- define: {
25
- PKG_NAME: JSON.stringify(isTest ? 'pkg-name-for-test' : pkg.name),
26
- PKG_VERSION: JSON.stringify(isTest ? 'pkg-version-for-test' : pkg.version),
27
- PKG_DESCRIPTION: JSON.stringify(isTest ? 'pkg-description-for-test' : pkg.description),
28
- IS_TEST: JSON.stringify(isTest),
29
- },
30
- build: {
31
- minify: false,
32
- sourcemap: true,
33
- copyPublicDir: false,
34
- reportCompressedSize: false,
35
- lib: {
36
- entry:
37
- // expose-start
38
- {
39
- index: 'src/index.ts',
40
- page: './src/page.ts',
41
- },
42
- // expose-end
43
- },
44
- rollupOptions: {
45
- output: [
46
- {
47
- format: 'esm',
48
- entryFileNames: '[name].mjs',
49
- chunkFileNames: '[name].mjs',
50
- },
51
- {
52
- format: 'cjs',
53
- entryFileNames: '[name].cjs',
54
- chunkFileNames: '[name].cjs',
55
- },
56
- ],
57
- },
58
- },
59
- test: {
60
- globals: true,
61
- coverage: {
62
- all: true,
63
- include: ['src/**/*.ts'],
64
- reporter: ['lcov', 'text'],
65
- },
66
- },
67
- // esbuild: {
68
- // drop: isProd ? ['console', 'debugger'] : [],
69
- // },
70
- plugins: [
71
- tsconfigPaths(),
72
- externalizeDeps({
73
- deps: true,
74
- devDeps: true,
75
- peerDeps: true,
76
- optionalDeps: true,
77
- nodeBuiltins: true,
78
- }),
79
- dts({
80
- include: 'src',
81
- }),
82
- ],
83
- };
84
- });