index.vue 2.54 KB
<template>
  <div>
    <template v-if="rowParams.length > 0">
      <div class="layout-wrap">
        <el-row :gutter="30">
          <template v-for="(params, index) in rowParams">
            <!-- <template v-if="params.isHidden && params.isHidden(list)">
            <el-col :span="params.span" :key="index">
              <div class="label-wrap">
                <label>{{ params.label }}</label>
                <slot v-if="params.addHtml" :name="params.addHtml" :scope="list"></slot>
                <span v-else>
                  {{ list[params.prop] }}
                </span>
              </div>
            </el-col>
          </template> -->
            <template>
              <el-col :span="params.span" :key="index">
                <div class="label-wrap">
                  <label>{{ params.label }}</label>
                  <slot v-if="params.addHtml" :name="params.addHtml" :scope="list"></slot>
                  <span v-else>
                    {{ list[params.prop] }}
                  </span>
                </div>
              </el-col>
            </template>
          </template>
        </el-row>
      </div>
    </template>
  </div>
</template>
<script>
export default {
  name: 'glsx-rows',
  data() {
    return {
      list: '',
      rowParams: ''
    }
  },
  props: {
    //获取的数据
    layoutData: {
      type: Object,
      default: () => {}
    },
    layoutParams: {
      type: Array,
      default: () => []
    }
  },
  watch: {
    layoutData(val) {
      this.list = val
      let { layoutParams } = this
      for (let i = 0; i < layoutParams.length; i++) {
        if (layoutParams[i].isHidden && !layoutParams[i].isHidden(val)) {
          layoutParams.splice(i--, 1)
        }
      }
      this.rowParams = layoutParams
    }
  },
  created() {}
}
</script>
<style scoped lang="scss">
.layout-wrap {
  .el-row {
    &:last-child {
      margin-bottom: -20px;
    }
    .el-col {
      margin-bottom: 20px;
    }
    .label-wrap {
      display: flex;
      align-items: center;
      min-width: 80%;
      label {
        font-size: 14px;
        font-weight: 400;
        color: #666666;
        line-height: 20px;
        text-align: right;
        min-width: 70px;
        display: inline-block;
      }
      span {
        font-size: 14px;
        font-weight: 400;
        color: #333333;
        line-height: 20px;
        text-align: left;
        // max-width: 228px;
        // white-space: nowrap;
        // overflow: hidden;
        // text-overflow: ellipsis;
        // display: inline-block;
      }
    }
  }
}
</style>