uni-popup-message.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="uni-popup-message">
  3. <view
  4. class="uni-popup-message__box fixforpc-width"
  5. :class="'uni-popup__' + type"
  6. >
  7. <slot>
  8. <text
  9. class="uni-popup-message-text"
  10. :class="'uni-popup__' + type + '-text'"
  11. >{{ message }}</text
  12. >
  13. </slot>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import popup from '../uni-popup/popup.js'
  19. /**
  20. * PopUp 弹出层-消息提示
  21. * @description 弹出层-消息提示
  22. * @tutorial https://ext.dcloud.net.cn/plugin?id=329
  23. * @property {String} type = [success|warning|info|error] 主题样式
  24. * @value success 成功
  25. * @value warning 提示
  26. * @value info 消息
  27. * @value error 错误
  28. * @property {String} message 消息提示文字
  29. * @property {String} duration 显示时间,设置为 0 则不会自动关闭
  30. */
  31. export default {
  32. name: 'uniPopupMessage',
  33. mixins: [popup],
  34. props: {
  35. /**
  36. * 主题 success/warning/info/error 默认 success
  37. */
  38. type: {
  39. type: String,
  40. default: 'success'
  41. },
  42. /**
  43. * 消息文字
  44. */
  45. message: {
  46. type: String,
  47. default: ''
  48. },
  49. /**
  50. * 显示时间,设置为 0 则不会自动关闭
  51. */
  52. duration: {
  53. type: Number,
  54. default: 3000
  55. },
  56. maskShow: {
  57. type: Boolean,
  58. default: false
  59. }
  60. },
  61. data () {
  62. return {}
  63. },
  64. created () {
  65. this.popup.maskShow = this.maskShow
  66. this.popup.messageChild = this
  67. },
  68. methods: {
  69. timerClose () {
  70. if (this.duration === 0) return
  71. clearTimeout(this.timer)
  72. this.timer = setTimeout(() => {
  73. this.popup.close()
  74. }, this.duration)
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss">
  80. .uni-popup-message {
  81. /* #ifndef APP-NVUE */
  82. display: flex;
  83. /* #endif */
  84. flex-direction: row;
  85. justify-content: center;
  86. }
  87. .uni-popup-message__box {
  88. background-color: #e1f3d8;
  89. padding: 10px 15px;
  90. border-color: #eee;
  91. border-style: solid;
  92. border-width: 1px;
  93. flex: 1;
  94. }
  95. @media screen and (min-width: 500px) {
  96. .fixforpc-width {
  97. margin-top: 20px;
  98. border-radius: 4px;
  99. flex: none;
  100. min-width: 380px;
  101. /* #ifndef APP-NVUE */
  102. max-width: 50%;
  103. /* #endif */
  104. /* #ifdef APP-NVUE */
  105. max-width: 500px;
  106. /* #endif */
  107. }
  108. }
  109. .uni-popup-message-text {
  110. font-size: 32rpx;
  111. padding: 0;
  112. }
  113. .uni-popup__success {
  114. background-color: #e1f3d8;
  115. }
  116. .uni-popup__success-text {
  117. color: #67c23a;
  118. }
  119. .uni-popup__warn {
  120. background-color: #faecd8;
  121. }
  122. .uni-popup__warn-text {
  123. color: #e6a23c;
  124. }
  125. .uni-popup__error {
  126. background-color: #fde2e2;
  127. }
  128. .uni-popup__error-text {
  129. color: #f56c6c;
  130. }
  131. .uni-popup__info {
  132. background-color: #f2f6fc;
  133. }
  134. .uni-popup__info-text {
  135. color: #909399;
  136. }
  137. </style>