index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 #status>
  8. <el-option v-for="i in statusList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  9. </template>
  10. </cSearch>
  11. </el-col>
  12. <el-col :span="24" class="two">
  13. <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @exam="toExam" @edit="toEdit" @del="toDel"> </cTable>
  14. </el-col>
  15. </el-col>
  16. </el-row>
  17. <cDialog :dialog="dialog" @toClose="toClose">
  18. <template v-slot:info>
  19. <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
  20. <cForm :span="24" :fields="formFields" :form="form" :rules="{}" @save="toSave" label-width="auto">
  21. <template #status>
  22. <el-option v-for="i in statusList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  23. </template>
  24. </cForm>
  25. </el-col>
  26. </template>
  27. </cDialog>
  28. </div>
  29. </template>
  30. <script setup lang="ts">
  31. // 基础
  32. import type { Ref } from 'vue';
  33. import { onMounted, ref, getCurrentInstance } from 'vue';
  34. import { ElMessage } from 'element-plus';
  35. import { useRouter } from 'vue-router';
  36. // 接口
  37. import { AdminStore } from '@/stores/users/admin';
  38. import { RoleStore } from '@/stores/basic/role'; // 角色
  39. import { DictDataStore } from '@/stores/basic/dictData'; // 字典表
  40. import type { IQueryResult } from '@/util/types.util';
  41. const adminAxios = AdminStore();
  42. const dictAxios = DictDataStore();
  43. const roleAxios = RoleStore();
  44. const { proxy } = getCurrentInstance() as any;
  45. // 路由
  46. const router = useRouter();
  47. // 加载中
  48. const loading: Ref<any> = ref(false);
  49. let list: Ref<any> = ref([]);
  50. let total: Ref<number> = ref(0);
  51. let skip = 0;
  52. let limit: number = proxy.$limit;
  53. let fields: Ref<any[]> = ref([
  54. { label: '账号', model: 'account', isSearch: true },
  55. { label: '昵称', model: 'name', isSearch: true },
  56. { label: '手机号', model: 'phone', isSearch: true },
  57. { label: '角色', model: 'role', format: (i: any) => getDict(i, roleList.value, 'role') },
  58. { label: '状态', model: 'status', format: (i: any) => getDict(i, statusList.value, 'status'), type: 'select', isSearch: true }
  59. ]);
  60. // 操作
  61. let opera: Ref<any[]> = ref([
  62. { label: '审核', method: 'exam', type: 'warning', display: (i: any) => i.status == '0' },
  63. { label: '修改', method: 'edit' },
  64. { label: '删除', method: 'del', confirm: true, type: 'danger' }
  65. ]);
  66. // 查询数据
  67. let searchForm: Ref<any> = ref({});
  68. // 字典表
  69. const roleList: Ref<any> = ref([]);
  70. const statusList: Ref<any> = ref([]);
  71. // 弹框
  72. const dialog: Ref<any> = ref({ title: '审核管理', show: false, type: '1' });
  73. const form: Ref<any> = ref({ file: [] });
  74. const formFields: Ref<any> = ref([{ label: '状态', model: 'status', type: 'select' }]);
  75. // 请求
  76. onMounted(async () => {
  77. loading.value = true;
  78. await searchOther();
  79. await search({ skip, limit });
  80. loading.value = false;
  81. });
  82. const search = async (e: { skip: number; limit: number }) => {
  83. const info = { skip: e.skip, limit: e.limit, ...searchForm.value };
  84. const res: IQueryResult = await adminAxios.query(info);
  85. if (res.errcode == '0') {
  86. list.value = res.data;
  87. total.value = res.total;
  88. }
  89. };
  90. const toSearch = (query: any) => {
  91. searchForm.value = query;
  92. search({ skip, limit });
  93. };
  94. const getDict = (e: any, model: any, type: any) => {
  95. if (type == 'role') {
  96. let data: any = model.find((i: any) => i._id == e);
  97. if (data) return data.name;
  98. else return '暂无';
  99. } else if (type == 'status') {
  100. let data: any = model.find((i: any) => i.value == e);
  101. if (data) return data.label;
  102. else return '暂无';
  103. }
  104. };
  105. // 审核
  106. const toExam = async (data: any) => {
  107. let res: IQueryResult = await adminAxios.fetch(data._id);
  108. if (res.errcode == '0') {
  109. form.value = res.data;
  110. dialog.value = { title: '审核管理', show: true, type: '1' };
  111. }
  112. };
  113. // 提交保存
  114. const toSave = async (data: any) => {
  115. let res: IQueryResult = await adminAxios.update(data);
  116. if (res.errcode == '0') {
  117. ElMessage({ message: '信息审核成功', type: 'success' });
  118. toClose();
  119. } else {
  120. ElMessage({ message: `${res.errmsg}`, type: 'error' });
  121. }
  122. };
  123. // 修改
  124. const toEdit = (data: any) => {
  125. router.push({ path: '/admin/detail', query: { id: data._id } });
  126. };
  127. // 删除
  128. const toDel = async (data: any) => {
  129. let res: IQueryResult = await adminAxios.del(data._id);
  130. if (res.errcode == 0) {
  131. ElMessage({ type: `success`, message: `刪除信息成功` });
  132. search({ skip, limit });
  133. }
  134. };
  135. // 关闭弹框
  136. const toClose = () => {
  137. form.value = {};
  138. dialog.value = { show: false };
  139. search({ skip, limit });
  140. };
  141. // 查询其他信息
  142. const searchOther = async () => {
  143. let res: IQueryResult;
  144. // 角色
  145. res = await roleAxios.query({ is_use: '0' });
  146. if (res.errcode == '0') roleList.value = res.data;
  147. // 状态
  148. res = await dictAxios.query({ type: 'exam_status', is_use: '0' });
  149. if (res.errcode == '0') statusList.value = res.data;
  150. };
  151. </script>
  152. <style scoped lang="scss">
  153. .main {
  154. .two {
  155. margin: 0 0 10px 0;
  156. }
  157. }
  158. </style>