index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. >
  129. <div v-loading="loadingView" class="views">
  130. <el-tabs type="border-card" class="tabs" v-model="activeName">
  131. <el-tab-pane label="目录" name="1"
  132. ><EditMenu
  133. v-if="activeName === '1'"
  134. ref="addList"
  135. :activeName="activeName"
  136. :tableData="tableData"
  137. :checkId="checkId"
  138. :title="title"
  139. @updateList="updateList"
  140. :row="row"
  141. />
  142. </el-tab-pane>
  143. <el-tab-pane label="菜单" name="2"
  144. ><EditMenu
  145. v-if="activeName === '2'"
  146. ref="addMenu"
  147. :activeName="activeName"
  148. :tableData="tableData"
  149. :checkId="checkId"
  150. :title="title"
  151. @updateList="updateList"
  152. :row="row"
  153. /></el-tab-pane>
  154. </el-tabs>
  155. <span slot="footer" class="dialog-footer">
  156. <el-button @click="handleClose" size="small">取 消</el-button>
  157. <el-button type="primary" @click="editAuthMenu" size="small"
  158. >确 定</el-button
  159. >
  160. </span>
  161. </div>
  162. </el-dialog>
  163. </div>
  164. </template>
  165. <script>
  166. import {
  167. addMenuFn,
  168. deleteMenuFn,
  169. updateMenuFn,
  170. getAllMenu,
  171. } from "@/api/system";
  172. import EditMenu from "./components/editDialog.vue";
  173. export default {
  174. components: {
  175. EditMenu,
  176. },
  177. data() {
  178. return {
  179. piconUrl: "",
  180. activeName: "1",
  181. title: "",
  182. loadingView: false,
  183. defaultExpandAll: true,
  184. row: {},
  185. rules: {
  186. roleId: { permissionName: "change" },
  187. userName: { permissionState: "blur" },
  188. },
  189. loading: false,
  190. formInline: {
  191. permissionName: "",
  192. permissionState: "",
  193. },
  194. tableData: [],
  195. unusualdialog: false,
  196. checkId: "",
  197. };
  198. },
  199. created() {
  200. this.getTableList();
  201. },
  202. watch: {
  203. tableData: {
  204. handler(newData) {
  205. this.$nextTick(() => {
  206. this.setExpandAll(this.defaultExpandAll);
  207. });
  208. },
  209. immediate: true,
  210. deep: true,
  211. },
  212. },
  213. methods: {
  214. selected(name) {
  215. console.log(name);
  216. this.piconUrl = name;
  217. },
  218. handleClose() {
  219. if (this.activeName === "1") {
  220. this.$refs.addList.cancel();
  221. } else {
  222. this.$refs.addMenu.cancel();
  223. }
  224. this.loadingView = false;
  225. this.unusualdialog = false;
  226. this.checkId = null;
  227. },
  228. toggleExpandAll() {
  229. this.defaultExpandAll = !this.defaultExpandAll;
  230. this.$nextTick(() => {
  231. this.setExpandAll(this.defaultExpandAll);
  232. });
  233. },
  234. setExpandAll(expand) {
  235. const table = this.$refs.table;
  236. if (table) {
  237. this.tableData.forEach((row) => {
  238. table.toggleRowExpansion(row, expand);
  239. if (row.children) {
  240. row.children.forEach((child) => {
  241. table.toggleRowExpansion(child, expand);
  242. });
  243. }
  244. });
  245. }
  246. },
  247. async getTableList() {
  248. try {
  249. this.loading = true;
  250. // console.log(" debugger;");
  251. // debugger;
  252. const result = await getAllMenu({ ...this.formInline });
  253. this.tableData = result.data;
  254. this.loading = false;
  255. } catch (error) {
  256. this.$message({
  257. type: "error",
  258. message: "请检查是否连接网络",
  259. });
  260. }
  261. },
  262. //弹框确定按钮
  263. editAuthMenu() {
  264. if (this.activeName === "1") {
  265. this.$refs.addList.submit();
  266. this.checkId = null;
  267. //目录
  268. } else {
  269. //菜单
  270. this.$refs.addMenu.submit();
  271. this.checkId = null;
  272. }
  273. },
  274. updateList() {
  275. this.getTableList();
  276. this.unusualdialog = false;
  277. },
  278. // 查询
  279. onSubmit() {
  280. this.getTableList();
  281. },
  282. // 重置
  283. reset(formName) {
  284. this.$refs[formName].resetFields();
  285. this.getTableList();
  286. },
  287. // 编辑
  288. compile(row) {
  289. this.unusualdialog = true;
  290. if (row.permissionType === 1) {
  291. this.activeName = "1";
  292. this.checkId = 0;
  293. } else {
  294. this.activeName = "2";
  295. this.checkId = row.parentId;
  296. }
  297. this.row = { ...row };
  298. this.title = "编辑";
  299. },
  300. // 新增子级
  301. newcomer(row) {
  302. this.unusualdialog = true;
  303. this.checkId = row.permissionId;
  304. this.activeName = "2";
  305. this.title = "新增";
  306. },
  307. // 启用/停用
  308. updateState(row, state) {
  309. updateMenuFn({ permissionId: row.permissionId, pstat: state })
  310. .then((res) => {
  311. this.$message({
  312. message: "状态更新成功",
  313. type: "success",
  314. });
  315. this.getTableList();
  316. })
  317. .catch(() => {});
  318. },
  319. // 删除
  320. deleted(row) {
  321. this.$confirm("此操作将永久删除该文件,是否继续?", "提示", {
  322. confirmButtonText: "确定",
  323. cancelButtonText: "取消",
  324. type: "warning",
  325. })
  326. .then(() => {
  327. // 执行删除操作
  328. deleteMenuFn({ permissionId: row.permissionId })
  329. .then(() => {
  330. this.$message({
  331. type: "success",
  332. message: "删除成功!",
  333. });
  334. this.getTableList();
  335. })
  336. .catch(() => {});
  337. })
  338. .catch(() => {
  339. // 取消删除
  340. this.$message({
  341. type: "info",
  342. message: "已取消删除",
  343. });
  344. });
  345. },
  346. //新增菜单目录
  347. newnuedialog() {
  348. this.unusualdialog = true;
  349. this.activeName = "1";
  350. this.title = "新增";
  351. },
  352. },
  353. };
  354. </script>
  355. <style lang="scss" scoped>
  356. .el-select {
  357. width: 250px;
  358. }
  359. </style>