2019-04-29 03:11:57 +03:00
|
|
|
<template>
|
2020-04-20 15:35:27 +03:00
|
|
|
<div class="iroscrza" :class="{ center: page.alignCenter, serif: page.font === 'serif' }" v-if="hpml">
|
2021-01-30 03:59:05 +02:00
|
|
|
<XBlock v-for="child in page.content" :block="child" :hpml="hpml" :key="child.id" :h="2"/>
|
2019-04-29 03:11:57 +03:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-01-30 03:59:05 +02:00
|
|
|
import { defineComponent, onMounted, nextTick, onUnmounted, PropType } from 'vue';
|
2020-04-20 15:35:27 +03:00
|
|
|
import { parse } from '@syuilo/aiscript';
|
2019-04-29 03:11:57 +03:00
|
|
|
import XBlock from './page.block.vue';
|
2021-03-23 10:30:14 +02:00
|
|
|
import { Hpml } from '@client/scripts/hpml/evaluator';
|
|
|
|
import { url } from '@client/config';
|
|
|
|
import { $i } from '@client/account';
|
|
|
|
import { defaultStore } from '@client/store';
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2020-10-17 14:12:00 +03:00
|
|
|
export default defineComponent({
|
2019-04-29 03:11:57 +03:00
|
|
|
components: {
|
|
|
|
XBlock
|
|
|
|
},
|
|
|
|
props: {
|
2019-07-07 00:56:13 +03:00
|
|
|
page: {
|
2021-01-30 03:59:05 +02:00
|
|
|
type: Object as PropType<Record<string, any>>,
|
2019-04-29 03:11:57 +03:00
|
|
|
required: true
|
|
|
|
},
|
|
|
|
},
|
2021-01-30 03:59:05 +02:00
|
|
|
setup(props, ctx) {
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2021-01-30 03:59:05 +02:00
|
|
|
const hpml = new Hpml(props.page, {
|
2019-07-07 00:56:13 +03:00
|
|
|
randomSeed: Math.random(),
|
2021-01-30 03:59:05 +02:00
|
|
|
visitor: $i,
|
2020-04-13 17:46:53 +03:00
|
|
|
url: url,
|
2021-01-30 03:59:05 +02:00
|
|
|
enableAiScript: !defaultStore.state.disablePagesScript
|
2019-07-07 00:56:13 +03:00
|
|
|
});
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2021-01-30 03:59:05 +02:00
|
|
|
onMounted(() => {
|
|
|
|
nextTick(() => {
|
|
|
|
if (props.page.script && hpml.aiscript) {
|
|
|
|
let ast;
|
|
|
|
try {
|
|
|
|
ast = parse(props.page.script);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
/*os.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: 'Syntax error :('
|
|
|
|
});*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hpml.aiscript.exec(ast).then(() => {
|
|
|
|
hpml.eval();
|
|
|
|
}).catch(e => {
|
|
|
|
console.error(e);
|
|
|
|
/*os.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});*/
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
hpml.eval();
|
2020-04-15 18:39:21 +03:00
|
|
|
}
|
2021-01-30 03:59:05 +02:00
|
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
|
|
if (hpml.aiscript) hpml.aiscript.abort();
|
|
|
|
});
|
2020-04-15 18:39:21 +03:00
|
|
|
});
|
|
|
|
|
2021-01-30 03:59:05 +02:00
|
|
|
return {
|
|
|
|
hpml,
|
|
|
|
};
|
2020-04-13 17:46:53 +03:00
|
|
|
},
|
2019-04-29 03:11:57 +03:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.iroscrza {
|
|
|
|
&.serif {
|
|
|
|
> div {
|
|
|
|
font-family: serif;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 03:11:57 +03:00
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
&.center {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 03:11:57 +03:00
|
|
|
</style>
|