feat: 优化截图处理类
This commit is contained in:
parent
8679aec19a
commit
6abe3bb5b1
|
@ -0,0 +1,7 @@
|
||||||
|
import { Messages } from '../src/core/index.js'
|
||||||
|
const message = new Messages({
|
||||||
|
priority: 9000
|
||||||
|
})
|
||||||
|
message.response(/^你好/, async e => {
|
||||||
|
e.reply('你好')
|
||||||
|
})
|
|
@ -0,0 +1,25 @@
|
||||||
|
import React from 'react'
|
||||||
|
import { Component, Puppeteer } from '../src/utils/index.js'
|
||||||
|
import Hello from './hello.tsx'
|
||||||
|
const Com = new Component()
|
||||||
|
const Pup = new Puppeteer()
|
||||||
|
export class Image {
|
||||||
|
constructor() {
|
||||||
|
// 启动
|
||||||
|
Pup.start()
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async getHelloComponent() {
|
||||||
|
// 生成 html 地址
|
||||||
|
const Address = Com.create(<Hello data={{ name: 'word' }} />, {
|
||||||
|
html_head: `<link rel="stylesheet" href="../public/output.css"></link>`,
|
||||||
|
html_name: 'hello.html'
|
||||||
|
})
|
||||||
|
//
|
||||||
|
const img = await Pup.render(Address)
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,12 +31,13 @@ export class Component {
|
||||||
*/
|
*/
|
||||||
create(element: React.ReactNode, options: ComponentCreateOpsionType) {
|
create(element: React.ReactNode, options: ComponentCreateOpsionType) {
|
||||||
const str = renderToString(element)
|
const str = renderToString(element)
|
||||||
const dir = join(this.#dir, options.join_dir)
|
const dir = join(this.#dir, options?.join_dir ?? '')
|
||||||
mkdirSync(dir, { recursive: true })
|
mkdirSync(dir, { recursive: true })
|
||||||
const address = join(dir, options.html_name)
|
const address = join(dir, options?.html_name ?? 'hello.html')
|
||||||
const DOCTYPE = '<!DOCTYPE html>'
|
const DOCTYPE = '<!DOCTYPE html>'
|
||||||
const head = `<head>${options.html_head}</head>`
|
const Link = `<link rel="stylesheet" href="../public/output.css"></link>`
|
||||||
const body = `<body>${str}${options.html_body}</body>`
|
const head = `<head>${options?.html_head ?? Link}</head>`
|
||||||
|
const body = `<body> ${str} ${options?.html_body ?? ''}</body>`
|
||||||
const html = `${DOCTYPE}<html>${head}${body}</html>`
|
const html = `${DOCTYPE}<html>${head}${body}</html>`
|
||||||
writeFileSync(address, html)
|
writeFileSync(address, html)
|
||||||
return address
|
return address
|
||||||
|
|
Loading…
Reference in New Issue