@mpxjs/api-proxy 2.9.66 → 2.9.69-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/@types/index.d.ts +13 -0
  2. package/package.json +3 -12
  3. package/src/common/js/promisify.js +11 -3
  4. package/src/platform/api/action-sheet/rnActionSheet.jsx +69 -81
  5. package/src/platform/api/app/index.web.js +26 -11
  6. package/src/platform/api/create-intersection-observer/rnIntersectionObserver.js +14 -10
  7. package/src/platform/api/create-selector-query/rnNodesRef.js +1 -6
  8. package/src/platform/api/image/index.ali.js +4 -1
  9. package/src/platform/api/image/index.ios.js +45 -0
  10. package/src/platform/api/image/index.js +4 -1
  11. package/src/platform/api/image/index.web.js +46 -2
  12. package/src/platform/api/modal/rnModal.jsx +7 -8
  13. package/src/platform/api/next-tick/index.ios.js +7 -1
  14. package/src/platform/api/request/index.web.js +10 -8
  15. package/src/platform/api/route/index.ios.js +19 -24
  16. package/src/platform/api/set-navigation-bar/index.ali.js +6 -1
  17. package/src/platform/api/set-navigation-bar/index.ios.js +6 -3
  18. package/src/platform/api/set-navigation-bar/index.js +4 -1
  19. package/src/platform/api/set-navigation-bar/index.web.js +5 -2
  20. package/src/platform/api/setting/index.js +19 -0
  21. package/src/platform/api/storage/index.web.js +1 -1
  22. package/src/platform/api/storage/rnStorage.js +1 -1
  23. package/src/platform/api/system/index.ali.js +7 -1
  24. package/src/platform/api/system/index.ios.js +84 -1
  25. package/src/platform/api/system/index.js +7 -1
  26. package/src/platform/api/system/index.web.js +77 -16
  27. package/src/platform/api/system/rnSystem.js +24 -86
  28. package/src/platform/api/toast/rnToast.jsx +23 -16
  29. package/src/platform/index.js +6 -6
  30. package/LICENSE +0 -433
  31. package/src/platform/api/action-sheet/index.android.js +0 -1
  32. package/src/platform/api/animation/index.android.js +0 -1
  33. package/src/platform/api/app/index.android.js +0 -1
  34. package/src/platform/api/base/index.android.js +0 -1
  35. package/src/platform/api/clipboard-data/index.android.js +0 -1
  36. package/src/platform/api/create-selector-query/index.android.js +0 -1
  37. package/src/platform/api/device/network/index.android.js +0 -1
  38. package/src/platform/api/keyboard/index.android.js +0 -1
  39. package/src/platform/api/lifecycle/index.ali.js +0 -9
  40. package/src/platform/api/lifecycle/index.js +0 -7
  41. package/src/platform/api/lifecycle/index.web.js +0 -12
  42. package/src/platform/api/location/index.android.js +0 -1
  43. package/src/platform/api/make-phone-call/index.android.js +0 -1
  44. package/src/platform/api/modal/index.android.js +0 -1
  45. package/src/platform/api/next-tick/index.android.js +0 -1
  46. package/src/platform/api/request/index.android.js +0 -1
  47. package/src/platform/api/route/index.android.js +0 -1
  48. package/src/platform/api/screen-brightness/index.android.js +0 -1
  49. package/src/platform/api/set-navigation-bar/index.android.js +0 -1
  50. package/src/platform/api/socket/index.android.js +0 -1
  51. package/src/platform/api/storage/index.android.js +0 -1
  52. package/src/platform/api/system/index.android.js +0 -1
  53. package/src/platform/api/toast/index.android.js +0 -1
  54. package/src/platform/api/vibrate/index.android.js +0 -1
  55. package/src/platform/api/window/index.android.js +0 -1
package/@types/index.d.ts CHANGED
@@ -110,6 +110,19 @@ export const createVideoContext: WechatMiniprogram.Wx['createVideoContext']
110
110
  export const onWindowResize: WechatMiniprogram.Wx['onWindowResize']
