@mpxjs/api-proxy 2.9.0-beta.5 → 2.9.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/api-proxy",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.1",
|
|
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": "
|
|
42
|
+
"gitHead": "5460efb7afae97e321ff608258a8c0ad0b366f4c"
|
|
43
43
|
}
|
package/src/common/js/web.js
CHANGED
|
@@ -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
|
package/src/web/api/index.js
CHANGED
|
@@ -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
|
+
}
|
|
@@ -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 = {
|