uni-popup-message.vue 2.5 KB

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