ソースを参照

修改客户资料

huangbin 4 年 前
コミット
1e68ae75a4

+ 0 - 5
src/common/setup/contextMenu/interface.ts

@@ -1,5 +0,0 @@
-
-export interface PermisionList {
-    code: string;   // 服务配置权限按钮 对应的 code
-    fn: Function;   // 按钮名称
-}

+ 176 - 0
src/common/setup/table/index.ts

@@ -0,0 +1,176 @@
+import { ModalName } from '@/common/constants/modalName';
+import { ColumnType, getTableHead } from '@/common/methods/table';
+import { TableKey } from '@/common/methods/table/interface';
+import { Column, OperationTabMenu } from '@/services/go/commonService/interface';
+import { sessionStorageUtil } from "@/utils/storage";
+import { inject, onUnmounted, reactive, Ref, ref } from "vue";
+import { MenuType } from "../buttonPermission/interface";
+import { openModal } from "../modal";
+import { BtnClassName, BtnList, TableEventCB } from './interface';
+
+
+/**
+ * 获取动态表头数据
+ * ant-design 表格数据的过滤功能与表头绑定在一起
+ */
+export function getTableColumns() {
+    // 表头数据
+    const columns = ref<ColumnType[]>([]);
+    // 过滤信息
+    const filteredInfo = ref();
+    // 缓存 注册表头回调
+    let cacheColumnCB: Function = (): void => { };
+    // 缓存 动态表头 key
+    let cacheTableKey: keyof TableKey = 'table_pcweb_userinfo';
+    /**
+     * 注册表头
+     * @param tableName 动态表头数据key
+     * @param cb 回调函数,处理添加不同表格过滤,排序等功能
+     */
+    function registerColumn(tableName: keyof TableKey, cb: Function) {
+        cacheTableKey = tableName;
+        cacheColumnCB = cb;
+        const list = getTableHead(tableName);
+        const filtered = filteredInfo.value || {};
+        columns.value.length = 0;
+        list.forEach((e, i) => {
+            const { columnfield, columntitle, aligntype } = e;
+            const item: ColumnType = {
+                key: String(i),
+                dataIndex: columnfield, // 表格数据对应的key
+                title: columntitle,
+                align: aligntype === 1 ? 'center' : aligntype === 2 ? 'left' : 'right',
+                slots: { customRender: columnfield },
+            };
+            cb(e, item, filtered);
+            columns.value.push(item);
+        });
+    }
+    /**
+     * 更新动态表头
+     */
+    function updateColumn() {
+        registerColumn(cacheTableKey, cacheColumnCB)
+    }
+    return { columns, registerColumn, updateColumn, filteredInfo }
+}
+
+/**
+ * 表格事件
+ * @param param TableEventCB
+ * @returns 
+ */
+export function getTableEvent<T>(param: TableEventCB) {
+    // 表格展开行
+    const expandedRowKeys = ref<string[]>([]);
+    // 表格选中的数据
+    const selectedRow = reactive({})
+    function Rowclick(record: T, index: number) {
+        return {
+            onClick: () => {  // 表格点击
+                Object.assign(selectedRow, record)
+                const value = expandedRowKeys.value;
+                expandedRowKeys.value = value.length ? [] : [`${index}`];
+                param.clickCB && param.clickCB()
+            },
+            // onDblclick: () => { // 双击
+            //     console.log('onDblclick');
+            // },
+            onContextmenu: () => {  // 表格右键
+                Object.assign(selectedRow, record)
+                param.contextmenuCB && param.contextmenuCB()
+            },
+        };
+    }
+    return { expandedRowKeys, selectedRow, Rowclick }
+}
+
+/**
+ * 获取class 名
+ * @param val 
+ * @returns 
+ */
+function getClassName(val: string): BtnClassName {
+    let result: BtnClassName = 'btnDeafault'
+    if (val.includes('disable') || val.includes('cancle') || val.includes('delete')) {
+        result = 'btnDanger'
+    } else if (val === '') {
+        result = 'btnDeafault'
+    } else if (val.includes('add')) {
+        result = 'operBtn'
+    } else {
+        result = 'btnPrimary'
+    }
+    return result
+}
+
+/**
+ * 获取表格操作按钮列表
+ * @param menuType 
+ * @param hasDetail 操作按钮是否需要详情按钮(详情按钮服务 不配置)
+ * @returns 
+ */
+export function getBtnList(menuType: keyof MenuType, hasDetail: boolean) {
+    // 获取 数据
+    const permissionData = inject('thirdMenuList') as Ref<OperationTabMenu[]>;
+    const name = 'permissionData'
+    // 存入sessionStorageUtil 是为了处理页面刷新的情况(这个时候重新从服务获取数据,但页面已经先加载了,vue 中的 依赖注入在异步中不能建立通信)
+    const data: OperationTabMenu[] = permissionData.value.length ? permissionData.value : sessionStorageUtil.getItem(name)
+    sessionStorageUtil.setItem(name, data)
+
+    const commonBtn = ref<BtnList[]>([]); // 通用按钮列表,不用选中数据才显示
+    const forDataBtn = ref<BtnList[]>([]); // 针对数据按钮列表,选中某条数据才显示
+
+    const list = data.find((e) => e.code === menuType);
+    if (list && list.children) {
+        list.children.forEach(e => {
+            const { code, type, title } = e;
+            if (type === 2) { // 按钮类型
+                const { openAction } = openModal(code as keyof ModalName);
+                const item = { lable: title, callback: openAction, className: getClassName(code) }
+                const commonName = ['新增'] // 目前通用的按钮只要新增,需要添加其它的时候需要往这里添加
+                if (commonName.includes(title)) { // 
+                    commonBtn.value.push(item)
+                } else {
+                    forDataBtn.value.push(item)
+                }
+            }
+        })
+    } else {
+        console.warn(`menuType: ${menuType}未找到`)
+    }
+    // 详情
+    if (hasDetail) {
+        const { openAction } = openModal('detail')
+        forDataBtn.value.push({ lable: '详情', callback: openAction, className: getClassName('') })
+    }
+
+
+    onUnmounted(() => {
+        sessionStorageUtil.removeItem(name)
+    });
+    return { commonBtn, forDataBtn }
+}
+
+// /**
+//  * 获取表格数据
+//  * @param param 
+//  * @returns 
+//  */
+// export function getTableData<T>(param: TableEventCB) {
+//     // 加载状态
+//     const loading = ref<boolean>(false);
+//     // 表格数据
+//     const tableList = ref<T[]>([]);
+//     // 获取表头数据
+//     const { columns, registerColumn, updateColumn, filteredInfo } = getTableColumns()
+//     // 获取表格事件
+//     const { expandedRowKeys, selectedRow, Rowclick } = getTableEvent<T>(param)
+//     return {
+//         loading, tableList,
+//         columns, registerColumn, updateColumn, filteredInfo,
+//         expandedRowKeys, selectedRow, Rowclick,
+//     }
+// }
+
+export type { Column, ColumnType };

