feat: add AI page preview URL
This commit is contained in:
@@ -16,10 +16,44 @@
|
||||
<script>
|
||||
(function () {
|
||||
const params = new URLSearchParams(location.search);
|
||||
const schemaId = params.get('schema') || params.get('templateId');
|
||||
const schemaUrl = params.get('schemaUrl');
|
||||
const source = params.get('source');
|
||||
const template = params.get('template') || '角色维护';
|
||||
fetch('/api/poc/amis-schema?template=' + encodeURIComponent(template))
|
||||
.then(r => r.json())
|
||||
|
||||
function schemaEndpoint() {
|
||||
if (schemaUrl) {
|
||||
if (!schemaUrl.startsWith('/api/page/schema/')) {
|
||||
throw new Error('schemaUrl 只允许 /api/page/schema/ 路径');
|
||||
}
|
||||
return schemaUrl;
|
||||
}
|
||||
if (schemaId) {
|
||||
return '/api/page/schema/' + encodeURIComponent(schemaId);
|
||||
}
|
||||
if (source === 'page-schema') {
|
||||
return '/api/page/schema/' + encodeURIComponent(template);
|
||||
}
|
||||
return '/api/poc/amis-schema?template=' + encodeURIComponent(template);
|
||||
}
|
||||
|
||||
function loadSchema() {
|
||||
const endpoint = schemaEndpoint();
|
||||
return fetch(endpoint)
|
||||
.then(r => {
|
||||
if (!r.ok) {
|
||||
throw new Error(endpoint + ' 返回 HTTP ' + r.status);
|
||||
}
|
||||
return r.json();
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('root').innerText = '加载中...';
|
||||
loadSchema()
|
||||
.then(schema => {
|
||||
if (schema && schema.status !== undefined && schema.data) {
|
||||
schema = schema.data;
|
||||
}
|
||||
const amis = amisRequire('amis/embed');
|
||||
amis.embed('#root', schema);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user