gridItem.vue 3.18 KB
<template>
  <div class="row-wrapper">
    <div v-for="item in schema"
         :key="item.name"
         class="col-wrapper van-col-wrapper"
         :style="item.colStyle">
      <Tooltip v-if="item.tips"
               :content="item.tips"
               :hide-after="1500"
               :options="{
                 triggers: ['click'],
                 placement: 'top',
                 autoHide: true,
                 disabled: !item.tips,
               }">
        <div class="item-wrapper"
             :class="{ special: item.special }"
             :style="item.style">
          <div class="label">
            <div class="text-hide" style="margin-right:2px">
              {{ item.label }}
            </div>
            <SvgIcon v-if="item.tips"
                     class="icon"
                     color="#DCDDE1"
                     name="form-tips"
                     size="16px" />
          </div>
          <div class="value text-hide ">
            {{ getValue(item.name, item) }}
          </div>
        </div>
      </Tooltip>

      <div v-else
           class="item-wrapper"
           :class="{ special: item.special }"
           :style="item.style">
        <div class="label">
          <div class="text-hide" style="margin-right:2px">
            {{ item.label }}
          </div>
          <SvgIcon v-if="item.tips"
                   class="icon"
                   color="#DCDDE1"
                   name="form-tips"
                   size="16px" />
        </div>
        <div class="value text-hide ">
          {{ getValue(item.name, item) }}
        </div>
      </div>
    </div>

  </div>
  <!-- <van-row gutter="4">
    <van-col v-for="item in schema"
             :key="item.name"
             class="van-col-wrapper"
             :span="item.col">

    </van-col>
  </van-row> -->
</template>

<script>
import { get } from "lodash-es";
import { Col, Divider, Icon, Row } from "vant";
import SvgIcon from "@/components/svgIcon/index.vue";
import Tooltip from "@/components/tooltip/index.vue";

export default {
	name: "",
	components: {
		[Col.name]: Col,
		[Row.name]: Row,
		[Divider.name]: Divider,
		[Icon.name]: Icon,
		SvgIcon,
		Tooltip,
	},
	props: {
		schema: {
			type: Array,
			default: () => ([]),
		},
		data: {
			type: Object,
			default: () => ({}),
		},
	},
	data() {
		return {

		};
	},
	computed: {

	},
	mounted() {

	},
	methods: {
		getValue(path, schema) {
			return get(this.data, path) || schema.emptyValue || "-";
		},
	},
};
</script>

<style scoped lang="scss">
.row-wrapper {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
}
.van-col-wrapper {
	overflow: hidden;
	flex-shrink: 0;
	margin-right: 4px;
	&:last-child {
		margin-right: 0;
	}
	.item-wrapper {
		background: #f8f8f8;
		padding: 8px 12px;
		overflow: hidden;
		box-sizing: border-box;
		.label {
			font-weight: 400;
			font-size: 12px;
			line-height: 20px;
			color: rgba(0, 0, 0, 0.26);
			display: flex;
			align-items: center;
			flex-wrap: nowrap;
			flex-shrink: 0;
			.icon {
				flex-shrink: 0;
			}
		}
		.value {
			margin-top: 4px;
			font-family: numberNor;
			font-weight: 500;
			font-size: 16px;
			line-height: 20px;
			color: var(--themeColor);
			flex-shrink: 0;
		}
	}
}
</style>