u-toolbar.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 v-if="!showIcon" class="u-toolbar__wrapper__cancel" @tap="cancel" :style="{
  5. color: cancelColor
  6. }">{{ cancelText }}</text>
  7. <image class="closeBtn" v-else src="/static/images/closeBtn.png" mode="" @tap="cancel"></image>
  8. </view>
  9. <text class="u-toolbar__title u-line-1" v-if="title">{{ title }}</text>
  10. <view class="u-toolbar__confirm__wrapper" hover-class="u-hover-class">
  11. <text v-if="!showIcon" class="u-toolbar__wrapper__confirm" @tap="confirm" :style="{
  12. color: confirmColor
  13. }">{{ confirmText }}</text>
  14. <image class="confirmBtn" v-else src="/static/images/selected.png" mode="" @tap="confirm"></image>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import props from './props.js';
  20. /**
  21. * Toolbar 工具条
  22. * @description
  23. * @tutorial https://www.uviewui.com/components/toolbar.html
  24. * @property {Boolean} show 是否展示工具条(默认 true )
  25. * @property {String} cancelText 取消按钮的文字(默认 '取消' )
  26. * @property {String} confirmText 确认按钮的文字(默认 '确认' )
  27. * @property {String} cancelColor 取消按钮的颜色(默认 '#909193' )
  28. * @property {String} confirmColor 确认按钮的颜色(默认 '#3c9cff' )
  29. * @property {String} title 标题文字
  30. * @event {Function}
  31. * @example
  32. */
  33. export default {
  34. name: 'u-toolbar',
  35. mixins: [uni.$u.mpMixin, uni.$u.mixin, props],
  36. methods: {
  37. // 点击取消按钮
  38. cancel() {
  39. this.$emit('cancel')
  40. },
  41. // 点击确定按钮
  42. confirm() {
  43. this.$emit('confirm')
  44. }
  45. },
  46. }
  47. </script>
  48. <style lang="scss" scoped>
  49. @import "../../libs/css/components.scss";
  50. .closeBtn {
  51. width: 30rpx;
  52. height: 30rpx;
  53. margin-left: 15px;
  54. margin-right: 15px;
  55. }
  56. .confirmBtn {
  57. width: 38rpx;
  58. height: 30rpx;
  59. margin-left: 15px;
  60. margin-right: 15px;
  61. }
  62. .u-toolbar {
  63. height: 42px;
  64. @include flex;
  65. justify-content: space-between;
  66. align-items: center;
  67. &__wrapper {
  68. &__cancel {
  69. color: $u-tips-color;
  70. font-size: 15px;
  71. padding: 0 15px;
  72. }
  73. }
  74. &__title {
  75. color: $u-main-color;
  76. padding: 0 60rpx;
  77. font-size: 16px;
  78. flex: 1;
  79. text-align: center;
  80. }
  81. &__wrapper {
  82. &__confirm {
  83. color: $u-primary;
  84. font-size: 15px;
  85. padding: 0 15px;
  86. }
  87. }
  88. }
  89. </style>