function RFC3986UrlEncode(str){
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16).toUpperCase();
});
}思路:将真实图片地址先放在 data-src 属性上,当图片出现在可视区域当时候,再将 data-src 属性值设置到 src 属性上,触发下载图片。
判断是否在可视区域,可以用元素的 getBoundingClientRect 方法(参考)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 相对时间校验 | |
| * @param property [数量,时间单位],时间单位参考 dayjs,例如 1 年前,[1, 'year'] | |
| * @param validationOptions | |
| * @returns | |
| */ | |
| const IsRelativeDate = function (property: [number, string], validationOptions?: ValidationOptions) { | |
| return function (object: Object, propertyName: string) { | |
| registerDecorator({ | |
| name: 'IsRelativeDate', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 不同的算法要求的 key 长度不一样 | |
| // 算法 key iv | |
| // 128 16 16 | |
| // 192 24 16 | |
| // 256 32 16 | |
| // 示例 key d42308a3a6f9db4e6eeff373e1b34663 iv 8109f3a93716beab | |
| /** | |
| * aes 加密封装 | |
| * @param data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useRef } from "react" | |
| import * as monaco from 'monaco-editor' | |
| interface Props { | |
| defaultValue?: string | |
| height?: number | |
| onChange?: any | |
| } | |
| export default function Editor({defaultValue, height = 500, onChange}: Props) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as archiver from 'archiver'; | |
| import * as fs from 'fs' | |
| import * as unzipper from 'unzipper' | |
| /** | |
| * 根据目录压缩 zip 文件 | |
| * @param filePath | |
| * @param folderPath | |
| * @returns | |
| */ |
html 标签转义
value = value.replace(/&/g, "&");
value = value.replace(/</g, "<");
value = value.replace(/>/g, ">");
value = value.replace(/ /g, " ");
value = value.replace(/"/g, '"');
滚动吸顶的 js 实现
useEffect(() => {
const handle = () => {
const top = document.documentElement.scrollTop || document.body.scrollTop
setTabFixed((value: boolean) => {
console.log(top, value, safeArea().top)
if (top > headerRef.current?.clientHeight) {
console.log('set fixed')
return true
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func DownloadFile(url string) (localPath string, err error) { | |
| resp, err := http.Get(url) | |
| if err != nil { | |
| panic(err) | |
| } | |
| defer resp.Body.Close() | |
| filename := filepath.Base(url) | |
| localPath = "bg/" + filename |