+ 12 - 0
src/common/setup/table/interface.ts

@@ -0,0 +1,12 @@
+export interface TableEventCB {
+    clickCB?: Function; // 单击事件回调函数
+    contextmenuCB?: Function; // 右键事件回调函数
+    dblclick?: Function; // 双击事件回调函数
+}
+
+export type BtnClassName = 'btnDeafault' | 'btnPrimary' | 'btnDanger' | 'operBtn'
+export interface BtnList {
+    lable: string;  // 按钮名字
+    callback: Function;
+    className: BtnClassName    // 按钮 class 名字
+}

+ 29 - 48
src/views/information/custom/list/normal-use/index.vue

@@ -12,7 +12,7 @@
                :expandedRowKeys="expandedRowKeys"
                :customRow="Rowclick"
                rowKey="key"
-               :data-source="customList">
+               :data-source="tableList">
         <!-- 额外的展开行 -->
         <template #expandedRowRender="{  }">
           <BtnList :btnList="forDataBtn" />
@@ -43,16 +43,11 @@ import ModifyCustom from '@/views/information/custom/compoments/modify/index.vue
 import DisableCustom from '@/views/information/custom/compoments/disable/index.vue';
 import AddCustom from '@/views/information/custom/compoments/add/index.vue';
 import { getBtnList } from '@/common/setup/contextMenu/index';
-import { handleTableEvent } from '@/common/setup/event/index';
 import BtnList from '@/common/components/buttonList/index.vue';
-import { getCustomModule } from '@/common/setup/customModule';
-import DeleteCustom from '@/views/information/custom/compoments/delete/index.vue';
-import RecoverCustom from '@/views/information/custom/compoments/recover/index.vue';
-import { Column } from '@/services/go/commonService/interface';
-import { ColumnType } from '@/common/methods/table';
 import { QueryCustomInfoType } from '@/services/go/ermcp/customInfo/interface';
