Compare commits

..

7 Commits

1 changed files with 57 additions and 3 deletions

View File

@ -114,7 +114,7 @@
/>
</Modal>
<!--插入试题-->
<el-dialog v-model="classWorkTaskVisible" append-to-body :show-close="false" width="70%">
<QuestToPPTist
class="class-work-task-modal"
@ -208,9 +208,63 @@ const insertImageElement = (files: FileList) => {
// })
}
//
const getTime=()=>{
const now = new Date();
const year = now.getFullYear();
const month = ('0' + (now.getMonth() + 1)).slice(-2);
const day = ('0' + now.getDate()).slice(-2);
const hours = ('0' + now.getHours()).slice(-2);
const minutes = ('0' + now.getMinutes()).slice(-2);
const seconds = ('0' + now.getSeconds()).slice(-2);
return `${year}-${month}-${day}_${hours}:${minutes}:${seconds}`;
};
/**
* base64转图片File
* @param {String} base64 图片base64
* @param {String} fileName 图片名称| 默认 myimg
* @returns File 返回转换后的file数据类型
*/
const base64ToFile = (base64: string, fileName = '试题图片') => {
// base64 ,
let data = base64.split(','),
// image/pngimage/jpegimage/webp
type = data[0].match(/:(.*?);/)[1],
// pngjpegwebp
suffix = type.split('/')[1],
// 使atob()base64
bstr = window.atob(data[1]),
//
n = bstr.length,
//
// 0
u8arr = new Uint8Array(n)
// UTF-16
while (n--) {
// charCodeAt() UTF-16
u8arr[n] = bstr.charCodeAt(n)
}
const filename = fileName+getTime()
// File
// new File(bits, name, options)
const file = new File([u8arr], `${filename}.${suffix}`, {
type: type
})
// file
return file
}
const onhtml2canvas = async (html: HTMLElement) => {
const ele = await toPng(html);
createImageElement(ele);
const base64Dta = await toPng(html);
const toFile = base64ToFile(base64Dta)
// 线
PPTApi.toRousrceUrl(toFile).then(data=>{
createImageElement(data)
})
// createImageElement(ele);
}
const shapePoolVisible = ref(false)