|
|
@@ -309,6 +309,45 @@
|
|
|
import MarkdownIt from "markdown-it";
|
|
|
import katex from 'katex'
|
|
|
import 'katex/dist/katex.min.css'
|
|
|
+const getFile = url => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ var credentials = {
|
|
|
+ accessKeyId: "AKIATLPEDU37QV5CHLMH",
|
|
|
+ secretAccessKey: "Q2SQw37HfolS7yeaR1Ndpy9Jl4E2YZKUuuy2muZR"
|
|
|
+ }; //秘钥形式的登录上传
|
|
|
+ window.AWS.config.update(credentials);
|
|
|
+ window.AWS.config.region = "cn-northwest-1"; //设置区域
|
|
|
+ let url2 = url;
|
|
|
+ let _url2 = "";
|
|
|
+ if (
|
|
|
+ url2.indexOf("https://view.officeapps.live.com/op/view.aspx?src=") != -1
|
|
|
+ ) {
|
|
|
+ _url2 = url2.split(
|
|
|
+ "https://view.officeapps.live.com/op/view.aspx?src="
|
|
|
+ )[1];
|
|
|
+ } else {
|
|
|
+ _url2 = url2;
|
|
|
+ }
|
|
|
+ var s3 = new window.AWS.S3({ params: { Bucket: "ccrb" } });
|
|
|
+ let name = decodeURIComponent(
|
|
|
+ _url2.split("https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/")[1]
|
|
|
+ );
|
|
|
+ var params = {
|
|
|
+ Bucket: "ccrb",
|
|
|
+ Key: name
|
|
|
+ };
|
|
|
+ s3.getObject(params, function(err, data) {
|
|
|
+ if (err) {
|
|
|
+ console.log(err, err.stack);
|
|
|
+ resolve({ data: 1 });
|
|
|
+ } else {
|
|
|
+ const fileContent = data.Body.toString("utf-8");
|
|
|
+ resolve({ data: fileContent });
|
|
|
+ } // sxuccessful response
|
|
|
+ });
|
|
|
+ // axios({
|
|
|
+ });
|
|
|
+};
|
|
|
export default {
|
|
|
components: {},
|
|
|
data() {
|
|
|
@@ -380,13 +419,30 @@ export default {
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
- open({ work, testData, testJson, tool }) {
|
|
|
+ async open({ work, testData, testJson, tool }) {
|
|
|
+
|
|
|
+ console.log('work',work);
|
|
|
+ if (this.isValidURL(work.works)) {
|
|
|
+ await getFile(work.works).then((res) => {
|
|
|
+ work.works = res.data;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
this.studentWork = work;
|
|
|
(this.testData = testData),
|
|
|
(this.testJson = testJson),
|
|
|
(this.tool = tool);
|
|
|
this.show = true;
|
|
|
},
|
|
|
+ isValidURL(str){
|
|
|
+ try {
|
|
|
+ const url = new URL(str);
|
|
|
+ return ['http:', 'https:', 'ftp:'].includes(url.protocol) && !!url.hostname;
|
|
|
+ } catch (e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ },
|
|
|
close() {
|
|
|
this.show = false;
|
|
|
(this.studentWork = null),
|