运行代码更改为消息通知

master
yujialong 8 months ago
parent 771d4930d4
commit e9a49f0a46
  1. 158
      package-lock.json
  2. 1
      package.json
  3. 2
      src/api/index.js
  4. 88
      src/components/TestPanel.vue
  5. 254
      src/components/codemirror.vue
  6. 4
      src/config/index.js
  7. 4
      src/styles/common.scss

158
package-lock.json generated

@ -3177,6 +3177,15 @@
"integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=",
"dev": true
},
"bufferutil": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.8.tgz",
"integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==",
"optional": true,
"requires": {
"node-gyp-build": "^4.3.0"
}
},
"builtin-status-codes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz",
@ -4478,6 +4487,15 @@
"integrity": "sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk=",
"dev": true
},
"d": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz",
"integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==",
"requires": {
"es5-ext": "^0.10.64",
"type": "^2.7.2"
}
},
"dashdash": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
@ -5167,6 +5185,36 @@
"is-symbol": "^1.0.2"
}
},
"es5-ext": {
"version": "0.10.64",
"resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz",
"integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==",
"requires": {
"es6-iterator": "^2.0.3",
"es6-symbol": "^3.1.3",
"esniff": "^2.0.1",
"next-tick": "^1.1.0"
}
},
"es6-iterator": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz",
"integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==",
"requires": {
"d": "1",
"es5-ext": "^0.10.35",
"es6-symbol": "^3.1.1"
}
},
"es6-symbol": {
"version": "3.1.4",
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz",
"integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==",
"requires": {
"d": "^1.0.2",
"ext": "^1.7.0"
}
},
"escalade": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
@ -5193,6 +5241,17 @@
"estraverse": "^4.1.1"
}
},
"esniff": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz",
"integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==",
"requires": {
"d": "^1.0.1",
"es5-ext": "^0.10.62",
"event-emitter": "^0.3.5",
"type": "^2.7.2"
}
},
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
@ -5234,6 +5293,15 @@
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=",
"dev": true
},
"event-emitter": {
"version": "0.3.5",
"resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz",
"integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==",
"requires": {
"d": "1",
"es5-ext": "~0.10.14"
}
},
"event-pubsub": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/event-pubsub/-/event-pubsub-4.3.0.tgz",
@ -5397,6 +5465,14 @@
}
}
},
"ext": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz",
"integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==",
"requires": {
"type": "^2.7.2"
}
},
"extend": {
"version": "3.0.2",
"resolved": "https://registry.npm.taobao.org/extend/download/extend-3.0.2.tgz",
@ -7044,8 +7120,7 @@
"is-typedarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=",
"dev": true
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
},
"is-utf8": {
"version": "0.2.1",
@ -7872,6 +7947,11 @@
"integrity": "sha1-rCetpmFn+ohJpq3dg39rGJrSCBw=",
"dev": true
},
"next-tick": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz",
"integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ=="
},
"nice-try": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
@ -7921,6 +8001,12 @@
}
}
},
"node-gyp-build": {
"version": "4.8.0",
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.0.tgz",
"integrity": "sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og==",
"optional": true
},
"node-ipc": {
"version": "9.2.1",
"resolved": "https://registry.npmjs.org/node-ipc/-/node-ipc-9.2.1.tgz",
@ -11117,6 +11203,14 @@
"readable-stream": "^2.0.1"
}
},
"stompjs": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/stompjs/-/stompjs-2.3.3.tgz",
"integrity": "sha512-5l/Ogz0DTFW7TrpHF0LAETGqM/so8UxNJvYZjJKqcX31EVprSQgnGkO80tZctPC/lFBDUrSFiTG3xd0R27XAIA==",
"requires": {
"websocket": "^1.0.34"
}
},
"stream-browserify": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.2.tgz",
@ -11645,6 +11739,11 @@
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
"dev": true
},
"type": {
"version": "2.7.2",
"resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz",
"integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw=="
},
"type-fest": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz",
@ -11667,6 +11766,15 @@
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=",
"dev": true
},
"typedarray-to-buffer": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
"integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
"optional": true,
"requires": {
"is-typedarray": "^1.0.0"
}
},
"uglify-js": {
"version": "3.4.10",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.10.tgz",
@ -11956,6 +12064,15 @@
"integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==",
"dev": true
},
"utf-8-validate": {
"version": "5.0.10",
"resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz",
"integrity": "sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==",
"optional": true,
"requires": {
"node-gyp-build": "^4.3.0"
}
},
"util": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/util/-/util-0.11.1.tgz",
@ -12798,6 +12915,37 @@
}
}
},
"websocket": {
"version": "1.0.34",
"resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.34.tgz",
"integrity": "sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==",
"optional": true,
"requires": {
"bufferutil": "^4.0.1",
"debug": "^2.2.0",
"es5-ext": "^0.10.50",
"typedarray-to-buffer": "^3.1.5",
"utf-8-validate": "^5.0.2",
"yaeti": "^0.0.6"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"optional": true,
"requires": {
"ms": "2.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"optional": true
}
}
},
"websocket-driver": {
"version": "0.7.4",
"resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.4.tgz",
@ -12971,6 +13119,12 @@
"integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==",
"dev": true
},
"yaeti": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
"integrity": "sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==",
"optional": true
},
"yallist": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",

