index.vue 11 KB

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