|
@@ -132,47 +132,21 @@ export default defineComponent({
|
|
|
watch(
|
|
|
() => props.fileList,
|
|
|
() => {
|
|
|
- // console.log('list');
|
|
|
initFileList();
|
|
|
}
|
|
|
);
|
|
|
const handleClearFile = () => {
|
|
|
- console.log(uploadRef.value, 'uploadRef.value');
|
|
|
uploadRef.value?.clear();
|
|
|
};
|
|
|
expose({
|
|
|
handleClearFile
|
|
|
});
|
|
|
|
|
|
- const getVideoMsg = (file: any) => {
|
|
|
- return new Promise(resolve => {
|
|
|
- let dataURL = '';
|
|
|
- const videoElement = document.createElement('video');
|
|
|
- videoElement.src = URL.createObjectURL(file);
|
|
|
- videoElement.addEventListener('loadedmetadata', function () {
|
|
|
- const canvas: any = document.createElement('canvas'),
|
|
|
- width = videoElement.videoWidth, //canvas的尺寸和图片一样
|
|
|
- height = videoElement.videoHeight;
|
|
|
- canvas.width = width;
|
|
|
- canvas.height = height;
|
|
|
- canvas.getContext('2d').drawImage(videoElement, 0, 0, width, height); //绘制canvas
|
|
|
- dataURL = canvas.toDataURL('image/jpeg'); //转换为base64
|
|
|
- resolve(dataURL);
|
|
|
- // resolve({
|
|
|
- // duration: videoElement.duration,
|
|
|
- // height: videoElement.videoHeight,
|
|
|
- // width: videoElement.videoWidth
|
|
|
- // });
|
|
|
- });
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
const CropperModal = ref();
|
|
|
const onBeforeUpload = async (options: any) => {
|
|
|
const file = options.file;
|
|
|
// 文件大小
|
|
|
let isLt2M = true;
|
|
|
- console.log(file, 'file');
|
|
|
|
|
|
const type = file.type.includes('image')
|
|
|
? NaturalTypeEnum.IMG
|
|
@@ -203,7 +177,6 @@ export default defineComponent({
|
|
|
|
|
|
setTimeout(() => {
|
|
|
CropperModal.value?.edit(target);
|
|
|
- // console.log(CropperModal.value, 'cropper');
|
|
|
}, 100);
|
|
|
});
|
|
|
return false;
|
|
@@ -248,7 +221,8 @@ export default defineComponent({
|
|
|
reader.addEventListener('load', () => callback(reader.result));
|
|
|
reader.readAsDataURL(img);
|
|
|
};
|
|
|
- const onFinish = async (options: any) => {
|
|
|
+
|
|
|
+ const onFinish = (options: any) => {
|
|
|
const url = ossUploadUrl + state.key;
|
|
|
const type = formatUrlType(url);
|
|
|
let coverImg = '';
|
|
@@ -258,65 +232,95 @@ export default defineComponent({
|
|
|
coverImg = PageEnum.SONG_DEFAULT_COVER;
|
|
|
} else if (type === 'VIDEO') {
|
|
|
// 获取视频封面图
|
|
|
- await getVideoCoverImg();
|
|
|
+ // await getVideoCoverImg();
|
|
|
+ coverImg = 'https://gyt.ks3-cn-beijing.ksyuncs.com/1688997532875.png';
|
|
|
}
|
|
|
+ emit('update:fileList', url);
|
|
|
+ emit('readFileInputEventAsArrayBuffer', tempFiileBuffer.value);
|
|
|
emit('finished', {
|
|
|
- cover: coverImg,
|
|
|
+ coverImg,
|
|
|
content: url
|
|
|
});
|
|
|
- emit('update:fileList', url);
|
|
|
- emit('readFileInputEventAsArrayBuffer', tempFiileBuffer.value);
|
|
|
+
|
|
|
options.file.url = url;
|
|
|
visiable.value = false;
|
|
|
btnLoading.value = false;
|
|
|
};
|
|
|
|
|
|
- const getVideoCoverImg = async () => {
|
|
|
- try {
|
|
|
- btnLoading.value = true;
|
|
|
- const imgBlob: any = await getVideoMsg(tempFiileBuffer.value);
|
|
|
- const fileName = `${props.path}${Date.now() + '.png'}`;
|
|
|
- const obj = {
|
|
|
- filename: fileName,
|
|
|
- bucketName: props.bucketName,
|
|
|
- postData: {
|
|
|
- filename: fileName,
|
|
|
- acl: 'public-read',
|
|
|
- key: fileName,
|
|
|
- unknowValueField: []
|
|
|
- }
|
|
|
- };
|
|
|
- const { data } = await policy(obj);
|
|
|
+ // 获取文件流
|
|
|
+ // const base64ImgtoFile = (dataurl: string, filename = 'file') => {
|
|
|
+ // const arr: any = dataurl.split(',');
|
|
|
+ // const mime = arr[0].match(/:(.*?);/)[1];
|
|
|
+ // const suffix = mime.split('/')[1];
|
|
|
+ // const bstr = atob(arr[1]);
|
|
|
+ // let n = bstr.length;
|
|
|
+ // const u8arr = new Uint8Array(n);
|
|
|
+ // while (n--) {
|
|
|
+ // u8arr[n] = bstr.charCodeAt(n);
|
|
|
+ // }
|
|
|
+ // return new File([u8arr], `${filename}.${suffix}`, {
|
|
|
+ // type: mime
|
|
|
+ // });
|
|
|
+ // };
|
|
|
|
|
|
- const fileParams = {
|
|
|
- policy: data.policy,
|
|
|
- signature: data.signature,
|
|
|
- key: fileName,
|
|
|
- KSSAccessKeyId: data.KSSAccessKeyId,
|
|
|
- name: fileName
|
|
|
- } as any;
|
|
|
- const formData = new FormData();
|
|
|
- for (const key in fileParams) {
|
|
|
- formData.append(key, fileParams[key]);
|
|
|
- }
|
|
|
- formData.append('file', imgBlob);
|
|
|
+ // const getVideoMsg = (file: any) => {
|
|
|
+ // return new Promise(resolve => {
|
|
|
+ // let dataURL = '';
|
|
|
+ // const videoElement = document.createElement('video');
|
|
|
+ // videoElement.currentTime = 1;
|
|
|
+ // videoElement.src = URL.createObjectURL(file);
|
|
|
+ // videoElement.addEventListener('loadeddata', function () {
|
|
|
+ // const canvas: any = document.createElement('canvas'),
|
|
|
+ // width = videoElement.videoWidth, //canvas的尺寸和图片一样
|
|
|
+ // height = videoElement.videoHeight;
|
|
|
+ // canvas.width = width;
|
|
|
+ // canvas.height = height;
|
|
|
+ // canvas.getContext('2d').drawImage(videoElement, 0, 0, width, height); //绘制canvas
|
|
|
+ // dataURL = canvas.toDataURL('image/jpeg'); //转换为base64
|
|
|
+ // resolve(dataURL);
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ // };
|
|
|
|
|
|
- await axios.post(ossUploadUrl, formData);
|
|
|
+ // const getVideoCoverImg = async () => {
|
|
|
+ // try {
|
|
|
+ // btnLoading.value = true;
|
|
|
+ // const imgBlob: any = await getVideoMsg(tempFiileBuffer.value);
|
|
|
+ // const fileName = `${props.path}${Date.now() + '.png'}`;
|
|
|
+ // const obj = {
|
|
|
+ // filename: fileName,
|
|
|
+ // bucketName: props.bucketName,
|
|
|
+ // postData: {
|
|
|
+ // filename: fileName,
|
|
|
+ // acl: 'public-read',
|
|
|
+ // key: fileName,
|
|
|
+ // unknowValueField: []
|
|
|
+ // }
|
|
|
+ // };
|
|
|
+ // const { data } = await policy(obj);
|
|
|
|
|
|
- const url = ossUploadUrl + state.key;
|
|
|
- console.log(url, 'url');
|
|
|
- return url;
|
|
|
- } catch {
|
|
|
- //
|
|
|
- // message.error('上传失败')
|
|
|
- // btnLoading.value = false;
|
|
|
- // return false;
|
|
|
- } finally {
|
|
|
- btnLoading.value = false;
|
|
|
- }
|
|
|
- };
|
|
|
+ // const fileParams = {
|
|
|
+ // policy: data.policy,
|
|
|
+ // signature: data.signature,
|
|
|
+ // key: fileName,
|
|
|
+ // KSSAccessKeyId: data.kssAccessKeyId,
|
|
|
+ // name: fileName
|
|
|
+ // } as any;
|
|
|
+ // const formData = new FormData();
|
|
|
+ // for (const key in fileParams) {
|
|
|
+ // formData.append(key, fileParams[key]);
|
|
|
+ // }
|
|
|
+ // formData.append('file', base64ImgtoFile(imgBlob));
|
|
|
+ // await axios.post(ossUploadUrl, formData);
|
|
|
|
|
|
- const onRemove = async (options: any) => {
|
|
|
+ // const url = ossUploadUrl + fileName;
|
|
|
+ // return url;
|
|
|
+ // } finally {
|
|
|
+ // btnLoading.value = false;
|
|
|
+ // }
|
|
|
+ // };
|
|
|
+
|
|
|
+ const onRemove = async () => {
|
|
|
emit('update:fileList', '');
|
|
|
emit('remove');
|
|
|
btnLoading.value = false;
|
|
@@ -356,7 +360,6 @@ export default defineComponent({
|
|
|
|
|
|
await axios.post(ossUploadUrl, formData).then(() => {
|
|
|
const url = ossUploadUrl + state.key;
|
|
|
- console.log(url, 'url');
|
|
|
const splitName = url.split('/');
|
|
|
fileListRef.value = [
|
|
|
{
|
|
@@ -367,6 +370,10 @@ export default defineComponent({
|
|
|
}
|
|
|
];
|
|
|
emit('update:fileList', url);
|
|
|
+ emit('finished', {
|
|
|
+ coverImg: url,
|
|
|
+ content: url
|
|
|
+ });
|
|
|
visiable.value = false;
|
|
|
});
|
|
|
} catch {
|
|
@@ -389,7 +396,7 @@ export default defineComponent({
|
|
|
showPreviewButton
|
|
|
onBeforeUpload={(options: any) => onBeforeUpload(options)}
|
|
|
onFinish={(options: any) => onFinish(options)}
|
|
|
- onRemove={(options: any) => onRemove(options)}>
|
|
|
+ onRemove={() => onRemove()}>
|
|
|
{props.showType === 'default' && (
|
|
|
<div class={styles.uploadBtn}>
|
|
|
<img src={iconUploadAdd} class={styles.iconUploadAdd} />
|