@cloudcome/utils-uni 1.1.1 → 1.1.2

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/dist/index.cjs ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const VERSION = "1.1.1";
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.1";
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.1.2",
4
4
  "description": "cloudcome utils for uni-app",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -30,12 +30,18 @@
30
30
  "main": "./dist/index.cjs",
31
31
  "module": "./dist/index.mjs",
32
32
  "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "dist"
35
+ ],
33
36
  "dependencies": {
34
- "@cloudcome/utils-core": "1.1.1",
37
+ "@cloudcome/utils-core": "1.2.0",
35
38
  "@dcloudio/uni-app": "3.0.0-4060620250520001",
36
39
  "vue": "^3.5.13"
37
40
  },
38
- "repository": "https://github.com/cloudcome/utils",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/cloudcome/utils.git"
44
+ },
39
45
  "keywords": [
40
46
  "utils",
41
47
  "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
- });