MappingNodeItem.vue 3.01 KB
<template>
  <div class="nodeItem" :style="nodeCoordinate">
    <div class="nodeHeader" :style="setHeaderColor(node.type)">
      <ht-icon
        name="component"
        v-if="node.flowType == 'main'"
        title="主流程业务对象"
      />
      <ht-icon name="block" v-else title="子流程业务对象" />
      {{ node.comment }}({{ node.name }})
    </div>
    <ul :id="`${node.id}${minus}cols`" class="cols">
      <li
        v-for="col in node.columns"
        :key="`${node.type}${minus}${node.name}${minus}${col.name}`"
        :id="`${node.type}${minus}${node.name}${minus}${col.name}`"
        @click="handleColumnClick(col)"
        :class="['col', {current: isCurrentNode && col == currentColumn}]"
      >
        <p :title="col.comment">
          {{ col.comment }}
        </p>
        <span :title="col.name">({{ col.name }})</span>
        <ht-icon
          v-if="col == creatorFollowColumn"
          title="发起人账号字段"
          class="col-user-icon"
          name="user"
        />
      </li>
    </ul>
  </div>
</template>

<script>
import {tbType} from './tbType.js'

export default {
  name: 'MappingNodeItem',
  props: {
    node: Object,
    creatorFollowColumn: Object,
    currentNode: Object,
    currentColumn: Object
  },
  data() {
    return {
      tbType: tbType,
      minus: '-' //表名和列名的分割符号
    }
  },
  methods: {
    setHeaderColor(type) {
      for (let key in tbType) {
        if (type === key) {
          return {
            backgroundColor: tbType[key].color
          }
        }
      }
    },
    handleColumnClick(column) {
      if (this.node && this.node.type != 'RS') {
        return
      }
      this.$emit('column-click', this.node, column)
    }
  },
  computed: {
    nodeCoordinate: {
      get() {
        return {
          top: this.node.top + 'px',
          left: this.node.left + 'px'
        }
      }
    },
    isCurrentNode() {
      return this.node == this.currentNode
    }
  }
}
</script>

<style lang="scss" scoped>
.nodeItem {
  position: absolute;
  display: felx;
  border: 1px solid #b7b6b6;
  border-top-left-radius: 3px;
  border-top-right-radius: 3px;
  justify-items: center;
  align-items: center;
  z-index: 9995;
  .nodeHeader {
    cursor: move;
    border-top-left-radius: 3px;
    border-top-right-radius: 3px;
    padding: 12px;
    background-color: #91c051;
    color: white;
    font-size: 12px;
  }
  .col {
    display: flex;
    align-items: center;
    list-style: none;
    background-color: #fff;
    padding: 5px 10px;
    font-size: smaller;
    cursor: default;
    &:hover,
    &.current {
      background-color: #f8f8f8;
      outline: 1px solid #ccc;
    }
    p {
      max-width: 100px;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    span {
      max-width: 80px;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      margin-right: 25px;
    }
    svg.col-user-icon {
      position: absolute;
      right: 10px;
      color: #999;
    }
  }
}
</style>