index.vue 8.4 KB

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