spring
2025-02-17 ab87052f4a82332b9b4a471941a7bf48994b4390
src/components/Table/lims-table.vue
@@ -13,7 +13,7 @@
          :row-style="rowStyle"
          :row-key="rowKey"
          stripe
          style="width: 100%; "
      style="width: 100%"
          tooltip-effect="dark"
          @row-click="rowClick"
          @current-change="currentChange"
@@ -23,27 +23,55 @@
          <el-table-column type="selection" width="55" />
        </template>
        <template>
          <el-table-column align="center" label="序号" type="index" width="60" />
        <el-table-column
          align="center"
          label="序号"
          type="index"
          width="60"
          :index="indexMethod"
        />
        </template>
        <template v-for="(item, index) in column">
          <el-table-column :column-key="item.columnKey" :filter-method="item.filterHandler"
            :filter-multiple="item.filterMultiple" :filtered-value="item.filteredValue"
            :filters="item.filters" :fixed="item.fixed" :label="item.label"
            :min-width="item.minWidth" :prop="item.prop"
        <el-table-column
          :column-key="item.columnKey"
          :filter-method="item.filterHandler"
          :filter-multiple="item.filterMultiple"
          :filtered-value="item.filteredValue"
          :filters="item.filters"
          :fixed="item.fixed"
          :label="item.label"
          :min-width="item.minWidth"
          :prop="item.prop"
            show-overflow-tooltip
            :sortable="item.sortable ? true : false" :type="item.type" :width="item.width"
            align="center">
          :sortable="item.sortable ? true : false"
          :type="item.type"
          :width="item.width"
          align="center"
        >
            <!-- <div class="123" v-if="item.type == ''"> -->
            <template v-if="item.hasOwnProperty('colunmTemplate')" :slot="item.colunmTemplate"
                      slot-scope="scope">
              <slot v-if="item.theadSlot" :index="index" :name="item.theadSlot" :row="scope.row" />
          <template
            v-if="item.hasOwnProperty('colunmTemplate')"
            :slot="item.colunmTemplate"
            slot-scope="scope"
          >
            <slot
              v-if="item.theadSlot"
              :index="index"
              :name="item.theadSlot"
              :row="scope.row"
            />
            </template>
            <template slot-scope="scope">
              <!-- 插槽 -->
              <div v-if="item.dataType == 'slot'">
                <slot v-if="item.slot" :index="scope.$index" :name="item.slot" :row="scope.row" />
              <slot
                v-if="item.slot"
                :index="scope.$index"
                :name="item.slot"
                :row="scope.row"
              />
              </div>
              <!-- 进度条 -->
              <div v-else-if="item.dataType == 'progress'">
