useCommonModbus.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. page: number;
  17. size: number;
  18. total: number;
  19. [key: string]: any;
  20. }
  21. const params = reactive<SearchParams>({
  22. page: 1,
  23. size: 10,
  24. total: 0,
  25. ...expandParams
  26. })
  27. const loading = ref(false)
  28. const tableData = ref<T[] | any[]>([])
  29. const getList = async (page?: number) => {
  30. page && (params.page = page);
  31. tableData.value = [];
  32. loading.value = true;
  33. params.total = 0;
  34. let res = await api(params).finally(() => loading.value = false)
  35. tableData.value = (resKey ? (res[resKey]) : (res)) || [];
  36. params.total = res.Total;
  37. };
  38. return { params, tableData, getList, loading }
  39. }