view.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <script lang="ts" setup>
  2. import { reactive, ref, unref } from 'vue';
  3. import { useVbenModal } from '@vben/common-ui';
  4. import { Button } from 'ant-design-vue';
  5. import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
  6. import { QueryApi } from '#/api';
  7. defineOptions({
  8. name: 'QueryView',
  9. });
  10. const modelRef = ref<Record<string, any>>({});
  11. const gridOptions = reactive<VxeGridProps<QueryApi.BasicRecordItem>>({
  12. columns: [{ title: '序号', type: 'seq', width: 50 }],
  13. height: 'auto',
  14. keepSource: true,
  15. pagerConfig: { enabled: false },
  16. proxyConfig: {
  17. autoLoad: false,
  18. ajax: {
  19. query: async ({ page }, formValues) => {
  20. return await QueryApi.postExecuteReal({
  21. pageIndex: page.currentPage,
  22. pageSize: page.pageSize,
  23. ...formValues,
  24. id: unref(modelRef).id,
  25. });
  26. },
  27. },
  28. },
  29. });
  30. const [Grid, { reload, setGridOptions }] = useVbenVxeGrid({
  31. gridOptions,
  32. });
  33. const [Modal, { getData, setState }] = useVbenModal({
  34. fullscreenButton: true,
  35. draggable: true,
  36. footer: false,
  37. onOpenChange: async (isOpen: boolean) => {
  38. if (isOpen) {
  39. setState({ loading: true });
  40. const data = getData<Record<string, any>>();
  41. modelRef.value = { ...data.baseData };
  42. const resColumns = await QueryApi.getColumns(data.baseData.id);
  43. const columns = [
  44. { align: 'center', title: '序号', type: 'seq', width: 50 },
  45. ];
  46. resColumns.forEach((column) => {
  47. columns.push({
  48. align: 'left',
  49. field: column.alias,
  50. title: column.remark,
  51. });
  52. });
  53. setGridOptions({
  54. columns,
  55. });
  56. await reload();
  57. setState({ loading: false });
  58. }
  59. },
  60. title: '查看查询',
  61. });
  62. </script>
  63. <template>
  64. <Modal class="h-[750px] w-[1000px]">
  65. <Grid>
  66. <template #toolbar-tools>
  67. <Button class="mr-2" type="primary" @click="reload"> 刷新 </Button>
  68. </template>
  69. </Grid>
  70. </Modal>
  71. </template>