Files
code-center/src/routes/page/module/file-template.ts
2025-01-06 10:44:04 +08:00

103 lines
2.1 KiB
TypeScript

type HTMLOptions = {
title?: string;
rootId: string;
dataKey?: string;
};
/**
* data list
* @param opts
* @returns
*/
export const getHTML = (opts: HTMLOptions) => {
return `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${opts.title || 'Kevisual'}</title>
<style>
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
font-size: 16px;
}
</style>
<script src="https://kevisual.xiongxiao.me/system/lib/app.js"></script>
</head>
<body>
<div id="root"></div>
<script type="module">
import { Container } from 'https://kevisual.xiongxiao.me/root/container/index.js'
import { data } from './${opts.dataKey || 'data'}.js'
const container = new Container({
root: 'root',
data: data
});
container.render('${opts.rootId}');
</script>
</body>
</html>`;
};
export const getDataJs = (result: any) => {
return 'export const data=' + JSON.stringify(result);
};
type OneHTMLOptions = {
title?: string;
file: string;
}
/**
* one data
* @param opts
* @returns
*/
export const getOneHTML = (opts: OneHTMLOptions) => {
return `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="https://envision.xiongxiao.me/resources/root/avatar.png"/>
<title>${opts.title || 'Kevisual'}</title>
<style>
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
font-size: 16px;
}
</style>
<script src="https://kevisual.xiongxiao.me/system/lib/app.js"></script>
</head>
<body>
<div id="root"></div>
<script type="module">
import { ContainerOne } from 'https://kevisual.xiongxiao.me/system/lib/container.js'
import { render, unmount } from './${opts.file}.js'
const container = new ContainerOne({
root: '#root',
});
container.renderOne({
code: {render, unmount}
});
</script>
</body>
</html>`;
};