@ -25,6 +25,7 @@
"postcss-pxtorem": "^5.1.1",
"px2rem-loader": "^0.1.9",
"quill": "^1.3.7",
"stompjs": "^2.3.3",
"tinymce": "^6.8.3",
"vue": "^2.6.14",
"vue-codemirror": "^4.0.6",

@ -44,4 +44,6 @@ export default {
getStartTime: `python/python/getStartTime`,
getProductSystemTheme: `nakadai/mall/getProductSystemTheme`,
heartbeatDetection : `nakadai/message/heartbeatDetection`,
createQueue : `python/rabbitMessage/createQueue`,
endRunningProcess : `python/python/endRunningProcess`,
}

@ -319,6 +319,12 @@ import "codemirror/theme/monokai.css";
import "codemirror/theme/base16-light.css";
import { mavonEditor } from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
import Stomp from 'stompjs'
export const IP = "x.108.x.33" // mqip
export const MQTT_USERNAME = 'huoran' // , todo: read from database
export const MQTT_PASSWORD = 'huoran2024' // , todo: read from database
export const VIRTUAL_HOST = '15674' //
export default {
data () {
return {
@ -396,7 +402,10 @@ export default {
reportVisible: false,
tableHeight: 0,
dragIds: ['panelHeader', 'aside', 'main', 'infoContainer'],
submiting: false
submiting: false,
client: '',
accountId: '',
runCodeType: '',
};
},
components: {
@ -419,6 +428,10 @@ export default {
await this.getEntryTime()
newmain.$on('changeRunStatus', val => {
this.runCodeType = val
})
if (this.assessmentId) { // assessmentIdcompetitionId)
this.getAssList()
} else { //
@ -840,6 +853,14 @@ export default {
}
}
},
vscodeRunCode (data) {
// this.$parent.workbench[i].codeId = data.codeId
// this.$parent.workbench[i].retResult = 1
},
emptyRunCode (data) {
this.$parent.workbench[0].codeId = data.codeId
this.submit()
},
//
confirmSubmit () {
if (this.submiting) return false
@ -869,17 +890,17 @@ export default {
const promises = []
taskList.map(async (e, i) => {
(e.code || e.codeResult) && promises.push(new Promise(async (resolve, reject) => {
const { code, codeId } = await this.$post(this.api.runPythonCode, {
this.runCodeType = 'vscodeRunCode'
await this.$post(this.api.runPythonCode, {
code: e.code,
bcId: e.judgmentId,
cid: this.courseId,
projectId: this.projectId,
userAnswer: e.codeResult || null,
type: 0
type: 0,
sort: i
})
this.$parent.workbench[i].codeId = codeId
this.$parent.workbench[i].answer = e.codeResult
this.$parent.workbench[i].retResult = 1
resolve()
}))
})
@ -889,16 +910,14 @@ export default {
} else {
//
if (!pointList.find(e => e.codeId)) {
this.runCodeType = 'emptyRunCode'
this.$post(this.api.runPythonCode, {
code: '',
bcId: pointList[0].judgmentId,
cid: this.courseId,
projectId: this.projectId,
type: 0
}).then(({ codeId }) => {
this.$parent.workbench[0].codeId = codeId
this.submit()
}).catch(err => {
}).then(res => { }).catch(err => {
this.submiting = false
})
} else {
@ -1198,6 +1217,52 @@ export default {
// socket
this.socket.onmessage = this.getMessage;
},
//
connect () {
let ws = new WebSocket(`ws://124.71.74.9:15674/ws`);
this.client = Stomp.over(ws);
//
const headers = {
login: MQTT_USERNAME,
passcode: MQTT_PASSWORD
};
//
this.client.connect(headers.login, headers.passcode, this.onConnected, this.onFailed, 'pyhost');
},
onConnected: function () {
//
const topic = '/amq/queue/pythonQueue_' + this.accountId;
this.client.subscribe(topic, this.responseCallback, this.onFailed);
},
onFailed: function (frame) {
console.log("MQ Failed: " + frame);
// this.$message.error('')
},
//
responseCallback: function (frame) {
const data = JSON.parse(frame.body)
console.log("接收信息:", data, typeof data);
if (typeof data === 'object') {
newmain.$emit('setPid', '')
if (this.runCodeType) {
this[this.runCodeType](data)
} else {
newmain.$emit('runCode', data)
}
this.runCodeType = ''
} else if (typeof data === 'string') {
newmain.$emit('setPid', data)
}
},
//
close: function () {
this.client.disconnect(function () {
console.log("已退出账号");
})
},
//
heartbeatDetection () {
setInterval(async () => {
@ -1206,7 +1271,10 @@ export default {
},
//
getUserDetail () {
this.$get(this.api.queryUserInfoDetails).then(res => {
this.$get(this.api.queryUserInfoDetails).then(async (res) => {
this.accountId = res.result.userAccount.id
await this.$get(this.api.createQueue)
this.connect();
this.initSocket(res.result.userAccount)
}).catch(res => { })
},

@ -9,20 +9,31 @@
<div v-if="isSubmit"
class="code-mask"></div>
<div class="btns">
<span class="el-icon-delete del"
@click="clearCode"></span>
<el-button v-if="isPrac"
class="btn"
type="danger"
@click="myCode">我的代码</el-button>
<el-button v-if="modelIsShow"
class="btn"
type="warning"
@click="importModel">导入模型</el-button>
<el-button class="run btn"
type="primary"
@click="runCode(false)"
:disabled="runEnable">运行</el-button>
<template v-if="!pid">
<span class="el-icon-delete del"
@click="clearCode"></span>
<el-button v-if="isPrac"
class="btn"
type="danger"
@click="myCode">我的代码</el-button>
<el-button v-if="modelIsShow"
class="btn"
type="warning"
@click="importModel">导入模型</el-button>
<el-button class="run btn"
type="primary"
@click="runCode(false)"
:disabled="runEnable">运行</el-button>
</template>
<el-popconfirm v-else
title="确定终止运行本次代码?"
@confirm="stopRunCode">
<el-button slot="reference"
class="run"
type="danger"
:disabled="runEnable">终止运行</el-button>
</el-popconfirm>
</div>
</div>
<div class="line"></div>
@ -420,6 +431,10 @@ export default {
curRow: {},
curCode: '',
curPhotoUrl: [],
runCodeType: '',
pid: '',
cancelRunTimer: null,
runCodeConfirm: null,
};
},
components: {
@ -445,9 +460,19 @@ export default {
if (!this.assessmentId && !this.competitionId) this.isPrac = true
//
newmain.$on("isSubmit", isSubmit => {
newmain.$on('isSubmit', isSubmit => {
this.isSubmit = isSubmit
})
newmain.$on('runCode', data => {
this.handleRunCode(data)
})
newmain.$on('setPid', pid => {
if (this.runCodeConfirm) this.runCodeConfirm.close()
this.pid = pid
})
newmain.$on('cancelRunTimer', () => {
clearTimeout(this.cancelRunTimer)
})
this.dragSide()
},
@ -556,6 +581,44 @@ export default {
})
}).catch(res => { })
},
handleRunCodeCb (fn) {
newmain.$emit('changeRunStatus', '')
this.runCodeType = fn
clearTimeout(this.cancelRunTimer)
// this.cancelRunTimer = setTimeout(() => {
// this.runCodeConfirm = this.$confirm('5', '', {
// type: 'warning',
// closeOnClickModal: false,
// showClose: false
// }).then(async () => {
// if (this.pid) await this.$post(`${this.api.endRunningProcess}?pid=${this.pid}`)
// if (this.loadIns) this.loadIns.close()
// }).catch(() => { })
// }, 5000)
},
//
async stopRunCode () {
if (this.pid) await this.$post(`${this.api.endRunningProcess}?pid=${this.pid}`)
this.pid = ''
if (this.loadIns) this.loadIns.close()
},
inputRunCode (data) {
const result = data.runResult
if (result.includes('File ')) {
this.runResult = result
this.errLine = this.getErrLine(result)
this.isError = data.retResult
} else if (result.includes('validing:')) {
this.isError = 1
this.confirmInput(result)
} else if (data.retResult) {
this.isError = 1
this.runResult += result
}
this.$emit('update:codeId', data.codeId) // coddeId
this.$emit('update:answer', this.runResult) //
this.$emit('update:retResult', data.retResult) //
},
/**
* python代码里如果有input函数的话是做了单独的处理的原理是先把所有input函数都替换成exit函数再在exit函数里加上特定标识再通过接口传给后端去执行
* 因为exit函数是跟input有类似的效果就是都会产生阻塞所以python引擎一旦遇到exit进程就会被停止然后返回exit函数里面的值而这个值就是上面说的特定标识加上原本这个input函数里的值
@ -583,6 +646,7 @@ export default {
this.requestList.map(n => n('interrupt'))
}, 1000)
this.handleRunCodeCb('inputRunCode')
axios.post(config.host + this.api.runPythonCode, {
code: this.sourceCode,
bcId: this.judgmentId,
@ -596,25 +660,8 @@ export default {
cancelToken: new CANCEL_TOKEN(c => { //
this.requestList.push(c)
})
}).then(response => {
let res = response.data
const data = res.code
const result = data.runResult
if (result.includes('File ')) {
this.runResult = result
this.errLine = this.getErrLine(result)
this.isError = data.retResult
} else if (result.includes('validing:')) {
this.isError = 1
this.confirmInput(result)
} else if (data.retResult) {
this.isError = 1
this.runResult += result
}
}).then(res => {
this.$emit('update:finalCode', this.sourceCode)
this.$emit('update:codeId', res.codeId) // coddeId
this.$emit('update:answer', this.runResult) //
this.$emit('update:retResult', data.retResult) //
}).catch(e => {
if (e && e.message == 'interrupt') {
this.runCode(true)
@ -628,6 +675,72 @@ export default {
getErrLine (result) {
return parseInt(result.substring(result.indexOf('line') + 4, result.length)) || 1
},
handleRunCode (data) {
if (this.runCodeType && this[this.runCodeType]) this[this.runCodeType](data)
},
runCodeCb1 (res) {
const result = data.runResult
if (result.includes('File ')) {
if (isWhile) {
this.runResult += result
} else {
this.runResult = result
}
this.errLine = this.getErrLine(result)
this.isError = data.retResult
} else if (result.includes('validing:')) {
this.isError = 1
this.confirmInput(result)
}
this.$emit('update:codeId', res.codeId) // coddeId
this.$emit('update:answer', this.runResult) //
this.$emit('update:retResult', data.retResult) //
},
runCodeCb2 (data) {
//
if (data) {
const photo = data.photoUrl
const result = data.runResult || ''
this.$emit('cache') //
if (this.loadIns) this.loadIns.close()
this.picSrcList = []
this.$emit('update:photoUrl', '')
if (photo) {
this.picSrcList = photo.split(',')
this.$emit('update:photoUrl', photo)
}
this.$emit('update:codeId', data.codeId) // coddeId
this.$emit('update:answer', result) //
this.$emit('update:retResult', data.retResult) //
let imgList = ''
let firtImg = ''
try {
imgList = eval(result)
} catch (error) { }
if (imgList && imgList.length) firtImg = imgList[0]
//
if (photo) {
this.isError = data.retResult //
const text = result.replace(photo, '') //
this.runResult = text
this.picSrcList = photo.split(',')
this.errLine = this.getErrLine(result)
} else if (imgList instanceof Array && imgList.length && typeof firtImg === 'string' && (firtImg.includes('.jpg') || firtImg.includes('.png') || firtImg.includes('img'))) {
/**
* 这段是为要下载图片的项目案例写的后端会返回图片名称的数组前端负责循环这个数组然后下载下来
*/
imgList.map((n, i) => {
util.downloadFile(`${i + 1}.jpg`, n)
})
this.isError = 0
this.runResult = '下载完成'
} else {
this.isError = data.retResult
this.runResult = result
this.errLine = this.getErrLine(result)
}
}
},
//
runCode (isWhile) { // isWhiletruewhile
if (!this.isSubmit) {
@ -657,6 +770,7 @@ export default {
this.sourceCode = code
if (!isWhile) this.runResult = ''
this.handleRunCodeCb('runCodeCb1')
this.$post(this.api.runPythonCode, {
code,
bcId,
@ -664,37 +778,23 @@ export default {
projectId,
type: 0
}).then(res => {
const data = res.code
const result = data.runResult
if (result.includes('File ')) {
if (isWhile) {
this.runResult += result
} else {
this.runResult = result
}
this.errLine = this.getErrLine(result)
this.isError = data.retResult
} else if (result.includes('validing:')) {
this.isError = 1
this.confirmInput(result)
}
this.$emit('update:finalCode', code)
this.$emit('update:codeId', res.codeId) // coddeId
this.$emit('update:answer', this.runResult) //
this.$emit('update:retResult', data.retResult) //
}).catch(err => {
this.loadIns.close()
})
} else {
this.loadIns = Loading.service({
text: '代码运行中请稍等几分钟',
background: 'transparent'
text: '代码运行中,请稍候',
background: 'transparent',
customClass: 'code-load',
})
// savefig(python),savefig
code = code.replace(/\.savefig\(([\u4e00-\u9fa5\w]*?['"])/mg, str => {
return str + Date.now()
})
// Python
this.handleRunCodeCb('runCodeCb2')
this.$post(this.api.runPythonCode, {
code,
bcId,
@ -702,55 +802,7 @@ export default {
projectId,
type: 0
}).then(res => {
//
if (res.code) {
const data = res.code
const photo = data.photoUrl
const result = data.runResult || ''
this.$emit('cache') //
this.loadIns.close()
this.picSrcList = []
this.$emit('update:photoUrl', '')
if (photo) {
this.picSrcList = photo.split(',')
this.$emit('update:photoUrl', photo)
}
this.$emit('update:finalCode', code)
this.$emit('update:codeId', res.codeId) // coddeId
this.$emit('update:answer', result) //
this.$emit('update:retResult', data.retResult) //
let imgList = ''
let firtImg = ''
try {
imgList = eval(result)
} catch (error) { }
if (imgList && imgList.length) firtImg = imgList[0]
//
if (photo) {
this.isError = data.retResult //
const text = result.replace(photo, '') //
this.runResult = text
this.picSrcList = photo.split(',')
this.errLine = this.getErrLine(result)
} else if (imgList instanceof Array && imgList.length && typeof firtImg === 'string' && (firtImg.includes('.jpg') || firtImg.includes('.png') || firtImg.includes('img'))) {
/**
* 这段是为要下载图片的项目案例写的后端会返回图片名称的数组前端负责循环这个数组然后下载下来
*/
imgList.map((n, i) => {
util.downloadFile(`${i + 1}.jpg`, n)
})
this.isError = 0
this.runResult = '下载完成'
} else {
this.isError = data.retResult
this.runResult = result
this.errLine = this.getErrLine(result)
}
} else if (res.data && res.data.current) {
//
this.$message.success(`当前队列有${res.data.current - 1}人在排队,请稍等!`)
this.loadIns.close()
}
this.$emit('update:finalCode', code)
}).catch(res => {
this.isError = false
this.runResult = ''

@ -13,9 +13,9 @@ let host = location.origin + '/'
let bankPath = `${location.origin}/banksystem` // 银行系统
// 121.37.12.51 | 192.168.31.151
if (isDev) {
// host = 'http://192.168.31.217:9000/'
host = 'http://192.168.31.51:9000/'
// host = 'http://121.37.12.51:9000/'
host = 'https://occupationlab.com/'
// host = 'https://occupationlab.com/'
bankPath = `http://${location.hostname}:8093`
} else if (isPro) {
host = 'https://occupationlab.com/'

@ -99,3 +99,7 @@ body .cus-table.el-table {
text-align: left;
line-height: 30px;
}
.code-load {
bottom: 50px !important;
}

Loading…
Cancel
Save