@bit-sun/business-component 4.0.13-alpha.2 → 4.0.13-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,17 @@
1
1
  // @ts-nocheck
2
2
  import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
3
3
  import { useDebounceFn } from 'ahooks';
4
- import { Input, Button, Modal, Select, Divider, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag, Row, Col, Space, Tabs } from 'antd';
4
+ import { Input, Button, Modal, Select, Divider, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag, Row, Col, Space, Tabs, Empty, DatePicker } from 'antd';
5
5
  import { SearchOutlined, CopyOutlined, CaretLeftOutlined } from '@ant-design/icons';
6
6
  import request from '@/utils/request';
7
7
  import _, { escapeRegExp, isNil, values } from "lodash"
8
8
  import './index.less';
9
9
  import { BusinessSearchSelect, QueryMutipleInput, QueryMutipleSearchSelect } from '@/index';
10
- import { handleSourceName, getFormRowInfo, hasMoreQueryFields, defaultVisibleFieldsCount, getRealStr, ColSpan, getTableHeigth, getCurrentSRKs, getRenderSource, handleParams, convertUrlQueryParams, convertBodyParams, formatSelectedValue, convertResData, makeUniqueValue, handleSelectOptionsShowValue, LightHeightOption, maxTagPlaceholder } from './utils';
10
+ import { handleSourceName, getFormRowInfo, hasMoreQueryFields, defaultVisibleFieldsCount, getRealStr, getTableHeigth, getCurrentSRKs, getRenderSource, handleParams, convertUrlQueryParams, convertBodyParams, formatSelectedValue, convertResData, makeUniqueValue, handleSelectOptionsShowValue, LightHeightOption, maxTagPlaceholder, getShowStr, handleTableColumns } from './utils';
11
11
  import { judgeIsRequestError } from '@/utils/requestUtils';
12
12
  import zhankaitiaojian from '../../../assets/zhankaitiaojian-icon.svg';
13
13
  import PropertySelector from '@/components/Business/PropertyModal';
14
+ import ItemPropertySelector from '@/components/Business/ItemPropertySelector';
14
15
 
15
16
  const { Option } = Select;
16
17
 
@@ -21,7 +22,8 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
21
22
  selectProps = {},
22
23
  modalTableProps = {},
23
24
  labelInValue = false,
24
- requestConfig,
25
+ needTopSelectedSource,
26
+ requestConfig:rCTemp,
25
27
  ctx,
26
28
  onlyShowStr = false,
27
29
  sourceName,
@@ -51,7 +53,8 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
51
53
  noOperate, // 级联禁用按钮设置字段
52
54
  viewShowValueStr, // 详情展示值,不传展示组件处理的默认值
53
55
  searchStartLength, // 默认不校验长度去搜索,如果配置了,则按照配置项长度进行处理搜索
54
- } = requestConfig || {};
56
+ } = rCTemp || {};
57
+ const requestConfig = {url,method,otherParams,isMap,fixedparameter,fieldValToParam,fixedparamsDisabled,mappingTextField,mappingTextShowKeyField,mappingValueField,mappingTextShowTextField,init,extralHeaders,specialBracket,noNeedSplit,noOperate,viewShowValueStr,searchStartLength,...rCTemp};
55
58
  const resultSourceKey = handleSourceName(sourceName || requestConfig?.sourceName || ctx?.name || 'supplierCode')
56
59
 
57
60
  const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
@@ -80,7 +83,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
80
83
 
81
84
  const initPagination = { showQuickJumper: true, showSizeChanger: true, showTotal: (total: any) => `共 ${total} 条`, pageSize: tableInitPageSize }
82
85
  const tableInitPagination = { ...initPagination, total: 0, current: 1 }
83
- const disabled = noOperate || selectProps?.disabled || props?.disabled;
86
+ const disabled = !!noOperate || selectProps?.disabled || props?.disabled;
84
87
  const isHaveDependency = fixedparameter && fieldValToParam && ctx;
85
88
  const isHaveDValue = () => {
86
89
  let formValueList = [];
@@ -139,7 +142,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
139
142
  const [indeterminate, setIndeterminate] = useState(false)
140
143
  const [tableFormParams, setTableFormParams] = useState({});
141
144
  const [tooltipVisible, setTooltipVisible] = useState(false);
142
- const [tableShowColumns, setTabletShowColumns] = useState(modalTableProps?.tableColumns?.filter(s => typeof s.defaultSort == 'number')?.sort((a,b)=> a.defaultSort-b.defaultSort)||[]);
145
+ const [tableShowColumns, setTabletShowColumns] = useState(handleTableColumns(modalTableProps?.tableColumns)); // 默认展示表头-modalTableProps?.tableColumns
143
146
  const [confirmLoading, setConfirmLoading] = useState(false);
144
147
  const [modalSearched, setModalSearched]=useState(false);
145
148
 
@@ -228,12 +231,12 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
228
231
  ...fixedParam,
229
232
  ...params,
230
233
  };
