index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <el-row>
  3. <el-col :span="24" class="main animate__animated animate__backInRight">
  4. <el-col :span="24" class="one">
  5. <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch">
  6. <template #is_use>
  7. <el-option v-for="i in is_useList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  8. </template>
  9. </cSearch>
  10. </el-col>
  11. <el-col :span="24" class="two">
  12. <cButton @toAdd="toAdd"></cButton>
  13. </el-col>
  14. <el-col :span="24" class="thr">
  15. <cTable :fields="fields" :opera="opera" :list="list" :total="total" @query="search" @edit="toEdit" @del="toDel" @menu="toMenu"></cTable>
  16. </el-col>
  17. </el-col>
  18. </el-row>
  19. </template>
  20. <script setup lang="ts">
  21. // 基础
  22. import type { Ref } from 'vue';
  23. import { onMounted, ref, getCurrentInstance } from 'vue';
  24. import router from '@/router';
  25. import { ElMessage } from 'element-plus';
  26. // 接口
  27. import { ModuleStore } from '@common/src/stores/system/module';
  28. import { DictDataStore } from '@common/src/stores/system/dictData';
  29. import type { IQueryResult } from '@/util/types.util';
  30. const moduleAxios = ModuleStore();
  31. const dictAxios = DictDataStore();
  32. const { proxy } = getCurrentInstance() as any;
  33. // 分页数据
  34. const list: Ref<any> = ref([]);
  35. const total: Ref<any> = ref(0);
  36. const skip = 0;
  37. const limit = proxy.$limit;
  38. const fields: Ref<any> = ref([
  39. { label: '模块名称', model: 'name', isSearch: true },
  40. { label: '模块地址', model: 'url' },
  41. { label: '模块简介', model: 'brief' },
  42. { label: '是否使用', model: 'is_use', format: (i) => getDict(i, 'is_use'), type: 'select', isSearch: true }
  43. ]);
  44. const opera: Ref<any> = ref([
  45. { label: '菜单管理', method: 'menu' },
  46. { label: '修改', method: 'edit', type: 'warning' },
  47. { label: '删除', method: 'del', confirm: true, type: 'danger' }
  48. ]);
  49. // 查询
  50. const searchInfo: Ref<any> = ref({});
  51. // 字典表
  52. const is_useList: Ref<any> = ref([]);
  53. // 请求
  54. onMounted(async () => {
  55. await searchOther();
  56. await search({ skip, limit });
  57. });
  58. const search = async (e: { skip: number; limit: number }) => {
  59. const info = { skip: e.skip, limit: e.limit, ...searchInfo.value };
  60. const res: IQueryResult = await moduleAxios.query(info);
  61. if (res.errcode == '0') {
  62. list.value = res.data;
  63. total.value = res.total;
  64. }
  65. };
  66. const toSearch = (e) => {
  67. searchInfo.value = e;
  68. search({ skip, limit });
  69. };
  70. //
  71. const getDict = (e, model) => {
  72. if (model == 'is_use') {
  73. let data = is_useList.value.find((i) => i.value == e);
  74. if (data) return data.label;
  75. else return '暂无';
  76. }
  77. };
  78. // 添加
  79. const toAdd = () => {
  80. router.push({ path: '/system/module/detail' });
  81. };
  82. // 修改
  83. const toEdit = (e) => {
  84. router.push({ path: '/system/module/detail', query: { id: e._id } });
  85. };
  86. // 删除
  87. const toDel = async (e) => {
  88. let res: IQueryResult;
  89. res = await moduleAxios.del(e._id);
  90. if (res.errcode == '0') {
  91. ElMessage({ message: `删除信息成功`, type: 'success' });
  92. search({ skip, limit });
  93. } else {
  94. ElMessage({ message: `${res.errmsg}`, type: 'error' });
  95. }
  96. };
  97. // 菜单管理
  98. const toMenu = (e) => {
  99. router.push({ path: '/system/module/menus', query: { id: e._id } });
  100. };
  101. // 查询其他信息
  102. const searchOther = async () => {
  103. let res: IQueryResult;
  104. // 是否使用
  105. res = await dictAxios.query({ type: 'common_use' });
  106. if (res.errcode == '0') is_useList.value = res.data;
  107. };
  108. </script>
  109. <style scoped lang="scss">
  110. .main {
  111. .two {
  112. margin: 0 0 10px 0;
  113. }
  114. }
  115. </style>