di-descriptions-item.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <u-row class="di-descriptions-item" align="top">
  3. <u-col :span="labelCol || parentCol.labelCol || 3" class="di-descriptions-item__label">
  4. <slot name="label">
  5. {{label ? label + ':' : ''}}
  6. </slot>
  7. </u-col>
  8. <u-col :span="valueCol || parentCol.valueCol || 9" class="di-descriptions-item__value">
  9. <slot name="value">
  10. <view :class="{'di-descriptions-item__ellipsis': ellipsis}">
  11. {{value || ''}}
  12. </view>
  13. </slot>
  14. </u-col>
  15. </u-row>
  16. </template>
  17. <script>
  18. /**
  19. * di-descriptions-item 描述列表项
  20. * @description 描述列表项,用于展示label value的值,比如对象详情页面等。 搭配父组件di-descriptions
  21. * @property {String slot} label label
  22. * @property {String Number slot} value value
  23. * @property {Boolean} ellipsis value过长是否显示省略(默认false)
  24. * @property {Number String} label-col label宽度,等分12份,可以继承di-descriptions#label-col,默认值3
  25. * @property {Number String} value-col value宽度,等分12份,可以继承di-descriptions#value-col,默认值9
  26. */
  27. export default {
  28. computed: {
  29. parentCol() {
  30. if(this.descriptions && this.descriptions.$options && this.descriptions.$options.propsData) {
  31. let {labelCol, valueCol} = this.descriptions.$options.propsData
  32. return {labelCol, valueCol}
  33. }
  34. return {}
  35. },
  36. descriptions() {
  37. let parent = this.$parent;
  38. let parentName = parent.$options._componentTag;
  39. while (parentName !== 'di-descriptions') {
  40. if(!(parent = parent.$parent)) {
  41. break
  42. }
  43. parentName = parent.$options._componentTag;
  44. }
  45. return parent;
  46. }
  47. },
  48. props: {
  49. label: {
  50. type: String,
  51. require: true
  52. },
  53. value: {
  54. type: [String, Number],
  55. require: true
  56. },
  57. ellipsis: {
  58. type: Boolean,
  59. default: false
  60. },
  61. labelCol: {
  62. type: [String, Number]
  63. },
  64. valueCol: {
  65. type: [String, Number]
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss">
  71. .di-descriptions-item {
  72. color: $u-content-color;
  73. margin-bottom: 10rpx;
  74. &__label {
  75. color: #a3a3a3;;
  76. }
  77. &__ellipsis {
  78. overflow: hidden;
  79. text-overflow: ellipsis;
  80. white-space: nowrap;
  81. }
  82. }
  83. </style>