com-button.vue 2.5 KB

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