DictList.vue 5.58 KB
<template>
  <el-container>
    <el-header style="height: 30px">
      <div class="search-container">
        <div class="search-item">
          <span class="search-label">字典编码</span>
          <el-input
            placeholder="请输入内容"
            v-model="inputCode"
            style="width: 200px; margin-right: 20px"
          >
          </el-input>
        </div>
        <div class="search-item">
          <span class="search-label">字典名称</span>
          <el-input
            size="medium"
            placeholder="请输入内容"
            v-model="inputName"
            style="width: 200px"
          >
          </el-input>
        </div>
      </div>
    </el-header>

    <el-main>
      <div>
        <el-card shadow="always">
          <div style="text-align: right">
            <el-button
              type="primary"
              size="small"
              icon="el-icon-search"
              @click="handleSearch"
            >
              查询
            </el-button>
            <el-button
              type="success"
              size="small"
              icon="el-icon-plus"
              @click="handleAdd"
            >
              新增
            </el-button>
            <el-button
              type="danger"
              size="small"
              icon="el-icon-delete"
              @click="handleBatchDelete"
            >
              删除
            </el-button>
          </div>
        </el-card>
      </div>
      <el-table
        :data="dictList"
        max-height="540"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="id" label="ID" width="80"></el-table-column>
        <el-table-column
          prop="code"
          label="字典编码"
          width="150"
        ></el-table-column>
        <el-table-column
          prop="name"
          label="字典名称"
          width="150"
        ></el-table-column>
        <el-table-column prop="remark" label="备注"></el-table-column>
        <el-table-column
          prop="created"
          label="创建时间"
          width="160"
        ></el-table-column>
        <el-table-column
          prop="updatedBy"
          label="创建人"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="updateTime"
          label="更新时间"
          width="160"
        ></el-table-column>
        <el-table-column
          prop="updater"
          label="更新人"
          width="120"
        ></el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.id"
              type="text"
              @click="handleEdit(scope.row)"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        style="margin-top: 15px"
        align="center"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      />
    </el-main>
  </el-container>
</template>

<script>
import {
  GetDictsByPage,
  AddDict,
  EditDict,
  DeleteDicts,
} from "@/api/systemManage/dict";
export default {
  name: "DictList",
  data() {
    return {
      currentPage: 1,
      total: 0,
      pageSize: 10,
      dictList: [
        {
          id: "",
          code: "",
          name: "",
          remark: "",
          createTime: "",
          creator: "",
          updateTime: "",
          updater: "",
        },
      ], // 字典列表数据
      inputCode: "",
      inputName: "",
      selectedItems: [],
    };
  },
  methods: {
    handleSelectionChange(val) {
      this.selectedItems = val;
      console.log("选中的行数据:", this.selectedItems);
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.handleSearch();
    },

    handleCurrentChange(val) {
      this.currentPage = val;
      this.handleSearch();
    },
    handleEdit(row) {
      // 编辑字典
    },

    handleSearch() {
      const requestData = {
        pageNumber: this.currentPage,
        perPageCount: this.pageSize,
        queryConfig: {
          dictId: 0,
          code: this.inputCode,
          name: this.inputName,
        },
      };
      GetDictsByPage(requestData).then((res) => {
        console.log("查询字典", res.data.data);
        if (res.code == "Success" && res.data) {
          this.dictList = res.data.data || res.data;
          this.total = res.data.totalCount || res.data.data.length;
        }
      });
    },
    handleAdd() {
      // 新增逻辑
    },
    handleBatchDelete() {
      if (this.selectedItems.length === 0) {
        this.$message.warning("请至少选择一条数据");
        return;
      }

      const ids = this.selectedItems.map((item) => item.id);
      DeleteDicts({ ids }).then((res) => {
        if (res.code === "Success") {
          this.$message.success("删除成功");
          this.handleSearch();
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep.el-table thead {
  color: #101010;
  font-weight: 600;
}
.app-container {
  padding: 16px;
}
.search-container {
  display: flex;
  align-items: center;
  .search-item {
    display: flex;
    align-items: center;
    margin-right: 20px;
    .search-label {
      margin-right: 10px;
      white-space: nowrap;
    }
  }
}
</style>