Browse Source

fix: 修改BsUi基础组件

hanxiaohui 5 months ago
parent
commit
a62691a24d

+ 9 - 0
src/api/system/table-api.js

@@ -0,0 +1,9 @@
+import { request } from '/@/lib/axios.js';
+
+export const getTableDataApi = (url, data) => {
+  return request({
+    url: 'url',
+    method: 'post',
+    data,
+  });
+};

+ 3 - 2
src/components/BsUi/Form/Form.vue

@@ -7,8 +7,8 @@
         </a-col>
         <a-col :span="24" v-for="(item, idx) in newFormTemp[key]">
           <a-row>
-            <a-col :span="24" v-if="item.visible === true">
-              <a-form-item :label="item.label" :name="item.field" :required="item.required === true" v-bind="item.formItemExtraProps">
+            <a-col :span="24" v-if="item.visible === DISPLAY_STATE.VISIBLE">
+              <a-form-item :label="item.label" :name="item.field" :required="item.required === REQUIRED_STATE.REQUIRED" v-bind="item.formItemExtraProps">
                 <component
                   :is="item.component"
                   v-model:value="props.formData[item.field]"
@@ -48,6 +48,7 @@
   import { computed, ref, useSlots } from 'vue';
   import RenderVNode from '/@/components/BsUi/RenderVNode/index.js';
   import { groupBy, mapValues, sortBy } from 'lodash';
+  import { DISPLAY_STATE, REQUIRED_STATE } from '/@/components/BsUi/constant.js'
 
   const formRef = ref(null);
   const confirmLoading = ref(false);

+ 10 - 0
src/components/BsUi/Render/cell.jsx

@@ -41,3 +41,13 @@ VxeUI.renderer.add('CellDateTime', {
       return <>{ dayjs(getValue(params)).format('YYYY-MM-DD HH:mm:ss') }</>
   },
 });
+
+
+// 字典渲染
+VxeUI.renderer.add('CellDict', {
+  // 默认显示模板
+  renderTableDefault(renderOpts, params) {
+    if (isEmpty(getValue(params))) return <></>;
+    return <>{ getValue(params)[0].valueName || '' }</>
+  },
+});

+ 3 - 36
src/components/BsUi/Table/Table.vue

@@ -83,45 +83,12 @@
 
   const isZoom = ref(false);
 
-  const handleReset = () => {
-    props.searchConfig.data = {};
-    props?.searchConfig &&
-      props?.searchConfig.onReset({
-        searchParams: {
-          ...props.searchConfig.data,
-        },
-        pageInfo: {
-          pageSize: props.pagerConfig?.pageSize,
-          pageNum: props.pagerConfig?.pageNum,
-        },
-      });
-  };
-
-  const handleSearch = () => {
-    props?.searchConfig &&
-      props?.searchConfig.onSearch({
-        searchParams: {
-          ...props.searchConfig.data,
-        },
-        pageInfo: {
-          pageSize: props.pagerConfig?.pageSize,
-          pageNum: props.pagerConfig?.pageNum,
-        },
-      });
-  };
+  const handleReset = () => {};
 
+  const handleSearch = () => {};
   // 刷新回调
   const handleRefresh = () => {
-    props?.toolbarConfig &&
-      props.toolbarConfig.onRefresh({
-        searchParams: {
-          ...props.searchConfig.data,
-        },
-        pageInfo: {
-          pageSize: props.pagerConfig?.pageSize,
-          pageNum: props.pagerConfig?.pageNum,
-        },
-      });
+    props.toolbarConfig.onRefresh && props.toolbarConfig.onRefresh();
   };
 
   onMounted(() => {

+ 39 - 9
src/components/BsUi/Table/index.js

@@ -1,6 +1,7 @@
 import BsTable from './Table.vue';
 import { reactive, onMounted, onBeforeMount, toRaw } from 'vue';
 import { set, get, isEmpty, isUndefined } from 'lodash';
+import { getTableDataApi } from '/@/api/system/table-api.js';
 
 export const useBsTable = (options, tableRef) => {
   let tableOptions = reactive(options.tableOptions);
@@ -39,6 +40,17 @@ export const useBsTable = (options, tableRef) => {
     });
 
     set(tableOptions, 'searchConfig.fields', newFields);
+
+    set(tableOptions, 'searchConfig.onSearch',  async () => {
+      setPageNum(1);
+      await getTableData();
+    });
+
+    set(tableOptions, 'searchConfig.onReset',  async () => {
+      setSearchParams({});
+      setPageNum(1);
+      await getTableData();
+    });
   };
 
   const toggleSearchFields = () => {
@@ -92,7 +104,7 @@ export const useBsTable = (options, tableRef) => {
   const getTableData = () => {
     options.tableSearchBeforeBiz && options.tableSearchBeforeBiz();
     setLoading(true);
-    return new Promise((resolve, reject) => {
+    return new Promise(async (resolve, reject) => {
       const pageNum = tableOptions?.pagerConfig.pageNum;
       const pageSize = tableOptions?.pagerConfig.pageSize;
       const searchParams = getSearchParams();
@@ -105,15 +117,22 @@ export const useBsTable = (options, tableRef) => {
           resolve(tableOptions.gridOptions.data);
         }, 500);
       } else {
-        // const resData = await getTableData(searchParams, {pageNum, pageSize});
-        // resolve(resData);
 
-        setTimeout(() => {
-          setLoading(false);
-          setTableData(data);
-          setPageTotal(1000);
-          resolve();
-        }, 1000);
+        console.log("入参为 =====>", { pageNum, pageSize, ...searchParams })
+        const resData = await getTableDataApi(tableOptions?.url,{ pageNum, pageSize, ...searchParams });
+        const { data } = resData;
+        setLoading(false);
+        setTableData(data.list);
+        setPageTotal(data.total);
+        resolve(data);
+
+        // setTimeout(() => {
+        //   setLoading(false);
+        //   setTableData([{name: "12334"}]);
+        //   setPageTotal(1000);
+        //   resolve();
+        // }, 1000);
+
       }
     });
   };
@@ -129,6 +148,10 @@ export const useBsTable = (options, tableRef) => {
   const initPageEvent = () => {
     const visible = get(tableOptions, 'pagerConfig.enable', true);
     setPagerVisible(visible);
+
+    set(tableOptions, 'pagerConfig.onChange',  async () => {
+      await getTableData();
+    });
   };
 
   const initSearchConfig = () => {
@@ -146,6 +169,12 @@ export const useBsTable = (options, tableRef) => {
   const initToolbarConfig = () => {
     const visible = get(tableOptions, 'toolbarConfig.enable', true);
     setToolBarVisible(visible);
+
+    set(tableOptions, 'toolbarConfig.onRefresh',  async () => {
+      setPageNum(1);
+      await getTableData();
+    });
+
   };
 
   const onTableBeforeMount = (callback) => {
@@ -173,6 +202,7 @@ export const useBsTable = (options, tableRef) => {
     initSearchConfig();
     onTableBeforeMount();
     options.beforeMount && options.beforeMount();
+    await getTableData();
     onTableMounted();
     options.mounted && options.mounted();
   });

+ 10 - 0
src/components/BsUi/constant.js

@@ -2,3 +2,13 @@ export const SELECT_MULTIPLE = Object.freeze({
   ONE: '0',
   MORE: '1',
 });
+
+export const DISPLAY_STATE = Object.freeze({
+  VISIBLE: '1',
+  HIDDEN: '0',
+});
+
+export const REQUIRED_STATE = Object.freeze({
+  REQUIRED: '1',
+  NO_REQUIRED: '0',
+});