|
@@ -1,5 +1,5 @@
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
-import { ref, reactive, toRaw, provide, onMounted } from "vue";
|
|
|
|
|
|
+import { ref, onMounted } from "vue";
|
|
import {v4 as uuid4} from 'uuid'
|
|
import {v4 as uuid4} from 'uuid'
|
|
import {
|
|
import {
|
|
S3Client,
|
|
S3Client,
|
|
@@ -20,9 +20,6 @@ import { MdEditor } from "md-editor-v3";
|
|
import { pathsToTree, getTreeLeafs } from "@/utils/s3Helper";
|
|
import { pathsToTree, getTreeLeafs } from "@/utils/s3Helper";
|
|
import "md-editor-v3/lib/style.css";
|
|
import "md-editor-v3/lib/style.css";
|
|
|
|
|
|
-const DOCS_LIST_BUCKET = "cococlass-help-docs";
|
|
|
|
-const DOCS_MEDIA_BUCKET = "cococlass-help-docs-medias";
|
|
|
|
-
|
|
|
|
const s3 = new S3Client({
|
|
const s3 = new S3Client({
|
|
credentials: {
|
|
credentials: {
|
|
accessKeyId: import.meta.env.VITE_AWS_S3_ACCESS_KEY_ID,
|
|
accessKeyId: import.meta.env.VITE_AWS_S3_ACCESS_KEY_ID,
|
|
@@ -30,15 +27,13 @@ const s3 = new S3Client({
|
|
},
|
|
},
|
|
region: import.meta.env.VITE_AWS_S3_REGION,
|
|
region: import.meta.env.VITE_AWS_S3_REGION,
|
|
});
|
|
});
|
|
-provide("s3", s3);
|
|
|
|
-provide("DOCS_LIST_BUCKET", DOCS_LIST_BUCKET);
|
|
|
|
|
|
|
|
const tree$ = ref<InstanceType<typeof ElTree>>();
|
|
const tree$ = ref<InstanceType<typeof ElTree>>();
|
|
|
|
|
|
const dataSource = ref<TreeData[]>([]);
|
|
const dataSource = ref<TreeData[]>([]);
|
|
const sideLoading = ref(false);
|
|
const sideLoading = ref(false);
|
|
const loadS3DocsListObjects = async () => {
|
|
const loadS3DocsListObjects = async () => {
|
|
- const command = new ListObjectsCommand({ Bucket: DOCS_LIST_BUCKET });
|
|
|
|
|
|
+ const command = new ListObjectsCommand({ Bucket: import.meta.env.VITE_DOCS_LIST_BUCKET });
|
|
const result = await s3.send(command);
|
|
const result = await s3.send(command);
|
|
return result.Contents!.map((item) => item.Key!).slice(0, 200);
|
|
return result.Contents!.map((item) => item.Key!).slice(0, 200);
|
|
};
|
|
};
|
|
@@ -59,7 +54,7 @@ const onNodeClick = async (data: TreeData, node) => {
|
|
}
|
|
}
|
|
textLoading.value = true;
|
|
textLoading.value = true;
|
|
const command = new GetObjectCommand({
|
|
const command = new GetObjectCommand({
|
|
- Bucket: DOCS_LIST_BUCKET,
|
|
|
|
|
|
+ Bucket: import.meta.env.VITE_DOCS_LIST_BUCKET,
|
|
Key: data.key,
|
|
Key: data.key,
|
|
ResponseCacheControl: "no-cache",
|
|
ResponseCacheControl: "no-cache",
|
|
});
|
|
});
|
|
@@ -74,25 +69,24 @@ const text = ref("");
|
|
const textLoading = ref(false);
|
|
const textLoading = ref(false);
|
|
|
|
|
|
const onUploadImg = async (files: File[], callback: (urls: string[] | { url: string; alt: string; title: string }[]) => void) => {
|
|
const onUploadImg = async (files: File[], callback: (urls: string[] | { url: string; alt: string; title: string }[]) => void) => {
|
|
- console.log(files)
|
|
|
|
let result = []
|
|
let result = []
|
|
for (const file of files) {
|
|
for (const file of files) {
|
|
try {
|
|
try {
|
|
const key = `${uuid4()}::${file.name}`
|
|
const key = `${uuid4()}::${file.name}`
|
|
const command = new PutObjectCommand({
|
|
const command = new PutObjectCommand({
|
|
- Bucket: DOCS_MEDIA_BUCKET,
|
|
|
|
|
|
+ Bucket: import.meta.env.DOCS_MEDIA_BUCKET,
|
|
Key: key,
|
|
Key: key,
|
|
Body: file,
|
|
Body: file,
|
|
ACL: 'public-read',
|
|
ACL: 'public-read',
|
|
});
|
|
});
|
|
const res = await s3.send(command);
|
|
const res = await s3.send(command);
|
|
- result.push({url: `https://${DOCS_MEDIA_BUCKET}.s3.amazonaws.com/${key}`, alt: file.name, title: file.name})
|
|
|
|
|
|
+ result.push({url: `https://${import.meta.env.DOCS_MEDIA_BUCKET}.s3.amazonaws.com/${key}`, alt: file.name, title: file.name})
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.error(e)
|
|
console.error(e)
|
|
ElNotification.error(`${file.name} 上传失败`)
|
|
ElNotification.error(`${file.name} 上传失败`)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- callback(result)
|
|
|
|
|
|
+ callback(result)
|
|
};
|
|
};
|
|
const onSave = async () => {
|
|
const onSave = async () => {
|
|
if (!currentOpenData.value) {
|
|
if (!currentOpenData.value) {
|
|
@@ -102,7 +96,7 @@ const onSave = async () => {
|
|
textLoading.value = true
|
|
textLoading.value = true
|
|
try {
|
|
try {
|
|
const command = new PutObjectCommand({
|
|
const command = new PutObjectCommand({
|
|
- Bucket: DOCS_LIST_BUCKET,
|
|
|
|
|
|
+ Bucket: import.meta.env.VITE_DOCS_LIST_BUCKET,
|
|
Key: currentOpenData.value?.key,
|
|
Key: currentOpenData.value?.key,
|
|
Body: text.value,
|
|
Body: text.value,
|
|
});
|
|
});
|
|
@@ -139,7 +133,7 @@ const onAppend = async (data: TreeData) => {
|
|
const key = `${data.key ? `${data.key}/` : ''}${filename}`
|
|
const key = `${data.key ? `${data.key}/` : ''}${filename}`
|
|
if (!isDir) {
|
|
if (!isDir) {
|
|
const command = new PutObjectCommand({
|
|
const command = new PutObjectCommand({
|
|
- Bucket: DOCS_LIST_BUCKET,
|
|
|
|
|
|
+ Bucket: import.meta.env.VITE_DOCS_LIST_BUCKET,
|
|
Key: key,
|
|
Key: key,
|
|
Body: "",
|
|
Body: "",
|
|
});
|
|
});
|
|
@@ -172,7 +166,7 @@ const onRemove = async (node: Node, data: TreeData) => {
|
|
try {
|
|
try {
|
|
const leafDatas = getTreeLeafs(data)
|
|
const leafDatas = getTreeLeafs(data)
|
|
const command = new DeleteObjectsCommand({
|
|
const command = new DeleteObjectsCommand({
|
|
- Bucket: DOCS_LIST_BUCKET,
|
|
|
|
|
|
+ Bucket: import.meta.env.VITE_DOCS_LIST_BUCKET,
|
|
Delete: {
|
|
Delete: {
|
|
Objects: leafDatas.map(d => ({Key: d.key})),
|
|
Objects: leafDatas.map(d => ({Key: d.key})),
|
|
Quiet: false,
|
|
Quiet: false,
|