123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <template>
- <div class="global-variable">
- <div class="condition">
- <el-form
- :inline="true"
- :model="formInline"
- class="demo-form-inline"
- ref="ruleForm"
- :rules="rules"
- >
- <el-form-item label="菜单名称:" prop="permissionName">
- <el-input
- v-model="formInline.permissionName"
- placeholder="请输入菜单名称"
- size="small"
- ></el-input>
- </el-form-item>
- <el-form-item label="状态:" prop="permissionState">
- <el-select
- v-model="formInline.permissionState"
- placeholder="选择状态"
- size="small "
- >
- <el-option label="启用" value="1"></el-option>
- <el-option label="停用" value="0"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="onSubmit" size="small"
- >查询</el-button
- >
- <el-button @click="reset('ruleForm')" size="small">重置</el-button>
- </el-form-item>
- </el-form>
- </div>
- <div class="list-page">
- <div class="newly">
- <el-button type="primary" @click="newnuedialog" size="small"
- >新增</el-button
- >
- <el-button type="primary" @click="toggleExpandAll" size="small">{{
- defaultExpandAll ? "收起" : "展开"
- }}</el-button>
- </div>
- <el-table
- v-loading="loading"
- class="center-align-table"
- :data="tableData"
- border
- stripe
- row-key="permissionId"
- :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
- ref="table"
- >
- <el-table-column prop="permissionName" label="菜单名称">
- </el-table-column>
- <el-table-column
- prop="permissionType"
- label="类型"
- width="100"
- align="center"
- >
- <template slot-scope="scope">
- <span>{{
- scope.row.permissionType == 1
- ? "目录"
- : scope.row.permissionType == 2
- ? "菜单"
- : "按钮"
- }}</span>
- </template>
- </el-table-column>
- <el-table-column prop="permissionCode" label="权限标识" align="center">
- </el-table-column>
- <el-table-column prop="permissionUrl" label="路径" align="center">
- </el-table-column>
- <el-table-column
- prop="permissionState"
- label="状态"
- align="center"
- width="80"
- >
- <template slot-scope="scope">
- <span>{{ scope.row.permissionState === 1 ? "启用" : "停用" }}</span>
- </template>
- </el-table-column>
- <el-table-column fixed="right" label="操作" align="center">
- <template slot-scope="scope">
- <el-button @click="compile(scope.row)" type="text" size="small"
- >编辑</el-button
- >
- <el-button @click="newcomer(scope.row)" type="text" size="small"
- >新增</el-button
- >
- <el-button
- v-if="scope.row.permissionState === 0"
- @click="updateState(scope.row, 1)"
- type="text"
- size="small"
- >启用</el-button
- >
- <el-button
- v-else
- style="color: #666"
- @click="updateState(scope.row, 0)"
- type="text"
- size="small"
- >停用</el-button
- >
- <el-button
- style="color: #f00"
- @click="deleted(scope.row)"
- type="text"
- size="small"
- :disabled="scope.row.permissionState == 1"
- >删除</el-button
- >
- </template>
- </el-table-column>
- </el-table>
- </div>
- <!-- 新增编辑弹出层 -->
- <el-dialog
- :title="title"
- :visible.sync="unusualdialog"
- width="500px"
- @close="handleClose"
- >
- <div v-loading="loadingView" class="views">
- <el-tabs type="border-card" class="tabs" v-model="activeName">
- <el-tab-pane label="目录" name="1"
- ><EditMenu
- v-if="activeName === '1'"
- ref="addList"
- :activeName="activeName"
- :tableData="tableData"
- :checkId="checkId"
- :title="title"
- @updateList="updateList"
- :row="row"
- />
- </el-tab-pane>
- <el-tab-pane label="菜单" name="2"
- ><EditMenu
- v-if="activeName === '2'"
- ref="addMenu"
- :activeName="activeName"
- :tableData="tableData"
- :checkId="checkId"
- :title="title"
- @updateList="updateList"
- :row="row"
- /></el-tab-pane>
- </el-tabs>
- <span slot="footer" class="dialog-footer">
- <el-button @click="handleClose" size="small">取 消</el-button>
- <el-button type="primary" @click="editAuthMenu" size="small"
- >确 定</el-button
- >
- </span>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import {
- addMenuFn,
- deleteMenuFn,
- updateMenuFn,
- getAllMenu,
- } from "@/api/system";
- import EditMenu from "./components/editDialog.vue";
- export default {
- components: {
- EditMenu,
- },
- data() {
- return {
- piconUrl: "",
- activeName: "1",
- title: "",
- loadingView: false,
- defaultExpandAll: true,
- row: {},
- rules: {
- roleId: { permissionName: "change" },
- userName: { permissionState: "blur" },
- },
- loading: false,
- formInline: {
- permissionName: "",
- permissionState: "",
- },
- tableData: [],
- unusualdialog: false,
- checkId: "",
- };
- },
- created() {
- this.getTableList();
- },
- watch: {
- tableData: {
- handler(newData) {
- this.$nextTick(() => {
- this.setExpandAll(this.defaultExpandAll);
- });
- },
- immediate: true,
- deep: true,
- },
- },
- methods: {
- selected(name) {
- console.log(name);
- this.piconUrl = name;
- },
- handleClose() {
- if (this.activeName === "1") {
- this.$refs.addList.cancel();
- } else {
- this.$refs.addMenu.cancel();
- }
- this.loadingView = false;
- this.unusualdialog = false;
- this.checkId = null;
- },
- toggleExpandAll() {
- this.defaultExpandAll = !this.defaultExpandAll;
- this.$nextTick(() => {
- this.setExpandAll(this.defaultExpandAll);
- });
- },
- setExpandAll(expand) {
- const table = this.$refs.table;
- if (table) {
- this.tableData.forEach((row) => {
- table.toggleRowExpansion(row, expand);
- if (row.children) {
- row.children.forEach((child) => {
- table.toggleRowExpansion(child, expand);
- });
- }
- });
- }
- },
- async getTableList() {
- try {
- this.loading = true;
- // console.log(" debugger;");
- // debugger;
- const result = await getAllMenu({ ...this.formInline });
- this.tableData = result.data;
- this.loading = false;
- } catch (error) {
- this.$message({
- type: "error",
- message: "请检查是否连接网络",
- });
- }
- },
- //弹框确定按钮
- editAuthMenu() {
- if (this.activeName === "1") {
- this.$refs.addList.submit();
- this.checkId = null;
- //目录
- } else {
- //菜单
- this.$refs.addMenu.submit();
- this.checkId = null;
- }
- },
- updateList() {
- this.getTableList();
- this.unusualdialog = false;
- },
- // 查询
- onSubmit() {
- this.getTableList();
- },
- // 重置
- reset(formName) {
- this.$refs[formName].resetFields();
- this.getTableList();
- },
- // 编辑
- compile(row) {
- this.unusualdialog = true;
- if (row.permissionType === 1) {
- this.activeName = "1";
- this.checkId = 0;
- } else {
- this.activeName = "2";
- this.checkId = row.parentId;
- }
- this.row = { ...row };
- this.title = "编辑";
- },
- // 新增子级
- newcomer(row) {
- this.unusualdialog = true;
- this.checkId = row.permissionId;
- this.activeName = "2";
- this.title = "新增";
- },
- // 启用/停用
- updateState(row, state) {
- updateMenuFn({ permissionId: row.permissionId, pstat: state })
- .then((res) => {
- this.$message({
- message: "状态更新成功",
- type: "success",
- });
- this.getTableList();
- })
- .catch(() => {});
- },
- // 删除
- deleted(row) {
- this.$confirm("此操作将永久删除该文件,是否继续?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- // 执行删除操作
- deleteMenuFn({ permissionId: row.permissionId })
- .then(() => {
- this.$message({
- type: "success",
- message: "删除成功!",
- });
- this.getTableList();
- })
- .catch(() => {});
- })
- .catch(() => {
- // 取消删除
- this.$message({
- type: "info",
- message: "已取消删除",
- });
- });
- },
- //新增菜单目录
- newnuedialog() {
- this.unusualdialog = true;
- this.activeName = "1";
- this.title = "新增";
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .el-select {
- width: 250px;
- }
- </style>
|