111
111
  export const offWindowResize: WechatMiniprogram.Wx['offWindowResize']
112
112
  export const createAnimation: WechatMiniprogram.Wx['createAnimation']
113
+ export const hideHomeButton: WechatMiniprogram.Wx['hideHomeButton']
114
+ export const getSetting: WechatMiniprogram.Wx['getSetting']
115
+ export const openSetting: WechatMiniprogram.Wx['openSetting']
116
+ export const enableAlertBeforeUnload: WechatMiniprogram.Wx['enableAlertBeforeUnload']
117
+ export const disableAlertBeforeUnload: WechatMiniprogram.Wx['disableAlertBeforeUnload']
118
+ export const getMenuButtonBoundingClientRect: WechatMiniprogram.Wx['getMenuButtonBoundingClientRect']
119
+ export const getImageInfo: WechatMiniprogram.Wx['getImageInfo']
120
+ export const vibrateShort: WechatMiniprogram.Wx['vibrateShort']
121
+ export const vibrateLong: WechatMiniprogram.Wx['vibrateLong']
122
+ export const getExtConfig: WechatMiniprogram.Wx['getExtConfig']
123
+ export const getExtConfigSync: WechatMiniprogram.Wx['getExtConfigSync']
124
+ export const openLocation: WechatMiniprogram.Wx['openLocation']
125
+ export const chooseLocation: WechatMiniprogram.Wx['chooseLocation']
113
126
 
114
127
  declare const install: (...args: any) => any
115
128
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/api-proxy",
3
- "version": "2.9.66",
3
+ "version": "2.9.69-beta.1",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -37,15 +37,13 @@
37
37
  },
38
38
  "homepage": "https://github.com/didi/mpx#readme",
39
39
  "dependencies": {
40
- "@mpxjs/utils": "^2.9.65",
40
+ "@mpxjs/utils": "^2.9.69",
41
41
  "axios": "^1.7.3"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@ant-design/react-native": "^5.1.3",
45
45
  "@react-native-async-storage/async-storage": "^1.23.1",
46
46
  "@react-native-community/netinfo": "^11.2.1",
47
- "expo-brightness": "~11.8.0",
48
- "expo-clipboard": "~6.0.3",
49
47
  "react-native-device-info": "^10.13.2",
50
48
  "react-native-get-location": "^4.0.1",
51
49
  "react-native-haptic-feedback": "^2.3.3",
@@ -55,9 +53,6 @@
55
53
  "@react-native-async-storage/async-storage": {
56
54
  "optional": true
57
55
  },
58
- "expo-clipboard": {
59
- "optional": true
60
- },
61
56
  "@react-native-community/netinfo": {
62
57
  "optional": true
63
58
  },
@@ -73,12 +68,8 @@
73
68
  "@ant-design/react-native": {
74
69
  "optional": true
75
70
  },
76
- "expo-brightness": {
77
- "optional": true
78
- },
79
71
  "react-native-haptic-feedback": {
80
72
  "optional": true
81
73
  }
82
- },
83
- "gitHead": "ff9eb06a3be28538870823cebf813ed56f39bbd7"
74
+ }
84
75
  }
