@tarojs/taro-h5 3.4.0 → 3.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/ai/visual.js +2 -0
- package/dist/api/base/system.js +187 -0
- package/dist/api/canvas/CanvasContext.js +1 -1
- package/dist/api/canvas/index.js +5 -1
- package/dist/api/cloud/index.js +4 -0
- package/dist/api/device/battery.js +18 -1
- package/dist/api/device/index.js +1 -0
- package/dist/api/{base/system → device}/network.js +29 -14
- package/dist/api/device/wifi.js +1 -0
- package/dist/api/media/{editor.js → EditorContext.js} +1 -0
- package/dist/api/media/audio/InnerAudioContext.js +84 -0
- package/dist/api/media/audio/index.js +1 -74
- package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
- package/dist/api/media/{background-audio.js → background-audio/index.js} +6 -2
- package/dist/api/media/index.js +0 -1
- package/dist/api/network/upload.js +2 -7
- package/dist/api/ui/animation/index.js +9 -5
- package/dist/api/ui/fonts.js +50 -2
- package/dist/api/ui/scroll/index.js +3 -3
- package/dist/api/utils/handler.js +45 -45
- package/dist/api/utils/index.js +36 -12
- package/dist/index.cjs.js +517 -188
- package/dist/taroApis.js +1 -1
- package/package.json +7 -7
- package/src/api/ai/visual.ts +3 -0
- package/src/api/base/system.ts +207 -0
- package/src/api/canvas/CanvasContext.ts +7 -7
- package/src/api/canvas/index.ts +10 -2
- package/src/api/cloud/index.ts +4 -0
- package/src/api/device/battery.ts +18 -1
- package/src/api/device/index.ts +1 -0
- package/src/api/{base/system → device}/network.ts +35 -15
- package/src/api/device/wifi.ts +1 -0
- package/src/api/media/{editor.ts → EditorContext.ts} +2 -0
- package/src/api/media/audio/InnerAudioContext.ts +98 -0
- package/src/api/media/audio/index.ts +1 -86
- package/src/api/media/background-audio/BackgroundAudioManager.ts +103 -0
- package/src/api/media/{background-audio.ts → background-audio/index.ts} +7 -2
- package/src/api/media/index.ts +0 -1
- package/src/api/network/upload.ts +2 -8
- package/src/api/ui/animation/index.ts +10 -6
- package/src/api/ui/fonts.ts +61 -2
- package/src/api/ui/scroll/index.ts +3 -3
- package/src/api/utils/handler.ts +4 -4
- package/src/api/utils/index.ts +33 -12
- package/dist/api/base/system/index.js +0 -2
- package/dist/api/base/system/info.js +0 -57
- package/src/api/base/system/index.ts +0 -2
- package/src/api/base/system/info.ts +0 -64
|
@@ -1,93 +1,8 @@
|
|
|
1
1
|
import Taro from '@tarojs/api'
|
|
2
2
|
import { temporarilyNotSupport } from '../../utils'
|
|
3
|
-
import {
|
|
3
|
+
import { InnerAudioContext } from './InnerAudioContext'
|
|
4
4
|
|
|
5
5
|
// 音频
|
|
6
|
-
class InnerAudioContext implements Taro.InnerAudioContext {
|
|
7
|
-
Instance?: HTMLAudioElement
|
|
8
|
-
errorStack: CallbackManager
|
|
9
|
-
stopStack: CallbackManager
|
|
10
|
-
|
|
11
|
-
constructor () {
|
|
12
|
-
this.Instance = new Audio()
|
|
13
|
-
this.errorStack = new CallbackManager()
|
|
14
|
-
this.stopStack = new CallbackManager()
|
|
15
|
-
|
|
16
|
-
Taro.eventCenter.on('__taroRouterChange', () => { this.stop() })
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
set autoplay (e) { this.setProperty('autoplay', e) }
|
|
20
|
-
get autoplay () { return this.Instance?.autoplay || false }
|
|
21
|
-
get buffered () { return this.Instance?.buffered.length || 0 }
|
|
22
|
-
get currentTime () { return this.Instance?.currentTime || 0 }
|
|
23
|
-
get duration () { return this.Instance?.duration || 0 }
|
|
24
|
-
set loop (e) { this.setProperty('loop', e) }
|
|
25
|
-
get loop () { return this.Instance?.loop || false }
|
|
26
|
-
get paused () { return this.Instance?.paused || true }
|
|
27
|
-
set src (e) { this.setProperty('src', e) }
|
|
28
|
-
get src () { return this.Instance?.src || '' }
|
|
29
|
-
set volume (e) { this.setProperty('volume', e) }
|
|
30
|
-
get volume () { return this.Instance?.volume || 0 }
|
|
31
|
-
set playbackRate (e) { this.setProperty('playbackRate', e) }
|
|
32
|
-
get playbackRate () { return this.Instance?.volume || 0 }
|
|
33
|
-
get obeyMuteSwitch () { return true }
|
|
34
|
-
set startTime (e) { this.setProperty('startTime', e) }
|
|
35
|
-
get startTime () { return this.Instance?.volume || 0 }
|
|
36
|
-
|
|
37
|
-
private setProperty (key: string, value: unknown) {
|
|
38
|
-
if (this.Instance) {
|
|
39
|
-
this.Instance[key] = value
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
play = () => this.Instance?.play()
|
|
44
|
-
|
|
45
|
-
pause = () => this.Instance?.pause()
|
|
46
|
-
|
|
47
|
-
stop = () => {
|
|
48
|
-
this.pause()
|
|
49
|
-
this.seek(0)
|
|
50
|
-
this.stopStack.trigger()
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
seek = (position: number) => {
|
|
54
|
-
if (this.Instance) {
|
|
55
|
-
this.Instance.currentTime = position
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @TODO destroy得并不干净
|
|
61
|
-
*/
|
|
62
|
-
destroy = () => {
|
|
63
|
-
this.stop()
|
|
64
|
-
if (this.Instance) {
|
|
65
|
-
document.body.removeChild(this.Instance)
|
|
66
|
-
this.Instance = undefined
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
onCanplay = (callback = () => {}) => this.Instance?.addEventListener('canplay', callback)
|
|
71
|
-
onPlay = (callback = () => {}) => this.Instance?.addEventListener('play', callback)
|
|
72
|
-
onPause = (callback = () => {}) => this.Instance?.addEventListener('pause', callback)
|
|
73
|
-
onStop = (callback = () => {}) => this.stopStack.add(callback)
|
|
74
|
-
onEnded = (callback = () => {}) => this.Instance?.addEventListener('ended', callback)
|
|
75
|
-
onTimeUpdate = (callback = () => {}) => this.Instance?.addEventListener('timeupdate', callback)
|
|
76
|
-
onError = (callback?: ((res: Taro.InnerAudioContext.onErrorDetail) => void)) => this.errorStack.add(callback)
|
|
77
|
-
onWaiting = (callback = () => {}) => this.Instance?.addEventListener('waiting', callback)
|
|
78
|
-
onSeeking = (callback = () => {}) => this.Instance?.addEventListener('seeking', callback)
|
|
79
|
-
onSeeked = (callback = () => {}) => this.Instance?.addEventListener('seeked', callback)
|
|
80
|
-
offCanplay = (callback = () => {}) => this.Instance?.removeEventListener('canplay', callback)
|
|
81
|
-
offPlay = (callback = () => {}) => this.Instance?.removeEventListener('play', callback)
|
|
82
|
-
offPause = (callback = () => {}) => this.Instance?.removeEventListener('pause', callback)
|
|
83
|
-
offStop = (callback = () => {}) => this.stopStack.remove(callback)
|
|
84
|
-
offEnded = (callback = () => {}) => this.Instance?.removeEventListener('ended', callback)
|
|
85
|
-
offTimeUpdate = (callback = () => {}) => this.Instance?.removeEventListener('timeupdate', callback)
|
|
86
|
-
offError = (callback = () => {}) => this.errorStack.remove(callback)
|
|
87
|
-
offWaiting = (callback = () => {}) => this.Instance?.removeEventListener('waiting', callback)
|
|
88
|
-
offSeeking = (callback = () => {}) => this.Instance?.removeEventListener('seeking', callback)
|
|
89
|
-
offSeeked = (callback = () => {}) => this.Instance?.removeEventListener('seeked', callback)
|
|
90
|
-
}
|
|
91
6
|
|
|
92
7
|
export const stopVoice = temporarilyNotSupport('stopVoice')
|
|
93
8
|
export const setInnerAudioOption = temporarilyNotSupport('setInnerAudioOption')
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { permanentlyNotSupport } from '../../utils'
|
|
3
|
+
import { CallbackManager } from '../../utils/handler'
|
|
4
|
+
|
|
5
|
+
export class BackgroundAudioManager implements Taro.BackgroundAudioManager {
|
|
6
|
+
Instance?: HTMLAudioElement
|
|
7
|
+
errorStack: CallbackManager
|
|
8
|
+
stopStack: CallbackManager
|
|
9
|
+
__startTime = 0
|
|
10
|
+
|
|
11
|
+
constructor () {
|
|
12
|
+
this.Instance = new Audio()
|
|
13
|
+
this.errorStack = new CallbackManager()
|
|
14
|
+
this.stopStack = new CallbackManager()
|
|
15
|
+
this.Instance.autoplay = true
|
|
16
|
+
this.onPlay(() => {
|
|
17
|
+
if (this.currentTime !== this.startTime) {
|
|
18
|
+
this.seek(this.startTime)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
set src (e) { this.setProperty('src', e) }
|
|
24
|
+
get src () { return this.Instance?.src || '' }
|
|
25
|
+
set startTime (e) { this.__startTime = e }
|
|
26
|
+
get startTime () { return this.__startTime || 0 }
|
|
27
|
+
set title (e) { this.dataset('title', e) }
|
|
28
|
+
get title () { return this.Instance?.dataset.title || '' }
|
|
29
|
+
set epname (e) { this.dataset('epname', e) }
|
|
30
|
+
get epname () { return this.Instance?.dataset.epname || '' }
|
|
31
|
+
set singer (e) { this.dataset('singer', e) }
|
|
32
|
+
get singer () { return this.Instance?.dataset.singer || '' }
|
|
33
|
+
set coverImgUrl (e) { this.dataset('coverImgUrl', e) }
|
|
34
|
+
get coverImgUrl () { return this.Instance?.dataset.coverImgUrl || '' }
|
|
35
|
+
set webUrl (e) { this.dataset('webUrl', e) }
|
|
36
|
+
get webUrl () { return this.Instance?.dataset.webUrl || '' }
|
|
37
|
+
set protocol (e) { this.dataset('protocol', e) }
|
|
38
|
+
get protocol () { return this.Instance?.dataset.protocol || '' }
|
|
39
|
+
set playbackRate (e) { this.setProperty('playbackRate', e) }
|
|
40
|
+
get playbackRate () { return this.Instance?.playbackRate || 0 }
|
|
41
|
+
get duration () { return this.Instance?.duration || 0 }
|
|
42
|
+
get currentTime () { return this.Instance?.currentTime || 0 }
|
|
43
|
+
get paused () { return this.Instance?.paused || false }
|
|
44
|
+
get buffered () { return this.Instance?.buffered.length || 0 }
|
|
45
|
+
set referrerPolicy (e) { this.Instance?.setAttribute('referrerpolicy', e) }
|
|
46
|
+
get referrerPolicy () { return this.Instance?.getAttribute('referrerpolicy') || 'origin' }
|
|
47
|
+
|
|
48
|
+
private setProperty (key: string, value: unknown) {
|
|
49
|
+
if (this.Instance) {
|
|
50
|
+
this.Instance[key] = value
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private dataset (key: string, value: string) {
|
|
55
|
+
if (this.Instance) {
|
|
56
|
+
this.Instance.dataset[key] = value
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
play = () => this.Instance?.play()
|
|
61
|
+
|
|
62
|
+
pause = () => this.Instance?.pause()
|
|
63
|
+
|
|
64
|
+
seek = (position: number) => {
|
|
65
|
+
if (this.Instance) {
|
|
66
|
+
this.Instance.currentTime = position
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
stop = () => {
|
|
71
|
+
this.pause()
|
|
72
|
+
this.seek(0)
|
|
73
|
+
this.stopStack.trigger()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
onCanplay = (callback = () => {}) => this.Instance?.addEventListener('canplay', callback)
|
|
77
|
+
onWaiting = (callback = () => {}) => this.Instance?.addEventListener('waiting', callback)
|
|
78
|
+
onError = (callback?: ((res: Taro.InnerAudioContext.onErrorDetail) => void)) => this.errorStack.add(callback)
|
|
79
|
+
onPlay = (callback = () => {}) => this.Instance?.addEventListener('play', callback)
|
|
80
|
+
onPause = (callback = () => {}) => this.Instance?.addEventListener('pause', callback)
|
|
81
|
+
onSeeking = (callback = () => {}) => this.Instance?.addEventListener('seeking', callback)
|
|
82
|
+
onSeeked = (callback = () => {}) => this.Instance?.addEventListener('seeked', callback)
|
|
83
|
+
|
|
84
|
+
onEnded = (callback = () => {}) => this.Instance?.addEventListener('ended', callback)
|
|
85
|
+
onStop = (callback = () => {}) => this.stopStack.add(callback)
|
|
86
|
+
onTimeUpdate = (callback = () => {}) => this.Instance?.addEventListener('timeupdate', callback)
|
|
87
|
+
onPrev = permanentlyNotSupport('BackgroundAudioManager.onPrev')
|
|
88
|
+
onNext = permanentlyNotSupport('BackgroundAudioManager.onNext')
|
|
89
|
+
|
|
90
|
+
offCanplay = (callback = () => {}) => this.Instance?.removeEventListener('canplay', callback)
|
|
91
|
+
offWaiting = (callback = () => {}) => this.Instance?.removeEventListener('waiting', callback)
|
|
92
|
+
offError = (callback = () => {}) => this.errorStack.remove(callback)
|
|
93
|
+
offPlay = (callback = () => {}) => this.Instance?.removeEventListener('play', callback)
|
|
94
|
+
offPause = (callback = () => {}) => this.Instance?.removeEventListener('pause', callback)
|
|
95
|
+
offSeeking = (callback = () => {}) => this.Instance?.removeEventListener('seeking', callback)
|
|
96
|
+
offSeeked = (callback = () => {}) => this.Instance?.removeEventListener('seeked', callback)
|
|
97
|
+
|
|
98
|
+
offEnded = (callback = () => {}) => this.Instance?.removeEventListener('ended', callback)
|
|
99
|
+
offStop = (callback = () => {}) => this.stopStack.remove(callback)
|
|
100
|
+
offTimeUpdate = (callback = () => {}) => this.Instance?.removeEventListener('timeupdate', callback)
|
|
101
|
+
offPrev = permanentlyNotSupport('BackgroundAudioManager.offPrev')
|
|
102
|
+
offNext = permanentlyNotSupport('BackgroundAudioManager.offNext')
|
|
103
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { temporarilyNotSupport } from '
|
|
1
|
+
import { temporarilyNotSupport } from '../../utils'
|
|
2
|
+
import { BackgroundAudioManager } from './BackgroundAudioManager'
|
|
2
3
|
|
|
3
4
|
// 背景音频
|
|
4
5
|
export const stopBackgroundAudio = temporarilyNotSupport('stopBackgroundAudio')
|
|
@@ -9,4 +10,8 @@ export const onBackgroundAudioStop = temporarilyNotSupport('onBackgroundAudioSto
|
|
|
9
10
|
export const onBackgroundAudioPlay = temporarilyNotSupport('onBackgroundAudioPlay')
|
|
10
11
|
export const onBackgroundAudioPause = temporarilyNotSupport('onBackgroundAudioPause')
|
|
11
12
|
export const getBackgroundAudioPlayerState = temporarilyNotSupport('getBackgroundAudioPlayerState')
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 获取全局唯一的背景音频管理器
|
|
16
|
+
*/
|
|
17
|
+
export const getBackgroundAudioManager = () => new BackgroundAudioManager()
|
package/src/api/media/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Taro from '@tarojs/api'
|
|
2
|
-
import { temporarilyNotSupport } from '../utils'
|
|
3
2
|
import { CallbackManager } from '../utils/handler'
|
|
4
3
|
import {
|
|
5
4
|
convertObjectUrlToBlob,
|
|
@@ -8,7 +7,7 @@ import {
|
|
|
8
7
|
XHR_STATS
|
|
9
8
|
} from './utils'
|
|
10
9
|
|
|
11
|
-
const createUploadTask = ({ url, filePath, formData, name, header, timeout, fileName, success, error }): Taro.UploadTask => {
|
|
10
|
+
const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout, fileName, success, error }): Taro.UploadTask => {
|
|
12
11
|
let timeoutInter
|
|
13
12
|
let formKey
|
|
14
13
|
const apiName = 'uploadFile'
|
|
@@ -125,17 +124,12 @@ const createUploadTask = ({ url, filePath, formData, name, header, timeout, file
|
|
|
125
124
|
*/
|
|
126
125
|
const offProgressUpdate = callbackManager.progressUpdate.remove
|
|
127
126
|
|
|
128
|
-
const headersReceived = temporarilyNotSupport('UploadTask.headersReceived')
|
|
129
|
-
const progress = temporarilyNotSupport('UploadTask.progress')
|
|
130
|
-
|
|
131
127
|
return {
|
|
132
128
|
abort,
|
|
133
129
|
onHeadersReceived,
|
|
134
130
|
offHeadersReceived,
|
|
135
131
|
onProgressUpdate,
|
|
136
|
-
offProgressUpdate
|
|
137
|
-
headersReceived,
|
|
138
|
-
progress
|
|
132
|
+
offProgressUpdate
|
|
139
133
|
}
|
|
140
134
|
}
|
|
141
135
|
|
|
@@ -9,13 +9,17 @@ class StyleSheet {
|
|
|
9
9
|
this.$style = document.createElement('style')
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
$style
|
|
13
|
-
sheet?: CSSStyleSheet | null
|
|
12
|
+
$style?: HTMLStyleElement | null = null
|
|
13
|
+
sheet?: CSSStyleSheet | null = null
|
|
14
|
+
|
|
14
15
|
appendStyleSheet = () => {
|
|
15
|
-
this.$style
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
if (this.$style) {
|
|
17
|
+
const head = document.getElementsByTagName('head')[0]
|
|
18
|
+
this.$style.setAttribute('type', 'text/css')
|
|
19
|
+
this.$style.setAttribute('data-type', 'Taro')
|
|
20
|
+
head.appendChild(this.$style)
|
|
21
|
+
this.sheet = this.$style.sheet
|
|
22
|
+
}
|
|
19
23
|
if (this.sheet && !('insertRule' in this.sheet)) {
|
|
20
24
|
console.warn('当前浏览器不支持 stylesheet.insertRule 接口')
|
|
21
25
|
}
|
package/src/api/ui/fonts.ts
CHANGED
|
@@ -1,4 +1,63 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { MethodHandler } from '../utils/handler'
|
|
2
3
|
|
|
3
4
|
// 字体
|
|
4
|
-
export const loadFontFace =
|
|
5
|
+
export const loadFontFace: typeof Taro.loadFontFace = async options => {
|
|
6
|
+
options = Object.assign({ global: false }, options)
|
|
7
|
+
const { success, fail, complete, family, source, desc = {} } = options
|
|
8
|
+
const handle = new MethodHandler({ name: 'loadFontFace', success, fail, complete })
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const fonts = document.fonts
|
|
11
|
+
if (fonts) {
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
const fontFace = new FontFace(family, source, desc)
|
|
14
|
+
try {
|
|
15
|
+
await fontFace.load()
|
|
16
|
+
fonts.add(fontFace)
|
|
17
|
+
return handle.success({})
|
|
18
|
+
} catch (error) {
|
|
19
|
+
return handle.fail({
|
|
20
|
+
errMsg: error.message || error
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
const style = document.createElement('style')
|
|
25
|
+
let innerText = `font-family:"${
|
|
26
|
+
family
|
|
27
|
+
}";src:${
|
|
28
|
+
source
|
|
29
|
+
};font-style:${
|
|
30
|
+
desc.style || 'normal'
|
|
31
|
+
};font-weight:${
|
|
32
|
+
desc.weight || 'normal'
|
|
33
|
+
};font-variant:${
|
|
34
|
+
desc.variant || 'normal'
|
|
35
|
+
};`
|
|
36
|
+
|
|
37
|
+
if (desc.ascentOverride) {
|
|
38
|
+
innerText += `ascent-override:${desc.ascentOverride};`
|
|
39
|
+
}
|
|
40
|
+
if (desc.descentOverride) {
|
|
41
|
+
innerText += `descent-override:${desc.descentOverride};`
|
|
42
|
+
}
|
|
43
|
+
if (desc.featureSettings) {
|
|
44
|
+
innerText += `font-feature-settings:${desc.featureSettings};`
|
|
45
|
+
}
|
|
46
|
+
if (desc.lineGapOverride) {
|
|
47
|
+
innerText += `line-gap-override:${desc.lineGapOverride};`
|
|
48
|
+
}
|
|
49
|
+
if (desc.stretch) {
|
|
50
|
+
innerText += `font-stretch:${desc.stretch};`
|
|
51
|
+
}
|
|
52
|
+
if (desc.unicodeRange) {
|
|
53
|
+
innerText += `unicode-range:${desc.unicodeRange};`
|
|
54
|
+
}
|
|
55
|
+
if (desc.variationSettings) {
|
|
56
|
+
innerText += `font-variation-settings:${desc.variationSettings};`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
style.innerText = `@font-face{${innerText}}`
|
|
60
|
+
document.head.appendChild(style)
|
|
61
|
+
return handle.success()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -4,7 +4,7 @@ import { Current } from '@tarojs/runtime'
|
|
|
4
4
|
import { MethodHandler } from '../../utils/handler'
|
|
5
5
|
import { getTimingFunc, easeInOut } from '../../utils'
|
|
6
6
|
|
|
7
|
-
let timer:
|
|
7
|
+
let timer: NodeJS.Timer
|
|
8
8
|
const FRAME_DURATION = 17
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -21,9 +21,9 @@ export const pageScrollTo: typeof Taro.pageScrollTo = ({ scrollTop, selector = '
|
|
|
21
21
|
}, reject)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const id = Current.page?.path
|
|
24
|
+
const id = Current.page?.path?.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1')
|
|
25
25
|
const el: HTMLDivElement | null = (id
|
|
26
|
-
? document.
|
|
26
|
+
? document.querySelector(`.taro_page#${id}`)
|
|
27
27
|
: document.querySelector('.taro_page') ||
|
|
28
28
|
document.querySelector('.taro_router')) as HTMLDivElement
|
|
29
29
|
|
package/src/api/utils/handler.ts
CHANGED
|
@@ -58,7 +58,7 @@ export class CallbackManager {
|
|
|
58
58
|
* 添加回调
|
|
59
59
|
* @param {{ callback: function, ctx: any } | function} opt
|
|
60
60
|
*/
|
|
61
|
-
add (opt?: TCallbackManagerListItem) {
|
|
61
|
+
add = (opt?: TCallbackManagerListItem) => {
|
|
62
62
|
if (opt) this.callbacks.push(opt)
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -66,7 +66,7 @@ export class CallbackManager {
|
|
|
66
66
|
* 移除回调
|
|
67
67
|
* @param {{ callback: function, ctx: any } | function} opt
|
|
68
68
|
*/
|
|
69
|
-
remove (opt?: TCallbackManagerListItem) {
|
|
69
|
+
remove = (opt?: TCallbackManagerListItem) => {
|
|
70
70
|
if (opt) {
|
|
71
71
|
let pos = -1
|
|
72
72
|
this.callbacks.forEach((callback, k) => {
|
|
@@ -84,7 +84,7 @@ export class CallbackManager {
|
|
|
84
84
|
* 获取回调函数数量
|
|
85
85
|
* @return {number}
|
|
86
86
|
*/
|
|
87
|
-
count () {
|
|
87
|
+
count = () => {
|
|
88
88
|
return this.callbacks.length
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -92,7 +92,7 @@ export class CallbackManager {
|
|
|
92
92
|
* 触发回调
|
|
93
93
|
* @param {...any} args 回调的调用参数
|
|
94
94
|
*/
|
|
95
|
-
trigger (...args: TCallbackManagerList) {
|
|
95
|
+
trigger = (...args: TCallbackManagerList) => {
|
|
96
96
|
this.callbacks.forEach(opt => {
|
|
97
97
|
if (typeof opt === 'function') {
|
|
98
98
|
opt(...args)
|
package/src/api/utils/index.ts
CHANGED
|
@@ -88,30 +88,51 @@ export function serializeParams (params) {
|
|
|
88
88
|
export function temporarilyNotSupport (apiName) {
|
|
89
89
|
return () => {
|
|
90
90
|
const errMsg = `暂时不支持 API ${apiName}`
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
92
|
+
console.error(errMsg)
|
|
93
|
+
return Promise.reject({
|
|
94
|
+
errMsg
|
|
95
|
+
})
|
|
96
|
+
} else {
|
|
97
|
+
console.warn(errMsg)
|
|
98
|
+
return Promise.resolve({
|
|
99
|
+
errMsg
|
|
100
|
+
})
|
|
101
|
+
}
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
export function weixinCorpSupport (apiName) {
|
|
99
106
|
return () => {
|
|
100
107
|
const errMsg = `h5端仅在微信公众号中支持 API ${apiName}`
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
109
|
+
console.error(errMsg)
|
|
110
|
+
return Promise.reject({
|
|
111
|
+
errMsg
|
|
112
|
+
})
|
|
113
|
+
} else {
|
|
114
|
+
console.warn(errMsg)
|
|
115
|
+
return Promise.resolve({
|
|
116
|
+
errMsg
|
|
117
|
+
})
|
|
118
|
+
}
|
|
105
119
|
}
|
|
106
120
|
}
|
|
107
121
|
|
|
108
122
|
export function permanentlyNotSupport (apiName) {
|
|
109
123
|
return () => {
|
|
110
124
|
const errMsg = `不支持 API ${apiName}`
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
125
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
126
|
+
console.error(errMsg)
|
|
127
|
+
return Promise.reject({
|
|
128
|
+
errMsg
|
|
129
|
+
})
|
|
130
|
+
} else {
|
|
131
|
+
console.warn(errMsg)
|
|
132
|
+
return Promise.resolve({
|
|
133
|
+
errMsg
|
|
134
|
+
})
|
|
135
|
+
}
|
|
115
136
|
}
|
|
116
137
|
}
|
|
117
138
|
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import MobileDetect from 'mobile-detect';
|
|
2
|
-
import { MethodHandler } from '../../utils/handler';
|
|
3
|
-
export const getSystemInfoSync = () => {
|
|
4
|
-
const md = new MobileDetect(navigator.userAgent);
|
|
5
|
-
const info = {
|
|
6
|
-
brand: md.mobile() || '',
|
|
7
|
-
model: md.mobile() || '',
|
|
8
|
-
system: md.os(),
|
|
9
|
-
pixelRatio: window.devicePixelRatio,
|
|
10
|
-
screenWidth: window.screen.width,
|
|
11
|
-
screenHeight: window.screen.height,
|
|
12
|
-
windowWidth: document.documentElement.clientWidth,
|
|
13
|
-
windowHeight: document.documentElement.clientHeight,
|
|
14
|
-
version: '',
|
|
15
|
-
statusBarHeight: NaN,
|
|
16
|
-
platform: navigator.platform,
|
|
17
|
-
language: navigator.language,
|
|
18
|
-
fontSizeSetting: NaN,
|
|
19
|
-
SDKVersion: '',
|
|
20
|
-
// TODO
|
|
21
|
-
albumAuthorized: false,
|
|
22
|
-
benchmarkLevel: 0,
|
|
23
|
-
bluetoothEnabled: false,
|
|
24
|
-
cameraAuthorized: false,
|
|
25
|
-
enableDebug: false,
|
|
26
|
-
locationAuthorized: false,
|
|
27
|
-
locationEnabled: false,
|
|
28
|
-
microphoneAuthorized: false,
|
|
29
|
-
notificationAlertAuthorized: false,
|
|
30
|
-
notificationAuthorized: false,
|
|
31
|
-
notificationBadgeAuthorized: false,
|
|
32
|
-
notificationSoundAuthorized: false,
|
|
33
|
-
safeArea: {
|
|
34
|
-
bottom: 0,
|
|
35
|
-
height: 0,
|
|
36
|
-
left: 0,
|
|
37
|
-
right: 0,
|
|
38
|
-
top: 0,
|
|
39
|
-
width: 0
|
|
40
|
-
},
|
|
41
|
-
wifiEnabled: false
|
|
42
|
-
};
|
|
43
|
-
return info;
|
|
44
|
-
};
|
|
45
|
-
export const getSystemInfo = async (options = {}) => {
|
|
46
|
-
const { success, fail, complete } = options;
|
|
47
|
-
const handle = new MethodHandler({ name: 'getSystemInfo', success, fail, complete });
|
|
48
|
-
try {
|
|
49
|
-
const info = await getSystemInfoSync();
|
|
50
|
-
return handle.success(info);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
return handle.fail({
|
|
54
|
-
errMsg: error
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
import MobileDetect from 'mobile-detect'
|
|
3
|
-
|
|
4
|
-
import { MethodHandler } from '../../utils/handler'
|
|
5
|
-
|
|
6
|
-
export const getSystemInfoSync: typeof Taro.getSystemInfoSync = () => {
|
|
7
|
-
const md = new MobileDetect(navigator.userAgent)
|
|
8
|
-
|
|
9
|
-
const info: ReturnType<typeof Taro.getSystemInfoSync> = {
|
|
10
|
-
brand: md.mobile() || '', // 手机品牌
|
|
11
|
-
model: md.mobile() || '', // 手机型号
|
|
12
|
-
system: md.os(), // 操作系统版本
|
|
13
|
-
pixelRatio: window.devicePixelRatio, // 设备像素比
|
|
14
|
-
screenWidth: window.screen.width, // 屏幕宽度
|
|
15
|
-
screenHeight: window.screen.height, // 屏幕高度
|
|
16
|
-
windowWidth: document.documentElement.clientWidth, // 可使用窗口宽度
|
|
17
|
-
windowHeight: document.documentElement.clientHeight, // 可使用窗口高度
|
|
18
|
-
version: '', // 微信版本号
|
|
19
|
-
statusBarHeight: NaN, // 状态栏的高度
|
|
20
|
-
platform: navigator.platform, // 客户端平台
|
|
21
|
-
language: navigator.language, // 微信设置的语言
|
|
22
|
-
fontSizeSetting: NaN, // 用户字体大小设置。以“我-设置-通用-字体大小”中的设置为准,单位:px
|
|
23
|
-
SDKVersion: '', // 客户端基础库版本
|
|
24
|
-
|
|
25
|
-
// TODO
|
|
26
|
-
albumAuthorized: false,
|
|
27
|
-
benchmarkLevel: 0,
|
|
28
|
-
bluetoothEnabled: false,
|
|
29
|
-
cameraAuthorized: false,
|
|
30
|
-
enableDebug: false,
|
|
31
|
-
locationAuthorized: false,
|
|
32
|
-
locationEnabled: false,
|
|
33
|
-
microphoneAuthorized: false,
|
|
34
|
-
notificationAlertAuthorized: false,
|
|
35
|
-
notificationAuthorized: false,
|
|
36
|
-
notificationBadgeAuthorized: false,
|
|
37
|
-
notificationSoundAuthorized: false,
|
|
38
|
-
safeArea: {
|
|
39
|
-
bottom: 0,
|
|
40
|
-
height: 0,
|
|
41
|
-
left: 0,
|
|
42
|
-
right: 0,
|
|
43
|
-
top: 0,
|
|
44
|
-
width: 0
|
|
45
|
-
},
|
|
46
|
-
wifiEnabled: false
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return info
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const getSystemInfo: typeof Taro.getSystemInfo = async (options = {}) => {
|
|
53
|
-
const { success, fail, complete } = options
|
|
54
|
-
const handle = new MethodHandler({ name: 'getSystemInfo', success, fail, complete })
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const info = await getSystemInfoSync()
|
|
58
|
-
return handle.success(info)
|
|
59
|
-
} catch (error) {
|
|
60
|
-
return handle.fail({
|
|
61
|
-
errMsg: error
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
}
|