index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch">
  7. <template #type>
  8. <el-option v-for="(i, index) in typeList" :key="index" :label="i.label" :value="i.value"></el-option>
  9. </template>
  10. <template #is_use>
  11. <el-option v-for="(i, index) in is_useList" :key="index" :label="i.label" :value="i.value"></el-option>
  12. </template>
  13. </cSearch>
  14. </el-col>
  15. <el-col :span="24" class="two">
  16. <cButton @toAdd="toAdd()"></cButton>
  17. </el-col>
  18. <el-col :span="24" class="thr">
  19. <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @edit="toEdit" @del="toDel"> </cTable>
  20. </el-col>
  21. </el-col>
  22. </el-row>
  23. </div>
  24. </template>
  25. <script setup lang="ts">
  26. // 基础
  27. import type { Ref } from 'vue';
  28. import { onMounted, ref, getCurrentInstance } from 'vue';
  29. import { useRouter } from 'vue-router';
  30. import { ElMessage } from 'element-plus';
  31. // 接口
  32. import { QuestionStore } from '@common/src/stores/question/question'; //
  33. import { DictDataStore } from '@common/src/stores/system/dictData'; // 字典表
  34. import type { IQueryResult } from '@/util/types.util';
  35. const qquesAxios = QuestionStore();
  36. const dictAxios = DictDataStore();
  37. const { proxy } = getCurrentInstance() as any;
  38. // 路由
  39. const router = useRouter();
  40. // 加载中
  41. const loading: Ref<any> = ref(false);
  42. const list: Ref<any> = ref([]);
  43. const total: Ref<any> = ref(0);
  44. const skip = 0;
  45. const limit = proxy.limit;
  46. const fields: Ref<any[]> = ref([
  47. { label: '标题', model: 'title', isSearch: true },
  48. { label: '类型', model: 'type', isSearch: true, format: (i) => getDict(i, 'type'), type: 'select' },
  49. { label: '是否启用', model: 'is_use', isSearch: true, format: (i) => getDict(i, 'is_use'), type: 'select' }
  50. ]);
  51. const opera: Ref<any[]> = ref([
  52. { label: '修改', method: 'edit' },
  53. { label: '删除', method: 'del', confirm: true, type: 'danger' }
  54. ]);
  55. // 查询
  56. const searchInfo: Ref<any> = ref({});
  57. // 字典表
  58. const typeList: Ref<any> = ref([]);
  59. const is_useList: Ref<any> = ref([]);
  60. // 请求
  61. onMounted(async () => {
  62. loading.value = true;
  63. await searchOther();
  64. await search({ skip, limit });
  65. loading.value = false;
  66. });
  67. const search = async (e: { skip: number; limit: number }) => {
  68. const info = { skip: e.skip, limit: e.limit, ...searchInfo.value };
  69. const res: IQueryResult = await qquesAxios.query(info);
  70. if (res.errcode == '0') {
  71. list.value = res.data;
  72. total.value = res.total;
  73. }
  74. };
  75. const toSearch = (query) => {
  76. searchInfo.value = query;
  77. search({ skip, limit });
  78. };
  79. const getDict = (e, model) => {
  80. if (model == 'type') {
  81. let data: any = typeList.value.find((i: any) => i.value == e);
  82. if (data) return data.label;
  83. else return '暂无';
  84. } else if (model == 'is_use') {
  85. let data: any = is_useList.value.find((i: any) => i.value == e);
  86. if (data) return data.label;
  87. else return '暂无';
  88. }
  89. };
  90. // 新增
  91. const toAdd = () => {
  92. router.push({ path: '/question/detail' });
  93. };
  94. // 修改
  95. const toEdit = async (data) => {
  96. router.push({ path: '/question/detail', query: { id: data._id } });
  97. };
  98. // 删除
  99. const toDel = async (data) => {
  100. let res: IQueryResult = await qquesAxios.del(data._id);
  101. if (res.errcode == 0) {
  102. ElMessage({ type: `success`, message: `刪除信息成功` });
  103. search({ skip, limit });
  104. }
  105. };
  106. const searchOther = async () => {
  107. let res: IQueryResult;
  108. // 类型
  109. res = await dictAxios.query({ type: 'wenjuan-question-type' });
  110. if (res.errcode == '0') {
  111. typeList.value = res.data;
  112. }
  113. // 是否启用
  114. res = await dictAxios.query({ type: 'common_use' });
  115. if (res.errcode == '0') {
  116. is_useList.value = res.data;
  117. }
  118. };
  119. </script>
  120. <style scoped lang="scss">
  121. .main {
  122. .two {
  123. margin: 0 0 10px 0;
  124. }
  125. }
  126. </style>