xiangpei
2025-04-18 23da057f35cea1ee061adc23ccb9b7511635133b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<template>
  <div>
    <el-table
        :data="tableData"
        :class="{tableTopLevel1: topLevel === 1, tableTopLevel2: topLevel === 2, tableTopLevel3: topLevel === 3, tableTopLevelDefault: topLevel === -1}"
        row-key="id"
        border
        @selection-change="handleSelectionChange">
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      #foreach($field in ${formInfo.fields})
      <el-table-column
          prop="$!{field.propertyName}"
          label="$!{field.comment}"
          >
      </el-table-column>
      #end
      <el-table-column
          label="操作">
        <template slot-scope="scope">
          <el-button v-if="editShow" type="primary" @click="edit$!{vueInfo.name}(scope.row.id)" size="mini">修改</el-button>
          <el-button v-if="delShow" type="primary" @click="delete$!{vueInfo.name}(scope.row.id)" size="mini">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <PageC
            :top-level="topLevel"
            :handleSizeChange="handleSizeChange"
            :handleCurrentChange="handleCurrentChange"
            :pageSize="pageSize"
            :total="total"
            :currentPage="currentPage"></PageC>
  </div>
</template>
 
<script>
  import PageC from "@/components/PageC";
  import {delete$!{vueInfo.name}ById, get$!{vueInfo.name}s} from "@/api/$!{vueInfo.lowerName}";
  import {Message} from "element-ui";
  export default {
    name: "$!{vueInfo.name}Table",
    components: {PageC},
    computed: {
      tableData: {
        get() {
          return this.#[[$store]]#.state.$!{vueInfo.lowerName}.tableData;
        },
        set(value) {
          this.#[[$store]]#.state.$!{vueInfo.lowerName}.tableData = value;
        }
      },
      // 选中行id
      multipleSelection: {
        get() {
          return this.#[[$store]]#.state.$!{vueInfo.lowerName}.multipleSelection;
        },
        set(value) {
          this.#[[$store]]#.state.$!{vueInfo.lowerName}.multipleSelection = value;
        }
      },
      total: {
        get() {
          return this.#[[$store]]#.state.$!{vueInfo.lowerName}.total;
        },
        set(value) {
          this.#[[$store]]#.state.$!{vueInfo.lowerName}.total = value;
        }
      },
      pageSize: {
        get() {
          return this.#[[$store]]#.state.$!{vueInfo.lowerName}.pageSize;
        },
        set(value) {
          this.#[[$store]]#.state.$!{vueInfo.lowerName}.pageSize = value;
        }
      },
      currentPage: {
        get() {
          return this.#[[$store]]#.state.$!{vueInfo.lowerName}.currentPage;
        },
        set(value) {
          this.#[[$store]]#.state.$!{vueInfo.lowerName}.currentPage = value;
        }
      }
    },
    props: {
      topLevel: {
        required: false,
        default: -1,
        type: Number
      },
      editShow: {
        required: true,
        default: false,
        type: Boolean
      },
      delShow: {
        required: true,
        default: false,
        type: Boolean
      },
    },
    methods: {
      handleSelectionChange(val) {
        this.multipleSelection = val.map((item) => {return item.id;})
      },
      get$!{vueInfo.name}s(params) {
        if (! params) {
          params = {
            currentPage: this.currentPage,
            pageSize: this.pageSize
          };
        } else {
          params.currentPage = this.currentPage;
          params.pageSize = this.pageSize;
        }
        // 刷新
        get$!{vueInfo.name}s(params).then((res) => {
          this.tableData = res.data.data;
          this.total = res.data.total;
        })
      },
      edit$!{vueInfo.name}(id) {
        this.#[[$store]]#.dispatch("$!{vueInfo.lowerName}/edit$!{vueInfo.name}", id);
      },
      delete$!{vueInfo.name}(id) {
        this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delete$!{vueInfo.name}ById(id).then((res) => {
            Message.success(res.data.msg);
            this.get$!{vueInfo.name}s();
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.get$!{vueInfo.name}s();
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.get$!{vueInfo.name}s();
      }
    },
    created() {
      this.get$!{vueInfo.name}s();
    }
  }
</script>
 
<style scoped>
 
</style>