2023-01-05 04:59:48 +00:00
|
|
|
<template>
|
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<MkSpacer :content-max="700">
|
2023-01-16 01:04:10 +00:00
|
|
|
<div class="_gaps">
|
2023-01-05 12:04:56 +00:00
|
|
|
<MkInput v-model="title">
|
|
|
|
<template #label>{{ i18n.ts._play.title }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkTextarea v-model="summary">
|
|
|
|
<template #label>{{ i18n.ts._play.summary }}</template>
|
|
|
|
</MkTextarea>
|
2023-01-16 01:04:10 +00:00
|
|
|
<MkButton primary @click="selectPreset">{{ i18n.ts.selectFromPresets }}<i class="ti ti-chevron-down"></i></MkButton>
|
2023-01-05 12:04:56 +00:00
|
|
|
<MkTextarea v-model="script" class="_monospace" tall spellcheck="false">
|
|
|
|
<template #label>{{ i18n.ts._play.script }}</template>
|
|
|
|
</MkTextarea>
|
2023-01-06 00:41:14 +00:00
|
|
|
<div class="_buttons">
|
2023-01-05 12:04:56 +00:00
|
|
|
<MkButton primary @click="save"><i class="ti ti-check"></i> {{ i18n.ts.save }}</MkButton>
|
|
|
|
<MkButton @click="show"><i class="ti ti-eye"></i> {{ i18n.ts.show }}</MkButton>
|
|
|
|
</div>
|
2023-01-05 04:59:48 +00:00
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, onDeactivated, onUnmounted, Ref, ref, watch } from 'vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { url } from '@/config';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2023-01-07 06:09:46 +00:00
|
|
|
import MkTextarea from '@/components/MkTextarea.vue';
|
|
|
|
import MkInput from '@/components/MkInput.vue';
|
2023-01-05 04:59:48 +00:00
|
|
|
import { useRouter } from '@/router';
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
id?: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
let flash = $ref(null);
|
|
|
|
|
|
|
|
if (props.id) {
|
|
|
|
flash = await os.api('flash/show', {
|
|
|
|
flashId: props.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let title = $ref(flash?.title ?? 'New Play');
|
|
|
|
let summary = $ref(flash?.summary ?? '');
|
|
|
|
let permissions = $ref(flash?.permissions ?? []);
|
2023-01-07 08:18:30 +00:00
|
|
|
let script = $ref(flash?.script ?? `/// @ 0.12.2
|
2023-01-05 04:59:48 +00:00
|
|
|
|
|
|
|
var name = ""
|
|
|
|
|
|
|
|
Ui:render([
|
|
|
|
Ui:C:textInput({
|
|
|
|
label: "Your name"
|
|
|
|
onInput: @(v) { name = v }
|
|
|
|
})
|
|
|
|
Ui:C:button({
|
|
|
|
text: "Hello"
|
|
|
|
onClick: @() {
|
|
|
|
Mk:dialog(null \`Hello, {name}!\`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
])
|
|
|
|
`);
|
|
|
|
|
2023-01-16 01:04:10 +00:00
|
|
|
function selectPreset(ev: MouseEvent) {
|
|
|
|
os.popupMenu([{
|
|
|
|
text: 'Omikuji',
|
|
|
|
action: () => {
|
|
|
|
script = `/// @ 0.12.2
|
|
|
|
// ユーザーごとに日替わりのおみくじのプリセット
|
|
|
|
|
|
|
|
// 選択肢
|
|
|
|
let choices = [
|
|
|
|
"ギガ吉"
|
|
|
|
"大吉"
|
|
|
|
"吉"
|
|
|
|
"中吉"
|
|
|
|
"小吉"
|
|
|
|
"末吉"
|
|
|
|
"凶"
|
|
|
|
"大凶"
|
|
|
|
]
|
|
|
|
|
|
|
|
// シードが「ユーザーID+今日の日付」である乱数生成器を用意
|
|
|
|
let random = Math:gen_rng(\`{USER_ID}{Date:day()}\`)
|
|
|
|
|
|
|
|
// ランダムに選択肢を選ぶ
|
|
|
|
let chosen = choices[random(0 (choices.len - 1))]
|
|
|
|
|
|
|
|
// 結果のテキスト
|
|
|
|
let result = \`今日のあなたの運勢は **{chosen}** です。\`
|
|
|
|
|
|
|
|
// UIを表示
|
|
|
|
Ui:render([
|
|
|
|
Ui:C:container({
|
|
|
|
align: 'center'
|
|
|
|
children: [
|
|
|
|
Ui:C:mfm({ text: result })
|
|
|
|
Ui:C:postFormButton({
|
|
|
|
text: "投稿する"
|
|
|
|
rounded: true
|
|
|
|
primary: true
|
|
|
|
form: {
|
|
|
|
text: \`{result}{Str:lf}{THIS_URL}\`
|
|
|
|
}
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
])
|
|
|
|
`;
|
|
|
|
},
|
|
|
|
}], ev.currentTarget ?? ev.target);
|
|
|
|
}
|
|
|
|
|
2023-01-05 04:59:48 +00:00
|
|
|
async function save() {
|
|
|
|
if (flash) {
|
|
|
|
os.apiWithDialog('flash/update', {
|
|
|
|
flashId: props.id,
|
|
|
|
title,
|
|
|
|
summary,
|
|
|
|
permissions,
|
|
|
|
script,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const created = await os.apiWithDialog('flash/create', {
|
|
|
|
title,
|
|
|
|
summary,
|
|
|
|
permissions,
|
|
|
|
script,
|
|
|
|
});
|
|
|
|
router.push('/play/' + created.id + '/edit');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function show() {
|
|
|
|
if (flash == null) {
|
|
|
|
os.alert({
|
|
|
|
text: 'Please save',
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
os.pageWindow(`/play/${flash.id}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata(computed(() => flash ? {
|
|
|
|
title: i18n.ts._play.edit + ': ' + flash.title,
|
|
|
|
} : {
|
|
|
|
title: i18n.ts._play.new,
|
|
|
|
}));
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
</style>
|