2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
|
|
|
<div class="ngbfujlo">
|
2021-08-06 22:29:19 +09:00
|
|
|
<MkTextarea :model-value="text" readonly style="margin: 0;"></MkTextarea>
|
2021-11-19 19:36:12 +09:00
|
|
|
<MkButton class="button" primary :disabled="posting || posted" @click="post()">
|
2021-04-20 23:22:59 +09:00
|
|
|
<i v-if="posted" class="fas fa-check"></i>
|
|
|
|
<i v-else class="fas fa-paper-plane"></i>
|
|
|
|
</MkButton>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-01-30 10:59:05 +09:00
|
|
|
import { defineComponent, PropType } from 'vue';
|
2021-09-30 00:50:45 +09:00
|
|
|
import MkTextarea from '../form/textarea.vue';
|
2020-01-30 04:37:25 +09:00
|
|
|
import MkButton from '../ui/button.vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import { apiUrl } from '@/config';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { PostBlock } from '@/scripts/hpml/block';
|
|
|
|
import { Hpml } from '@/scripts/hpml/evaluator';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-01-30 04:37:25 +09:00
|
|
|
components: {
|
|
|
|
MkTextarea,
|
|
|
|
MkButton,
|
|
|
|
},
|
|
|
|
props: {
|
2021-01-30 10:59:05 +09:00
|
|
|
block: {
|
|
|
|
type: Object as PropType<PostBlock>,
|
2020-01-30 04:37:25 +09:00
|
|
|
required: true
|
|
|
|
},
|
2020-04-20 21:35:27 +09:00
|
|
|
hpml: {
|
2021-01-30 10:59:05 +09:00
|
|
|
type: Object as PropType<Hpml>,
|
2020-01-30 04:37:25 +09:00
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-01-30 10:59:05 +09:00
|
|
|
text: this.hpml.interpolate(this.block.text),
|
2020-01-30 04:37:25 +09:00
|
|
|
posted: false,
|
|
|
|
posting: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
2020-04-20 21:35:27 +09:00
|
|
|
'hpml.vars': {
|
2020-01-30 04:37:25 +09:00
|
|
|
handler() {
|
2021-01-30 10:59:05 +09:00
|
|
|
this.text = this.hpml.interpolate(this.block.text);
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
deep: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2020-04-19 09:05:20 +09:00
|
|
|
upload() {
|
2020-10-18 10:11:34 +09:00
|
|
|
const promise = new Promise((ok) => {
|
2021-01-30 10:59:05 +09:00
|
|
|
const canvas = this.hpml.canvases[this.block.canvasId];
|
2020-04-19 09:05:20 +09:00
|
|
|
canvas.toBlob(blob => {
|
2022-05-26 22:53:09 +09:00
|
|
|
const formData = new FormData();
|
|
|
|
formData.append('file', blob);
|
|
|
|
formData.append('i', this.$i.token);
|
2020-12-19 10:55:52 +09:00
|
|
|
if (this.$store.state.uploadFolder) {
|
2022-05-26 22:53:09 +09:00
|
|
|
formData.append('folderId', this.$store.state.uploadFolder);
|
2020-04-22 00:34:56 +09:00
|
|
|
}
|
2020-04-19 09:05:20 +09:00
|
|
|
|
|
|
|
fetch(apiUrl + '/drive/files/create', {
|
|
|
|
method: 'POST',
|
2022-05-26 22:53:09 +09:00
|
|
|
body: formData,
|
2020-04-19 09:05:20 +09:00
|
|
|
})
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(f => {
|
|
|
|
ok(f);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
2020-10-18 10:11:34 +09:00
|
|
|
os.promiseDialog(promise);
|
|
|
|
return promise;
|
2020-04-19 09:05:20 +09:00
|
|
|
},
|
|
|
|
async post() {
|
2020-01-30 04:37:25 +09:00
|
|
|
this.posting = true;
|
2021-01-30 10:59:05 +09:00
|
|
|
const file = this.block.attachCanvasImage ? await this.upload() : null;
|
2020-10-17 20:12:00 +09:00
|
|
|
os.apiWithDialog('notes/create', {
|
2020-04-19 17:40:46 +09:00
|
|
|
text: this.text === '' ? null : this.text,
|
2020-04-19 09:05:20 +09:00
|
|
|
fileIds: file ? [file.id] : undefined,
|
2020-01-30 04:37:25 +09:00
|
|
|
}).then(() => {
|
|
|
|
this.posted = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ngbfujlo {
|
2020-04-19 09:05:20 +09:00
|
|
|
position: relative;
|
2020-01-31 07:01:45 +09:00
|
|
|
padding: 32px;
|
2020-01-30 04:37:25 +09:00
|
|
|
border-radius: 6px;
|
2020-01-31 07:01:45 +09:00
|
|
|
box-shadow: 0 2px 8px var(--shadow);
|
2020-04-19 09:05:20 +09:00
|
|
|
z-index: 1;
|
2020-01-31 07:01:45 +09:00
|
|
|
|
|
|
|
> .button {
|
|
|
|
margin-top: 32px;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
@media (max-width: 600px) {
|
2020-01-31 07:01:45 +09:00
|
|
|
padding: 16px;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-01-31 07:01:45 +09:00
|
|
|
> .button {
|
2020-01-30 04:37:25 +09:00
|
|
|
margin-top: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|