From bc56062cebc1fcab0cadc1580600365e97d2fbbe Mon Sep 17 00:00:00 2001 From: lijingjia Date: Fri, 12 Jul 2024 12:48:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Form/src/components/AdvancedSearch.vue | 246 ++++++++++------- .../Form/src/components/FormAction.vue | 13 +- src/components/Form/src/props.ts | 2 +- src/components/Table/src/BasicTable.vue | 3 +- .../Table/src/hooks/useDataSource.ts | 38 +++ src/hooks/web/common.ts | 68 ++++- src/views/operation/seaexport/index.vue | 248 ++---------------- 7 files changed, 291 insertions(+), 327 deletions(-) diff --git a/src/components/Form/src/components/AdvancedSearch.vue b/src/components/Form/src/components/AdvancedSearch.vue index 08453759..9b51dc19 100644 --- a/src/components/Form/src/components/AdvancedSearch.vue +++ b/src/components/Form/src/components/AdvancedSearch.vue @@ -6,75 +6,85 @@ \ No newline at end of file diff --git a/src/components/Form/src/components/FormAction.vue b/src/components/Form/src/components/FormAction.vue index c2c17fb5..1f72fb2e 100644 --- a/src/components/Form/src/components/FormAction.vue +++ b/src/components/Form/src/components/FormAction.vue @@ -60,7 +60,7 @@ @@ -94,6 +94,10 @@ useAdvancedSearch: propTypes.bool.def(false), // 多单号查询 useNumbersSearch: propTypes.bool.def(false), + // 高级查询更新参数使用 + fetch: { + type: Function + }, showSubmitButton: propTypes.bool.def(true), showAdvancedButton: propTypes.bool.def(true), resetButtonOptions: { @@ -108,6 +112,11 @@ type: Object as PropType>, default: () => ({}), }, + // 传进来的表格操作的方法集合 + tableAction: { + type: Object, + default: () => ({}), + }, actionSpan: propTypes.number.def(6), isAdvanced: propTypes.bool, hideAdvanceBtn: propTypes.bool, @@ -145,7 +154,7 @@ }) // 执行高级查询 const toSearch = (params) => { - console.log(params) + props.fetch({ advanced : params }) } const getSubmitBtnOptions = computed(() => { return Object.assign( diff --git a/src/components/Form/src/props.ts b/src/components/Form/src/props.ts index fb2664f9..3bccb10f 100644 --- a/src/components/Form/src/props.ts +++ b/src/components/Form/src/props.ts @@ -84,7 +84,7 @@ export const basicProps = { // 自定义重置函数 resetFunc: Function as PropType<() => Promise>, submitFunc: Function as PropType<() => Promise>, - + fetch: Function as PropType<() => Promise>, // 以下为默认props hideRequiredMark: propTypes.bool, diff --git a/src/components/Table/src/BasicTable.vue b/src/components/Table/src/BasicTable.vue index 720c03da..0028527a 100644 --- a/src/components/Table/src/BasicTable.vue +++ b/src/components/Table/src/BasicTable.vue @@ -6,6 +6,7 @@ ref="formRef" submit-on-reset v-bind="getFormProps" + :fetch="fetch" :table-action="tableAction" :autoSubmitOnEnter="true" @register="registerForm" @@ -233,7 +234,6 @@ const { getFormProps, replaceFormSlotKey, getFormSlotKeys, handleSearchInfoChange } = useTableForm(getProps, slots, fetch, getLoading) - console.log(getFormProps) const getBindValues = computed(() => { const dataSource = unref(getDataSourceRef) let propsData: Recordable = { @@ -340,6 +340,7 @@ wrapRef, tableAction, redoHeight, + fetch, getFormProps: getFormProps as any, replaceFormSlotKey, getFormSlotKeys, diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index 51e65016..648c30d0 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -297,6 +297,44 @@ export function useDataSource( opt?.sortInfo ?? {}, opt?.filterInfo ?? {}, ) + // 如果是高级查询,塞入高级查询参数 + if (opt && opt.advanced) { + const ap = { + Key: opt?.advanced?.logicalOperator, + Value: { + ConditionalList: [] + } + } + // 配置高级查询参数固定格式 + opt.advanced?.conditions.forEach(item => { + let obj = { + Key: '', + Value: null + } + obj['Key'] = item.logicalOperator + if (item?.conditions) { + item.conditions.forEach(row => { + // 只有当查询条件字段和筛选符都有值的时候才行(不然后台报错) + if (row.field && row.value) { + obj.Value = { + FieldName: row.field, + FieldValue: row.value, + ConditionalType: row.operator + } + } + }) + } + if (obj.Value != null) { + ap.Value.ConditionalList.push(obj) + } + }) + if (ap.Value.ConditionalList.length) { + params['advancedSearchParams'] = { ConditionalList: [ap] } + } else { + // ConditionalList没有值还不能传空数组。。。 + params['advancedSearchParams'] = { ConditionalList: [] } + } + } if (beforeFetch && isFunction(beforeFetch)) { params = (await beforeFetch(params)) || params } diff --git a/src/hooks/web/common.ts b/src/hooks/web/common.ts index f9426801..05e99357 100644 --- a/src/hooks/web/common.ts +++ b/src/hooks/web/common.ts @@ -27,7 +27,6 @@ export function closePage(topath) { } else { // 父级路由 const parent = router?.options?.history?.state?.back - console.log(router) // 如果存在父级路由,直接返回父级 if (parent) { router.push(parent) @@ -119,3 +118,70 @@ function toBlob(fileData, name) { document.body.removeChild(a) }, 0) } + +// 返回表格查询的参数 +export function formatParams(params = {}) { + const postData = { + queryCondition: '', + pageCondition: { + pageIndex: params?.page, + pageSize: params?.pageSize, + sortConditions: [] + } + } + const conditions = [] + for (let key in params) { + if (key != 'page' && key != 'pageSize' && key != 'order' && key != 'field') { + if (key == 'advancedSearchParams') { + // 高级查询 + conditions.push(params[key]) + } else { + // 其他查询 + if (Array.isArray(params[key])) { + if (params[key][0].length && params[key][0].length > 3) { + // 判定成日期 + conditions.push({ + FieldName: key, + FieldValue: params[key][0], + ConditionalType: 3 + }) + conditions.push({ + FieldName: key, + FieldValue: params[key][1], + ConditionalType: 5 + }) + } else { + // 判定为筛选 + params[key].forEach(item => { + conditions.push({ + FieldName: key, + FieldValue: item, + ConditionalType: 1 + }) + }) + } + } else { + // 其他普通查询 + if (params[key] || params[key] === 0) { + conditions.push({ + FieldName: key, + FieldValue: params[key], + ConditionalType: 1 + }) + } + } + } + } + } + // 排序 + if (params?.field) { + postData.pageCondition.sortConditions = [{ + sortField: params.field, + listSortDirection: params.order == "ascend" ? 0 : 1 + }] + } else { + postData.pageCondition.sortConditions = [] + } + postData.queryCondition = JSON.stringify(conditions) + return postData +} \ No newline at end of file diff --git a/src/views/operation/seaexport/index.vue b/src/views/operation/seaexport/index.vue index ae6941aa..b17b7561 100644 --- a/src/views/operation/seaexport/index.vue +++ b/src/views/operation/seaexport/index.vue @@ -82,20 +82,6 @@ - - -
- -
-
import TableActionBar from './components/tableActionBar.vue' import tableActionBarRight from './components/tableActionBarRight.vue' - import ConditionFilter from '/@/components/Condition/index.vue' import { onMounted, ref } from 'vue' import { BasicTable, useTable, TableAction } from '/@/components/Table' - import { PageDataByBooking, UpdateUserQuerySet, GetUserQuerySet } from './api/BookingLedger.js' + import { PageDataByBooking, } from './api/BookingLedger.js' import { getColumnsByClient } from '/@/views/baseinfo/formcopy/api' import { useModal } from '/@/components/Modal' import { columns, searchFormSchema, FeeStatus } from './columns' import { useGo } from '/@/hooks/web/usePage' import { useMessage } from '/@/hooks/web/useMessage' import { formatTableData } from '/@/hooks/web/common' - import { FilterRules } from '/@/components/Condition/index' import { Field } from '/@/components/Render/interface' import { useOptionsStore } from '/@/store/modules/options' const optionsStore = useOptionsStore() @@ -197,8 +181,10 @@ import { useI18n } from '/@/hooks/web/useI18n' const { t } = useI18n() import initData from './modules/initData.js' - import { useRouter, useRoute } from 'vue-router' + import { useRouter } from 'vue-router' import { useAppStore } from '/@/store/modules/app' + // 引入处理入参方法 + import { formatParams } from '/@/hooks/web/common' const appStore = useAppStore() const router = useRouter() const { notification } = useMessage() @@ -326,142 +312,21 @@ }) }, beforeFetch: (p) => { - console.log(p) - var data = getForm().getFieldsValue() - const postParam: API.PageRequest = { - queryCondition: '', - pageCondition: { - pageIndex: p.current, - pageSize: p.pageSize, - sortConditions: [] - } - } - if (p.field) { - postParam.sortConditions = [ - { - sortField: p.field, - listSortDirection: p.order == "ascend" ? 0 : 1 - } - ] - } else { - postParam.sortConditions = [] - } - let condition: API.ConditionItem[] = [] - if (!!data.mblno) { - condition.push({ - FieldName: 'mblno', - FieldValue: data.mblno, - ConditionalType: 1 - }) - } - if (!!data.hblno) { - condition.push({ - FieldName: 'hblno', - FieldValue: data.hblno, - ConditionalType: 1 - }) - } - if (!!data.customerId) { - condition.push({ - FieldName: 'customerId', - FieldValue: data.customerId, - ConditionalType: 1 - }) - } - if (!!data.etd) { - condition.push({ - FieldName: 'etd', - FieldValue: data.etd[0], - ConditionalType: 3 - }) - condition.push({ - FieldName: 'etd', - FieldValue: data.etd[1], - ConditionalType: 5 - }) - } - if (!!data.operatorId) { - condition.push({ - FieldName: 'operatorId', - FieldValue: data.operatorId, - ConditionalType: 1 - }) - } - if (!!data.saleId) { - condition.push({ - FieldName: 'saleId', - FieldValue: data.saleId, - ConditionalType: 1 - }) - } - if (!!data.vesselId) { - condition.push({ - FieldName: 'vesselId', - FieldValue: data.vesselId, - ConditionalType: 1 - }) - } - if (!!data.voyno) { - condition.push({ - FieldName: 'voyno', - FieldValue: data.voyno, - ConditionalType: 1 - }) - } - if (!!data.dischargePortId) { - condition.push({ - FieldName: 'dischargePortId', - FieldValue: data.dischargePortId, - ConditionalType: 1 - }) - } - if (!!data.destinationId) { - condition.push({ - FieldName: 'destinationId', - FieldValue: data.destinationId, - ConditionalType: 1 - }) - } - if (!!data.carrierId) { - condition.push({ - FieldName: 'carrierId', - FieldValue: data.carrierId, - ConditionalType: 1 - }) - } - if (!!data.laneId) { - condition.push({ - FieldName: 'laneId', - FieldValue: data.laneId, - ConditionalType: 1 - }) - } - if (!!data.laneId) { - condition.push({ - FieldName: 'laneId', - FieldValue: data.laneId, - ConditionalType: 1 - }) - } - if (isAdvancedQuery.value) { - condition.push(ConditionalList.value) - } - if (moreNumVal.value) { - let ManyQueryData: any = { ConditionalList: [] } - moreNumVal.value - .replace(/\n|\r/g, ',') - .split(',') - .forEach((item) => { - ManyQueryData.ConditionalList.push({ - Key: 0, - Value: { FieldName: 'mblno', FieldValue: item, ConditionalType: 1 }, - }) - }) + return formatParams(p) + // if (moreNumVal.value) { + // let ManyQueryData: any = { ConditionalList: [] } + // moreNumVal.value + // .replace(/\n|\r/g, ',') + // .split(',') + // .forEach((item) => { + // ManyQueryData.ConditionalList.push({ + // Key: 0, + // Value: { FieldName: 'mblno', FieldValue: item, ConditionalType: 1 }, + // }) + // }) - condition.push(ManyQueryData) - } - postParam.queryCondition = JSON.stringify(condition) - return postParam + // condition.push(ManyQueryData) + // } }, afterFetch: () => { isAdvancedQuery.value = false @@ -471,7 +336,9 @@ columns, formConfig: { labelWidth: 120, + // 表格表单需要的过滤字段集合 schemas: searchFormSchema, + // 是否显示高级查询(默认否) useAdvancedSearch: true }, isTreeTable: false, @@ -527,8 +394,6 @@ moreNumVisible.value = false } const isAdvancedQuery = ref(false) - const AdvancedQueryVisible = ref(false) - const AdvancedQueryData = ref({ logicalOperator: 'and', conditions: [], groups: [] }) const showColumns = ref({}) const formAllData = ref([]) const fromTableAllData = ref({}) @@ -542,14 +407,6 @@ const TaskShippingOrderCompareVisible = ref(false) const formatSheetVisible = ref(false) - //打开高级查询弹窗 - function FnOpenAdvancedQuery() { - AdvancedQueryVisible.value = true - } - //关闭高级查询弹窗 - function FnCancelAdvancedQuery() { - AdvancedQueryVisible.value = false - } // 批量编辑 function batchEditing() { const select = getSelectRows() @@ -567,60 +424,6 @@ } const permissionId = ref('') const ConditionalList: Ref = ref() - //执行高级查询 - async function FnAdvancedQuery() { - let Api = (data) => { - let Obj: any = {} - let key: number = 0 - data.logicalOperator == 'and' ? (key = 0) : (key = 1) - if (data.conditions.length) { - if (!Obj.ConditionalList) { - Obj.ConditionalList = [] - } - - let Arr: any[] = [] - data.conditions.forEach((item) => { - Arr.push({ - Key: key, - Value: { - FieldName: item.field, - FieldValue: item.operator, - ConditionalType: item.value, - }, - }) - }) - Obj.ConditionalList.push(...Arr) - } - if (data.groups.length) { - if (!Obj.ConditionalList) { - Obj.ConditionalList = [] - } - let Arr: any[] = [] - data.groups.forEach((item) => { - Arr.push({ - Key: key, - Value: Api(item), - }) - }) - Obj.ConditionalList.push(...Arr) - } - return Obj - } - - ConditionalList.value = { - ConditionalList: Api(AdvancedQueryData.value).ConditionalList, - } - - let ApiData = { - permissionId: permissionId.value, - content: JSON.stringify(AdvancedQueryData.value), - } - const res: API.DataResult = await UpdateUserQuerySet(ApiData) - if (res.succeeded) { - isAdvancedQuery.value = true - reload() - } - } async function createdInit() { showColumns.value = JSON.parse(JSON.stringify(initData.columns)) formAllData.value = JSON.parse(JSON.stringify(initData.condAllData)) @@ -661,17 +464,6 @@ fields.value = data } - FnGetUserQuerySet() - // getConfigUser(true) - } - async function FnGetUserQuerySet() { - const res: API.DataResult = await GetUserQuerySet({ - permissionId: permissionId.value, - }) - if (res.succeeded) { - console.log(res) - AdvancedQueryData.value = JSON.parse(res.data.content) - } } function handledbclick(record) { editColumns(record)