@tarojs/plugin-platform-harmony-cpp 4.1.0 → 4.1.1-alpha.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/README.md +0 -7
- package/dist/index.js +1236 -0
- package/dist/runtime/apis/apis.ts +20 -0
- package/dist/runtime/apis/base/crypto.ts +4 -0
- package/dist/runtime/apis/base/debug.ts +5 -0
- package/dist/runtime/apis/base/index.ts +13 -0
- package/dist/runtime/apis/base/performance.ts +8 -0
- package/dist/runtime/apis/base/system.ts +181 -0
- package/dist/runtime/apis/base/update.ts +5 -0
- package/dist/runtime/apis/base/weapp/app-event.ts +75 -0
- package/dist/runtime/apis/base/weapp/life-cycle.ts +21 -0
- package/dist/runtime/apis/canvas/index.ts +27 -0
- package/dist/runtime/apis/data-analysis/index.ts +6 -0
- package/dist/runtime/apis/device/accelerometer.ts +79 -0
- package/dist/runtime/apis/device/accessibility.ts +4 -0
- package/dist/runtime/apis/device/battery.ts +24 -0
- package/dist/runtime/apis/device/bluetooth-ble.ts +19 -0
- package/dist/runtime/apis/device/bluetooth-peripheral.ts +6 -0
- package/dist/runtime/apis/device/bluetooth.ts +16 -0
- package/dist/runtime/apis/device/calendar.ts +5 -0
- package/dist/runtime/apis/device/clipboard.ts +85 -0
- package/dist/runtime/apis/device/compass.ts +21 -0
- package/dist/runtime/apis/device/contact.ts +5 -0
- package/dist/runtime/apis/device/crypto.ts +4 -0
- package/dist/runtime/apis/device/gyroscope.ts +77 -0
- package/dist/runtime/apis/device/iBeacon.ts +10 -0
- package/dist/runtime/apis/device/index.ts +24 -0
- package/dist/runtime/apis/device/keyboard.ts +63 -0
- package/dist/runtime/apis/device/memory.ts +11 -0
- package/dist/runtime/apis/device/motion.ts +6 -0
- package/dist/runtime/apis/device/network.ts +123 -0
- package/dist/runtime/apis/device/nfc.ts +10 -0
- package/dist/runtime/apis/device/phone.ts +44 -0
- package/dist/runtime/apis/device/scan.ts +4 -0
- package/dist/runtime/apis/device/screen.ts +80 -0
- package/dist/runtime/apis/device/sms.ts +4 -0
- package/dist/runtime/apis/device/vibrate.ts +32 -0
- package/dist/runtime/apis/device/wifi.ts +15 -0
- package/dist/runtime/apis/ext/index.ts +5 -0
- package/dist/runtime/apis/files/index.ts +136 -0
- package/dist/runtime/apis/files/manager.ts +942 -0
- package/dist/runtime/apis/framework/index.ts +48 -0
- package/dist/runtime/apis/harmony/task-pool.ts +39 -0
- package/dist/runtime/apis/index.ts +61 -0
- package/dist/runtime/apis/location/index.ts +133 -0
- package/dist/runtime/apis/media/EditorContext.ts +32 -0
- package/dist/runtime/apis/media/audio/index.ts +36 -0
- package/dist/runtime/apis/media/background-audio/index.ts +16 -0
- package/dist/runtime/apis/media/camera.ts +16 -0
- package/dist/runtime/apis/media/common.ts +58 -0
- package/dist/runtime/apis/media/image/index.ts +291 -0
- package/dist/runtime/apis/media/index.ts +13 -0
- package/dist/runtime/apis/media/live.ts +5 -0
- package/dist/runtime/apis/media/map.ts +4 -0
- package/dist/runtime/apis/media/media-recorder.ts +4 -0
- package/dist/runtime/apis/media/recorder.ts +6 -0
- package/dist/runtime/apis/media/video/VideoContext.ts +67 -0
- package/dist/runtime/apis/media/video/index.ts +45 -0
- package/dist/runtime/apis/media/video-decoder.ts +4 -0
- package/dist/runtime/apis/media/video-processing.ts +4 -0
- package/dist/runtime/apis/media/voip.ts +19 -0
- package/dist/runtime/apis/navigate/index.ts +8 -0
- package/dist/runtime/apis/network/downloadFile.ts +85 -0
- package/dist/runtime/apis/network/index.ts +7 -0
- package/dist/runtime/apis/network/mdns.ts +13 -0
- package/dist/runtime/apis/network/request.ts +140 -0
- package/dist/runtime/apis/network/tcp.ts +4 -0
- package/dist/runtime/apis/network/udp.ts +4 -0
- package/dist/runtime/apis/network/uploadFile.ts +105 -0
- package/dist/runtime/apis/network/webSocket.ts +126 -0
- package/dist/runtime/apis/open-api/account.ts +4 -0
- package/dist/runtime/apis/open-api/address.ts +4 -0
- package/dist/runtime/apis/open-api/authorize.ts +5 -0
- package/dist/runtime/apis/open-api/card.ts +5 -0
- package/dist/runtime/apis/open-api/channels-live.ts +11 -0
- package/dist/runtime/apis/open-api/customer-service.ts +4 -0
- package/dist/runtime/apis/open-api/device-voip.ts +5 -0
- package/dist/runtime/apis/open-api/facial.ts +7 -0
- package/dist/runtime/apis/open-api/favorites.ts +5 -0
- package/dist/runtime/apis/open-api/group.ts +4 -0
- package/dist/runtime/apis/open-api/index.ts +21 -0
- package/dist/runtime/apis/open-api/invoice.ts +5 -0
- package/dist/runtime/apis/open-api/license-plate.ts +4 -0
- package/dist/runtime/apis/open-api/login.ts +6 -0
- package/dist/runtime/apis/open-api/my-miniprogram.ts +4 -0
- package/dist/runtime/apis/open-api/privacy.ts +7 -0
- package/dist/runtime/apis/open-api/red-package.ts +4 -0
- package/dist/runtime/apis/open-api/settings.ts +5 -0
- package/dist/runtime/apis/open-api/soter.ts +6 -0
- package/dist/runtime/apis/open-api/subscribe-message.ts +6 -0
- package/dist/runtime/apis/open-api/user-info.ts +70 -0
- package/dist/runtime/apis/open-api/werun.ts +5 -0
- package/dist/runtime/apis/payment/index.ts +6 -0
- package/dist/runtime/apis/route/index.ts +88 -0
- package/dist/runtime/apis/share/index.ts +33 -0
- package/dist/runtime/apis/storage/background-fetch.ts +7 -0
- package/dist/runtime/apis/storage/cache-manager.ts +4 -0
- package/dist/runtime/apis/storage/index.ts +203 -0
- package/dist/runtime/apis/ui/animation/animation.ts +264 -0
- package/dist/runtime/apis/ui/animation/index.ts +7 -0
- package/dist/runtime/apis/ui/background.ts +20 -0
- package/dist/runtime/apis/ui/custom-component.ts +1 -0
- package/dist/runtime/apis/ui/fonts.ts +4 -0
- package/dist/runtime/apis/ui/index.ts +12 -0
- package/dist/runtime/apis/ui/interaction/index.ts +198 -0
- package/dist/runtime/apis/ui/menu.ts +4 -0
- package/dist/runtime/apis/ui/navigation-bar/index.ts +72 -0
- package/dist/runtime/apis/ui/pull-down-refresh.ts +47 -0
- package/dist/runtime/apis/ui/scroll/index.ts +82 -0
- package/dist/runtime/apis/ui/sticky.ts +4 -0
- package/dist/runtime/apis/ui/tab-bar.ts +144 -0
- package/dist/runtime/apis/ui/window.ts +20 -0
- package/dist/runtime/apis/utils/constant.ts +1 -0
- package/dist/runtime/apis/utils/handler.ts +117 -0
- package/dist/runtime/apis/utils/index.ts +105 -0
- package/dist/runtime/apis/utils/permissions.ts +6 -0
- package/dist/runtime/apis/utils/types.ts +12 -0
- package/dist/runtime/apis/utils/unit.ts +104 -0
- package/dist/runtime/apis/utils/validate.ts +87 -0
- package/dist/runtime/apis/worker/index.ts +4 -0
- package/dist/runtime/apis/wxml/index.ts +17 -0
- package/dist/runtime/apis/wxml/intersectionObserver.ts +100 -0
- package/dist/runtime/apis/wxml/nodesRef.ts +58 -0
- package/dist/runtime/apis/wxml/selectorQuery.ts +221 -0
- package/dist/runtime/apischunk/index.d.ts +802 -0
- package/dist/runtime/apischunk/index.js +5054 -0
- package/dist/runtime/components/deprecated.ets +43 -0
- package/dist/runtime/components/index.ets +49 -0
- package/dist/runtime/components/innerHtml.ets +16 -0
- package/dist/runtime/components/navigationBar.ets +65 -0
- package/dist/runtime/components/pageMeta.ets +94 -0
- package/dist/runtime/components/richText.ets +24 -0
- package/dist/runtime/components/slider.ets +119 -0
- package/dist/runtime/components/style.ets +286 -0
- package/dist/runtime/components/switch.ets +73 -0
- package/dist/runtime/components/tag.ts +58 -0
- package/dist/runtime/components/utils/AttributeManager.ets +252 -0
- package/dist/runtime/components/utils/DynamicCenter.ts +41 -0
- package/dist/runtime/components/utils/constant/event.ets +25 -0
- package/dist/runtime/components/utils/constant/style.ets +91 -0
- package/dist/runtime/components/utils/events.ts +26 -0
- package/dist/runtime/components/utils/flexManager.ets +49 -0
- package/dist/runtime/components/utils/helper.ets +51 -0
- package/dist/runtime/components/utils/htmlParser/HarmonyHTMLParser.ts +100 -0
- package/dist/runtime/components/utils/htmlParser/index.ts +58 -0
- package/dist/runtime/components/utils/index.ts +77 -0
- package/dist/runtime/components/utils/styles.ets +41 -0
- package/dist/runtime/components/video.ets +119 -0
- package/dist/runtime/components/webView.ets +55 -0
- package/dist/runtime/components/xComponent.ets +89 -0
- package/dist/runtime/framework/app.ts +248 -0
- package/dist/runtime/framework/connect.ts +24 -0
- package/dist/runtime/framework/constant.ts +3 -0
- package/dist/runtime/framework/hooks.ts +99 -0
- package/dist/runtime/framework/index.ts +15 -0
- package/dist/runtime/framework/native-page.ts +511 -0
- package/dist/runtime/framework/page.ts +256 -0
- package/dist/runtime/framework/utils/index.ts +17 -0
- package/dist/runtime/framework/utils/is.ts +26 -0
- package/dist/runtime/framework-reconciler/componentTree.ts +81 -0
- package/dist/runtime/framework-reconciler/constant.ts +86 -0
- package/dist/runtime/framework-reconciler/domInput.ts +90 -0
- package/dist/runtime/framework-reconciler/event.ts +108 -0
- package/dist/runtime/framework-reconciler/index.ts +99 -0
- package/dist/runtime/framework-reconciler/inputValueTracking.ts +106 -0
- package/dist/runtime/framework-reconciler/props.ts +132 -0
- package/dist/runtime/framework-reconciler/reconciler.ts +202 -0
- package/dist/runtime/framework-reconciler/render.ts +139 -0
- package/dist/runtime/framework-reconciler/workTags.ts +53 -0
- package/dist/runtime/runtime-cpp/bom/URL.ts +2 -0
- package/dist/runtime/runtime-cpp/bom/document.ts +45 -0
- package/dist/runtime/runtime-cpp/bom/history.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/location.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/navigator.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/raf.ts +1 -0
- package/dist/runtime/runtime-cpp/bom/window.ts +57 -0
- package/dist/runtime/runtime-cpp/constant.ts +29 -0
- package/dist/runtime/runtime-cpp/current.ts +48 -0
- package/dist/runtime/runtime-cpp/dom/class-list.ts +41 -0
- package/dist/runtime/runtime-cpp/dom/comment.ts +9 -0
- package/dist/runtime/runtime-cpp/dom/dataSource.ts +87 -0
- package/dist/runtime/runtime-cpp/dom/document.ts +113 -0
- package/dist/runtime/runtime-cpp/dom/element/canvas.ts +285 -0
- package/dist/runtime/runtime-cpp/dom/element/element.ts +262 -0
- package/dist/runtime/runtime-cpp/dom/element/form.ts +371 -0
- package/dist/runtime/runtime-cpp/dom/element/index.ts +129 -0
- package/dist/runtime/runtime-cpp/dom/element/movable.ts +250 -0
- package/dist/runtime/runtime-cpp/dom/element/normal.ts +123 -0
- package/dist/runtime/runtime-cpp/dom/element/scroll_view.ts +32 -0
- package/dist/runtime/runtime-cpp/dom/element/text.ts +9 -0
- package/dist/runtime/runtime-cpp/dom/element/video.ts +66 -0
- package/dist/runtime/runtime-cpp/dom/element/web_view.ts +72 -0
- package/dist/runtime/runtime-cpp/dom/event-source.ts +1 -0
- package/dist/runtime/runtime-cpp/dom/event.ts +187 -0
- package/dist/runtime/runtime-cpp/dom/eventTarget.ts +81 -0
- package/dist/runtime/runtime-cpp/dom/node.ts +307 -0
- package/dist/runtime/runtime-cpp/dom/style.ts +44 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/index.ts +379 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/type.ts +212 -0
- package/dist/runtime/runtime-cpp/dom/stylesheet/util.ts +186 -0
- package/dist/runtime/runtime-cpp/emitter/emitter.ts +29 -0
- package/dist/runtime/runtime-cpp/env.ts +1 -0
- package/dist/runtime/runtime-cpp/harmony-library.ts +1 -0
- package/dist/runtime/runtime-cpp/index.ts +79 -0
- package/dist/runtime/runtime-cpp/interface/event.ts +10 -0
- package/dist/runtime/runtime-cpp/interface/index.ts +7 -0
- package/dist/runtime/runtime-cpp/next-tick.ts +14 -0
- package/dist/runtime/runtime-cpp/system.ts +213 -0
- package/dist/runtime/runtime-cpp/utils/index.ts +63 -0
- package/dist/runtime/runtime-cpp/utils/info.ts +123 -0
- package/dist/runtime/runtime-cpp/utils/page.ts +12 -0
- package/dist/runtime/runtime-cpp/utils/router.ts +1 -0
- package/dist/runtime/runtime-harmony/apis/helper.ets +33 -0
- package/dist/runtime/runtime-harmony/apis/network/common.ets +41 -0
- package/dist/runtime/runtime-harmony/apis/network/downloadFile.ets +327 -0
- package/dist/runtime/runtime-harmony/apis/network/index.ets +58 -0
- package/dist/runtime/runtime-harmony/apis/network/request.ets +206 -0
- package/dist/runtime/runtime-harmony/apis/network/uploadFile.ets +190 -0
- package/dist/runtime/runtime-harmony/apis/route.ets +110 -0
- package/dist/runtime/runtime-harmony/apis/taskpool.ets +149 -0
- package/dist/runtime/runtime-harmony/index.ets +41 -0
- package/dist/runtime/runtime-harmony/utils.ts +53 -0
- package/package.json +25 -23
- package/static/@taro-oh/library-4.1.1-alpha.0.har +0 -0
- package/LICENSE +0 -174
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Current } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { callAsyncFail, callAsyncSuccess, temporarilyNotSupport, validateParams } from '../../utils'
|
|
4
|
+
|
|
5
|
+
const resCallback = (res) => {
|
|
6
|
+
return { errMsg: `${res}:ok` }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const showToastSchema = {
|
|
10
|
+
title: 'String',
|
|
11
|
+
duration: 'Number',
|
|
12
|
+
bottom: 'String'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function showToast (options) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const _default = {
|
|
18
|
+
title: '',
|
|
19
|
+
duration: 1500,
|
|
20
|
+
bottom: '50%'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
options = { ..._default, ...options }
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
validateParams<any>('showToast', options, showToastSchema)
|
|
27
|
+
} catch (error) {
|
|
28
|
+
const res = { errMsg: error.message }
|
|
29
|
+
return callAsyncFail(reject, res, options)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
const uiContext = Current?.page?.getUIContext?.()
|
|
34
|
+
|
|
35
|
+
if (!uiContext) return
|
|
36
|
+
|
|
37
|
+
uiContext.getPromptAction().showToast({
|
|
38
|
+
message: options.title,
|
|
39
|
+
duration: options.duration,
|
|
40
|
+
bottom: options.bottom,
|
|
41
|
+
showMode: 1 // 设置弹窗显示模式,显示在应用之上。
|
|
42
|
+
})
|
|
43
|
+
callAsyncSuccess(resolve, resCallback('showToast'), options)
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function showModal (options) {
|
|
48
|
+
const _default = {
|
|
49
|
+
title: '',
|
|
50
|
+
content: '',
|
|
51
|
+
showCancel: true,
|
|
52
|
+
cancelText: '取消',
|
|
53
|
+
cancelColor: '#000000',
|
|
54
|
+
confirmText: '确定',
|
|
55
|
+
confirmColor: '#3CC51F',
|
|
56
|
+
backgroundColor: '#ffffff'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
options = { ..._default, ...options }
|
|
60
|
+
|
|
61
|
+
const {
|
|
62
|
+
title, content, cancelText, confirmText,
|
|
63
|
+
cancelColor, confirmColor, showCancel, backgroundColor
|
|
64
|
+
} = options
|
|
65
|
+
|
|
66
|
+
const buttons: any = []
|
|
67
|
+
|
|
68
|
+
if (cancelText !== '' && showCancel) {
|
|
69
|
+
buttons.push({
|
|
70
|
+
text: cancelText,
|
|
71
|
+
color: cancelColor
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (confirmText !== '') {
|
|
76
|
+
buttons.push({
|
|
77
|
+
text: confirmText,
|
|
78
|
+
color: confirmColor
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
const modalOptions = {
|
|
84
|
+
title,
|
|
85
|
+
message: content,
|
|
86
|
+
buttons: buttons,
|
|
87
|
+
backgroundColor
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
const uiContext = Current?.page?.getUIContext?.()
|
|
92
|
+
|
|
93
|
+
if (!uiContext) return
|
|
94
|
+
|
|
95
|
+
uiContext.getPromptAction().showDialog(modalOptions, (error, data) => {
|
|
96
|
+
if (error) {
|
|
97
|
+
const res = { errMsg: error }
|
|
98
|
+
callAsyncFail(reject, res, options)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (data.index === 0 && showCancel) {
|
|
102
|
+
callAsyncSuccess(
|
|
103
|
+
resolve,
|
|
104
|
+
{
|
|
105
|
+
...resCallback('showModal'),
|
|
106
|
+
confirm: false,
|
|
107
|
+
cancel: true
|
|
108
|
+
},
|
|
109
|
+
options
|
|
110
|
+
)
|
|
111
|
+
} else {
|
|
112
|
+
callAsyncSuccess(
|
|
113
|
+
resolve,
|
|
114
|
+
{
|
|
115
|
+
...resCallback('showModal'),
|
|
116
|
+
confirm: true,
|
|
117
|
+
cancel: false,
|
|
118
|
+
content: null
|
|
119
|
+
},
|
|
120
|
+
options
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const showActionSheetSchema = {
|
|
128
|
+
title: 'String',
|
|
129
|
+
itemList: 'Array'
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function showActionSheet (options) {
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
const _default = {
|
|
135
|
+
title: '',
|
|
136
|
+
itemList: [],
|
|
137
|
+
itemColor: '#000000'
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
options = { ..._default, ...options }
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
validateParams<any>('showActionSheet', options, showActionSheetSchema)
|
|
144
|
+
} catch (error) {
|
|
145
|
+
const res = { errMsg: error.message }
|
|
146
|
+
return callAsyncFail(reject, res, options)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const { title, itemList, itemColor } = options
|
|
150
|
+
|
|
151
|
+
const buttons = itemList.map(res => {
|
|
152
|
+
return {
|
|
153
|
+
text: res,
|
|
154
|
+
color: itemColor
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
const actionSheetOptions = {
|
|
159
|
+
title,
|
|
160
|
+
buttons
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
const uiContext = Current?.page?.getUIContext?.()
|
|
165
|
+
|
|
166
|
+
if (!uiContext) return
|
|
167
|
+
|
|
168
|
+
uiContext.getPromptAction().showActionMenu(actionSheetOptions, (error, data) => {
|
|
169
|
+
if (error) {
|
|
170
|
+
callAsyncFail(
|
|
171
|
+
reject,
|
|
172
|
+
{
|
|
173
|
+
...data,
|
|
174
|
+
errMsg: data.errMsg?.replace('showActionMenu', 'showActionSheet')
|
|
175
|
+
},
|
|
176
|
+
options
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
callAsyncSuccess(
|
|
181
|
+
resolve,
|
|
182
|
+
{
|
|
183
|
+
...data,
|
|
184
|
+
...resCallback('showActionSheet')
|
|
185
|
+
},
|
|
186
|
+
options
|
|
187
|
+
)
|
|
188
|
+
})
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export const hideToast = /* @__PURE__ */ temporarilyNotSupport('hideToast')
|
|
193
|
+
|
|
194
|
+
export const showLoading = temporarilyNotSupport('showLoading')
|
|
195
|
+
export const hideLoading = temporarilyNotSupport('hideLoading')
|
|
196
|
+
|
|
197
|
+
export const enableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('enableAlertBeforeUnload')
|
|
198
|
+
export const disableAlertBeforeUnload = /* @__PURE__ */ temporarilyNotSupport('disableAlertBeforeUnload')
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { eventCenter } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { MethodHandler } from '../../utils/handler'
|
|
4
|
+
|
|
5
|
+
import type Taro from '@tarojs/taro/types'
|
|
6
|
+
|
|
7
|
+
export const setNavigationBarTitle: typeof Taro.setNavigationBarTitle = function (options) {
|
|
8
|
+
const { success, fail, complete } = options || {}
|
|
9
|
+
const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete })
|
|
10
|
+
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
eventCenter.trigger('__taroNavigationStyle', {
|
|
13
|
+
title: options.title,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
return handle.success({}, { resolve, reject })
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const setNavigationBarColor: typeof Taro.setNavigationBarColor = function (options) {
|
|
21
|
+
const { success, fail, complete } = options || {}
|
|
22
|
+
const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete })
|
|
23
|
+
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
eventCenter.trigger('__taroNavigationStyle', {
|
|
26
|
+
animation: options.animation,
|
|
27
|
+
backgroundColor: options.backgroundColor,
|
|
28
|
+
frontColor: options.frontColor,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return handle.success({}, { resolve, reject })
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const showNavigationBarLoading: typeof Taro.setNavigationBarColor = function (options) {
|
|
36
|
+
const { success, fail, complete } = options || {}
|
|
37
|
+
const handle = new MethodHandler({ name: 'showNavigationBarLoading', success, fail, complete })
|
|
38
|
+
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
eventCenter.trigger('__taroNavigationStyle', {
|
|
41
|
+
loading: true,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return handle.success({}, { resolve, reject })
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const hideNavigationBarLoading: typeof Taro.hideNavigationBarLoading = function (options) {
|
|
49
|
+
const { success, fail, complete } = options || {}
|
|
50
|
+
const handle = new MethodHandler({ name: 'hideNavigationBarLoading', success, fail, complete })
|
|
51
|
+
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
eventCenter.trigger('__taroNavigationStyle', {
|
|
54
|
+
loading: false,
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
return handle.success({}, { resolve, reject })
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const hideHomeButton: typeof Taro.hideHomeButton = function (options) {
|
|
62
|
+
const { success, fail, complete } = options || {}
|
|
63
|
+
const handle = new MethodHandler({ name: 'hideHomeButton', success, fail, complete })
|
|
64
|
+
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
eventCenter.trigger('__taroNavigationStyle', {
|
|
67
|
+
home: false,
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
return handle.success({}, { resolve, reject })
|
|
71
|
+
})
|
|
72
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Current } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { callAsyncFail, callAsyncSuccess } from '../utils'
|
|
4
|
+
|
|
5
|
+
import type Taro from '@tarojs/taro/types'
|
|
6
|
+
|
|
7
|
+
export const startPullDownRefresh: typeof Taro.startPullDownRefresh = function (options) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const taro = Current.taro
|
|
10
|
+
const page = taro.getCurrentInstance().page
|
|
11
|
+
|
|
12
|
+
if (!page) {
|
|
13
|
+
return callAsyncFail(reject, { errMsg: 'stopPullDownRefresh:fail' }, options)
|
|
14
|
+
}
|
|
15
|
+
if (page.isRefreshing instanceof Array) {
|
|
16
|
+
const index = page.tabBarCurrentIndex || 0
|
|
17
|
+
page.isRefreshing[index] = true
|
|
18
|
+
} else {
|
|
19
|
+
page.isRefreshing = true
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const res = { errMsg: 'startPullDownRefresh:ok' }
|
|
23
|
+
page.$set?.('isRefreshing', true)
|
|
24
|
+
callAsyncSuccess(resolve, res, options)
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const stopPullDownRefresh: typeof Taro.stopPullDownRefresh = function (options) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const taro = Current.taro
|
|
31
|
+
const page = taro.getCurrentInstance().page
|
|
32
|
+
|
|
33
|
+
if (!page) {
|
|
34
|
+
return callAsyncFail(reject, { errMsg: 'stopPullDownRefresh:fail' }, options)
|
|
35
|
+
}
|
|
36
|
+
if (page.isRefreshing instanceof Array) {
|
|
37
|
+
const index = page.tabBarCurrentIndex || 0
|
|
38
|
+
page.isRefreshing[index] = false
|
|
39
|
+
} else {
|
|
40
|
+
page.isRefreshing = false
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const res = { errMsg: 'stopPullDownRefresh:ok' }
|
|
44
|
+
page.$set?.('isRefreshing', false)
|
|
45
|
+
callAsyncSuccess(resolve, res, options)
|
|
46
|
+
})
|
|
47
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Current, document, getPageScrollerOrNode } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { MethodHandler, pxTransformHelper } from '../../utils'
|
|
4
|
+
|
|
5
|
+
import type { TaroAny } from '@tarojs/runtime'
|
|
6
|
+
import type Taro from '@tarojs/taro/types'
|
|
7
|
+
|
|
8
|
+
export const pageScrollTo: typeof Taro.pageScrollTo = (options) => {
|
|
9
|
+
const { scrollTop, selector = '', duration = 300, offsetTop = 0, success, fail, complete } = options || {}
|
|
10
|
+
const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete })
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
if (scrollTop === undefined && !selector) {
|
|
13
|
+
return handle.fail({
|
|
14
|
+
errMsg: 'scrollTop" 或 "selector" 需要其之一'
|
|
15
|
+
}, { resolve, reject })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (scrollTop && selector) {
|
|
19
|
+
console.warn('"scrollTop" 或 "selector" 建议只设一个值, 全部设置会忽略selector')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const taro = Current.taro
|
|
23
|
+
const page = taro.getCurrentInstance().page
|
|
24
|
+
|
|
25
|
+
let scrollTopValue = -1
|
|
26
|
+
let scrollLeftValue = -1
|
|
27
|
+
let scrollNode: TaroAny = null
|
|
28
|
+
const currentPageNode = getPageScrollerOrNode(page?.node, page)
|
|
29
|
+
|
|
30
|
+
if (scrollTop || typeof scrollTop === 'number') {
|
|
31
|
+
scrollTopValue = scrollTop
|
|
32
|
+
} else if (selector) {
|
|
33
|
+
const node: TaroAny = document.querySelector(selector)
|
|
34
|
+
|
|
35
|
+
if (!node) return
|
|
36
|
+
|
|
37
|
+
const globalPositionY = node.getComputedStyle().globalY
|
|
38
|
+
|
|
39
|
+
let parent = node?.parentNode
|
|
40
|
+
while (!!parent && parent !== currentPageNode) {
|
|
41
|
+
if (parent?.nodeName === 'SCROLL-VIEW') {
|
|
42
|
+
scrollNode = parent
|
|
43
|
+
break
|
|
44
|
+
}
|
|
45
|
+
parent = parent?.parentNode
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!scrollNode) return
|
|
49
|
+
|
|
50
|
+
// FIXME 更新为新的获取方式获取组件参数
|
|
51
|
+
const result = Current.nativeModule.getCurrentOffset(scrollNode)
|
|
52
|
+
|
|
53
|
+
if (!result) return
|
|
54
|
+
|
|
55
|
+
const { yOffset, xOffset } = result
|
|
56
|
+
scrollTopValue = globalPositionY + yOffset + pxTransformHelper(offsetTop, 'px', true)
|
|
57
|
+
scrollLeftValue = xOffset
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (scrollTopValue === -1) {
|
|
61
|
+
return handle.fail({
|
|
62
|
+
errMsg: '请检查传入的 scrollTop 或 selector 是否合法'
|
|
63
|
+
}, { resolve, reject })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
Current.nativeModule.scrollTo(currentPageNode, {
|
|
68
|
+
xOffset: scrollLeftValue,
|
|
69
|
+
yOffset: scrollTopValue,
|
|
70
|
+
duration,
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
handle.success({}, { resolve, reject })
|
|
75
|
+
}, duration)
|
|
76
|
+
} catch (err) {
|
|
77
|
+
return handle.fail({
|
|
78
|
+
errMsg: err.message
|
|
79
|
+
}, { resolve, reject })
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Current, eventCenter } from '@tarojs/runtime'
|
|
2
|
+
|
|
3
|
+
import { callAsyncFail, callAsyncSuccess } from '../utils'
|
|
4
|
+
|
|
5
|
+
import type Taro from '@tarojs/taro/types'
|
|
6
|
+
|
|
7
|
+
interface ShowTabBar {
|
|
8
|
+
type: 'show'
|
|
9
|
+
fn: typeof Taro.showTabBar
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface HideTabBar {
|
|
13
|
+
type: 'hide'
|
|
14
|
+
fn: typeof Taro.hideTabBar
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type ToggleAPIs = ShowTabBar | HideTabBar
|
|
18
|
+
|
|
19
|
+
const toggleTabBar = function<T extends ToggleAPIs['type']> (type: T): Extract<ToggleAPIs, {type: T}>['fn'] {
|
|
20
|
+
return function (options) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const taro = Current.taro
|
|
23
|
+
const page = taro.getCurrentInstance().page
|
|
24
|
+
const currentData = page?._data?.taroTabBar || page?.tabBar
|
|
25
|
+
const res = { errMsg: `${type}TabBar:ok` }
|
|
26
|
+
const error = { errMsg: `${type}TabBar:fail not TabBar page` }
|
|
27
|
+
|
|
28
|
+
if (!currentData) {
|
|
29
|
+
callAsyncFail(reject, error, options)
|
|
30
|
+
} else {
|
|
31
|
+
const isShow = type === 'show'
|
|
32
|
+
const event = isShow ? '__taroShowTabBar' : '__taroHideTabBar'
|
|
33
|
+
eventCenter.trigger(event, {
|
|
34
|
+
animation: options?.animation,
|
|
35
|
+
})
|
|
36
|
+
page.$set?.('isShowTaroTabBar', isShow)
|
|
37
|
+
callAsyncSuccess(resolve, res, options)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const showTabBar = toggleTabBar('show')
|
|
44
|
+
|
|
45
|
+
export const hideTabBar = toggleTabBar('hide')
|
|
46
|
+
|
|
47
|
+
export const setTabBarStyle: typeof Taro.setTabBarStyle = function (options = {}) {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const taro = Current.taro
|
|
50
|
+
const page = taro.getCurrentInstance().page
|
|
51
|
+
const currentData = page?._data?.taroTabBar || page?.tabBar
|
|
52
|
+
const res = { errMsg: 'setTabBarStyle:ok' }
|
|
53
|
+
const error = { errMsg: 'setTabBarStyle:fail not TabBar page' }
|
|
54
|
+
|
|
55
|
+
if (!currentData) {
|
|
56
|
+
callAsyncFail(reject, error, options)
|
|
57
|
+
} else {
|
|
58
|
+
const data = Object.assign({}, currentData)
|
|
59
|
+
|
|
60
|
+
if (options.color) data.color = options.color
|
|
61
|
+
if (options.selectedColor) data.selectedColor = options.selectedColor
|
|
62
|
+
if (options.backgroundColor) data.backgroundColor = options.backgroundColor
|
|
63
|
+
if (options.borderStyle) data.borderStyle = options.borderStyle
|
|
64
|
+
|
|
65
|
+
eventCenter.trigger('__taroSetTabBarStyle', options)
|
|
66
|
+
page.$set?.('taroTabBar', data)
|
|
67
|
+
callAsyncSuccess(resolve, res, options)
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const setTabBarItem: typeof Taro.setTabBarItem = function (options) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
const taro = Current.taro
|
|
75
|
+
const page = taro.getCurrentInstance().page
|
|
76
|
+
const currentData = page?._data?.taroTabBar || page?.tabBar
|
|
77
|
+
const res = { errMsg: 'setTabBarItem:ok' }
|
|
78
|
+
const error = { errMsg: 'setTabBarItem:fail not TabBar page' }
|
|
79
|
+
|
|
80
|
+
if (!currentData) {
|
|
81
|
+
callAsyncFail(reject, error, options)
|
|
82
|
+
} else {
|
|
83
|
+
const index = options.index
|
|
84
|
+
const item = Object.assign({}, currentData.list[index])
|
|
85
|
+
|
|
86
|
+
if (options.text) item.text = options.text
|
|
87
|
+
if (options.iconPath) item.iconPath = options.iconPath
|
|
88
|
+
if (options.selectedIconPath) item.selectedIconPath = options.selectedIconPath
|
|
89
|
+
|
|
90
|
+
const list = [
|
|
91
|
+
...currentData.list.slice(0, index),
|
|
92
|
+
item,
|
|
93
|
+
...currentData.list.slice(index + 1)
|
|
94
|
+
]
|
|
95
|
+
const data = Object.assign({}, currentData, { list })
|
|
96
|
+
|
|
97
|
+
eventCenter.trigger('__taroSetTabBarItem', options)
|
|
98
|
+
page.$set?.('taroTabBar', data)
|
|
99
|
+
callAsyncSuccess(resolve, res, options)
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function showTabBarRedDot (options) {
|
|
105
|
+
const res = { errMsg: 'showTabBarRedDot:ok' }
|
|
106
|
+
return new Promise((resolve) => {
|
|
107
|
+
eventCenter.trigger('__taroShowTabBarRedDotHandler', {
|
|
108
|
+
index: options?.index || 0,
|
|
109
|
+
})
|
|
110
|
+
callAsyncSuccess(resolve, res, options)
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function hideTabBarRedDot (options) {
|
|
115
|
+
const res = { errMsg: 'hideTabBarRedDot:ok' }
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
eventCenter.trigger('__taroHideTabBarRedDotHandler', {
|
|
118
|
+
index: options?.index || 0,
|
|
119
|
+
})
|
|
120
|
+
callAsyncSuccess(resolve, res, options)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function setTabBarBadge (options) {
|
|
125
|
+
const res = { errMsg: 'setTabBarBadge:ok' }
|
|
126
|
+
return new Promise((resolve) => {
|
|
127
|
+
const text = options?.text || ''
|
|
128
|
+
eventCenter.trigger('__taroSetTabBarBadge', {
|
|
129
|
+
index: options?.index || 0,
|
|
130
|
+
text: text.replace(/[\u0391-\uFFE5]/g, 'aa').length > 4 ? '...' : text,
|
|
131
|
+
})
|
|
132
|
+
callAsyncSuccess(resolve, res, options)
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function removeTabBarBadge (options) {
|
|
137
|
+
const res = { errMsg: 'removeTabBarBadge:ok' }
|
|
138
|
+
return new Promise((resolve) => {
|
|
139
|
+
eventCenter.trigger('__taroRemoveTabBarBadge', {
|
|
140
|
+
index: options?.index || 0,
|
|
141
|
+
})
|
|
142
|
+
callAsyncSuccess(resolve, res, options)
|
|
143
|
+
})
|
|
144
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
import type Taro from '@tarojs/taro/types'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 设置窗口大小,该接口仅适用于 PC 平台,使用细则请参见指南
|
|
7
|
+
*/
|
|
8
|
+
export const setWindowSize = /* @__PURE__ */ temporarilyNotSupport('setWindowSize')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 监听窗口尺寸变化事件
|
|
12
|
+
*/
|
|
13
|
+
export const onWindowResize: typeof Taro.onWindowResize = /* @__PURE__ */ temporarilyNotSupport('onWindowResize')
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 取消监听窗口尺寸变化事件
|
|
17
|
+
*/
|
|
18
|
+
export const offWindowResize: typeof Taro.offWindowResize = /* @__PURE__ */ temporarilyNotSupport('offWindowResize')
|
|
19
|
+
|
|
20
|
+
export const checkIsPictureInPictureActive = /* @__PURE__ */ temporarilyNotSupport('checkIsPictureInPictureActive')
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ETS_METHODS_TRIGGER_EVENTNAME = '__taroPluginEtsMethodsTrigger'
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { isFunction } from '@tarojs/shared'
|
|
2
|
+
|
|
3
|
+
import type { TFunc } from '@tarojs/runtime'
|
|
4
|
+
|
|
5
|
+
export interface ICallbackResult {
|
|
6
|
+
/** 错误信息 */
|
|
7
|
+
errMsg: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type TCallback<T = Partial<ICallbackResult>> = (res: T) => Promise<void> | void
|
|
11
|
+
interface IMethodParam<T = Partial<ICallbackResult>> {
|
|
12
|
+
name: string
|
|
13
|
+
success?: TCallback<T & ICallbackResult>
|
|
14
|
+
fail?: TCallback
|
|
15
|
+
complete?: TCallback<T | ICallbackResult>
|
|
16
|
+
}
|
|
17
|
+
interface IMockPromise {
|
|
18
|
+
resolve?: typeof Promise.resolve | TFunc
|
|
19
|
+
reject?: typeof Promise.reject | TFunc
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class MethodHandler<T = Partial<ICallbackResult>> {
|
|
23
|
+
methodName: string
|
|
24
|
+
|
|
25
|
+
protected __success?: TCallback<T>
|
|
26
|
+
protected __fail?: TCallback
|
|
27
|
+
protected __complete?: TCallback<T | ICallbackResult>
|
|
28
|
+
|
|
29
|
+
protected isHandlerError = false
|
|
30
|
+
|
|
31
|
+
constructor ({ name, success, fail, complete }: IMethodParam<T>) {
|
|
32
|
+
this.methodName = name
|
|
33
|
+
this.__success = success
|
|
34
|
+
this.__fail = fail
|
|
35
|
+
this.__complete = complete
|
|
36
|
+
|
|
37
|
+
this.isHandlerError = isFunction(this.__complete) || isFunction(this.__fail)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
success<U = Record<string, unknown>> (res: Partial<T> & Partial<ICallbackResult> = {}, promise: IMockPromise = {}): Promise<T & U & ICallbackResult> {
|
|
41
|
+
if (!res.errMsg) {
|
|
42
|
+
res.errMsg = `${this.methodName}:ok`
|
|
43
|
+
}
|
|
44
|
+
isFunction(this.__success) && this.__success(res as T)
|
|
45
|
+
isFunction(this.__complete) && this.__complete(res as T)
|
|
46
|
+
|
|
47
|
+
const { resolve = Promise.resolve.bind(Promise) } = promise
|
|
48
|
+
return resolve(res as Required<T & U & ICallbackResult>)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fail<U = Record<string, unknown>> (res: Partial<T> & Partial<ICallbackResult> = {}, promise: IMockPromise = {}): Promise<T & U & ICallbackResult> {
|
|
52
|
+
if (!res.errMsg) {
|
|
53
|
+
res.errMsg = `${this.methodName}:fail`
|
|
54
|
+
} else {
|
|
55
|
+
res.errMsg = `${this.methodName}:fail ${res.errMsg}`
|
|
56
|
+
}
|
|
57
|
+
isFunction(this.__fail) && this.__fail(res)
|
|
58
|
+
isFunction(this.__complete) && this.__complete(res as ICallbackResult)
|
|
59
|
+
|
|
60
|
+
const {
|
|
61
|
+
resolve = Promise.resolve.bind(Promise),
|
|
62
|
+
reject = Promise.reject.bind(Promise)
|
|
63
|
+
} = promise
|
|
64
|
+
return this.isHandlerError
|
|
65
|
+
? resolve(res as Required<T & U & ICallbackResult>)
|
|
66
|
+
: reject(res)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type TCallbackManagerFunc<T extends unknown[] = unknown[]> = (...arr: T) => void
|
|
71
|
+
interface ICallbackManagerOption<T extends unknown[] = unknown[]> {
|
|
72
|
+
callback?: TCallbackManagerFunc<T>
|
|
73
|
+
ctx?: any
|
|
74
|
+
[key: string]: unknown
|
|
75
|
+
}
|
|
76
|
+
type TCallbackManagerUnit<T extends unknown[] = unknown[]> = (TCallbackManagerFunc<T> | ICallbackManagerOption<T>)
|
|
77
|
+
|
|
78
|
+
export class CallbackManager<T extends unknown[] = unknown[]> {
|
|
79
|
+
callbacks: TCallbackManagerUnit<T>[] = []
|
|
80
|
+
|
|
81
|
+
/** 添加回调 */
|
|
82
|
+
add = (opt?: TCallbackManagerUnit<T>) => {
|
|
83
|
+
if (opt) this.callbacks.push(opt)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** 移除回调 */
|
|
87
|
+
remove = (opt?: TCallbackManagerUnit<T>) => {
|
|
88
|
+
if (opt) {
|
|
89
|
+
let pos = -1
|
|
90
|
+
this.callbacks.forEach((callback, k) => {
|
|
91
|
+
if (callback === opt) {
|
|
92
|
+
pos = k
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
if (pos > -1) {
|
|
96
|
+
this.callbacks.splice(pos, 1)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 获取回调函数数量 */
|
|
102
|
+
count = () => {
|
|
103
|
+
return this.callbacks.length
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 触发回调 */
|
|
107
|
+
trigger = (...args: T) => {
|
|
108
|
+
this.callbacks.forEach(opt => {
|
|
109
|
+
if (isFunction(opt)) {
|
|
110
|
+
opt(...args)
|
|
111
|
+
} else {
|
|
112
|
+
const { callback, ctx } = opt
|
|
113
|
+
isFunction(callback) && callback.call(ctx, ...args)
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
}
|