This commit is contained in:
syuilo 2018-02-25 22:56:23 +09:00
parent 59834220c1
commit 18595dd3bb

View File

@ -36,8 +36,28 @@ export default Vue.extend({
sending: false sending: false
}; };
}, },
computed: {
draftId(): string {
return this.user.id;
}
},
watch: {
text() {
this.saveDraft();
},
file() {
this.saveDraft();
}
},
mounted() { mounted() {
autosize(this.$refs.textarea); autosize(this.$refs.textarea);
// 稿
const draft = JSON.parse(localStorage.getItem('message_drafts') || '{}')[this.draftId];
if (draft) {
this.text = draft.data.text;
this.file = draft.data.file;
}
}, },
methods: { methods: {
onPaste(e) { onPaste(e) {
@ -89,7 +109,30 @@ export default Vue.extend({
clear() { clear() {
this.text = ''; this.text = '';
this.file = null; this.file = null;
} this.deleteDraft();
},
saveDraft() {
const data = JSON.parse(localStorage.getItem('message_drafts') || '{}');
data[this.draftId] = {
updated_at: new Date(),
data: {
text: this.text,
file: this.file
}
}
localStorage.setItem('message_drafts', JSON.stringify(data));
},
deleteDraft() {
const data = JSON.parse(localStorage.getItem('message_drafts') || '{}');
delete data[this.draftId];
localStorage.setItem('message_drafts', JSON.stringify(data));
},
} }
}); });
</script> </script>