su-toolbar.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="u-toolbar" @touchmove.stop.prevent="noop" v-if="show">
  3. <view class="u-toolbar__cancel__wrapper" hover-class="u-hover-class">
  4. <text
  5. class="u-toolbar__wrapper__cancel"
  6. @tap="cancel"
  7. :style="{
  8. color: cancelColor,
  9. }"
  10. >
  11. {{ cancelText }}
  12. </text>
  13. </view>
  14. <text class="u-toolbar__title u-line-1" v-if="title">{{ title }}</text>
  15. <view class="u-toolbar__confirm__wrapper" hover-class="u-hover-class">
  16. <text
  17. class="u-toolbar__wrapper__confirm"
  18. @tap="confirm"
  19. :style="{
  20. color: confirmColor,
  21. }"
  22. >
  23. {{ confirmText }}
  24. </text>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. /**
  30. * Toolbar 工具条
  31. * @description
  32. * @tutorial https://www.uviewui.com/components/toolbar.html
  33. * @property {Boolean} show 是否展示工具条(默认 true )
  34. * @property {String} cancelText 取消按钮的文字(默认 '取消' )
  35. * @property {String} confirmText 确认按钮的文字(默认 '确认' )
  36. * @property {String} cancelColor 取消按钮的颜色(默认 '#909193' )
  37. * @property {String} confirmColor 确认按钮的颜色(默认 '#3c9cff' )
  38. * @property {String} title 标题文字
  39. * @event {Function}
  40. * @example
  41. */
  42. export default {
  43. name: 'SuToolbar',
  44. props: {
  45. // 是否展示工具条
  46. show: {
  47. type: Boolean,
  48. default: true,
  49. },
  50. // 取消按钮的文字
  51. cancelText: {
  52. type: String,
  53. default: '取消',
  54. },
  55. // 确认按钮的文字
  56. confirmText: {
  57. type: String,
  58. default: '确认',
  59. },
  60. // 取消按钮的颜色
  61. cancelColor: {
  62. type: String,
  63. default: '#909193',
  64. },
  65. // 确认按钮的颜色
  66. confirmColor: {
  67. type: String,
  68. default: '#3c9cff',
  69. },
  70. // 标题文字
  71. title: {
  72. type: String,
  73. default: '',
  74. },
  75. },
  76. methods: {
  77. // 点击取消按钮
  78. cancel() {
  79. this.$emit('cancel');
  80. },
  81. // 点击确定按钮
  82. confirm() {
  83. this.$emit('confirm');
  84. },
  85. // 阻止事件冒泡
  86. preventEvent(e) {
  87. e && typeof e.stopPropagation === 'function' && e.stopPropagation();
  88. },
  89. // 空操作
  90. noop(e) {
  91. this.preventEvent(e);
  92. },
  93. },
  94. };
  95. </script>
  96. <style lang="scss" scoped>
  97. .u-toolbar {
  98. height: 42px;
  99. @include flex;
  100. justify-content: space-between;
  101. align-items: center;
  102. &__wrapper {
  103. &__cancel {
  104. color: #111111;
  105. font-size: 15px;
  106. padding: 0 15px;
  107. }
  108. }
  109. &__title {
  110. color: #000000;
  111. padding: 0 60rpx;
  112. font-size: 16px;
  113. flex: 1;
  114. text-align: center;
  115. }
  116. &__wrapper {
  117. &__confirm {
  118. color: #ffffff;
  119. font-size: 15px;
  120. padding: 0 15px;
  121. }
  122. }
  123. }
  124. </style>