spring
8 天以前 af7fa041da9f063ca49f1f1126ec01616f14cd85
src/components/PIMTable/PIMTable.vue
@@ -40,7 +40,7 @@
      :fixed="item.fixed"
      :label="item.label"
      :prop="item.prop"
      show-overflow-tooltip
      :show-overflow-tooltip="item.dataType !== 'multiTagLink'"
      :align="item.align"
      :sortable="!!item.sortable"
      :type="item.type"
@@ -80,43 +80,22 @@
            style="width: 40px; height: 40px; margin-top: 10px"
          />
        </div>
        <!-- tag -->
        <div v-else-if="item.dataType == 'tag'">
          <el-tag
            v-if="
              typeof dataTypeFn(scope.row[item.prop], item.formatData) ===
              'string'
            "
            :title="formatters(scope.row[item.prop], item.formatData)"
            :type="formatType(scope.row[item.prop], item.formatType)"
        <div v-else-if="item.dataType === 'multiTagLink'">
          <el-tooltip
              v-for="(file, index) in dataTypeFnArray(scope.row[item.prop], item.formatData)"
              :key="index"
              :content="file.name"
              effect="dark"
              placement="top"
          >
            {{ formatters(scope.row[item.prop], item.formatData) }}
          </el-tag>
          <el-tag
            v-for="(tag, index) in dataTypeFn(
              scope.row[item.prop],
              item.formatData
            )"
            v-else-if="
              typeof dataTypeFn(scope.row[item.prop], item.formatData) ===
              'object'
            "
            :key="index"
            :title="formatters(scope.row[item.prop], item.formatData)"
            :type="formatType(tag, item.formatType)"
          >
            {{ item.tagGroup ? tag[item.tagGroup.label] ?? tag : tag }}
          </el-tag>
          <el-tag
            v-else
            :title="formatters(scope.row[item.prop], item.formatData)"
            :type="formatType(scope.row[item.prop], item.formatType)"
          >
            {{ formatters(scope.row[item.prop], item.formatData) }}
          </el-tag>
            <el-tag
                type="info"
                style="margin-right: 4px;margin-top: 4px; cursor: pointer;"
                @click="downloadFile(file)"
            >
              {{ truncateName(file.name, 5) }}
            </el-tag>
          </el-tooltip>
        </div>
        <!-- 按钮 -->
@@ -351,6 +330,29 @@
    return format(val);
  } else return val;
};
const dataTypeFnArray = (val, format) => {
  if (!val) return [];
  if (typeof format === "function") {
    return format(val);
  }
  // 保证返回的是数组
  return Array.isArray(val) ? val : [];
};
const truncateName = (name, length = 5) => {
  if (!name) return '';
  return name.length > length ? name.slice(0, length) + '...' : name;
};
const downloadFile = (file) => {
  const link = document.createElement("a");
  link.href = file.url;
  // 设置下载文件名为 file.name
  link.download = file.name;
  link.click();
};
const formatType = (val, format) => {
  if (typeof format === "function") {