2022-07-24 11:46:05 +08:00
|
|
|
import lodash from 'lodash'
|
|
|
|
import Data from '../components/Data.js'
|
|
|
|
import puppeteer from '../../../lib/puppeteer/puppeteer.js'
|
|
|
|
|
|
|
|
const plugin = 'xiaoyao-cvs-plugin'
|
|
|
|
|
|
|
|
const _path = process.cwd()
|
|
|
|
|
2022-10-12 16:51:51 +08:00
|
|
|
export async function render(app = '', tpl = '', data = {}, imgType = 'jpeg') {
|
|
|
|
// 在data中保存plugin信息
|
|
|
|
data._plugin = plugin
|
|
|
|
if (lodash.isUndefined(data._res_path)) {
|
|
|
|
data._res_path = `../../../../../plugins/${plugin}/resources/`
|
|
|
|
}
|
|
|
|
if (imgType == "png") {
|
|
|
|
data.omitBackground = true;
|
|
|
|
}
|
|
|
|
data.imgType = imgType;
|
|
|
|
Data.createDir(_path + '/data/', `html/${plugin}/${app}/${tpl}`)
|
|
|
|
data.saveId = data.saveId || data.save_id || tpl
|
|
|
|
data.tplFile = `./plugins/${plugin}/resources/${app}/${tpl}.html`
|
|
|
|
data.pluResPath = data._res_path
|
|
|
|
data.pageGotoParams = {
|
|
|
|
waitUntil: 'networkidle0'
|
|
|
|
}
|
|
|
|
return await puppeteer.screenshot(`${plugin}/${app}/${tpl}`, data)
|
2022-07-24 11:46:05 +08:00
|
|
|
}
|
2022-09-13 23:06:47 +08:00
|
|
|
|
2022-10-12 16:51:51 +08:00
|
|
|
export function getRender() {
|
|
|
|
return async function render(app = '', tpl = '', data = {}, imgType = 'jpeg') {
|
|
|
|
// 在data中保存plugin信息
|
|
|
|
data._plugin = plugin
|
|
|
|
if (lodash.isUndefined(data._res_path)) {
|
|
|
|
data._res_path = `../../../../../plugins/${plugin}/resources/`
|
|
|
|
}
|
|
|
|
if (imgType == "png") {
|
|
|
|
data.omitBackground = true;
|
|
|
|
}
|
|
|
|
data.imgType = imgType;
|
|
|
|
Data.createDir(_path + '/data/', `html/${plugin}/${app}/${tpl}`)
|
|
|
|
data.saveId = data.saveId || data.save_id || tpl
|
|
|
|
data.tplFile = `./plugins/${plugin}/resources/${app}/${tpl}.html`
|
|
|
|
data.pluResPath = data._res_path
|
|
|
|
data.pageGotoParams = {
|
|
|
|
waitUntil: 'networkidle0'
|
|
|
|
}
|
|
|
|
return await puppeteer.screenshot(`${plugin}/${app}/${tpl}`, data)
|
|
|
|
}
|
2022-09-13 23:06:47 +08:00
|
|
|
}
|