list.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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: {
  39. type: Array,
  40. default: () => [
  41. {
  42. text: "1#逆变室",
  43. color: "blue",
  44. },
  45. {
  46. text: "1#逆变室",
  47. color: "blue",
  48. },
  49. {
  50. text: "1#逆变室",
  51. color: "red",
  52. },
  53. {
  54. text: "1#逆变室",
  55. color: "green",
  56. },
  57. {
  58. text: "1#逆变室",
  59. color: "purple",
  60. },
  61. ],
  62. },
  63. },
  64. // 自定义事件
  65. emits: {
  66. // 选中事件
  67. select: null,
  68. },
  69. // 数据
  70. data() {
  71. return {
  72. activeIndex: 0,
  73. };
  74. },
  75. // 函数
  76. methods: {
  77. select: function(index) {
  78. this.activeIndex = index;
  79. this.$emit("select", this.list[index]);
  80. },
  81. },
  82. // 生命周期钩子
  83. beforeCreate() {
  84. // 创建前
  85. },
  86. created() {
  87. // 创建后
  88. this.activeIndex = this.index;
  89. },
  90. beforeMount() {
  91. // 渲染前
  92. },
  93. mounted() {
  94. // 渲染后
  95. if (this.height != "fill" && this.height != "auto") {
  96. this.$el.style.height = this.height;
  97. }
  98. },
  99. beforeUpdate() {
  100. // 数据更新前
  101. },
  102. updated() {
  103. // 数据更新后
  104. },
  105. };
  106. </script>
  107. <style lang="less">
  108. .com-list-box {
  109. display: flex;
  110. flex-direction: column;
  111. &.auto {
  112. height: auto;
  113. }
  114. &.fill {
  115. height: 100%;
  116. }
  117. .com-list-title {
  118. font-size: @fontsize-l;
  119. color: @write;
  120. background-color: fade(@darkgray, 50%);
  121. padding: 1.481vh 1.852vh;
  122. }
  123. .com-list-body {
  124. background-color: fade(@darkgray, 20%);
  125. flex-grow: 1;
  126. overflow: auto;
  127. display: flex;
  128. flex-direction: column;
  129. .con-list-item {
  130. color: @gray;
  131. position: relative;
  132. font-size: @fontsize;
  133. text-align: center;
  134. padding: 0.37vh 0;
  135. border-bottom: 0.093vh solid @darkgray;
  136. cursor: pointer;
  137. &:hover {
  138. background-color: fade(@darkgray, 30%);
  139. }
  140. &.active {
  141. color: @write;
  142. background-color: fade(@purple, 60%);
  143. }
  144. &::after {
  145. content: "";
  146. position: absolute;
  147. width: 0.741vh;
  148. height: 0.741vh;
  149. left: 1.111vh;
  150. top: calc(50% - 0.37vh);
  151. }
  152. &.write {
  153. &::after {
  154. background-color: @write;
  155. }
  156. }
  157. &.green {
  158. &::after {
  159. background-color: @green;
  160. }
  161. }
  162. &.blue {
  163. &::after {
  164. background-color: @blue;
  165. }
  166. }
  167. &.purple {
  168. &::after {
  169. background-color: @purple;
  170. }
  171. }
  172. &.red {
  173. &::after {
  174. background-color: @red;
  175. }
  176. }
  177. &.orange {
  178. &::after {
  179. background-color: @orange;
  180. }
  181. }
  182. &.gray {
  183. &::after {
  184. background-color: @darkgray;
  185. }
  186. }
  187. &.yellow {
  188. &::after {
  189. background-color: @yellow;
  190. }
  191. }
  192. }
  193. }
  194. }
  195. </style>