231
- if (isNil(queryParams[selectParamsKey])) {
234
+ if (isNil(queryParams[selectParamsKey])&&searchValue?.length) {
232
235
  queryParams[selectParamsKey] = searchValue;
233
236
  }
234
237
 
235
238
  let getRequest;
236
- const methodName = method?.toLocaleLowerCase();
239
+ const methodName = method?.toLocaleLowerCase?.();
237
240
  if(['post','patch','put'].includes(methodName)) {
238
241
  getRequest = request[methodName](`${url}${convertUrlQueryParams(queryParams)}`,convertBodyParams(queryParams))
239
242
  } else {
@@ -250,7 +253,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
250
253
  return;
251
254
  }
252
255
  const res = result.data;
253
- const source: any = convertResData(requestConfig, res, { selectMode, labelInValue, value, type, items, queryParams });
256
+ const source: any = convertResData(requestConfig, res, { selectMode, labelInValue, value, type, items, queryParams, needTopSelectedSource });
254
257
 
255
258
  if(callback) {
256
259
  callback(source)
@@ -321,6 +324,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
321
324
 
322
325
  useEffect(() => {
323
326
  setUniqueValue(makeUniqueValue());
327
+ setTabletShowColumns(handleTableColumns(modalTableProps?.tableColumns));
324
328
  }, [resultSourceKey])
325
329
 
326
330
  useEffect(() => {
@@ -570,9 +574,10 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
570
574
  }
571
575
  };
572
576
 
573
- const { emptyArray } = getFormRowInfo(list);
577
+ const { emptyArray, ColSpan } = getFormRowInfo(list, modalTableProps?.tableSearchColSpan);
574
578
  const addKong = emptyArray?.map((i: any) =>({ type: 'kong'}))||[];
575
- return list?.concat(addKong)?.map((i: any, index: number) => {
579
+ const searchList = modalTableProps?.noEmptySearchField ? list : list?.concat(addKong);
580
+ return searchList.map((i: any, index: number) => {
576
581
  if(i?.type === 'kong') return <Col span={ColSpan} key={i}></Col>;
577
582
 
578
583
  if (i?.type === 'select' || i?.field?.type === 'select') {
@@ -599,6 +604,25 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
599
604
  )
600
605
  }
601
606
 
607
+ if (i?.type === 'rangepicker' || i?.field?.type === 'rangepicker') {
608
+ return (
609
+ <Col span={ColSpan} key={i.name}>
610
+ <Form.Item name={i.name} label={i.label} key={i.name} initialValue={i?.initialValue ?? []}>
611
+ <DatePicker.RangePicker style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}></DatePicker.RangePicker>
612
+ </Form.Item>
613
+ </Col>
614
+ )
615
+ }
616
+ if (i?.type === 'datepicker' || i?.field?.type === 'datepicker') {
617
+ return (
618
+ <Col span={ColSpan} key={i.name}>
619
+ <Form.Item name={i.name} label={i.label} key={i.name}>
620
+ <DatePicker style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}></DatePicker>
621
+ </Form.Item>
622
+ </Col>
623
+ )
624
+ }
625
+
602
626
  if (i?.type === 'businessSearchSelect' || i?.field?.type === 'businessSearchSelect') {
603
627
  return (
604
628
  <Col span={ColSpan} key={i.name}>
@@ -632,6 +656,19 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
632
656
  </Col>
633
657
  );
634
658
  }
659
+ if (i?.type === 'itemPropertySelector' || i?.field?.type === 'itemPropertySelector') {
660
+ return (
661
+ <Col span={ColSpan} key={i.name}>
662
+ <Form.Item name={i.name} label={i.label} key={i.name}>
663
+ <ItemPropertySelector
664
+ style={{ width: '100%' }}
665
+ placeholder="请选择"
666
+ {...i?.field?.props}
667
+ ></ItemPropertySelector>
668
+ </Form.Item>
669
+ </Col>
670
+ );
671
+ }
635
672
  if (i?.field?.type === 'multipleQuerySearchSelect') {
636
673
  return (
637
674
  <Col span={ColSpan} key={i.name}>
@@ -664,9 +701,15 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
664
701
  return collapsed ? formItem(list?.slice(0,viCount)) : formItem(list)
665
702
  }
666
703
 
704
+ const renderEmptyText = (text: string,x: string) => {
705
+ return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={text} style={{ margin: `${x} 0px`}} />
706
+ }
707
+
667
708
  const renderShowTable = (tableList, type) => {
668
709
  const tableBoxHeighth = getTableHeigth(modalTableProps?.tableSearchForm);
669
- const oSY = `calc(100vh - ${tableBoxHeighth}px - 82px)`; // 分页 24+16*2+10 「高 + margin * 2 + paddingBottom 10 」
710
+ const x = tableList?.length ? 82 : 28; // 无数据没有分页,有数据计算减去:分页 24+16*2+10 「高 + margin * 2 + paddingBottom 10 」
711
+ const oSY = `calc(100vh - ${tableBoxHeighth}px - ${x}px)`;
712
+ const mTB = `calc(50vh - ${tableBoxHeighth/2}px - ${x/2}px - 40px)`
670
713
  return (
671
714
  <div style={{ height: `calc(100vh - ${tableBoxHeighth}px)` }}>
672
715
  <Table
@@ -678,14 +721,14 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
678
721
  {...type=='noPage'?{
679
722
  pagination: { ...initPagination,showSizeChanger: false },
680
723
  locale: {
681
- emptyText: '暂无已选结果',
724
+ emptyText: renderEmptyText('暂无已选结果',mTB),
682
725
  }
683
726
  }:{
684
727
  pagination: tablePagination,
685
728
  onChange: handleTableChange,
686
729
  loading: fetching,
687
730
  locale: {
688
- emptyText: modalSearched? '无匹配结果,请更换其他内容再试' : '请输入搜索条件',
731
+ emptyText: modalSearched? renderEmptyText('匹配结果,请更换其他内容再试',mTB) : renderEmptyText('请输入搜索条件',mTB),
689
732
  }
690
733
  }}
691
734
  rowKey={mappingValueField}
@@ -811,34 +854,6 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
811
854
  );
812
855
  }
813
856
 
814
- const getShowLabelTextStr = (kongValue): string => {
815
- if (selectMode) {
816
- return Array.isArray(value) && value?.map(item => item.label || item.text || '')?.join(',') || kongValue;
817
- }
818
- return (value?.label || value?.text || kongValue) as string;
819
- };
820
- const getSelectValueText = (v: any) => {
821
- return (items || []).filter(item => item.value === v)?.[0]?.text || v || '';
822
- }
823
- const getShowValueStr = (kongValue): string => {
824
- if (selectMode) {
825
- return Array.isArray(value) && value?.map(item => getSelectValueText(item))?.join(',') || kongValue;
826
- }
827
- return (getSelectValueText(value) || kongValue) as string;
828
- }
829
- const getShowStr = () => {
830
- // 优先使用业务使用传入的展示
831
- if(viewShowValueStr) return viewShowValueStr;
832
-
833
- const kongValue = '无'
834
- // 先判断labelInValue与否,labelInValue可以直接去value中获取字段名称,否则去下拉框数据里面去拿;
835
- // 再判断是单选还是多选,数据类型不同取值方式也不同
836
- if (labelInValue) {
837
- return getShowLabelTextStr(kongValue);
838
- }
839
- return getShowValueStr(kongValue);
840
- }
841
-
842
857
  const isShouldShowStr = (props.disabled && ctx) || ctx?.mode == 'view';
843
858
  return (
844
859
  <div className={'search_select'}>
@@ -853,8 +868,8 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
853
868
  </div>
854
869
  ) : (
855
870
  isShouldShowStr ?
856
- (<div title={getShowStr()} style={{overflow:'hidden',textOverflow:'ellipsis',whiteSpace:'nowrap'}} className={'search_select_show'}>
857
- {getShowStr()}
871
+ (<div title={getShowStr({ viewShowValueStr, labelInValue, selectMode, value, items })} style={{overflow:'hidden',textOverflow:'ellipsis',whiteSpace:'nowrap'}} className={'search_select_show'}>
872
+ {getShowStr({viewShowValueStr, labelInValue, selectMode, value, items })}
858
873
  </div>) :
859
874
  <div
860
875
  className={`${isFormPage ? '' : 'search_select_show_list'} search_select_show`}
@@ -906,7 +921,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
906
921
  <Modal
907
922
  maskClosable={false}
908
923
  destroyOnClose
909
- width="80%"
924
+ width={`calc(100% - 320px)`}
910
925
  title={modalTableProps?.modalTableTitle}
911
926
  visible={isModalVisible}
912
927
  confirmLoading={confirmLoading}
@@ -948,7 +963,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
948
963
  重置 ctrl+U
949
964
  </Button>
950
965
  <div style={{position: 'absolute',top: 0,right: 0}}>
951
- {hasMoreQueryFields(modalTableProps) && modalTableProps?.isHorizontally
966
+ {hasMoreQueryFields(modalTableProps)
952
967
  ? <img onClick={() => {toggleCollapsed()}} style={{
953
968
  cursor: 'pointer',
954
969
  fontSize: '10px',
@@ -17,12 +17,13 @@ export const handleSourceName = (sName: any) => {
17
17
  }
18
18
 
19
19
  // ------------------------------------------处理样式相关--开始----------------------------------------
20
- export const getFormRowInfo = (list: any) => {
21
- const totalRows = Math.ceil(list.length / columnsPerRow); // 计算总行数
22
- const lastRowColumns = (list.length+1) % columnsPerRow; // 计算最后一行的实际列数
23
- const emptySlots = lastRowColumns === 0 ? 0 : columnsPerRow - lastRowColumns; // 计算最后一行的空位数
20
+ export const getFormRowInfo = (list: any, tableSearchColSpan: number) => {
21
+ const lastColumnsPerRow = tableSearchColSpan == 6 ? columnsPerRow : 3;
22
+ const totalRows = Math.ceil(list.length / lastColumnsPerRow); // 计算总行数
23
+ const lastRowColumns = (list.length+1) % lastColumnsPerRow; // 计算最后一行的实际列数
24
+ const emptySlots = lastRowColumns === 0 ? 0 : lastColumnsPerRow - lastRowColumns; // 计算最后一行的空位数
24
25
  const emptyArray = new Array(emptySlots).fill(null); // 生成长度为 emptySlots 的数组
25
- return { totalRows, emptyArray }
26
+ return { totalRows, emptyArray, ColSpan: tableSearchColSpan ?? ColSpan}
26
27
  }
27
28
 
28
29
  export const defaultVisibleFieldsCount = 7;
@@ -397,4 +398,43 @@ export const maxTagPlaceholder = (selectedValues: any, { selectProps, onChange,
397
398
  )
398
399
  }
399
400
 
400
- // ------------------------------------------ 数据源展示 相关处理--结束----------------------------------------
401
+ // 弹窗数据表头处理
402
+ export const handleTableColumns = (tableColumns: any) => {
403
+ // 按照默认设置排序 > 没有排序字段的展示所有列表头 > 没有表头列不展示
404
+ const showTableColumns = tableColumns?.filter((s: any) => typeof s.defaultSort == 'number')||tableColumns||[];
405
+ return showTableColumns?.sort((a: any,b: any)=> a.defaultSort-b.defaultSort)||[]
406
+ };
407
+
408
+ // ------------------------------------------ 数据源展示 相关处理--结束----------------------------------------
409
+
410
+
411
+
412
+ // ------------------------------------------ 选中数据展示 相关处理--开始----------------------------------------
413
+ const getShowLabelTextStr = ({ kongValue, selectMode, value, items }: any) => {
414
+ if (selectMode) {
415
+ return Array.isArray(value) && value?.map(item => item.label || item.text || '')?.join(',') || kongValue;
416
+ }
417
+ return (value?.label || value?.text || kongValue) as string;
418
+ };
419
+ const getSelectValueText = (v: any, items: any) => {
420
+ return (items || []).filter((item: any) => item.value === v)?.[0]?.text || v || '';
421
+ }
422
+ const getShowValueStr = ({ kongValue, selectMode, value, items }: any): string => {
423
+ if (selectMode) {
424
+ return Array.isArray(value) && value?.map(item => getSelectValueText(item, items))?.join(',') || kongValue;
425
+ }
426
+ return (getSelectValueText(value, items) || kongValue) as string;
427
+ }
428
+ export const getShowStr = ({ viewShowValueStr, labelInValue, selectMode, value, items }: any) => {
429
+ // 优先使用业务使用传入的展示
430
+ if(viewShowValueStr) return viewShowValueStr;
431
+
432
+ const kongValue = '无'
433
+ // 先判断labelInValue与否,labelInValue可以直接去value中获取字段名称,否则去下拉框数据里面去拿;
434
+ // 再判断是单选还是多选,数据类型不同取值方式也不同
435
+ if (labelInValue) {
436
+ return getShowLabelTextStr({ kongValue, selectMode, value, items});
437
+ }
438
+ return getShowValueStr({ kongValue, selectMode, value, items });
439
+ }
440
+ // ------------------------------------------ 选中数据展示 相关处理--结束---------------------------------------