index.vue 5.54 KB
<template>
  <div style="display: flex">
    <n-grid :x-gap="12" :y-gap="12" :cols="4" layout-shift-disabled>
      <n-gi>
        <div :style="{ marginLeft: headLeftInfo.ml + 'px', marginTop: headLeftInfo.mt + 'px' }">
          <svg :width="headLeftInfo.w + 'px'" :height="headLeftInfo.h + 'px'">
            <polyline
              :stroke="colorLefts[0]"
              stroke-width="2"
              fill="transparent"
              :points="`${xLeftPos(0)}, 0 ${xLeftPos(30)}, ${headLeftInfo.h / 2}`"
            />
            <polyline
              :stroke="colorLefts[0]"
              stroke-width="2"
              fill="transparent"
              :points="`${xLeftPos(20)}, 0 ${xLeftPos(50)}, ${headLeftInfo.h / 2} ${xLeftPos(headLeftInfo.w)}, ${
                headLeftInfo.h / 2
              }`"
            />
            <polyline
              :stroke="colorLefts[1]"
              fill="transparent"
              stroke-width="3"
              :points="`${xLeftPos(0)}, ${headLeftInfo.h - 3}, ${xLeftPos(200)}, ${headLeftInfo.h - 3}`"
            />
          </svg>
        </div>
      </n-gi>
      <n-gi>
        <div :style="{ top: headCenterInfo.mt + 'px', left: headCenterInfo.ml + 'px' }" class="go-border-06">
          <svg xmlns="http://www.w3.org/2000/svg" :width="headCenterInfo.w" :height="headCenterInfo.h">
            <polygon class="stroke fill" :points="`15.5 6.5 20.5 0.5 50.5 0.5 55.5 6.5 15.5 6.5`" />
            <polygon
              class="stroke fill"
              :points="`15.5 ${headCenterInfo.h - 6.5} 20.5 ${headCenterInfo.h - 0.5} 50.5 ${
                headCenterInfo.h - 0.5
              } 55.5 ${headCenterInfo.h - 6.5} 15.5 ${headCenterInfo.h - 6.5}`"
            />
            <polygon
              class="stroke fill"
              :points="`${headCenterInfo.w - 15.5} 6.5 ${headCenterInfo.w - 20.5} 0.5 ${headCenterInfo.w - 50.5} 0.5 ${
                headCenterInfo.w - 55.5
              } 6.5 ${headCenterInfo.w - 15.5} 6.5`"
            />
            <polygon
              class="stroke fill"
              :points="`${headCenterInfo.w - 15.5} ${headCenterInfo.h - 6.5} ${headCenterInfo.w - 20.5} ${
                headCenterInfo.h - 0.5
              } ${headCenterInfo.w - 50.5} ${headCenterInfo.h - 0.5} ${headCenterInfo.w - 55.5} ${
                headCenterInfo.h - 6.5
              } ${headCenterInfo.w - 15.5} ${headCenterInfo.h - 6.5}`"
            />
            <polygon
              class="stroke fill"
              :points="`15.5 6.5 0.5 ${headCenterInfo.h / 2} 15.5 ${headCenterInfo.h - 6.5} ${
                headCenterInfo.w - 15.5
              } ${headCenterInfo.h - 6.5} ${headCenterInfo.w - 0.5} ${headCenterInfo.h / 2} ${
                headCenterInfo.w - 15.5
              } 6.5 15.5 6.5`"
            />
            <polyline
              class="stroke fill-none"
              :points="`20.5 14.5 8.5 ${headCenterInfo.h / 2} 20.5 ${headCenterInfo.h - 14.5}`"
            />
            <polyline
              class="stroke fill-none"
              :points="`${headCenterInfo.w - 20.5} 14.5 ${headCenterInfo.w - 8.5} ${headCenterInfo.h / 2} ${
                headCenterInfo.w - 20.5
              } ${headCenterInfo.h - 14.5}`"
            />
          </svg>
          <span class="text">{{ headCenterInfo.dataset }}</span>
        </div>
      </n-gi>
      <n-gi>
        <div :style="{ marginLeft: headRightInfo.ml + 'px', marginTop: headRightInfo.mt + 'px' }">
          <svg :width="headRightInfo.w" :height="headRightInfo.h">
            <polyline
              :stroke="colorRights[0]"
              stroke-width="2"
              fill="transparent"
              :points="`${xRightPos(0)}, 0 ${xRightPos(30)}, ${headRightInfo.h / 2}`"
            />
            <polyline
              :stroke="colorRights[0]"
              stroke-width="2"
              fill="transparent"
              :points="`${xRightPos(20)}, 0 ${xRightPos(50)}, ${headRightInfo.h / 2} ${xRightPos(headRightInfo.w)}, ${
                headRightInfo.h / 2
              }`"
            />
            <polyline
              :stroke="colorRights[1]"
              fill="transparent"
              stroke-width="3"
              :points="`${xRightPos(0)}, ${headRightInfo.h - 3}, ${xRightPos(200)}, ${headRightInfo.h - 3}`"
            />
          </svg>
        </div>
      </n-gi>
    </n-grid>
  </div>
</template>
<script setup lang="ts">
import { PropType, toRefs } from 'vue'
import { CreateComponentType } from '@/packages/index.d'

const props = defineProps({
  chartConfig: {
    type: Object as PropType<CreateComponentType>,
    required: true
  }
})

//默认设置宽高距离位置
props.chartConfig.attr.w = 1920
props.chartConfig.attr.h = 300
props.chartConfig.attr.x = 0
props.chartConfig.attr.y = 0

const { headLeftInfo, headCenterInfo, headRightInfo, colorLefts, colorRights, colorTexts } = toRefs(
  props.chartConfig.option
)

const xLeftPos = (pos: number) => {
  if (!headLeftInfo.value.headLeftReverse) return pos
  return headLeftInfo.value.w - pos
}

const xRightPos = (pos: number) => {
  if (!headRightInfo.value.headRightReverse) return pos
  return headRightInfo.value.w - pos
}
</script>

<style lang="scss" scoped>
@include go('border-06') {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;

  svg {
    position: absolute;
    z-index: -1;
  }

  .fill {
    fill: v-bind('colorTexts[0]');
  }
  .fill-none {
    fill: none;
  }
  .stroke {
    stroke: v-bind('colorTexts[1]');
  }

  .text {
    color: v-bind('headCenterInfo.textColor');
    font-size: v-bind('headCenterInfo.textSize+"px"');
  }
}
</style>