@tarojs/plugin-platform-harmony-ets 3.7.0-alpha.27
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/LICENSE +160 -0
- package/dist/apis/apis.ts +15 -0
- package/dist/apis/base/index.ts +5 -0
- package/dist/apis/base/system.ts +77 -0
- package/dist/apis/device/accelerometer.ts +76 -0
- package/dist/apis/device/battery.ts +24 -0
- package/dist/apis/device/clipboard.ts +70 -0
- package/dist/apis/device/index.ts +9 -0
- package/dist/apis/device/keyboard.ts +62 -0
- package/dist/apis/device/memory.ts +4 -0
- package/dist/apis/device/network.ts +72 -0
- package/dist/apis/device/phone.ts +43 -0
- package/dist/apis/device/screen.ts +79 -0
- package/dist/apis/device/vibrate.ts +24 -0
- package/dist/apis/files/index.ts +135 -0
- package/dist/apis/files/manager.ts +941 -0
- package/dist/apis/framework/index.ts +32 -0
- package/dist/apis/index.ts +124 -0
- package/dist/apis/location/index.ts +133 -0
- package/dist/apis/media/common.ts +74 -0
- package/dist/apis/media/image.ts +122 -0
- package/dist/apis/media/index.ts +3 -0
- package/dist/apis/media/video.ts +86 -0
- package/dist/apis/navigate/index.ts +8 -0
- package/dist/apis/network/downloadFile.ts +113 -0
- package/dist/apis/network/index.ts +4 -0
- package/dist/apis/network/request.ts +113 -0
- package/dist/apis/network/uploadFile.ts +158 -0
- package/dist/apis/network/webSocket.ts +130 -0
- package/dist/apis/open-api/index.ts +7 -0
- package/dist/apis/open-api/user-info/index.ts +85 -0
- package/dist/apis/page/index.ts +92 -0
- package/dist/apis/route/index.ts +138 -0
- package/dist/apis/storage/index.ts +133 -0
- package/dist/apis/tabbar/index.ts +147 -0
- package/dist/apis/ui/animation.ts +222 -0
- package/dist/apis/ui/background.ts +35 -0
- package/dist/apis/ui/index.ts +14 -0
- package/dist/apis/ui/interaction/index.ts +195 -0
- package/dist/apis/ui/navigation-bar/index.ts +33 -0
- package/dist/apis/ui/pull-down-refresh.ts +41 -0
- package/dist/apis/utils/handler.ts +116 -0
- package/dist/apis/utils/index.ts +85 -0
- package/dist/apis/utils/types.ts +12 -0
- package/dist/apis/utils/validate.ts +87 -0
- package/dist/apis/wxml/IntersectionObserver.ts +119 -0
- package/dist/apis/wxml/index.ts +12 -0
- package/dist/apis/wxml/nodesRef.ts +56 -0
- package/dist/apis/wxml/selectorQuery.ts +287 -0
- package/dist/components/components-react.js +51 -0
- package/dist/components/components-react.js.map +1 -0
- package/dist/components-harmony/button/index.css +109 -0
- package/dist/components-harmony/button/index.hml +31 -0
- package/dist/components-harmony/button/index.js +105 -0
- package/dist/components-harmony/camera/index.hml +6 -0
- package/dist/components-harmony/camera/index.js +12 -0
- package/dist/components-harmony/checkbox/index.hml +11 -0
- package/dist/components-harmony/checkbox/index.js +60 -0
- package/dist/components-harmony/checkbox-group/index.hml +3 -0
- package/dist/components-harmony/checkbox-group/index.js +22 -0
- package/dist/components-harmony/cover-image/index.css +4 -0
- package/dist/components-harmony/cover-image/index.hml +9 -0
- package/dist/components-harmony/cover-image/index.js +15 -0
- package/dist/components-harmony/form/index.hml +10 -0
- package/dist/components-harmony/form/index.js +11 -0
- package/dist/components-harmony/icon/index.css +27 -0
- package/dist/components-harmony/icon/index.hml +54 -0
- package/dist/components-harmony/icon/index.js +17 -0
- package/dist/components-harmony/image/index.css +5 -0
- package/dist/components-harmony/image/index.hml +11 -0
- package/dist/components-harmony/image/index.js +28 -0
- package/dist/components-harmony/input/index.hml +21 -0
- package/dist/components-harmony/input/index.js +98 -0
- package/dist/components-harmony/label/index.hml +3 -0
- package/dist/components-harmony/label/index.js +6 -0
- package/dist/components-harmony/navbar/index.css +56 -0
- package/dist/components-harmony/navbar/index.hml +9 -0
- package/dist/components-harmony/navbar/index.js +30 -0
- package/dist/components-harmony/navigator/index.css +8 -0
- package/dist/components-harmony/navigator/index.hml +9 -0
- package/dist/components-harmony/navigator/index.js +104 -0
- package/dist/components-harmony/picker/index.hml +25 -0
- package/dist/components-harmony/picker/index.js +132 -0
- package/dist/components-harmony/picker-view/index.hml +23 -0
- package/dist/components-harmony/picker-view/index.js +161 -0
- package/dist/components-harmony/picker-view-column/index.hml +3 -0
- package/dist/components-harmony/picker-view-column/index.js +3 -0
- package/dist/components-harmony/progress/index.css +4 -0
- package/dist/components-harmony/progress/index.hml +28 -0
- package/dist/components-harmony/progress/index.js +23 -0
- package/dist/components-harmony/radio/index.hml +11 -0
- package/dist/components-harmony/radio/index.js +41 -0
- package/dist/components-harmony/radio-group/index.hml +3 -0
- package/dist/components-harmony/radio-group/index.js +11 -0
- package/dist/components-harmony/rich-text/index.hml +5 -0
- package/dist/components-harmony/rich-text/index.js +16 -0
- package/dist/components-harmony/scroll-view/index.css +5 -0
- package/dist/components-harmony/scroll-view/index.hml +12 -0
- package/dist/components-harmony/scroll-view/index.js +65 -0
- package/dist/components-harmony/slider/index.hml +16 -0
- package/dist/components-harmony/slider/index.js +53 -0
- package/dist/components-harmony/swiper/index.css +3 -0
- package/dist/components-harmony/swiper/index.hml +14 -0
- package/dist/components-harmony/swiper/index.js +19 -0
- package/dist/components-harmony/switch/index.hml +7 -0
- package/dist/components-harmony/switch/index.js +16 -0
- package/dist/components-harmony/tabbar/index.css +7 -0
- package/dist/components-harmony/tabbar/index.hml +26 -0
- package/dist/components-harmony/tabbar/index.js +42 -0
- package/dist/components-harmony/textarea/index.hml +24 -0
- package/dist/components-harmony/textarea/index.js +92 -0
- package/dist/components-harmony/utils/index.js +41 -0
- package/dist/components-harmony/video/index.hml +7 -0
- package/dist/components-harmony/video/index.js +73 -0
- package/dist/components-harmony/web-view/index.hml +8 -0
- package/dist/components-harmony/web-view/index.js +22 -0
- package/dist/components-harmony-ets/base.ets +63 -0
- package/dist/components-harmony-ets/button.ets +119 -0
- package/dist/components-harmony-ets/checkbox.ets +219 -0
- package/dist/components-harmony-ets/element.ets +223 -0
- package/dist/components-harmony-ets/form.ets +149 -0
- package/dist/components-harmony-ets/icon.ets +84 -0
- package/dist/components-harmony-ets/image.ets +85 -0
- package/dist/components-harmony-ets/index.ts +49 -0
- package/dist/components-harmony-ets/innerHtml.ets +79 -0
- package/dist/components-harmony-ets/input.ets +195 -0
- package/dist/components-harmony-ets/label.ets +111 -0
- package/dist/components-harmony-ets/picker.ets +370 -0
- package/dist/components-harmony-ets/radio.ets +225 -0
- package/dist/components-harmony-ets/richText.ets +97 -0
- package/dist/components-harmony-ets/scrollView.ets +199 -0
- package/dist/components-harmony-ets/slider.ets +159 -0
- package/dist/components-harmony-ets/swiper.ets +204 -0
- package/dist/components-harmony-ets/switch.ets +113 -0
- package/dist/components-harmony-ets/text.ets +97 -0
- package/dist/components-harmony-ets/textArea.ets +169 -0
- package/dist/components-harmony-ets/utils/AttributeManager.ets +250 -0
- package/dist/components-harmony-ets/utils/DynamicCenter.ts +48 -0
- package/dist/components-harmony-ets/utils/constant/event.ets +25 -0
- package/dist/components-harmony-ets/utils/constant/icon.ts +19 -0
- package/dist/components-harmony-ets/utils/constant/style.ets +88 -0
- package/dist/components-harmony-ets/utils/events.ts +24 -0
- package/dist/components-harmony-ets/utils/flexManager.ets +107 -0
- package/dist/components-harmony-ets/utils/helper.ets +99 -0
- package/dist/components-harmony-ets/utils/htmlParser/HarmonyHTMLParser.ts +103 -0
- package/dist/components-harmony-ets/utils/htmlParser/index.ts +56 -0
- package/dist/components-harmony-ets/utils/index.ts +83 -0
- package/dist/components-harmony-ets/utils/styles.ets +91 -0
- package/dist/components-harmony-ets/video.ets +161 -0
- package/dist/components-harmony-ets/view.ets +79 -0
- package/dist/index.js +1183 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime-ets/bom/document.ts +38 -0
- package/dist/runtime-ets/bom/getComputedStyle.ts +5 -0
- package/dist/runtime-ets/bom/navigator.ts +21 -0
- package/dist/runtime-ets/bom/raf.ts +37 -0
- package/dist/runtime-ets/bom/window.ts +44 -0
- package/dist/runtime-ets/constant.ts +29 -0
- package/dist/runtime-ets/current.ts +16 -0
- package/dist/runtime-ets/dom/class-list.ts +117 -0
- package/dist/runtime-ets/dom/comment.ts +10 -0
- package/dist/runtime-ets/dom/cssStyleDeclaration.ts +105 -0
- package/dist/runtime-ets/dom/document.ts +108 -0
- package/dist/runtime-ets/dom/element.ts +457 -0
- package/dist/runtime-ets/dom/event.ts +164 -0
- package/dist/runtime-ets/dom/eventTarget.ts +98 -0
- package/dist/runtime-ets/dom/node.ts +215 -0
- package/dist/runtime-ets/dom/stylesheet/index.ts +687 -0
- package/dist/runtime-ets/dom/stylesheet/type.ts +136 -0
- package/dist/runtime-ets/dom/stylesheet/util.ts +134 -0
- package/dist/runtime-ets/dom/text.ts +19 -0
- package/dist/runtime-ets/index.ts +19 -0
- package/dist/runtime-ets/interface/event.ts +9 -0
- package/dist/runtime-ets/interface/index.ts +1 -0
- package/dist/runtime-ets/utils/bind.ts +35 -0
- package/dist/runtime-ets/utils/index.ts +135 -0
- package/dist/runtime-ets/utils/info.ts +128 -0
- package/dist/runtime-framework/react/app.ts +256 -0
- package/dist/runtime-framework/react/connect.ts +24 -0
- package/dist/runtime-framework/react/constant.ts +5 -0
- package/dist/runtime-framework/react/hooks.ts +101 -0
- package/dist/runtime-framework/react/index.ts +16 -0
- package/dist/runtime-framework/react/page.ts +263 -0
- package/dist/runtime-framework/react/utils/index.ts +25 -0
- package/dist/runtime-framework/react/utils/is.ts +46 -0
- package/dist/runtime-framework/solid/README.md +99 -0
- package/dist/runtime-framework/solid/app.ts +200 -0
- package/dist/runtime-framework/solid/connect.ts +11 -0
- package/dist/runtime-framework/solid/contant.ts +5 -0
- package/dist/runtime-framework/solid/hooks.ts +88 -0
- package/dist/runtime-framework/solid/index.ts +10 -0
- package/dist/runtime-framework/solid/page.ts +202 -0
- package/dist/runtime-framework/solid/reconciler/h.ts +132 -0
- package/dist/runtime-framework/solid/reconciler/index.ts +3 -0
- package/dist/runtime-framework/solid/reconciler/props.ts +151 -0
- package/dist/runtime-framework/solid/reconciler/render.ts +61 -0
- package/dist/runtime-framework/solid/reconciler/use.ts +8 -0
- package/dist/runtime-framework/solid/utils/index.ts +49 -0
- package/dist/runtime-framework/solid/utils/is.ts +46 -0
- package/dist/runtime-utils.js +4149 -0
- package/dist/runtime-utils.js.map +1 -0
- package/dist/runtime.js +4150 -0
- package/dist/runtime.js.map +1 -0
- package/dist/template/container.js +7 -0
- package/index.js +4 -0
- package/package.json +54 -0
- package/types/api.d.ts +4 -0
- package/types/component.d.ts +4 -0
- package/types/harmony.d.ts +11 -0
- package/types/runtime.d.ts +15 -0
- package/types/taro.d.ts +7 -0
- package/types/webpack-sources.d.ts +108 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* 鸿蒙SDK API Version 6
|
|
4
|
+
* 将页面滚动到目标位置
|
|
5
|
+
* - 支持选择器(只支持id选择器和 class 选择器,暂不支持子选择器、后代选择器、跨自定义组件选择器、多选择器并集)
|
|
6
|
+
* - 滚动距离
|
|
7
|
+
* 文档地址 https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-framework-syntax-js-0000000000611432
|
|
8
|
+
*/
|
|
9
|
+
import { AREA_CHANGE_EVENT_NAME, Current, findChildNodeWithDFS, getPageScrollerOrNode, setNodeEventCallbackAndTriggerComponentUpdate } from '@tarojs/runtime'
|
|
10
|
+
import { pxTransformHelper } from '@tarojs/taro'
|
|
11
|
+
|
|
12
|
+
import { callAsyncFail, callAsyncSuccess } from '../utils'
|
|
13
|
+
|
|
14
|
+
import type Taro from '@tarojs/api'
|
|
15
|
+
|
|
16
|
+
// TODO
|
|
17
|
+
export const getCurrentPages = () => []
|
|
18
|
+
|
|
19
|
+
export const pageScrollTo: typeof Taro.pageScrollTo = (options) => {
|
|
20
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
21
|
+
return new Promise(async (resolve, reject) => {
|
|
22
|
+
const taro = (Current as any).taro
|
|
23
|
+
const page = taro.getCurrentInstance().page
|
|
24
|
+
const res = { errMsg: 'pageScrollTo:ok' }
|
|
25
|
+
const error = { errMsg: 'pageScrollTo:fail' }
|
|
26
|
+
const { scrollTop, selector = '', duration = 300, offsetTop = 0 } = options
|
|
27
|
+
|
|
28
|
+
if (scrollTop && selector) {
|
|
29
|
+
console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let scrollValue = -1
|
|
33
|
+
let scroller = page.scroller
|
|
34
|
+
const currentPageNode = getPageScrollerOrNode(page.node, page)
|
|
35
|
+
|
|
36
|
+
if (scrollTop || typeof scrollTop === 'number') {
|
|
37
|
+
scrollValue = scrollTop
|
|
38
|
+
} else if (selector) {
|
|
39
|
+
const node = findChildNodeWithDFS(currentPageNode, selector)
|
|
40
|
+
|
|
41
|
+
if (!node || !node._instance) return
|
|
42
|
+
|
|
43
|
+
const instance = node._instance
|
|
44
|
+
const id = node?._nid
|
|
45
|
+
|
|
46
|
+
// 获取 areaInfo,需要先调用 setNodeEventCallbackAndTriggerComponentUpdate 更新一次组件并获取组件信息
|
|
47
|
+
await setNodeEventCallbackAndTriggerComponentUpdate(node, AREA_CHANGE_EVENT_NAME, null, true)
|
|
48
|
+
|
|
49
|
+
const { areaInfo } = instance?.nodeInfoMap?.[id] || {}
|
|
50
|
+
|
|
51
|
+
let parent = node?.parentNode
|
|
52
|
+
while (!!parent && parent !== currentPageNode) {
|
|
53
|
+
if (parent?._instance?.scroller) {
|
|
54
|
+
scroller = parent._instance.scroller
|
|
55
|
+
break
|
|
56
|
+
}
|
|
57
|
+
parent = parent?.parentNode
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
scroller = getPageScrollerOrNode(scroller, page)
|
|
61
|
+
|
|
62
|
+
const { yOffset } = scroller.currentOffset()
|
|
63
|
+
|
|
64
|
+
if (areaInfo) {
|
|
65
|
+
scrollValue = areaInfo.globalPosition.y + yOffset + pxTransformHelper(offsetTop, 'px', true)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const { xOffset } = scroller.currentOffset()
|
|
69
|
+
|
|
70
|
+
if (scrollValue === -1) {
|
|
71
|
+
return callAsyncFail(reject, { errMsg: 'pageScrollTo:fail, 请检查传入的 scrollTop 或 selector 是否合法' }, options)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
scroller.scrollTo({
|
|
76
|
+
xOffset,
|
|
77
|
+
yOffset: scrollValue,
|
|
78
|
+
animation: {
|
|
79
|
+
duration: duration,
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
curve: Curve.Linear
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
callAsyncSuccess(resolve, res, options)
|
|
87
|
+
}, duration)
|
|
88
|
+
} catch (_) {
|
|
89
|
+
callAsyncFail(reject, error, options)
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import router from '@ohos.router'
|
|
2
|
+
// eslint-disable-next-line import/no-duplicates
|
|
3
|
+
import { window } from '@tarojs/runtime'
|
|
4
|
+
// eslint-disable-next-line import/no-duplicates
|
|
5
|
+
import { eventCenter } from '@tarojs/runtime/dist/runtime.esm'
|
|
6
|
+
import { queryToJson } from '@tarojs/shared'
|
|
7
|
+
|
|
8
|
+
import { callAsyncFail, callAsyncSuccess } from '../utils'
|
|
9
|
+
import { IAsyncParams } from '../utils/types'
|
|
10
|
+
|
|
11
|
+
import type Taro from '@tarojs/api'
|
|
12
|
+
|
|
13
|
+
const launchOptions: Taro.getLaunchOptionsSync.LaunchOptions = {
|
|
14
|
+
path: '',
|
|
15
|
+
query: {},
|
|
16
|
+
scene: 0,
|
|
17
|
+
shareTicket: '',
|
|
18
|
+
referrerInfo: {}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function initLaunchOptions (options = {}) {
|
|
22
|
+
Object.assign(launchOptions, options)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
eventCenter.once('__taroRouterLaunch', initLaunchOptions)
|
|
26
|
+
|
|
27
|
+
const TARO_TABBAR_PAGE_PATH = 'taro_tabbar'
|
|
28
|
+
function isTabPage (url: string): boolean {
|
|
29
|
+
return window.__taroAppConfig.tabBar?.list?.some(item => item.pagePath === url)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function parseURL (raw = ''): [string, Record<string, unknown>] {
|
|
33
|
+
const [urlStr, queryStr = ''] = raw.split('?')
|
|
34
|
+
const query: Record<string, unknown> = queryToJson(queryStr)
|
|
35
|
+
let url = urlStr.replace(/^\//, '')
|
|
36
|
+
if (isTabPage(url)) {
|
|
37
|
+
query.$page = url
|
|
38
|
+
url = TARO_TABBAR_PAGE_PATH
|
|
39
|
+
}
|
|
40
|
+
return [url, query]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 生命周期
|
|
44
|
+
export const getLaunchOptionsSync = () => launchOptions
|
|
45
|
+
export const getEnterOptionsSync = () => launchOptions
|
|
46
|
+
|
|
47
|
+
const getRouterFunc = (method): typeof Taro.navigateTo => {
|
|
48
|
+
const methodName = method === 'navigateTo' ? 'pushUrl' : 'replaceUrl'
|
|
49
|
+
|
|
50
|
+
return function (options) {
|
|
51
|
+
const [url, params = {}] = parseURL(options.url)
|
|
52
|
+
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
router[methodName]({
|
|
55
|
+
url,
|
|
56
|
+
params
|
|
57
|
+
}, (error) => {
|
|
58
|
+
const res: { code?: number, errMsg: string } = { errMsg: `${method}:ok` }
|
|
59
|
+
if (error) {
|
|
60
|
+
const { code, message } = error
|
|
61
|
+
res.code = code
|
|
62
|
+
res.errMsg = `${method}:failed, ${message}`
|
|
63
|
+
callAsyncFail(reject, res, options)
|
|
64
|
+
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
callAsyncSuccess(resolve, res, options)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const navigateTo = getRouterFunc('navigateTo')
|
|
75
|
+
export const redirectTo = getRouterFunc('redirectTo')
|
|
76
|
+
|
|
77
|
+
interface INavigateBackParams extends IAsyncParams {
|
|
78
|
+
url?: string
|
|
79
|
+
}
|
|
80
|
+
export function navigateBack (options: INavigateBackParams): Promise<any> {
|
|
81
|
+
return new Promise(resolve => {
|
|
82
|
+
if (!options?.url) {
|
|
83
|
+
router.back()
|
|
84
|
+
} else {
|
|
85
|
+
const [url] = parseURL(options.url)
|
|
86
|
+
router.back({ url })
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const res = { errMsg: 'navigateBack:ok' }
|
|
90
|
+
callAsyncSuccess(resolve, res, options)
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const reLaunch: typeof Taro.reLaunch = (options) => {
|
|
95
|
+
return new Promise(resolve => {
|
|
96
|
+
redirectTo({ url: options.url })
|
|
97
|
+
router.clear()
|
|
98
|
+
const res = { errMsg: 'reLaunch:ok' }
|
|
99
|
+
callAsyncSuccess(resolve, res, options)
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const switchTab: typeof Taro.switchTab = (options) => {
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
const stack = AppStorage.prop('__TARO_PAGE_STACK').get()
|
|
106
|
+
const [url, params] = parseURL(options.url)
|
|
107
|
+
|
|
108
|
+
if (url !== TARO_TABBAR_PAGE_PATH) {
|
|
109
|
+
const res = { errMsg: 'switchTab:failed' }
|
|
110
|
+
callAsyncFail(reject, res, options)
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (stack[stack.length - 1]?.path === url) {
|
|
115
|
+
// Note: 当前为 Tab 页时,触发 switch 事件
|
|
116
|
+
eventCenter.trigger('__taroSwitchTab', { url, params })
|
|
117
|
+
router.getLength() > 1 && router.clear()
|
|
118
|
+
} else if (stack.some(item => item.path === url)) {
|
|
119
|
+
// Note: 寻找路由栈中的 Tab 页,如果找到,则使用 navigateBack
|
|
120
|
+
router.back({ url, params })
|
|
121
|
+
router.getLength() > 1 && router.clear()
|
|
122
|
+
} else {
|
|
123
|
+
// Note: 未找到页面时,使用 reLaunch
|
|
124
|
+
reLaunch({ url: options.url })
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const res = { errMsg: 'switchTab:ok' }
|
|
128
|
+
callAsyncSuccess(resolve, res, options)
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const getLength = () => {
|
|
133
|
+
return router.getLength()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export const getState = () => {
|
|
137
|
+
return router.getState()
|
|
138
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 从API Version 6开始,该模块不再维护,可以使用模块@ohos.data.storage。在API Version 9后,推荐使用新模块@ohos.data.preferences。
|
|
3
|
+
* https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/js-apis-data-preferences-0000001427745052-V3
|
|
4
|
+
*/
|
|
5
|
+
import bundleManager from '@ohos.bundle.bundleManager'
|
|
6
|
+
import dataPreferences from '@ohos.data.preferences'
|
|
7
|
+
import hilog from '@ohos.hilog'
|
|
8
|
+
import { Current } from '@tarojs/runtime'
|
|
9
|
+
|
|
10
|
+
import { callAsyncFail, callAsyncSuccess, temporarilyNotSupport, validateParams } from '../utils'
|
|
11
|
+
|
|
12
|
+
import type { IAsyncParams } from '../utils/types'
|
|
13
|
+
|
|
14
|
+
interface IGetStorageParams extends IAsyncParams {
|
|
15
|
+
key: string
|
|
16
|
+
}
|
|
17
|
+
interface ISetStorageParams extends IAsyncParams {
|
|
18
|
+
key: string
|
|
19
|
+
data: number | string | boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface IRemoveStorageParams extends IAsyncParams {
|
|
23
|
+
key: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const preferencesPromise = (Current as any).contextPromise
|
|
27
|
+
.then((context) => {
|
|
28
|
+
return bundleManager
|
|
29
|
+
.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION)
|
|
30
|
+
.then(data => {
|
|
31
|
+
return dataPreferences
|
|
32
|
+
.getPreferences(context, `${data.appInfo.uid}Store`)
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
.catch((error) => {
|
|
36
|
+
hilog.error(0x0000, 'TaroFailedTag', 'Failed to load the storage. Cause: %{public}s', error.code ? JSON.stringify(error) : error.message || error)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
async function getItem (key: string): Promise<{ result: boolean, data?: number | string | boolean }> {
|
|
40
|
+
try {
|
|
41
|
+
const preferences = await preferencesPromise
|
|
42
|
+
const item = await preferences.get(key, null)
|
|
43
|
+
|
|
44
|
+
return { result: true, data: item }
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return { result: false }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const storageSchema = {
|
|
51
|
+
key: 'String'
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function getStorage (options: IGetStorageParams) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
try {
|
|
57
|
+
validateParams('getStorage', options, storageSchema)
|
|
58
|
+
} catch (error) {
|
|
59
|
+
const res = { errMsg: error.message }
|
|
60
|
+
return callAsyncFail(reject, res, options)
|
|
61
|
+
}
|
|
62
|
+
getItem(options.key).then(({ result, data }) => {
|
|
63
|
+
const res: Record<string, any> = { errMsg: 'getStorage:ok' }
|
|
64
|
+
|
|
65
|
+
if (result) {
|
|
66
|
+
res.data = data
|
|
67
|
+
callAsyncSuccess(resolve, res, options)
|
|
68
|
+
} else {
|
|
69
|
+
res.errMsg = 'getStorage:fail data not found'
|
|
70
|
+
callAsyncFail(reject, res, options)
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function setStorage (options: ISetStorageParams) {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
try {
|
|
79
|
+
validateParams('setStorage', options, storageSchema)
|
|
80
|
+
} catch (error) {
|
|
81
|
+
const res = { errMsg: error.message }
|
|
82
|
+
return callAsyncFail(reject, res, options)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const { key, data } = options
|
|
86
|
+
const res = { errMsg: 'setStorage:ok' }
|
|
87
|
+
|
|
88
|
+
preferencesPromise.then(async (preferences) => {
|
|
89
|
+
await preferences.put(key, data)
|
|
90
|
+
await preferences.flush()
|
|
91
|
+
|
|
92
|
+
callAsyncSuccess(resolve, res, options)
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function removeStorage (options: IRemoveStorageParams) {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
try {
|
|
100
|
+
validateParams('removeStorage', options, storageSchema)
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const res = { errMsg: error.message }
|
|
103
|
+
return callAsyncFail(reject, res, options)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const { key } = options
|
|
107
|
+
|
|
108
|
+
preferencesPromise.then(async (preferences) => {
|
|
109
|
+
await preferences.delete(key)
|
|
110
|
+
await preferences.flush()
|
|
111
|
+
|
|
112
|
+
const res = { errMsg: 'removeStorage:ok' }
|
|
113
|
+
callAsyncSuccess(resolve, res, options)
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function clearStorage (options: IAsyncParams) {
|
|
119
|
+
return new Promise(resolve => {
|
|
120
|
+
preferencesPromise.then(async (preferences) => {
|
|
121
|
+
await preferences.clear()
|
|
122
|
+
await preferences.flush()
|
|
123
|
+
|
|
124
|
+
const res = { errMsg: 'clearStorage:ok' }
|
|
125
|
+
callAsyncSuccess(resolve, res, options)
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const getStorageSync = temporarilyNotSupport('getStorageSync', 'getStorage')
|
|
131
|
+
export const setStorageSync = temporarilyNotSupport('setStorageSync', 'setStorage')
|
|
132
|
+
export const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clearStorage')
|
|
133
|
+
export const removeStorageSync = temporarilyNotSupport('removeStorageSync', 'removeStorage')
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-duplicates
|
|
2
|
+
import { Current } from '@tarojs/runtime'
|
|
3
|
+
// eslint-disable-next-line import/no-duplicates
|
|
4
|
+
import { eventCenter } from '@tarojs/runtime/dist/runtime.esm'
|
|
5
|
+
|
|
6
|
+
import { callAsyncFail, callAsyncSuccess } from '../utils'
|
|
7
|
+
|
|
8
|
+
import type Taro from '@tarojs/api'
|
|
9
|
+
|
|
10
|
+
interface ShowTabBar {
|
|
11
|
+
type: 'show'
|
|
12
|
+
fn: typeof Taro.showTabBar
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface HideTabBar {
|
|
16
|
+
type: 'hide'
|
|
17
|
+
fn: typeof Taro.hideTabBar
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type ToggleAPIs = ShowTabBar | HideTabBar
|
|
21
|
+
|
|
22
|
+
const toggleTabBar = function<T extends ToggleAPIs['type']> (type: T): Extract<ToggleAPIs, {type: T}>['fn'] {
|
|
23
|
+
return function (options) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const taro = (Current as any).taro
|
|
26
|
+
const page = taro.getCurrentInstance().page
|
|
27
|
+
const currentData = page._data?.taroTabBar || page.tabBar
|
|
28
|
+
const res = { errMsg: `${type}TabBar:ok` }
|
|
29
|
+
const error = { errMsg: `${type}TabBar:fail not TabBar page` }
|
|
30
|
+
|
|
31
|
+
if (!currentData) {
|
|
32
|
+
callAsyncFail(reject, error, options)
|
|
33
|
+
} else {
|
|
34
|
+
const isShow = type === 'show'
|
|
35
|
+
const event = isShow ? '__taroShowTabBar' : '__taroHideTabBar'
|
|
36
|
+
eventCenter.trigger(event, {
|
|
37
|
+
animation: options?.animation,
|
|
38
|
+
})
|
|
39
|
+
page.$set?.('isShowTaroTabBar', isShow)
|
|
40
|
+
callAsyncSuccess(resolve, res, options)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const showTabBar = toggleTabBar('show')
|
|
47
|
+
|
|
48
|
+
export const hideTabBar = toggleTabBar('hide')
|
|
49
|
+
|
|
50
|
+
export const setTabBarStyle: typeof Taro.setTabBarStyle = function (options = {}) {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const taro = (Current as any).taro
|
|
53
|
+
const page = taro.getCurrentInstance().page
|
|
54
|
+
const currentData = page._data?.taroTabBar || page.tabBar
|
|
55
|
+
const res = { errMsg: 'setTabBarStyle:ok' }
|
|
56
|
+
const error = { errMsg: 'setTabBarStyle:fail not TabBar page' }
|
|
57
|
+
|
|
58
|
+
if (!currentData) {
|
|
59
|
+
callAsyncFail(reject, error, options)
|
|
60
|
+
} else {
|
|
61
|
+
const data = Object.assign({}, currentData)
|
|
62
|
+
|
|
63
|
+
if (options.color) data.color = options.color
|
|
64
|
+
if (options.selectedColor) data.selectedColor = options.selectedColor
|
|
65
|
+
if (options.backgroundColor) data.backgroundColor = options.backgroundColor
|
|
66
|
+
if (options.borderStyle) data.borderStyle = options.borderStyle
|
|
67
|
+
|
|
68
|
+
eventCenter.trigger('__taroSetTabBarStyle', options)
|
|
69
|
+
page.$set?.('taroTabBar', data)
|
|
70
|
+
callAsyncSuccess(resolve, res, options)
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const setTabBarItem: typeof Taro.setTabBarItem = function (options) {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const taro = (Current as any).taro
|
|
78
|
+
const page = taro.getCurrentInstance().page
|
|
79
|
+
const currentData = page._data?.taroTabBar || page.tabBar
|
|
80
|
+
const res = { errMsg: 'setTabBarItem:ok' }
|
|
81
|
+
const error = { errMsg: 'setTabBarItem:fail not TabBar page' }
|
|
82
|
+
|
|
83
|
+
if (!currentData) {
|
|
84
|
+
callAsyncFail(reject, error, options)
|
|
85
|
+
} else {
|
|
86
|
+
const index = options.index
|
|
87
|
+
const item = Object.assign({}, currentData.list[index])
|
|
88
|
+
|
|
89
|
+
if (options.text) item.text = options.text
|
|
90
|
+
if (options.iconPath) item.iconPath = options.iconPath
|
|
91
|
+
if (options.selectedIconPath) item.selectedIconPath = options.selectedIconPath
|
|
92
|
+
|
|
93
|
+
const list = [
|
|
94
|
+
...currentData.list.slice(0, index),
|
|
95
|
+
item,
|
|
96
|
+
...currentData.list.slice(index + 1)
|
|
97
|
+
]
|
|
98
|
+
const data = Object.assign({}, currentData, { list })
|
|
99
|
+
|
|
100
|
+
eventCenter.trigger('__taroSetTabBarItem', options)
|
|
101
|
+
page.$set?.('taroTabBar', data)
|
|
102
|
+
callAsyncSuccess(resolve, res, options)
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function showTabBarRedDot (options) {
|
|
108
|
+
const res = { errMsg: 'showTabBarRedDot:ok' }
|
|
109
|
+
return new Promise((resolve) => {
|
|
110
|
+
eventCenter.trigger('__taroShowTabBarRedDotHandler', {
|
|
111
|
+
index: options?.index || 0,
|
|
112
|
+
})
|
|
113
|
+
callAsyncSuccess(resolve, res, options)
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function hideTabBarRedDot (options) {
|
|
118
|
+
const res = { errMsg: 'hideTabBarRedDot:ok' }
|
|
119
|
+
return new Promise((resolve) => {
|
|
120
|
+
eventCenter.trigger('__taroHideTabBarRedDotHandler', {
|
|
121
|
+
index: options?.index || 0,
|
|
122
|
+
})
|
|
123
|
+
callAsyncSuccess(resolve, res, options)
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function setTabBarBadge (options) {
|
|
128
|
+
const res = { errMsg: 'setTabBarBadge:ok' }
|
|
129
|
+
return new Promise((resolve) => {
|
|
130
|
+
const text = options?.text || ''
|
|
131
|
+
eventCenter.trigger('__taroSetTabBarBadge', {
|
|
132
|
+
index: options?.index || 0,
|
|
133
|
+
text: text.replace(/[\u0391-\uFFE5]/g, 'aa').length > 4 ? '...' : text,
|
|
134
|
+
})
|
|
135
|
+
callAsyncSuccess(resolve, res, options)
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function removeTabBarBadge (options) {
|
|
140
|
+
const res = { errMsg: 'removeTabBarBadge:ok' }
|
|
141
|
+
return new Promise((resolve) => {
|
|
142
|
+
eventCenter.trigger('__taroRemoveTabBarBadge', {
|
|
143
|
+
index: options?.index || 0,
|
|
144
|
+
})
|
|
145
|
+
callAsyncSuccess(resolve, res, options)
|
|
146
|
+
})
|
|
147
|
+
}
|