Miao-Yunzai/example/index.tsx

39 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-06-10 10:05:51 +08:00
import React from 'react'
import { Component, Puppeteer } from '../src/utils/index.js'
2024-06-10 10:27:51 +08:00
import Hello, { type DataType } from './hello.tsx'
export const Com = new Component()
export const Pup = new Puppeteer()
2024-06-10 10:05:51 +08:00
export class Image {
constructor() {
// 启动
Pup.start()
}
/**
2024-06-10 10:27:51 +08:00
* html html文件
2024-06-10 10:05:51 +08:00
* @returns
*/
2024-06-10 10:27:51 +08:00
getHelloComponent(uid: number, data: DataType) {
2024-06-10 10:46:16 +08:00
// 生成 html 地址 或 html字符串
2024-06-10 10:27:51 +08:00
const Address = Com.create(<Hello data={data} />, {
/**
* json_dir时
* html_head路径应该是../public/output.css
* html_head默认值路径也是../public/output.css
2024-06-10 10:46:16 +08:00
* head的话html_head和join_dir都可以省略
2024-06-10 10:27:51 +08:00
* { html_name: `${uid}.html`}
*/
html_head: `<link rel="stylesheet" href="../../public/output.css"></link>`,
// html/hello/uid.html
join_dir: 'hello',
html_name: `${uid}.html`
2024-06-10 10:46:16 +08:00
// 不生成文件返回的将是html字符串
// file_create:false
2024-06-10 10:05:51 +08:00
})
2024-06-10 10:27:51 +08:00
return Pup.render(Address)
2024-06-10 10:05:51 +08:00
}
}
2024-06-10 10:27:51 +08:00
export const imgae = new Image()
// render 是异步的,因此 此处也是异步的
const img = await imgae.getHelloComponent(1715713638, { name: 'word' })
// e.reply(segment.buffer(img))