zy-react-library 2.2.0 → 2.2.2

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.
package/README.md CHANGED
@@ -37,7 +37,7 @@ import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
37
37
 
38
38
  - 本文档根据当前包内 `.d.ts` 类型声明整理。
39
39
  - 继承自 `antd`、`@ant-design/pro-components`、`ahooks` 的原生属性不逐项展开,文档会说明继承关系;库自身新增的参数逐项列出。
40
- - `css` 仅做简要说明。
40
+ - `css` 仅做简要说明。
41
41
  - 参数表中的 `-` 表示源码未设置显式默认值;`undefined` 表示源码显式传入或保留为 `undefined`。
42
42
 
43
43
  ## 基础样式
@@ -50,7 +50,7 @@ import "zy-react-library/css/common.less";
50
50
 
51
51
  `common.less` 提供组件库通用样式,适合在应用入口统一引入。
52
52
 
53
- ## 枚举
53
+ ## 枚举
54
54
 
55
55
  ### FORM_ITEM_RENDER_ENUM
56
56
 
@@ -80,7 +80,7 @@ import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
80
80
  | `DATETIME` | `"datetime"` | `antd DatePicker` 日期时间 | `DatePickerProps` |
81
81
  | `DATETIME_RANGE` | `"datetimeRange"` | `antd DatePicker.RangePicker` 日期时间范围 | `RangePickerProps` |
82
82
  | `DIVIDER` | `"divider"` | `antd Divider` | `DividerProps` |
83
- | `FORM_LIST` | `"formList"` | `antd Form.List` | `FormListProps` |
83
+ | `FORM_LIST` | `"formList"` | `antd Form.List` | `FormListProps` |
84
84
 
85
85
  ## 表单配置类型
86
86
 
@@ -213,22 +213,22 @@ import { FORM_ITEM_RENDER_ENUM } from "zy-react-library/enum/formItemRender";
213
213
  | `TooltipPreviewImg` | `files=[]`、`fileUrlKey="filePath"`。 |
214
214
  | `SelectCreate` | `showDelete=true`、`label=""`、`maxCount=1`,内部固定 `mode="tags"`。 |
215
215
  | `BasicSelect` | `placeholder=""`、`data=[]`、`nameKey="name"`、`idKey="id"`,内置 `showSearch=true`、`allowClear=true`、`optionFilterProp="children"`。 |
216
- | `DictionarySelect` | `appKey="0bb989ecada5470c87635018ece9f327"`、`dictValue=""`、`nameKey="dictLabel"`、`idKey="dictValue"`。 |
216
+ | `DictionarySelect` | `appKey="0bb989ecada5470c87635018ece9f327"`、`dictValue=""`、`nameKey="dictLabel"`、`idKey="dictValue"`。 |
217
217
  | `PersonnelSelect` | `params={}`、`placeholder="人员"`、`isNeedCorpInfoId=false`、`isNeedDepartmentId=true`、`isNeedPostId=false`、`extraParams={}`,内部默认额外参数 `{ noMain: "", eqEmploymentFlag: 1 }`。 |
218
218
  | `BasicSelectTree` | `getNodePathsIsIncludeOneself=true`、`placeholder=""`、`treeData=[]`、`nameKey="name"`、`idKey="id"`、`childrenKey="children"`、`onlyLastLevel=false`,内置 `showSearch=true`、`allowClear=true`、`style={ width: "100%" }`。 |
219
219
  | `AreaSelectTree` | 内部使用 `area.json`,默认 `nameKey="label"`、`idKey="value"`。 |
220
220
  | `IndustrySelectTree` | 内部使用 `industry.json`,默认 `nameKey="dict_label"`、`idKey="dict_value"`、`childrenKey="childrenList"`。 |
221
221
  | `DepartmentSelectTree` | `params={}`、`placeholder="部门"`、`isNeedCorpInfoId=false`、`isNeedParentId=false`、`searchType="current"`,内部固定 `childrenKey="childrenList"`。 |
222
- | `DictionarySelectTree` | `appKey="0bb989ecada5470c87635018ece9f327"`、`dictValue=""`、`nameKey="dictLabel"`、`idKey="dictValue"`。 |
222
+ | `DictionarySelectTree` | `appKey="0bb989ecada5470c87635018ece9f327"`、`dictValue=""`、`nameKey="dictLabel"`、`idKey="dictValue"`。 |
223
223
  | `HiddenLevelSelectTree` | `isShowNeglect=true`、`isShowLarger=true`、`isShowMajor=true`,内部固定 `placeholder="隐患级别"`、`onlyLastLevel=true`、`nameKey="dictLabel"`、`idKey="dictValue"`。 |
