3
0

u-toolbar.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view
  3. class="u-toolbar"
  4. @touchmove.stop.prevent="noop"
  5. v-if="show"
  6. >
  7. <view
  8. class="u-toolbar__left"
  9. >
  10. <view
  11. class="u-toolbar__cancel__wrapper"
  12. hover-class="u-hover-class"
  13. >
  14. <text
  15. class="u-toolbar__wrapper__cancel"
  16. @tap="cancel"
  17. :style="{
  18. color: cancelColor
  19. }"
  20. >{{ cancelText }}</text>
  21. </view>
  22. </view>
  23. <text
  24. class="u-toolbar__title u-line-1"
  25. v-if="title"
  26. >{{ title }}</text>
  27. <view
  28. class="u-toolbar__right"
  29. >
  30. <view
  31. v-if="!rightSlot"
  32. class="u-toolbar__confirm__wrapper"
  33. hover-class="u-hover-class"
  34. >
  35. <text
  36. class="u-toolbar__wrapper__confirm"
  37. @tap="confirm"
  38. :style="{
  39. color: confirmColor
  40. }"
  41. >{{ confirmText }}</text>
  42. </view>
  43. <template v-else>
  44. <slot name="right">
  45. </slot>
  46. </template>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import { props } from './props';
  52. import { mpMixin } from '../../libs/mixin/mpMixin';
  53. import { mixin } from '../../libs/mixin/mixin';
  54. /**
  55. * Toolbar 工具条
  56. * @description
  57. * @tutorial https://ijry.github.io/uview-plus/components/toolbar.html
  58. * @property {Boolean} show 是否展示工具条(默认 true )
  59. * @property {String} cancelText 取消按钮的文字(默认 '取消' )
  60. * @property {String} confirmText 确认按钮的文字(默认 '确认' )
  61. * @property {String} cancelColor 取消按钮的颜色(默认 '#909193' )
  62. * @property {String} confirmColor 确认按钮的颜色(默认 '#3c9cff' )
  63. * @property {String} title 标题文字
  64. * @event {Function}
  65. * @example
  66. */
  67. export default {
  68. name: 'u-toolbar',
  69. mixins: [mpMixin, mixin, props],
  70. emits: ["confirm", "cancel"],
  71. created() {
  72. // console.log(this.$slots)
  73. },
  74. methods: {
  75. // 点击取消按钮
  76. cancel() {
  77. this.$emit('cancel')
  78. },
  79. // 点击确定按钮
  80. confirm() {
  81. this.$emit('confirm')
  82. }
  83. },
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. @import "../../libs/css/components.scss";
  88. .u-toolbar {
  89. height: 42px;
  90. @include flex;
  91. justify-content: space-between;
  92. align-items: center;
  93. &__wrapper {
  94. &__cancel {
  95. color: $u-tips-color;
  96. font-size: 15px;
  97. padding: 0 15px;
  98. }
  99. }
  100. &__title {
  101. color: $u-main-color;
  102. padding: 0 60rpx;
  103. font-size: 16px;
  104. flex: 1;
  105. text-align: center;
  106. }
  107. &__wrapper {
  108. &__left,
  109. &__right {
  110. @include flex;
  111. }
  112. &__confirm {
  113. color: $u-primary;
  114. font-size: 15px;
  115. padding: 0 15px;
  116. }
  117. }
  118. }
  119. </style>