xm-cell.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view class="xm-cell" :class="{
  3. 'xm-cell-clickable': clickable,
  4. 'xm-cell-border': border,
  5. }" @click.stop="$emit('show', $event)">
  6. <view class="xm-cell-label">
  7. <view v-if="label">{{ label }}</view>
  8. <slot v-else name="label"></slot>
  9. </view>
  10. <view class="xm-cell-value">
  11. <view v-if="value" :class="{ 'xm-cell-special': special }">{{ valueFormat(value) }}</view>
  12. <slot v-else></slot>
  13. </view>
  14. <view v-if="arrow" class="xm-cell-arrow"></view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'xm-cell',
  20. emits: ['show'],
  21. props: {
  22. label: {
  23. type: String,
  24. default: ''
  25. },
  26. value: {
  27. type: String,
  28. default: ''
  29. },
  30. // 是否显示右箭头
  31. arrow: {
  32. type: Boolean,
  33. default: true
  34. },
  35. // 是否显示点击效果
  36. clickable: {
  37. type: Boolean,
  38. default: true
  39. },
  40. border: {
  41. type: Boolean,
  42. default: true
  43. },
  44. special: {
  45. type: Boolean,
  46. default: false
  47. }
  48. },
  49. methods: {
  50. valueFormat(value){
  51. if(!value){
  52. return ''
  53. }
  54. if(!this.special){
  55. return value;
  56. }
  57. return [ value.substring(0, 2), value.substring(2) ].filter(x => x).join('·')
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. .xm-cell {
  64. position: relative;
  65. flex: 1;
  66. width: 100%;
  67. display: flex;
  68. box-sizing: border-box;
  69. flex-direction: row;
  70. align-items: center;
  71. justify-content: space-between;
  72. padding: 10px 22px 10px 16px;
  73. background-color: #FFF;
  74. font-size: 14px;
  75. height: 48px;
  76. &-label {
  77. color: #323233;
  78. }
  79. &-value {
  80. color: #969799;
  81. }
  82. &-arrow {
  83. height: 20px;
  84. width: 20px;
  85. border-width: 3px 3px 0 0;
  86. border-style: solid;
  87. transform: rotate(45deg) scale(0.5);
  88. border-radius: 2px;
  89. flex-shrink: 0;
  90. margin-left: auto;
  91. box-sizing: border-box;
  92. transform-origin: center center;
  93. margin-right: -3px;
  94. border-color: #969799;
  95. position: absolute;
  96. right: 10px;
  97. }
  98. &-clickable:active {
  99. background-color: rgba(0, 0, 0, 0.03) !important;
  100. }
  101. &-border::after {
  102. position: absolute;
  103. box-sizing: border-box;
  104. content: ' ';
  105. pointer-events: none;
  106. right: 16px;
  107. bottom: 0;
  108. left: 16px;
  109. border-bottom: 1px solid #ebedf0;
  110. -webkit-transform: scaleY(0.5);
  111. transform: scaleY(0.5);
  112. }
  113. &-special {
  114. font-family: '微软雅黑';
  115. display: inline-block;
  116. padding: 4px 6px;
  117. background-color: #0072C6;
  118. color: #FFFFFF;
  119. letter-spacing: 2px;
  120. text-align: center;
  121. border-radius: 2px;
  122. }
  123. }
  124. </style>