123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <template>
- <view class="app-modal" ref="appModal">
- <view class="app-modal__container">
- <view class="app-modal__container__header" v-if="title">
- <text class="app-modal__container__header__text">{{title}}</text>
- </view>
- <view class="app-modal__container__content">
- <text class="app-modal__container__content__text" :style="{textAlign: align}">{{content}}</text>
- </view>
- <view class="app-modal__container__footer">
- <view v-if="showCancel" style="width: 315rpx" class="app-modal__container__footer-left" hover-class="app-modal__container__footer-hover" :hover-start-time="20" :hover-stay-time="70" @click="clickLeft" >
- <text class="app-modal__container__footer-left__text" :style="{color:cancelColor}">{{cancelText}}</text>
- </view>
- <view :style="{width: showCancel?'315rpx':'630rpx'}" class="app-modal__container__footer-right" hover-class="app-modal__container__footer-hover" :hover-start-time="20" :hover-stay-time="70" @click="clickRight" >
- <text class="app-modal__container__footer-right__text" :style="{color:confirmColor}">{{confirmText}}</text>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- const animation = weex.requireModule('animation');
- export default {
- data() {
- return {
- title: "提示",
- content: "",
- align: "center", // 对齐方式 left/center/right
- cancelText: "取消", // 取消按钮的文字
- cancelColor: "#8F8F8F", // 取消按钮颜色
- confirmText: "确定", // 确认按钮颜色
- confirmColor: "#FFAD15", // 确认按钮颜色
- showCancel: true, // 是否显示取消按钮,默认为 true
- };
- },
- onBackPress(options) {
- if (options.from === 'navigateBack') {
- return false;
- }
- return true;
- },
- onReady() {
- // 添加动画,避免弹窗闪烁问题
- animation.transition(this.$refs.appModal, {
- styles: {
- opacity: 1,
- },
- duration: 100,
- timingFunction: 'ease-in'
- });
- },
- onLoad(options) {
- if (options.showCancel) {
- options.showCancel = JSON.parse(options.showCancel)
- }
- Object.assign(this.$data, options)
- },
- methods: {
- clickLeft() {
- // 先关闭后发送事件
- this.closeModal();
- uni.$emit('AppModalCancel')
- },
- clickRight() {
- // 先关闭后发送事件
- this.closeModal();
- uni.$emit('AppModalConfirm')
- },
- closeModal() {
- uni.navigateBack();
- }
- }
- }
- </script>
- <style lang="scss">
- // nvue页面只支持flex布局
- .app-modal {
- position: fixed;
- left: 0;
- top: 0;
- right: 0;
- bottom: 0;
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- justify-content: center;
- align-items: center;
- background-color: rgba(0, 0, 0, 0.4);
- opacity: 0;
-
- &__container {
- width: 630rpx;
- border-radius: 24rpx;
- background-color: #fff;
- overflow: hidden;
-
- &__header {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- justify-content: center;
- align-items: center;
- height: 90rpx;
- &__text {
- font-size: 32rpx;
- color: #262626;
- }
- }
-
- &__content {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- justify-content: center;
- align-items: center;
-
- padding: 0 30rpx 30rpx 30rpx;
- &__text {
- font-size: 30rpx;
- color: #262626;
- line-height: 50rpx;
- }
- }
-
- &__footer {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- justify-content: center;
- align-items: center;
- flex-direction: row;
- height: 88rpx;
-
- &-left {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- justify-content: center;
- align-items: center;
-
- border-top-width: 1rpx;
- border-right-width: 1rpx;
- border-color: #E6E6E6;
- border-style: solid;
- border-bottom-left-radius: 24rpx;
- padding: 22rpx;
-
- &__text{
- font-size: 34rpx;
- }
- }
-
- &-right {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- justify-content: center;
- align-items: center;
-
- border-top-width: 1rpx;
- border-right-width: 1rpx;
- border-color: #E6E6E6;
- border-style: solid;
- border-bottom-right-radius: 24rpx;
- padding: 22rpx;
-
- &__text{
- font-size: 34rpx;
- }
- }
-
- &-hover {
- background-color: #f1f1f1;
- }
-
- }
- }
-
- }
- </style>
|