nhanh-pure-function 1.3.8 → 1.3.10
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/lib/Index.d.ts +1 -1
- package/lib/Math/Math.js +4 -2
- package/lib/User/User.d.ts +3 -3
- package/lib/User/User.js +3 -3
- package/lib/Utility/Utility.d.ts +10 -0
- package/lib/Utility/Utility.js +37 -10
- package/package.json +1 -1
package/lib/Index.d.ts
CHANGED
package/lib/Math/Math.js
CHANGED
|
@@ -118,9 +118,11 @@ export function _FormatNumberWithUnit(number, config = {}) {
|
|
|
118
118
|
"载",
|
|
119
119
|
"极",
|
|
120
120
|
];
|
|
121
|
-
const digits = Math.floor(Math.log10(number) / 4); // 计算位数
|
|
122
121
|
|
|
123
|
-
|
|
122
|
+
/** 计算位数 */
|
|
123
|
+
const digits = Math.floor(Math.log10(number) / 4);
|
|
124
|
+
|
|
125
|
+
/** 不超过万位的数字直接返回 */
|
|
124
126
|
if (digits === 0) {
|
|
125
127
|
if (integer) {
|
|
126
128
|
return _join(number, suffix, plus);
|
package/lib/User/User.d.ts
CHANGED
|
@@ -183,11 +183,11 @@ export class _LocalDrag {
|
|
|
183
183
|
finish(): void;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
/** 进入全屏模式 */
|
|
187
187
|
export function _EnterFullscreen(content: HTMLElement): void;
|
|
188
|
-
|
|
188
|
+
/** 退出全屏模式 */
|
|
189
189
|
export function _ExitFullscreen(): void;
|
|
190
|
-
|
|
190
|
+
/** 判断是否处于全屏模式 */
|
|
191
191
|
export function _IsFullscreen(): HTMLElement | undefined;
|
|
192
192
|
|
|
193
193
|
/**
|
package/lib/User/User.js
CHANGED
|
@@ -483,7 +483,7 @@ export class _LocalDrag {
|
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
|
|
486
|
-
|
|
486
|
+
/** 进入全屏模式 */
|
|
487
487
|
export function _EnterFullscreen(content) {
|
|
488
488
|
if (!content) return console.error("No DOM: ", content);
|
|
489
489
|
if (content.requestFullscreen) {
|
|
@@ -499,7 +499,7 @@ export function _EnterFullscreen(content) {
|
|
|
499
499
|
content.msRequestFullscreen();
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
|
-
|
|
502
|
+
/** 退出全屏模式 */
|
|
503
503
|
export function _ExitFullscreen() {
|
|
504
504
|
if (document.exitFullscreen) {
|
|
505
505
|
document.exitFullscreen();
|
|
@@ -514,7 +514,7 @@ export function _ExitFullscreen() {
|
|
|
514
514
|
document.msExitFullscreen();
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
|
-
|
|
517
|
+
/** 判断是否处于全屏模式 */
|
|
518
518
|
export function _IsFullscreen() {
|
|
519
519
|
return (
|
|
520
520
|
document.fullscreenElement ||
|
package/lib/Utility/Utility.d.ts
CHANGED
|
@@ -78,6 +78,16 @@ export function _TimeTransition(
|
|
|
78
78
|
*/
|
|
79
79
|
export function _ReadFile(src: string): Promise<string>;
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* 从给定的URL中提取文件名
|
|
83
|
+
* 如果无法提取文件名,则返回默认的文件名
|
|
84
|
+
*
|
|
85
|
+
* @param {string} href - 包含文件路径的URL
|
|
86
|
+
* @param {string} [defaultName="file"] - 默认的文件名,当无法提取时使用
|
|
87
|
+
* @returns {string} 提取到的文件名或默认的文件名
|
|
88
|
+
*/
|
|
89
|
+
export function _GetHrefName(href: string, defaultName = "file"): string;
|
|
90
|
+
|
|
81
91
|
/**
|
|
82
92
|
* 下载文件
|
|
83
93
|
* @param {string} href 文件路径
|
package/lib/Utility/Utility.js
CHANGED
|
@@ -175,19 +175,46 @@ export function _ReadFile(src) {
|
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/**
|
|
179
|
+
* 从给定的URL中提取文件名
|
|
180
|
+
* 如果无法提取文件名,则返回默认的文件名
|
|
181
|
+
*
|
|
182
|
+
* @param {string} href - 包含文件路径的URL
|
|
183
|
+
* @param {string} [defaultName="file"] - 默认的文件名,当无法提取时使用
|
|
184
|
+
* @returns {string} 提取到的文件名或默认的文件名
|
|
185
|
+
*/
|
|
186
|
+
export function _GetHrefName(href, defaultName = "file") {
|
|
187
|
+
// 分割URL并获取最后一个路径段,然后去除查询字符串,最后返回文件名或默认名
|
|
188
|
+
return href.split("/").pop().split("?")[0] || defaultName;
|
|
189
|
+
}
|
|
190
|
+
|
|
178
191
|
/**
|
|
179
192
|
* 下载文件
|
|
180
|
-
* @param {
|
|
181
|
-
* @param {
|
|
193
|
+
* @param {string} href - 文件路径
|
|
194
|
+
* @param {string} [fileName] - 导出文件名
|
|
182
195
|
*/
|
|
183
|
-
export function _DownloadFile(href, fileName) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
196
|
+
export async function _DownloadFile(href, fileName) {
|
|
197
|
+
try {
|
|
198
|
+
const response = await fetch(href); // 获取文件
|
|
199
|
+
if (!response.ok) throw new Error("文件下载失败");
|
|
200
|
+
|
|
201
|
+
const blob = await response.blob(); // 将响应转换为 Blob 对象
|
|
202
|
+
const url = URL.createObjectURL(blob); // 创建文件 URL
|
|
203
|
+
|
|
204
|
+
const a = document.createElement("a");
|
|
205
|
+
a.href = url;
|
|
206
|
+
a.download = fileName || _GetHrefName(href, "image");
|
|
207
|
+
|
|
208
|
+
// 临时将 a 标签添加到 DOM,然后触发点击事件,最后移除
|
|
209
|
+
document.body.appendChild(a);
|
|
210
|
+
a.click();
|
|
211
|
+
document.body.removeChild(a);
|
|
212
|
+
|
|
213
|
+
// 释放 URL 对象
|
|
214
|
+
URL.revokeObjectURL(url);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
console.error("下载文件时发生错误:", error);
|
|
217
|
+
}
|
|
191
218
|
}
|
|
192
219
|
|
|
193
220
|
/**
|