@mpxjs/api-proxy 2.9.0-beta.3 → 2.9.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/api-proxy",
3
- "version": "2.9.0-beta.3",
3
+ "version": "2.9.0",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -39,5 +39,5 @@
39
39
  "dependencies": {
40
40
  "axios": "^0.21.1"
41
41
  },
42
- "gitHead": "521f0cec1231962f9c071c8b70499772a0a81fda"
42
+ "gitHead": "91ac258dbf1d0a324a74cac606e2cc10ef557823"
43
43
  }
@@ -15,8 +15,24 @@ function isTabBarPage (url, router) {
15
15
  return !!tabBarPagesMap[path.slice(1)]
16
16
  }
17
17
 
18
+ /**
19
+ * Creates a new DOM element with the specified tag, attributes, and children.
20
+ *
21
+ * @param {string} tag - The tag name of the new element.
22
+ * @param {Object.<string, string>} [attrs={}] - An object containing the attributes to set on the new element.
23
+ * @param {Array.<HTMLElement>} [children=[]] - An array of child elements to append to the new element.
24
+ * @returns {HTMLElement} The newly created DOM element.
25
+ */
26
+ function createDom (tag, attrs = {}, children = []) {
27
+ const dom = document.createElement(tag)
28
+ Object.keys(attrs).forEach(k => dom.setAttribute(k, attrs[k]))
29
+ children.length && children.forEach(child => dom.appendChild(child))
30
+ return dom
31
+ }
32
+
18
33
  export {
19
34
  webHandleSuccess,
20
35
  webHandleFail,
36
+ createDom,
21
37
  isTabBarPage
22
38
  }
@@ -0,0 +1,29 @@
1
+ .__mpx_preview__
2
+ display none
3
+ width 100%
4
+ height 100%
5
+ background black
6
+ position fixed
7
+ top 0
8
+ left 0
9
+ z-index 1000
10
+ .__mpx_preview_tip__
11
+ position absolute
12
+ top 0
13
+ left 50%
14
+ transform translateX(-50%)
15
+ color white
16
+ font-size 48px
17
+ letter-spacing 0.3em
18
+ .__mpx_preview_images__
19
+ display flex
20
+ width 100%
21
+ height 100%
22
+ transition transform 0.3s ease-in-out
23
+ &>div
24
+ flex-shrink 0
25
+ width 100%
26
+ height 100%
27
+ background-position center
28
+ background-size contain
29
+ background-repeat no-repeat
@@ -136,8 +136,16 @@ class SelectQuery {
136
136
  }
137
137
  }
138
138
  if (scrollOffset) {
139
- res.scrollLeft = el.scrollLeft
140
- res.scrollTop = el.scrollTop
139
+ if (el.isBScrollContainer) {
140
+ const bs = el?.__vue__?.bs
141
+ res.scrollLeft = -bs.x
142
+ res.scrollTop = -bs.y
143
+ } else {
144
+ res.scrollLeft = el.scrollLeft
145
+ res.scrollTop = el.scrollTop
146
+ }
147
+ res.scrollHeight = el.scrollHeight
148
+ res.scrollWidth = el.scrollWidth
141
149
  }
