index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div class="global-variable">
  3. <div class="condition">
  4. <el-form
  5. :inline="true"
  6. :model="formInline"
  7. class="demo-form-inline"
  8. ref="ruleForm"
  9. :rules="rules"
  10. >
  11. <el-form-item label="菜单名称:" prop="permissionName">
  12. <el-input
  13. v-model="formInline.permissionName"
  14. placeholder="请输入菜单名称"
  15. size="small"
  16. ></el-input>
  17. </el-form-item>
  18. <el-form-item label="状态:" prop="permissionState">
  19. <el-select
  20. v-model="formInline.permissionState"
  21. placeholder="选择状态"
  22. size="small "
  23. >
  24. <el-option label="启用" value="1"></el-option>
  25. <el-option label="停用" value="0"></el-option>
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button type="primary" @click="onSubmit" size="small"
  30. >查询</el-button
  31. >
  32. <el-button @click="reset('ruleForm')" size="small">重置</el-button>
  33. </el-form-item>
  34. </el-form>
  35. </div>
  36. <div class="list-page">
  37. <div class="newly">
  38. <el-button type="primary" @click="newnuedialog" size="small"
  39. >新增</el-button
  40. >
  41. <el-button type="primary" @click="toggleExpandAll" size="small">{{
  42. defaultExpandAll ? "收起" : "展开"
  43. }}</el-button>
  44. </div>
  45. <el-table
  46. v-loading="loading"
  47. class="center-align-table"
  48. :data="tableData"
  49. border
  50. stripe
  51. row-key="permissionId"
  52. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  53. ref="table"
  54. >
  55. <el-table-column prop="permissionName" label="菜单名称">
  56. </el-table-column>
  57. <el-table-column
  58. prop="permissionType"
  59. label="类型"
  60. width="100"
  61. align="center"
  62. >
  63. <template slot-scope="scope">
  64. <span>{{
  65. scope.row.permissionType == 1
  66. ? "目录"
  67. : scope.row.permissionType == 2
  68. ? "菜单"
  69. : "按钮"
  70. }}</span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column prop="permissionCode" label="权限标识" align="center">
  74. </el-table-column>
  75. <el-table-column prop="permissionUrl" label="路径" align="center">
  76. </el-table-column>
  77. <el-table-column
  78. prop="permissionState"
  79. label="状态"
  80. align="center"
  81. width="80"
  82. >
  83. <template slot-scope="scope">
  84. <span>{{ scope.row.permissionState === 1 ? "启用" : "停用" }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column fixed="right" label="操作" align="center">
  88. <template slot-scope="scope">
  89. <el-button @click="compile(scope.row)" type="text" size="small"
  90. >编辑</el-button
  91. >
  92. <el-button @click="newcomer(scope.row)" type="text" size="small"
  93. >新增</el-button
  94. >
  95. <el-button
  96. v-if="scope.row.permissionState === 0"
  97. @click="updateState(scope.row, 1)"
  98. type="text"
  99. size="small"
  100. >启用</el-button
  101. >
  102. <el-button
  103. v-else
  104. style="color: #666"
  105. @click="updateState(scope.row, 0)"
  106. type="text"
  107. size="small"
  108. >停用</el-button
  109. >
  110. <el-button
  111. style="color: #f00"
  112. @click="deleted(scope.row)"
  113. type="text"
  114. size="small"
  115. :disabled="scope.row.permissionState == 1"
  116. >删除</el-button
  117. >
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. </div>
  122. <!-- 新增编辑弹出层 -->
  123. <el-dialog
  124. :title="title"
  125. :visible.sync="unusualdialog"
  126. width="500px"
  127. @close="handleClose"
  128. :before-close="handleCloses"
  129. >
  130. <div v-loading="loadingView" class="views">
  131. <el-tabs type="border-card" class="tabs" v-model="activeName">
  132. <el-tab-pane label="目录" name="1"
  133. ><EditMenu
  134. v-if="activeName === '1'"
  135. ref="addList"
  136. :activeName="activeName"
  137. :tableData="tableData"
  138. :checkId="checkId"
  139. :title="title"
  140. @updateList="updateList"
  141. :row="row"
  142. />
  143. </el-tab-pane>
  144. <el-tab-pane label="菜单" name="2"
  145. ><EditMenu
  146. v-if="activeName === '2'"
  147. ref="addMenu"
  148. :activeName="activeName"
  149. :tableData="tableData"
  150. :checkId="checkId"
  151. :title="title"
  152. @updateList="updateList"
  153. :row="row"
  154. /></el-tab-pane>
  155. <el-tab-pane label="功能" name="3"
  156. ><EditMenuBtn
  157. v-if="activeName === '3'"
  158. ref="addMenuBtn"
  159. :activeName="activeName"
  160. :tableData="tableData"
  161. :checkId="checkId"
  162. :title="title"
  163. @updateList="updateList"
  164. :row="row"
  165. /></el-tab-pane>
  166. </el-tabs>
  167. <span slot="footer" class="dialog-footer">
  168. <el-button @click="handleClose" size="small">取 消</el-button>
  169. <el-button type="primary" @click="editAuthMenu" size="small"
  170. >确 定</el-button
  171. >
  172. </span>
  173. </div>
  174. </el-dialog>
  175. </div>
  176. </template>
  177. <script>
  178. import {
  179. addMenuFn,
  180. deleteMenuFn,
  181. updateMenuFn,
  182. getAllMenu,
  183. } from "@/api/system";
  184. import EditMenu from "./components/editDialog.vue";
  185. import EditMenuBtn from "./components/editDialogBtn.vue";
  186. export default {
  187. components: {
  188. EditMenu,
  189. EditMenuBtn,
  190. },
  191. data() {
  192. return {
  193. piconUrl: "",
  194. activeName: "1",
  195. title: "",
  196. loadingView: false,
  197. defaultExpandAll: true,
  198. row: {},
  199. rules: {
  200. roleId: { permissionName: "change" },
  201. userName: { permissionState: "blur" },
  202. },
  203. loading: false,
  204. formInline: {
  205. permissionName: "",
  206. permissionState: "",
  207. },
  208. tableData: [],
  209. unusualdialog: false,
  210. checkId: 0,
  211. };
  212. },
  213. created() {
  214. this.getTableList();
  215. },
  216. watch: {
  217. tableData: {
  218. handler(newData) {
  219. this.$nextTick(() => {
  220. this.setExpandAll(this.defaultExpandAll);
  221. });
  222. },
  223. immediate: true,
  224. deep: true,
  225. },
  226. },
  227. methods: {
  228. handleCloses(done) {
  229. this.$confirm("确认关闭?")
  230. .then((_) => {
  231. done();
  232. })
  233. .catch((_) => {});
  234. },
  235. selected(name) {
  236. console.log(name);
  237. this.piconUrl = name;
  238. },
  239. handleClose() {
  240. if (this.activeName === "1") {
  241. this.$refs.addList.cancel();
  242. } else if (this.activeName === "2") {
  243. this.$refs.addMenu.cancel();
  244. } else if (this.activeName === "3") {
  245. this.$refs.addMenuBtn.cancel();
  246. }
  247. this.loadingView = false;
  248. this.unusualdialog = false;
  249. this.checkId = null;
  250. },
  251. toggleExpandAll() {
  252. this.defaultExpandAll = !this.defaultExpandAll;
  253. this.$nextTick(() => {
  254. this.setExpandAll(this.defaultExpandAll);
  255. });
  256. },
  257. setExpandAll(expand) {
  258. const table = this.$refs.table;
  259. if (table) {
  260. this.tableData.forEach((row) => {
  261. table.toggleRowExpansion(row, expand);
  262. if (row.children) {
  263. row.children.forEach((child) => {
  264. table.toggleRowExpansion(child, expand);
  265. });
  266. }
  267. });
  268. }
  269. },
  270. async getTableList() {
  271. try {
  272. this.loading = true;
  273. const result = await getAllMenu({ ...this.formInline });
  274. this.tableData = result.data;
  275. this.loading = false;
  276. } catch (error) {
  277. this.$message({
  278. type: "error",
  279. message: "请检查是否连接网络",
  280. });
  281. }
  282. },
  283. //弹框确定按钮
  284. editAuthMenu() {
  285. if (this.activeName === "1") {
  286. this.$refs.addList.submit();
  287. this.checkId = null;
  288. //目录
  289. } else if (this.activeName === "2") {
  290. //菜单
  291. this.$refs.addMenu.submit();
  292. this.checkId = null;
  293. } else if (this.activeName === "3") {
  294. this.$refs.addMenuBtn.submit();
  295. this.checkId = null;
  296. }
  297. },
  298. updateList() {
  299. this.getTableList();
  300. this.unusualdialog = false;
  301. },
  302. // 查询
  303. onSubmit() {
  304. this.getTableList();
  305. },
  306. // 重置
  307. reset(formName) {
  308. this.$refs[formName].resetFields();
  309. this.getTableList();
  310. },
  311. // 编辑
  312. compile(row) {
  313. this.unusualdialog = true;
  314. if (row.permissionType === 1) {
  315. this.activeName = "1";
  316. this.checkId = 0;
  317. } else if (row.permissionType === 2) {
  318. this.activeName = "2";
  319. this.checkId = row.parentId;
  320. } else if (row.permissionType === 3) {
  321. this.activeName = "3";
  322. this.checkId = row.parentId;
  323. }
  324. this.row = { ...row };
  325. this.title = "编辑";
  326. },
  327. // 新增子级
  328. newcomer(row) {
  329. this.unusualdialog = true;
  330. this.checkId = row.permissionId;
  331. this.activeName = "2";
  332. if (row.permissionType === 2) {
  333. this.activeName = "3";
  334. }
  335. this.title = "新增";
  336. },
  337. // 启用/停用
  338. updateState(row, state) {
  339. updateMenuFn({ permissionId: row.permissionId, pstat: state })
  340. .then((res) => {
  341. this.$message({
  342. message: "状态更新成功",
  343. type: "success",
  344. });
  345. this.getTableList();
  346. })
  347. .catch(() => {});
  348. },
  349. // 删除
  350. deleted(row) {
  351. this.$confirm("此操作将永久删除该文件,是否继续?", "提示", {
  352. confirmButtonText: "确定",
  353. cancelButtonText: "取消",
  354. type: "warning",
  355. })
  356. .then(() => {
  357. // 执行删除操作
  358. deleteMenuFn({ permissionId: row.permissionId })
  359. .then(() => {
  360. this.$message({
  361. type: "success",
  362. message: "删除成功!",
  363. });
  364. this.getTableList();
  365. })
  366. .catch(() => {});
  367. })
  368. .catch(() => {
  369. // 取消删除
  370. this.$message({
  371. type: "info",
  372. message: "已取消删除",
  373. });
  374. });
  375. },
  376. //新增菜单目录
  377. newnuedialog() {
  378. this.unusualdialog = true;
  379. this.activeName = "1";
  380. this.title = "新增";
  381. },
  382. },
  383. };
  384. </script>
  385. <style lang="scss" scoped>
  386. .el-select {
  387. width: 250px;
  388. }
  389. .views {
  390. .el-tabs--border-card {
  391. min-height: 470px;
  392. }
  393. }
  394. .dialog-footer {
  395. margin-top: 20px;
  396. }
  397. </style>