仅能打开一个python页面限制

master
yujialong 5 months ago
parent 05fd504802
commit d90fcd1df0
  1. 160
      src/api/http.js
  2. 10
      src/components/TestPanel.vue
  3. 4
      src/config/index.js
  4. 98
      src/views/Home.vue

@ -1,112 +1,120 @@
import axios from 'axios'; import axios from 'axios';
import { import {
Message Message
} from 'element-ui' } from 'element-ui'
import router from '../router/index' import router from '../router/index'
import Cookie from 'js-cookie' import Cookie from 'js-cookie'
import config from '@/config' import config from '@/config'
const service = axios.create({ const service = axios.create({
baseURL: config.host, baseURL: config.host,
timeout: 10000000 timeout: 10000000
}) })
// post请求头 // post请求头
service.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; service.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';
// 请求拦截器 // 请求拦截器
service.interceptors.request.use(config => { service.interceptors.request.use(config => {
const token = Cookie.get('admin-token') const token = Cookie.get('admin-token')
if (token) { if (token) {
config.headers.token = token config.headers.token = token
}
return config;
}, err => {
Message.error({
message: '退出登陆',
onClose: function () {
router.push({ name: 'login' });
} }
return config; })
}, err => { return Promise.reject(err);
Message.error({
message: '退出登陆',
onClose: function () {
router.push({name: 'login'});
}
})
return Promise.reject(err);
}) })
let logouted = 0; let logouted = 0;
// 响应拦截器 // 响应拦截器
service.interceptors.response.use( service.interceptors.response.use(
response => { response => {
const res = response.data; const res = response.data;
if (res.status == 200 || res.status == 10000 || res.status == 30001) { if (res.status == 200 || res.status == 10000 || res.status == 30001) {
return Promise.resolve(res).catch(e => {}); return Promise.resolve(res).catch(e => { });
} else if (!res.status) { } else if (res.code === 401) {
return Promise.resolve(res).catch(e => {}); // 账号互踢
} else { if (!logouted) {
Message.error(res.message) Message.error(res.msg.includes('顶') ? '您的账号已在其他设备登录,您已被迫下线!' : '登录过期,请重新登录!')
return Promise.reject(res) setTimeout(() => {
} history.back()
}, }, 1500)
// 服务器状态码不是200的情况 logouted = 1
error => { }
if (error.response.status) { } else if (!res.status) {
switch (error.response.status) { return Promise.resolve(res).catch(e => { });
// 401: 未登录 } else {
case 401: Message.error(res.message)
if (!logouted) { return Promise.reject(res)
Message.error('登录过期,请重新登录') }
setTimeout(() => { },
history.back() // 服务器状态码不是200的情况
}, 1500) error => {
logouted = 1 if (error.response.status) {
} switch (error.response.status) {
break; // 401: 未登录
default: case 401:
// Message.error(error.response.data.message) if (!logouted) {
Promise.reject(error.response); Message.error('登录过期,请重新登录')
} setTimeout(() => {
return Promise.reject(error.response); history.back()
} }, 1500)
logouted = 1
}
break;
default:
Promise.reject(error.response);
}
return Promise.reject(error.response);
} }
}
); );
function get(url, params) { function get (url, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
service.get(url, { params: params }).then(res => { service.get(url, { params: params }).then(res => {
resolve(res); resolve(res);
}).catch(err => { }).catch(err => {
reject(err); reject(err);
});
}); });
});
} }
function post(url, params) { function post (url, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
service.post(url, params).then(res => { service.post(url, params).then(res => {
resolve(res); resolve(res);
}).catch(err => { }).catch(err => {
reject(err.data); reject(err.data);
});
}); });
});
} }
function del(url, params) { function del (url, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
service.delete(url, { service.delete(url, {
params params
}).then(res => { }).then(res => {
resolve(res); resolve(res);
}).catch(err => { }).catch(err => {
reject(err.data); reject(err.data);
});
}); });
});
} }
function put(url, params) { function put (url, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
service.put(url, params).then(res => { service.put(url, params).then(res => {
resolve(res); resolve(res);
}).catch(err => { }).catch(err => {
reject(err.data); reject(err.data);
});
}); });
});
} }
export { get, post, del, put } export { get, post, del, put }

