annil 1.8.3 → 1.10.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +1 -1
  3. package/dist/api/DefineComponent/normalizeOptions/hijackHandle/pagePathCheck.d.ts +2 -0
  4. package/dist/api/DefineComponent/normalizeOptions/hijackHandle/pagePathCheck.js +8 -0
  5. package/dist/api/DefineComponent/normalizeOptions/hijackHandle/pagePathCheck.js.map +1 -0
  6. package/dist/api/DefineComponent/normalizeOptions/index.d.ts +1 -2
  7. package/dist/api/DefineComponent/normalizeOptions/index.js +5 -1
  8. package/dist/api/DefineComponent/normalizeOptions/index.js.map +1 -1
  9. package/dist/api/SubComponent/SubComponentType.d.ts +1 -1
  10. package/dist/api/SubComponent/index.d.ts +9 -1
  11. package/dist/api/SubComponent/index.js.map +1 -1
  12. package/dist/api/{navigateTo.d.ts → wxSugar.d.ts} +11 -1
  13. package/dist/api/{navigateTo.js → wxSugar.js} +34 -2
  14. package/dist/api/wxSugar.js.map +1 -0
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +2 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/thirdLib/wm/index.d.ts +1 -0
  19. package/dist/thirdLib/wm/map.d.ts +201 -0
  20. package/dist/thirdLib/wm/map.js +2 -0
  21. package/dist/thirdLib/wm/map.js.map +1 -0
  22. package/dist/utils/applyDebounceAndThrottle.d.ts +7 -0
  23. package/dist/utils/applyDebounceAndThrottle.js +28 -0
  24. package/dist/utils/applyDebounceAndThrottle.js.map +1 -0
  25. package/dist/utils/debounce.d.ts +5 -3
  26. package/dist/utils/debounce.js +6 -6
  27. package/dist/utils/debounce.js.map +1 -1
  28. package/dist/utils/throttle.js +2 -1
  29. package/dist/utils/throttle.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/api/DefineComponent/normalizeOptions/hijackHandle/pagePathCheck.ts +9 -0
  32. package/src/api/DefineComponent/normalizeOptions/index.ts +8 -4
  33. package/src/api/SubComponent/SubComponentType.ts +1 -0
  34. package/src/api/SubComponent/SubComputed/test/error.test.ts +33 -0
  35. package/src/api/SubComponent/SubComputed/test/normal.test.ts +12 -0
  36. package/src/api/SubComponent/SubData/test/error.test.ts +7 -0
  37. package/src/api/SubComponent/SubStore/test/error.test.ts +15 -3
  38. package/src/api/SubComponent/index.ts +57 -7
  39. package/src/api/{navigateTo.ts → wxSugar.ts} +41 -1
  40. package/src/index.ts +3 -1
  41. package/src/thirdLib/wm/index.ts +2 -0
  42. package/src/thirdLib/wm/map.ts +266 -0
  43. package/src/utils/applyDebounceAndThrottle.ts +31 -0
  44. package/src/utils/debounce.ts +8 -6
  45. package/src/utils/throttle.ts +3 -2
  46. package/dist/api/navigateTo.js.map +0 -1
@@ -2,6 +2,7 @@ import type { Func } from "hry-types/src/Misc/_api";
2
2
  import { BBeforeCreate } from "../../../behaviors/BbeforeCreated";
3
3
  import { BStore } from "../../../behaviors/BStore";
4
4
  import { BthrottleDebounce } from "../../../behaviors/BthrottleDebounce";
5
+ import { applyDebounceAndThrottle } from "../../../utils/applyDebounceAndThrottle";
5
6
  import { isEmptyObject } from "../../../utils/isEmptyObject";
6
7
  import { instanceConfig } from "../../InstanceInject/instanceConfig";
7
8
  import type { ComputedConstraint } from "../../RootComponent/Computed/ComputedConstraint";
@@ -19,6 +20,7 @@ import { hijack } from "./hijackHandle";
19
20
  import { isPageCheck } from "./hijackHandle/isPageCheck";
20
21
  import { loadReceivedDataHandle } from "./hijackHandle/loadReceivedDataHandle";
21
22
  import { onLoadReceivedDataHandle } from "./hijackHandle/onLoadReceivedDataHandle";
23
+ import { pagePathCheck } from "./hijackHandle/pagePathCheck";
22
24
  import { initStore } from "./initStore";
