1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-18 08:38:45 +09:00
cherrypick/src/client/components/page/page.vue

92 lines
1.7 KiB
Vue
Raw Normal View History

<template>
2020-04-20 21:35:27 +09:00
<div class="iroscrza" :class="{ center: page.alignCenter, serif: page.font === 'serif' }" v-if="hpml">
<x-block v-for="child in page.content" :value="child" @input="v => updateBlock(v)" :page="page" :hpml="hpml" :key="child.id" :h="2"/>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2020-04-20 21:35:27 +09:00
import { parse } from '@syuilo/aiscript';
import { faHeart as faHeartS } from '@fortawesome/free-solid-svg-icons';
import { faHeart } from '@fortawesome/free-regular-svg-icons';
import XBlock from './page.block.vue';
2020-04-20 21:35:27 +09:00
import { Hpml } from '../../scripts/hpml/evaluator';
import { url } from '../../config';
export default Vue.extend({
components: {
XBlock
},
props: {
page: {
type: Object,
required: true
},
},
data() {
return {
2020-04-20 21:35:27 +09:00
hpml: null,
faHeartS, faHeart
};
},
created() {
2020-04-20 21:35:27 +09:00
this.hpml = new Hpml(this, this.page, {
randomSeed: Math.random(),
visitor: this.$store.state.i,
2020-04-13 23:46:53 +09:00
url: url,
enableAiScript: !this.$store.state.device.disablePagesScript
});
},
2020-04-16 00:39:21 +09:00
mounted() {
this.$nextTick(() => {
2020-04-20 21:35:27 +09:00
if (this.page.script && this.hpml.aiscript) {
2020-04-16 00:39:21 +09:00
let ast;
try {
2020-04-20 21:35:27 +09:00
ast = parse(this.page.script);
2020-04-16 00:39:21 +09:00
} catch (e) {
console.error(e);
/*this.$root.dialog({
type: 'error',
text: 'Syntax error :('
});*/
return;
}
2020-04-20 21:35:27 +09:00
this.hpml.aiscript.exec(ast).then(() => {
this.hpml.eval();
2020-04-16 00:39:21 +09:00
}).catch(e => {
console.error(e);
/*this.$root.dialog({
type: 'error',
text: e
});*/
});
} else {
2020-04-20 21:35:27 +09:00
this.hpml.eval();
2020-04-16 00:39:21 +09:00
}
});
},
2020-04-13 23:46:53 +09:00
beforeDestroy() {
2020-04-20 21:35:27 +09:00
if (this.hpml.aiscript) this.hpml.aiscript.abort();
2020-04-13 23:46:53 +09:00
},
});
</script>
<style lang="scss" scoped>
.iroscrza {
&.serif {
> div {
font-family: serif;
}
}
&.center {
text-align: center;
}
}
</style>