index.vue 8.5 KB

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