224
224
  | `HiddenPartSelectTree` | `params={}`、`isNeedCorpInfoId=false`,内部固定 `placeholder="隐患部位"`、`nameKey="hiddenregion"`、`idKey="hiddenregionId"`。 |
225
225
  | `BasicCascader` | `getNodePathsIsIncludeOneself=true`、`placeholder=""`、`data=[]`、`nameKey="name"`、`idKey="id"`、`childrenKey="children"`。 |
226
226
  | `AreaCascader` | 内部使用 `area.json`,默认 `nameKey="label"`、`idKey="value"`。 |
227
227
  | `IndustryCascader` | 内部使用 `industry.json`,默认 `nameKey="dict_label"`、`idKey="dict_value"`、`childrenKey="childrenList"`。 |
228
- | `DictionaryCascader` | `appKey="0bb989ecada5470c87635018ece9f327"`、`dictValue=""`、`nameKey="dictLabel"`、`idKey="dictValue"`。 |
228
+ | `DictionaryCascader` | `appKey="0bb989ecada5470c87635018ece9f327"`、`dictValue=""`、`nameKey="dictLabel"`、`idKey="dictValue"`。 |
229
229
  | `BasicLeftTree` | `getNodePathsIsIncludeOneself=true`、`treeData=[]`、`nameKey="name"`、`idKey="id"`、`childrenKey="children"`,搜索框固定宽度容器 `300`。 |
230
230
  | `AreaLeftTree` | 内部使用 `area.json`,默认 `nameKey="label"`、`idKey="value"`。 |
231
- | `DictionaryLeftTree` | `appKey="0bb989ecada5470c87635018ece9f327"`、`dictValue=""`、`nameKey="dictLabel"`、`idKey="dictValue"`。 |
231
+ | `DictionaryLeftTree` | `appKey="0bb989ecada5470c87635018ece9f327"`、`dictValue=""`、`nameKey="dictLabel"`、`idKey="dictValue"`。 |
232
232
  | `DepartmentLeftTree` | `params={}`、`searchType="current"`,内部固定 `childrenKey="childrenList"`。 |
233
233
  | `Map` | `longitudeProps="longitude"`、`latitudeProps="latitude"`、`required=true`、`area=""`、`showArea=false`、`disable=false`、`type="baidu"`。 |
234
234
  | `MapSelector` | `area=""`、`showArea=false`、`disable=false`、`type="baidu"`;弹窗宽度 `1000`、`maskClosable=false`、地图容器高度 `500px`。 |
@@ -813,7 +813,7 @@ import DictionarySelect from "zy-react-library/components/Select/Dictionary";
813
813
 
814
814
  | 参数 | 类型 | 必填 | 默认值 | 说明 |
815
815
  | --- | --- | --- | --- | --- |
816
- | `appKey` | `string` | 否 | `"0bb989ecada5470c87635018ece9f327"` | 字典应用 key。 |
816
+ | `appKey` | `string` | 否 | `"0bb989ecada5470c87635018ece9f327"` | 字典应用 key。 |
817
817
  | `dictValue` | `string` | 是 | `""` | 字典类型值;为空会输出缺少参数错误。 |
818
818
  | `nameKey` | `string` | 否 | `"dictLabel"` | 标签字段名。 |
819
819
  | `idKey` | `string` | 否 | `"dictValue"` | 值字段名。 |
@@ -951,7 +951,7 @@ import DictionarySelectTree from "zy-react-library/components/SelectTree/Diction
951
951
 
952
952
  | 参数 | 类型 | 必填 | 默认值 | 说明 |
953
953
  | --- | --- | --- | --- | --- |
954
- | `appKey` | `string` | 否 | `"0bb989ecada5470c87635018ece9f327"` | 字典应用 key。 |
954
+ | `appKey` | `string` | 否 | `"0bb989ecada5470c87635018ece9f327"` | 字典应用 key。 |
955
955
  | `dictValue` | `string` | 是 | - | 字典类型值。 |
956
956
  | `nameKey` | `string` | 否 | 节点标签字段名。 |
957
957
  | `idKey` | `string` | 否 | 节点值字段名。 |
@@ -1099,7 +1099,7 @@ import DictionaryCascader from "zy-react-library/components/Cascader/Dictionary"
1099
1099
 
1100
1100
  | 参数 | 类型 | 必填 | 默认值 | 说明 |