-import { message } from 'ant-design-vue';
-import { QueryCustomInfo } from '@/services/go/ermcp/customInfo';
+import { getTableColumns, getTableEvent } from '@/common/setup/table/index';
+import { queryTableList, getFilterTableCB } from '../setup';
+
 export default defineComponent({
     name: 'custom-normal',
     components: {
@@ -65,53 +60,39 @@ export default defineComponent({
         BtnList,
     },
     setup() {
-        const { columns, customList, filteredInfo, loading, getColumns, getColumnsList, columnsListToUpdate } = getCustomModule<QueryCustomInfoType>();
+        // 表头数据
+        const { columns, registerColumn, updateColumn, filteredInfo } = getTableColumns();
+        // 表格事件
+        const { expandedRowKeys, selectedRow, Rowclick } = getTableEvent<QueryCustomInfoType>({});
+        // 表格操作按钮列表
+        const { commonBtn, forDataBtn } = getBtnList('custom_info_normal', true);
+        // 表格列表数据
+        const { loading, tableList, queryTable } = queryTableList(3);
         initData(() => {
             // 获取列表数据
-            getColumnsList(() => {
-                loading.value = true;
-                customList.value.length = 0;
-                QueryCustomInfo(3)
-                    .then((res) => {
-                        customList.value = res.map((e, i) => {
-                            return { ...e, key: String(i) };
-                        });
-                        loading.value = false;
-                        console.log('查询列表', customList);
-                    })
-                    .catch((err) => {
-                        message.error(err);
-                        loading.value = false;
-                    });
-            });
-            // 注册表头信息
-            getColumns('table_pcweb_userinfo', (e: Column, item: ColumnType, filtered: any) => {
-                // 以下添加过滤数据对应的方法
-                if (e.columntitle === '客户类型') {
-                    item.onFilter = (value: string, record: QueryCustomInfoType) => record.userinfotype.includes(String(value));
-                    item.filteredValue = filtered.userinfotype || null;
-                }
-                if (e.columntitle === '客户简称') {
-                    item.onFilter = (value: string, record: QueryCustomInfoType) => record.nickname.includes(value);
-                    item.filteredValue = filtered.nickname || null;
-                }
-                if (e.columntitle === '客户名称') {
-                    item.onFilter = (value: string, record: QueryCustomInfoType) => record.contactname.includes(value);
-                    item.filteredValue = filtered.contactname || null;
-                }
-                if (e.columntitle === '手机号码') {
-                    item.onFilter = (value: string, record: QueryCustomInfoType) => record.mobile.includes(value);
-                    item.filteredValue = filtered.mobile || null;
-                }
-            });
+            queryTable();
+            // 注册表头信息 过滤
+            registerColumn('table_pcweb_userinfo', getFilterTableCB);
         });
         // 查询
         function search(value: any) {
+            debugger;
             filteredInfo.value = value;
             // 更新表信息
-            columnsListToUpdate();
+            updateColumn();
         }
-        return { customList, columns, search, loading, ...getBtnList('custom_info_normal', true), ...handleTableEvent() };
+        return {
+            columns,
+            filteredInfo,
+            expandedRowKeys,
+            selectedRow,
+            Rowclick,
+            commonBtn,
+            forDataBtn,
+            loading,
+            tableList,
+            search,
+        };
     },
 });
 </script>

+ 61 - 0
src/views/information/custom/list/setup.ts

@@ -0,0 +1,61 @@
+import { Column, ColumnType } from '@/common/setup/table/index';
+import { QueryCustomInfo } from '@/services/go/ermcp/customInfo';
+import { QueryCustomInfoType } from '@/services/go/ermcp/customInfo/interface';
+import { QueryCustomInfoEnum } from '@/services/go/ermcp/customInfo/type';
+import { message } from 'ant-design-vue';
+import { ref } from 'vue';
+
+/**
+ * 获取表格列表数据
+ * @param type 
+ * @returns 
+ */
+export function queryTableList(type: QueryCustomInfoEnum) {
+    // 加载状态
+    const loading = ref<boolean>(false);
+    // 表格数据
+    const tableList = ref<QueryCustomInfoType[]>([]);
+    function queryTable() {
+        QueryCustomInfo(type)
+            .then((res) => {
+                tableList.value = res.map((e, i) => {
+                    return { ...e, key: String(i) };
+                });
+                loading.value = false;
+                console.log('查询列表', tableList);
+            })
+            .catch((err) => {
+                message.error(err);
+                loading.value = false;
+            });
+    }
+    return { loading, tableList, queryTable }
+}
+
+/**
+ * 过滤表格的回调函数
+ * @param e 
+ * @param item 
+ * @param filtered 
+ */
+export function getFilterTableCB(e: Column, item: ColumnType, filtered: any) {
+    // 以下添加过滤数据对应的方法
+    if (e.columntitle === '客户类型') {
+        item.onFilter = (value: string, record: QueryCustomInfoType) => record.userinfotype.includes(String(value));
+        item.filteredValue = filtered.userinfotype || null;
+    }
+    if (e.columntitle === '客户简称') {
+        debugger;
+        item.onFilter = (value: string, record: QueryCustomInfoType) => record.nickname.includes(value);
+        item.filteredValue = filtered.nickname || null;
+    }
+    if (e.columntitle === '客户名称') {
+        item.onFilter = (value: string, record: QueryCustomInfoType) => record.contactname.includes(value);
+        item.filteredValue = filtered.contactname || null;
+    }
+    if (e.columntitle === '手机号码') {
+        item.onFilter = (value: string, record: QueryCustomInfoType) => record.mobile.includes(value);
+        item.filteredValue = filtered.mobile || null;
+    }
+}
+

+ 96 - 105
src/views/information/custom/list/stop-use/index.vue

@@ -1,113 +1,104 @@
 <template>
-    <!-- 客户信息: 停用 -->
-    <div class="custom-normal" :loading="loading">
-        <filterCustomTable @search="search">
-            <BtnList :btnList="commonBtn" />
-        </filterCustomTable>
-        <contextMenu :contextMenuList="forDataBtn">
-            <a-table :columns="columns" class="topTable" :expandedRowKeys="expandedRowKeys" :customRow="Rowclick" :pagination="false" rowKey="key" :data-source="customList">
-                <!-- 额外的展开行 -->
-                <template #expandedRowRender="{  }">
-                    <BtnList :btnList="forDataBtn" />
-                </template>
-                <template #userinfotype="{ text }">
-                    <a>{{ text === '2' ? '企业' : '个人' }}</a>
-                </template>
-            </a-table>
-        </contextMenu>
-        <!-- 新增 -->
-        <AddCustom />
-        <!-- 详情 -->
-        <CustomDetail />
-        <!-- 删除 -->
-        <DeleteCustom />
-        <!-- 恢复客户资料 -->
-        <RecoverCustom />
-    </div>
+  <!-- 客户信息: 停用 -->
+  <div class="custom-normal"
+       :loading="loading">
+    <filterCustomTable @search="search">
+      <BtnList :btnList="commonBtn" />
+    </filterCustomTable>
+    <contextMenu :contextMenuList="forDataBtn">
+      <a-table :columns="columns"
+               class="topTable"
+               :expandedRowKeys="expandedRowKeys"
+               :customRow="Rowclick"
+               :pagination="false"
+               rowKey="key"
+               :data-source="customList">
+        <!-- 额外的展开行 -->
+        <template #expandedRowRender="{  }">
+          <BtnList :btnList="forDataBtn" />
+        </template>
+        <template #userinfotype="{ text }">
+          <a>{{ text === '2' ? '企业' : '个人' }}</a>
+        </template>
+      </a-table>
+    </contextMenu>
+    <!-- 新增 -->
+    <AddCustom />
+    <!-- 详情 -->
+    <CustomDetail />
+    <!-- 删除 -->
+    <DeleteCustom />
+    <!-- 恢复客户资料 -->
+    <RecoverCustom />
+  </div>
 </template>
 
 <script lang="ts">
-    import { defineComponent, Ref } from 'vue';
-    import { initData } from '@/common/methods/index';
-    import filterCustomTable from '@/views/information/custom/compoments/filterTable/index.vue';
-    import contextMenu from '@/common/components/contextMenu/index.vue';
-    import { getCustomModule } from '@/common/setup/customModule';
-    import CustomDetail from '@/views/information/custom/compoments/detail/index.vue';
-    import DeleteCustom from '@/views/information/custom/compoments/delete/index.vue';
-    import RecoverCustom from '@/views/information/custom/compoments/recover/index.vue';
-    import AddCustom from '@/views/information/custom/compoments/add/index.vue';
-    import { getBtnList } from '@/common/setup/contextMenu/index';
-    import { handleTableEvent } from '@/common/setup/event/index';
-    import BtnList from '@/common/components/buttonList/index.vue';
-    import { Column } from '@/services/go/commonService/interface';
-    import { ColumnType } from '@/common/methods/table';
-    import { QueryCustomInfoType } from '@/services/go/ermcp/customInfo/interface';
-    import { message } from 'ant-design-vue';
-    import { QueryCustomInfo } from '@/services/go/ermcp/customInfo';
-    export default defineComponent({
-        name: 'custom-normal',
-        components: {
-            filterCustomTable,
-            contextMenu,
-            CustomDetail,
-            DeleteCustom,
-            RecoverCustom,
-            AddCustom,
-            BtnList,
-        },
-        setup() {
-            const { columns, customList, filteredInfo, loading, getColumns, getColumnsList, columnsListToUpdate } = getCustomModule<QueryCustomInfoType>();
-            initData(() => {
-                // 获取列表数据
-                getColumnsList(() => {
-                    loading.value = true;
-                    customList.value.length = 0;
-                    QueryCustomInfo(4)
-                        .then((res) => {
-                            customList.value = res.map((e, i) => {
-                                return { ...e, key: String(i) };
-                            });
-                            loading.value = false;
-                            console.log('查询列表', customList);
-                        })
-                        .catch((err) => {
-                            message.error(err);
-                            loading.value = false;
-                        });
-                });
-                // 注册表头信息
-                getColumns('table_pcweb_userinfo', (e: Column, item: ColumnType, filtered: any) => {
-                    // 以下添加过滤数据对应的方法
-                    if (e.columntitle === '客户类型') {
-                        item.onFilter = (value: string, record: QueryCustomInfoType) => record.userinfotype.includes(String(value));
-                        item.filteredValue = filtered.userinfotype || null;
-                    }
-                    if (e.columntitle === '客户简称') {
-                        item.onFilter = (value: string, record: QueryCustomInfoType) => record.nickname.includes(value);
-                        item.filteredValue = filtered.nickname || null;
-                    }
-                    if (e.columntitle === '客户名称') {
-                        item.onFilter = (value: string, record: QueryCustomInfoType) => record.contactname.includes(value);
-                        item.filteredValue = filtered.contactname || null;
-                    }
-                    if (e.columntitle === '手机号码') {
-                        item.onFilter = (value: string, record: QueryCustomInfoType) => record.mobile.includes(value);
-                        item.filteredValue = filtered.mobile || null;
-                    }
-                });
-            });
-            // 查询
-            function search(value: any) {
-                filteredInfo.value = value;
-                // 更新表信息
-                columnsListToUpdate();
-            }
-            return { customList, columns, search, loading, ...getBtnList('custom_info_disabled', true), ...handleTableEvent() };
-        },
-    });
+import { defineComponent } from 'vue';
+import { initData } from '@/common/methods/index';
+import filterCustomTable from '@/views/information/custom/compoments/filterTable/index.vue';
+import contextMenu from '@/common/components/contextMenu/index.vue';
+import CustomDetail from '@/views/information/custom/compoments/detail/index.vue';
+import DeleteCustom from '@/views/information/custom/compoments/delete/index.vue';
+import RecoverCustom from '@/views/information/custom/compoments/recover/index.vue';
+import AddCustom from '@/views/information/custom/compoments/add/index.vue';
+import { getBtnList } from '@/common/setup/contextMenu/index';
+import BtnList from '@/common/components/buttonList/index.vue';
+import { QueryCustomInfoType } from '@/services/go/ermcp/customInfo/interface';
+import { getTableColumns, getTableEvent } from '@/common/setup/table/index';
+import { queryTableList, getFilterTableCB } from '../setup';
+
+export default defineComponent({
+    name: 'custom-normal',
+    components: {
+        filterCustomTable,
+        contextMenu,
+        CustomDetail,
+        DeleteCustom,
+        RecoverCustom,
+        AddCustom,
+        BtnList,
+    },
+    setup() {
+        // 表头数据
+        const { columns, registerColumn, updateColumn, filteredInfo } = getTableColumns();
+        // 表格事件
+        const { expandedRowKeys, selectedRow, Rowclick } = getTableEvent<QueryCustomInfoType>({});
+        // 表格操作按钮列表
+        const { commonBtn, forDataBtn } = getBtnList('custom_info_disabled', true);
+        // 表格列表数据
+        const { loading, tableList, queryTable } = queryTableList(3);
+        initData(() => {
+            // 获取列表数据
+            queryTable();
+            // 注册表头信息 过滤
+            registerColumn('table_pcweb_userinfo', getFilterTableCB);
+        });
+        // 查询
+        function search(value: any) {
+            debugger;
+            filteredInfo.value = value;
+            // 更新表信息
+            updateColumn();
+        }
+        return {
+            columns,
+            filteredInfo,
+            expandedRowKeys,
+            selectedRow,
+            Rowclick,
+            commonBtn,
+            forDataBtn,
+            loading,
+            tableList,
+            search,
+        };
+    },
+});
 </script>
 
 <style lang="less">
-    .custom-normal {
-    }</style
+.custom-normal {
+}
+</style
 >;