From d2b269710b71703d7b005f8f7483f67786f6e1ff Mon Sep 17 00:00:00 2001 From: qiang Date: Wed, 30 Sep 2020 15:42:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20H5=20=E7=AB=AF=20uni.showActionSheet=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=A7=E5=B1=8F=E5=B1=95=E7=A4=BA=E6=95=88?= =?UTF-8?q?=E6=9E=9C=EF=BC=8C=E6=94=AF=E6=8C=81=20popover=20=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/view/index.css | 28 +- .../h5/components/app/popup/actionSheet.vue | 246 +++++++++++++----- src/platforms/h5/view/index.css | 28 +- 3 files changed, 203 insertions(+), 99 deletions(-) diff --git a/src/core/view/index.css b/src/core/view/index.css index 6ec35cf78..4278501c3 100644 --- a/src/core/view/index.css +++ b/src/core/view/index.css @@ -103,7 +103,7 @@ uni-page { right: 0; left: 0; bottom: 0; - background: rgba(0, 0, 0, 0.6); + background: rgba(0, 0, 0, 0.5); } @@ -122,20 +122,20 @@ uni-page { } [nvue] uni-view, -[nvue] uni-swiper-item, +[nvue] uni-swiper-item, [nvue] uni-scroll-view { - display: flex; - flex-shrink: 0; - flex-grow: 0; - flex-basis: auto; - align-items: stretch; + display: flex; + flex-shrink: 0; + flex-grow: 0; + flex-basis: auto; + align-items: stretch; align-content: flex-start; -} +} [nvue-dir-row] uni-view, [nvue-dir-row] uni-swiper-item { flex-direction: row; -} +} [nvue-dir-column] uni-view, [nvue-dir-column] uni-swiper-item { @@ -164,8 +164,8 @@ uni-page { position: relative; border: 0px solid #000000; box-sizing: border-box; -} - -[nvue] uni-swiper-item { - position: absolute; -} +} + +[nvue] uni-swiper-item { + position: absolute; +} diff --git a/src/platforms/h5/components/app/popup/actionSheet.vue b/src/platforms/h5/components/app/popup/actionSheet.vue index c4f6fd32b..e2d503f24 100644 --- a/src/platforms/h5/components/app/popup/actionSheet.vue +++ b/src/platforms/h5/components/app/popup/actionSheet.vue @@ -3,40 +3,42 @@
+ :class="{ 'uni-actionsheet_toggle': visible }" + :style="actionSheetStyle.content" + class="uni-actionsheet" + >
- {{ title }} + > + {{ title }}
- {{ itemTitle }} + @click="_close(index)" + > + {{ itemTitle }}
- 取消 + @click="_close(-1)" + > + 取消
+
@@ -58,11 +60,84 @@ export default { type: String, default: '#000000' }, + popover: { + type: Object, + default: null + }, visible: { type: Boolean, default: false } }, + data () { + return { + width: 0, + height: 0, + top: top + } + }, + computed: { + actionSheetStyle () { + const style = {} + const contentStyle = style.content = {} + const triangleStyle = style.triangle = {} + const popover = this.popover + function getNumber (value) { + return Number(value) || 0 + } + if (this.width >= 500 && popover) { + Object.assign(triangleStyle, { + position: 'absolute', + width: '0', + height: '0', + 'margin-left': '-6px', + 'border-style': 'solid' + }) + const popoverLeft = getNumber(popover.left) + const popoverWidth = getNumber(popover.width) + const popoverTop = getNumber(popover.top) + const popoverHeight = getNumber(popover.height) + const center = (popoverLeft + popoverWidth) / 2 + contentStyle.transform = 'none !important' + const contentLeft = Math.max(0, center - 300 / 2) + contentStyle.left = `${contentLeft}px` + let triangleLeft = Math.max(12, center - contentLeft) + triangleLeft = Math.min(300 - 12, triangleLeft) + triangleStyle.left = `${triangleLeft}px` + const vcl = this.height / 2 + if (popoverTop + popoverHeight - vcl > vcl - popoverTop) { + contentStyle.top = 'auto' + contentStyle.bottom = `${this.height - popoverTop + 6}px` + triangleStyle.bottom = '-6px' + triangleStyle['border-width'] = '6px 6px 0 6px' + triangleStyle['border-color'] = '#fcfcfd transparent transparent transparent' + } else { + contentStyle.top = `${popoverTop + popoverHeight + 6}px` + triangleStyle.top = '-6px' + triangleStyle['border-width'] = '0 6px 6px 6px' + triangleStyle['border-color'] = 'transparent transparent #fcfcfd transparent' + } + } + return style + } + }, + mounted () { + const fixSize = () => { + const { + windowWidth, + windowHeight, + windowTop + } = uni.getSystemInfoSync() + this.width = windowWidth + this.height = windowHeight + windowTop + this.top = windowTop + } + this.$watch('visible', value => value && fixSize()) + window.addEventListener('resize', fixSize) + this.$once('hook:beforeDestroy', () => { + window.removeEventListener('resize', fixSize) + }) + }, methods: { _close (tapIndex) { this.$emit('close', tapIndex) @@ -71,67 +146,96 @@ export default { } diff --git a/src/platforms/h5/view/index.css b/src/platforms/h5/view/index.css index 6ec35cf78..4278501c3 100644 --- a/src/platforms/h5/view/index.css +++ b/src/platforms/h5/view/index.css @@ -103,7 +103,7 @@ uni-page { right: 0; left: 0; bottom: 0; - background: rgba(0, 0, 0, 0.6); + background: rgba(0, 0, 0, 0.5); } @@ -122,20 +122,20 @@ uni-page { } [nvue] uni-view, -[nvue] uni-swiper-item, +[nvue] uni-swiper-item, [nvue] uni-scroll-view { - display: flex; - flex-shrink: 0; - flex-grow: 0; - flex-basis: auto; - align-items: stretch; + display: flex; + flex-shrink: 0; + flex-grow: 0; + flex-basis: auto; + align-items: stretch; align-content: flex-start; -} +} [nvue-dir-row] uni-view, [nvue-dir-row] uni-swiper-item { flex-direction: row; -} +} [nvue-dir-column] uni-view, [nvue-dir-column] uni-swiper-item { @@ -164,8 +164,8 @@ uni-page { position: relative; border: 0px solid #000000; box-sizing: border-box; -} - -[nvue] uni-swiper-item { - position: absolute; -} +} + +[nvue] uni-swiper-item { + position: absolute; +} -- GitLab