menus.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div id="menus">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <el-col :span="24" class="one">
  6. <cSearch :is_title="false" :is_back="true" @toBack="toBack"> </cSearch>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <cButton @toAdd="toAdd"></cButton>
  10. </el-col>
  11. <el-col :span="24" class="thr"> 列表 </el-col>
  12. </el-col>
  13. </el-row>
  14. <cDialog :dialog="dialog" @handleClose="toClose">
  15. <template v-slot:info>
  16. <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
  17. <cForm :fields="fields" :form="form" labelWidth="auto" @save="toSave" @dataChange="dataChange">
  18. <template #type>
  19. <el-option v-for="(i, index) in typeList" :key="`t${index}`" :label="i.label" :value="i.value"></el-option>
  20. </template>
  21. <!-- <template #parent_id>
  22. <el-option v-for="(i, index) in getOneDimensionList()" :key="`m${index}`" :label="i.name" :value="i._id"></el-option>
  23. </template>
  24. <template #icon>
  25. <el-option v-for="i in iconList" :key="i.dict_value" :label="i.dict_label" :value="i.dict_value">
  26. <span style="float: left" :class="['iconfont', i.dict_label]"></span>
  27. <span style="float: right; color: #8492a6; font-size: 13px">{{ i.dict_label }}</span>
  28. </el-option>
  29. </template>
  30. <template #status>
  31. <el-radio-group v-model="form.status">
  32. <el-radio label="0">使用</el-radio>
  33. <el-radio label="1">禁用</el-radio>
  34. </el-radio-group>
  35. </template> -->
  36. </cForm>
  37. </el-col>
  38. </template>
  39. </cDialog>
  40. </div>
  41. </template>
  42. <script setup lang="ts">
  43. // 基础
  44. import type { Ref } from 'vue';
  45. import { onMounted, ref } from 'vue';
  46. import { useRoute } from 'vue-router';
  47. // 接口
  48. import { MenusStore } from '@common/src/stores/system/menus';
  49. import type { IQueryResult } from '@/util/types.util';
  50. const menusAxios = MenusStore();
  51. // 路由
  52. const route = useRoute();
  53. // 模块id
  54. const module_id: Ref<any> = ref(['']);
  55. // 菜单列表
  56. const list: Ref<any> = ref([]);
  57. // 弹框
  58. const dialog: Ref<any> = ref({ title: '菜单管理', show: false, type: '1' });
  59. const form: Ref<any> = ref({});
  60. const fields: Ref<any> = ref([
  61. { label: '菜单名称', model: 'name' },
  62. { label: '菜单类型', model: 'type', type: 'select' },
  63. { label: '父级菜单', model: 'parent_id', type: 'select' },
  64. { label: '顺序', model: 'order_num', type: 'number' },
  65. { label: '图标', model: 'icon', type: 'select' },
  66. { label: '状态', model: 'status', custom: true },
  67. { label: '备注', model: 'remark', type: 'textarea' }
  68. ]);
  69. // 字典
  70. const typeList: Ref<any> = ref([
  71. { label: '目录', value: '0' },
  72. { label: '菜单', value: '1' },
  73. { label: '子页面', value: '2' }
  74. ]);
  75. // 请求
  76. onMounted(async () => {
  77. let id = route.query.id;
  78. if (id) module_id.value = id;
  79. await search();
  80. });
  81. const search = async () => {
  82. if (module_id.value) {
  83. let res: IQueryResult;
  84. res = await menusAxios.query({ module_id: module_id.value });
  85. if (res.errcode == '0') {
  86. list.value = res.data;
  87. }
  88. }
  89. };
  90. // 添加
  91. const toAdd = () => {
  92. form.value = { module_id: module_id.value };
  93. dialog.value = { title: '菜单管理', show: true, type: '1' };
  94. };
  95. // 选择
  96. const dataChange = ({ model, value }) => {
  97. if (model == 'type') {
  98. if (value == '0') {
  99. fields.value = fields.value.filter((i) => i.model != 'path' && i.model != 'component');
  100. } else {
  101. let data = fields.value.find((i) => i.model == 'path');
  102. if (!data) {
  103. fields.value.splice(3, 0, { label: '路由地址', model: 'path' }, { label: '组件地址', model: 'component' });
  104. }
  105. }
  106. }
  107. };
  108. // 提交保存
  109. const toSave = async (e) => {
  110. console.log(e);
  111. };
  112. // 关闭弹框
  113. const toClose = () => {
  114. dialog.value = { title: '菜单管理', show: false, type: '1' };
  115. search();
  116. };
  117. // 返回上一页
  118. const toBack = () => {
  119. window.history.go(-1);
  120. };
  121. </script>
  122. <style scoped lang="scss">
  123. .main {
  124. .two {
  125. margin: 0 0 10px 0;
  126. }
  127. }
  128. </style>