@hlw-uni-mp/use 1.1.3 → 1.1.5

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.d.mts CHANGED
@@ -1,64 +1,6 @@
1
1
  import * as pinia from 'pinia';
2
2
  import { App, Ref, ComputedRef } from 'vue';
3
3
 
4
- /**
5
- * 具有消息提示属性的响应体对象
6
- */
7
- interface ToastRes {
8
- /** 提示文案 */
9
- msg?: string;
10
- /** 是否为模态弹窗 */
11
- modal?: boolean;
12
- /** 模态弹窗配置 */
13
- modalOptions?: UniApp.ShowModalOptions;
14
- }
15
- /**
16
- * 提示回调函数类型 (confirm 为 true 表示确定,false 为取消)
17
- */
18
- type ToastCallback = (confirm: boolean) => void;
19
- /**
20
- * 消息门面体
21
- */
22
- interface HlwMsg {
23
- /** 显示轻提示或模态确认框 (支持回调与 Promise) */
24
- toast(opts: UniApp.ShowToastOptions | ToastRes | string, callback?: ToastCallback): Promise<boolean>;
25
- /** 成功提示框 */
26
- success(msg: string): void;
27
- /** 失败提示框 */
28
- error(msg: string): void;
29
- /** 显全局加载 */
30
- showLoading(msg?: string): void;
31
- /** 隐全局加载 */
32
- hideLoading(): void;
33
- /** 弹出确认框 */
34
- modal(opts?: UniApp.ShowModalOptions): Promise<boolean>;
35
- /** 标题进度条 */
36
- setLoadingBar(progress: number): void;
37
- }
38
- /**
39
- * 统一的消息提示与弹窗能力 hook。
40
- *
41
- * @example
42
- * ```ts
43
- * const msg = useMsg();
44
- * msg.toast('操作成功');
45
- * msg.toast(res, (confirm) => {
46
- * if (confirm) console.log('点击确定');
47
- * else console.log('点击取消');
48
- * });
49
- * const ok = await msg.modal({ content: '确定删除吗?' });
50
- * ```
51
- */
52
- declare function useMsg(): HlwMsg;
53
- /**
54
- * 全局提示单例门面
55
- */
56
- declare const hlw: {
57
- /** 统一提示门面 */
58
- readonly $msg: HlwMsg;
59
- };
60
- type HlwInstance = typeof hlw;
61
-
62
4
  declare module "pinia" {
63
5
  interface DefineStoreOptionsBase<S, Store> {
64
6
  /** 本地持久化配置 */
@@ -192,26 +134,6 @@ declare function useTheme(): {
192
134
  }, {}, {}>;
193
135
  };
194
136
 
195
- /**
196
- * 分享卡片配置项
197
- */
198
- interface ShareConfig {
199
- /** 分享标题 */
200
- title?: string;
201
- /** 分享页面路径 */
202
- path?: string;
203
- /** 分享卡片封面图 */
204
- imageUrl?: string;
205
- }
206
- /**
207
- * 显式调起分享菜单
208
- */
209
- declare function showShareMenu(): void;
210
- /**
211
- * 分享组合式函数
212
- */
213
- declare function useShare(config?: ShareConfig): void;
214
-
215
137
  /**
216
138
  * useRefs - 模板 Ref 批量管理
217
139
  *
@@ -244,4 +166,4 @@ interface UseRefsReturn<T = unknown> {
244
166
  */
245
167
  declare function useRefs<T = unknown>(): UseRefsReturn<T>;
246
168
 
247
- export { DEFAULT_THEME, type FontFamily, type FontFamilyPreset, type FontSize, type FontSizePreset, type HlwInstance, type HlwMsg, type InitThemeOptions, type ShareConfig, THEME_COLORS, type ThemeColor, type ThemeMode, type ThemeState, type ToastCallback, type ToastRes, type UseRefsReturn, applyTheme, fontFamilyPresets, fontSizePresets, getTheme, hlw, initTheme, showShareMenu, useMsg, useRefs, useShare, useTheme, useThemeStore };
169
+ export { DEFAULT_THEME, type FontFamily, type FontFamilyPreset, type FontSize, type FontSizePreset, type InitThemeOptions, THEME_COLORS, type ThemeColor, type ThemeMode, type ThemeState, type UseRefsReturn, applyTheme, fontFamilyPresets, fontSizePresets, getTheme, initTheme, useRefs, useTheme, useThemeStore };
package/dist/index.d.ts CHANGED
@@ -1,64 +1,6 @@
1
1
  import * as pinia from 'pinia';
2
2
  import { App, Ref, ComputedRef } from 'vue';
3
3
 
4
- /**
5
- * 具有消息提示属性的响应体对象
6
- */
7
- interface ToastRes {
8
- /** 提示文案 */
9
- msg?: string;
10
- /** 是否为模态弹窗 */
11
- modal?: boolean;
12
- /** 模态弹窗配置 */
13
- modalOptions?: UniApp.ShowModalOptions;
14
- }
15
- /**
16
- * 提示回调函数类型 (confirm 为 true 表示确定,false 为取消)
17
- */
18
- type ToastCallback = (confirm: boolean) => void;
19
- /**
20
- * 消息门面体
21
- */
22
- interface HlwMsg {
23
- /** 显示轻提示或模态确认框 (支持回调与 Promise) */
24
- toast(opts: UniApp.ShowToastOptions | ToastRes | string, callback?: ToastCallback): Promise<boolean>;
25
- /** 成功提示框 */
26
- success(msg: string): void;
27
- /** 失败提示框 */
28
- error(msg: string): void;
29
- /** 显全局加载 */
30
- showLoading(msg?: string): void;
31
- /** 隐全局加载 */
32
- hideLoading(): void;
33
- /** 弹出确认框 */
34
- modal(opts?: UniApp.ShowModalOptions): Promise<boolean>;
35
- /** 标题进度条 */
36
- setLoadingBar(progress: number): void;
37
- }
38
- /**
39
- * 统一的消息提示与弹窗能力 hook。
40
- *
41
- * @example
42
- * ```ts
43
- * const msg = useMsg();
44
- * msg.toast('操作成功');
45
- * msg.toast(res, (confirm) => {
46
- * if (confirm) console.log('点击确定');
47
- * else console.log('点击取消');
48
- * });
49
- * const ok = await msg.modal({ content: '确定删除吗?' });
50
- * ```
51
- */
52
- declare function useMsg(): HlwMsg;
53
- /**
54
- * 全局提示单例门面
55
- */
56
- declare const hlw: {
57
- /** 统一提示门面 */
58
- readonly $msg: HlwMsg;
59
- };
60
- type HlwInstance = typeof hlw;
61
-
62
4
  declare module "pinia" {
63
5
  interface DefineStoreOptionsBase<S, Store> {
64
6
  /** 本地持久化配置 */
@@ -192,26 +134,6 @@ declare function useTheme(): {
192
134
  }, {}, {}>;
193
135
  };
194
136
 
195
- /**
196
- * 分享卡片配置项
197
- */
198
- interface ShareConfig {
199
- /** 分享标题 */
200
- title?: string;
201
- /** 分享页面路径 */
202
- path?: string;
203
- /** 分享卡片封面图 */
204
- imageUrl?: string;
205
- }
206
- /**
207
- * 显式调起分享菜单
208
- */
209
- declare function showShareMenu(): void;
210
- /**
211
- * 分享组合式函数
212
- */
213
- declare function useShare(config?: ShareConfig): void;
214
-
215
137
  /**
216
138
  * useRefs - 模板 Ref 批量管理
217
139
  *
@@ -244,4 +166,4 @@ interface UseRefsReturn<T = unknown> {
244
166
  */
245
167
  declare function useRefs<T = unknown>(): UseRefsReturn<T>;
246
168
 
247
- export { DEFAULT_THEME, type FontFamily, type FontFamilyPreset, type FontSize, type FontSizePreset, type HlwInstance, type HlwMsg, type InitThemeOptions, type ShareConfig, THEME_COLORS, type ThemeColor, type ThemeMode, type ThemeState, type ToastCallback, type ToastRes, type UseRefsReturn, applyTheme, fontFamilyPresets, fontSizePresets, getTheme, hlw, initTheme, showShareMenu, useMsg, useRefs, useShare, useTheme, useThemeStore };
169
+ export { DEFAULT_THEME, type FontFamily, type FontFamilyPreset, type FontSize, type FontSizePreset, type InitThemeOptions, THEME_COLORS, type ThemeColor, type ThemeMode, type ThemeState, type UseRefsReturn, applyTheme, fontFamilyPresets, fontSizePresets, getTheme, initTheme, useRefs, useTheme, useThemeStore };
package/dist/index.js CHANGED
@@ -26,121 +26,13 @@ __export(index_exports, {
26
26
  fontFamilyPresets: () => fontFamilyPresets,
27
27
  fontSizePresets: () => fontSizePresets,
28
28
  getTheme: () => getTheme,
29
- hlw: () => hlw,
30
29
  initTheme: () => initTheme,
31
- showShareMenu: () => showShareMenu,
32
- useMsg: () => useMsg,
33
30
  useRefs: () => useRefs,
34
- useShare: () => useShare,
35
31
  useTheme: () => useTheme,
36
32
  useThemeStore: () => useThemeStore
37
33
  });
38
34
  module.exports = __toCommonJS(index_exports);
39
35
 
40
- // src/msg/index.ts
41
- function useMsg() {
42
- function toast(opts, callback) {
43
- let msg = "";
44
- let isModal = false;
45
- let modalOptions;
46
- let toastOptions;
47
- if (typeof opts === "string") {
48
- msg = opts;
49
- } else if ("msg" in opts) {
50
- msg = opts.msg || "";
51
- isModal = !!opts.modal;
52
- modalOptions = opts.modalOptions;
53
- } else if ("title" in opts) {
54
- msg = opts.title || "";
55
- toastOptions = opts;
56
- }
57
- if (!msg) {
58
- callback?.(true);
59
- return Promise.resolve(true);
60
- }
61
- if (isModal) {
62
- return modal({
63
- ...modalOptions,
64
- content: msg
65
- }).then((confirm) => {
66
- callback?.(confirm);
67
- return confirm;
68
- });
69
- }
70
- uni.showToast({
71
- title: msg,
72
- icon: toastOptions?.icon || "none",
73
- image: toastOptions?.image,
74
- duration: toastOptions?.duration || 2e3,
75
- mask: toastOptions?.mask || false,
76
- position: toastOptions?.position || "center"
77
- });
78
- callback?.(true);
79
- return Promise.resolve(true);
80
- }
81
- function success(msg) {
82
- if (!msg) return;
83
- uni.showToast({ title: msg, icon: "success", duration: 2e3 });
84
- }
85
- function error(msg) {
86
- if (!msg) return;
87
- uni.showToast({ title: msg, icon: "error", duration: 2e3 });
88
- }
89
- function showLoading(msg = "\u52A0\u8F7D\u4E2D...") {
90
- uni.showLoading({ title: msg, mask: true });
91
- }
92
- function hideLoading() {
93
- uni.hideLoading();
94
- }
95
- function modal(opts = {}) {
96
- return new Promise((resolve) => {
97
- const {
98
- title = "\u63D0\u793A",
99
- content,
100
- confirmText = "\u786E\u5B9A",
101
- cancelText = "\u53D6\u6D88",
102
- confirmColor = "#3b82f6",
103
- cancelColor = "#999999",
104
- showCancel = true
105
- } = opts || {};
106
- uni.showModal({
107
- title,
108
- content,
109
- confirmText,
110
- cancelText,
111
- confirmColor,
112
- cancelColor,
113
- showCancel,
114
- success: (res) => resolve(res.confirm),
115
- fail: () => resolve(false)
116
- });
117
- });
118
- }
119
- function setLoadingBar(progress) {
120
- const clamped = Math.max(0, Math.min(100, progress));
121
- const filled = Math.round(clamped / 2);
122
- uni.setNavigationBarTitle({
123
- title: `${"\u25A0".repeat(filled)}${"\u25A1".repeat(50 - filled)} ${clamped}%`
124
- });
125
- }
126
- return {
127
- toast,
128
- success,
129
- error,
130
- showLoading,
131
- hideLoading,
132
- modal,
133
- setLoadingBar
134
- };
135
- }
136
- var _msg = null;
137
- var hlw = {
138
- /** 统一提示门面 */
139
- get $msg() {
140
- return _msg ?? (_msg = useMsg());
141
- }
142
- };
143
-
144
36
  // src/theme/index.ts
145
37
  var import_vue = require("vue");
146
38
 
@@ -307,24 +199,6 @@ function useTheme() {
307
199
  };
308
200
  }
309
201
 
310
- // src/share/index.ts
311
- var import_uni_app = require("@dcloudio/uni-app");
312
- function showShareMenu() {
313
- uni.showShareMenu({
314
- withShareTicket: true,
315
- menus: ["shareAppMessage", "shareTimeline"]
316
- });
317
- }
318
- function useShare(config = {}) {
319
- showShareMenu();
320
- (0, import_uni_app.onShareAppMessage)(() => ({ ...config }));
321
- (0, import_uni_app.onShareTimeline)(() => ({
322
- title: config.title,
323
- query: config.path?.split("?")[1],
324
- imageUrl: config.imageUrl
325
- }));
326
- }
327
-
328
202
  // src/refs/index.ts
329
203
  var import_vue2 = require("vue");
330
204
  function useRefs() {
@@ -348,12 +222,8 @@ function useRefs() {
348
222
  fontFamilyPresets,
349
223
  fontSizePresets,
350
224
  getTheme,
351
- hlw,
352
225
  initTheme,
353
- showShareMenu,
354
- useMsg,
355
226
  useRefs,
356
- useShare,
357
227
  useTheme,
358
228
  useThemeStore
359
229
  });
package/dist/index.mjs CHANGED
@@ -1,107 +1,3 @@
1
- // src/msg/index.ts
2
- function useMsg() {
3
- function toast(opts, callback) {
4
- let msg = "";
5
- let isModal = false;
6
- let modalOptions;
7
- let toastOptions;
8
- if (typeof opts === "string") {
9
- msg = opts;
10
- } else if ("msg" in opts) {
11
- msg = opts.msg || "";
12
- isModal = !!opts.modal;
13
- modalOptions = opts.modalOptions;
14
- } else if ("title" in opts) {
15
- msg = opts.title || "";
16
- toastOptions = opts;
17
- }
18
- if (!msg) {
19
- callback?.(true);
20
- return Promise.resolve(true);
21
- }
22
- if (isModal) {
23
- return modal({
24
- ...modalOptions,
25
- content: msg
26
- }).then((confirm) => {
27
- callback?.(confirm);
28
- return confirm;
29
- });
30
- }
31
- uni.showToast({
32
- title: msg,
33
- icon: toastOptions?.icon || "none",
34
- image: toastOptions?.image,
35
- duration: toastOptions?.duration || 2e3,
36
- mask: toastOptions?.mask || false,
37
- position: toastOptions?.position || "center"
38
- });
39
- callback?.(true);
40
- return Promise.resolve(true);
41
- }
42
- function success(msg) {
43
- if (!msg) return;
44
- uni.showToast({ title: msg, icon: "success", duration: 2e3 });
45
- }
46
- function error(msg) {
47
- if (!msg) return;
48
- uni.showToast({ title: msg, icon: "error", duration: 2e3 });
49
- }
50
- function showLoading(msg = "\u52A0\u8F7D\u4E2D...") {
51
- uni.showLoading({ title: msg, mask: true });
52
- }
53
- function hideLoading() {
54
- uni.hideLoading();
55
- }
56
- function modal(opts = {}) {
57
- return new Promise((resolve) => {
58
- const {
59
- title = "\u63D0\u793A",
60
- content,
61
- confirmText = "\u786E\u5B9A",
62
- cancelText = "\u53D6\u6D88",
63
- confirmColor = "#3b82f6",
64
- cancelColor = "#999999",
65
- showCancel = true
66
- } = opts || {};
67
- uni.showModal({
68
- title,
69
- content,
70
- confirmText,
71
- cancelText,
72
- confirmColor,
73
- cancelColor,
74
- showCancel,
75
- success: (res) => resolve(res.confirm),
76
- fail: () => resolve(false)
77
- });
78
- });
79
- }
80
- function setLoadingBar(progress) {
81
- const clamped = Math.max(0, Math.min(100, progress));
82
- const filled = Math.round(clamped / 2);
83
- uni.setNavigationBarTitle({
84
- title: `${"\u25A0".repeat(filled)}${"\u25A1".repeat(50 - filled)} ${clamped}%`
85
- });
86
- }
87
- return {
88
- toast,
89
- success,
90
- error,
91
- showLoading,
92
- hideLoading,
93
- modal,
94
- setLoadingBar
95
- };
96
- }
97
- var _msg = null;
98
- var hlw = {
99
- /** 统一提示门面 */
100
- get $msg() {
101
- return _msg ?? (_msg = useMsg());
102
- }
103
- };
104
-
105
1
  // src/theme/index.ts
106
2
  import { computed, toRef } from "vue";
107
3
 
@@ -268,24 +164,6 @@ function useTheme() {
268
164
  };
269
165
  }
270
166
 
271
- // src/share/index.ts
272
- import { onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
273
- function showShareMenu() {
274
- uni.showShareMenu({
275
- withShareTicket: true,
276
- menus: ["shareAppMessage", "shareTimeline"]
277
- });
278
- }
279
- function useShare(config = {}) {
280
- showShareMenu();
281
- onShareAppMessage(() => ({ ...config }));
282
- onShareTimeline(() => ({
283
- title: config.title,
284
- query: config.path?.split("?")[1],
285
- imageUrl: config.imageUrl
286
- }));
287
- }
288
-
289
167
  // src/refs/index.ts
290
168
  import { ref, onBeforeUpdate, onUnmounted } from "vue";
291
169
  function useRefs() {
@@ -308,12 +186,8 @@ export {
308
186
  fontFamilyPresets,
309
187
  fontSizePresets,
310
188
  getTheme,
311
- hlw,
312
189
  initTheme,
313
- showShareMenu,
314
- useMsg,
315
190
  useRefs,
316
- useShare,
317
191
  useTheme,
318
192
  useThemeStore
319
193
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni-mp/use",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Universal Uni-App Vue 3 stateful composables library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",