@@ -52,15 +80,45 @@
              <!-- tag -->
              <div v-else-if="item.dataType == 'tag'">
                <el-tag v-if="typeof dataTypeFn(scope.row[item.prop], item.formatData) == 'string'"
              <el-tag
                v-if="
                  typeof dataTypeFn(scope.row[item.prop], item.formatData) ==
                  'string'
                "
                        :title="scope.row[item.prop] | formatters(item.formatData)"
                        :type="formatType(scope.row[item.prop], item.formatType)">{{ scope.row[item.prop] | formatters(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="scope.row[item.prop] | formatters(item.formatData)"
                        :type="formatType(tag, item.formatType)">{{ item.tagGroup ? tag[item.tagGroup.label] ? tag[item.tagGroup.label] : tag : tag }}</el-tag>
                <el-tag v-else :title="scope.row[item.prop] | formatters(item.formatData)"
                        :type="formatType(scope.row[item.prop], item.formatType)">{{ scope.row[item.prop] | formatters(item.formatData) }}</el-tag>
                :type="formatType(scope.row[item.prop], item.formatType)"
                >{{
                  scope.row[item.prop] | formatters(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="scope.row[item.prop] | formatters(item.formatData)"
                :type="formatType(tag, item.formatType)"
                >{{
                  item.tagGroup
                    ? tag[item.tagGroup.label]
                      ? tag[item.tagGroup.label]
                      : tag
                    : tag
                }}</el-tag
              >
              <el-tag
                v-else
                :title="scope.row[item.prop] | formatters(item.formatData)"
                :type="formatType(scope.row[item.prop], item.formatType)"
                >{{
                  scope.row[item.prop] | formatters(item.formatData)
                }}</el-tag
              >
              </div>
              <!-- 按钮 -->
@@ -73,32 +131,48 @@
                      :disabled="o.disabled ? o.disabled(scope.row) : false"
                      :icon="iconFn(o)"
                      :plain="o.plain"
                      :style="{ 'color': o.name === '删除' ? '#f56c6c' : o.color }"
                  :style="{ color: o.name === '删除' ? '#f56c6c' : o.color }"
                      :type="o.type | typeFn(scope.row)"
                      @click="o.clickFun(scope.row)">
                  @click="o.clickFun(scope.row)"
                >
                    {{ o.name }}
                  </el-button>
                  <el-upload
                    action="#"
                    size="mini"
                    :on-change="(file, fileList)=>o.clickFun(scope.row,file, fileList)"
                  :on-change="
                    (file, fileList) => o.clickFun(scope.row, file, fileList)
                  "
                    :multiple="o.multiple?o.multiple:false"
                    :limit="o.limit?o.limit:1"
                    :disabled="o.disabled ? o.disabled(scope.row) : false"
                    :accept="o.accept?o.accept:'.jpg,.jpeg,.png,.gif,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.zip,.rar'"
                    v-if="o.type=='upload'" style="display: inline-block;width: 50px;"
                  :accept="
                    o.accept
                      ? o.accept
                      : '.jpg,.jpeg,.png,.gif,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.zip,.rar'
                  "
                  v-if="o.type == 'upload'"
                  style="display: inline-block; width: 50px"
                    v-show="o.showHide ? o.showHide(scope.row) : true"
                    :auto-upload="false"
                    :on-exceed="onExceed"
                    :show-file-list="false">
                    <el-button :size="o.size?o.size:'small'" type="text" :disabled="o.disabled ? o.disabled(scope.row) : false">{{o.name}}</el-button>
                  :show-file-list="false"
                >
                  <el-button
                    :size="o.size ? o.size : 'small'"
                    type="text"
                    :disabled="o.disabled ? o.disabled(scope.row) : false"
                    >{{ o.name }}</el-button
                  >
                  </el-upload>
                </template>
              </div>
              <!-- 默认纯展示数据 -->
              <div v-else>
                <span v-if="!item.formatData">{{ scope.row[item.prop] }}</span>
                <span v-else>{{ scope.row[item.prop] | formatters(item.formatData) }}</span>
              <span v-else>{{
                scope.row[item.prop] | formatters(item.formatData)
              }}</span>
              </div>
            </template>
          </el-table-column>
@@ -166,95 +240,88 @@
  // plain:按elementUi 文档为准
  // clickFun:按钮的回调函数
  export default {
    name: 'ZTTable',
  name: "ZTTable",
    filters: {
      typeFn(val, row) {
        // console.log(val, row, '11111111');
        if (typeof (val) === 'function') {
      if (typeof val === "function") {
          return val(row);
        } else return val;
      },
      describeConts(val, describeCont) {
        if (typeof (describeCont) === 'function') {
      if (typeof describeCont === "function") {
          return describeCont(val);
        } else return val;
      },
      formatters(val, format) {
        if (typeof (format) === 'function') {
      if (typeof format === "function") {
          return format(val);
        } else return val;
      }
    },
    },
    props: {
      isSelection: {
        type: Boolean,
        default: false
      default: false,
      },
      height: {
        type: String,
        default: null
      default: null,
      },
      tableLoading: {
        type: Boolean,
        default: false
      default: false,
      },
      handleSelectionChange: {
        type: Function,
        default: () => {
          return () => {
          };
        }
        return () => {};
      },
      },
      rowClick: {
        type: Function,
        default: () => {
          return () => {
          };
        }
        return () => {};
      },
      },
      currentChange: {
        type: Function,
        default: () => {
          return () => {
          };
        }
        return () => {};
      },
      },
      border: {
        type: Boolean,
        default: false
      default: false,
      },
      highlightCurrentRow: {
        type: Boolean,
        default: false
      default: false,
      },
      headerCellStyle: {
        type: Object,
        default: () => {
          return {};
        }
      },
      },
      column: {
        type: Array,
        default() {
          return [];
        }
      },
      },
      rowClassName: {
        type: Function,
        default: () => {
        }
      default: () => {},
      },
      rowStyle: {
        type: Object || Function,
        default: () => {
        }
      default: () => {},
      },
      tableData: {
        type: Array,
        default() {
          return [];
        }
      },
      rowKey: {
        type: String,
@@ -272,29 +339,30 @@
        }
      }
    },
  },
    methods: {
      iconFn(row) {
        if (row.name === '编辑') {
          return 'el-icon-edit'
        } else if (row.name === '删除') {
          return 'el-icon-delete'
        } else if (row.name === '查看') {
          return 'el-icon-view'
      if (row.name === "编辑" || row.name === "修改") {
        return "el-icon-edit";
      } else if (row.name === "删除") {
        return "el-icon-delete";
      } else if (row.name === "查看") {
        return "el-icon-view";
        } else {
          return row.icon
        return row.icon;
        }
        // if (typeof (val) === 'function') {
        //   return val(row);
        // } else return val;
      },
      formatType(val, format) {
        if (typeof (format) === 'function') {
      if (typeof format === "function") {
          return format(val);
        } else return '';
      } else return "";
      },
      dataTypeFn(val, format) {
        if (typeof (format) === 'function') {
      if (typeof format === "function") {
          return format(val);
        } else return val;
      },
@@ -302,17 +370,21 @@
        this.$refs.multipleTable.setCurrentRow();
      },
      onExceed(){
        this.$message.warning('超出文件个数');
      this.$message.warning("超出文件个数");
      },
      pagination(page,limit){
        this.$emit('pagination',{pageNum: page, pageSize: limit});
      }
    }
    pagination({ page, limit }) {
      this.$emit("pagination", { page: page, limit: limit });
    },
    indexMethod(index) {
      // return index * 2;
      return (this.page.current - 1) * this.page.size + index + 1;
    },
  },
  };
  </script>
  <style scoped>
  .el-table >>> .el-table__empty-text {
    text-align: center
  text-align: center;
  }
  </style>