142
150
  properties.forEach(prop => {
143
151
  const attr = el.getAttribute(prop)
@@ -10,6 +10,9 @@ export * from './action-sheet'
10
10
  // showToast, hideToast, showLoading, hideLoading
11
11
  export * from './toast'
12
12
 
13
+ // previewImage
14
+ export * from './preview-image'
15
+
13
16
  // showModal
14
17
  export * from './modal'
15
18
 
@@ -0,0 +1,80 @@
1
+ import { webHandleSuccess, webHandleFail, createDom, warn } from '../../../common/js'
2
+ import '../../../common/stylus/Preview.styl'
3
+ /**
4
+ * Preview class for displaying images in a slideshow format.
5
+ * todo: unit test
6
+ */
7
+ export default class Preview {
8
+ constructor () {
9
+ this.currentIndex = 0
10
+ this.maxIndex = 0
11
+ this.minDistance = 30
12
+ this.preview = createDom('div', { class: '__mpx_preview__' }, [
13
+ this.textTip = createDom('div', { class: '__mpx_preview_tip__' })
14
+ ])
15
+ document.body.appendChild(this.preview)
16
+ this.initEvent()
17
+ }
18
+
19
+ /**
20
+ * Initializes the event listeners for the preview image feature.
21
+ */
22
+ initEvent () {
23
+ // swipe to change image
24
+ let startX = 0
25
+ this.preview.addEventListener('touchstart', (e) => {
26
+ startX = e.touches[0].pageX
27
+ })
28
+ this.preview.addEventListener('touchend', (e) => {
29
+ const endX = e.changedTouches[0].pageX
30
+ const distance = endX - startX
31
+ if (Math.abs(distance) < this.minDistance) {
32
+ return
33
+ }
34
+ if (distance > 0) {
35
+ this.currentIndex = Math.max(0, this.currentIndex - 1)
36
+ }
37
+ if (distance < 0) {
38
+ this.currentIndex = Math.min(this.maxIndex - 1, this.currentIndex + 1)
39
+ }
40
+ this.preview.querySelector('.__mpx_preview_images__').style.transform = `translateX(-${this.currentIndex * 100}%)`
41
+ this.updateTextTip()
42
+ })
43
+ // click to close
44
+ this.preview.addEventListener('click', () => {
45
+ this.preview.style.display = 'none'
46
+ this.preview.querySelector('.__mpx_preview_images__').remove()
47
+ })
48
+ }
49
+
50
+ /**
51
+ * 显示预览图片
52
+ * @param {Object} options - 选项对象
53
+ * @param {string[]} options.urls - 图片地址数组
54
+ */
55
+ show (options) {
56
+ const supported = ['urls', 'success', 'fail', 'complete']
57
+ Object.keys(options).forEach(key => !supported.includes(key) && warn(`previewImage: 暂不支持选项 ${key} !`))
58
+ const { urls, success, fail, complete } = options
59
+ try {
60
+ this.preview.style.display = 'block'
61
+ // create images with urls
62
+ // append to preview
63
+ this.preview.appendChild(createDom('div', { class: '__mpx_preview_images__' }, urls.map(url => createDom('div', {
64
+ style: `background-image: url(${url})`
65
+ }))))
66
+ this.maxIndex = urls.length
67
+ this.updateTextTip()
68
+ webHandleSuccess({ errMsg: 'previewImage:ok' }, success, complete)
69
+ } catch (e) {
70
+ webHandleFail({ errMsg: 'previewImage:fail', err: e }, fail, complete)
71
+ }
72
+ }
73
+
74
+ /**
75
+ * 更新文本提示
76
+ */
77
+ updateTextTip () {
78
+ this.textTip.textContent = `${this.currentIndex + 1}/${this.maxIndex}`
79
+ }
80
+ }
@@ -0,0 +1,12 @@
1
+ import Preview from './Preview'
2
+
3
+ let preview = null
4
+
5
+ /**
6
+ * 预览图片
7
+ * @param {Object} options - 预览图片的配置项
8
+ */
9
+ export const previewImage = (options) => {
10
+ if (!preview) preview = new Preview()
11
+ preview.show(options)
12
+ }
@@ -1,14 +1,7 @@
1
- import { webHandleSuccess } from '../../../common/js'
1
+ import { webHandleSuccess, createDom } from '../../../common/js'
2
2
  import '../../../common/stylus/Toast.styl'
3
3
  import '../../../common/stylus/Loading.styl'
4
4
 
5
- function createDom (tag, attrs = {}, children = []) {
6
- const dom = document.createElement(tag)
7
- Object.keys(attrs).forEach(k => dom.setAttribute(k, attrs[k]))
8
- children.length && children.forEach(child => dom.appendChild(child))
9
- return dom
10
- }
11
-
12
5
  export default class Toast {
13
6
  constructor () {
14
7
  this.defaultOpts = {