Commit 20e34e35a3bdc48e6a4c58e3849aa729bd18efe5

Authored by YunaiV
1 parent cfcc2c67

v3.4.0 表格右侧工具栏组件支持显隐列

yudao-ui-admin/src/components/RightToolbar/index.vue
1   -<!-- @author Shiyn/ huangmx 20200807优化-->
2 1 <template>
3 2 <div class="top-right-btn">
4 3 <el-row>
... ... @@ -8,31 +7,74 @@
8 7 <el-tooltip class="item" effect="dark" content="刷新" placement="top">
9 8 <el-button size="mini" circle icon="el-icon-refresh" @click="refresh()" />
10 9 </el-tooltip>
  10 + <el-tooltip class="item" effect="dark" content="显隐列" placement="top" v-if="columns">
  11 + <el-button size="mini" circle icon="el-icon-menu" @click="showColumn()" />
  12 + </el-tooltip>
11 13 </el-row>
  14 + <el-dialog :title="title" :visible.sync="open" append-to-body>
  15 + <el-transfer
  16 + :titles="['显示', '隐藏']"
  17 + v-model="value"
  18 + :data="columns"
  19 + @change="dataChange"
  20 + ></el-transfer>
  21 + </el-dialog>
12 22 </div>
13 23 </template>
14 24 <script>
15 25 export default {
16 26 name: "RightToolbar",
17 27 data() {
18   - return {};
  28 + return {
  29 + // 显隐数据
  30 + value: [],
  31 + // 弹出层标题
  32 + title: "显示/隐藏",
  33 + // 是否显示弹出层
  34 + open: false,
  35 + };
19 36 },
20 37 props: {
21 38 showSearch: {
22 39 type: Boolean,
23 40 default: true,
24 41 },
  42 + columns: {
  43 + type: Array,
  44 + },
25 45 },
26 46  
27 47 methods: {
28   - //搜索
  48 + // 搜索
29 49 toggleSearch() {
30 50 this.$emit("update:showSearch", !this.showSearch);
31 51 },
32   - //刷新
  52 + // 刷新
33 53 refresh() {
34 54 this.$emit("queryTable");
35 55 },
  56 + // 右侧列表元素变化
  57 + dataChange(data) {
  58 + for (var item in this.columns) {
  59 + const key = this.columns[item].key;
  60 + this.columns[item].visible = !data.includes(key);
  61 + }
  62 + },
  63 + // 打开显隐列dialog
  64 + showColumn() {
  65 + this.open = true;
  66 + },
36 67 },
37 68 };
38 69 </script>
  70 +<style lang="scss" scoped>
  71 +::v-deep .el-transfer__button {
  72 + border-radius: 50%;
  73 + padding: 12px;
  74 + display: block;
  75 + margin-left: 0px;
  76 +}
  77 +::v-deep .el-transfer__button:first-child {
  78 + margin-bottom: 10px;
  79 +}
  80 +</style>
... ...
yudao-ui-admin/src/layout/components/global.js deleted
1   -import Vue from 'vue'
2   -const global = new Vue()
3   -export default global
yudao-ui-admin/src/views/system/user/index.vue
... ... @@ -50,21 +50,21 @@
50 50 <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
51 51 v-hasPermi="['system:user:export']">导出</el-button>
52 52 </el-col>
53   - <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  53 + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
54 54 </el-row>
55 55  
56 56 <el-table v-loading="loading" :data="userList">
57   - <el-table-column label="用户编号" align="center" prop="id" />
58   - <el-table-column label="用户名称" align="center" prop="username" :show-overflow-tooltip="true" />
59   - <el-table-column label="用户昵称" align="center" prop="nickname" :show-overflow-tooltip="true" />
60   - <el-table-column label="部门" align="center" prop="dept.name" :show-overflow-tooltip="true" />
61   - <el-table-column label="手机号码" align="center" prop="mobile" width="120" />
62   - <el-table-column label="状态" align="center">
  57 + <el-table-column label="用户编号" align="center" prop="id" v-if="columns[0].visible" />
  58 + <el-table-column label="用户名称" align="center" prop="username" v-if="columns[1].visible" :show-overflow-tooltip="true" />
  59 + <el-table-column label="用户昵称" align="center" prop="nickname" v-if="columns[2].visible" :show-overflow-tooltip="true" />
  60 + <el-table-column label="部门" align="center" prop="dept.name" v-if="columns[3].visible" :show-overflow-tooltip="true" />
  61 + <el-table-column label="手机号码" align="center" prop="mobile" v-if="columns[4].visible" width="120" />
  62 + <el-table-column label="状态" v-if="columns[5].visible" align="center">
63 63 <template slot-scope="scope">
64 64 <el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1" @change="handleStatusChange(scope.row)" />
65 65 </template>
66 66 </el-table-column>
67   - <el-table-column label="创建时间" align="center" prop="createTime" width="160">
  67 + <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[6].visible" width="160">
68 68 <template slot-scope="scope">
69 69 <span>{{ parseTime(scope.row.createTime) }}</span>
70 70 </template>
... ... @@ -317,6 +317,16 @@ export default {
317 317 status: undefined,
318 318 deptId: undefined
319 319 },
  320 + // 列信息
  321 + columns: [
  322 + { key: 0, label: `用户编号`, visible: true },
  323 + { key: 1, label: `用户名称`, visible: true },
  324 + { key: 2, label: `用户昵称`, visible: true },
  325 + { key: 3, label: `部门`, visible: true },
  326 + { key: 4, label: `手机号码`, visible: true },
  327 + { key: 5, label: `状态`, visible: true },
  328 + { key: 6, label: `创建时间`, visible: true }
  329 + ],
320 330 // 表单校验
321 331 rules: {
322 332 username: [
... ...