useCommon.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { reactive, ref } from 'vue'
  2. export default function () {
  3. const statusParams = reactive({
  4. status: 1
  5. })
  6. return { statusParams }
  7. }
  8. export function useSearch<T>(api: any, resKey: string, expandParams?: any) {
  9. // <pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
  10. // import api from '/@/api/system';
  11. // import { ApiRow } from '/@/api/model/system/menu';
  12. // import { useSearch } from '/@/hooks/useCommon';
  13. // const { params, tableData, getList } = useSearch<ApiRow[]>(api.api.getList, 'Info', { name: '', address: '' });
  14. // getList() // 获取列表数据
  15. interface SearchParams {
  16. status: -1 | 0 | 1,
  17. pageNum: number;
  18. pageSize: number;
  19. total: number;
  20. [key: string]: any;
  21. }
  22. const params = reactive<SearchParams>({
  23. status: -1,
  24. pageNum: 1,
  25. pageSize: 10,
  26. total: 0,
  27. ...expandParams
  28. })
  29. const loading = ref(false)
  30. const tableData = ref<T[] | any[]>([])
  31. const getList = async (pageNum?: number) => {
  32. pageNum && (params.pageNum = pageNum);
  33. tableData.value = [];
  34. loading.value = true;
  35. params.total = 0;
  36. let res = await api(params).finally(() => loading.value = false)
  37. console.log(res)
  38. tableData.value = (resKey ? (res[resKey]) : (res)) || [];
  39. params.total = res.total;
  40. };
  41. return { params, tableData, getList, loading }
  42. }