zhangwencui
5 天以前 9625881d9c655bc22b22fd4410e07526b5a81f6c
src/components/PIMTable/PIMTable.vue
@@ -1,6 +1,5 @@
<template>
  <el-table
    ref="multipleTable"
  <el-table ref="multipleTable"
    v-loading="tableLoading"
    :border="border"
    :data="tableData"
@@ -19,18 +18,16 @@
    @current-change="currentChange"
    @selection-change="handleSelectionChange"
    @expand-change="expandChange"
    class="lims-table"
  >
    <el-table-column
      align="center"
            class="lims-table">
    <el-table-column align="center"
      type="selection"
      width="55"
      v-if="isSelection"
    />
    <el-table-column align="center" label="序号" type="index" width="60" />
    <el-table-column
      v-for="(item, index) in column"
                     v-if="isSelection" />
    <el-table-column align="center"
                     label="序号"
                     type="index"
                     width="60" />
    <el-table-column v-for="(item, index) in column"
      :key="index"
      :column-key="item.columnKey"
      :filter-method="item.filterHandler"
@@ -44,39 +41,33 @@
      :align="item.align"
      :sortable="!!item.sortable"
      :type="item.type"
      :width="item.width"
    >
                     :width="item.width">
      <template #header="scope">
        <div class="pim-table-header-cell">
          <div class="pim-table-header-title">
            {{ item.label }}
          </div>
          <div v-if="item.headerSlot" class="pim-table-header-extra">
            <slot :name="item.headerSlot" :column="scope.column" />
          <div v-if="item.headerSlot"
               class="pim-table-header-extra">
            <slot :name="item.headerSlot"
                  :column="scope.column" />
          </div>
        </div>
      </template>
      <template
        v-if="item.hasOwnProperty('colunmTemplate')"
        #[item.colunmTemplate]="scope"
      >
        <slot
          v-if="item.theadSlot"
      <template v-if="item.hasOwnProperty('colunmTemplate')"
                #[item.colunmTemplate]="scope">
        <slot v-if="item.theadSlot"
          :name="item.theadSlot"
          :index="scope.$index"
          :row="scope.row"
        />
              :row="scope.row" />
      </template>
      <template #default="scope">
        <!-- 插槽 -->
        <div v-if="item.dataType == 'slot'">
          <slot
            v-if="item.slot"
          <slot v-if="item.slot"
            :index="scope.$index"
            :name="item.slot"
            :row="scope.row"
          />
                :row="scope.row" />
        </div>
        <!-- 进度条 -->
        <div v-else-if="item.dataType == 'progress'">
@@ -84,28 +75,21 @@
        </div>
        <!-- 图片 -->
        <div v-else-if="item.dataType == 'image'">
          <img
            :src="javaApi + '/img/' + scope.row[item.prop]"
          <img :src="javaApi + '/img/' + scope.row[item.prop]"
            alt=""
            style="width: 40px; height: 40px; margin-top: 10px"
          />
               style="width: 40px; height: 40px; margin-top: 10px" />
        </div>
        <!-- tag -->
        <div v-else-if="item.dataType == 'tag'">
          <el-tag
            v-if="
          <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)"
          >
                  :type="formatType(scope.row[item.prop], item.formatType)">
            {{ formatters(scope.row[item.prop], item.formatData) }}
          </el-tag>
          <el-tag
            v-for="(tag, index) in dataTypeFn(
          <el-tag v-for="(tag, index) in dataTypeFn(
              scope.row[item.prop],
              item.formatData
            )"
@@ -115,25 +99,21 @@
            "
            :key="index"
            :title="formatters(scope.row[item.prop], item.formatData)"
            :type="formatType(tag, item.formatType)"
          >
                  :type="formatType(tag, item.formatType)">
            {{ item.tagGroup ? tag[item.tagGroup.label] ?? tag : tag }}
          </el-tag>
          <el-tag
            v-else
          <el-tag v-else
            :title="formatters(scope.row[item.prop], item.formatData)"
            :type="formatType(scope.row[item.prop], item.formatType)"
          >
                  :type="formatType(scope.row[item.prop], item.formatType)">
            {{ formatters(scope.row[item.prop], item.formatData) }}
          </el-tag>
        </div>
        <!-- 按钮 -->
        <div v-else-if="item.dataType == 'action'" @click.stop>
          <template v-for="(o, key) in item.operation" :key="key">
            <el-button
              v-show="o.type != 'upload'"
        <div v-else-if="item.dataType == 'action'"
             @click.stop>
          <template v-for="(o, key) in item.operation"
                    :key="key">
            <el-button v-show="o.type != 'upload'"
              v-if="o.showHide ? o.showHide(scope.row) : true"
              :disabled="o.disabled ? o.disabled(scope.row) : false"
              :plain="o.plain"
