summaryrefslogtreecommitdiff
path: root/src/components/table/setting/ProfilesTable.vue
blob: 6ba31fcf365b95b86bbe5c38dc4ce21d2bcae2ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<template>
  <el-table
      id="userTable"
      ref="dataTable"
      :data="tableData"
      tooltip-effect="light"
      empty-text=" "
      @header-dragend="dragend"
      @sort-change="tableDataSort"
      @selection-change="selectionChange"
      :row-class-name="tableRowClassName"
  >
    <el-table-column
        :resizable="false"
        align="center"
        type="selection"
        :selectable="checkSelectable"
        width="55">
    </el-table-column>
    <el-table-column
        v-for="(item, index) in customTableTitles"
        :key="item.prop+index"
        :fixed="item.fixed"
        :label="item.label"
        :min-width="`${item.minWidth}`"
        :prop="item.prop"
        :resizable="true"
        :sort-orders="['ascending', 'descending']"
        :sortable="item.sortable"
        :width="`${item.width}`"
    >
      <template #header>
        <span class="data-column__span">{{ item.label }}</span>
        <div class="col-resize-area"></div>
      </template>
      <template #default="scope" :column="item">
        <template v-if="item.prop === 'ctime' || item.prop === 'utime'">
          <template v-if="scope.row[item.prop]">
            {{ dateFormatByAppearance(scope.row[item.prop]) || '-' }}
          </template>
          <template v-else><span>-</span></template>
        </template>
        <template v-if="item.prop === 'entitySource'">
          {{ scope.row[item.prop]?.name || '-' }}
        </template>
        <template v-if="item.prop === 'entities' || item.prop === 'relations'">
          {{ handleListTypes(scope.row[item.prop]) }}
        </template>
      </template>
    </el-table-column>
    <template v-slot:empty>
      <div class="table-no-data" v-if="isNoData">
        <div class="table-no-data__title">{{ $t('npm.noData') }}</div>
      </div>
    </template>
  </el-table>
</template>

<script>
import table from '@/mixins/table'
import { dateFormatByAppearance } from '@/utils/date-util'

export default {
  name: 'SourcesTable',
  props: {
    isNoData: {
      type: Boolean,
      default: false
    }
  },
  mixins: [table],
  data () {
    return {
      tableTitle: [ // 原始table列
        {
          label: 'ID',
          prop: 'id',
          show: true,
          minWidth: 50,
          sortable: 'custom'
        },
        {
          label: this.$t('setting.source'),
          prop: 'entitySource',
          show: true,
          sortable: 'custom',
          minWidth: 100
        },
        {
          label: this.$t('setting.entityTypes'),
          prop: 'entities',
          show: true,
          minWidth: 150
        },
        {
          label: this.$t('setting.relationTypes'),
          prop: 'relations',
          show: true,
          minWidth: 200
        },
        {
          label: this.$t('config.user.createTime'),
          prop: 'ctime',
          show: true,
          minWidth: 150
        },
        {
          label: this.$t('overall.updateTime'),
          prop: 'utime',
          show: true,
          minWidth: 150
        }
      ]
    }
  },
  methods: {
    dateFormatByAppearance,
    // 禁止勾选buildIn为1的项,即禁止修改、删除admin的账号
    checkSelectable (row) {
      return row.isBuiltIn !== 1
    },
    handleListTypes (data) {
      let str = ''
      if (data && typeof data === 'string') {
        data = JSON.parse(data)
        data.forEach(item => {
          if (!str) {
            str = item.type + ','
          } else if (str.indexOf(item.type) < 0) {
            str += item.type + ','
          }
        })
        str = str.slice(0, -1) || '-'
      } else {
        str = '-'
      }
      return str
    },
    tableRowClassName (row) {
      if (row.row.isBuiltIn === 1) {
        return 'table-disabled-row'
      }
    }
  }
}
</script>