index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <div class="box pagePadding MenuOperator">
  3. <div
  4. class="MenuOperator-main"
  5. v-if=" powers.some((i) => i == '001')"
  6. >
  7. <el-row class="MenuOperator-search">
  8. <el-col :span="24" style="padding: 5px">
  9. <el-col :span="3" style="width: 195px; float: right">
  10. <el-button
  11. type="primary"
  12. :size="searchSize"
  13. style="float: right; margin-left: 5px"
  14. @click="searchList"
  15. >
  16. 刷新
  17. </el-button>
  18. <el-button
  19. v-if="powers.some((i) => i == '003')"
  20. type="success"
  21. :size="searchSize"
  22. style="float: right"
  23. @click="addEditFn(0, '0', 1, false, true, {})"
  24. >
  25. 添加
  26. </el-button>
  27. </el-col>
  28. </el-col>
  29. </el-row>
  30. <el-row class="MenuOperator-show">
  31. <el-col :span="24" v-loading="loading">
  32. <shy-tree
  33. :value="tableData"
  34. :level="1"
  35. @addEdit="addEditFn"
  36. @openChildren="openChildren"
  37. @remove="remove"
  38. @deleteMenu="deleteMenu"
  39. />
  40. </el-col>
  41. </el-row>
  42. <add-edit
  43. :id="modelId"
  44. :show-model="showModel"
  45. :level="level"
  46. :parent-ids="parentIds"
  47. :is-add="isAdd"
  48. :form-data="formData"
  49. :type="parmValue.type"
  50. :is-detail="isDetail"
  51. @refresh="submitRefresh"
  52. @cancel="showModel = false"
  53. />
  54. </div>
  55. <div v-else>
  56. <no-auth></no-auth>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import mixinPage from "@/mixins/elPaginationHandle";
  62. import asyncRequest from "@/apis/service/system/menu";
  63. import addEdit from "@/views/system/menuOperator/addEdit";
  64. import resToken from "@/mixins/resToken";
  65. import { mapGetters } from "vuex";
  66. export default {
  67. name: "MenuOperator",
  68. components: {
  69. addEdit,
  70. },
  71. mixins: [mixinPage, resToken],
  72. computed: {
  73. ...mapGetters(["tablebtnSize", "searchSize", "size"]),
  74. powers() {
  75. const { btnList } = this.$store.getters;
  76. const tran = btnList.find((item) => item.menu_route == "menuOperator") || {};
  77. const { action } = tran ?? {};
  78. return action ?? [];
  79. },
  80. },
  81. data() {
  82. return {
  83. loading: true,
  84. showModel: false,
  85. showInterface: false,
  86. isDetail: false,
  87. isAdd: true,
  88. level: 1,
  89. modelId: 0,
  90. formData: {},
  91. parentIds: "",
  92. parmValue: {
  93. parentId: 0, // 父级Id
  94. code: "", // 编码
  95. status: "", // 状态(1启用 2禁用)
  96. type: 1, // 类型(1.运营菜单 2.物业菜单)
  97. menuCategory: "", // 菜单类别(1.导航菜单 2.按钮)
  98. current: 1, // 页码
  99. size: 15, // 每页显示条数
  100. },
  101. tableData: [],
  102. };
  103. },
  104. mounted() {
  105. this.searchList();
  106. },
  107. methods: {
  108. addEditFn(id, parentIds, level, isDetail, isAdd, formData) {
  109. this.showModel = true;
  110. this.modelId = id;
  111. this.level = level;
  112. this.parentIds = parentIds;
  113. this.isDetail = isDetail;
  114. this.isAdd = isAdd;
  115. this.formData = formData;
  116. },
  117. async submitRefresh(id, parentIds, level) {
  118. if (level < 3) {
  119. await this.searchList();
  120. } else {
  121. this.getchildList(parentIds);
  122. }
  123. },
  124. async remove(id, parentIds, level, status) {
  125. await this.$confirm(`确定要${status === "0" ? "启用" : "禁用"}?`, {
  126. confirmButtonText: "确定",
  127. cancelButtonText: "取消",
  128. type: "warning",
  129. })
  130. .then(async () => {
  131. const model = {
  132. id: id,
  133. status: status === "1" ? "0" : "1",
  134. };
  135. let res = {};
  136. if (level === 3) {
  137. res = await asyncRequest.actionstatus(model);
  138. } else {
  139. res = await asyncRequest.menustatus(model);
  140. }
  141. if (res && res.code === 0) {
  142. this.$notify.success({
  143. title: "修改成功!",
  144. message: "",
  145. });
  146. if (level === 3) {
  147. this.getchildList(parentIds);
  148. } else {
  149. await this.searchList();
  150. }
  151. } else if (res && res.code >= 100 && res.code <= 104) {
  152. await this.logout();
  153. } else {
  154. this.$message.warning(res.message);
  155. }
  156. })
  157. .catch(() => {
  158. console.log("取消");
  159. });
  160. },
  161. async deleteMenu(id, parentIds, level, status) {
  162. await this.$confirm(`确定要删除?`, {
  163. confirmButtonText: "确定",
  164. cancelButtonText: "取消",
  165. type: "warning",
  166. })
  167. .then(async () => {
  168. const model = {
  169. id: id,
  170. };
  171. let res = {};
  172. if (level === 3) {
  173. res = await asyncRequest.actiondel(model);
  174. } else {
  175. res = await asyncRequest.menudel(model);
  176. }
  177. if (res && res.code === 0) {
  178. this.$notify.success({
  179. title: "删除成功!",
  180. message: "",
  181. });
  182. if (level === 3) {
  183. this.getchildList(parentIds);
  184. } else {
  185. await this.searchList();
  186. }
  187. } else if (res && res.code >= 100 && res.code <= 104) {
  188. await this.logout();
  189. }
  190. })
  191. .catch(() => {
  192. console.log("取消");
  193. });
  194. },
  195. openChildren(id, parentIds, level, isOpen) {
  196. if (isOpen) {
  197. if (level === 1) {
  198. this.tableData = this.tableData.map((v) => {
  199. if (v.id === id) {
  200. v.child = [];
  201. }
  202. return v;
  203. });
  204. } else {
  205. this.tableData = this.tableData.map((v) => {
  206. if (v.id === parentIds) {
  207. v.child = v.child.map((val) => {
  208. if (val.id === id) val.child = [];
  209. return val;
  210. });
  211. }
  212. return v;
  213. });
  214. }
  215. } else {
  216. if (level === 1) {
  217. this.concatData(id, "0", level);
  218. } else {
  219. this.getchildList(id);
  220. }
  221. }
  222. },
  223. async getchildList(id) {
  224. this.loading = true;
  225. const res = await asyncRequest.actionList({ id: id });
  226. let tableData = [];
  227. if (res && res.code === 0 && res.data) {
  228. tableData = res.data;
  229. // tableData = tableData.map((val) => {
  230. // let index = btnList.findIndex((e) => val.action_code === e.code);
  231. // if (index !== -1) {
  232. // val.menu_name = btnList[index].name;
  233. // }
  234. // return val;
  235. // });
  236. } else if (res && res.code >= 100 && res.code <= 104) {
  237. await this.logout();
  238. } else {
  239. this.$message.warning(res.message);
  240. }
  241. let arr = JSON.parse(JSON.stringify(this.tableData));
  242. arr = arr.map((val, index) => {
  243. if (val && val.child && val.child.length > 0) {
  244. val.child.forEach((el, eli) => {
  245. if (id === el.id) {
  246. el.child = tableData;
  247. }
  248. return el;
  249. });
  250. }
  251. return val;
  252. });
  253. this.tableData = arr;
  254. this.loading = false;
  255. },
  256. async concatData(id, parentIds, level) {
  257. this.loading = true;
  258. const res = await asyncRequest.list({});
  259. let tableData = [];
  260. if (res && res.code === 0 && res.data) {
  261. tableData = res.data;
  262. } else if (res && res.code >= 100 && res.code <= 104) {
  263. await this.logout();
  264. } else {
  265. this.$message.warning(res.message);
  266. }
  267. let arr = JSON.parse(JSON.stringify(this.tableData));
  268. arr = arr.map((val, index) => {
  269. if (level === 1 ? id : parentIds === val.id) {
  270. val.child = tableData[index].child;
  271. }
  272. return val;
  273. });
  274. this.tableData = arr;
  275. this.loading = false;
  276. },
  277. async searchList() {
  278. this.loading = true;
  279. const res = await asyncRequest.list({});
  280. this.tableData = [];
  281. if (res && res.code === 0 && res.data) {
  282. this.tableData = res.data;
  283. } else if (res && res.code >= 100 && res.code <= 104) {
  284. await this.logout();
  285. } else {
  286. this.tableData = [];
  287. }
  288. this.loading = false;
  289. },
  290. },
  291. };
  292. </script>
  293. <style lang="scss" scoped>
  294. .MenuOperator {
  295. position: relative;
  296. height: 100%;
  297. width: 100%;
  298. box-sizing: border-box;
  299. .MenuOperator-main {
  300. position: relative;
  301. height: 100%;
  302. width: 100%;
  303. box-sizing: border-box;
  304. .MenuOperator-search{
  305. position: absolute;
  306. top:0;
  307. left:0;
  308. width: 100%;
  309. z-index: 2;
  310. background: #fff;
  311. }
  312. .MenuOperator-show{
  313. position: relative;
  314. height: 100%;
  315. padding: 40px 0 0 0;
  316. overflow-y: scroll;
  317. }
  318. }
  319. }
  320. </style>