@cloudcome/utils-uni 1.1.0 → 1.1.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
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))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ☁️淡然
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1 +1,52 @@
1
- {"name":"@cloudcome/utils-uni","version":"1.1.0","description":"cloudcome utils for uni-app","engines":{"node":">=22"},"engineStrict":true,"sideEffects":false,"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"},"./package.json":"./package.json","./page":{"types":"./dist/page.d.ts","import":"./dist/page.mjs","require":"./dist/page.cjs"}},"typesVersions":{"*":{"page":["./dist/page.d.ts"]}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","files":["dist"],"repository":{"url":"https://github.com/cloudcome/utils","directory":"packages/utils-uni"},"dependencies":{"@cloudcome/utils-core":"1.1.0","@dcloudio/uni-app":"3.0.0-4060620250520001","vue":"^3.5.13"}}
1
+ {
2
+ "name": "@cloudcome/utils-uni",
3
+ "version": "1.1.1",
4
+ "description": "cloudcome utils for uni-app",
5
+ "engines": {
6
+ "node": ">=22"
7
+ },
8
+ "engineStrict": true,
9
+ "sideEffects": false,
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.cjs"
15
+ },
16
+ "./package.json": "./package.json",
17
+ "./page": {
18
+ "types": "./dist/page.d.ts",
19
+ "import": "./dist/page.mjs",
20
+ "require": "./dist/page.cjs"
21
+ }
22
+ },
23
+ "typesVersions": {
24
+ "*": {
25
+ "page": [
26
+ "./dist/page.d.ts"
27
+ ]
28
+ }
29
+ },
30
+ "main": "./dist/index.cjs",
31
+ "module": "./dist/index.mjs",
32
+ "types": "./dist/index.d.ts",
33
+ "dependencies": {
34
+ "@cloudcome/utils-core": "1.1.1",
35
+ "@dcloudio/uni-app": "3.0.0-4060620250520001",
36
+ "vue": "^3.5.13"
37
+ },
38
+ "repository": "https://github.com/cloudcome/utils",
39
+ "keywords": [
40
+ "utils",
41
+ "cloudcome",
42
+ "utils-core",
43
+ "utils-vue",
44
+ "utils-react",
45
+ "utils-uni",
46
+ "utils-node",
47
+ "utils-browser"
48
+ ],
49
+ "homepage": "https://github.com/cloudcome/utils",
50
+ "license": "MIT",
51
+ "author": "云淡然 <hi@ydr.me> (https://ydr.me/)"
52
+ }
@@ -0,0 +1,27 @@
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 ADDED
@@ -0,0 +1 @@
1
+ export const VERSION = PKG_VERSION;
@@ -1,5 +1,7 @@
1
- import { AnyObject } from '@cloudcome/utils-core/types';
2
- import { Reactive } from 'vue';
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
+
3
5
  /**
4
6
  * 用于获取页面参数的 hook 函数
5
7
  * @template T - 页面参数对象的类型,继承自 AnyObject
@@ -22,4 +24,13 @@ import { Reactive } from 'vue';
22
24
  * }
23
25
  * const query = usePageQuery<PageParams>();
24
26
  */
25
- export declare function usePageQuery<T extends AnyObject>(onPageLoad?: (query: Reactive<T>) => void): Reactive<T>;
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
+ }
@@ -0,0 +1,6 @@
1
+ import { VERSION } from '@/index';
2
+ import { expect, it } from 'vitest';
3
+
4
+ it('version', () => {
5
+ expect(VERSION).toEqual(PKG_VERSION);
6
+ });
@@ -0,0 +1,53 @@
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 ADDED
@@ -0,0 +1,31 @@
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
+ }
@@ -0,0 +1,84 @@
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
+ });
package/dist/index.cjs DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const VERSION = "1.1.0";
4
- exports.VERSION = VERSION;
5
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["export const VERSION = PKG_VERSION;\n"],"names":[],"mappings":";;AAAO,MAAM,UAAU;;"}
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const VERSION: string;
package/dist/index.mjs DELETED
@@ -1,5 +0,0 @@
1
- const VERSION = "1.1.0";
2
- export {
3
- VERSION
4
- };
5
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
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 DELETED
@@ -1,14 +0,0 @@
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
package/dist/page.cjs.map DELETED
@@ -1 +0,0 @@
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;;"}
package/dist/page.mjs DELETED
@@ -1,14 +0,0 @@
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
package/dist/page.mjs.map DELETED
@@ -1 +0,0 @@
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;"}