com-button.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view
  3. :class="{'com-button': true, 'default': defaultClass }"
  4. :style="{width: btnWidth, height: btnHeight, borderRadius: btnRadius,background:background}"
  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. type: {
  37. type: String,
  38. default: () => {
  39. return 'pramary'
  40. }
  41. },
  42. background: {
  43. type: String,
  44. default: () => {
  45. return 'linear-gradient(90deg, #3377FF 0%, #4D97FF 100%)'
  46. }
  47. }
  48. },
  49. computed: {
  50. btnWidth() {
  51. return this.width * 750 / 1200 + 'rpx';
  52. },
  53. btnHeight() {
  54. return this.height * 750 / 1200 + 'rpx';
  55. },
  56. btnRadius() {
  57. return this.height / 2 * 750 / 1200 + 'rpx';
  58. },
  59. fSize() {
  60. return this.fontSize * 750 / 1200 + 'rpx';
  61. },
  62. defaultClass() {
  63. return this.type === 'default' ? true : false
  64. },
  65. },
  66. data() {
  67. return {
  68. }
  69. },
  70. methods: {
  71. btnClick() {
  72. this.$emit('btnClick')
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="less" scoped>
  78. .com-button {
  79. display: flex;
  80. align-items: center;
  81. justify-content: center;
  82. width: 62.5rpx;
  83. height: 31.25rpx;
  84. background: linear-gradient(90deg, #3377FF 0%, #4D97FF 100%);
  85. border-radius: 37.5rpx;
  86. overflow: hidden;
  87. color: #FFFFFF;
  88. .btn-text {
  89. font-size: 10.93rpx;
  90. }
  91. }
  92. .default {
  93. background: #E6EAF2;
  94. color: #7A8599;
  95. }
  96. </style>