1101
1101
  | --- | --- | --- | --- | --- |
1102
- | `appKey` | `string` | 否 | `"0bb989ecada5470c87635018ece9f327"` | 字典应用 key。 |
1102
+ | `appKey` | `string` | 否 | `"0bb989ecada5470c87635018ece9f327"` | 字典应用 key。 |
1103
1103
  | `dictValue` | `string` | 是 | - | 字典类型值。 |
1104
1104
  | `nameKey` | `string` | 否 | 节点标签字段名。 |
1105
1105
  | `idKey` | `string` | 否 | 节点值字段名。 |
@@ -1158,7 +1158,7 @@ import DictionaryLeftTree from "zy-react-library/components/LeftTree/Dictionary"
1158
1158
 
1159
1159
  | 参数 | 类型 | 必填 | 默认值 | 说明 |
1160
1160
  | --- | --- | --- | --- | --- |
1161
- | `appKey` | `string` | 否 | `"0bb989ecada5470c87635018ece9f327"` | 字典应用 key。 |
1161
+ | `appKey` | `string` | 否 | `"0bb989ecada5470c87635018ece9f327"` | 字典应用 key。 |
1162
1162
  | `dictValue` | `string` | 是 | `""` | 字典类型值;为空会输出缺少参数错误。 |
1163
1163
  | `nameKey` | `string` | 否 | `"dictLabel"` | 节点标题字段名。 |
1164
1164
  | `idKey` | `string` | 否 | `"dictValue"` | 节点 key 字段名。 |
@@ -1219,7 +1219,7 @@ import DepartmentLeftTree from "zy-react-library/components/LeftTree/Department/
1219
1219
  | `useImportFile` | `returnType="object"`;执行导入时 `options.files=[]`、`options.params={}`。 |
1220
1220
  | `useDownloadBlob` | `returnType="object"`;执行下载时 `options.name=""`、`options.type=""`、`options.params={}`,未传 `type` 时使用 `application/vnd.ms-excel`,未传 `name` 时使用当前时间 `YYYY-MM-DD HH:mm:ss`。 |
1221
1221
  | `useDownloadFile` | `returnType="object"`;未传 `name` 时从 `url` 中截取文件名。 |
1222
- | `useDictionary` | `returnType="object"`;执行获取时 `appKey="0bb989ecada5470c87635018ece9f327"`。 |
1222
+ | `useDictionary` | `returnType="object"`;执行获取时 `appKey="0bb989ecada5470c87635018ece9f327"`。 |
1223
1223
  | `useGetUserInfo` | `returnType="object"`。 |
1224
1224
  | `useIdle` | `timeout=10000`、`events=["mousemove","mousedown","resize","keydown","touchstart","wheel"]`。 |
1225
1225
  | `useIsExistenceDuplicateSelection` | `message="存在重复项,请勿重复选择"`。 |
