Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
ujia
/
uj-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit e941562e
authored
Nov 17, 2026
by
chenwq
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'v1.0.0' of
http://192.168.3.233:8090/ujia/uj-admin
into v1.0.0
2 parents
fdcdc2e9
0fbfe84d
Pipeline
#511
for
e941562e
failed
in 0 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
141 additions
and
12 deletions
docs/PORT_CONVERSION.md
packages/download-center/src/deliver.ts
packages/download-center/src/handlers/simple.ts
packages/ui/src/components/FillTable/index.tsx
packages/ui/src/components/Table/imageCell.tsx
packages/ui/src/components/Table/index.tsx
docs/PORT_CONVERSION.md
View file @
e941562
...
@@ -408,6 +408,8 @@ downloadCenter.register({ ... }); // 显式 kind / 自定义 kind 的统一登
...
@@ -408,6 +408,8 @@ downloadCenter.register({ ... }); // 显式 kind / 自定义 kind 的统一登
公共字段(
`CommonDownloadInput`
):
`source`
、
`label`
、
`fileName`
、
`autoDownload`
(默认 true;false 只进面板供点击)、
`silent`
(默认 false)、
`dedupeKey`
(防连点去重)、
`channel`
(多网关,见 14.6)。
公共字段(
`CommonDownloadInput`
):
`source`
、
`label`
、
`fileName`
、
`autoDownload`
(默认 true;false 只进面板供点击)、
`silent`
(默认 false)、
`dedupeKey`
(防连点去重)、
`channel`
(多网关,见 14.6)。
`async-export`
另可覆盖:
`submitMethod`
/
`queryMethod`
/
`pollInterval`
(默认 3000ms)/
`timeoutMs`
(默认 10 分钟)。
`async-export`
另可覆盖:
`submitMethod`
/
`queryMethod`
/
`pollInterval`
(默认 3000ms)/
`timeoutMs`
(默认 10 分钟)。
**`url` kind 会在执行前归一明文地址**
:HTTPS 主壳 +
`http://`
直链时,
`packages/download-center/src/deliver.ts`
的
`upgradeInsecureUrl()`
把协议换成 https
**并丢掉原 HTTP 业务端口**
(回单
`http://qcimg01.glsx.com.cn:7060/...`
→
`https://qcimg01.glsx.com.cn/...`
,443 上返回同一份文件)。业务页只管把后端给的地址原样交给
`downloadCenter.url()`
,
**不要自己改协议**
。
### 14.5 后端零改动:对齐源系统的异步导出协议
### 14.5 后端零改动:对齐源系统的异步导出协议
源系统(
`D:/work/saas+/dj-car-life-system`
)的公共编排接口,
**完整 method 带 `dj.api.` 前缀**
(
`src/api/sys.base.js`
的
`path = "dj.api."`
,别漏前缀);提交 / 轮询 / 通知 / 自动下载的实现见
`src/layout/header-aside/components/header-user/index.vue`
:
源系统(
`D:/work/saas+/dj-car-life-system`
)的公共编排接口,
**完整 method 带 `dj.api.` 前缀**
(
`src/api/sys.base.js`
的
`path = "dj.api."`
,别漏前缀);提交 / 轮询 / 通知 / 自动下载的实现见
`src/layout/header-aside/components/header-user/index.vue`
:
...
@@ -441,6 +443,7 @@ downloadCenter.register({ ... }); // 显式 kind / 自定义 kind 的统一登
...
@@ -441,6 +443,7 @@ downloadCenter.register({ ... }); // 显式 kind / 自定义 kind 的统一登
-
`<a href={fileUrl} target="_blank">`
/
`<UButton href={fileUrl}>`
**触发文件下载**
→ 同样禁止,改用
`downloadCenter.url()`
;纯外链预览 / H5 跳转不算下载(静态门禁只拦明确的文件落地写法,href 靠语义判定 + 代码评审)。
-
`<a href={fileUrl} target="_blank">`
/
`<UButton href={fileUrl}>`
**触发文件下载**
→ 同样禁止,改用
`downloadCenter.url()`
;纯外链预览 / H5 跳转不算下载(静态门禁只拦明确的文件落地写法,href 靠语义判定 + 代码评审)。
-
自己 POST 导出接口后只
`message.success('导出任务已提交')`
→ 漏了轮询 / 浮窗提示 / 历史,改用
`asyncExport()`
。
-
自己 POST 导出接口后只
`message.success('导出任务已提交')`
→ 漏了轮询 / 浮窗提示 / 历史,改用
`asyncExport()`
。
-
自己写
`content-disposition`
解析 / C0 控制字符清洗 / Blob 落地 → 已在
`deliver.ts`
统一实现,别抄第二份。
-
自己写
`content-disposition`
解析 / C0 控制字符清洗 / Blob 落地 → 已在
`deliver.ts`
统一实现,别抄第二份。
-
业务页自己
`url.replace(/^http:/, 'https:')`
升级协议 →
`url`
kind 已在
`upgradeInsecureUrl()`
里做,且
**必须连端口一起丢**
:
`http://qcimg01.glsx.com.cn:7060/x`
只换协议会得到
`https://qcimg01.glsx.com.cn:7060/x`
,该端口只跑裸 HTTP(TLS 握手
`ERR_SSL_PACKET_LENGTH_TOO_LONG`
),等于把「被浏览器 Mixed Content 拦」换成「网络错误」。
`apps/mp/usedcar/subvehicleConversion/utils/imageUrl.js`
的
`ensureHttpsUrl`
正是只换协议保留端口的写法,别照抄到 web 下载链路。
-
给下载接口拼 URL、手写 sign、直接
`axios`
/
`fetch`
拿流 → 违反 §1.1 与 §4。
-
给下载接口拼 URL、手写 sign、直接
`axios`
/
`fetch`
拿流 → 违反 §1.1 与 §4。
-
把
`@uj/download-center`
运行时 import 进子应用 → 子应用只依赖
`@uj/platform-sdk`
(登记)+
`@uj/contracts`
(类型)。
-
把
`@uj/download-center`
运行时 import 进子应用 → 子应用只依赖
`@uj/platform-sdk`
(登记)+
`@uj/contracts`
(类型)。
...
...
packages/download-center/src/deliver.ts
View file @
e941562
...
@@ -46,6 +46,51 @@ export function saveBlob(blob: Blob, fileName: string): void {
...
@@ -46,6 +46,51 @@ export function saveBlob(blob: Blob, fileName: string): void {
}
}
}
}
/** 本地回环地址没有 TLS 服务,浏览器本身也不拦,改写只会把它改坏。 */
const
LOCAL_HOSTNAMES
=
new
Set
([
'localhost'
,
'127.0.0.1'
,
'::1'
]);
/**
* 把 HTTPS 页面里的明文 HTTP 直链升级成 HTTPS,并去掉原 HTTP 业务端口。
*
* 为什么需要:后端历史数据里的文件直链仍是 http(典型是回单
* `http://qcimg01.glsx.com.cn:7060/group1/...`)。主壳是 HTTPS,这类地址交给浏览器
* 必然被 Mixed Content 拦死,assertDownloadableUrl 也会直接判任务失败。
*
* 规则:
* - 非 `http://` 开头(https / 相对路径 / data: / blob:)原样返回,不做任何加工;
* - 页面不是 https(本地 HTTP 开发、小程序 webview 白名单调试)时原样返回,
* 这类环境本来就能下明文地址,没必要改;
* - http 且页面 https:协议换 https,**并丢掉端口**。
*
* 为什么必须丢端口:同源站点的 HTTPS 监听在 443,而不在原来的 HTTP 业务端口上。
* 实测 `qcimg01.glsx.com.cn`:`:7060` 只跑裸 HTTP(TLS 握手直接
* `ERR_SSL_PACKET_LENGTH_TOO_LONG`,服务端把 ClientHello 当 HTTP 请求解析返回 400),
* 而 `https://qcimg01.glsx.com.cn/<同路径>` 返回的是同一份文件(200、字节数一致)。
* 只换协议不丢端口会得到 `https://host:7060/...`——照样连不上,只是把「被浏览器拦」
* 换成「网络错误」,问题从明处藏到暗处。
*
* 代价边界:改写只作用于「在 HTTPS 页面里本来必然失败」的地址,最坏结果是从一种
* 失败变成另一种失败,不会让原本可用的下载变坏。
*/
export
function
upgradeInsecureUrl
(
url
:
string
):
string
{
const
raw
=
String
(
url
??
''
).
trim
();
if
(
!
/^http:
\/\/
/i
.
test
(
raw
))
return
raw
;
if
(
typeof
window
===
'undefined'
||
window
.
location
.
protocol
!==
'https:'
)
return
raw
;
let
parsed
:
URL
;
try
{
parsed
=
new
URL
(
raw
);
}
catch
{
// 解析不了就交给后面的 assertDownloadableUrl 报「地址无效」,这里不抢判断。
return
raw
;
}
if
(
LOCAL_HOSTNAMES
.
has
(
parsed
.
hostname
))
return
raw
;
parsed
.
protocol
=
'https:'
;
parsed
.
port
=
''
;
return
parsed
.
toString
();
}
/**
/**
* 下载地址前置校验:在把 URL 交给 iframe / 锚点之前,先拦截「发起前即可判定」的错误。
* 下载地址前置校验:在把 URL 交给 iframe / 锚点之前,先拦截「发起前即可判定」的错误。
*
*
...
@@ -68,7 +113,7 @@ export function assertDownloadableUrl(url: string): void {
...
@@ -68,7 +113,7 @@ export function assertDownloadableUrl(url: string): void {
if
(
if
(
window
.
location
.
protocol
===
'https:'
&&
window
.
location
.
protocol
===
'https:'
&&
parsed
.
protocol
===
'http:'
&&
parsed
.
protocol
===
'http:'
&&
!
[
'localhost'
,
'127.0.0.1'
,
'::1'
].
include
s
(
parsed
.
hostname
)
!
LOCAL_HOSTNAMES
.
ha
s
(
parsed
.
hostname
)
)
{
)
{
throw
new
Error
(
throw
new
Error
(
`下载地址被浏览器拦截:当前页面为 HTTPS,但文件地址是明文 HTTP(
${
parsed
.
host
}
)。`
+
`下载地址被浏览器拦截:当前页面为 HTTPS,但文件地址是明文 HTTP(
${
parsed
.
host
}
)。`
+
...
@@ -188,7 +233,9 @@ export async function probeDownloadUrl(
...
@@ -188,7 +233,9 @@ export async function probeDownloadUrl(
* 同源、需要签名头才能取到的文件必须走 stream kind,经主壳 request 拿流。
* 同源、需要签名头才能取到的文件必须走 stream kind,经主壳 request 拿流。
*/
*/
export
function
openUrl
(
url
:
string
,
openInNewTab
=
true
):
void
{
export
function
openUrl
(
url
:
string
,
openInNewTab
=
true
):
void
{
assertDownloadableUrl
(
url
);
// 兜住所有直接调 openUrl 的入口(不限 urlHandler):明文地址先升级再校验。
const
target
=
upgradeInsecureUrl
(
url
);
assertDownloadableUrl
(
target
);
if
(
openInNewTab
)
{
if
(
openInNewTab
)
{
const
iframe
=
document
.
createElement
(
'iframe'
);
const
iframe
=
document
.
createElement
(
'iframe'
);
iframe
.
style
.
position
=
'fixed'
;
iframe
.
style
.
position
=
'fixed'
;
...
@@ -198,14 +245,14 @@ export function openUrl(url: string, openInNewTab = true): void {
...
@@ -198,14 +245,14 @@ export function openUrl(url: string, openInNewTab = true): void {
iframe
.
style
.
left
=
'-9999px'
;
iframe
.
style
.
left
=
'-9999px'
;
iframe
.
style
.
top
=
'-9999px'
;
iframe
.
style
.
top
=
'-9999px'
;
iframe
.
setAttribute
(
'aria-hidden'
,
'true'
);
iframe
.
setAttribute
(
'aria-hidden'
,
'true'
);
iframe
.
src
=
url
;
iframe
.
src
=
target
;
document
.
body
.
appendChild
(
iframe
);
document
.
body
.
appendChild
(
iframe
);
// 下载由浏览器接管后移除 iframe,避免长期驻留;时长足以覆盖大文件落盘启动。
// 下载由浏览器接管后移除 iframe,避免长期驻留;时长足以覆盖大文件落盘启动。
setTimeout
(()
=>
iframe
.
remove
(),
60
_000
);
setTimeout
(()
=>
iframe
.
remove
(),
60
_000
);
return
;
return
;
}
}
const
link
=
document
.
createElement
(
'a'
);
const
link
=
document
.
createElement
(
'a'
);
link
.
href
=
url
;
link
.
href
=
target
;
link
.
rel
=
'noreferrer'
;
link
.
rel
=
'noreferrer'
;
document
.
body
.
appendChild
(
link
);
document
.
body
.
appendChild
(
link
);
link
.
click
();
link
.
click
();
...
...
packages/download-center/src/handlers/simple.ts
View file @
e941562
...
@@ -5,7 +5,7 @@ import type {
...
@@ -5,7 +5,7 @@ import type {
DownloadResult
,
DownloadResult
,
UrlPayload
,
UrlPayload
,
}
from
'../types'
;
}
from
'../types'
;
import
{
assertDownloadableUrl
,
blobFromBase64
,
probeDownloadUrl
}
from
'../deliver'
;
import
{
assertDownloadableUrl
,
blobFromBase64
,
probeDownloadUrl
,
upgradeInsecureUrl
}
from
'../deliver'
;
/** 从 URL 路径末段推断文件名(预签名 URL 的 query 不参与)。 */
/** 从 URL 路径末段推断文件名(预签名 URL 的 query 不参与)。 */
function
fileNameFromUrl
(
url
:
string
):
string
{
function
fileNameFromUrl
(
url
:
string
):
string
{
...
@@ -27,12 +27,17 @@ export const urlHandler: DownloadHandler = {
...
@@ -27,12 +27,17 @@ export const urlHandler: DownloadHandler = {
async
execute
(
task
,
ctx
):
Promise
<
DownloadResult
>
{
async
execute
(
task
,
ctx
):
Promise
<
DownloadResult
>
{
const
payload
=
task
.
input
.
payload
as
UrlPayload
;
const
payload
=
task
.
input
.
payload
as
UrlPayload
;
if
(
!
payload
?.
url
)
throw
new
Error
(
'URL 下载缺少 url'
);
if
(
!
payload
?.
url
)
throw
new
Error
(
'URL 下载缺少 url'
);
const
fileName
=
task
.
input
.
fileName
??
fileNameFromUrl
(
payload
.
url
);
// 后端历史数据里还有明文 http 直链(典型是付款回单
// http://qcimg01.glsx.com.cn:7060/group1/...)。主壳是 HTTPS,原样交给浏览器
// 必被 Mixed Content 拦死,过去只能整条链路报失败。入口统一升级协议并去掉
// 原 HTTP 业务端口,业务页(finance 列表页 / 详情抽屉)不用各自处理。
const
url
=
upgradeInsecureUrl
(
payload
.
url
);
const
fileName
=
task
.
input
.
fileName
??
fileNameFromUrl
(
url
);
// 先 fetch 探测:同源 / 带 CORS 的直链能读到 HTTP 状态与响应体,
// 先 fetch 探测:同源 / 带 CORS 的直链能读到 HTTP 状态与响应体,
// 过去 iframe 读不到的「请求资源不存在」(404 或 200+JSON 业务错误)
// 过去 iframe 读不到的「请求资源不存在」(404 或 200+JSON 业务错误)
// 现在会走 error 分支抛错,由引擎落 failed 并触发失败通知。
// 现在会走 error 分支抛错,由引擎落 failed 并触发失败通知。
const
probe
=
await
probeDownloadUrl
(
payload
.
url
,
fileName
,
ctx
.
signal
);
const
probe
=
await
probeDownloadUrl
(
url
,
fileName
,
ctx
.
signal
);
// 探测期间任务可能被取消(signal abort 会让 probe 返回 opaque 而非抛错)。
// 探测期间任务可能被取消(signal abort 会让 probe 返回 opaque 而非抛错)。
// 这里主动抛 AbortError,交回引擎按「已取消」落状态,避免取消后仍继续下载。
// 这里主动抛 AbortError,交回引擎按「已取消」落状态,避免取消后仍继续下载。
if
(
ctx
.
isCanceled
())
throw
new
DOMException
(
'已取消'
,
'AbortError'
);
if
(
ctx
.
isCanceled
())
throw
new
DOMException
(
'已取消'
,
'AbortError'
);
...
@@ -44,7 +49,7 @@ export const urlHandler: DownloadHandler = {
...
@@ -44,7 +49,7 @@ export const urlHandler: DownloadHandler = {
ctx
.
deliver
.
saveBlob
(
probe
.
blob
,
probe
.
fileName
);
ctx
.
deliver
.
saveBlob
(
probe
.
blob
,
probe
.
fileName
);
}
}
return
{
return
{
fileUrl
:
payload
.
url
,
fileUrl
:
url
,
fileName
:
probe
.
fileName
,
fileName
:
probe
.
fileName
,
bytes
:
probe
.
bytes
,
bytes
:
probe
.
bytes
,
note
:
'下载完成'
,
note
:
'下载完成'
,
...
@@ -53,11 +58,11 @@ export const urlHandler: DownloadHandler = {
...
@@ -53,11 +58,11 @@ export const urlHandler: DownloadHandler = {
// opaque:跨域无 CORS 的 OSS 预签名地址,无法探测,退回原 iframe 行为。
// opaque:跨域无 CORS 的 OSS 预签名地址,无法探测,退回原 iframe 行为。
// 这类地址的加载失败浏览器不让 JS 感知,是既定限制,不能因此误判为失败。
// 这类地址的加载失败浏览器不让 JS 感知,是既定限制,不能因此误判为失败。
assertDownloadableUrl
(
payload
.
url
);
assertDownloadableUrl
(
url
);
if
(
task
.
input
.
autoDownload
!==
false
)
{
if
(
task
.
input
.
autoDownload
!==
false
)
{
ctx
.
deliver
.
openUrl
(
payload
.
url
,
payload
.
openInNewTab
??
true
);
ctx
.
deliver
.
openUrl
(
url
,
payload
.
openInNewTab
??
true
);
}
}
return
{
fileUrl
:
payload
.
url
,
fileName
,
note
:
'已打开下载地址'
};
return
{
fileUrl
:
url
,
fileName
,
note
:
'已打开下载地址'
};
},
},
};
};
...
...
packages/ui/src/components/FillTable/index.tsx
View file @
e941562
...
@@ -2,6 +2,7 @@ import { Table, type TableProps } from 'antd';
...
@@ -2,6 +2,7 @@ import { Table, type TableProps } from 'antd';
import { useFillHeight } from './tools/useFillHeight';
import { useFillHeight } from './tools/useFillHeight';
import { useScrollbarRemeasure } from '../../hooks/useScrollbarRemeasure';
import { useScrollbarRemeasure } from '../../hooks/useScrollbarRemeasure';
import { resolveTableLoading } from '../Table/loading';
import { resolveTableLoading } from '../Table/loading';
import { withImageCell } from '../Table/imageCell';
/**
/**
* 自动铺满父容器剩余高度的表格。
* 自动铺满父容器剩余高度的表格。
...
@@ -33,7 +34,8 @@ export function FillTable<T extends object = Record<string, unknown>>(props: Tab
...
@@ -33,7 +34,8 @@ export function FillTable<T extends object = Record<string, unknown>>(props: Tab
<Table
<Table
key={`uj-fill-${remeasureEpoch}`}
key={`uj-fill-${remeasureEpoch}`}
{...props}
{...props}
// 与 UTable 共用同一个注入点,fillHeight 列表的加载态不出现第二种图形。
// 与 UTable 共用同一个注入点,图片单元格能力在底层表格统一收口。
columns={withImageCell(props.columns)}
loading={resolveTableLoading(props.loading)}
loading={resolveTableLoading(props.loading)}
rootClassName="uj-table"
rootClassName="uj-table"
scroll={{ ...props.scroll, y: size?.scrollY ?? props.scroll?.y }}
scroll={{ ...props.scroll, y: size?.scrollY ?? props.scroll?.y }}
...
...
packages/ui/src/components/Table/imageCell.tsx
0 → 100644
View file @
e941562
import type { ReactNode } from 'react';
import type { ColumnsType } from 'antd/es/table';
import { UImage } from '../Image';
/** 常见图片扩展名:去 query/hash 后按路径结尾判断。 */
const IMAGE_EXT = /\.(jpe?g|png|gif|bmp|webp|svg|avif|ico|tiff?|heic|heif)$/i;
/**
* 判断单元格原始值是否为「图片链接」。
*
* 严格判定,避免把普通文本/数字/普通链接误当成图片:
* - data:image/... 直接命中;
* - 其余必须是链接形态(http(s)://、// 协议相对、/ 根相对);
* - 去 query/hash 后路径以图片扩展名结尾,或带 OSS `x-oss-process=image/` 处理参数。
* 只认单个字符串链接;数组(多图)交给消费方自己的 render,不被本工具接管。
*/
export function isImageUrl(value: unknown): value is string {
if (typeof value !== 'string') return false;
const url = value.trim();
if (!url) return false;
if (/^data:image\//i.test(url)) return true;
if (!/^(https?:)?\/\/|^\//.test(url)) return false;
const pathname = url.split(/[?#]/, 1)[0];
if (IMAGE_EXT.test(pathname)) return true;
return /[?&]x-oss-process=image[%/]/i.test(url);
}
/** 表格内缩略图统一尺寸:短边定框、长边按 cover 裁剪铺满。 */
const THUMB_WIDTH = 72;
const THUMB_HEIGHT = 48;
/**
* 对 columns 的 render 做最外层包装:单元格原始值是图片链接时,
* 统一渲染成可点击查看大图的 cover 缩略图,消费方无需各自实现。
*
* 判断基于 render 的原始 value 参数,因此可安全叠加在 DataTable 的省略包装
* (withLineLimit)之上:图片列在这里直接返回 UImage、不会走进 EllipsisText;
* 非图片列调用原 render,行为与未包装完全一致。递归处理表头分组 children。
*/
export function withImageCell<T>(columns: ColumnsType<T> | undefined): ColumnsType<T> | undefined {
if (!columns) return columns;
return columns.map((column) => {
if ('children' in column && column.children) {
return {
...column,
children: withImageCell(column.children) as ColumnsType<T>,
};
}
const originalRender = 'render' in column ? column.render : undefined;
return {
...column,
render: (value: unknown, record: T, index: number) => {
if (isImageUrl(value)) {
return (
<UImage
src={value}
width={THUMB_WIDTH}
height={THUMB_HEIGHT}
styles={{ image: { objectFit: 'cover', objectPosition: 'center' } }}
preview
/>
);
}
return originalRender ? originalRender(value, record, index) : (value as ReactNode);
},
};
});
}
packages/ui/src/components/Table/index.tsx
View file @
e941562
import { Table, type TableProps } from 'antd';
import { Table, type TableProps } from 'antd';
import { useScrollbarRemeasure } from '../../hooks/useScrollbarRemeasure';
import { useScrollbarRemeasure } from '../../hooks/useScrollbarRemeasure';
import { resolveTableLoading } from './loading';
import { resolveTableLoading } from './loading';
import { withImageCell } from './imageCell';
/**
/**
* 项目统一表格。
* 项目统一表格。
...
@@ -24,6 +25,9 @@ export function UTable<T>(props: TableProps<T>) {
...
@@ -24,6 +25,9 @@ export function UTable<T>(props: TableProps<T>) {
rootClassName={['uj-table', rootClassName].filter(Boolean).join(' ')}
rootClassName={['uj-table', rootClassName].filter(Boolean).join(' ')}
loading={resolveTableLoading(loading)}
loading={resolveTableLoading(loading)}
{...rest}
{...rest}
// 图片单元格能力收口在表格底层:原始值是图片链接的列自动渲染成可点大图的
// cover 缩略图,所有消费方(含裸用 UTable 的页面)无需各自实现。
columns={withImageCell(rest.columns)}
/>
/>
);
);
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment