123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- <template>
- <div class="box pagePadding">
- <div
- v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
- >
- <el-row :gutter="10">
- <el-col :span="24" style="padding: 5px">
- <el-col :span="3" style="width: 195px; float: right">
- <el-button
- type="primary"
- :size="searchSize"
- style="float: right; margin-left: 5px"
- @click="searchList"
- >
- 刷新
- </el-button>
- <el-button
- v-if="powers.some((item) => item == '003')"
- type="success"
- :size="searchSize"
- style="float: right"
- @click="addEditFn(0, '0', 1, false, true, {})"
- >
- 添加
- </el-button>
- </el-col>
- </el-col>
- </el-row>
- <el-row :gutter="10">
- <el-col :span="24" v-loading="loading">
- <shy-tree
- :value="tableData"
- :level="1"
- @addEdit="addEditFn"
- @openChildren="openChildren"
- @remove="remove"
- @deleteMenu="deleteMenu"
- />
- </el-col>
- </el-row>
- <add-edit
- :id="modelId"
- :show-model="showModel"
- :level="level"
- :parent-ids="parentIds"
- :is-add="isAdd"
- :form-data="formData"
- :type="parmValue.type"
- :is-detail="isDetail"
- @refresh="submitRefresh"
- @cancel="showModel = false"
- />
- </div>
- <div v-else>
- <no-auth></no-auth>
- </div>
- </div>
- </template>
- <script>
- import mixinPage from "@/mixins/elPaginationHandle";
- import asyncRequest from "@/apis/service/system/menu";
- import addEdit from "@/views/system/menuOperator/addEdit";
- import { mapGetters } from "vuex";
- import resToken from "@/mixins/resToken";
- export default {
- name: "MenuOperator",
- components: {
- addEdit,
- },
- mixins: [mixinPage, resToken],
- computed: {
- ...mapGetters(["tablebtnSize", "searchSize", "size"]),
- powers() {
- let tran =
- this.$store.getters.btnList.find(
- (item) => item.menu_route == "menuOperator"
- ) || {};
- if (tran && tran.action && tran.action.length > 0) {
- return tran.action;
- } else {
- return [];
- }
- },
- },
- data() {
- return {
- loading: true,
- showModel: false,
- showInterface: false,
- isDetail: false,
- isAdd: true,
- level: 1,
- modelId: 0,
- formData: {},
- parentIds: "",
- parmValue: {
- parentId: 0, // 父级Id
- code: "", // 编码
- status: "", // 状态(1启用 2禁用)
- type: 1, // 类型(1.运营菜单 2.物业菜单)
- menuCategory: "", // 菜单类别(1.导航菜单 2.按钮)
- current: 1, // 页码
- size: 15, // 每页显示条数
- },
- tableData: [],
- };
- },
- created() {
- this.searchList();
- },
- methods: {
- addEditFn(id, parentIds, level, isDetail, isAdd, formData) {
- this.showModel = true;
- this.modelId = id;
- this.level = level;
- this.parentIds = parentIds;
- this.isDetail = isDetail;
- this.isAdd = isAdd;
- this.formData = formData;
- },
- async submitRefresh(id, parentIds, level) {
- if (level < 3) {
- await this.searchList();
- } else {
- this.getchildList(parentIds);
- }
- },
- async remove(id, parentIds, level, status) {
- await this.$confirm(`确定要${status === "0" ? "启用" : "禁用"}?`, {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(async () => {
- const model = {
- id: id,
- status: status === "1" ? "0" : "1",
- };
- let res = {};
- if (level === 3) {
- res = await asyncRequest.actionstatus(model);
- } else {
- res = await asyncRequest.menustatus(model);
- }
- if (res && res.code === 0) {
- this.$notify.success({
- title: "修改成功!",
- message: "",
- });
- if (level === 3) {
- this.getchildList(parentIds);
- } else {
- await this.searchList();
- }
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(res.message);
- }
- })
- .catch(() => {
- console.log("取消");
- });
- },
- async deleteMenu(id, parentIds, level, status) {
- await this.$confirm(`确定要删除?`, {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(async () => {
- const model = {
- id: id,
- };
- let res = {};
- if (level === 3) {
- res = await asyncRequest.actiondel(model);
- } else {
- res = await asyncRequest.menudel(model);
- }
- if (res && res.code === 0) {
- this.$notify.success({
- title: "删除成功!",
- message: "",
- });
- if (level === 3) {
- this.getchildList(parentIds);
- } else {
- await this.searchList();
- }
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- }
- })
- .catch(() => {
- console.log("取消");
- });
- },
- openChildren(id, parentIds, level, isOpen) {
- if (isOpen) {
- // console.log(
- // `openChildren-id, parentIds, level:${id}-${parentIds}-${level}`
- // );
- if (level === 1) {
- this.tableData = this.tableData.map((v) => {
- if (v.id === id) {
- v.child = [];
- }
- return v;
- });
- } else {
- this.tableData = this.tableData.map((v) => {
- if (v.id === parentIds) {
- v.child = v.child.map((val) => {
- if (val.id === id) val.child = [];
- return val;
- });
- }
- return v;
- });
- }
- } else {
- if (level === 1) {
- this.concatData(id, "0", level);
- } else {
- this.getchildList(id);
- }
- }
- },
- async getchildList(id) {
- this.loading = true;
- const res = await asyncRequest.actionList({ id: id });
- let tableData = [];
- if (res && res.code === 0 && res.data) {
- tableData = res.data;
- // tableData = tableData.map((val) => {
- // let index = btnList.findIndex((e) => val.action_code === e.code);
- // if (index !== -1) {
- // val.menu_name = btnList[index].name;
- // }
- // return val;
- // });
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(res.message);
- }
- let arr = JSON.parse(JSON.stringify(this.tableData));
- arr = arr.map((val, index) => {
- if (val && val.child && val.child.length > 0) {
- val.child.forEach((el, eli) => {
- if (id === el.id) {
- // console.log(el);
- el.child = tableData;
- }
- return el;
- });
- }
- return val;
- });
- this.tableData = arr;
- this.loading = false;
- },
- async concatData(id, parentIds, level) {
- this.loading = true;
- const res = await asyncRequest.list({});
- let tableData = [];
- if (res && res.code === 0 && res.data) {
- tableData = res.data;
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(res.message);
- }
- let arr = JSON.parse(JSON.stringify(this.tableData));
- arr = arr.map((val, index) => {
- if (level === 1 ? id : parentIds === val.id) {
- val.child = tableData[index].child;
- }
- return val;
- });
- this.tableData = arr;
- this.loading = false;
- },
- async searchList() {
- this.loading = true;
- const res = await asyncRequest.list({});
- this.tableData = [];
- if (res && res.code === 0 && res.data) {
- this.tableData = res.data;
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.tableData = [];
- }
- this.loading = false;
- },
- },
- };
- </script>
|