@@ -1465,7 +1465,7 @@ useDictionary("object"): { loading: boolean; getDictionary: getDictionaryFunctio
1465
1465
 
1466
1466
  | 参数 | 类型 | 必填 | 默认值 | 说明 |
1467
1467
  | --- | --- | --- | --- | --- |
1468
- | `appKey` | `string` | 否 | `"0bb989ecada5470c87635018ece9f327"` | 字典应用 key。 |
1468
+ | `appKey` | `string` | 否 | `"0bb989ecada5470c87635018ece9f327"` | 字典应用 key。 |
1469
1469
  | `dictValue` | `string` | 是 | - | 字典类型值。 |
1470
1470
 
1471
1471
  返回 `Promise<DictionaryItem[]>`。
@@ -1,4 +1,4 @@
1
- import type { FC } from "react";
1
+ import type { CSSProperties, FC, ReactNode } from "react";
2
2
 
3
3
  export interface ExcelProps {
4
4
  /** 是否显示弹窗 */
@@ -13,8 +13,10 @@ export interface ExcelProps {
13
13
  inline?: boolean;
14
14
  /** 弹窗标题 */
15
15
  title?: string;
16
- /** 内容样式 */
17
- style?: Record<string, any>;
16
+ /** 内联模式下的样式 */
17
+ style?: CSSProperties;
18
+ /** 弹窗底部额外的按钮 */
19
+ extraButtons?: ReactNode;
18
20
  }
19
21
 
20
22
  declare const Excel: FC<ExcelProps>;
@@ -1 +1 @@
1
- import{Modal as e,Button as t,message as r,Spin as n}from"antd";import i from"exceljs";import{useRef as o,useState as l,useEffect as c}from"react";import a from"x-data-spreadsheet";import u from"../../hooks/useDownloadFile/index.js";import{getFileUrl as s}from"../../utils/index.js";import"x-data-spreadsheet/dist/xspreadsheet.css";import{jsx as d}from"react/jsx-runtime";function h(h){const{visible:x=!1,onCancel:w,file:p,name:v,inline:g=!1,title:y="Excel预览",style:C={}}=h,E=o(null),k=o(null),I=o(!1),T=s(),[b,j]=l(!1),{downloadFile:S}=u();c(()=>{if(!x&&!g||!p)return;I.current=!1;const e=setTimeout(()=>{(async()=>{j(!0),E.current.innerHTML="";try{const e=await fetch(p.includes(T)?p:T+p);if(!e.ok)throw new Error("加载 Excel 文件失败");const t=await e.arrayBuffer(),r=new i.Workbook;if(await r.xlsx.load(t),I.current)return;new a(E.current,{mode:"read",showToolbar:!1,showContextmenu:!1,view:{height:()=>E.current?.clientHeight||520,width:()=>E.current?.clientWidth||800}}).loadData(function(e){const t=[];return e.worksheets.forEach(e=>{t.push(function(e){const t={name:e.name,rows:{},cols:{len:e.columnCount||26},merges:e.model?.merges||[]};return e.columns.forEach((e,r)=>{e.width&&(t.cols[r]={width:Math.round(8*e.width)})}),e.eachRow({includeEmpty:!0},(e,r)=>{const n={cells:{}};e.height&&(n.height=Math.round(1.4*e.height)),e.eachCell({includeEmpty:!0},(e,t)=>{n.cells[t-1]={text:m(e)}}),t.rows[r-1]=n}),(t.merges||[]).forEach(e=>{const r=function(e){const[t,r=t]=e.split(":"),n=f(t),i=f(r);return{sri:n.rowIndex,sci:n.colIndex,eri:i.rowIndex,eci:i.colIndex}}(e),n=t.rows[r.sri]?.cells?.[r.sci];n&&(n.merge=[r.eri-r.sri,r.eci-r.sci])}),t}(e))}),t.length>0?t:[{name:"Sheet1",rows:{}}]}(r))}catch{r.error("加载 Excel 文件失败"),!g&&w&&w()}finally{I.current||j(!1)}})()},100);return()=>{I.current=!0,E.current&&(E.current.innerHTML=""),e&&clearTimeout(e)}},[x,g,p]);const D=()=>d(n,{spinning:b,children:d("div",{style:{height:"72vh",overflow:"hidden",...C},children:d("div",{ref:E,style:{width:"100%",height:"100%"}})})});return g?D():d("div",{ref:k,children:d(e,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:x,mask:{closable:!1},width:1e3,title:y,onCancel:()=>{w()},getContainer:!1,footer:[d(t,{onClick:()=>{w()},children:"关闭"},"cancel"),d(t,{type:"primary",onClick:()=>{S({url:p,name:v})},children:"下载"},"download")],children:D()})})}function m(e){if(null===e.value||void 0===e.value)return"";if(e.formula)return null===e.result||void 0===e.result?`=${e.formula}`:String(e.result);if(e.text)return e.text;if(e.value instanceof Date)return e.value.toLocaleDateString();if("object"==typeof e.value){if(e.value.text)return e.value.text;if(e.value.richText)return e.value.richText.map(e=>e.text).join("");if(void 0!==e.value.result)return String(e.value.result)}return String(e.value)}function f(e){const t=/^([A-Z]+)(\d+)$/i.exec(e);return t?{rowIndex:Number(t[2])-1,colIndex:(r=t[1],r.toUpperCase().split("").reduce((e,t)=>26*e+t.charCodeAt(0)-64,0)-1)}:{rowIndex:0,colIndex:0};var r}h.displayName="Excel";export{h as default};
1
+ import{Modal as e,Button as t,message as r,Spin as n}from"antd";import o from"exceljs";import{useRef as i,useState as l,useEffect as c}from"react";import a from"x-data-spreadsheet";import u from"../../hooks/useDownloadFile/index.js";import{getFileUrl as s}from"../../utils/index.js";import"x-data-spreadsheet/dist/xspreadsheet.css";import{jsx as d}from"react/jsx-runtime";function h(h){const{visible:x=!1,onCancel:w,file:p,name:v,inline:g=!1,title:y="Excel预览",style:C={},extraButtons:E}=h,k=i(null),I=i(null),T=i(!1),b=s(),[j,S]=l(!1),{downloadFile:D}=u();c(()=>{if(!x&&!g||!p)return;T.current=!1;const e=setTimeout(()=>{(async()=>{S(!0),k.current.innerHTML="";try{const e=await fetch(p.includes(b)?p:b+p);if(!e.ok)throw new Error("加载 Excel 文件失败");const t=await e.arrayBuffer(),r=new o.Workbook;if(await r.xlsx.load(t),T.current)return;new a(k.current,{mode:"read",showToolbar:!1,showContextmenu:!1,view:{height:()=>k.current?.clientHeight||520,width:()=>k.current?.clientWidth||800}}).loadData(function(e){const t=[];return e.worksheets.forEach(e=>{t.push(function(e){const t={name:e.name,rows:{},cols:{len:e.columnCount||26},merges:e.model?.merges||[]};return e.columns.forEach((e,r)=>{e.width&&(t.cols[r]={width:Math.round(8*e.width)})}),e.eachRow({includeEmpty:!0},(e,r)=>{const n={cells:{}};e.height&&(n.height=Math.round(1.4*e.height)),e.eachCell({includeEmpty:!0},(e,t)=>{n.cells[t-1]={text:m(e)}}),t.rows[r-1]=n}),(t.merges||[]).forEach(e=>{const r=function(e){const[t,r=t]=e.split(":"),n=f(t),o=f(r);return{sri:n.rowIndex,sci:n.colIndex,eri:o.rowIndex,eci:o.colIndex}}(e),n=t.rows[r.sri]?.cells?.[r.sci];n&&(n.merge=[r.eri-r.sri,r.eci-r.sci])}),t}(e))}),t.length>0?t:[{name:"Sheet1",rows:{}}]}(r))}catch{r.error("加载 Excel 文件失败"),!g&&w&&w()}finally{T.current||S(!1)}})()},100);return()=>{T.current=!0,k.current&&(k.current.innerHTML=""),e&&clearTimeout(e)}},[x,g,p]);const M=()=>d(n,{spinning:j,children:d("div",{style:{height:"72vh",overflow:"hidden",...C},children:d("div",{ref:k,style:{width:"100%",height:"100%"}})})});return g?M():d("div",{ref:I,children:d(e,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:x,mask:{closable:!1},width:1e3,title:y,onCancel:()=>{w()},getContainer:!1,footer:[d(t,{onClick:()=>{w()},children:"关闭"},"cancel"),d(t,{type:"primary",onClick:()=>{D({url:p,name:v})},children:"下载"},"download"),...E||[]],children:M()})})}function m(e){if(null===e.value||void 0===e.value)return"";if(e.formula)return null===e.result||void 0===e.result?`=${e.formula}`:String(e.result);if(e.text)return e.text;if(e.value instanceof Date)return e.value.toLocaleDateString();if("object"==typeof e.value){if(e.value.text)return e.value.text;if(e.value.richText)return e.value.richText.map(e=>e.text).join("");if(void 0!==e.value.result)return String(e.value.result)}return String(e.value)}function f(e){const t=/^([A-Z]+)(\d+)$/i.exec(e);return t?{rowIndex:Number(t[2])-1,colIndex:(r=t[1],r.toUpperCase().split("").reduce((e,t)=>26*e+t.charCodeAt(0)-64,0)-1)}:{rowIndex:0,colIndex:0};var r}h.displayName="Excel";export{h as default};
@@ -3,7 +3,7 @@ import type { ColProps } from "antd/es/col";
3
3
  import type { FormItemProps, Rule } from "antd/es/form";
