permission-list.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <div>
  3. <el-breadcrumb separator=">">
  4. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  5. <el-breadcrumb-item>
  6. <a href="#">系统管理</a>
  7. </el-breadcrumb-item>
  8. <el-breadcrumb-item>
  9. <a href="/sys/permission">接口权限管理</a>
  10. </el-breadcrumb-item>
  11. </el-breadcrumb>
  12. <el-divider></el-divider>
  13. <!--
  14. 要resetFields起作用,必须配置:model和prop
  15. -->
  16. <el-form ref="queryForm" :model="queryModel" inline class="demo-form-inline">
  17. <el-form-item label="访问路径" prop="path">
  18. <el-input type="text" size="mini" v-model="queryModel.path"></el-input>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button
  22. type="primary"
  23. size="mini"
  24. icon="ios-search"
  25. @click="changePage(1)"
  26. :loading="loading"
  27. >查询</el-button>&nbsp;
  28. <el-button
  29. type="info"
  30. size="mini"
  31. style="margin-left: 8px"
  32. @click="handleReset('queryForm')"
  33. >重置</el-button>&nbsp;
  34. </el-form-item>
  35. </el-form>
  36. <el-divider></el-divider>
  37. <el-row class="button-group">
  38. <el-button
  39. type="primary"
  40. size="small"
  41. plain
  42. icon="el-icon-document-add"
  43. @click="handleImport"
  44. >导入</el-button>
  45. <el-button type="primary" size="small" plain icon="el-icon-circle-plus" @click="handleAdd">新增</el-button>
  46. <el-button
  47. type="primary"
  48. size="small"
  49. plain
  50. icon="el-icon-circle-plus"
  51. :disabled="multipleSelection.length==0"
  52. @click="handleBatchDelete"
  53. >删除选中项</el-button>
  54. </el-row>
  55. <el-table
  56. :data="tableData"
  57. style="min-height:400px;"
  58. v-loading="loading"
  59. stripe
  60. @sort-change="sortChange"
  61. @selection-change="handleSelectionChange"
  62. >
  63. <el-table-column type="selection" width="55"></el-table-column>
  64. <el-table-column prop="path" sort-by="path_" label="访问路径" sortable="custom" width="210"></el-table-column>
  65. <el-table-column prop="method" sort-by="method_" label="访问方式" sortable="custom" width="150"></el-table-column>
  66. <el-table-column prop="summary" sort-by="summary_" label="简介" sortable="custom" width="180"></el-table-column>
  67. <el-table-column
  68. prop="createTime"
  69. sort-by="create_time"
  70. label="创建时间"
  71. sortable="custom"
  72. width="180"
  73. ></el-table-column>
  74. <el-table-column
  75. prop="updateTime"
  76. sort-by="update_time"
  77. label="更新时间"
  78. sortable="custom"
  79. width="180"
  80. ></el-table-column>
  81. <el-table-column label="操作">
  82. <template slot-scope="{row}">
  83. <el-button size="mini" type="warning" @click="handleEdit(row)">编辑</el-button>
  84. <el-button size="mini" type="danger" @click="handleDelete(row)">删除</el-button>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <el-pagination
  89. :current-page.sync="pageIndex"
  90. :total="totalElements"
  91. :page-sizes="pageSizeList"
  92. @current-change="changePage"
  93. @size-change="pageSizeChange"
  94. layout="total, sizes, prev, pager, next, jumper"
  95. ></el-pagination>
  96. <permission-detail
  97. v-if="showDetailModal"
  98. @close="onDetailModalClose"
  99. :modalTitle="modalTitle"
  100. :permId="permId"
  101. ></permission-detail>
  102. <permission-import
  103. v-if="showImportModal"
  104. @close="onImportModalClose"
  105. :permId="permId"
  106. ></permission-import>
  107. </div>
  108. </template>
  109. <script>
  110. import Constant from "@/constant";
  111. import PermissionImport from "./permission-import";
  112. import PermissionDetail from "./permission-detail";
  113. import permissionApi from "@/api/sys/permission";
  114. import NProgress from "nprogress"; // progress bar
  115. import "nprogress/nprogress.css"; // progress bar style
  116. export default {
  117. data() {
  118. var self = this;
  119. return {
  120. queryModel: {
  121. path: ""
  122. },
  123. loading: false,
  124. tableData: [],
  125. pageIndex: 1,
  126. pageSize: 10,
  127. totalPages: 0,
  128. totalElements: 0,
  129. field: "",
  130. direction: "",
  131. pageSizeList: [10, 20, 30],
  132. multipleSelection: [],
  133. permId:"",
  134. modalTitle: "",
  135. showDetailModal: false,
  136. showImportModal: false
  137. };
  138. },
  139. methods: {
  140. changePage(pageIndex) {
  141. var self = this;
  142. self.loading = true;
  143. self.pageIndex = pageIndex;
  144. var formData = new FormData();
  145. formData.append("pageIndex", self.pageIndex);
  146. formData.append("pageSize", self.pageSize);
  147. formData.append("path", self.queryModel.path);
  148. if (this.field != null) {
  149. formData.append("field", this.field);
  150. }
  151. if (this.direction != null) {
  152. formData.append("direction", this.direction);
  153. }
  154. permissionApi
  155. .pageList(formData)
  156. .then(function(response) {
  157. self.loading = false;
  158. var jsonData = response.data;
  159. if(jsonData.result){
  160. var pageInfo = jsonData.data;
  161. self.tableData = pageInfo.data;
  162. self.totalPages = pageInfo.totalPages;
  163. self.totalElements = pageInfo.recordsTotal;
  164. }
  165. else {
  166. self.$message({
  167. message: jsonData.message + "",
  168. type: "warning"
  169. });
  170. }
  171. })
  172. .catch(error => {
  173. self.loading = false;
  174. // self.$message.error(error + "");
  175. });
  176. },
  177. pageSizeChange(pageSize) {
  178. this.pageSize = pageSize;
  179. },
  180. sortChange(data) {
  181. this.field = data.column.field;
  182. this.direction = data.order;
  183. this.changePage(this.pageIndex);
  184. },
  185. handleSelectionChange(val) {
  186. this.multipleSelection = val;
  187. },
  188. handleReset(name) {
  189. this.$refs[name].resetFields();
  190. },
  191. handleAdd() {
  192. var self = this;
  193. self.modalTitle = "新增";
  194. self.permId = "";
  195. self.showDetailModal = true;
  196. },
  197. handleEdit(record) {
  198. var self = this;
  199. self.modalTitle = "编辑";
  200. self.permId = record.id;
  201. self.showDetailModal = true;
  202. },
  203. handleDelete(record) {
  204. var self = this;
  205. self
  206. .$confirm("是否确认删除?", "提示", {
  207. confirmButtonText: "确定",
  208. cancelButtonText: "取消",
  209. type: "warning"
  210. })
  211. .then(() => {
  212. permissionApi.remove(record.id).then(function(response) {
  213. var jsonData = response.data;
  214. if (jsonData.result) {
  215. // var index = self.tableData.indexOf(record);
  216. // self.tableData.splice(index, 1);
  217. self.changePage(self.pageIndex);
  218. self.$message({
  219. type: "success",
  220. message: "删除成功!"
  221. });
  222. }
  223. });
  224. });
  225. },
  226. handleBatchDelete() {
  227. var self = this;
  228. var idList = this.multipleSelection.map(record => {
  229. return record.id;
  230. });
  231. this.$confirm("是否确认删除选中项?", "提示", {
  232. confirmButtonText: "确定",
  233. cancelButtonText: "取消",
  234. type: "warning"
  235. }).then(() => {
  236. permissionApi.batchRemove(idList).then(function(response) {
  237. var jsonData = response.data;
  238. if (jsonData.result) {
  239. self.changePage(self.pageIndex);
  240. self.$message({
  241. type: "success",
  242. message: "删除成功!"
  243. });
  244. }
  245. });
  246. });
  247. },
  248. handleImport() {
  249. // 读取所有菜单
  250. var self = this;
  251. self.showImportModal = true;
  252. },
  253. onDetailModalClose(refreshed){
  254. this.showDetailModal = false;
  255. if(refreshed){
  256. this.changePage(this.pageIndex);
  257. }
  258. },
  259. onImportModalClose(refreshed){
  260. this.showImportModal = false;
  261. if(refreshed){
  262. this.changePage(this.pageIndex);
  263. }
  264. }
  265. },
  266. mounted: function() {
  267. this.changePage(1);
  268. },
  269. components: {
  270. "permission-detail": PermissionDetail,
  271. "permission-import": PermissionImport
  272. }
  273. };
  274. </script>
  275. <style lang="scss" scoped>
  276. .el-breadcrumb {
  277. margin: 10px;
  278. line-height: 20px;
  279. }
  280. .el-divider {
  281. margin: 5px 0;
  282. }
  283. .demo-form-inline {
  284. margin-left: 10px;
  285. text-align: left;
  286. }
  287. .button-group {
  288. margin-left: 10px;
  289. text-align: left;
  290. }
  291. </style>