@hlw-uni/mp-vue 2.1.35 → 2.1.37

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.
@@ -25,13 +25,16 @@ export type TapEvent = {
25
25
  currentTarget?: {
26
26
  dataset?: Record<string, any>;
27
27
  };
28
+ target?: {
29
+ dataset?: Record<string, any>;
30
+ };
28
31
  };
29
32
  /**
30
33
  * 剪贴板、下载与相册保存工具集合。
31
34
  */
32
35
  export declare function useUtils(): {
33
- copy: (data: string, showToast?: boolean) => Promise<boolean>;
34
- copyFromEvent: (event: TapEvent) => void;
36
+ copy: (data: string | TapEvent, showToast?: boolean) => Promise<boolean>;
37
+ copyFromEvent: (event: TapEvent) => Promise<boolean>;
35
38
  paste: () => Promise<string>;
36
39
  saveImage: (filePath: string) => Promise<boolean>;
37
40
  downloadFile: (options: DownloadFileOptions) => Promise<DownloadFileResult>;
@@ -0,0 +1 @@
1
+ export declare function getErrorMessage(error: unknown): string;
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  * UI 组件(hlw-page / hlw-button / hlw-ad 等)走 easycom 自动注册,不在这里 export。
9
9
  */
10
10
  export * from './composables';
11
+ export { getErrorMessage } from './error';
11
12
  export type { HlwMenuItem } from './components/hlw-menu/types';
12
13
  export type { HlwPagingRef, HlwPagingInstance } from './components/hlw-paging/types';
13
14
  export { useThemeStore } from './stores/theme';
package/dist/index.js CHANGED
@@ -973,6 +973,14 @@ var __publicField = (obj, key, value) => {
973
973
  }
974
974
  function useUtils() {
975
975
  function copy(data, showToast = true) {
976
+ var _a, _b;
977
+ if (typeof data !== "string") {
978
+ const dataset = ((_a = data == null ? void 0 : data.currentTarget) == null ? void 0 : _a.dataset) || ((_b = data == null ? void 0 : data.target) == null ? void 0 : _b.dataset);
979
+ const text = dataset == null ? void 0 : dataset.copy;
980
+ if (text == null || text === "")
981
+ return Promise.resolve(false);
982
+ return copy(String(text), (dataset == null ? void 0 : dataset.copyToast) !== "false");
983
+ }
976
984
  return new Promise((resolve) => {
977
985
  uni.setClipboardData({
978
986
  data,
@@ -988,13 +996,7 @@ var __publicField = (obj, key, value) => {
988
996
  });
989
997
  }
990
998
  function copyFromEvent(event) {
991
- var _a;
992
- const dataset = (_a = event == null ? void 0 : event.currentTarget) == null ? void 0 : _a.dataset;
993
- const text = dataset == null ? void 0 : dataset.copy;
994
- if (text == null || text === "")
995
- return;
996
- const showToast = (dataset == null ? void 0 : dataset.copyToast) !== "false";
997
- copy(String(text), showToast);
999
+ return copy(event);
998
1000
  }
999
1001
  function paste() {
1000
1002
  return new Promise((resolve) => {
@@ -1501,6 +1503,13 @@ var __publicField = (obj, key, value) => {
1501
1503
  });
1502
1504
  return { themePageStyle };
1503
1505
  }
1506
+ function getErrorMessage(error) {
1507
+ if (error instanceof Error && error.message)
1508
+ return error.message;
1509
+ if (typeof error === "string" && error)
1510
+ return error;
1511
+ return "查询失败,请稍后重试";
1512
+ }
1504
1513
  let _msg = null;
1505
1514
  let _device = null;
1506
1515
  let _utils = null;
@@ -1943,6 +1952,7 @@ var __publicField = (obj, key, value) => {
1943
1952
  exports2.getCurrentThemeColor = getCurrentThemeColor;
1944
1953
  exports2.getCurrentThemeVars = getCurrentThemeVars;
1945
1954
  exports2.getCurrentTypographyVars = getCurrentTypographyVars;
1955
+ exports2.getErrorMessage = getErrorMessage;
1946
1956
  exports2.hlw = hlw;
1947
1957
  exports2.http = http;
1948
1958
  exports2.ossAdapter = ossAdapter;
package/dist/index.mjs CHANGED
@@ -972,6 +972,14 @@ function useContact() {
972
972
  }
973
973
  function useUtils() {
974
974
  function copy(data, showToast = true) {
975
+ var _a, _b;
976
+ if (typeof data !== "string") {
977
+ const dataset = ((_a = data == null ? void 0 : data.currentTarget) == null ? void 0 : _a.dataset) || ((_b = data == null ? void 0 : data.target) == null ? void 0 : _b.dataset);
978
+ const text = dataset == null ? void 0 : dataset.copy;
979
+ if (text == null || text === "")
980
+ return Promise.resolve(false);
981
+ return copy(String(text), (dataset == null ? void 0 : dataset.copyToast) !== "false");
982
+ }
975
983
  return new Promise((resolve) => {
976
984
  uni.setClipboardData({
977
985
  data,
@@ -987,13 +995,7 @@ function useUtils() {
987
995
  });
988
996
  }
989
997
  function copyFromEvent(event) {
990
- var _a;
991
- const dataset = (_a = event == null ? void 0 : event.currentTarget) == null ? void 0 : _a.dataset;
992
- const text = dataset == null ? void 0 : dataset.copy;
993
- if (text == null || text === "")
994
- return;
995
- const showToast = (dataset == null ? void 0 : dataset.copyToast) !== "false";
996
- copy(String(text), showToast);
998
+ return copy(event);
997
999
  }
998
1000
  function paste() {
999
1001
  return new Promise((resolve) => {
@@ -1500,6 +1502,13 @@ function useThemePageStyle() {
1500
1502
  });
1501
1503
  return { themePageStyle };
1502
1504
  }
1505
+ function getErrorMessage(error) {
1506
+ if (error instanceof Error && error.message)
1507
+ return error.message;
1508
+ if (typeof error === "string" && error)
1509
+ return error;
1510
+ return "查询失败,请稍后重试";
1511
+ }
1503
1512
  let _msg = null;
1504
1513
  let _device = null;
1505
1514
  let _utils = null;
@@ -1943,6 +1952,7 @@ export {
1943
1952
  getCurrentThemeColor,
1944
1953
  getCurrentThemeVars,
1945
1954
  getCurrentTypographyVars,
1955
+ getErrorMessage,
1946
1956
  hlw,
1947
1957
  http,
1948
1958
  ossAdapter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hlw-uni/mp-vue",
3
- "version": "2.1.35",
3
+ "version": "2.1.37",
4
4
  "description": "hlw-uni 小程序运行时 — Vue 组件 + composables + theme + http + 工具集(合并自原 mp-core)",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -88,7 +88,7 @@ const props = withDefaults(defineProps<Props>(), {
88
88
  titleSize: "var(--font-30)",
89
89
  titleColor: "",
90
90
  titleWeight: "",
91
- descSize: "var(--font-xs)",
91
+ descSize: "var(--font-sm)",
92
92
  descColor: "",
93
93
  descWeight: "",
94
94
  divider: false,
@@ -210,18 +210,18 @@ defineOptions({
210
210
  }
211
211
 
212
212
  .hlw-card-header__title {
213
- font-size: var(--font-base);
213
+ font-size: calc(var(--font-base) * 0.9);
214
214
  font-weight: 500;
215
215
  color: var(--text-primary, #1e293b);
216
- letter-spacing: 1rpx;
216
+ letter-spacing: 1rpx;
217
217
  }
218
218
 
219
219
  .hlw-card-header__desc {
220
- padding: 4rpx 16rpx;
220
+ padding: 8rpx 16rpx;
221
221
  border-radius: var(--radius-sm, 8rpx);
222
222
  background: rgba(241, 245, 249, 0.8);
223
223
  color: var(--text-muted, #64748b);
224
- font-size: var(--font-xs);
225
- font-weight: 400;
224
+ font-size: var(--font-sm);
225
+ letter-spacing: 3rpx;
226
226
  }
227
227
  </style>
@@ -24,7 +24,10 @@ export interface DownloadFileResult {
24
24
  errMsg?: string;
25
25
  }
26
26
 
27
- export type TapEvent = { currentTarget?: { dataset?: Record<string, any> } };
27
+ export type TapEvent = {
28
+ currentTarget?: { dataset?: Record<string, any> };
29
+ target?: { dataset?: Record<string, any> };
30
+ };
28
31
 
29
32
  /**
30
33
  * 剪贴板、下载与相册保存工具集合。
@@ -32,8 +35,16 @@ export type TapEvent = { currentTarget?: { dataset?: Record<string, any> } };
32
35
  export function useUtils() {
33
36
  /**
34
37
  * 复制文本到剪贴板,可选显示成功提示。
38
+ * 也可直接作为 tap 事件处理函数,从 data-copy 读取文本。
35
39
  */
36
- function copy(data: string, showToast = true): Promise<boolean> {
40
+ function copy(data: string | TapEvent, showToast = true): Promise<boolean> {
41
+ if (typeof data !== "string") {
42
+ const dataset = data?.currentTarget?.dataset || data?.target?.dataset;
43
+ const text = dataset?.copy;
44
+ if (text == null || text === "") return Promise.resolve(false);
45
+ return copy(String(text), dataset?.copyToast !== "false");
46
+ }
47
+
37
48
  return new Promise((resolve) => {
38
49
  uni.setClipboardData({
39
50
  data,
@@ -53,11 +64,7 @@ export function useUtils() {
53
64
  * 从事件 dataset 的 data-copy 字段读取文本并复制。
54
65
  */
55
66
  function copyFromEvent(event: TapEvent) {
56
- const dataset = event?.currentTarget?.dataset;
57
- const text = dataset?.copy;
58
- if (text == null || text === "") return;
59
- const showToast = dataset?.copyToast !== "false";
60
- copy(String(text), showToast);
67
+ return copy(event);
61
68
  }
62
69
 
63
70
  /**
package/src/error.ts ADDED
@@ -0,0 +1,5 @@
1
+ export function getErrorMessage(error: unknown): string {
2
+ if (error instanceof Error && error.message) return error.message;
3
+ if (typeof error === "string" && error) return error;
4
+ return "查询失败,请稍后重试";
5
+ }
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@
10
10
 
11
11
  // Composables / 工具 / Theme
12
12
  export * from "./composables";
13
+ export { getErrorMessage } from "./error";
13
14
 
14
15
  // 类型
15
16
  export type { HlwMenuItem } from "./components/hlw-menu/types";