123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <template>
- <div class="com-list-box" :class="{ fill: height == 'fill', auto: height == 'auto' }">
- <div class="com-list-title" v-if="title != ''">{{ title }}</div>
- <div class="com-list-body">
- <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>
- </div>
- </div>
- </template>
- <script>
- export default {
- // 名称
- name: "List",
- // 使用组件
- components: {},
- // 传入参数
- props: {
- // 标题 ""不显示
- title: {
- type: String,
- default: "",
- },
- // 列表面板高度 fill auto 27.778vh
- height: {
- type: String,
- default: "fill",
- },
- // 默认选中第几个
- index: {
- type: Number,
- default: 0,
- },
- /**
- * {
- text: "1#逆变室",
- color: "blue"
- }
- */
- list: {
- type: Array,
- default: () => [
- {
- text: "1#逆变室",
- color: "blue",
- },
- {
- text: "1#逆变室",
- color: "blue",
- },
- {
- text: "1#逆变室",
- color: "red",
- },
- {
- text: "1#逆变室",
- color: "green",
- },
- {
- text: "1#逆变室",
- color: "purple",
- },
- ],
- },
- },
- // 自定义事件
- emits: {
- // 选中事件
- select: null,
- },
- // 数据
- data() {
- return {
- activeIndex: 0,
- };
- },
- // 函数
- methods: {
- select: function(index) {
- this.activeIndex = index;
- this.$emit("select", this.list[index]);
- },
- },
- // 生命周期钩子
- beforeCreate() {
- // 创建前
- },
- created() {
- // 创建后
- this.activeIndex = this.index;
- },
- beforeMount() {
- // 渲染前
- },
- mounted() {
- // 渲染后
- if (this.height != "fill" && this.height != "auto") {
- this.$el.style.height = this.height;
- }
- },
- beforeUpdate() {
- // 数据更新前
- },
- updated() {
- // 数据更新后
- },
- };
- </script>
- <style lang="less">
- .com-list-box {
- display: flex;
- flex-direction: column;
- &.auto {
- height: auto;
- }
- &.fill {
- height: 100%;
- }
- .com-list-title {
- font-size: @fontsize-l;
- color: @write;
- background-color: fade(@darkgray, 50%);
- padding: 1.481vh 1.852vh;
- }
- .com-list-body {
- background-color: fade(@darkgray, 20%);
- flex-grow: 1;
- overflow: auto;
- display: flex;
- flex-direction: column;
- .con-list-item {
- color: @gray;
- position: relative;
- font-size: @fontsize;
- text-align: center;
- padding: 0.37vh 0;
- border-bottom: 0.093vh solid @darkgray;
- cursor: pointer;
- &:hover {
- background-color: fade(@darkgray, 30%);
- }
- &.active {
- color: @write;
- background-color: fade(@purple, 60%);
- }
- &::after {
- content: "";
- position: absolute;
- width: 0.741vh;
- height: 0.741vh;
- left: 1.111vh;
- top: calc(50% - 0.37vh);
- }
- &.write {
- &::after {
- background-color: @write;
- }
- }
- &.green {
- &::after {
- background-color: @green;
- }
- }
- &.blue {
- &::after {
- background-color: @blue;
- }
- }
- &.purple {
- &::after {
- background-color: @purple;
- }
- }
- &.red {
- &::after {
- background-color: @red;
- }
- }
- &.orange {
- &::after {
- background-color: @orange;
- }
- }
- &.gray {
- &::after {
- background-color: @darkgray;
- }
- }
- &.yellow {
- &::after {
- background-color: @yellow;
- }
- }
- }
- }
- }
- </style>
|