|
@@ -0,0 +1,94 @@
|
|
|
+function jietu_shishi(uid, cid, stage, task, tool) {
|
|
|
+ html2canvas($("body")[0]).then(function (canvas) {
|
|
|
+ //获取截取图片路径
|
|
|
+
|
|
|
+ var base64Url = canvas.toDataURL('image/png');
|
|
|
+ //后台操作处理
|
|
|
+
|
|
|
+ var base64 = "<img src=" + base64Url + " />"
|
|
|
+ var file = dataURLtoFile_shishi(base64Url, "截图")
|
|
|
+ beforeUpload_shishi(file, uid, cid, stage, task, tool)
|
|
|
+ // $("body")[0].innerHTML = base64
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function dataURLtoFile_shishi(dataurl, filename) {
|
|
|
+ let arr = dataurl.split(","),
|
|
|
+ mime = arr[0].match(/:(.*?);/)[1],
|
|
|
+ bstr = atob(arr[1]),
|
|
|
+ n = bstr.length,
|
|
|
+ u8arr = new Uint8Array(n);
|
|
|
+ while (n--) {
|
|
|
+ u8arr[n] = bstr.charCodeAt(n);
|
|
|
+ }
|
|
|
+ return new File([u8arr], filename, {
|
|
|
+ type: mime
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function beforeUpload_shishi(nfile, uid, cid, stage, task, tool) {
|
|
|
+ var file = nfile;
|
|
|
+ var credentials = {
|
|
|
+ accessKeyId: "AKIATLPEDU37QV5CHLMH",
|
|
|
+ secretAccessKey: "Q2SQw37HfolS7yeaR1Ndpy9Jl4E2YZKUuuy2muZR",
|
|
|
+ }; //秘钥形式的登录上传
|
|
|
+ window.AWS.config.update(credentials);
|
|
|
+ window.AWS.config.region = "cn-northwest-1"; //设置区域
|
|
|
+
|
|
|
+ var bucket = new window.AWS.S3({
|
|
|
+ params: {
|
|
|
+ Bucket: "ccrb"
|
|
|
+ }
|
|
|
+ }); //选择桶
|
|
|
+
|
|
|
+ if (file) {
|
|
|
+ var params = {
|
|
|
+ Key: file.name.split(".")[0] + new Date().getTime() + "." + "png",
|
|
|
+ ContentType: file.type,
|
|
|
+ Body: file,
|
|
|
+ "Access-Control-Allow-Credentials": "*",
|
|
|
+ ACL: "public-read",
|
|
|
+ }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
|
|
|
+ var options = {
|
|
|
+ partSize: 2048 * 1024 * 1024,
|
|
|
+ queueSize: 2,
|
|
|
+ leavePartsOnError: true,
|
|
|
+ };
|
|
|
+ bucket.upload(params, options)
|
|
|
+ .on("httpUploadProgress", function (evt) {
|
|
|
+ //这里可以写进度条
|
|
|
+ // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
|
|
|
+ }).send(function (err, data) {
|
|
|
+ console.log(data.Location);
|
|
|
+ var a = {
|
|
|
+ name: file.name,
|
|
|
+ url: data.Location,
|
|
|
+ uid: file.uid,
|
|
|
+ }
|
|
|
+ addSWork_shishi(uid, cid, stage, task, tool, a)
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function addSWork_shishi(uid, cid, stage, task, tool, a) {
|
|
|
+ let params = {
|
|
|
+ uid: uid,
|
|
|
+ cid: cid,
|
|
|
+ stage:stage,
|
|
|
+ task:task,
|
|
|
+ tool:tool,
|
|
|
+ content: a,
|
|
|
+ type: 1,
|
|
|
+ // upload: JSON.stringify(this.imgFileUp),
|
|
|
+ };
|
|
|
+ $.ajax({
|
|
|
+ type: 'GET',
|
|
|
+ url: 'https://pbl.cocorobo.cn/api/pbl/addCourseWorks',
|
|
|
+ data: params,
|
|
|
+ dataType: "json",
|
|
|
+ success: (data) => {
|
|
|
+ console.log("截图上传成功");
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|