list.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div class="com-list-box" :class="{ fill: height == 'fill', auto: height == 'auto' }">
  3. <div class="com-list-title" v-if="title != ''">{{ title }}</div>
  4. <div class="com-list-body">
  5. <div class="con-list-item" v-for="(data, index) of list" :key="index" @click="select(index)" :class="data.color + ' ' + (activeIndex == index ? 'active' : '')">{{ data.text }}</div>
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. export default {
  11. // 名称
  12. name: "List",
  13. // 使用组件
  14. components: {},
  15. // 传入参数
  16. props: {
  17. // 标题 ""不显示
  18. title: {
  19. type: String,
  20. default: "",
  21. },
  22. // 列表面板高度 fill auto 27.778vh
  23. height: {
  24. type: String,
  25. default: "fill",
  26. },
  27. // 默认选中第几个
  28. index: {
  29. type: Number,
  30. default: 0,
  31. },
  32. /**
  33. * {
  34. text: "1#逆变室",
  35. color: "blue"
  36. }
  37. */
  38. list: Array,
  39. },
  40. // 自定义事件
  41. emits: {
  42. // 选中事件
  43. select: null,
  44. },
  45. // 数据
  46. data() {
  47. return {
  48. activeIndex: 0,
  49. };
  50. },
  51. // 函数
  52. methods: {
  53. select: function(index) {
  54. this.activeIndex = index;
  55. this.$emit("select", this.list[index]);
  56. },
  57. },
  58. // 生命周期钩子
  59. beforeCreate() {
  60. // 创建前
  61. },
  62. created() {
  63. // 创建后
  64. this.activeIndex = this.index;
  65. },
  66. beforeMount() {
  67. // 渲染前
  68. },
  69. mounted() {
  70. // 渲染后
  71. if (this.height != "fill" && this.height != "auto") {
  72. this.$el.style.height = this.height;
  73. }
  74. },
  75. beforeUpdate() {
  76. // 数据更新前
  77. },
  78. updated() {
  79. // 数据更新后
  80. },
  81. };
  82. </script>
  83. <style lang="less">
  84. .com-list-box {
  85. display: flex;
  86. flex-direction: column;
  87. &.auto {
  88. height: auto;
  89. }
  90. &.fill {
  91. height: 100%;
  92. }
  93. .com-list-title {
  94. font-size: @fontsize-l;
  95. color: @write;
  96. background-color: fade(@darkgray, 50%);
  97. padding: 1.481vh 1.852vh;
  98. }
  99. .com-list-body {
  100. background-color: fade(@darkgray, 20%);
  101. flex-grow: 1;
  102. overflow: auto;
  103. display: flex;
  104. flex-direction: column;
  105. .con-list-item {
  106. color: @gray;
  107. position: relative;
  108. font-size: @fontsize;
  109. text-align: center;
  110. padding: 0.37vh 0;
  111. border-bottom: 0.093vh solid @darkgray;
  112. cursor: pointer;
  113. &:hover {
  114. background-color: fade(@darkgray, 30%);
  115. }
  116. &.active {
  117. color: @write;
  118. background-color: fade(@blue, 60%);
  119. }
  120. &::after {
  121. content: "";
  122. position: absolute;
  123. width: 0.741vh;
  124. height: 0.741vh;
  125. left: 1.111vh;
  126. top: calc(50% - 0.37vh);
  127. }
  128. &.write {
  129. &::after {
  130. background-color: @write;
  131. }
  132. }
  133. &.green {
  134. &::after {
  135. background-color: @green;
  136. }
  137. }
  138. &.blue {
  139. &::after {
  140. background-color: @blue;
  141. }
  142. }
  143. &.purple {
  144. &::after {
  145. background-color: @purple;
  146. }
  147. }
  148. &.red {
  149. &::after {
  150. background-color: @red;
  151. }
  152. }
  153. &.orange {
  154. &::after {
  155. background-color: @orange;
  156. }
  157. }
  158. &.gray {
  159. &::after {
  160. background-color: @darkgray;
  161. }
  162. }
  163. &.yellow {
  164. &::after {
  165. background-color: @yellow;
  166. }
  167. }
  168. }
  169. }
  170. }
  171. </style>