liweilong
2020-12-25 faeb372259f5d47cd3ba304bf383361d18da2714
提交 | 用户 | age
2a61f6 1 <template>
L 2   <div class="app-container">
3     <!-- 搜索区 ↓↓↓↓↓↓↓↓↓↓ -->
4     <el-form v-show="showSearch" ref="searchForm" :inline="true">
5       <el-form-item label="角色名称">
6         <el-input
7           v-model="keyWord"
8           placeholder="请输入角色名称"
9           clearable
10           size="small"
11           style="width: 240px"
12           @keyup.enter.native="reGetList"
13         />
14       </el-form-item>
15       <el-form-item>
16         <el-button type="cyan" icon="el-icon-search" size="mini" @click="reGetList">搜索</el-button>
17         <el-button icon="el-icon-refresh" size="mini" @click="resetHandle">重置</el-button>
18       </el-form-item>
19     </el-form>
20     <!-- 搜索区 ↑↑↑↑↑↑↑↑↑↑ -->
21
22     <!-- 操作区 ↓↓↓↓↓↓↓↓↓↓ -->
23     <el-row :gutter="10" class="mb8">
24       <el-col :span="1.5">
25         <el-button
26           type="primary"
27           icon="el-icon-plus"
28           size="mini"
29         >新增</el-button>
30       </el-col>
31       <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
32     </el-row>
33     <!-- 操作区 ↑↑↑↑↑↑↑↑↑↑ -->
34
35     <el-table :data="list">
36       <el-table-column type="index" label="序号" align="center" width="60" />
37       <el-table-column label="角色名称" prop="name" align="center" min-width="120" />
38       <el-table-column label="创建时间" prop="createTime" align="center" min-width="180" />
39       <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="100">
40         <template slot-scope="scope">
41           <el-button
42             size="mini"
43             type="text"
44             icon="el-icon-edit"
45           >编辑</el-button>
46           <el-button
47             size="mini"
48             type="text warn"
49             icon="el-icon-delete"
50             @click="handleDelete(scope.row)"
51           >删除</el-button>
52         </template>
53       </el-table-column>
54     </el-table>
55
56     <pagination
57       v-show="total>0"
58       :total="total"
59       :page.sync="pageNum"
60       :limit.sync="pageSize"
61       @pagination="getList"
62     />
63   </div>
64 </template>
65
66 <script>
67
68 export default {
69   name: 'Role',
70   data() {
71     return {
72       showSearch: true, // 是否显示搜索区
73       keyWord: '',
74
75       list: [],
76
77       // 分页 ↓↓↓↓↓↓↓↓↓↓
78       total: 0,
79       pageNum: 1,
80       pageSize: 20
81       // 分页 ↑↑↑↑↑↑↑↑↑↑
82     }
83   },
84   mounted() {
85     this.init()
86   },
87   methods: {
88     // 初始化
89     init() {
90       this.getList()
91     },
92
93     // 获取列表
94     getList() {
95       var { pageNum, pageSize, keyWord } = this
96       this.postFN({
97         url: 'xxx',
98         params: {
99           pageNum: pageNum,
efd7c8 100           pageSize: pageSize,
2a61f6 101           keyWord: keyWord
L 102         },
103         mockData: {
104           code: 100,
105           msg: '',
106           data: {
107             list: [{
108               id: 'xxx',
109               index: 1,
110               name: '超级管理员',
111               createTime: '2020-08-09 10:10:10'
112             }],
113             total: 100
114           }
115         }
116       }, (inf) => {
117         this.list = inf.list || []
118         this.total = inf.total
119       })
120     },
121     // 重新获取列表
122     reGetList() {
123       this.pageNum = 1
124       this.getList()
125     },
126     // 重置
127     resetHandle() {
128       this.keyWord = ''
129       this.reGetList()
130     },
131     // 删除
132     handleDelete(item) {
133       // 打开二次确认弹窗
134       this.$confirm('是否确认删除该角色?', '提示', {
135         confirmButtonText: '确定',
136         cancelButtonText: '取消',
137         type: 'warning'
138       }).then(() => {
139         // 确定回调
140         this.postFN({
141           url: 'xxx',
142           params: {
143             id: item.id
144           },
145           mockData: {
146             code: 100,
147             msg: '',
148             data: {}
149           }
150         }, () => {
151           this.getList()
152           this.$messageSuc('删除成功')
153         })
154       }).catch(() => {})
155     }
156   }
157 }
158 </script>
159
160 <style lang="scss" scoped>
161
162 </style>