Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

220 Zeilen
4.4 KiB

  1. <template>
  2. <view class="u-alert-tips" v-if="show" :class="[
  3. !show ? 'u-close-alert-tips': '',
  4. type ? 'u-alert-tips--bg--' + type + '-light' : '',
  5. type ? 'u-alert-tips--border--' + type + '-disabled' : '',
  6. ]" :style="{
  7. backgroundColor: bgColor,
  8. borderColor: borderColor
  9. }">
  10. <view class="u-icon-wrap">
  11. <u-icon v-if="showIcon" :name="$u.type2icon(type)" :size="description ? 40 : 32" class="u-icon" :color="type"></u-icon>
  12. </view>
  13. <view class="u-alert-content" @tap.stop="click">
  14. <view class="u-alert-title" :style="{fontWeight: description ? 500 : 'normal'}">
  15. {{title}}
  16. </view>
  17. <view v-if="description" class="u-alert-desc">
  18. {{description}}
  19. </view>
  20. </view>
  21. <view class="u-icon-wrap">
  22. <u-icon @click="close" v-if="closeAble && !closeText" hoverClass="u-type-error-hover-color" name="close" color="#c0c4cc"
  23. :size="22" class="u-close-icon" :style="{
  24. top: description ? '18rpx' : '24rpx'
  25. }"></u-icon>
  26. </view>
  27. <text v-if="closeAble && closeText" class="u-close-text" :style="{
  28. top: description ? '18rpx' : '24rpx'
  29. }">{{closeText}}</text>
  30. </view>
  31. </template>
  32. <script>
  33. /**
  34. * alertTips 警告提示
  35. * @description 警告提示,展现需要关注的信息
  36. * @tutorial https://uviewui.com/components/alertTips.html
  37. * @property {String} title 显示的标题文字
  38. * @property {String} description 辅助性文字,颜色比title浅一点,字号也小一点,可选
  39. * @property {String} type 关闭按钮(默认为叉号icon图标)
  40. * @property {String} close-able 用文字替代关闭图标,close-able为true时有效
  41. * @property {Boolean} show-icon 是否显示左边的辅助图标
  42. * @property {Boolean} show 显示或隐藏组件
  43. * @event {Function} click 点击组件时触发
  44. * @event {Function} close 点击关闭按钮时触发
  45. */
  46. export default {
  47. name: 'u-alert-tips',
  48. props: {
  49. // 显示文字
  50. title: {
  51. type: String,
  52. default: ''
  53. },
  54. // 主题,success/warning/info/error
  55. type: {
  56. type: String,
  57. default: 'warning'
  58. },
  59. // 辅助性文字
  60. description: {
  61. type: String,
  62. default: ''
  63. },
  64. // 是否可关闭
  65. closeAble: {
  66. type: Boolean,
  67. default: false
  68. },
  69. // 关闭按钮自定义文本
  70. closeText: {
  71. type: String,
  72. default: ''
  73. },
  74. // 是否显示图标
  75. showIcon: {
  76. type: Boolean,
  77. default: false
  78. },
  79. // 文字颜色,如果定义了color值,icon会失效
  80. color: {
  81. type: String,
  82. default: ''
  83. },
  84. // 背景颜色
  85. bgColor: {
  86. type: String,
  87. default: ''
  88. },
  89. // 边框颜色
  90. borderColor: {
  91. type: String,
  92. default: ''
  93. },
  94. // 是否显示
  95. show: {
  96. type: Boolean,
  97. default: true
  98. }
  99. },
  100. data() {
  101. return {
  102. }
  103. },
  104. methods: {
  105. // 点击内容
  106. click() {
  107. this.$emit('click');
  108. },
  109. // 点击关闭按钮
  110. close() {
  111. this.$emit('close');
  112. }
  113. }
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. @import "../../libs/css/style.components.scss";
  118. .u-alert-tips {
  119. display: flex;
  120. align-items: center;
  121. padding: 16rpx 30rpx;
  122. border-radius: 8rpx;
  123. position: relative;
  124. transition: all 0.3s linear;
  125. border: 1px solid #fff;
  126. &--bg--primary-light {
  127. background-color: $u-type-primary-light;
  128. }
  129. &--bg--info-light {
  130. background-color: $u-type-info-light;
  131. }
  132. &--bg--success-light {
  133. background-color: $u-type-success-light;
  134. }
  135. &--bg--warning-light {
  136. background-color: $u-type-warning-light;
  137. }
  138. &--bg--error-light {
  139. background-color: $u-type-error-light;
  140. }
  141. &--border--primary-disabled {
  142. border-color: $u-type-primary-disabled;
  143. }
  144. &--border--success-disabled {
  145. border-color: $u-type-success-disabled;
  146. }
  147. &--border--error-disabled {
  148. border-color: $u-type-error-disabled;
  149. }
  150. &--border--warning-disabled {
  151. border-color: $u-type-warning-disabled;
  152. }
  153. &--border--info-disabled {
  154. border-color: $u-type-info-disabled;
  155. }
  156. }
  157. .u-close-alert-tips {
  158. opacity: 0;
  159. visibility: hidden;
  160. }
  161. @keyframes myfirst {
  162. from {
  163. height: 100%;
  164. }
  165. to {
  166. height: 0
  167. }
  168. }
  169. .u-icon {
  170. margin-right: 16rpx;
  171. }
  172. .u-alert-title {
  173. font-size: 28rpx;
  174. color: $u-main-color;
  175. }
  176. .u-alert-desc {
  177. font-size: 26rpx;
  178. text-align: left;
  179. color: $u-content-color;
  180. }
  181. .u-close-icon {
  182. position: absolute;
  183. top: 20rpx;
  184. right: 20rpx;
  185. }
  186. .u-close-hover {
  187. color: red;
  188. }
  189. .u-close-text {
  190. font-size: 24rpx;
  191. color: $u-tips-color;
  192. position: absolute;
  193. top: 20rpx;
  194. right: 20rpx;
  195. line-height: 1;
  196. }
  197. </style>