uni-popup-message.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <view class="uni-popup-message" :class="'uni-popup__'+[type]">
  3. <text class="uni-popup-message-text" :class="'uni-popup__'+[type]+'-text'">
  4. {{ message }}
  5. </text>
  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. inject: ['popup'],
  24. props: {
  25. /**
  26. * 主题 success/warning/info/error 默认 success
  27. */
  28. type: {
  29. type: String,
  30. default: 'success'
  31. },
  32. /**
  33. * 消息文字
  34. */
  35. message: {
  36. type: String,
  37. default: ''
  38. },
  39. /**
  40. * 显示时间,设置为 0 则不会自动关闭
  41. */
  42. duration: {
  43. type: Number,
  44. default: 3000
  45. }
  46. },
  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 scoped>
  68. .uni-popup-message {
  69. /* #ifndef APP-NVUE */
  70. display: flex;
  71. /* #endif */
  72. flex-direction: row;
  73. background-color: #e1f3d8;
  74. padding: 10px 15px;
  75. border-color: #eee;
  76. border-style: solid;
  77. border-width: 1px;
  78. }
  79. .uni-popup-message-text {
  80. font-size: 14px;
  81. padding: 0;
  82. }
  83. .uni-popup__success {
  84. background-color: #e1f3d8;
  85. }
  86. .uni-popup__success-text {
  87. color: #67C23A;
  88. }
  89. .uni-popup__warn {
  90. background-color: #faecd8;
  91. }
  92. .uni-popup__warn-text {
  93. color: #E6A23C;
  94. }
  95. .uni-popup__error {
  96. background-color: #fde2e2;
  97. }
  98. .uni-popup__error-text {
  99. color: #F56C6C;
  100. }
  101. .uni-popup__info {
  102. background-color: #F2F6FC;
  103. }
  104. .uni-popup__info-text {
  105. color: #909399;
  106. }
  107. </style>