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