feat: 增加截图新配置

This commit is contained in:
ningmengchongshui 2024-06-10 10:46:16 +08:00
parent 841c31d4ec
commit 03ff09289f
2 changed files with 11 additions and 2 deletions

View File

@ -13,19 +13,21 @@ export class Image {
* @returns * @returns
*/ */
getHelloComponent(uid: number, data: DataType) { getHelloComponent(uid: number, data: DataType) {
// 生成 html 地址 // 生成 html 地址 或 html字符串
const Address = Com.create(<Hello data={data} />, { const Address = Com.create(<Hello data={data} />, {
/** /**
* json_dir时 * json_dir时
* html_head路径应该是../public/output.css * html_head路径应该是../public/output.css
* html_head默认值路径也是../public/output.css * html_head默认值路径也是../public/output.css
* head的话html_head和join_dir都可以胜利 * head的话html_head和join_dir都可以省略
* { html_name: `${uid}.html`} * { html_name: `${uid}.html`}
*/ */
html_head: `<link rel="stylesheet" href="../../public/output.css"></link>`, html_head: `<link rel="stylesheet" href="../../public/output.css"></link>`,
// html/hello/uid.html // html/hello/uid.html
join_dir: 'hello', join_dir: 'hello',
html_name: `${uid}.html` html_name: `${uid}.html`
// 不生成文件返回的将是html字符串
// file_create:false
}) })
return Pup.render(Address) return Pup.render(Address)
} }

View File

@ -8,6 +8,7 @@ type ComponentCreateOpsionType = {
html_name?: string html_name?: string
join_dir?: string join_dir?: string
html_body?: string html_body?: string
file_create?: boolean
} }
/** /**
@ -39,6 +40,12 @@ export class Component {
const head = `<head>${options?.html_head ?? Link}</head>` const head = `<head>${options?.html_head ?? Link}</head>`
const body = `<body> ${str} ${options?.html_body ?? ''}</body>` const body = `<body> ${str} ${options?.html_body ?? ''}</body>`
const html = `${DOCTYPE}<html>${head}${body}</html>` const html = `${DOCTYPE}<html>${head}${body}</html>`
if (
typeof options?.file_create == 'boolean' &&
options?.file_create == false
) {
return html
}
writeFileSync(address, html) writeFileSync(address, html)
return address return address
} }