@@ -146,12 +126,10 @@
              }"
              link
              @click.stop="o.clickFun(scope.row)"
              :key="key"
            >
                       :key="key">
              {{ o.name }}
            </el-button>
            <el-upload
              :action="
            <el-upload :action="
                javaApi +
                o.url +
                '?id=' +
@@ -183,28 +161,24 @@
                  handleSuccessUp(response, file, fileList, scope.$index)
              "
              :on-exceed="onExceed"
              :show-file-list="false"
            >
              <el-button
                link
                       :show-file-list="false">
              <el-button link
                type="primary"
                :disabled="o.disabled ? o.disabled(scope.row) : false"
                >{{ o.name }}</el-button
              >
                         :disabled="o.disabled ? o.disabled(scope.row) : false">{{ o.name }}</el-button>
            </el-upload>
          </template>
        </div>
        <!-- 可点击的文字 -->
        <div
          v-else-if="item.dataType == 'link'"
        <div v-else-if="item.dataType == 'link'"
          class="cell link"
          style="width: 100%"
          @click="goLink(scope.row, item.linkMethod)"
        >
             @click="goLink(scope.row, item.linkMethod)">
          <span v-if="!item.formatData">{{ scope.row[item.prop] }}</span>
        </div>
        <!-- 默认纯展示数据 -->
        <div v-else class="cell" style="width: 100%">
        <div v-else
             class="cell"
             style="width: 100%">
          <span v-if="!item.formatData">{{ scope.row[item.prop] }}</span>
          <span v-else>{{
            formatters(scope.row[item.prop], item.formatData)
@@ -213,14 +187,12 @@
      </template>
    </el-table-column>
  </el-table>
  <pagination
      v-if="isShowPagination"
  <pagination v-if="isShowPagination"
    :total="page.total"
    :layout="page.layout"
    :page="page.current"
    :limit="page.size"
    @pagination="paginationSearch"
  />
              @pagination="paginationSearch" />
</template>
<script setup>
@@ -233,7 +205,12 @@
const uploadHeader = proxy.uploadHeader;
const javaApi = proxy.javaApi;
const emit = defineEmits(["pagination", "expand-change", "selection-change", "row-click"]);
  const emit = defineEmits([
    "pagination",
    "expand-change",
    "selection-change",
    "row-click",
  ]);
// Filters
const typeFn = (val, row) => {
@@ -312,7 +289,7 @@
  },
  rowKey: {
    type: String,
    default: 'id',
      default: "id",
  },
  page: {
    type: Object,
@@ -338,7 +315,7 @@
const currentFiles = ref({});
const uploadKeys = ref({});
const indexMethod = (index) => {
  const indexMethod = index => {
  return (props.page.current - 1) * props.page.size + index + 1;
};
@@ -356,7 +333,7 @@
};
// 获取父组件方法(示例实现)
const getParentMethod = (methodName) => {
  const getParentMethod = methodName => {
  const parentMethods = inject("parentMethods", {});
  return parentMethods[methodName];
};
@@ -406,7 +383,7 @@
  }
};
const resetUploadComponent = (index) => {
  const resetUploadComponent = index => {
  uploadKeys[index] = Date.now();
};
@@ -427,7 +404,7 @@
  emit("pagination", { page: page, limit: limit });
};
const rowClick = (row) => {
  const rowClick = row => {
  emit("row-click", row);
};
@@ -435,7 +412,7 @@
  emit("expand-change", row, expandedRows);
};
const handleSelectionChange = (newSelection) => {
  const handleSelectionChange = newSelection => {
  emit("selection-change", newSelection);
};
</script>