2019-04-29 02:11:57 +02:00
|
|
|
<template>
|
2021-12-04 10:27:31 +01:00
|
|
|
<MkSpacer :content-max="700">
|
|
|
|
<div class="jqqmcavi">
|
2021-10-23 21:03:07 +02:00
|
|
|
<MkButton v-if="pageId" class="button" inline link :to="`/@${ author.username }/pages/${ currentName }`"><i class="fas fa-external-link-square-alt"></i> {{ $ts._pages.viewPage }}</MkButton>
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkButton v-if="!readonly" inline primary class="button" @click="save"><i class="fas fa-save"></i> {{ $ts.save }}</MkButton>
|
|
|
|
<MkButton v-if="pageId" inline class="button" @click="duplicate"><i class="fas fa-copy"></i> {{ $ts.duplicate }}</MkButton>
|
|
|
|
<MkButton v-if="pageId && !readonly" inline class="button" danger @click="del"><i class="fas fa-trash-alt"></i> {{ $ts.delete }}</MkButton>
|
2021-10-23 21:03:07 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="tab === 'settings'">
|
2021-12-04 10:27:31 +01:00
|
|
|
<div class="_formRoot">
|
2021-10-23 21:03:07 +02:00
|
|
|
<MkInput v-model="title" class="_formBlock">
|
|
|
|
<template #label>{{ $ts._pages.title }}</template>
|
|
|
|
</MkInput>
|
|
|
|
|
|
|
|
<MkInput v-model="summary" class="_formBlock">
|
|
|
|
<template #label>{{ $ts._pages.summary }}</template>
|
|
|
|
</MkInput>
|
|
|
|
|
|
|
|
<MkInput v-model="name" class="_formBlock">
|
|
|
|
<template #prefix>{{ url }}/@{{ author.username }}/pages/</template>
|
|
|
|
<template #label>{{ $ts._pages.url }}</template>
|
|
|
|
</MkInput>
|
|
|
|
|
|
|
|
<MkSwitch v-model="alignCenter" class="_formBlock">{{ $ts._pages.alignCenter }}</MkSwitch>
|
|
|
|
|
|
|
|
<MkSelect v-model="font" class="_formBlock">
|
|
|
|
<template #label>{{ $ts._pages.font }}</template>
|
|
|
|
<option value="serif">{{ $ts._pages.fontSerif }}</option>
|
|
|
|
<option value="sans-serif">{{ $ts._pages.fontSansSerif }}</option>
|
|
|
|
</MkSelect>
|
|
|
|
|
|
|
|
<MkSwitch v-model="hideTitleWhenPinned" class="_formBlock">{{ $ts._pages.hideTitleWhenPinned }}</MkSwitch>
|
2019-07-06 23:56:13 +02:00
|
|
|
|
2021-10-23 21:03:07 +02:00
|
|
|
<div class="eyeCatch">
|
|
|
|
<MkButton v-if="eyeCatchingImageId == null && !readonly" @click="setEyeCatchingImage"><i class="fas fa-plus"></i> {{ $ts._pages.eyeCatchingImageSet }}</MkButton>
|
|
|
|
<div v-else-if="eyeCatchingImage">
|
|
|
|
<img :src="eyeCatchingImage.url" :alt="eyeCatchingImage.name" style="max-width: 100%;"/>
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkButton v-if="!readonly" @click="removeEyeCatchingImage()"><i class="fas fa-trash-alt"></i> {{ $ts._pages.eyeCatchingImageRemove }}</MkButton>
|
2020-11-15 05:42:04 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-10 05:40:50 +02:00
|
|
|
</div>
|
2021-10-23 21:03:07 +02:00
|
|
|
</div>
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2021-10-23 21:03:07 +02:00
|
|
|
<div v-else-if="tab === 'contents'">
|
2021-12-04 10:27:31 +01:00
|
|
|
<div>
|
2021-11-19 11:36:12 +01:00
|
|
|
<XBlocks v-model="content" class="content" :hpml="hpml"/>
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkButton v-if="!readonly" @click="add()"><i class="fas fa-plus"></i></MkButton>
|
2021-04-10 05:40:50 +02:00
|
|
|
</div>
|
2021-10-23 21:03:07 +02:00
|
|
|
</div>
|
2019-05-01 13:48:56 +02:00
|
|
|
|
2021-10-23 21:03:07 +02:00
|
|
|
<div v-else-if="tab === 'variables'">
|
|
|
|
<div class="qmuvgica">
|
2021-11-19 11:36:12 +01:00
|
|
|
<XDraggable v-show="variables.length > 0" v-model="variables" tag="div" class="variables" item-key="name" handle=".drag-handle" :group="{ name: 'variables' }" animation="150" swap-threshold="0.5">
|
2021-10-23 21:03:07 +02:00
|
|
|
<template #item="{element}">
|
|
|
|
<XVariable
|
|
|
|
:modelValue="element"
|
|
|
|
:removable="true"
|
|
|
|
:hpml="hpml"
|
|
|
|
:name="element.name"
|
|
|
|
:title="element.name"
|
|
|
|
:draggable="true"
|
2021-11-19 11:36:12 +01:00
|
|
|
@remove="() => removeVariable(element)"
|
2021-10-23 21:03:07 +02:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</XDraggable>
|
|
|
|
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkButton v-if="!readonly" class="add" @click="addVariable()"><i class="fas fa-plus"></i></MkButton>
|
2021-04-10 05:40:50 +02:00
|
|
|
</div>
|
2021-10-23 21:03:07 +02:00
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-10-23 21:03:07 +02:00
|
|
|
<div v-else-if="tab === 'script'">
|
|
|
|
<div>
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkTextarea v-model="script" class="_code"/>
|
2021-04-10 05:40:50 +02:00
|
|
|
</div>
|
2021-10-02 17:33:29 +02:00
|
|
|
</div>
|
2021-12-04 10:27:31 +01:00
|
|
|
</MkSpacer>
|
2019-04-29 02:11:57 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-11-15 05:42:04 +01:00
|
|
|
import { defineComponent, defineAsyncComponent, computed } from 'vue';
|
2020-08-22 01:03:11 +02:00
|
|
|
import 'prismjs';
|
|
|
|
import { highlight, languages } from 'prismjs/components/prism-core';
|
|
|
|
import 'prismjs/components/prism-clike';
|
|
|
|
import 'prismjs/components/prism-javascript';
|
2020-04-17 13:36:51 +02:00
|
|
|
import 'prismjs/themes/prism-okaidia.css';
|
2020-08-22 01:03:11 +02:00
|
|
|
import 'vue-prism-editor/dist/prismeditor.min.css';
|
2020-01-29 20:37:25 +01:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2019-04-29 02:11:57 +02:00
|
|
|
import XVariable from './page-editor.script-block.vue';
|
2019-05-02 10:55:59 +02:00
|
|
|
import XBlocks from './page-editor.blocks.vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import MkTextarea from '@/components/form/textarea.vue';
|
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkSelect from '@/components/form/select.vue';
|
|
|
|
import MkSwitch from '@/components/form/switch.vue';
|
|
|
|
import MkInput from '@/components/form/input.vue';
|
|
|
|
import { blockDefs } from '@/scripts/hpml/index';
|
|
|
|
import { HpmlTypeChecker } from '@/scripts/hpml/type-checker';
|
|
|
|
import { url } from '@/config';
|
|
|
|
import { collectPageVars } from '@/scripts/collect-page-vars';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { selectFile } from '@/scripts/select-file';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
export default defineComponent({
|
2019-04-29 02:11:57 +02:00
|
|
|
components: {
|
2020-12-05 04:50:09 +01:00
|
|
|
XDraggable: defineAsyncComponent(() => import('vuedraggable').then(x => x.default)),
|
2020-10-17 13:12:00 +02:00
|
|
|
XVariable, XBlocks, MkTextarea, MkContainer, MkButton, MkSelect, MkSwitch, MkInput,
|
2019-04-29 02:11:57 +02:00
|
|
|
},
|
|
|
|
|
2021-11-19 11:36:12 +01:00
|
|
|
provide() {
|
|
|
|
return {
|
|
|
|
readonly: this.readonly,
|
|
|
|
getScriptBlockList: this.getScriptBlockList,
|
|
|
|
getPageBlockList: this.getPageBlockList
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-04-29 02:11:57 +02:00
|
|
|
props: {
|
2019-05-24 12:19:43 +02:00
|
|
|
initPageId: {
|
|
|
|
type: String,
|
2019-04-29 02:11:57 +02:00
|
|
|
required: false
|
2019-04-29 23:40:02 +02:00
|
|
|
},
|
2019-05-24 12:19:43 +02:00
|
|
|
initPageName: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
initUser: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
2019-04-29 23:40:02 +02:00
|
|
|
},
|
2019-04-29 02:11:57 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 05:54:12 +02:00
|
|
|
[symbols.PAGE_INFO]: computed(() => {
|
2021-03-13 02:56:27 +01:00
|
|
|
let title = this.$ts._pages.newPage;
|
|
|
|
if (this.initPageId) {
|
|
|
|
title = this.$ts._pages.editPage;
|
|
|
|
}
|
|
|
|
else if (this.initPageName && this.initUser) {
|
|
|
|
title = this.$ts._pages.readPage;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
title: title,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-pencil-alt',
|
2021-10-01 17:51:37 +02:00
|
|
|
bg: 'var(--bg)',
|
2021-10-02 17:33:29 +02:00
|
|
|
tabs: [{
|
|
|
|
active: this.tab === 'settings',
|
|
|
|
title: this.$ts._pages.pageSetting,
|
|
|
|
icon: 'fas fa-cog',
|
|
|
|
onClick: () => { this.tab = 'settings'; },
|
|
|
|
}, {
|
|
|
|
active: this.tab === 'contents',
|
|
|
|
title: this.$ts._pages.contents,
|
|
|
|
icon: 'fas fa-sticky-note',
|
|
|
|
onClick: () => { this.tab = 'contents'; },
|
|
|
|
}, {
|
|
|
|
active: this.tab === 'variables',
|
|
|
|
title: this.$ts._pages.variables,
|
|
|
|
icon: 'fas fa-magic',
|
|
|
|
onClick: () => { this.tab = 'variables'; },
|
|
|
|
}, {
|
|
|
|
active: this.tab === 'script',
|
|
|
|
title: this.$ts.script,
|
|
|
|
icon: 'fas fa-code',
|
|
|
|
onClick: () => { this.tab = 'script'; },
|
2021-10-23 21:03:07 +02:00
|
|
|
}],
|
2021-03-13 02:56:27 +01:00
|
|
|
};
|
2020-11-15 05:42:04 +01:00
|
|
|
}),
|
2021-10-23 21:03:07 +02:00
|
|
|
tab: 'settings',
|
2020-12-19 02:55:52 +01:00
|
|
|
author: this.$i,
|
2019-05-24 12:19:43 +02:00
|
|
|
readonly: false,
|
|
|
|
page: null,
|
2019-04-29 02:11:57 +02:00
|
|
|
pageId: null,
|
2019-04-29 07:46:35 +02:00
|
|
|
currentName: null,
|
2019-04-29 02:11:57 +02:00
|
|
|
title: '',
|
|
|
|
summary: null,
|
|
|
|
name: Date.now().toString(),
|
|
|
|
eyeCatchingImage: null,
|
|
|
|
eyeCatchingImageId: null,
|
|
|
|
font: 'sans-serif',
|
|
|
|
content: [],
|
|
|
|
alignCenter: false,
|
2019-07-06 23:56:13 +02:00
|
|
|
hideTitleWhenPinned: false,
|
2019-04-29 02:11:57 +02:00
|
|
|
variables: [],
|
2020-04-20 14:35:27 +02:00
|
|
|
hpml: null,
|
2020-04-12 20:23:23 +02:00
|
|
|
script: '',
|
2019-04-29 02:11:57 +02:00
|
|
|
url,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
async eyeCatchingImageId() {
|
|
|
|
if (this.eyeCatchingImageId == null) {
|
|
|
|
this.eyeCatchingImage = null;
|
|
|
|
} else {
|
2020-10-17 13:12:00 +02:00
|
|
|
this.eyeCatchingImage = await os.api('drive/files/show', {
|
2019-04-29 02:11:57 +02:00
|
|
|
fileId: this.eyeCatchingImageId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-05-24 12:19:43 +02:00
|
|
|
async created() {
|
2020-04-20 14:35:27 +02:00
|
|
|
this.hpml = new HpmlTypeChecker();
|
2019-04-29 02:11:57 +02:00
|
|
|
|
|
|
|
this.$watch('variables', () => {
|
2020-04-20 14:35:27 +02:00
|
|
|
this.hpml.variables = this.variables;
|
2019-04-29 02:11:57 +02:00
|
|
|
}, { deep: true });
|
|
|
|
|
|
|
|
this.$watch('content', () => {
|
2020-04-20 14:35:27 +02:00
|
|
|
this.hpml.pageVars = collectPageVars(this.content);
|
2019-04-29 02:11:57 +02:00
|
|
|
}, { deep: true });
|
|
|
|
|
2019-05-24 12:19:43 +02:00
|
|
|
if (this.initPageId) {
|
2020-10-17 13:12:00 +02:00
|
|
|
this.page = await os.api('pages/show', {
|
2019-05-24 12:19:43 +02:00
|
|
|
pageId: this.initPageId,
|
|
|
|
});
|
|
|
|
} else if (this.initPageName && this.initUser) {
|
2020-10-17 13:12:00 +02:00
|
|
|
this.page = await os.api('pages/show', {
|
2019-05-24 12:19:43 +02:00
|
|
|
name: this.initPageName,
|
|
|
|
username: this.initUser,
|
|
|
|
});
|
|
|
|
this.readonly = true;
|
|
|
|
}
|
|
|
|
|
2019-04-29 02:11:57 +02:00
|
|
|
if (this.page) {
|
2019-05-01 13:48:56 +02:00
|
|
|
this.author = this.page.user;
|
|
|
|
this.pageId = this.page.id;
|
|
|
|
this.title = this.page.title;
|
|
|
|
this.name = this.page.name;
|
|
|
|
this.currentName = this.page.name;
|
|
|
|
this.summary = this.page.summary;
|
|
|
|
this.font = this.page.font;
|
2020-04-12 20:23:23 +02:00
|
|
|
this.script = this.page.script;
|
2019-07-06 23:56:13 +02:00
|
|
|
this.hideTitleWhenPinned = this.page.hideTitleWhenPinned;
|
2019-05-01 13:48:56 +02:00
|
|
|
this.alignCenter = this.page.alignCenter;
|
|
|
|
this.content = this.page.content;
|
|
|
|
this.variables = this.page.variables;
|
|
|
|
this.eyeCatchingImageId = this.page.eyeCatchingImageId;
|
2019-04-29 02:11:57 +02:00
|
|
|
} else {
|
2019-08-18 05:42:58 +02:00
|
|
|
const id = uuid();
|
2019-04-29 02:11:57 +02:00
|
|
|
this.content = [{
|
|
|
|
id,
|
|
|
|
type: 'text',
|
|
|
|
text: 'Hello World!'
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-12-19 13:41:00 +01:00
|
|
|
getSaveOptions() {
|
|
|
|
return {
|
2019-08-28 01:00:05 +02:00
|
|
|
title: this.title.trim(),
|
|
|
|
name: this.name.trim(),
|
|
|
|
summary: this.summary,
|
|
|
|
font: this.font,
|
2020-04-12 20:23:23 +02:00
|
|
|
script: this.script,
|
2019-08-28 01:00:05 +02:00
|
|
|
hideTitleWhenPinned: this.hideTitleWhenPinned,
|
|
|
|
alignCenter: this.alignCenter,
|
|
|
|
content: this.content,
|
|
|
|
variables: this.variables,
|
|
|
|
eyeCatchingImageId: this.eyeCatchingImageId,
|
|
|
|
};
|
2020-12-19 13:41:00 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
save() {
|
|
|
|
const options = this.getSaveOptions();
|
2019-08-28 01:00:05 +02:00
|
|
|
|
2019-09-01 23:21:43 +02:00
|
|
|
const onError = err => {
|
2019-09-01 23:02:35 +02:00
|
|
|
if (err.id == '3d81ceae-475f-4600-b2a8-2bc116157532') {
|
2019-09-01 23:04:12 +02:00
|
|
|
if (err.info.param == 'name') {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2019-09-01 23:02:35 +02:00
|
|
|
type: 'error',
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts._pages.invalidNameTitle,
|
|
|
|
text: this.$ts._pages.invalidNameText
|
2019-09-01 23:02:35 +02:00
|
|
|
});
|
|
|
|
}
|
2019-09-01 23:04:12 +02:00
|
|
|
} else if (err.code == 'NAME_ALREADY_EXISTS') {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2019-09-01 23:04:12 +02:00
|
|
|
type: 'error',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts._pages.nameAlreadyExists
|
2019-09-01 23:04:12 +02:00
|
|
|
});
|
|
|
|
}
|
2019-09-01 23:21:43 +02:00
|
|
|
};
|
2019-09-01 23:02:35 +02:00
|
|
|
|
2019-04-29 02:11:57 +02:00
|
|
|
if (this.pageId) {
|
2019-08-28 01:00:05 +02:00
|
|
|
options.pageId = this.pageId;
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('pages/update', options)
|
2019-08-28 01:00:05 +02:00
|
|
|
.then(page => {
|
2019-04-29 07:46:35 +02:00
|
|
|
this.currentName = this.name.trim();
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2019-04-29 02:11:57 +02:00
|
|
|
type: 'success',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts._pages.updated
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
2019-09-01 23:04:12 +02:00
|
|
|
}).catch(onError);
|
2019-04-29 02:11:57 +02:00
|
|
|
} else {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('pages/create', options)
|
2019-08-28 01:00:05 +02:00
|
|
|
.then(page => {
|
2019-04-29 02:11:57 +02:00
|
|
|
this.pageId = page.id;
|
2019-04-29 07:46:35 +02:00
|
|
|
this.currentName = this.name.trim();
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2019-04-29 02:11:57 +02:00
|
|
|
type: 'success',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts._pages.created
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
2020-11-17 06:59:15 +01:00
|
|
|
this.$router.push(`/pages/edit/${this.pageId}`);
|
2019-09-01 23:04:12 +02:00
|
|
|
}).catch(onError);
|
2019-04-29 02:11:57 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
del() {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.confirm({
|
2019-04-29 02:11:57 +02:00
|
|
|
type: 'warning',
|
2020-03-22 02:51:40 +01:00
|
|
|
text: this.$t('removeAreYouSure', { x: this.title.trim() }),
|
2019-04-29 02:11:57 +02:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('pages/delete', {
|
2019-04-29 02:11:57 +02:00
|
|
|
pageId: this.pageId,
|
|
|
|
}).then(() => {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2019-04-29 02:11:57 +02:00
|
|
|
type: 'success',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts._pages.deleted
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
2020-11-17 06:59:15 +01:00
|
|
|
this.$router.push(`/pages`);
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-12-19 13:41:00 +01:00
|
|
|
duplicate() {
|
|
|
|
this.title = this.title + ' - copy';
|
|
|
|
this.name = this.name + '-copy';
|
|
|
|
os.api('pages/create', this.getSaveOptions()).then(page => {
|
|
|
|
this.pageId = page.id;
|
|
|
|
this.currentName = this.name.trim();
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2020-12-19 13:41:00 +01:00
|
|
|
type: 'success',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts._pages.created
|
2020-12-19 13:41:00 +01:00
|
|
|
});
|
|
|
|
this.$router.push(`/pages/edit/${this.pageId}`);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-04-29 02:11:57 +02:00
|
|
|
async add() {
|
2021-11-18 10:45:58 +01:00
|
|
|
const { canceled, result: type } = await os.select({
|
2019-04-29 02:11:57 +02:00
|
|
|
type: null,
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts._pages.chooseBlock,
|
2021-11-18 10:45:58 +01:00
|
|
|
groupedItems: this.getPageBlockList()
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2019-08-18 05:42:58 +02:00
|
|
|
const id = uuid();
|
2019-04-29 02:11:57 +02:00
|
|
|
this.content.push({ id, type });
|
|
|
|
},
|
|
|
|
|
|
|
|
async addVariable() {
|
2021-11-18 10:45:58 +01:00
|
|
|
let { canceled, result: name } = await os.inputText({
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts._pages.enterVariableName,
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
name = name.trim();
|
|
|
|
|
2020-04-20 14:35:27 +02:00
|
|
|
if (this.hpml.isUsedName(name)) {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2019-04-29 02:11:57 +02:00
|
|
|
type: 'error',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts._pages.variableNameIsAlreadyUsed
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-18 05:42:58 +02:00
|
|
|
const id = uuid();
|
2019-04-29 02:11:57 +02:00
|
|
|
this.variables.push({ id, name, type: null });
|
|
|
|
},
|
|
|
|
|
|
|
|
removeVariable(v) {
|
2020-12-07 16:32:00 +01:00
|
|
|
this.variables = this.variables.filter(x => x.name !== v.name);
|
2019-04-29 02:11:57 +02:00
|
|
|
},
|
|
|
|
|
2019-04-29 23:40:02 +02:00
|
|
|
getPageBlockList() {
|
|
|
|
return [{
|
2020-12-26 02:47:36 +01:00
|
|
|
label: this.$ts._pages.contentBlocks,
|
2019-04-30 05:15:41 +02:00
|
|
|
items: [
|
2020-12-26 02:47:36 +01:00
|
|
|
{ value: 'section', text: this.$ts._pages.blocks.section },
|
|
|
|
{ value: 'text', text: this.$ts._pages.blocks.text },
|
|
|
|
{ value: 'image', text: this.$ts._pages.blocks.image },
|
|
|
|
{ value: 'textarea', text: this.$ts._pages.blocks.textarea },
|
|
|
|
{ value: 'note', text: this.$ts._pages.blocks.note },
|
|
|
|
{ value: 'canvas', text: this.$ts._pages.blocks.canvas },
|
2019-04-30 05:15:41 +02:00
|
|
|
]
|
2019-04-29 23:40:02 +02:00
|
|
|
}, {
|
2020-12-26 02:47:36 +01:00
|
|
|
label: this.$ts._pages.inputBlocks,
|
2019-04-30 05:15:41 +02:00
|
|
|
items: [
|
2020-12-26 02:47:36 +01:00
|
|
|
{ value: 'button', text: this.$ts._pages.blocks.button },
|
|
|
|
{ value: 'radioButton', text: this.$ts._pages.blocks.radioButton },
|
|
|
|
{ value: 'textInput', text: this.$ts._pages.blocks.textInput },
|
|
|
|
{ value: 'textareaInput', text: this.$ts._pages.blocks.textareaInput },
|
|
|
|
{ value: 'numberInput', text: this.$ts._pages.blocks.numberInput },
|
|
|
|
{ value: 'switch', text: this.$ts._pages.blocks.switch },
|
|
|
|
{ value: 'counter', text: this.$ts._pages.blocks.counter }
|
2019-04-30 05:15:41 +02:00
|
|
|
]
|
2019-04-29 23:40:02 +02:00
|
|
|
}, {
|
2020-12-26 02:47:36 +01:00
|
|
|
label: this.$ts._pages.specialBlocks,
|
2019-04-30 05:15:41 +02:00
|
|
|
items: [
|
2020-12-26 02:47:36 +01:00
|
|
|
{ value: 'if', text: this.$ts._pages.blocks.if },
|
|
|
|
{ value: 'post', text: this.$ts._pages.blocks.post }
|
2019-04-30 05:15:41 +02:00
|
|
|
]
|
2019-04-29 23:40:02 +02:00
|
|
|
}];
|
|
|
|
},
|
|
|
|
|
2019-04-29 02:11:57 +02:00
|
|
|
getScriptBlockList(type: string = null) {
|
|
|
|
const list = [];
|
|
|
|
|
2019-05-05 08:17:29 +02:00
|
|
|
const blocks = blockDefs.filter(block => type === null || block.out === null || block.out === type || typeof block.out === 'number');
|
2019-04-29 02:11:57 +02:00
|
|
|
|
|
|
|
for (const block of blocks) {
|
|
|
|
const category = list.find(x => x.category === block.category);
|
|
|
|
if (category) {
|
|
|
|
category.items.push({
|
|
|
|
value: block.type,
|
2020-01-29 20:37:25 +01:00
|
|
|
text: this.$t(`_pages.script.blocks.${block.type}`)
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
list.push({
|
|
|
|
category: block.category,
|
2020-04-12 20:23:23 +02:00
|
|
|
label: this.$t(`_pages.script.categories.${block.category}`),
|
2019-04-29 02:11:57 +02:00
|
|
|
items: [{
|
|
|
|
value: block.type,
|
2020-01-29 20:37:25 +01:00
|
|
|
text: this.$t(`_pages.script.blocks.${block.type}`)
|
2019-04-29 02:11:57 +02:00
|
|
|
}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const userFns = this.variables.filter(x => x.type === 'fn');
|
|
|
|
if (userFns.length > 0) {
|
|
|
|
list.unshift({
|
2020-04-12 20:23:23 +02:00
|
|
|
label: this.$t(`_pages.script.categories.fn`),
|
2019-04-29 02:11:57 +02:00
|
|
|
items: userFns.map(v => ({
|
|
|
|
value: 'fn:' + v.name,
|
|
|
|
text: v.name
|
|
|
|
}))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
},
|
|
|
|
|
2020-11-15 05:42:04 +01:00
|
|
|
setEyeCatchingImage(e) {
|
2022-01-28 03:53:12 +01:00
|
|
|
selectFile(e.currentTarget ?? e.target, null).then(file => {
|
2019-04-29 02:11:57 +02:00
|
|
|
this.eyeCatchingImageId = file.id;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
removeEyeCatchingImage() {
|
|
|
|
this.eyeCatchingImageId = null;
|
2020-08-22 01:03:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
highlighter(code) {
|
|
|
|
return highlight(code, languages.js, 'javascript');
|
|
|
|
},
|
2019-04-29 02:11:57 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
<style lang="scss" scoped>
|
2021-10-11 18:04:50 +02:00
|
|
|
.jqqmcavi {
|
|
|
|
> .button {
|
|
|
|
& + .button {
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
.gwbmwxkm {
|
2020-10-17 13:12:00 +02:00
|
|
|
position: relative;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
> header {
|
|
|
|
> .title {
|
|
|
|
z-index: 1;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0 16px;
|
|
|
|
line-height: 42px;
|
|
|
|
font-size: 0.9em;
|
|
|
|
font-weight: bold;
|
2020-04-15 17:39:21 +02:00
|
|
|
box-shadow: 0 1px rgba(#000, 0.07);
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2021-04-20 16:22:59 +02:00
|
|
|
> i {
|
2020-01-29 20:37:25 +01:00
|
|
|
margin-right: 6px;
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
> .buttons {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 2;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
> button {
|
|
|
|
padding: 0;
|
|
|
|
width: 42px;
|
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 42px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
> section {
|
|
|
|
padding: 0 32px 32px 32px;
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
@media (max-width: 500px) {
|
|
|
|
padding: 0 16px 16px 16px;
|
|
|
|
}
|
2019-04-29 07:46:35 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
> .view {
|
|
|
|
display: inline-block;
|
|
|
|
margin: 16px 0 0 0;
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
> .content {
|
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
> .eyeCatch {
|
|
|
|
margin-bottom: 16px;
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
> div {
|
|
|
|
> img {
|
|
|
|
max-width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
.qmuvgica {
|
2021-10-11 18:04:50 +02:00
|
|
|
padding: 16px;
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
> .variables {
|
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
> .add {
|
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
</style>
|