tui-alerts.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="tui-alert__wrap"
  3. :style="{backgroundColor:backgroundColor?backgroundColor:getColor(type),borderRadius:radius,paddingTop:padding[0] || 0,paddingRight:padding[1]||0,paddingBottom:padding[2] || padding[0]||0,paddingLeft:padding[3] || padding[1]||0}">
  4. <view class="tui-alert__shrink" @tap.stop="leftClick">
  5. <slot name="left"></slot>
  6. <icon :type="type" :size="iconSize" :color="iconColor" v-if="!isLeft"></icon>
  7. </view>
  8. <view class="tui-alert__content" :class="{'tui-text__p-left':!isLeft,'tui-text__p-right':closable}"
  9. @tap.stop="onClick">
  10. <text class="tui-alert__text" :style="{fontSize:size,color:color}" v-if="title">{{title}}</text>
  11. <text class="tui-alert__text tui-desc__padding" :class="{'tui-alert__single':single}"
  12. :style="{fontSize:descSize,color:descColor}" v-if="desc">{{desc}}</text>
  13. <slot name="content"></slot>
  14. </view>
  15. <view class="tui-alert__shrink">
  16. <slot name="right"></slot>
  17. </view>
  18. <icon @tap.stop="close" type="cancel" :size="closeSize" :color="closeColor" v-if="closable"
  19. :class="{'tui-alert__icon-close':desc}">
  20. </icon>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: "tui-alerts",
  26. emits: ['leftClick','click','close'],
  27. props: {
  28. //info, success, warn, waiting,clear
  29. type: {
  30. type: String,
  31. default: 'info'
  32. },
  33. //背景色,如果设置type对应颜色失效
  34. backgroundColor: {
  35. type: String,
  36. default: ''
  37. },
  38. //nvue不支持简写,['20rpx','30rpx','20rpx','30rpx']=>[上,右,下,左]
  39. padding: {
  40. type: Array,
  41. default () {
  42. return ['20rpx', '30rpx']
  43. }
  44. },
  45. radius: {
  46. type: String,
  47. default: '6rpx'
  48. },
  49. iconColor: {
  50. type: String,
  51. default: '#fff'
  52. },
  53. //icon字体大小,px
  54. iconSize: {
  55. type: Number,
  56. default: 24
  57. },
  58. closable: {
  59. type: Boolean,
  60. default: false
  61. },
  62. closeColor: {
  63. type: String,
  64. default: '#fff'
  65. },
  66. //关闭icon字体大小,px
  67. closeSize: {
  68. type: Number,
  69. default: 24
  70. },
  71. //是否自定义左侧内容
  72. isLeft: {
  73. type: Boolean,
  74. default: false
  75. },
  76. isRight:{
  77. type: Boolean,
  78. default: false
  79. },
  80. title: {
  81. type: String,
  82. default: ''
  83. },
  84. color: {
  85. type: String,
  86. default: '#fff'
  87. },
  88. size: {
  89. type: String,
  90. default: '14px'
  91. },
  92. desc: {
  93. type: String,
  94. default: ''
  95. },
  96. descColor: {
  97. type: String,
  98. default: '#fff'
  99. },
  100. descSize: {
  101. type: String,
  102. default: '12px'
  103. },
  104. //描述文字单行展示,超出隐藏
  105. single: {
  106. type: Boolean,
  107. default: false
  108. }
  109. },
  110. methods: {
  111. getColor(type) {
  112. const color = "#5677fc"
  113. const colors = {
  114. 'success': '#19be6b',
  115. 'warn': '#ff7900',
  116. 'clear': '#EB0909'
  117. }
  118. return colors[type] ? colors[type] : color;
  119. },
  120. leftClick() {
  121. this.$emit('leftClick', {})
  122. },
  123. onClick() {
  124. this.$emit('click', {})
  125. },
  126. close() {
  127. this.$emit('close', {})
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. .tui-alert__wrap {
  134. flex: 1;
  135. /* #ifndef APP-NVUE */
  136. display: flex;
  137. width: 100%;
  138. box-sizing: border-box;
  139. /* #endif */
  140. flex-direction: row;
  141. align-items: center;
  142. position: relative;
  143. }
  144. .tui-alert__shrink {
  145. /* #ifndef APP-NVUE */
  146. flex-shrink: 0;
  147. display: flex;
  148. align-items: center;
  149. justify-content: center;
  150. /* #endif */
  151. }
  152. .tui-alert__content {
  153. flex: 1;
  154. flex-direction: column;
  155. overflow: hidden;
  156. }
  157. .tui-alert__text {
  158. /* #ifndef APP-NVUE */
  159. word-break: break-all;
  160. display: block;
  161. box-sizing: border-box;
  162. /* #endif */
  163. }
  164. .tui-desc__padding{
  165. padding-top: 3px;
  166. }
  167. .tui-text__p-left {
  168. padding-left: 20rpx;
  169. }
  170. .tui-text__p-right {
  171. padding-right: 60rpx;
  172. }
  173. .tui-alert__single {
  174. /* #ifdef APP-NVUE */
  175. lines: 1;
  176. /* #endif */
  177. /* #ifndef APP-NVUE */
  178. display: block;
  179. width: 100%;
  180. white-space: nowrap;
  181. /* #endif */
  182. flex-direction: row;
  183. overflow: hidden;
  184. text-overflow: ellipsis;
  185. }
  186. .tui-alert__icon-close {
  187. position: absolute;
  188. right: 30rpx;
  189. top: 16rpx;
  190. /* #ifdef H5 */
  191. cursor: pointer;
  192. /* #endif */
  193. }
  194. </style>