tm-loadding.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view @click="$emit('click',$event)" class="tm-loadding flex-center vertical-align-middle">
  3. <!-- 加载中。 -->
  4. <view style="line-height: 0;" v-if="model=='load'" class="tm-loadding-load d-inline-block vertical-align-middle">
  5. <tm-icons dense :name="icon?icon:'icon-loading'" :color="color?color:'grey'"></tm-icons>
  6. </view>
  7. <view style="line-height: 0;" v-if="model=='fail'" class="tm-loadding-error d-inline-block vertical-align-middle">
  8. <tm-icons dense :name="icon?icon:'icon-wind-cry'" :color="color?color:'red'"></tm-icons>
  9. </view>
  10. <view style="line-height: 0;" v-if="model=='success'" class="tm-loadding-error d-inline-block vertical-align-middle">
  11. <tm-icons dense :name="icon?icon:'icon-wind-smile'" :color="color?color:'green'"></tm-icons>
  12. </view>
  13. <text class="text-size-s pl-12" :class="['text-'+(color?color:text[model].color)]">{{label?label:text[model].text}}</text>
  14. </view>
  15. </template>
  16. <script>
  17. /**
  18. * 加载状态
  19. * @description 为了方便管理数据加载提示。在全为true时,fail最先展示 ,其次success,其次load.
  20. * @property {Boolean} load = [true|false] 默认true,优先级最低。
  21. * @property {Boolean} success = [true|false] 默认false,优先级高于load。
  22. * @property {Boolean} fail = [true|false] 默认false,优先级高于success。
  23. * @property {String} label = [] 默认 '',自定义文本
  24. * @property {String} icon = [] 默认 '',自定义图标
  25. * @property {String} color = [] 默认 '',自定义主题
  26. * @property {Function} click 点击事件
  27. * @example <tm-loadding ></tm-loadding>
  28. */
  29. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  30. export default {
  31. components:{tmIcons},
  32. name:"tm-loadding",
  33. props:{
  34. // 优先级最低。
  35. load:{
  36. type:Boolean,
  37. default:true
  38. },
  39. //优先级最高。
  40. fail:{
  41. type:Boolean,
  42. default:false
  43. },
  44. //优先级高于load
  45. success:{
  46. type:Boolean,
  47. default:false
  48. },
  49. label:{
  50. type:String,
  51. default:''
  52. },
  53. icon:{
  54. type:String,
  55. default:''
  56. },
  57. color:{
  58. type:String,
  59. default:''
  60. }
  61. },
  62. computed:{
  63. model:function(){
  64. if(this.fail) return 'fail';
  65. if(this.success) return 'success';
  66. if(this.load) return 'load';
  67. return 'load';
  68. }
  69. },
  70. data() {
  71. return {
  72. text:{
  73. load:{
  74. text:"加载中...",
  75. color:"grey"
  76. },
  77. fail:{
  78. text:"加载失败...",
  79. color:"red"
  80. },
  81. success:{
  82. text:"加载成功...",
  83. color:"green"
  84. },
  85. loadmore:{
  86. text:"上拉加载更多",
  87. color:"grey"
  88. },
  89. nomore:{
  90. text:"没有更多了哦",
  91. color:"grey"
  92. }
  93. }
  94. };
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .tm-loadding{
  100. .tm-loadding-load{
  101. animation: xhRote 0.8s infinite linear;
  102. }
  103. }
  104. @keyframes xhRote{
  105. 0%{
  106. transform: rotate(0deg);
  107. }
  108. 100%{
  109. transform: rotate(360deg);
  110. }
  111. }
  112. </style>