diff --git a/src/components/codemirror.vue b/src/components/codemirror.vue index 7ff6c38..5d2f734 100644 --- a/src/components/codemirror.vue +++ b/src/components/codemirror.vue @@ -21,8 +21,8 @@ >运行
- -

{{modifys}}

+

+
@@ -95,6 +95,8 @@ import "codemirror/theme/monokai.css"; import "codemirror/theme/base16-light.css"; import * as $ from "jquery"; import { Loading } from 'element-ui'; +import axios from 'axios'; +const CANCEL_TOKEN = axios.CancelToken export default { props: ["workbench1", "code", "codeid", "projectId"], data() { @@ -147,7 +149,13 @@ export default { showCursorWhenSelecting: true, theme: "monokai", // 主题 extraKeys: { Ctrl: "autocomplete" } // 可以用于为编辑器指定额外的键绑定,以及keyMap定义的键绑定 - } + }, + inputTextReg: /^((?!#).*?(,|\(|\[|\{|\s)+)?input(?!\w)\(['|"]([\s\S]+?)['|"]\)/m, + inputReg: /^((?!#).*?(,|\(|\[|\{|\s)+)?(input(?!\w)\(['|"][\s\S]*?['|"]\))/m, + exitTextReg: /exit(?!\w)\(['|"]([\s\S]+?)['|"]\)/m, + exitNotValidReg: /exit(?!\w)\(['|"]([\s\S]+?)['|"]\)/m, + requestList: [], + sourceCode: '' }; }, components: { @@ -245,19 +253,55 @@ export default { } x.send() }, - AnswerTips() { - // this.$post(this.api.AddCode, { - // // headers: {code: "#-*-coding:utf-8-*-↵发动机开始"}, - // code: "#-*-coding:utf-8-*-↵发动机开始", - // codeId: this.codeId, - // submit: this.submit //是否点击运行(0未运行,1已运行) - // }) - // .then(res => { - - // }) - // .catch(err => {}); + confirmInput(msg){ + let receiveResult = msg.replace('validing:','') + // console.log('进入函数:',receiveResult) + this.modifys += receiveResult + this.$prompt(receiveResult, "提示", { + confirmButtonText: "确定" + }).then(({ value }) => { + this.modifys += `${value}
` + console.log('替换前:',this.sourceCode,`exit('validing:${receiveResult.replace(/[\r\n]*/g,'')}')`) + this.sourceCode = this.sourceCode.replace(`exit('validing:${receiveResult.replace(/[\r\n]*/g,'')}')`,val => { + return `'${value}'` + }) + this.sourceCode = this.sourceCode.replace(`exit("validing:${receiveResult.replace(/[\r\n]*/g,'')}")`,val => { + return `'${value}'` + }) + console.log('替换后:',this.sourceCode) - // return false + this.$post(this.api.UpdateCode,{ + code: this.sourceCode, + codeId: this.codeId, + submit: this.submit //是否点击运行(0未运行,1已运行) + }).then(res => { + let result = res.message.result + if(result.includes('File ')){ + let modify = res.message.result + this.modifys = modify + this.after = modify.substring( + modify.indexOf("line") + 4, + modify.length + ); + this.num = parseInt(this.after) + this.isError = res.message.isError + }else if(result.includes('validing:')){ + this.isError = 0 + this.confirmInput(result) + }else if(!res.message.isError){ + this.isError = 0 + this.modifys += result + } + + // if(!res.message.isError){ + // this.modifys += res.message.result + // }else if(res.message.result.includes('validing:')){ + // this.confirmInput(res.message.result) + // } + }).catch(err => {}) + }).catch(err => {}) + }, + AnswerTips() { if (this.isSubmit == "") { this.submit = 1; if (this.codeid == "") { @@ -266,73 +310,41 @@ export default { type: "warning" }); } else { - if(this.projectId == 1110 && this.exampleData.includes('您好!请问您需要什么帮助呢?1 存取款;2 货币兑换;3 咨询')){ - this.isError = 0 - let msg = `您好!请问您需要什么帮助呢?1 存取款;2 货币兑换;3 咨询` - this.modifys = msg - this.$prompt(msg, "提示", { - confirmButtonText: "确定" - }).then(({ value }) => { - if(value == 1){ - msg = `建议您去线下银行办理` - this.modifys += `
${msg}` - // this.$message.success(msg) - }else if(value == 2){ - msg = `目前可选择兑换的货币为澳币,是否继续?是or否` - this.modifys += `
${msg}` - this.$prompt(msg, "提示", { - confirmButtonText: "确定" - }).then(({ value }) => { - if(value == '是'){ - msg = `澳币和人民币的兑换率为1:4.7,即一澳币=4.7元人民币。请问您需要兑换多少澳币呢?` - this.modifys += `
${msg}` - this.$prompt(msg, "提示", { - confirmButtonText: "确定" - }).then(({ value }) => { - if(isNaN(value)){ - msg = `请输入数字` - this.modifys += `
${msg}` - // this.$message.error(msg) - }else{ - let rmb = (Number(value) * 4.72).toFixed(2) - msg = `好的,确认兑换澳币${value}。依据当前汇率,一共需要${rmb}元人民币。` - this.modifys += `
${msg}` - // this.$message.success(msg) - } - }).catch(err => {}) - }else if(value == '否'){ - msg = `好的,感谢您使用本次服务。` - this.modifys += `
${msg}` - // this.$message.success(msg) - } - }).catch(err => {}) - }else if(value == 3){ - msg = `您的问题请咨询在线人工客服` - this.modifys += `
${msg}` - // this.$message.success(msg) + let inputTextReg = this.inputTextReg + let inputFuncReg = /input\(['|"]/g + if (inputTextReg.test(this.exampleData)) { + let sourceCode = this.exampleData + sourceCode = sourceCode.replace(inputTextReg,val => { + return val.replace(/[\r\n]/g,'') + }) + // return console.log(11,sourceCode) + + sourceCode = sourceCode.replace(inputFuncReg,val => { + return `exit(${val[val.length - 1]}validing:` + }) + this.sourceCode = sourceCode + + this.modifys = '' + this.$post(this.api.UpdateCode, { + code: sourceCode, + codeId: this.codeId, + submit: this.submit + }).then(res => { + let result = res.message.result + if(result.includes('File ')){ + let modify = res.message.result + this.modifys = modify + this.after = modify.substring( + modify.indexOf("line") + 4, + modify.length + ); + this.num = parseInt(this.after) + this.isError = res.message.isError + }else if(result.includes('validing:')){ + this.isError = 0 + this.confirmInput(result) } }).catch(err => {}) - return false - } - // if (/^((?!#).*?(,|\(|\[|\{|\s)+)?input(?!\w)(,|\(|\)|\[|\]|\{|\}|\s)?/m.test(this.exampleData)) { - if (false) { - this.isError = 0 - this.$prompt("请输入...", "提示", { - confirmButtonText: "确定" - }).then(({ value }) => { - this.datas = []; - this.datas.push(value); - this.$post(this.api.ChangeCode, { - datas: this.datas, - code: this.exampleData - }) - .then(res => { - this.exampleData = res.message; - }) - .catch(err => { - console.log(err); - }); - }); } else { this.loadIns = Loading.service({ background: 'transparent' @@ -545,6 +557,7 @@ export default { font-size: 18px; margin: 10px; position: absolute; + width: calc(100% - 14px); height: calc(100vh - 230px); overflow: auto; } diff --git a/src/config/index.js b/src/config/index.js index a052fde..6ab1cde 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -1,8 +1,13 @@ +const isHh = location.host.includes('10.196.131.73') //是否是河海版本 export default { + /** + * @description 域名切换,liuwan:职站测试环境,occupationlab.com:职站正式环境,10.196.131.73:河海版本 + */ + host: (process.env.NODE_ENV === 'development' || location.host.includes('liuwanr.cn')) ? 'http://www.liuwanr.cn/' : (location.host.includes('10.196.131.73') ? 'http://10.196.131.73/' : 'http://www.occupationlab.com/'), /** * @description 配置显示在浏览器标签的title */ - title: 'Python程序设计教学系统', + title: isHh ? '智信云Python程序设计教学系统' : 'Python程序设计教学系统', /** * @description 是否使用国际化,默认为false * 如果不使用,则需要在路由中给需要在菜单中展示的路由设置meta: {title: 'xxx'} diff --git a/src/utils/api.js b/src/utils/api.js index c113cad..d3a35c6 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -1,11 +1,7 @@ +import config from '@/config' // let host = 'http://192.168.31.125:8081/python'//林 // let host = 'http://192.168.31.152:8081/python'//榕 -let host = '' -if(location.host.includes('liuwanr.cn') || process.env.NODE_ENV === 'development'){ - host = 'http://www.liuwanr.cn/python' -}else{ - host = 'http://www.occupationlab.com/python' -} +let host = `${config.host}python` export default { QueryProject: `${host}/python/queryProject`, //项目选择下拉框+项目信息+判分点信息展示 diff --git a/src/utils/http.js b/src/utils/http.js index 369ba98..3dc44a1 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -172,7 +172,7 @@ export function get(url, params) { */ export function post(url, params) { return new Promise((resolve, reject) => { - axios.post(url, params,{headers: {code: "fsfsdff"}}) + axios.post(url, params) .then(res => { if (res.data.status) { switch (res.data.status) { diff --git a/src/views/Home.vue b/src/views/Home.vue index 8487bd6..9c8c090 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -111,7 +111,7 @@ export default { ? parseInt(sessionStorage.getItem("timer")) : 0, codeKey: 1, - host: location.host.includes('liuwanr.cn') ? 'http://www.liuwanr.cn/' : 'http://www.occupationlab.com/' + host: this.$config.host }; }, components: { @@ -187,17 +187,9 @@ export default { back() { this.leavePage() if(this.projectPermissions){ - if(location.host.includes('liuwanr.cn')){ - location.href = `http://www.liuwanr.cn/#/dashboard#2` - }else{ - location.href = `http://www.occupationlab.com/#/dashboard#2` - } + location.href = `${this.host}#/dashboard#2` }else{ - if(location.host.includes('liuwanr.cn')){ - location.href = `http://www.liuwanr.cn/#/dashboard#1` - }else{ - location.href = `http://www.occupationlab.com/#/dashboard#1` - } + location.href = `${this.host}#/dashboard#1` } this.$refs.mainindex.getClearTime(); },