| | |
| | | >保存</el-button |
| | | > |
| | | <el-divider /> |
| | | <div class="menuTreeBox"> |
| | | <div class="depTreeBox"> |
| | | <el-tree |
| | | ref="tree" |
| | | :props="defaultProps" |
| | |
| | | <span>{{ node.label }}</span> |
| | | <span class="btnBox"> |
| | | <el-button |
| | | v-if="menuStatus.insert" |
| | | type="text" |
| | | size="mini" |
| | | @click="() => append(node, data)" |
| | |
| | | <i class="el-icon-circle-plus"></i> |
| | | </el-button> |
| | | <el-button |
| | | v-if="menuStatus.delete" |
| | | type="text" |
| | | size="mini" |
| | | @click="() => remove(node, data)" |
| | |
| | | <h4>详细信息</h4> |
| | | </div> |
| | | <div class="form_box"> |
| | | <el-form :model="itemdetail"> |
| | | <el-form :model="itemdetail" ref="itemdetail" :rules="rules"> |
| | | <el-form-item label="名称" :label-width="formLabelWidth"> |
| | | <el-input v-model="itemdetail.name" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | |
| | | <el-form-item label="备注" :label-width="formLabelWidth"> |
| | | <el-input v-model="itemdetail.bak" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <div class="btnBox"> |
| | | <el-button type="primary" @click="updDep">保存</el-button> |
| | | <el-button type="primary" @click="reset">取消</el-button> |
| | | <div class="btnBox" v-if="menuStatus.update"> |
| | | <el-button type="primary" @click="updDep('itemdetail')" |
| | | >保存</el-button |
| | | > |
| | | <el-button type="primary" @click="reset('itemdetail')" |
| | | >取消</el-button |
| | | > |
| | | </div> |
| | | </el-form> |
| | | </div> |
| | | </div> |
| | | <el-dialog title="新增子目录" :visible.sync="dialogFormVisible"> |
| | | <el-dialog |
| | | width="30%" |
| | | top="5vh" |
| | | title="新增子目录" |
| | | :visible.sync="dialogFormVisible" |
| | | > |
| | | <el-form :model="ruleForm" ref="ruleForm" :rules="rules"> |
| | | <el-form-item |
| | | label="目录名称" |
| | | prop="name" |
| | | :label-width="formLabelWidth" |
| | | > |
| | | <el-form-item prop="name" label="名称" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.name" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="目录说明" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.descr" autocomplete="off"></el-input> |
| | | <el-form-item label="简称" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.sname" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="目录备注" :label-width="formLabelWidth"> |
| | | <el-form-item label="编码" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.code" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="机构代码" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.uncode" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="地址" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.addr" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="联系方式" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.contact" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="传真" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.fax" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="电子邮件" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.email" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="邮政编码" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.post" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="网站地址" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.website" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="备注" :label-width="formLabelWidth"> |
| | | <el-input v-model="ruleForm.bak" autocomplete="off"></el-input> |
| | | </el-form-item> |
| | | </el-form> |
| | |
| | | </template> |
| | | |
| | | <script> |
| | | import MyBread from "../../components/MyBread.vue"; |
| | | import MyBread from '../../components/MyBread.vue'; |
| | | import { |
| | | queryDepTree, |
| | | updateDepTree, |
| | | updateDepTrees, |
| | | queryMaxId, |
| | | } from "../../api/api"; |
| | | insertDep, |
| | | deleteDep, |
| | | } from '../../api/api'; |
| | | export default { |
| | | //import引入的组件需要注入到对象中才能使用 |
| | | components: { |
| | |
| | | }, |
| | | data() { |
| | | let validName = (rule, value, callback) => { |
| | | if (value === "") { |
| | | return callback(new Error("目录名称不能为空")); |
| | | if (value === '' || value === null || value === undefined) { |
| | | return callback(new Error('名称不能为空')); |
| | | } else { |
| | | callback(); |
| | | } |
| | | }; |
| | | return { |
| | | menuStatus: { |
| | | delete: false, |
| | | insert: false, |
| | | update: false, |
| | | }, |
| | | defaultProps: { |
| | | children: "children", |
| | | label: "name", |
| | | children: 'children', |
| | | label: 'name', |
| | | }, |
| | | fullscreenLoading: false, |
| | | oriData: [], //原始树数据 |
| | |
| | | old_depData: [], //el树数据(拖动前) |
| | | newData: [], //拖动后原始数据 |
| | | itemdetail: { |
| | | addr: "", |
| | | bak: "", |
| | | code: "", |
| | | contact: "", |
| | | email: "", |
| | | fax: "", |
| | | name: "", |
| | | post: "", |
| | | sname: "", |
| | | uncode: "", |
| | | website: "", |
| | | addr: '', |
| | | bak: '', |
| | | code: '', |
| | | contact: '', |
| | | email: '', |
| | | fax: '', |
| | | name: '', |
| | | post: '', |
| | | sname: '', |
| | | uncode: '', |
| | | website: '', |
| | | }, |
| | | backUpData: {}, |
| | | formLabelWidth: "170px", |
| | | deleteIDs: "", |
| | | backUpData: '', |
| | | formLabelWidth: '130px', |
| | | delChildID: '', |
| | | delChildIDs: [], |
| | | dialogFormVisible: false, |
| | | ruleForm: { |
| | | level: null, |
| | | orderNum: null, |
| | | pid: null, |
| | | name: "", |
| | | descr: "", |
| | | bak: "", |
| | | addr: '', |
| | | bak: '', |
| | | code: '', |
| | | contact: '', |
| | | email: '', |
| | | fax: '', |
| | | name: '', |
| | | post: '', |
| | | sname: '', |
| | | uncode: '', |
| | | website: '', |
| | | }, |
| | | rules: { |
| | | name: [{ validator: validName, trigger: "blur" }], |
| | | name: [{ required: true, validator: validName, trigger: 'blur' }], |
| | | }, |
| | | }; |
| | | }, |
| | | methods: { |
| | | getMenuTree() { |
| | | getDepTree() { |
| | | //获取目录树最大ID,新建节点使用 |
| | | // queryMaxId().then((res) => { |
| | | // this.id = res.data; |
| | |
| | | this.newData = res.result; |
| | | this.depList = this.treeData(res.result); |
| | | } else { |
| | | console.log("接口报错"); |
| | | this.$notify.error({ |
| | | title: res.code, |
| | | message: '无法获取单位列表', |
| | | }); |
| | | } |
| | | }); |
| | | }, |
| | |
| | | return cloneData.filter((father) => { |
| | | // 循环所有项 |
| | | let branchArr = cloneData.filter((child) => father.id == child.pid); // 对比ID,分别上下级菜单,并返回数据 |
| | | branchArr.length > 0 ? (father.children = branchArr) : ""; // 给父级添加一个children属性,并赋值 |
| | | return father.pid == 1; // 返回一级菜单 |
| | | branchArr.length > 0 ? (father.children = branchArr) : ''; // 给父级添加一个children属性,并赋值 |
| | | return father.pid == 0; // 返回一级菜单 |
| | | }); |
| | | }, |
| | | append(node, data) { |
| | |
| | | }, |
| | | resetForm(formName) { |
| | | this.dialogFormVisible = false; |
| | | this.$refs[formName].resetFields(); |
| | | this.$nextTick(() => { |
| | | this.ruleForm = {}; |
| | | this.$refs[formName].resetFields(); |
| | | }); |
| | | }, |
| | | submitForm(formName) { |
| | | this.$refs[formName].validate((valid) => { |
| | | if (valid) { |
| | | this.fullscreenLoading = true; |
| | | // console.log(this.ruleForm); |
| | | // insertDir(this.ruleForm) |
| | | // .then((res) => { |
| | | // setTimeout(() => { |
| | | // this.fullscreenLoading = false; |
| | | // if (res.code == 200) { |
| | | // this.$message({ |
| | | // message: "添加成功", |
| | | // type: "success", |
| | | // }); |
| | | // } |
| | | // }, 2000); |
| | | // }) |
| | | // .catch((res) => { |
| | | // console.log(res); |
| | | // this.fullscreenLoading = false; |
| | | // }); |
| | | |
| | | // this.validCode = ""; //清空验证码输入框的内容 |
| | | this.fullscreenLoading = true; |
| | | insertDep(this.ruleForm) |
| | | .then((res) => { |
| | | setTimeout(() => { |
| | | this.fullscreenLoading = false; |
| | | if (res.code == 200) { |
| | | this.$message({ |
| | | message: '添加成功', |
| | | type: 'success', |
| | | }); |
| | | this.getMenuTree(); |
| | | this.itemdetail = {}; |
| | | this.ruleForm = {}; |
| | | this.dialogFormVisible = false; |
| | | this.$refs[formName].resetFields(); |
| | | } |
| | | }, 500); |
| | | }) |
| | | .catch((res) => { |
| | | this.itemdetail = {}; |
| | | this.$message.error('添加失败'); |
| | | this.fullscreenLoading = false; |
| | | console.log(res); |
| | | }); |
| | | } else { |
| | | // alert("目录名称不能为空"); |
| | | return false; |
| | |
| | | }); |
| | | }, |
| | | remove(node, data) { |
| | | this.$confirm("此操作将删除该节点, 是否继续?", "提示", { |
| | | confirmButtonText: "确定", |
| | | cancelButtonText: "取消", |
| | | type: "warning", |
| | | this.$confirm('此操作将删除该节点, 是否继续?', '提示', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning', |
| | | }) |
| | | .then(() => { |
| | | // console.log(node); |
| | | // console.log(data); |
| | | |
| | | //兄弟重新排序 |
| | | const parent = node.parent; |
| | | const children = parent.data.children || parent.data; |
| | | children.splice(data.orderNum - 1, 1); |
| | |
| | | item.orderNum = index + 1; |
| | | }); |
| | | |
| | | this.traverseArr(data); |
| | | console.log(this.deleteIDs); |
| | | this.$message({ |
| | | type: "success", |
| | | message: "删除成功!", |
| | | }); |
| | | this.traverseArr(data); //获取删除的子ID |
| | | this.delChildIDs.push(data.id); //要删除的全部ID |
| | | let delIDs = this.delChildIDs; |
| | | Promise.all([ |
| | | deleteDep({ ids: delIDs.toString() }), |
| | | updateDepTrees(children), |
| | | ]) |
| | | .then((res) => { |
| | | console.log(res); |
| | | if (res[0].code == 200 && res[1].code == 200) { |
| | | this.$message({ |
| | | type: 'success', |
| | | message: '删除成功!', |
| | | }); |
| | | this.getMenuTree(); |
| | | this.itemdetail = {}; |
| | | } else if (res[0].code == 200) { |
| | | this.getMenuTree(); |
| | | this.$message.error('删除成功,位置调整失败'); |
| | | } else if (res[1].code == 200) { |
| | | this.getMenuTree(); |
| | | this.$message.error('删除失败,位置调整成功'); |
| | | } else { |
| | | this.getMenuTree(); |
| | | this.$message.error('删除失败'); |
| | | } |
| | | }) |
| | | .catch(() => { |
| | | this.$message.error('删除失败'); |
| | | this.itemdetail = {}; |
| | | }); |
| | | |
| | | //重置要删除的子ID |
| | | this.delChildIDs = []; |
| | | }) |
| | | .catch(() => { |
| | | this.$message({ |
| | | type: "info", |
| | | message: "已取消删除", |
| | | }); |
| | | this.$message('已取消删除'); |
| | | }); |
| | | // this.dialogMessage="是否删除" |
| | | // this.dialogFlag = 1; |
| | |
| | | if (obj.children) { |
| | | return obj.children.forEach((item) => { |
| | | // console.log(item.id + "---" + item.name); |
| | | this.deleteIDs += "id=" + item.id + "&"; |
| | | // this.delChildID += "id=" + item.id + "&"; |
| | | this.delChildIDs.push(item.id); |
| | | this.traverseArr(item); |
| | | }); |
| | | } |
| | |
| | | this.old_depData = JSON.parse(JSON.stringify(this.depList)); //将备份的dir重新赋值 |
| | | }, |
| | | handleDrop(draggingNode, dropNode, dropType, ev) { |
| | | this.$confirm("此操作将保存目录更改, 是否继续?", "提示", { |
| | | confirmButtonText: "确定", |
| | | cancelButtonText: "取消", |
| | | type: "warning", |
| | | this.$confirm('此操作将保存目录更改, 是否继续?', '提示', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning', |
| | | }) |
| | | .then(() => { |
| | | //父节点 |
| | | let data = dropType != "inner" ? dropNode.parent.data : dropNode.data; |
| | | let data = dropType != 'inner' ? dropNode.parent.data : dropNode.data; |
| | | // 父节点中全部子节点 |
| | | let nodeData = |
| | | dropNode.level == 1 && dropType != "inner" ? data : data.children; |
| | | dropNode.level == 1 && dropType != 'inner' ? data : data.children; |
| | | //变更节点 |
| | | // console.log(nodeData); |
| | | nodeData.forEach((item, i) => { |
| | | if (dropType != "inner") { |
| | | if (dropType != 'inner') { |
| | | if (draggingNode.data.pid === dropNode.data.pid) { |
| | | item.pid = item.pid; |
| | | } else { |
| | |
| | | arr.push(e); |
| | | }); |
| | | this.newData = arr; |
| | | this.sendChange(); |
| | | }) |
| | | .catch(() => { |
| | | this.$message({ |
| | | type: "info", |
| | | message: "已取消更改", |
| | | type: 'info', |
| | | message: '已取消更改', |
| | | }); |
| | | this.depList = this.old_depData; //将备份的dir重新赋值 |
| | | }); |
| | |
| | | sendChange() { |
| | | updateDepTrees(this.newData) |
| | | .then((res) => { |
| | | // console.log(res); |
| | | if (res.code == 200) { |
| | | this.$message({ |
| | | type: "success", |
| | | message: "更新成功!", |
| | | }); |
| | | this.getMenuTree(); |
| | | return; |
| | | } else { |
| | | alert('调整失败,请重试!'); |
| | | } |
| | | }) |
| | | .catch(() => { |
| | | alert("修改失败,请重试!"); |
| | | alert('修改失败,请重试!'); |
| | | }); |
| | | }, |
| | | handleNodeClick(data) { |
| | |
| | | this.backUpData = JSON.stringify(data); |
| | | this.itemdetail = JSON.parse(JSON.stringify(data)); |
| | | }, |
| | | updDep() { |
| | | updateDepTree(this.itemdetail).then((res) => { |
| | | console.log(res); |
| | | updDep(formName) { |
| | | this.$nextTick(() => { |
| | | this.$refs[formName].validate((valid) => { |
| | | if (valid) { |
| | | this.fullscreenLoading = true; |
| | | updateDepTree(this.itemdetail) |
| | | .then((res) => { |
| | | setTimeout(() => { |
| | | this.fullscreenLoading = false; |
| | | if (res.code == 200) { |
| | | this.getMenuTree(); |
| | | this.itemdetail = {}; |
| | | this.dialogFormVisible = false; |
| | | } |
| | | }, 500); |
| | | }) |
| | | .catch((res) => { |
| | | alert('修改失败,请重试!'); |
| | | this.fullscreenLoading = false; |
| | | }); |
| | | } else { |
| | | return false; |
| | | } |
| | | }); |
| | | }); |
| | | }, |
| | | reset() { |
| | | this.itemdetail = JSON.parse(this.backUpData); |
| | | this.$refs[formName].resetFields(); |
| | | if (this.backUpData != '') { |
| | | this.itemdetail = JSON.parse(this.backUpData); |
| | | } |
| | | }, |
| | | showPermsMenu(res) { |
| | | switch (res.tag) { |
| | | case '/delete': |
| | | this.menuStatus.delete = true; |
| | | break; |
| | | case '/insert': |
| | | this.menuStatus.insert = true; |
| | | break; |
| | | case '/update': |
| | | this.menuStatus.update = true; |
| | | break; |
| | | } |
| | | }, |
| | | }, |
| | | mounted() { |
| | | this.getMenuTree(); |
| | | this.getDepTree(); |
| | | }, |
| | | created() { |
| | | var val = this.$store.state.currentPerms; |
| | | var permsEntity = this.$store.state.permsEntity; |
| | | for (var i = 0; i < permsEntity.length; i++) { |
| | | if (permsEntity[i].perms == val) { |
| | | this.showPermsMenu(permsEntity[i]); |
| | | } |
| | | } |
| | | }, |
| | | }; |
| | | </script> |
| | |
| | | left: 250px; |
| | | top: 23px; |
| | | } |
| | | .menuTreeBox { |
| | | .depTreeBox { |
| | | height: 88%; |
| | | width: 100%; |
| | | overflow: auto; |
| | |
| | | background-color: rgb(153, 153, 153); |
| | | } |
| | | .btnBox { |
| | | margin-left: 5px; |
| | | margin: 0 10px 0 5px; |
| | | .el-button + .el-button { |
| | | margin-left: 5px; |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | /deep/ .el-dialog__body { |
| | | padding: 0 30px 0 0; |
| | | } |
| | | } |
| | | </style> |