4
4
  import type { FormListFieldData } from "antd/es/form/FormList";
5
5
  import type { Gutter } from "antd/es/grid/row";
6
- import type { CSSProperties, ReactElement, ReactNode } from "react";
6
+ import type { CSSProperties, Key, ReactElement, ReactNode } from "react";
7
7
  import type { FORM_ITEM_RENDER_TYPE_MAP } from "../../enum/formItemRender";
8
8
  import type { DeepPartial } from "./FormBuilder";
9
9
 
@@ -98,7 +98,7 @@ export interface FormOptionBase<
98
98
  Dependencies = NamePath<Values>,
99
99
  > {
100
100
  /** React 需要的 key,如果传递了唯一的 name,则不需要 */
101
- key?: string;
101
+ key?: Key;
102
102
  /** 表单项字段名 */
103
103
  name?: Name;
104
104
  /** 表单项标签 */
@@ -1,4 +1,4 @@
1
- import type { CSSProperties, FC } from "react";
1
+ import type { CSSProperties, FC, ReactNode } from "react";
2
2
 
3
3
  export interface PdfProps {
4
4
  /** pdf 文件地址 */
@@ -15,6 +15,8 @@ export interface PdfProps {
15
15
  inline?: boolean;
16
16
  /** 内联模式下的样式 */
17
17
  style?: CSSProperties;
18
+ /** 弹窗底部额外的按钮 */
19
+ extraButtons?: ReactNode;
18
20
  }
19
21
 
20
22
  declare const Pdf: FC<PdfProps>;
@@ -1 +1 @@
1
- import{useFullscreen as e}from"ahooks";import{Modal as r,Button as o,Spin as i,message as n}from"antd";import{useState as t,useRef as l}from"react";import{pdfjs as a,Document as d,Page as c}from"react-pdf";import s from"../../hooks/useDownloadFile/index.js";import{getFileUrl as p}from"../../utils/index.js";import"react-pdf/dist/Page/AnnotationLayer.css";import"react-pdf/dist/Page/TextLayer.css";import"./index.less";import{jsx as m,Fragment as f}from"react/jsx-runtime";function h(h){const{visible:u=!1,onCancel:x,file:g,name:v,inline:y=!1,title:w="PDF预览",style:k={}}=h,C=p(),[j,F]=t(0),[P,b]=t(600),L=l(null),[S,{enterFullscreen:D,exitFullscreen:A}]=e(L),{downloadFile:N}=s();a.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${a.version}/build/pdf.worker.min.mjs`;const W=({numPages:e})=>{F(e)},$=()=>{n.error("加载 PDF 文件失败"),x&&x()},z=({width:e})=>{b(e)},B=()=>m(f,{children:m("div",{style:{height:S?"calc(100vh - 40px - 24px - 8px - 32px - 12px)":"72vh",overflowY:"auto",padding:"24px",...k},children:m(d,{file:g.includes(C)?g:C+g,onLoadSuccess:W,onLoadError:$,loading:m("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"65vh"},children:m(i,{size:"large"})}),children:Array.from({length:j}).map((e,r)=>m(c,{pageNumber:r+1,onLoadSuccess:z},`page_${r+1}`))})})});return y?B():m("div",{ref:L,children:m(r,{style:{top:S?0:100,maxWidth:S?"100vw":"calc(100vw - 32px)",paddingBottom:S?0:24},open:u,mask:{closable:!1},width:S?"100vw":P+100,title:w,onCancel:()=>{S&&A(),x()},getContainer:!1,footer:[m(o,{onClick:()=>{S&&A(),x()},children:"关闭"},"cancel"),m(o,{onClick:()=>{S?A():D()},children:S?"退出全屏":"全屏"},"fullScreen"),m(o,{type:"primary",onClick:()=>{S&&A(),N({url:g,name:v})},children:"下载"},"download")],children:B()})})}h.displayName="Pdf";export{h as default};
1
+ import{useFullscreen as e}from"ahooks";import{Modal as r,Button as o,Spin as i,message as n}from"antd";import{useState as t,useRef as l}from"react";import{pdfjs as a,Document as d,Page as s}from"react-pdf";import c from"../../hooks/useDownloadFile/index.js";import{getFileUrl as p}from"../../utils/index.js";import"react-pdf/dist/Page/AnnotationLayer.css";import"react-pdf/dist/Page/TextLayer.css";import"./index.less";import{jsx as m,Fragment as f}from"react/jsx-runtime";function h(h){const{visible:u=!1,onCancel:x,file:g,name:v,inline:y=!1,title:w="PDF预览",style:k={},extraButtons:C}=h,j=p(),[F,P]=t(0),[b,L]=t(600),S=l(null),[D,{enterFullscreen:A,exitFullscreen:B}]=e(S),{downloadFile:N}=c();a.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${a.version}/build/pdf.worker.min.mjs`;const W=({numPages:e})=>{P(e)},$=()=>{n.error("加载 PDF 文件失败"),x&&x()},z=({width:e})=>{L(e)},E=()=>m(f,{children:m("div",{style:{height:D?"calc(100vh - 40px - 24px - 8px - 32px - 12px)":"72vh",overflowY:"auto",padding:"24px",...k},children:m(d,{file:g.includes(j)?g:j+g,onLoadSuccess:W,onLoadError:$,loading:m("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"65vh"},children:m(i,{size:"large"})}),children:Array.from({length:F}).map((e,r)=>m(s,{pageNumber:r+1,onLoadSuccess:z},`page_${r+1}`))})})});return y?E():m("div",{ref:S,children:m(r,{style:{top:D?0:100,maxWidth:D?"100vw":"calc(100vw - 32px)",paddingBottom:D?0:24},open:u,mask:{closable:!1},width:D?"100vw":b+100,title:w,onCancel:()=>{D&&B(),x()},getContainer:!1,footer:[m(o,{onClick:()=>{D&&B(),x()},children:"关闭"},"cancel"),m(o,{onClick:()=>{D?B():A()},children:D?"退出全屏":"全屏"},"fullScreen"),m(o,{type:"primary",onClick:()=>{D&&B(),N({url:g,name:v})},children:"下载"},"download"),...C||[]],children:E()})})}h.displayName="Pdf";export{h as default};
@@ -1,11 +1,33 @@
1
- import type { ProTableProps } from "@ant-design/pro-table";
2
- import type { TableProps as AntdTableProps } from "antd";
1
+ import type { ProColumns, ProTableProps } from "@ant-design/pro-components";
2
+ import type { TableProps as AntdTableProps, TableColumnType } from "antd";
3
3
  import type { FC } from "react";
4
4
 
5
+ /** 保留 Ant Design 推导的嵌套元组路径,移除宽泛字符串和普通数组 */
6
+ type StrictTableDataIndex<DataIndex> = DataIndex extends string
7
+ ? never
8
+ : DataIndex extends readonly unknown[]
9
+ ? number extends DataIndex["length"] ? never : DataIndex
10
+ : DataIndex extends number ? DataIndex : never;
11
+
12
+ /** 表格字段索引,支持一级字段和嵌套字段路径提示 */
13
+ export type TableDataIndex<DataSource>
14
+ = | Extract<keyof DataSource, string | number>
15
+ | StrictTableDataIndex<NonNullable<TableColumnType<DataSource>["dataIndex"]>>;
16
+
17
+ /** 表格列配置 */
18
+ export type TableColumn<DataSource, ValueType = "text"> = Omit<ProColumns<DataSource, ValueType>, "children" | "dataIndex"> & {
19
+ /** 当前列对应的数据字段 */
20
+ dataIndex?: TableDataIndex<DataSource>;
21
+ /** 多级表头子列 */
22
+ children?: TableColumn<DataSource, ValueType>[];
23
+ };
24
+
5
25
  /**
6
- * TablePro 组件属性
26
+ * Table 组件属性
7
27
  */
8
- export type TableProps<DataSource, U, ValueType> = Omit<AntdTableProps, "columns"> & ProTableProps<DataSource, U, ValueType> & {
28
+ export type TableProps<DataSource, U = Record<string, unknown>, ValueType = "text"> = Omit<AntdTableProps<DataSource>, "columns"> & Omit<ProTableProps<DataSource, U, ValueType>, "columns"> & {
29
+ /** 表格列配置 */
30
+ columns: TableColumn<DataSource, ValueType>[];
9
31
  /** 当一个路由下存在多个表格的情况下 需要给每一个表格设置一个唯一存储索引 若没有设置则使用默认索引,请注意缓存数据会被覆盖 */
10
32
  storeIndex?: string;
11
33
  /** 是否禁用内容区滚动,默认 false */
@@ -25,5 +47,5 @@ export type TableProps<DataSource, U, ValueType> = Omit<AntdTableProps, "columns
25
47
  /**
26
48
  * 表格组件
27
49
  */
28
- declare const Table: <DataSource, U, ValueType = "text">(props: TableProps<DataSource, U, ValueType>) => ReturnType<FC>;
50
+ declare const Table: <DataSource, U = Record<string, unknown>, ValueType = "text">(props: TableProps<DataSource, U, ValueType>) => ReturnType<FC>;
29
51
  export default Table;
@@ -1,4 +1,4 @@
1
- import type { FC } from "react";
1
+ import type { CSSProperties, FC, ReactNode } from "react";
2
2
 
3
3
  export interface WordProps {
4
4
  /** 是否显示弹窗 */
@@ -13,8 +13,10 @@ export interface WordProps {
13
13
  inline?: boolean;
14
14
  /** 弹窗标题 */
15
15
  title?: string;
16
- /** 内容样式 */
17
- style?: Record<string, any>;
16
+ /** 内联模式下的样式 */
17
+ style?: CSSProperties;
18
+ /** 弹窗底部额外的按钮 */
19
+ extraButtons?: ReactNode;
18
20
  }
19
21
 
20
22
  declare const Word: FC<WordProps>;
@@ -1 +1 @@
1
- import{Modal as r,Button as e,message as n,Spin as t}from"antd";import{renderAsync as i}from"docx-preview";import{useRef as o,useState as l,useEffect as a}from"react";import c from"../../hooks/useDownloadFile/index.js";import{getFileUrl as d}from"../../utils/index.js";import{jsx as u}from"react/jsx-runtime";function s(s){const{visible:f=!1,onCancel:m,file:p,name:h,inline:w=!1,title:g="Word预览",style:y={}}=s,v=o(null),x=o(null),k=o(!1),W=d(),[C,b]=l(!1),{downloadFile:T}=c();a(()=>{if(!f&&!w||!p)return;k.current=!1;const r=setTimeout(()=>{(async()=>{b(!0),v.current.innerHTML="";try{const r=await fetch(p.includes(W)?p:W+p);if(!r.ok)throw new Error("加载 Word 文件失败");const e=await r.arrayBuffer();if(k.current)return;await i(e,v.current,null,{className:"docx-preview",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,breakPages:!0})}catch{n.error("加载 Word 文件失败"),!w&&m&&m()}finally{k.current||b(!1)}})()},100);return()=>{k.current=!0,v.current&&(v.current.innerHTML=""),r&&clearTimeout(r)}},[f,w,p]);const j=()=>u(t,{spinning:C,children:u("div",{style:{height:"72vh",overflowY:"auto",padding:"24px",background:"#f5f5f5",...y},children:u("div",{ref:v})})});return w?j():u("div",{ref:x,children:u(r,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:f,mask:{closable:!1},width:900,title:g,onCancel:()=>{m()},getContainer:!1,footer:[u(e,{onClick:()=>{m()},children:"关闭"},"cancel"),u(e,{type:"primary",onClick:()=>{T({url:p,name:h})},children:"下载"},"download")],children:j()})})}s.displayName="Word";export{s as default};
1
+ import{Modal as r,Button as e,message as n,Spin as t}from"antd";import{renderAsync as i}from"docx-preview";import{useRef as o,useState as a,useEffect as l}from"react";import c from"../../hooks/useDownloadFile/index.js";import{getFileUrl as d}from"../../utils/index.js";import{jsx as u}from"react/jsx-runtime";function s(s){const{visible:f=!1,onCancel:m,file:p,name:h,inline:w=!1,title:g="Word预览",style:x={},extraButtons:y}=s,v=o(null),k=o(null),W=o(!1),C=d(),[b,T]=a(!1),{downloadFile:j}=c();l(()=>{if(!f&&!w||!p)return;W.current=!1;const r=setTimeout(()=>{(async()=>{T(!0),v.current.innerHTML="";try{const r=await fetch(p.includes(C)?p:C+p);if(!r.ok)throw new Error("加载 Word 文件失败");const e=await r.arrayBuffer();if(W.current)return;await i(e,v.current,null,{className:"docx-preview",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,breakPages:!0})}catch{n.error("加载 Word 文件失败"),!w&&m&&m()}finally{W.current||T(!1)}})()},100);return()=>{W.current=!0,v.current&&(v.current.innerHTML=""),r&&clearTimeout(r)}},[f,w,p]);const B=()=>u(t,{spinning:b,children:u("div",{style:{height:"72vh",overflowY:"auto",padding:"24px",background:"#f5f5f5",...x},children:u("div",{ref:v})})});return w?B():u("div",{ref:k,children:u(r,{style:{top:100,maxWidth:"calc(100vw - 32px)",paddingBottom:24},open:f,mask:{closable:!1},width:900,title:g,onCancel:()=>{m()},getContainer:!1,footer:[u(e,{onClick:()=>{m()},children:"关闭"},"cancel"),u(e,{type:"primary",onClick:()=>{j({url:p,name:h})},children:"下载"},"download"),...y||[]],children:B()})})}s.displayName="Word";export{s as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zy-react-library",
3
3
  "private": false,
4
- "version": "2.2.0",
4
+ "version": "2.2.2",
5
5
  "type": "module",
6
6
  "description": "",
7
7
  "author": "LiuJiaNan",
@@ -75,5 +75,9 @@
75
75
  "antd": ">=6.4.4 <7",
76
76
  "react": ">=18.3.1 <19",
77
77
  "zy-react-data": ">=1.0.0"
78
+ },
79
+ "publishConfig": {
80
+ "access": "public",
81
+ "registry": "https://registry.npmjs.org/"
78
82
  }
79
83
  }