@jzwd/vnd-design 0.0.0-stage → 0.2.0

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.
Files changed (47) hide show
  1. package/README.md +259 -2
  2. package/dist/file-center/api/endpoints.d.ts +42 -0
  3. package/dist/file-center/api/endpoints.js +45 -0
  4. package/dist/file-center/api/error.d.ts +6 -0
  5. package/dist/file-center/api/error.js +34 -0
  6. package/dist/file-center/api/index.d.ts +64 -0
  7. package/dist/file-center/api/index.js +238 -0
  8. package/dist/file-center/api/request.d.ts +28 -0
  9. package/dist/file-center/api/request.js +170 -0
  10. package/dist/file-center/api/token.d.ts +10 -0
  11. package/dist/file-center/api/token.js +122 -0
  12. package/dist/file-center/components/FcFileList/index.d.ts +39 -0
  13. package/dist/file-center/components/FcFileList/index.js +804 -0
  14. package/dist/file-center/components/FcFileList/style.css +106 -0
  15. package/dist/file-center/components/FcImage/index.d.ts +30 -0
  16. package/dist/file-center/components/FcImage/index.js +144 -0
  17. package/dist/file-center/components/FcImage/style.css +14 -0
  18. package/dist/file-center/components/FcUpload/index.d.ts +5 -0
  19. package/dist/file-center/components/FcUpload/index.js +642 -0
  20. package/dist/file-center/components/FcUpload/interface.d.ts +65 -0
  21. package/dist/file-center/components/FcUpload/interface.js +1 -0
  22. package/dist/file-center/components/FcUpload/style.css +279 -0
  23. package/dist/file-center/context.d.ts +22 -0
  24. package/dist/file-center/context.js +22 -0
  25. package/dist/file-center/index.d.ts +26 -0
  26. package/dist/file-center/index.js +21 -0
  27. package/dist/file-center/types.d.ts +144 -0
  28. package/dist/file-center/types.js +1 -0
  29. package/dist/file-center/upload.d.ts +35 -0
  30. package/dist/file-center/upload.js +295 -0
  31. package/dist/file-center/utils/common.d.ts +10 -0
  32. package/dist/file-center/utils/common.js +165 -0
  33. package/dist/file-center/utils/compress.d.ts +18 -0
  34. package/dist/file-center/utils/compress.js +108 -0
  35. package/dist/file-center/utils/md5.d.ts +5 -0
  36. package/dist/file-center/utils/md5.js +41 -0
  37. package/dist/index.d.ts +11 -0
  38. package/dist/index.js +15 -0
  39. package/dist/mobile/FcImage/index.d.ts +26 -0
  40. package/dist/mobile/FcImage/index.js +114 -0
  41. package/dist/mobile/FcImage/style.css +11 -0
  42. package/dist/mobile/FcUpload/index.d.ts +74 -0
  43. package/dist/mobile/FcUpload/index.js +539 -0
  44. package/dist/mobile/FcUpload/style.css +233 -0
  45. package/dist/mobile/index.d.ts +13 -0
  46. package/dist/mobile/index.js +9 -0
  47. package/package.json +70 -4
