com-button.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <view
  3. :class="{'com-button': true, 'default': defaultClass }"
  4. :style="{width: btnWidth, height: btnHeight, borderRadius: btnRadius,background:background,marginBottom:btnMarginBottom}"
  5. @click="btnClick">
  6. <text class="btn-text" :style="{fontSize: fSize}">{{ btnText }}</text>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. props:{
  12. width: { // 按钮宽度(直接写设计稿量取大小即可
  13. type: Number,
  14. default: () => {
  15. return 160
  16. }
  17. },
  18. height: { // 按钮宽度(直接写设计稿量取大小即可
  19. type: Number,
  20. default: () => {
  21. return 64
  22. }
  23. },
  24. btnText: {
  25. type: String,
  26. default: () => {
  27. return '完成'
  28. }
  29. },
  30. fontSize: {
  31. type: Number,
  32. default: () => {
  33. return 28
  34. }
  35. },
  36. marginBottom:{
  37. type: Number,
  38. default: () => {
  39. return 0
  40. }
  41. },
  42. type: {
  43. type: String,
  44. default: () => {
  45. return 'pramary'
  46. }
  47. },
  48. background: {
  49. type: String,
  50. default: () => {
  51. return 'linear-gradient(90deg, #3377FF 0%, #4D97FF 100%)'
  52. }
  53. }
  54. },
  55. computed: {
  56. btnWidth() {
  57. return this.width * 750 / 1200 + 'rpx';
  58. },
  59. btnHeight() {
  60. return this.height * 750 / 1200 + 'rpx';
  61. },
  62. btnRadius() {
  63. return this.height / 2 * 750 / 1200 + 'rpx';
  64. },
  65. fSize() {
  66. return this.fontSize * 750 / 1200 + 'rpx';
  67. },
  68. btnMarginBottom() {
  69. return this.marginBottom * 750 / 1200 + 'rpx';
  70. },
  71. defaultClass() {
  72. return this.type === 'default' ? true : false
  73. },
  74. },
  75. data() {
  76. return {
  77. }
  78. },
  79. methods: {
  80. btnClick() {
  81. this.$emit('btnClick')
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="less" scoped>
  87. .com-button {
  88. display: flex;
  89. align-items: center;
  90. justify-content: center;
  91. width: 62.5rpx;
  92. height: 31.25rpx;
  93. background: linear-gradient(90deg, #3377FF 0%, #4D97FF 100%);
  94. border-radius: 37.5rpx;
  95. overflow: hidden;
  96. color: #FFFFFF;
  97. .btn-text {
  98. font-size: 10.93rpx;
  99. }
  100. }
  101. .default {
  102. background: #E6EAF2!important;
  103. color: #7A8599;
  104. }
  105. </style>