index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <!--
  3. ss-search-button 搜索按钮组件
  4. 基于原JSP中的mobileSearch-button样式封装
  5. -->
  6. <button
  7. class="ss-search-button"
  8. :style="buttonStyle"
  9. @click="handleClick"
  10. :disabled="disabled"
  11. >
  12. <!-- 前置图标插槽 -->
  13. <view v-if="preIcon || $slots.preIcon" class="ss-search-button__pre-icon">
  14. <slot name="preIcon">
  15. <Icon v-if="preIcon" :name="preIcon" :size="iconSize" :color="iconColor" />
  16. </slot>
  17. </view>
  18. <!-- 按钮文本 -->
  19. <text class="ss-search-button__text">{{ text }}</text>
  20. <!-- 后置图标插槽 -->
  21. <view v-if="suffixIcon || $slots.suffixIcon" class="ss-search-button__suffix-icon">
  22. <slot name="suffixIcon">
  23. <Icon v-if="suffixIcon" :name="suffixIcon" :size="iconSize" :color="iconColor" />
  24. </slot>
  25. </view>
  26. </button>
  27. </template>
  28. <script setup>
  29. import { computed } from 'vue'
  30. import Icon from '@/components/icon/index.vue'
  31. const props = defineProps({
  32. // 按钮文本
  33. text: {
  34. type: String,
  35. default: '增加'
  36. },
  37. // 是否禁用
  38. disabled: {
  39. type: Boolean,
  40. default: false
  41. },
  42. // 按钮高度
  43. height: {
  44. type: [String, Number],
  45. default: '36px'
  46. },
  47. // 前置图标名称
  48. preIcon: {
  49. type: String,
  50. default: ''
  51. },
  52. // 后置图标名称
  53. suffixIcon: {
  54. type: String,
  55. default: ''
  56. },
  57. // 图标大小
  58. iconSize: {
  59. type: [String, Number],
  60. default: '32'
  61. },
  62. // 图标颜色
  63. iconColor: {
  64. type: String,
  65. default: '#585d6e'
  66. },
  67. // 自定义按钮样式
  68. customStyle: {
  69. type: Object,
  70. default: () => ({})
  71. },
  72. // 跳转链接(兼容原JSP用法)
  73. href: {
  74. type: String,
  75. default: ''
  76. }
  77. })
  78. const emit = defineEmits(['click'])
  79. // 按钮样式
  80. const buttonStyle = computed(() => ({
  81. height: typeof props.height === 'number' ? `${props.height}px` : props.height,
  82. ...props.customStyle
  83. }))
  84. const handleClick = () => {
  85. // 触发点击事件
  86. emit('click')
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .ss-search-button {
  91. height: auto;
  92. padding: 0 1rem;
  93. border: 1px solid #eceded;
  94. outline: none;
  95. background-color: #fff;
  96. text-align: center;
  97. font-size: 1rem;
  98. color: #585d6e;
  99. letter-spacing: 0.1rem;
  100. border-radius: 4px;
  101. display: flex;
  102. align-items: center;
  103. justify-content: center;
  104. -webkit-appearance: none;
  105. appearance: none;
  106. box-sizing: border-box;
  107. transition: all 0.2s ease;
  108. &:active {
  109. background-color: #eceded;
  110. color: #fff;
  111. border-color: #eceded;
  112. transform: scale(0.98);
  113. transition: all 0.1s ease;
  114. // active 状态下图标样式
  115. .ss-search-button__pre-icon,
  116. .ss-search-button__suffix-icon {
  117. :deep(.iconfont) {
  118. color: #fff !important;
  119. }
  120. :deep(text) {
  121. color: #fff !important;
  122. }
  123. }
  124. }
  125. &:disabled {
  126. opacity: 0.6;
  127. cursor: not-allowed;
  128. }
  129. &__pre-icon {
  130. margin-right: 0.3rem;
  131. display: flex;
  132. align-items: center;
  133. }
  134. &__suffix-icon {
  135. margin-left: 0.3rem;
  136. display: flex;
  137. align-items: center;
  138. }
  139. &__text {
  140. font-size: inherit;
  141. color: inherit;
  142. }
  143. }
  144. // 响应式适配
  145. @media screen and (max-width: 750px) {
  146. .ss-search-button {
  147. font-size: 14px;
  148. padding: 0 0.8rem;
  149. }
  150. }
  151. </style>