package/README.md CHANGED
@@ -1,3 +1,260 @@
1
- # Temporary Holding Version
1
+ # Vnd design(简称 Vnd)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 公司业务组件库。**Vnd design 继承 antd 的全部组件**:业务方只需从一个入口引入,即可同时拿到 antd 组件与 Vnd 自有业务组件,不必再从 antd 单独引一次。
4
+
5
+ 当前已封装的业务模块:**文件中心(FileCenter)**。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install @jzwd/vnd-design
11
+ ```
12
+
13
+ 对等依赖(业务项目需自行安装):`react >= 17`、`antd >= 5`、`@ant-design/icons >= 5`、`dayjs >= 1.11`。
14
+
15
+ ## 一个入口,拿到 antd 全部组件 + Vnd 业务组件
16
+
17
+ `@jzwd/vnd-design` 的主入口已 `export * from 'antd'`,所以 antd 的组件、类型可以直接从这里引入:
18
+
19
+ ```tsx
20
+ // antd 组件:Vnd design 已全量再导出,不需要再 from 'antd'
21
+ import { Button, Table, Form, message, ConfigProvider } from '@jzwd/vnd-design';
22
+
23
+ // Vnd 自有业务组件:同一个入口
24
+ import { FcUpload, FcImage, FcFileList } from '@jzwd/vnd-design';
25
+ ```
26
+
27
+ > 移动端子路径 `@jzwd/vnd-design/mobile` 提供基于 antd-mobile 的业务组件。
28
+ > 若也需要「一个入口拿到 antd-mobile 全部组件」,在该子入口加一行 `export * from 'antd-mobile'` 即可。
29
+
30
+ ## 文件中心模块
31
+
32
+ 对应《文件中心需求文档》第九章「业务组件库」的对接约定:业务项目**零接口开发**接入文件中心,只需把项目注册后拿到的 AppKey 传给组件,换令牌、上传、秒传、进度、失败重试、私有签名刷新、引用登记全部由组件内部完成。
33
+
34
+ ### 第一步:传入 appKey
35
+
36
+ 无需在应用根部包任何 Provider,直接在组件上传 `appKey` 即可;`baseUrl` 已内置默认值 `https://upload.yydslgd.cn`,一般不用传:
37
+
38
+ ```tsx
39
+ import { FcUpload } from '@jzwd/vnd-design';
40
+
41
+ // 最简:只传 appKey
42
+ <FcUpload appKey="你的项目AppKey" listType="picture-card" />;
43
+
44
+ // 特殊环境(联调 / 私有化部署)才需覆盖 baseUrl
45
+ <FcUpload appKey="你的项目AppKey" baseUrl="https://upload.yydslgd.cn" />;
46
+ ```
47
+
48
+ > 令牌获取默认走文件中心 OPEN-1 接口(AppKey 换令牌,组件内部自动缓存与刷新)。
49
+ > 如果后续服务端要求更高安全性(AppKey + AppSecret 在业务服务端换令牌),
50
+ > 可通过组件的 `getToken` prop 覆盖,其他代码不用改:
51
+ >
52
+ > ```tsx
53
+ > <FcUpload
54
+ > appKey="你的项目AppKey"
55
+ > getToken={appKey => fetch(`/api/my-server/fc-token?appKey=${appKey}`).then(r => r.json())}
56
+ > />
57
+ > ```
58
+
59
+ ### FcUpload 上传组件
60
+
61
+ 三种形态:图片卡片墙(默认)、文件列表、拖拽上传。
62
+
63
+ ```tsx
64
+ import { Form } from 'antd';
65
+ import { FcUpload } from '@jzwd/vnd-design';
66
+
67
+ // 图片卡片墙(头像、商品图场景),可直接放进 antd Form
68
+ <Form.Item name="images" label="商品图">
69
+ <FcUpload
70
+ appKey="你的项目AppKey" // 项目 AppKey(baseUrl 不传则走内置默认地址)
71
+ listType="picture-card"
72
+ maxCount={5}
73
+ maxSizeMB={20}
74
+ accept="image/*"
75
+ compress // 上传前自动压缩图片
76
+ bizType="goodsImage" // 业务标签
77
+ bizId={goodsId} // 传了 bizId 时,上传成功自动登记业务引用(OPEN-12)
78
+ bizUrl={`/goods/${goodsId}`}
79
+ />
80
+ </Form.Item>
81
+
82
+ // 文件列表 + 拖拽形态(附件、文档场景)
83
+ <FcUpload appKey="你的项目AppKey" listType="text" drag multiple maxCount={10} buttonText="上传附件" />
84
+ ```
85
+
86
+ 主要能力:
87
+
88
+ | 能力 | 说明 |
89
+ | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
90
+ | 秒传 | 上传前算 MD5 调 OPEN-4,同文件已存在时直接返回,不传实体 |
91
+ | 分片上传 | 超过 10MB 自动走 OPEN-5 分片(初始化 → 逐片 → 合并),支持断点续传 |
92
+ | 失败重试 | 普通上传与每个分片自动重试 2 次 |
93
+ | 进度展示 | MD5 校验占 10%、上传占 90%,卡片形态有环形进度、列表形态有进度条 |
94
+ | 图片压缩 | `compress` 开启,gif/svg 与小于 100KB 的图片自动跳过 |
95
+ | 取消上传 | 上传中点删除即中断请求 |
96
+ | 引用溯源删除 | `deleteOnRemove` 开启后,删除时若文件存在业务引用,弹窗展示全部引用(项目 / 业务类型 / 业务记录 / 可点击链接),勾选「我已知晓影响范围」才能删 |
97
+ | 复制 URL | 上传成功后悬浮卡片或行操作里一键复制 |
98
+
99
+ `value` / `onChange` 与 antd Form 完全兼容,文件项上额外带 `fileId`(文件中心文件 ID)与 `fileInfo`(完整元数据),业务表里存哪个都行。
100
+
101
+ ### FcImage 图片回显组件
102
+
103
+ ```tsx
104
+ import { FcImage } from '@jzwd/vnd-design';
105
+
106
+ // 业务表存的是文件 ID:组件自动调 OPEN-9 换取可访问 URL
107
+ <FcImage appKey="你的项目AppKey" fileId={record.avatarFileId} width={80} height={80} />
108
+
109
+ // 业务表存的是 URL:直接回显
110
+ <FcImage appKey="你的项目AppKey" src={record.avatarUrl} width={80} />
111
+ ```
112
+
113
+ 私有文件签名 URL 过期导致加载失败时,自动调 OPEN-11 刷新签名并重试一次,业务方无感。其余属性与 antd `Image` 一致(预览、占位、圆角等直接透传)。
114
+
115
+ ### FcFileList 文件列表组件
116
+
117
+ 对应需求 3.2.3 的核心页面能力,适合嵌到业务系统内部管理页:
118
+
119
+ ```tsx
120
+ import { FcFileList } from '@jzwd/vnd-design';
121
+
122
+ <FcFileList
123
+ appKey="你的项目AppKey"
124
+ bizTypes={[
125
+ { label: '商品图', value: 'goodsImage' },
126
+ { label: '内容图', value: 'contentImage' }
127
+ ]}
128
+ defaultView="table"
129
+ />;
130
+ ```
131
+
132
+ - 查询本项目文件(OPEN-7),支持名称模糊、业务标签、文件类型、时间范围筛选,分页;
133
+ - **表格 / 图片宫格**两种视图切换;
134
+ - 行操作:预览(图片灯箱 / 视频播放 / PDF 内嵌)、复制 URL、下载、刷新签名(私有文件)、删除;
135
+ - 删除时展示该文件的全部业务引用(OPEN-14),勾选确认后才能删除(OPEN-10)。
136
+
137
+ ### uploadFile 无界面上传函数
138
+
139
+ 需要完全自定义 UI 时,可直接使用上传函数,能力与 `FcUpload` 内部一致:
140
+
141
+ ```tsx
142
+ import { uploadFile } from '@jzwd/vnd-design';
143
+
144
+ const fileInfo = await uploadFile({
145
+ file, // File 对象
146
+ appKey: '你的AppKey', // baseUrl 不传则走内置默认地址
147
+ bizType: 'goodsImage',
148
+ bizInfo: { bizType: 'goodsImage', bizId: '1001', bizUrl: '/goods/1001' },
149
+ compress: true,
150
+ onProgress: ({ percent, stage }) => console.log(stage, percent),
151
+ signal: controller.signal // 可取消
152
+ });
153
+ console.log(fileInfo.id, fileInfo.url);
154
+ ```
155
+
156
+ ## 目录结构
157
+
158
+ ```
159
+ src/
160
+ ├── index.ts # 组件库总入口
161
+ └── file-center/ # 文件中心模块
162
+ ├── context.ts # 组件 props → 请求上下文解析(内置 baseUrl 默认值)
163
+ ├── types.ts # 类型契约(按需求文档预定义)
164
+ ├── upload.ts # 上传编排:压缩→MD5→秒传→分片/普通→登记引用
165
+ ├── api/ # 接口契约层
166
+ │ ├── endpoints.ts # OPEN-1~14 接口路径表(服务端定稿后只改这里)
167
+ │ ├── error.ts # FcError 错误类
168
+ │ ├── token.ts # 令牌缓存/并发去重/可插拔适配器
169
+ │ ├── request.ts # JSON 请求(401 自动刷新重试)
170
+ │ └── index.ts # 各开放接口函数 + 表单上传(XHR 带进度)
171
+ ├── components/
172
+ │ ├── FcUpload/ # 上传组件
173
+ │ ├── FcImage/ # 回显组件
174
+ │ └── FcFileList/ # 文件列表组件
175
+ └── utils/ # MD5、图片压缩、复制/下载/重试等工具
176
+ ```
177
+
178
+ ## 开发
179
+
180
+ ```bash
181
+ npm install # 安装依赖
182
+ npm run typecheck # 类型检查
183
+ npm run build # 构建产物到 dist(ESM + 类型声明)
184
+ ```
185
+
186
+ ## 移动端组件(H5)
187
+
188
+ 同一包内通过子路径提供基于 **antd-mobile** 的移动端组件,与 PC 端共用同一套接口契约与上传编排(压缩 → MD5 → 秒传 → 分片/普通上传 → 引用登记):
189
+
190
+ ```bash
191
+ # 移动端额外需要安装(纯 PC 项目不用装,已声明为可选对等依赖)
192
+ npm install antd-mobile antd-mobile-icons
193
+ ```
194
+
195
+ ```tsx
196
+ import { FcUpload, FcImage } from '@jzwd/vnd-design/mobile';
197
+
198
+ const APP_KEY = '你的AppKey';
199
+
200
+ {
201
+ /* 图片宫格:支持调起相机、压缩、引用自动登记 */
202
+ }
203
+ <FcUpload appKey={APP_KEY} listType="picture-card" capture compress bizType="goodsImage" bizId="1001" />;
204
+ {
205
+ /* 文件列表形态 */
206
+ }
207
+ <FcUpload appKey={APP_KEY} listType="text" multiple deleteOnRemove />;
208
+ {
209
+ /* 按文件 ID 回显,点按全屏预览,签名失效自动刷新 */
210
+ }
211
+ <FcImage appKey={APP_KEY} fileId="文件ID" width={72} height={72} />;
212
+ ```
213
+
214
+ 移动端与 PC 端差异点:`capture` 属性可直接调起相机;图片预览用 antd-mobile 的全屏预览器;引用溯源确认弹窗为移动端交互(底部勾选知晓后删除)。
215
+
216
+ ## 本地联调(不发包即可在浏览器里跑通全链路)
217
+
218
+ 仓库内置了一个**模拟文件中心服务端**和**演示应用**,不依赖真实后端、不依赖发布:
219
+
220
+ ```bash
221
+ npm run mock # 终端一:启动模拟文件中心(端口 4000,实现 OPEN-1~14 全部契约)
222
+ npm run playground # 终端二:启动演示应用(端口 5173)
223
+ ```
224
+
225
+ 打开 http://localhost:5173 即可体验三个组件的全部形态;http://localhost:5173/mobile.html 是移动端演示页(手机框内展示移动端组件)。演示应用通过别名直接引用组件库**源码**(见 `vite.playground.config.ts`),改 `src` 下任何组件代码都会即时热更新,联调效率等同在业务项目里改代码。
226
+
227
+ - 模拟服务端的数据存在 `mock/storage/`(已加入忽略清单),重启不丢失,想清空直接删该目录;
228
+ - 验证分片上传:选一个大于 10MB 的文件;验证秒传:同一文件传第二次;验证引用溯源删除:删除卡片墙传上去的文件(上传时已自动登记演示引用)。
229
+
230
+ ### 在真实业务项目里本地引用(发包前的过渡方案)
231
+
232
+ **方式一(推荐,Vite 业务项目)**:在业务项目的 Vite 配置里加别名,直接指向组件库源码或 dist:
233
+
234
+ ```ts
235
+ // 业务项目 vite.config.ts
236
+ resolve: {
237
+ alias: {
238
+ '@jzwd/vnd-design': '/路径/到/busComponent/src/index.ts',
239
+ },
240
+ dedupe: ['react', 'react-dom', 'antd'],
241
+ }
242
+ ```
243
+
244
+ **方式二(npm link,不限构建工具)**:
245
+
246
+ ```bash
247
+ # 组件库目录执行(先构建一次)
248
+ npm run build && npm link
249
+ # 业务项目目录执行
250
+ npm link @jzwd/vnd-design
251
+ ```
252
+
253
+ 注意:npm link 会让组件库解析到自己目录下的依赖副本,可能出现 React 双实例报错(hooks 报错);遇此情况在业务项目里把 react/react-dom 也做别名或 dedupe 指向业务项目自己的副本即可。
254
+
255
+ ## 与服务端的对接说明
256
+
257
+ 文件中心服务端(FileCenterApi)尚在开发中。本库按需求文档 v1.1 预先定义了接口契约
258
+ (`src/file-center/types.ts` 与 `src/file-center/api/endpoints.ts`),
259
+ 服务端实现时按此契约开发即可无缝对接;若有出入,只需调整 `api` 目录内少量代码,
260
+ 组件调用方不受影响。
@@ -0,0 +1,42 @@
1
+ /**
2
+ * 文件中心开放接口路径表(对应需求文档 OPEN-1 ~ OPEN-14)
3
+ * 服务端接口定稿后如有出入,仅需修改此文件。
4
+ */
5
+ export declare const FC_ENDPOINTS: {
6
+ /** OPEN-1 获取访问令牌 */
7
+ readonly auth: "/open/auth/token";
8
+ /** OPEN-2 普通上传 */
9
+ readonly upload: "/open/files/upload";
10
+ /** OPEN-3 批量上传 */
11
+ readonly uploadBatch: "/open/files/upload-batch";
12
+ /** OPEN-4 秒传校验 */
13
+ readonly instant: "/open/files/instant";
14
+ /** OPEN-5 分片上传:初始化 */
15
+ readonly chunkInit: "/open/files/chunk/init";
16
+ /** OPEN-5 分片上传:传分片 */
17
+ readonly chunkUpload: "/open/files/chunk/upload";
18
+ /** OPEN-5 分片上传:合并 */
19
+ readonly chunkMerge: "/open/files/chunk/merge";
20
+ /** OPEN-7 文件列表 */
21
+ readonly list: "/open/files";
22
+ /** OPEN-8 文件详情(拼接 /{id}) */
23
+ readonly detail: "/open/files";
24
+ /** OPEN-9 批量取 URL */
25
+ readonly urls: "/open/files/urls";
26
+ /** OPEN-10 删除文件(拼接 /{id}) */
27
+ readonly remove: "/open/files";
28
+ /** OPEN-11 刷新签名(拼接 /{id}/refresh-sign) */
29
+ readonly refreshSign: "/open/files";
30
+ /** OPEN-12 登记引用 */
31
+ readonly refAdd: "/open/references";
32
+ /** OPEN-13 解除引用 */
33
+ readonly refRemove: "/open/references";
34
+ /** OPEN-14 查询文件引用(拼接 /{fileId}) */
35
+ readonly refList: "/open/references";
36
+ };
37
+ /** 默认大文件分片阈值:10MB */
38
+ export declare const DEFAULT_CHUNK_THRESHOLD: number;
39
+ /** 默认分片大小:5MB */
40
+ export declare const DEFAULT_CHUNK_SIZE: number;
41
+ /** 令牌过期提前量(毫秒):到期前 1 分钟即视为过期 */
42
+ export declare const TOKEN_EXPIRE_AHEAD: number;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 文件中心开放接口路径表(对应需求文档 OPEN-1 ~ OPEN-14)
3
+ * 服务端接口定稿后如有出入,仅需修改此文件。
4
+ */
5
+ export var FC_ENDPOINTS = {
6
+ /** OPEN-1 获取访问令牌 */
7
+ auth: '/open/auth/token',
8
+ /** OPEN-2 普通上传 */
9
+ upload: '/open/files/upload',
10
+ /** OPEN-3 批量上传 */
11
+ uploadBatch: '/open/files/upload-batch',
12
+ /** OPEN-4 秒传校验 */
13
+ instant: '/open/files/instant',
14
+ /** OPEN-5 分片上传:初始化 */
15
+ chunkInit: '/open/files/chunk/init',
16
+ /** OPEN-5 分片上传:传分片 */
17
+ chunkUpload: '/open/files/chunk/upload',
18
+ /** OPEN-5 分片上传:合并 */
19
+ chunkMerge: '/open/files/chunk/merge',
20
+ /** OPEN-7 文件列表 */
21
+ list: '/open/files',
22
+ /** OPEN-8 文件详情(拼接 /{id}) */
23
+ detail: '/open/files',
24
+ /** OPEN-9 批量取 URL */
25
+ urls: '/open/files/urls',
26
+ /** OPEN-10 删除文件(拼接 /{id}) */
27
+ remove: '/open/files',
28
+ /** OPEN-11 刷新签名(拼接 /{id}/refresh-sign) */
29
+ refreshSign: '/open/files',
30
+ /** OPEN-12 登记引用 */
31
+ refAdd: '/open/references',
32
+ /** OPEN-13 解除引用 */
33
+ refRemove: '/open/references',
34
+ /** OPEN-14 查询文件引用(拼接 /{fileId}) */
35
+ refList: '/open/references'
36
+ };
37
+
38
+ /** 默认大文件分片阈值:10MB */
39
+ export var DEFAULT_CHUNK_THRESHOLD = 10 * 1024 * 1024;
40
+
41
+ /** 默认分片大小:5MB */
42
+ export var DEFAULT_CHUNK_SIZE = 5 * 1024 * 1024;
43
+
44
+ /** 令牌过期提前量(毫秒):到期前 1 分钟即视为过期 */
45
+ export var TOKEN_EXPIRE_AHEAD = 60 * 1000;
@@ -0,0 +1,6 @@
1
+ /** 文件中心接口/上传过程错误 */
2
+ export declare class FcError extends Error {
3
+ /** 业务错误码;HTTP 层错误时为 HTTP 状态码;主动取消时为 'ABORT' */
4
+ code: number | string;
5
+ constructor(message: string, code?: number | string);
6
+ }
@@ -0,0 +1,34 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
3
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
6
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
8
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
9
+ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
10
+ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
11
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
+ function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
13
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
15
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
+ /** 文件中心接口/上传过程错误 */
19
+ export var FcError = /*#__PURE__*/function (_Error) {
20
+ _inherits(FcError, _Error);
21
+ var _super = _createSuper(FcError);
22
+ function FcError(message) {
23
+ var _this;
24
+ var code = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
25
+ _classCallCheck(this, FcError);
26
+ _this = _super.call(this, message);
27
+ /** 业务错误码;HTTP 层错误时为 HTTP 状态码;主动取消时为 'ABORT' */
28
+ _defineProperty(_assertThisInitialized(_this), "code", void 0);
29
+ _this.name = 'FcError';
30
+ _this.code = code;
31
+ return _this;
32
+ }
33
+ return _createClass(FcError);
34
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
@@ -0,0 +1,64 @@
1
+ import type { FcRequestContext } from './request';
2
+ import type { FcBizInfo, FcDeleteResult, FcFileListQuery, FcFileInfo, FcFileReference, FcInstantUploadResult, FcPageResult } from '../types';
3
+ export { FC_ENDPOINTS, DEFAULT_CHUNK_SIZE, DEFAULT_CHUNK_THRESHOLD } from './endpoints';
4
+ export { FcError } from './error';
5
+ export { fcRequest } from './request';
6
+ export type { FcRequestContext } from './request';
7
+ export { ensureToken, invalidateToken } from './token';
8
+ /** 带表单体的请求(上传类接口共用):自动携带令牌,401 刷新重试一次 */
9
+ export declare function fcFormRequest<T>(ctx: FcRequestContext, path: string, form: FormData, options?: {
10
+ signal?: AbortSignal;
11
+ onProgress?: (percent: number) => void;
12
+ }): Promise<T>;
13
+ export declare function checkInstantUpload(ctx: FcRequestContext, params: {
14
+ md5: string;
15
+ name: string;
16
+ size: number;
17
+ bizType?: string;
18
+ }): Promise<FcInstantUploadResult>;
19
+ export declare function initChunkUpload(ctx: FcRequestContext, params: {
20
+ md5: string;
21
+ name: string;
22
+ size: number;
23
+ totalParts: number;
24
+ bizType?: string;
25
+ }): Promise<{
26
+ uploadId: string;
27
+ chunkSize?: number;
28
+ doneParts?: number[];
29
+ }>;
30
+ export declare function uploadChunk(ctx: FcRequestContext, params: {
31
+ uploadId: string;
32
+ partNumber: number;
33
+ blob: Blob;
34
+ }, options?: {
35
+ signal?: AbortSignal;
36
+ onProgress?: (percent: number) => void;
37
+ }): Promise<void>;
38
+ export declare function mergeChunkUpload(ctx: FcRequestContext, params: {
39
+ uploadId: string;
40
+ }): Promise<FcFileInfo>;
41
+ export declare function fetchFileList(ctx: FcRequestContext, query?: FcFileListQuery): Promise<FcPageResult<FcFileInfo>>;
42
+ export declare function fetchFileDetail(ctx: FcRequestContext, fileId: string): Promise<FcFileInfo>;
43
+ /** OPEN-9 批量取可访问 URL(私有文件返回带签名的临时 URL),回显图片核心接口 */
44
+ export declare function fetchFileUrls(ctx: FcRequestContext, fileIds: string[]): Promise<Record<string, string>>;
45
+ /** OPEN-10 删除文件(逻辑删除);存在业务引用时返回引用列表要求二次确认 */
46
+ export declare function deleteFile(ctx: FcRequestContext, fileId: string, options?: {
47
+ force?: boolean;
48
+ }): Promise<FcDeleteResult>;
49
+ /** OPEN-11 刷新私有文件签名 URL */
50
+ export declare function refreshFileSign(ctx: FcRequestContext, fileId: string): Promise<{
51
+ url: string;
52
+ }>;
53
+ /** OPEN-12 登记引用(支持批量) */
54
+ export declare function addReferences(ctx: FcRequestContext, refs: Array<FcBizInfo & {
55
+ fileId: string;
56
+ }>): Promise<void>;
57
+ /** OPEN-13 解除引用 */
58
+ export declare function removeReference(ctx: FcRequestContext, params: {
59
+ fileId: string;
60
+ bizType: string;
61
+ bizId: string;
62
+ }): Promise<void>;
63
+ /** OPEN-14 查询文件的全部引用记录 */
64
+ export declare function fetchReferences(ctx: FcRequestContext, fileId: string): Promise<FcFileReference[]>;