23
25
  import { injectInfoHandler } from "./injectInfoHandler";
24
26
  import { InternalFieldProtection } from "./internalFieldProtection";
@@ -36,8 +38,6 @@ export type OptionsInnerFields = {
36
38
  __throttleDebounce__?: ThrottleDebounce;
37
39
  };
38
40
  methods: {
39
- disposer?: Record<string, Func>;
40
- // computedHandle加入
41
41
  __computedUpdater__?: Func;
42
42
  };
43
43
  };
@@ -55,7 +55,7 @@ export type FinalOptionsOfComponent = {
55
55
  data: DataConstraint & OptionsInnerFields["data"];
56
56
  observers: Record<string, Func>;
57
57
  behaviors: string[];
58
- methods: MethodsConstraint & OptionsInnerFields["methods"];
58
+ methods: MethodsConstraint;
59
59
  externalClasses: string[];
60
60
  pageLifetimes: PageLifetimesOption<false, object>["pageLifetimes"] & {};
61
61
  isPage: boolean;
@@ -66,6 +66,7 @@ export type FinalOptionsOfComponent = {
66
66
  watch: Record<string, Func>;
67
67
  lifetimes: LifetimesConstraint;
68
68
  };
69
+
69
70
  /**
70
71
  * 把DefineComponentOption转化为原生Component API支持的配置
71
72
  * @param defineComponentOption
@@ -129,7 +130,7 @@ export function normalizeOptions(
129
130
  hijack(
130
131
  finalOptionsForComponent.lifetimes,
131
132
  "attached",
132
- [isPageCheck(rootComponentOption?.isPage)],
133
+ [isPageCheck(rootComponentOption?.isPage), pagePathCheck(defineComponentOption.path)],
133
134
  );
134
135
 
135
136
  // 页面时删除预设的虚拟组件字段
@@ -137,6 +138,9 @@ export function normalizeOptions(
137
138
  Reflect.deleteProperty(finalOptionsForComponent.options, "virtualHost");
138
139
  }
139
140
 
141
+ // 处理debounce和throttle前缀的方法(事件)配置
142
+ applyDebounceAndThrottle(finalOptionsForComponent.methods);
143
+
140
144
  // 初始化store数据到data并把store配置放入到data的__storeConfig__下为后续使用
141
145
  initStore(finalOptionsForComponent);
142
146
 
@@ -9,6 +9,7 @@ type _SubComponentType = {
9
9
  | boolean
10
10
  | symbol
11
11
  | null
12
+ | undefined
12
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
14
  | Record<string, any>
14
15
  | unknown[]
@@ -53,3 +53,36 @@ SubComponent<{}, OnlyPropsCompDoc>()({
53
53
  },
54
54
  },
55
55
  });
56
+ // 4 与data的内部字段重复
57
+ SubComponent<{}, OnlyPropsCompDoc>()({
58
+ data: {
59
+ _aaa_fff: 123,
60
+ },
61
+ computed: {
62
+ // @ts-expect-error 与data的内部字段重复
63
+ _aaa_fff(): number {
64
+ return 123;
65
+ },
66
+ },
67
+ });
68
+ // 5 与store的内部字段重复
69
+ SubComponent<{}, OnlyPropsCompDoc>()({
70
+ store: {
71
+ _aaa_ccc: () => 123,
72
+ },
73
+ computed: {
74
+ // @ts-expect-error 与store的内部字段重复
75
+ _aaa_ccc(): number {
76
+ return 123;
77
+ },
78
+ },
79
+ });
80
+ // 6 与root字段重复
81
+ SubComponent<{ data: { _aaa_ccc: 123 } }, OnlyPropsCompDoc>()({
82
+ computed: {
83
+ // @ts-expect-error 与store的内部字段重复
84
+ _aaa_ccc(): number {
85
+ return 123;
86
+ },
87
+ },
88
+ });
@@ -168,3 +168,15 @@ SubComponent<{ data: { _num: number } }, $aaa>()({
168
168
  },
169
169
  },
170
170
  });
171
+
172
+ // computed中可写 内部字段
173
+ SubComponent<{ data: { _num: number } }, $aaa>()({
174
+ computed: {
175
+ aaa_isReady() {
176
+ return true;
177
+ },
178
+ _aaa_ccc(): string {
179
+ return "123";
180
+ },
181
+ },
182
+ });
@@ -55,3 +55,10 @@ SubComponent<{}, OnlyPropsCompDoc>()({
55
55
  _aaa_xxx: 123, // ok 内部字段可写
56
56
  },
57
57
  });
58
+ // 4 与root的数据字段重复
59
+ SubComponent<{ data: { aaa_str: 123 } }, OnlyPropsCompDoc>()({
60
+ data: {
61
+ // @ts-expect-error 与root的data字段重复
62
+ aaa_str: "a",
63
+ },
64
+ });
@@ -16,15 +16,15 @@ type DocA = ComponentType<{
16
16
 
17
17
  SubComponent<{
18
18
  properties: {
19
- aaa_str: string;
20
- aaa_num: number;
19
+ str: string;
21
20
  };
22
21
  }, DocA>()({
23
22
  inherit: {
24
- aaa_str: "aaa_str",
23
+ aaa_str: "str",
25
24
  },
26
25
  data: {
27
26
  aaa_num: 20,
27
+ _aaa_xxx: 30,
28
28
  },
29
29
  store: {
30
30
  // @ts-expect-error 1 与 inherit 字段重复
@@ -33,5 +33,17 @@ SubComponent<{
33
33
  aaa_num: () => user.age,
34
34
  // @ts-expect-error 3 超出约束字段
35
35
  num: () => user.age,
36
+ // @ts-expect-error 4 与data的内部字段重复
37
+ _aaa_xxx: () => user.age,
38
+ },
39
+ });
40
+ SubComponent<{
41
+ properties: {
42
+ aaa_num: number;
43
+ };
44
+ }, DocA>()({
45
+ store: {
46
+ // @ts-expect-error 与 root 的 properties 字段重复
47
+ aaa_num: () => 123,
36
48
  },
37
49
  });
@@ -38,7 +38,10 @@ import type { CreateSubComponentDoc } from "./SubReturnType/CreateSubComponentDo
38
38
  import type { SubStoreConstraint } from "./SubStore/SubStoreConstraint";
39
39
  import type { SubStoreOption } from "./SubStore/SubStoreOption";
40
40
  import type { SubWatchOption } from "./SubWatch/SubWatchOption";
41
-
41
+ // type getLegalKeys<K> = K extends Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc))> ? K
42
+ // : K extends keyof AllRootDataDoc ? never
43
+ // : K extends Extract<Exclude<keyof NoInfer<TSubStore>, keyof SubDataDoc>, InnerFields<Prefix>> ? K
44
+ // : never;
42
45
  type Options<
43
46
  RootDoc extends RootComponentType,
44
47
  IsPage extends boolean,
@@ -59,21 +62,68 @@ type Options<
59
62
  SubMethodsDoc extends object,
60
63
  CompDocKeys extends PropertyKey = keyof CurrentCompDoc["properties"],
61
64
  > =
62
- & SubInheritOption<TInherit, CompDocKeys>
65
+ & SubInheritOption<
66
+ TInherit,
67
+ {
68
+ [k in keyof NoInfer<TInherit>]:
69
+ // 与根组件的数据字段重复的不合法
70
+ k extends keyof (AllRootDataDoc) ? never
71
+ // 继承CompDocKeys的字段合法
72
+ : k extends CompDocKeys ? k
73
+ : never;
74
+ }[keyof NoInfer<TInherit>]
75
+ >
63
76
  & SubDataOption<
64
77
  TSubData,
65
78
  // 合法的配置
66
- Exclude<CompDocKeys, (keyof InheritDoc)> | InnerFields<Prefix>
79
+ {
80
+ [k in keyof NoInfer<TSubData>]:
81
+ // 与根组件和InheritDoc的数据字段重复的不合法
82
+ k extends keyof (AllRootDataDoc) ? never
83
+ // 继承剩余的Doc的字段合法
84
+ : k extends Exclude<CompDocKeys, (keyof (InheritDoc))> ? k
85
+ // 内部字段合法
86
+ : k extends InnerFields<Prefix> ? k
87
+ : never;
88
+ }[keyof NoInfer<TSubData>]
67
89
  >
68
90
  & SubStoreOption<
69
91
  TSubStore,
70
- // 合法的配置
71
- Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc))> | InnerFields<Prefix>
92
+ {
93
+ [k in keyof NoInfer<TSubStore>]:
94
+ // 与根组件和DataDoc的数据字段重复的不合法(主要是验证内部字段)
95
+ k extends keyof (AllRootDataDoc & SubDataDoc) ? never
96
+ // 继承剩余Doc的字段合法
97
+ : k extends Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc))> ? k
98
+ // 内部字段合法
99
+ : k extends InnerFields<Prefix> ? k
100
+ : never;
101
+ }[keyof NoInfer<TSubStore>]
72
102
  >
103
+ // 下面为之前的写法 不好与根组件的字段重复检测。
104
+
105
+ // // 合法的字段(继承组件类型的keys)
106
+ // | Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc))>
107
+ // // 合法的内部字段(不与data重复的内部字段)
108
+ // | Extract<Exclude<keyof NoInfer<TSubStore>, keyof SubDataDoc>, InnerFields<Prefix>>
109
+ // 不与allData重复的字段
110
+ // | Exclude<keyof NoInfer<TSubStore>, keyof AllRootDataDoc>
111
+
73
112
  & SubComputedOption<
74
113
  TSubComputed,
75
- // 合法的配置
76
- Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))> | InnerFields<Prefix>,
114
+ {
115
+ [k in keyof NoInfer<TSubComputed>]:
116
+ // 与根组件和DataDoc和SubStoreDoc的key重复的不合法(主要是验证内部字段)
117
+ k extends keyof (AllRootDataDoc & SubDataDoc & SubStoreDoc) ? never
118
+ // 继承剩余Doc的字段合法
119
+ : k extends Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))> ? k
120
+ // 内部字段合法
121
+ : k extends InnerFields<Prefix> ? k
122
+ : never;
123
+ }[keyof NoInfer<TSubComputed>],
124
+ // 下面为之前的写法 不好与根组件的字段重复检测。
125
+ // | Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))>
126
+ // | Extract<Exclude<keyof NoInfer<TSubComputed>, keyof (SubDataDoc & SubStoreDoc)>, InnerFields<Prefix>>,
77
127
  {
78
128
  data: ComputeObject<
79
129
  & AllRootDataDoc
@@ -47,7 +47,7 @@ function _encodeURIComponent(
47
47
 
48
48
  return Object.assign(result, option);
49
49
  }
50
-
50
+ const backFuncs: (undefined | ((...args: unknown[]) => void))[] = [];
51
51
  /**
52
52
  * 页面onload参数中接受的数据值是传递的url解析后的字符串。例如:A页面通过`wx.navigateTo({url:'/pages/test/test?num=123&obj={"name":"zhao"}'})`
53
53
  * test页面onLoad(data)的参数data接受内容为` data = {num:"123",obj:"{"name":"zhao"}"}`即默认的url传的数据值为字符串,需要在接收时自行解析(JSON.parse)。且url采取ASCII编码只能接受0x20-0x7e区间的符号。无法使用一些特殊符号 如 ` :/?#[]@!$&'()*+,;= `。
@@ -55,7 +55,9 @@ function _encodeURIComponent(
55
55
  */
56
56
  export function navigateTo<TPageDoc extends PageDoc = never>(
57
57
  option: NoInfer<NavigateToOption<TPageDoc>>,
58
+ onBack?: (res: unknown) => void,
58
59
  ) {
60
+ backFuncs.push(onBack);
59
61
  // @ts-ignore 隐式索引
60
62
  if (!option.data) {
61
63
  return wx.navigateTo(option);
@@ -65,3 +67,41 @@ export function navigateTo<TPageDoc extends PageDoc = never>(
65
67
  );
66
68
  }
67
69
  }
70
+ type WMNavigateBackOption = WechatMiniprogram.NavigateBackOption;
71
+ type NavigateBackOption<Data> = WMNavigateBackOption & { data?: Data };
72
+
73
+ /**
74
+ * @param options
75
+ * @returns
76
+ */
77
+ export function navigateBack<Data, T extends NavigateBackOption<Data> = NavigateBackOption<Data>>(
78
+ options?: T,
79
+ ): WechatMiniprogram.PromisifySuccessResult<T, WMNavigateBackOption> {
80
+ const backFunc = backFuncs.pop();
81
+ if (backFunc) {
82
+ if (!options || options.data === undefined) {
83
+ throw new Error("navigateBack 需要带有data参数的配置对象,因为返回的组件需要data数据");
84
+ }
85
+ const data = options.data;
86
+ const complete = options.complete;
87
+ options.complete = (res) => {
88
+ backFunc(data);
89
+ if (complete) {
90
+ complete(res);
91
+ }
92
+ };
93
+ }
94
+ return wx.navigateBack(options);
95
+ }
96
+ export function redirectTo<TPageDoc extends PageDoc = never>(
97
+ option: NoInfer<NavigateToOption<TPageDoc>>,
98
+ ) {
99
+ // @ts-ignore 隐式索引
100
+ if (!option.data) {
101
+ return wx.redirectTo(option);
102
+ } else {
103
+ return wx.redirectTo(
104
+ _encodeURIComponent(option as NavigateToOption<TPageDoc> & { data: object }),
105
+ );
106
+ }
107
+ }
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { DefineComponent } from "./api/DefineComponent";
2
2
  import { type IInjectInfo, instanceConfig } from "./api/InstanceInject/instanceConfig";
3
- import { navigateTo } from "./api/navigateTo";
4
3
  import { RootComponent } from "./api/RootComponent";
5
4
  import { SubComponent } from "./api/SubComponent";
5
+ import { navigateBack, navigateTo, redirectTo } from "./api/wxSugar";
6
6
  import type { CreateComponentType } from "./types/CreateComponentType";
7
7
  import type { DetailedType } from "./types/DetailedType";
8
8
  import type { ExtendComponentType } from "./types/ExtendComponentType";
@@ -38,8 +38,10 @@ export {
38
38
  type ExtendComponentType,
39
39
  type IInjectInfo,
40
40
  instanceConfig,
41
+ navigateBack,
41
42
  navigateTo,
42
43
  type ParamsEqual,
44
+ redirectTo,
43
45
  RootComponent,
44
46
  SubComponent,
45
47
  };
@@ -5,3 +5,5 @@ export type { Swiper } from "./swiper";
5
5
  export type { View } from "./view";
6
6
 
7
7
  export type { Textarea } from "./Textarea";
8
+
9
+ export type { Map } from "./map";
@@ -0,0 +1,266 @@
1
+ import type { CreateComponentType } from "../../types/CreateComponentType";
2
+
3
+ type RegionChangeBegin = { type: "begin"; causedBy: "gesture" | "update" };
4
+
5
+ export type MarkLocation = { latitude: number; longitude: number };
6
+
7
+ type RegionChangeEnd = {
8
+ type: "end";
9
+ causedBy: "drag" | "scale" | "update";
10
+ centerLocation: MarkLocation;
11
+ region: { northeast: MarkLocation; southwest: MarkLocation };
12
+ rotate: number;
13
+ scale: number;
14
+ skew: number;
15
+ };
16
+
17
+ type RegionChangeDetail = RegionChangeBegin | RegionChangeEnd;
18
+
19
+ export type Callout = {
20
+ content: string;
21
+ display: "ALWAYS" | "BYCLICK";
22
+ color?: string;
23
+ fontSize?: string | number;
24
+ borderWidth?: number;
25
+ borderRadius?: number;
26
+ borderColor?: string;
27
+ bgColor?: string;
28
+ padding?: number;
29
+ textAlign?: "center" | "left" | "right";
30
+ /**
31
+ * 横向偏移量,向右为正数 number 2.11.0
32
+ */
33
+ anchorX?: number;
34
+ /**
35
+ * anchorY 纵向偏移量,向下为正数 number 2.11.0
36
+ */
37
+ anchorYL?: number;
38
+ };
39
+
40
+ // 官方说明 https://developers.weixin.qq.com/miniprogram/dev/component/map.html#marker
41
+ export type Marker = {
42
+ // 标记点 id marker 点击事件回调会返回此 id
43
+ id: number;
44
+ // 标注图标宽度 默认为图片实际宽度
45
+ width: number | string;
46
+ // 标注图标高度 默认为图片实际高度
47
+ height: number | string;
48
+ // 聚合簇的 id 自定义点聚合簇效果时使用
49
+ clusterId?: number;
50
+ // 是否参与点聚合 默认不参与点聚合
51
+ joinCluster?: boolean;
52
+ // 纬度 浮点数,范围 -90 ~ 90
53
+ latitude: number;
54
+ // 经度 浮点数,范围 -180 ~ 180
55
+ longitude: number;
56
+ // 标注点名 点击时显示,callout 存在时将被忽略
57
+ title?: string;
58
+ // 显示层级 默认为 0
59
+ zIndex?: number;
60
+ // 显示的图标 项目目录下的图片路径,支持网络路径、本地路径、代码包路径(2.3.0)
61
+ iconPath: string;
62
+ // 旋转角度 顺时针旋转的角度,范围 0 ~ 360,默认为 0
63
+ rotate?: number;
64
+ // 标注的透明度 默认 1,无透明,范围 0 ~ 1
65
+ alpha?: number;
66
+ // 标记点上方的气泡窗口 支持的属性见下表,可识别换行符
67
+ callout?: Callout;
68
+ // 自定义气泡窗口 支持的属性见下表
69
+ customCallout?: Callout;
70
+ // 为标记点旁边增加标签 支持的属性见下表,可识别换行符
71
+ label?: Callout;
72
+ // 经纬度在标注图标的锚点,默认底边中点
73
+ anchor?: { x: number; y: number };
74
+ // 无障碍访问,(属性)元素的额外描述
75
+ ariaLabel?: string;
76
+ // 碰撞关系 详见下表碰撞关系 3.4.3
77
+ collisionRelation?: string;
78
+ // 碰撞类型 详见下表碰撞关系 3.4.3
79
+ collision?: string;
80
+ };
81
+
82
+ export type Circle = {
83
+ // 纬度 number 是 浮点数,范围 -90 ~ 90
84
+ latitude: number;
85
+ // 经度 number 是 浮点数,范围 -180 ~ 180
86
+ longitude: number;
87
+ // 半径 number 是
88
+ radius: number;
89
+ // 描边的颜色 string 否 十六进制
90
+ color?: string;
91
+ // 填充颜色 string 否 十六进制
92
+ fillColor?: string;
93
+ // 描边的宽度 number 否
94
+ strokeWidth?: number;
95
+ // 压盖关系 string 否 默认为 abovelabels
96
+ level?: string;
97
+ };
98
+
99
+ export type Polygon = {
100
+ // 边线虚线 Array<number> 否 默认值 [0, 0] 为实线,[10, 10]表示十个像素的实线和十个像素的空白(如此反复)组成的虚线 2.22.0
101
+ dashArray?: number[];
102
+ // 经纬度数组 array 是 [{latitude: 0, longitude: 0}] 2.3.0
103
+ points: MarkLocation[];
104
+ // 描边的宽度 number 否 2.3.0
105
+ strokeWidth?: number;
106
+ // 描边的颜色 string 否 十六进制 2.3.0
107
+ strokeColor?: string;
108
+ // 填充颜色 string 否 十六进制
109
+ fillColor?: string;
110
+ // 设置多边形 Z 轴数值 number 否 2.3.0
111
+ zIndex?: number;
112
+ // 压盖关系 string 否 默认为 abovelabels 2.14.0
113
+ level?: string;
114
+ };
115
+
116
+ export type Polyline = {
117
+ // 经纬度数组 array
118
+ points: MarkLocation[];
119
+ // 线的颜色 string 否 十六进制
120
+ color?: string;
121
+ // 彩虹线 array 否 存在时忽略 color 值 2.13.0
122
+ colorList?: string[];
123
+ // 线的宽度 number 否
124
+ width?: number;
125
+ // 是否虚线 boolean 否 默认 false
126
+ dottedLine?: boolean;
127
+ // 带箭头的线 boolean 否 默认 false,开发者工具暂不支持该属性 1.2.0
128
+ arrowLine?: boolean;
129
+ // 更换箭头图标 string 否 在 arrowLine 为 true 时生效 1.6.0
130
+ arrowIconPath?: string;
131
+ // 线的边框颜色 string 否 1.2.0
132
+ borderColor?: string;
133
+ // 线的厚度 number 否 1.2.0
134
+ borderWidth?: number;
135
+ // 压盖关系 string 否 默认为 abovelabels 2.14.0
136
+ level?: string;
137
+ // 文字样式 TextStyle 否 折线上文本样式 2.22.0
138
+ textStyle?: TextStyle;
139
+ // 分段文本 Array<SegmentText> 否 折线上文本内容和位置 2.22.0
140
+ segmentTexts?: SegmentText[];
141
+ };
142
+
143
+ export type TextStyle = {
144
+ // 文本颜色 string 否 #000000
145
+ textColor?: string;
146
+ // 描边颜色 string 否 #ffffff
147
+ strokeColor?: string;
148
+ // 文本大小 number 否 14
149
+ fontSize?: number;
150
+ };
151
+
152
+ export type SegmentText = {
153
+ // 名称 string 默认''
154
+ name: string;
155
+ // 起点 number
156
+ startIndex: string;
157
+ // 终点 number
158
+ endIndex: number;
159
+ };
160
+
161
+ // 源自 https://developers.weixin.qq.com/miniprogram/dev/component/map.html#%E5%B1%9E%E6%80%A7%E8%AF%B4%E6%98%8E
162
+ export type Map = CreateComponentType<"map", {
163
+ properties: {
164
+ // 中心经度 1.0.0
165
+ latitude: number;
166
+ // 中心纬度 1.0.0
167
+ longitude: number;
168
+ // 缩放级别,取值范围为3-20 1.0.0
169
+ scale?: number;
170
+ // 最小缩放级别 2.13.0
171
+ minScale?: number;
172
+ // 最大缩放级别 2.13.0
173
+ maxScale?: number;
174
+ // 标记点 1.0.0
175
+ markers?: Marker[];
176
+ // 即将移除,请使用 markers 1.0.0
177
+ covers?: Marker[];
178
+ // 路线 1.0.0
179
+ polyline?: Polyline[];
180
+ // 圆 1.0.0
181
+ circles?: Circle[];
182
+ // 控件(即将废弃,建议使用 cover-view 代替) 1.0.0
183
+ controls?: Marker[];
184
+ // 缩放视野以包含所有给定的坐标点 1.0.0
185
+ includePoints?: Marker[];
186
+ /**
187
+ * 显示带有方向的当前定位点 1.0.0
188
+ */
189
+ showLocation?: boolean;
190
+ // 多边形 2.3.0
191
+ polygons?: Polygon[];
192
+ // 地图能力【个性化地图】使用的key,不支持动态修改 2.3.0
193
+ subkey?: string;
194
+ // 地图能力【个性化地图】配置的 style
195
+ layerStyle?: number;
196
+ // 旋转角度,范围 0 ~ 360, 地图正北和设备 y 轴角度的夹角 2.5.0
197
+ rotate?: number;
198
+ // 倾斜角度,范围 0 ~ 40 , 关于 z 轴的倾角 2.5.0
199
+ skew?: number;
200
+ // 展示3D楼块 2.3.0
201
+ enable3D?: boolean;
202
+ // 显示指南针 2.3.0
203
+ showCompass?: boolean;
204
+ // 显示比例尺,工具暂不支持 2.8.0
205
+ showScale?: boolean;
206
+ // 开启俯视 2.3.0
207
+ enableOverlooking?: boolean;
208
+ // 开启最大俯视角,俯视角度从 45 度拓展到 75 度 2.26.0
209
+ enableAutoMaxOverlooking?: boolean;
210
+ // 是否支持缩放 2.3.0
211
+ enableZoom?: boolean;
212
+ // 是否支持拖动 2.3.0
213
+ enableScroll?: boolean;
214
+ // 是否支持旋转 2.3.0
215
+ enableRotate?: boolean;
216
+ // 是否开启卫星图 2.7.0
217
+ enableSatellite?: boolean;
218
+ // 是否开启实时路况 2.7.0
219
+ enableTraffic?: boolean;
220
+ // 是否展示 POI 点 2.14.0
221
+ enablePOI?: boolean;
222
+ // 是否展示建筑物 2.14.0
223
+ enableBuilding?: boolean;
224
+ // 配置项 2.8.2
225
+ setting?: object;
226
+ };
227
+ customEvents: {
228
+ // 点击地图时触发,2.9.0起返回经纬度信息 1.0.0
229
+ tap: MarkLocation;
230
+ // 点击标记点时触发,e.detail = {markerId} 1.0.0
231
+ markertap: { markerId: number };
232
+ // 点击label时触发,e.detail = {markerId} 2.9.0
233
+ labeltap: { markerId: number };
234
+ // 点击控件时触发,e.detail = {controlId} 1.0.0
235
+ controltap: { controlId: number };
236
+ // 点击标记点对应的气泡时触发e.detail = {markerId} 1.2.0
237
+ callouttap: { markerId: number };
238
+ // 在地图渲染更新完成时触发 1.6.0
239
+ updated: undefined;
240
+ /**
241
+ * 视野改变时,regionchange 会触发两次,返回的 type 值分别为 begin 和 end。
242
+ * 2.8.0 起 begin 阶段返回 causedBy,有效值为 gesture(手势触发) & update(接口触发)
243
+ * 2.3.0 起 end 阶段返回 causedBy,有效值为 drag(拖动导致)、scale(缩放导致)、update(调用更新接口导致)
244
+ */
245
+ regionchange: RegionChangeDetail;
246
+ // 点击地图poi点时触发,e.detail = {name, longitude, latitude} 2.3.0
247
+ poitap: { name: string; longitude: number; latitude: number };
248
+ // 点击地图路线时触发,e.detail = {longitude, latitude} 3.1.0
249
+ polylinetap: { longitude: number; latitude: number };
250
+ // 地图能力生效时触发,e.detail = {ability, errCode, errMsg}
251
+ abilitysuccess: { ability: string; errCode: number; errMsg: string };
252
+ // 地图能力失败时触发,e.detail = {ability, errCode, errMsg}
253
+ abilityfail: { ability: string; errCode: number; errMsg: string };
254
+ // 地图鉴权结果成功时触发,e.detail = {errCode, errMsg}
255
+ authsuccess: { errCode: number; errMsg: string };
256
+ // MapContext.moveAlong 插值动画时触发。e.detail = {markerId, longitude, latitude, animationStatus: "interpolating" | "complete"}, 3.1.0
257
+ interpolatepoint: {
258
+ markerId: number;
259
+ longitude: number;
260
+ latitude: number;
261
+ animationStatus: "interpolating" | "complete";
262
+ };
263
+ // 组件错误时触发,例如创建或鉴权失败,e.detail = {longitude, latitude}
264
+ error: { longitude: number; latitude: number };
265
+ };
266
+ }>;
@@ -0,0 +1,31 @@
1
+ import type { Func } from "hry-types/src/Misc/Func";
2
+ import { debounce } from "./debounce";
3
+ import { throttle } from "./throttle";
4
+
5
+ /**
6
+ * 对象中的函数应用防抖和节流
7
+ * 规则 函数字段已下划线开始的后缀 如 xxx_debounced500 或 sub_xxx_throttled,无效后缀如 _debouncedxxx 不会被处理
8
+ * @param obj
9
+ */
10
+ export function applyDebounceAndThrottle(obj: Record<string, Func>) {
11
+ for (const [key, value] of Object.entries(obj)) {
12
+ if (!key.includes("_")) continue;
13
+ const suffix = key.split("_").at(-1) as string;
14
+
15
+ const remaining = suffix.slice(9);
16
+ const delay = remaining === "" ? 300 : Number(remaining);
17
+
18
+ if (suffix.startsWith("debounced")) {
19
+ if (!isNaN(delay)) {
20
+ obj[key] = debounce(value, delay);
21
+ }
22
+ continue;
23
+ }
24
+
25
+ if (suffix.startsWith("throttled")) {
26
+ if (!isNaN(delay)) {
27
+ obj[key] = throttle(value, delay);
28
+ }
29
+ }
30
+ }
31
+ }
@@ -1,20 +1,22 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ type Callback = (...args: any[]) => any;
1
3
  /**
2
4
  * 防抖函数
3
5
  * 注意 需要在tsconfig.json的types中添加"node",否则NodeJS.Timeout会报错
4
- * 例如 应用在输入框输入时,只有在输入完成并delay后,才会触发搜索,
6
+ * 例如 在input框输入内容时,只有输入停止一段时间(wait)后,才会触发输入事件.
5
7
  * @param func
6
- * @param delay
8
+ * @param wait
7
9
  * @returns
8
10
  */
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
- export function debounce<F extends (...args: any[]) => any>(func: F, delay: number): (...args: Parameters<F>) => void {
11
+ /* istanbul ignore next */
12
+ export function debounce<F extends Callback>(func: F, wait = 300): (...args: Parameters<F>) => void {
11
13
  let timeoutId: NodeJS.Timeout | null = null;
12
14
 
13
- return (...args: Parameters<F>): void => {
15
+ return function(this: unknown, ...args: Parameters<F>): void {
14
16
  if (timeoutId) {
15
17
  clearTimeout(timeoutId);
16
18
  }
17
19
 
18
- timeoutId = setTimeout(() => func(...args), delay);
20
+ timeoutId = setTimeout(() => func.call(this, ...args), wait);
19
21
  };
20
22
  }