@@ -70,14 +70,22 @@ function promisify (listObj, whiteList, customBlackList) {
70
70
  result[key] = function (...args) {
71
71
  const obj = args[0] || {}
72
72
  // 不需要转换 or 用户已定义回调,则不处理
73
- if (!promisifyFilter(key) || obj.success || obj.fail) {
73
+ if (!promisifyFilter(key)) {
74
74
  return listObj[key].apply(ENV_OBJ, args)
75
75
  } else { // 其他情况进行转换
76
76
  if (!args[0]) args.unshift(obj)
77
77
  let returned
78
78
  const promise = new Promise((resolve, reject) => {
79
- obj.success = resolve
80
- obj.fail = reject
79
+ const originSuccess = obj.success
80
+ const originFail = obj.fail
81
+ obj.success = function (res) {
82
+ originSuccess && originSuccess.call(this, res)
83
+ resolve(res)
84
+ }
85
+ obj.fail = function (e) {
86
+ originFail && originFail.call(this, e)
87
+ reject(e)
88
+ }
81
89
  returned = listObj[key].apply(ENV_OBJ, args)
82
90
  })
83
91
  promise.__returned = returned
@@ -1,38 +1,17 @@
1
- import { View, TouchableHighlight, Text, StyleSheet, Button, Animated } from 'react-native'
1
+ import { View, Text, StyleSheet } from 'react-native'
2
2
  import { successHandle, failHandle } from '../../../common/js'
3
3
  import { Portal } from '@ant-design/react-native'
4
+ import { getWindowInfo } from '../system/rnSystem'
5
+ import Animated, {
6
+ useSharedValue,
7
+ useAnimatedStyle,
8
+ withTiming
9
+ } from 'react-native-reanimated'
4
10
  function showActionSheet (options = {}) {
5
11
  const { alertText, itemList = [], itemColor = '#000000', success, fail, complete } = options
6
- let actionSheetKey
7
- const slideAnim = new Animated.Value(500)
8
- const slideIn = () => {
9
- // Will change fadeAnim value to 1 in 5 seconds
10
- Animated.timing(slideAnim, {
11
- toValue: 0,
12
- duration: 200,
13
- useNativeDriver: true,
14
- }).start()
15
- }
16
- const slideOut = () => {
17
- // Will change fadeAnim value to 1 in 5 seconds
18
- Animated.timing(slideAnim, {
19
- toValue: 500,
20
- duration: 200,
21
- useNativeDriver: true,
22
- }).start(() => {
23
- })
24
- }
25
- if (itemList.length === 0 || itemList.length > 6) {
26
- const result = {
27
- errMsg: 'showActionSheet:fail parameter error: itemList should not be large than 6'
28
- }
29
- if (itemList.length === 0) {
30
- result.errno = 1001
31
- result.errMsg = 'showActionSheet:fail parameter error: parameter.itemList should have at least 1 item;'
32
- }
33
- failHandle(result, fail, complete)
34
- return
35
- }
12
+ const windowInfo = getWindowInfo()
13
+ const bottom = windowInfo.screenHeight - windowInfo.safeArea.bottom
14
+ let actionSheetKey = null
36
15
  const styles = StyleSheet.create({
37
16
  actionActionMask: {
38
17
  left: 0,
@@ -44,16 +23,14 @@ function showActionSheet (options = {}) {
44
23
  zIndex: 1000
45
24
  },
46
25
  actionSheetContent: {
47
- left: 0,
48
- right: 0,
49
- position: 'absolute',
50
- bottom: 0,
51
26
  backgroundColor: '#ffffff',
52
27
  borderTopLeftRadius: 10,
53
28
  borderTopRightRadius: 10,
54
- transform: [{
55
- translateY: -500
56
- }]
29
+ position: 'absolute',
30
+ bottom: 0,
31
+ left: 0,
32
+ right: 0,
33
+ paddingBottom: bottom
57
34
  },
58
35
  itemStyle: {
59
36
  paddingTop: 15,
@@ -73,53 +50,64 @@ function showActionSheet (options = {}) {
73
50
  paddingBottom: 10
74
51
  }
75
52
  })
76
- const remove = function () {
77
- if (actionSheetKey) {
78
- slideOut()
79
- setTimeout(() => {
80
- Portal.remove(actionSheetKey)
81
- actionSheetKey = null
82
- }, 200)
53
+ function ActionSheet () {
54
+ const offset = useSharedValue(1000);
55
+
56
+ const animatedStyles = useAnimatedStyle(() => ({
57
+ transform: [{ translateY: offset.value }],
58
+ }))
59
+
60
+ const slideOut = () => {
61
+ // Will change fadeAnim value to 1 in 5 seconds
62
+ offset.value = withTiming(1000)
83
63
  }
84
- }
85
- const selectAction = function (index) {
86
- const result = {
87
- errMsg: 'showActionSheet:ok',
88
- tapIndex: index
64
+
65
+ offset.value = withTiming(0)
66
+
67
+ const selectAction = function (index, e) {
68
+ e.stopPropagation()
69
+ const result = {
70
+ errMsg: 'showActionSheet:ok',
71
+ tapIndex: index
72
+ }
73
+ successHandle(result, success, complete)
74
+ remove()
89
75
  }
90
- successHandle(result, success, complete)
91
- remove()
92
- }
93
- const cancelAction = function () {
94
- const result = {
95
- errMsg: 'showActionSheet:fail cancel'
76
+
77
+ const remove = function () {
78
+ if (actionSheetKey) {
79
+ slideOut()
80
+ setTimeout(() => {
81
+ Portal.remove(actionSheetKey)
82
+ actionSheetKey = null
83
+ }, 200)
84
+ }
96
85
  }
97
- failHandle(result, fail, complete)
98
- remove()
99
- }
100
- let alertTextList = []
101
- if (alertText) {
102
- alertTextList = [alertText]
86
+
87
+ const cancelAction = function (e) {
88
+ e.stopPropagation()
89
+ const result = {
90
+ errMsg: 'showActionSheet:fail cancel'
91
+ }
92
+ failHandle(result, fail, complete)
93
+ remove()
94
+ }
95
+ return (
96
+ <View onTouchEnd={cancelAction} style={styles.actionActionMask}>
97
+ <Animated.View style={[styles.actionSheetContent, animatedStyles]}>
98
+ { alertText ? <View style={ styles.itemStyle }><Text style={[styles.itemTextStyle, { color: '#666666' }]}>{alertText}</Text></View> : null }
99
+ { itemList.map((item, index) => <View key={index} onTouchEnd={(e) => selectAction(index, e)} style={ [styles.itemStyle, itemList.length -1 === index ? {
100
+ borderBottomWidth: 6,
101
+ borderBottomStyle: 'solid',
102
+ borderBottomColor: '#f7f7f7'
103
+ } : {}] }><Text style={[styles.itemTextStyle, { color: itemColor }]}>{item}</Text></View>) }
104
+ <View style={styles.buttonStyle} onTouchEnd={cancelAction}><Text style={{ color: "#000000", width: "100%", textAlign: "center" }}>取消</Text></View>
105
+ </Animated.View>
106
+ </View>
107
+ )
103
108
  }
104
- const ActionSheetView = <TouchableHighlight underlayColor="rgba(0,0,0,0.6)" onPress={cancelAction} style={styles.actionActionMask}>
105
- <Animated.View
106
- style={[
107
- styles.actionSheetContent,
108
- {
109
- transform: [{translateY: slideAnim}]
110
- }
111
- ]}>
112
- { alertTextList.map((item, index) => <View key={index} style={ styles.itemStyle }><Text style={[styles.itemTextStyle, { color: '#666666' }]}>{item}</Text></View>) }
113
- { itemList.map((item, index) => <TouchableHighlight key={index} underlayColor="#ececec" onPress={() => selectAction(index)} style={ [styles.itemStyle, itemList.length -1 === index ? {
114
- borderBottomWidth: 6,
115
- borderBottomStyle: 'solid',
116
- borderBottomColor: '#f7f7f7'
117
- } : {}] }><Text style={[styles.itemTextStyle, { color: itemColor }]}>{item}</Text></TouchableHighlight>) }
118
- <View style={styles.buttonStyle}><Button color={'#000000'} title={'取消'} onPress={cancelAction}></Button></View>
119
- </Animated.View>
120
- </TouchableHighlight>
121
- actionSheetKey = Portal.add(ActionSheetView)
122
- slideIn()
109
+
110
+ actionSheetKey = Portal.add(<ActionSheet/>)
123
111
  }
124
112
 
125
113
  export {
@@ -3,8 +3,27 @@ import { isBrowser, isReact } from '@mpxjs/utils'
3
3
  global.__mpxAppCbs = global.__mpxAppCbs || {
4
4
  show: [],
5
5
  hide: [],
6
- error: []
6
+ error: [],
7
+ rejection: []
8
+ }
9
+
10
+ function off (cbs, cb) {
11
+ if (cb) {
12
+ const idx = cbs.indexOf(cb)
13
+ if (idx > -1) cbs.splice(idx, 1)
14
+ } else {
15
+ cbs.length = 0
16
+ }
17
+ }
18
+
19
+ function onUnhandledRejection (callback) {
20
+ if (isBrowser || isReact) {
21
+ global.__mpxAppCbs.rejection.push(callback)
22
+ }
23
+ }
7
24
 
25
+ function offUnhandledRejection (callback) {
26
+ off(global.__mpxAppCbs.rejection, callback)
8
27
  }
9
28
 
10
29
  function onError (callback) {
@@ -14,9 +33,7 @@ function onError (callback) {
14
33
  }
15
34
 
16
35
  function offError (callback) {
17
- const cbs = global.__mpxAppCbs.error
18
- const index = cbs.indexOf(callback)
19
- if (index > -1) cbs.splice(index, 1)
36
+ off(global.__mpxAppCbs.error, callback)
20
37
  }
21
38
 
22
39
  function onAppShow (callback) {
@@ -26,9 +43,7 @@ function onAppShow (callback) {
26
43
  }
27
44
 
28
45
  function offAppShow (callback) {
29
- const cbs = global.__mpxAppCbs.show
30
- const index = cbs.indexOf(callback)
31
- if (index > -1) cbs.splice(index, 1)
46
+ off(global.__mpxAppCbs.show, callback)
32
47
  }
33
48
 
34
49
  function onAppHide (callback) {
@@ -38,9 +53,7 @@ function onAppHide (callback) {
38
53
  }
39
54
 
40
55
  function offAppHide (callback) {
41
- const cbs = global.__mpxAppCbs.hide
42
- const index = cbs.indexOf(callback)
43
- if (index > -1) cbs.splice(index, 1)
56
+ off(global.__mpxAppCbs.hide, callback)
44
57
  }
45
58
 
46
59
  export {
@@ -49,5 +62,7 @@ export {
49
62
  offAppShow,
50
63
  offAppHide,
51
64
  onError,
52
- offError
65
+ offError,
66
+ onUnhandledRejection,
67
+ offUnhandledRejection
53
68
  }
@@ -12,10 +12,14 @@ class RNIntersectionObserver {
12
12
  constructor (component, options, intersectionCtx) {
13
13
  this.id = idCount++
14
14
  this.component = component
15
- this.options = options
16
- this.thresholds = options.thresholds.sort((a, b) => a - b) || [0]
17
- this.initialRatio = options.initialRatio || 0
18
- this.observeAll = options.observeAll || false
15
+ this.options = Object.assign({
16
+ thresholds: [0],
17
+ initialRatio: 0,
18
+ observeAll: false
19
+ }, options || {})
20
+ this.thresholds = this.options.thresholds.sort((a, b) => a - b) || [0]
21
+ this.initialRatio = this.options.initialRatio
22
+ this.observeAll = this.options.observeAll
19
23
 
20
24
  // 组件上挂载对应的observers,用于在组件销毁的时候进行批量disconnect
21
25
  this.component._intersectionObservers = this.component.__intersectionObservers || []
@@ -26,7 +30,7 @@ class RNIntersectionObserver {
26
30
  this.margins = DefaultMargin
27
31
  this.callback = noop
28
32
 
29
- this.throttleMeasure = this.getThrottleMeasure(options.throttleTime || 100)
33
+ this.throttleMeasure = this.getThrottleMeasure(this.options.throttleTime || 100)
30
34
 
31
35
  // 记录上一次相交的比例
32
36
  this.previousIntersectionRatio = []
@@ -65,7 +69,7 @@ class RNIntersectionObserver {
65
69
 
66
70
  observe (selector, callback) {
67
71
  if (this.observerRefs) {
68
- console.error('"observe" call can be only called once in IntersectionObserver')
72
+ console.warn('"observe" call can be only called once in IntersectionObserver')
69
73
  return
70
74
  }
71
75
  let targetRef = null
@@ -75,7 +79,7 @@ class RNIntersectionObserver {
75
79
  targetRef = this.component.__selectRef(selector, 'node')
76
80
  }
77
81
  if (!targetRef || targetRef.length === 0) {
78
- console.error('intersection observer target not found')
82
+ console.warn('intersection observer target not found')
79
83
  return
80
84
  }
81
85
  this.observerRefs = isArray(targetRef) ? targetRef : [targetRef]
@@ -85,9 +89,9 @@ class RNIntersectionObserver {
85
89
 
86
90
  _getWindowRect () {
87
91
  if (this.windowRect) return this.windowRect
88
- const navigation = getFocusedNavigation()
92
+ const navigation = getFocusedNavigation() || {}
89
93
  const screen = Dimensions.get('screen')
90
- const navigationLayout = navigation.layout || {
94
+ const navigationLayout = navigation.layout || {
91
95
  x: 0,
92
96
  y: 0,
93
97
  width: screen.width,
@@ -96,7 +100,7 @@ class RNIntersectionObserver {
96
100
 
97
101
  const windowRect = {
98
102
  top: navigationLayout.y + this.margins.top,
99
- left: navigationLayout.x + this.margins.left,
103
+ left: this.margins.left,
100
104
  right: navigationLayout.width - this.margins.right,
101
105
  bottom: navigationLayout.y + navigationLayout.height - this.margins.bottom
102
106
  }
@@ -84,12 +84,7 @@ const getComputedStyle = (config = []) => {
84
84
  return wrapFn((nodeInstance, resolve) => {
85
85
  config = new Set(config)
86
86
  const res = {}
87
- const styles = nodeInstance.props.current.style || {}
88
- const defaultStyle = nodeInstance.instance.defaultStyle || {}
89
- const computedStyle = {
90
- ...defaultStyle,
91
- ...styles
92
- }
87
+ const computedStyle = nodeInstance.instance.style || {}
93
88
  config.forEach((key) => {
94
89
  const humpKey = dash2hump(key)
95
90
  // 取 style 的 key 是根据传入的 key 来设置,传什么设置什么 key,只不过取值需要做兼容
@@ -30,7 +30,10 @@ function compressImage (options = {}) {
30
30
  return ENV_OBJ.compressImage(opts)
31
31
  }
32
32
 
33
+ const getImageInfo = ENV_OBJ.getImageInfo
34
+
33
35
  export {
34
36
  previewImage,
35
- compressImage
37
+ compressImage,
38
+ getImageInfo
36
39
  }
@@ -0,0 +1,45 @@
1
+ import { envError, defineUnsupportedProps, successHandle, failHandle } from '../../../common/js'
2
+ import { Image } from 'react-native'
3
+
4
+ const previewImage = envError('previewImage')
5
+
6
+ const compressImage = envError('compressImage')
7
+
8
+ const getImageInfo = function (options = {}) {
9
+ const { src, success, fail, complete } = options
10
+ if (src === undefined) {
11
+ const result = {
12
+ errMsg: 'getImageInfo:fail parameter error: parameter.src should be String instead of Undefined;',
13
+ errno: 1001
14
+ }
15
+ failHandle(result, fail, complete)
16
+ return
17
+ }
18
+ if (src === '') {
19
+ const result = {
20
+ errMsg: 'getImageInfo:fail image not found'
21
+ }
22
+ failHandle(result, fail, complete)
23
+ return
24
+ }
25
+ Image.getSize(src, (width, height) => {
26
+ const result = {
27
+ errMsg: 'getImageInfo:ok',
28
+ width,
29
+ height
30
+ }
31
+ defineUnsupportedProps(result, ['path', 'orientation', 'type'])
32
+ successHandle(result, success, complete)
33
+ }, (err) => {
34
+ const result = {
35
+ errMsg: 'getImageInfo:fail download image fail. reason: ' + err
36
+ }
37
+ failHandle(result, fail, complete)
38
+ })
39
+ }
40
+
41
+ export {
42
+ previewImage,
43
+ compressImage,
44
+ getImageInfo
45
+ }
@@ -4,7 +4,10 @@ const previewImage = ENV_OBJ.previewImage || envError('previewImage')
4
4
 
5
5
  const compressImage = ENV_OBJ.compressImage || envError('compressImage')
6
6
 
7
+ const getImageInfo = ENV_OBJ.getImageInfo || envError('getImageInfo')
8
+
7
9
  export {
8
10
  previewImage,
9
- compressImage
11
+ compressImage,
12
+ getImageInfo
10
13
  }
@@ -1,5 +1,5 @@
1
1
  import Preview from './Preview'
2
- import { isBrowser, throwSSRWarning, envError } from '../../../common/js'
2
+ import { isBrowser, throwSSRWarning, envError, defineUnsupportedProps, successHandle, failHandle } from '../../../common/js'
3
3
 
4
4
  let preview = null
5
5
 
@@ -15,9 +15,53 @@ const previewImage = (options) => {
15
15
  if (!preview) preview = new Preview()
16
16
  preview.show(options)
17
17
  }
18
+
18
19
  const compressImage = envError('compressImage')
19
20
 
21
+ const getImageInfo = function (options = {}) {
22
+ const { src, success, fail, complete } = options
23
+
24
+ if (src === undefined) {
25
+ const result = {
26
+ errMsg: 'getImageInfo:fail parameter error: parameter.src should be String instead of Undefined;',
27
+ errno: 1001
28
+ }
29
+ failHandle(result, fail, complete)
30
+ return
31
+ }
32
+ if (src === '') {
33
+ const result = {
34
+ errMsg: 'getImageInfo:fail image not found'
35
+ }
36
+ failHandle(result, fail, complete)
37
+ return
38
+ }
39
+
40
+ const img = new Image()
41
+ img.src = src
42
+
43
+ img.onload = function () {
44
+ const width = img.width
45
+ const height = img.height
46
+ const result = {
47
+ errMsg: 'getImageInfo:ok',
48
+ width,
49
+ height
50
+ }
51
+ defineUnsupportedProps(result, ['path', 'orientation', 'type'])
52
+ successHandle(result, success, complete)
53
+ }
54
+
55
+ img.onerror = function () {
56
+ const result = {
57
+ errMsg: 'getImageInfo:fail download image fail. '
58
+ }
59
+ failHandle(result, fail, complete)
60
+ }
61
+ }
62
+
20
63
  export {
21
64
  previewImage,
22
- compressImage
65
+ compressImage,
66
+ getImageInfo
23
67
  }
@@ -17,7 +17,7 @@ const showModal = function (options = {}) {
17
17
  fail,
18
18
  complete
19
19
  } = options
20
- const modalWidth = width - 60
20
+ const modalWidth = width * 0.8
21
21
  const styles = StyleSheet.create({
22
22
  modalTask: {
23
23
  left: 0,
@@ -53,7 +53,8 @@ const showModal = function (options = {}) {
53
53
  lineHeight: 26,
54
54
  color: '#808080',
55
55
  paddingLeft: 20,
56
- paddingRight: 20
56
+ paddingRight: 20,
57
+ textAlign: 'center'
57
58
  },
58
59
  modalBtnBox: {
59
60
  borderTopWidth: StyleSheet.hairlineWidth,
@@ -67,8 +68,8 @@ const showModal = function (options = {}) {
67
68
  modalBtn: {
68
69
  flex: 1,
69
70
  textAlign: 'center',
70
- paddingTop: 10,
71
- paddingBottom: 10,
71
+ paddingTop: width * 0.04,
72
+ paddingBottom: width * 0.04,
72
73
  },
73
74
  modalButton: {
74
75
  width: '100%',
@@ -88,9 +89,8 @@ const showModal = function (options = {}) {
88
89
  let editableContent = []
89
90
  let modalButton = [{
90
91
  text: confirmText,
91
- confirmColor,
92
92
  type: 'confirm',
93
- color: 'rgb(87, 107, 149)'
93
+ color: confirmColor
94
94
  }]
95
95
  let contentText = content
96
96
  const onChangeText = function (text) {
@@ -128,10 +128,9 @@ const showModal = function (options = {}) {
128
128
  if (showCancel) {
129
129
  modalButton.unshift({
130
130
  text: cancelText,
131
- cancelColor,
132
131
  type: 'cancel',
133
132
  style: styles.cancelStyle,
134
- color: '#000000'
133
+ color: cancelColor
135
134
  })
136
135
  }
137
136
  ModalView = <View style={styles.modalTask}>
@@ -1 +1,7 @@
1
- export * from './index.ali'
1
+ function nextTick (fn) {
2
+ Promise.resolve().then(fn)
3
+ }
4
+
5
+ export {
6
+ nextTick
7
+ }
@@ -1,6 +1,7 @@
1
1
  import axios from 'axios'
2
2
  import { successHandle, failHandle, defineUnsupportedProps } from '../../../common/js'
3
3
  import RequestTask from './RequestTask'
4
+ import { serialize, buildUrl } from '@mpxjs/utils'
4
5
 
5
6
  function request (options = { url: '' }) {
6
7
  const CancelToken = axios.CancelToken
@@ -8,6 +9,7 @@ function request (options = { url: '' }) {
8
9
  const requestTask = new RequestTask(source.cancel)
9
10
 
10
11
  let {
12
+ url,
11
13
  data = {},
12
14
  method = 'GET',
13
15
  dataType = 'json',
@@ -18,8 +20,11 @@ function request (options = { url: '' }) {
18
20
  fail = null,
19
21
  complete = null
20
22
  } = options
21
-
22
23
  method = method.toUpperCase()
24
+ if (method === 'GET') {
25
+ url = buildUrl(url, data)
26
+ data = {}
27
+ }
23
28
 
24
29
  if (
25
30
  method === 'POST' &&
@@ -27,9 +32,7 @@ function request (options = { url: '' }) {
27
32
  (header['Content-Type'] === 'application/x-www-form-urlencoded' ||
28
33
  header['content-type'] === 'application/x-www-form-urlencoded')
29
34
  ) {
30
- data = Object.keys(data).reduce((pre, curKey) => {
31
- return `${pre}&${encodeURIComponent(curKey)}=${encodeURIComponent(data[curKey])}`
32
- }, '').slice(1)
35
+ data = serialize(data)
33
36
  }
34
37
 
35
38
  /**
@@ -58,7 +61,7 @@ function request (options = { url: '' }) {
58
61
  */
59
62
  const rOptions = Object.assign(options, {
60
63
  method,
61
- url: options.url,
64
+ url,
62
65
  data,
63
66
  headers: header,
64
67
  responseType,
@@ -104,10 +107,9 @@ function request (options = { url: '' }) {
104
107
  errMsg: `request:fail ${err}`,
105
108
  statusCode: response.status,
106
109
  header: response.headers,
107
- data: response.data,
108
- stack: realError.stack,
109
- ...realError
110
+ data: response.data
110
111
  }
112
+ Object.assign(res, realError)
111
113
  failHandle(res, fail, complete)
112
114
  })
113
115