feat: 对话功能,上传附件功能开发
This commit is contained in:
66
src/renderer/stores/draft.js
Normal file
66
src/renderer/stores/draft.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
|
||||
/**
|
||||
* 草稿消息 Store
|
||||
* 用于在页面间传递待发送的消息内容(文本和文件)
|
||||
*/
|
||||
export const useDraftStore = defineStore('draft', () => {
|
||||
// 待发送的文本内容
|
||||
const text = ref('');
|
||||
|
||||
// 待发送的文件列表
|
||||
// 格式: [{ id, filename, mime, type: File, url }]
|
||||
// url: 图片为 base64 (data:image/...),文本文件为 data:text/plain;base64,... 等
|
||||
const files = ref([]);
|
||||
|
||||
/**
|
||||
* 设置草稿内容
|
||||
* @param {string} content - 文本内容
|
||||
* @param {Array} fileList - 文件列表
|
||||
*/
|
||||
function setDraft(content, fileList = []) {
|
||||
text.value = content;
|
||||
files.value = fileList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取草稿内容并清空
|
||||
* @returns {{text: string, files: Array}}
|
||||
*/
|
||||
function takeDraft() {
|
||||
const result = {
|
||||
text: text.value,
|
||||
files: [...files.value],
|
||||
};
|
||||
// 清空草稿
|
||||
text.value = '';
|
||||
files.value = [];
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空草稿
|
||||
*/
|
||||
function clearDraft() {
|
||||
text.value = '';
|
||||
files.value = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有草稿内容
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasDraft() {
|
||||
return text.value.trim().length > 0 || files.value.length > 0;
|
||||
}
|
||||
|
||||
return {
|
||||
text,
|
||||
files,
|
||||
setDraft,
|
||||
takeDraft,
|
||||
clearDraft,
|
||||
hasDraft,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user