@ -214,8 +214,10 @@ import "codemirror/theme/base16-light.css";
import { mavonEditor } from 'mavon-editor' import { mavonEditor } from 'mavon-editor'
import 'mavon-editor/dist/css/index.css' import 'mavon-editor/dist/css/index.css'
import Stomp from 'stompjs' import Stomp from 'stompjs'
export const MQTT_USERNAME = 'huoran' // , todo: read from database // export const MQTT_USERNAME = 'huoran' // , todo: read from database
export const MQTT_PASSWORD = 'huoran2024' // , todo: read from database // export const MQTT_PASSWORD = 'huoran2024' // , todo: read from database
export const MQTT_USERNAME = 'huorantest' // , todo: read from database
export const MQTT_PASSWORD = 'huorantest2024' // , todo: read from database
export default { export default {
data () { data () {
@ -1090,8 +1092,8 @@ export default {
// //
connect () { connect () {
// let ws = new WebSocket(`ws://124.71.74.9:15674/ws`); let ws = new WebSocket(`ws://139.159.153.48:15674/ws`);
let ws = new WebSocket(`wss://python.occupationlab.com/ws`); // let ws = new WebSocket(`wss://python.occupationlab.com/ws`);
this.client = Stomp.over(ws); this.client = Stomp.over(ws);
this.client.heartbeat.outgoing = 0 this.client.heartbeat.outgoing = 0
this.client.heartbeat.incoming = 0 this.client.heartbeat.incoming = 0

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

@ -5,43 +5,47 @@
<p v-else>{{ curriculumName }}</p> <p v-else>{{ curriculumName }}</p>
<el-button class="back btn" type="primary" @click="back">退出实验</el-button> <el-button class="back btn" type="primary" @click="back">退出实验</el-button>
</div> </div>
<div class="top"> <template v-if="!notAllowed">
<div class="language"> <div class="top">
<p v-if="$config.isHh" style="font-size: 18px">{{ $config.title }}</p> <div class="language">
<p>编程语言</p> <p v-if="$config.isHh" style="font-size: 18px">{{ $config.title }}</p>
<el-select v-model="language" @change="languageChange"> <p>编程语言</p>
<el-option v-for="(item, i) in languages" :key="i" :label="item.name" :value="item.id"></el-option> <el-select v-model="language" @change="languageChange">
</el-select> <el-option v-for="(item, i) in languages" :key="i" :label="item.name" :value="item.id"></el-option>
</el-select>
<el-button v-if="language" class="open-vs" type="primary" size="small"
@click="openVscode">打开Vscode新窗口</el-button> <el-button v-if="language" class="open-vs" type="primary" size="small"
@click="openVscode">打开Vscode新窗口</el-button>
</div>
<div class="inline-center">
<el-tooltip class="item" effect="dark" content="支持导入其它数据用于实验,总上传的文件大小不可以超过10M" placement="bottom">
<i class="info el-icon-warning" style="margin-right: 10px"></i>
</el-tooltip>
<el-button type="primary" size="small" icon="el-icon-document" @click="toData">我的数据</el-button>
</div>
</div> </div>
<div class="inline-center">
<el-tooltip class="item" effect="dark" content="支持导入其它数据用于实验,总上传的文件大小不可以超过10M" placement="bottom">
<i class="info el-icon-warning" style="margin-right: 10px"></i>
</el-tooltip>
<el-button type="primary" size="small" icon="el-icon-document" @click="toData">我的数据</el-button>
</div>
</div>
<div class="tab"> <div class="tab">
<el-tabs v-model="curTab" type="card" @tab-click="judChange"> <el-tabs v-model="curTab" type="card" @tab-click="judChange">
<el-tab-pane v-for="(item, i) in workbench" :key="item.judgmentId" :label="item.name" :value="item.judgmentId"> <el-tab-pane v-for="(item, i) in workbench" :key="item.judgmentId" :label="item.name"
<codemirror v-if="!language" :ref="'code' + i" :key="codeKey" :projectId.sync="projectId" :value="item.judgmentId">
:systemId.sync="systemId" :code.sync="item.code" :finalCode.sync="item.finalCode" <codemirror v-if="!language" :ref="'code' + i" :key="codeKey" :projectId.sync="projectId"
:judgmentId="item.judgmentId" :codeId.sync="item.codeId" :answer.sync="item.answer" :systemId.sync="systemId" :code.sync="item.code" :finalCode.sync="item.finalCode"
:retResult.sync="item.retResult" :photoUrl.sync="item.photoUrl" :index="i" :curTab.sync="curTab" :judgmentId="item.judgmentId" :codeId.sync="item.codeId" :answer.sync="item.answer"
:modelIsShow.sync="modelIsShow"></codemirror> :retResult.sync="item.retResult" :photoUrl.sync="item.photoUrl" :index="i" :curTab.sync="curTab"
<iframe v-else class="vscode" :src="Config.vscodeUrl" frameborder="0" width="100%"></iframe> :modelIsShow.sync="modelIsShow"></codemirror>
</el-tab-pane> <iframe v-else class="vscode" :src="Config.vscodeUrl" frameborder="0" width="100%"></iframe>
</el-tabs> </el-tab-pane>
</div> </el-tabs>
</div>
<div class="menu"> <div class="menu">
<testPanel @tell="setPoints" @recoveryCode="recoveryCode" ref="mainindex" :workbench.sync="workbench"></testPanel> <testPanel @tell="setPoints" @recoveryCode="recoveryCode" ref="mainindex" :workbench.sync="workbench">
</div> </testPanel>
</div>
<div v-if="isSubmit" class="mask"></div> <div v-if="isSubmit" class="mask"></div>
</template>
</div> </div>
</template> </template>
@ -82,7 +86,8 @@ export default {
], ],
curTab: '', // curTab: '', //
workbench: [], // workbench: [], //
codeKey: 1 // codeKey: 1, //
notAllowed: 0,
}; };
}, },
components: { components: {
@ -90,22 +95,32 @@ export default {
testPanel testPanel
}, },
mounted () { mounted () {
const opened = localStorage.getItem('opened') //
if (opened || opened === '0') { const opened = +localStorage.getItem('opened')
localStorage.setItem('opened', +opened + 1) if (opened) {
localStorage.setItem('opened', opened + 1)
this.notAllowed = 1
this.$alert('我们注意到您当前已尝试打开多个实验页面。为保证实验的公平性和诚信,系统仅允许单个实验页面处于活跃状态。', '提示', {
confirmButtonText: '退出当前页面',
showClose: false,
callback: action => {
this.back()
}
})
} else { } else {
localStorage.setItem('opened', 1) localStorage.setItem('opened', 1)
} }
//
window.addEventListener('unload', function () { window.addEventListener('unload', function () {
const opened = localStorage.getItem('opened') const opened = +localStorage.getItem('opened')
if (opened) { if (opened) {
localStorage.setItem('opened', +opened - 1) localStorage.setItem('opened', opened - 1)
} else { } else {
localStorage.removeItem('opened') localStorage.removeItem('opened')
} }
}); })
console.log(11, localStorage.getItem('opened'))
document.onkeydown = function (event) { document.onkeydown = function (event) {
var e = event || window.event || arguments.callee.caller.arguments[0]; var e = event || window.event || arguments.callee.caller.arguments[0];
@ -142,7 +157,6 @@ export default {
}, },
// //
toData () { toData () {
return console.log(11, localStorage.getItem('opened'))
this.$router.push('/data') this.$router.push('/data')
}, },
// 退 // 退

Loading…
Cancel
Save