modal-mask-nvue.nvue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="app-modal" ref="appModal">
  3. <view class="app-modal__container">
  4. <view class="app-modal__container__header" v-if="title">
  5. <text class="app-modal__container__header__text">{{title}}</text>
  6. </view>
  7. <view class="app-modal__container__content">
  8. <text class="app-modal__container__content__text" :style="{textAlign: align}">{{content}}</text>
  9. </view>
  10. <view class="app-modal__container__footer">
  11. <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" >
  12. <text class="app-modal__container__footer-left__text" :style="{color:cancelColor}">{{cancelText}}</text>
  13. </view>
  14. <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" >
  15. <text class="app-modal__container__footer-right__text" :style="{color:confirmColor}">{{confirmText}}</text>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. const animation = weex.requireModule('animation');
  23. export default {
  24. data() {
  25. return {
  26. title: "提示",
  27. content: "",
  28. align: "center", // 对齐方式 left/center/right
  29. cancelText: "取消", // 取消按钮的文字
  30. cancelColor: "#8F8F8F", // 取消按钮颜色
  31. confirmText: "确定", // 确认按钮颜色
  32. confirmColor: "#FFAD15", // 确认按钮颜色
  33. showCancel: true, // 是否显示取消按钮,默认为 true
  34. };
  35. },
  36. onBackPress(options) {
  37. if (options.from === 'navigateBack') {
  38. return false;
  39. }
  40. return true;
  41. },
  42. onReady() {
  43. // 添加动画,避免弹窗闪烁问题
  44. animation.transition(this.$refs.appModal, {
  45. styles: {
  46. opacity: 1,
  47. },
  48. duration: 100,
  49. timingFunction: 'ease-in'
  50. });
  51. },
  52. onLoad(options) {
  53. if (options.showCancel) {
  54. options.showCancel = JSON.parse(options.showCancel)
  55. }
  56. Object.assign(this.$data, options)
  57. },
  58. methods: {
  59. clickLeft() {
  60. // 先关闭后发送事件
  61. this.closeModal();
  62. uni.$emit('AppModalCancel')
  63. },
  64. clickRight() {
  65. // 先关闭后发送事件
  66. this.closeModal();
  67. uni.$emit('AppModalConfirm')
  68. },
  69. closeModal() {
  70. uni.navigateBack();
  71. }
  72. }
  73. }
  74. </script>
  75. <style lang="scss">
  76. // nvue页面只支持flex布局
  77. .app-modal {
  78. position: fixed;
  79. left: 0;
  80. top: 0;
  81. right: 0;
  82. bottom: 0;
  83. /* #ifndef APP-NVUE */
  84. display: flex;
  85. /* #endif */
  86. justify-content: center;
  87. align-items: center;
  88. background-color: rgba(0, 0, 0, 0.4);
  89. opacity: 0;
  90. &__container {
  91. width: 630rpx;
  92. border-radius: 24rpx;
  93. background-color: #fff;
  94. overflow: hidden;
  95. &__header {
  96. /* #ifndef APP-NVUE */
  97. display: flex;
  98. /* #endif */
  99. justify-content: center;
  100. align-items: center;
  101. height: 90rpx;
  102. &__text {
  103. font-size: 32rpx;
  104. color: #262626;
  105. }
  106. }
  107. &__content {
  108. /* #ifndef APP-NVUE */
  109. display: flex;
  110. /* #endif */
  111. justify-content: center;
  112. align-items: center;
  113. padding: 0 30rpx 30rpx 30rpx;
  114. &__text {
  115. font-size: 30rpx;
  116. color: #262626;
  117. line-height: 50rpx;
  118. }
  119. }
  120. &__footer {
  121. /* #ifndef APP-NVUE */
  122. display: flex;
  123. /* #endif */
  124. justify-content: center;
  125. align-items: center;
  126. flex-direction: row;
  127. height: 88rpx;
  128. &-left {
  129. /* #ifndef APP-NVUE */
  130. display: flex;
  131. /* #endif */
  132. justify-content: center;
  133. align-items: center;
  134. border-top-width: 1rpx;
  135. border-right-width: 1rpx;
  136. border-color: #E6E6E6;
  137. border-style: solid;
  138. border-bottom-left-radius: 24rpx;
  139. padding: 22rpx;
  140. &__text{
  141. font-size: 34rpx;
  142. }
  143. }
  144. &-right {
  145. /* #ifndef APP-NVUE */
  146. display: flex;
  147. /* #endif */
  148. justify-content: center;
  149. align-items: center;
  150. border-top-width: 1rpx;
  151. border-right-width: 1rpx;
  152. border-color: #E6E6E6;
  153. border-style: solid;
  154. border-bottom-right-radius: 24rpx;
  155. padding: 22rpx;
  156. &__text{
  157. font-size: 34rpx;
  158. }
  159. }
  160. &-hover {
  161. background-color: #f1f1f1;
  162. }
  163. }
  164. }
  165. }
  166. </style>