fs-cell.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view
  3. class="fs-cell"
  4. :class="[cls,{shadow}]"
  5. :style="{backgroundColor:bgColor}"
  6. @click="handleClick"
  7. >
  8. <view class="fs-cell-flex" :class="['fs-cell-align-' + align, justify,{reverse}]">
  9. <view class="fs-cell-title" :style="titleStyle">
  10. <template v-if="title">{{title}}</template>
  11. <slot v-else name="title"></slot>
  12. </view>
  13. <view class="fs-cell-value">
  14. <template v-if="value">{{value}}</template>
  15. <slot v-else name="value"></slot>
  16. </view>
  17. <view class="fs-cell-extra">
  18. <template v-if="extra">{{extra}}</template>
  19. <slot v-else name="extra"></slot>
  20. </view>
  21. </view>
  22. <view class="fs-cell-label">
  23. <template v-if="label">{{label}}</template>
  24. <slot v-else name="label"></slot>
  25. </view>
  26. <view class="arrow-icon">
  27. <fs-icon type="icon-d-down" rotate="-90" size="28rpx" :color="arrowColor" :colorType="arrowColorType"></fs-icon>
  28. </view>
  29. </view>
  30. </template>
  31. <script setup>
  32. import { computed, toRefs, inject } from 'vue'
  33. const props = defineProps({
  34. title: String,
  35. titleWidth: String,
  36. value: String,
  37. extra: String,
  38. label: String,
  39. arrow: Boolean,
  40. arrowColor: {
  41. type: String,
  42. default: ''
  43. },
  44. arrowColorType: {
  45. type: String,
  46. validator(value) {
  47. return ['primary', 'success', 'info', 'warning', 'danger'].includes(value)
  48. }
  49. },
  50. border: Boolean,
  51. tighten: Boolean,
  52. gutter: Boolean,
  53. radius: Boolean,
  54. reverse: Boolean,
  55. align: {
  56. type: String,
  57. default: 'center',
  58. validator(value) {
  59. return ['top', 'center', 'bottom', 'stretch'].includes(value)
  60. }
  61. },
  62. justify: {
  63. type: String,
  64. validator(value) {
  65. return ['left', 'center', 'right'].includes(value)
  66. }
  67. },
  68. bgColor: {
  69. type: String,
  70. },
  71. shadow: Boolean,
  72. link: String,
  73. linkType: {
  74. type: String,
  75. default: 'navigateTo'
  76. },
  77. })
  78. const emits = defineEmits(['click'])
  79. const cellGroup = inject('cellGroup', {})
  80. const justify = props.justify || cellGroup.justify || 'left'
  81. const bgColor = props.bgColor || cellGroup.bgColor || '#fff'
  82. const arrowColor = props.arrowColor || cellGroup.arrowColor
  83. const arrowColorType = props.arrowColorType || cellGroup.arrowColorType
  84. const cls = computed(() => {
  85. const classNames = [];
  86. (props.arrow || cellGroup.arrow) && classNames.push('arrow');
  87. (props.border || cellGroup.border) && classNames.push('border');
  88. (props.tighten || cellGroup.tighten) && classNames.push('tighten')
  89. props.gutter && classNames.push('gutter')
  90. props.radius && classNames.push('radius')
  91. return classNames.join(' ')
  92. })
  93. const titleStyle = computed(() => {
  94. const width = props.titleWidth || cellGroup.titleWidth
  95. return width ? `width: ${width}` : ''
  96. })
  97. const handleClick = () => {
  98. if (props.link) {
  99. uni[props.linkType]({
  100. url: props.link
  101. })
  102. }
  103. emits('click')
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .fs-cell {
  108. padding: 30rpx var(--gutter);
  109. position: relative;
  110. font-size: var(--content-size);
  111. background-color: #fff;
  112. line-height: 1.4;
  113. width: 100%;
  114. box-sizing: border-box;
  115. &-flex {
  116. display: flex;
  117. justify-content: space-between;
  118. }
  119. &-value {
  120. flex: 1;
  121. padding-left: 20rpx;
  122. text-align: right;
  123. }
  124. &-label {
  125. font-size: var(--sub-size);
  126. color: var(--sub);
  127. }
  128. &-align-top {
  129. align-items: flex-start;
  130. }
  131. &-align-center {
  132. align-items: center;
  133. }
  134. &-align-bottom {
  135. align-items: flex-end;
  136. }
  137. &.arrow {
  138. padding-right: 50rpx;
  139. .arrow-icon{
  140. display: block;
  141. }
  142. }
  143. &.gutter {
  144. margin-bottom: var(--gutter-v);
  145. }
  146. &.radius {
  147. border-radius: var(--radius);
  148. }
  149. &.reverse{
  150. flex-direction: row-reverse;
  151. }
  152. &.tighten {
  153. padding: var(--tighten-gutter);
  154. }
  155. &.border {
  156. border-bottom: 2rpx solid var(--border-color);
  157. }
  158. }
  159. .arrow-icon{
  160. display: none;
  161. position: absolute;
  162. right: 10rpx;
  163. top: 50%;
  164. transform: translateY(-50%);
  165. }
  166. .left .fs-cell-value {
  167. text-align: left;
  168. }
  169. .center .fs-cell-value {
  170. text-align: center;
  171. }
  172. .right .fs-cell-value {
  173. text-align: right;
  174. }
  175. </style>