Преглед изворни кода

Leone设置新门户、修改vue.config.js

Leonezhurui пре 5 година
родитељ
комит
ce51269c98

+ 1 - 1
package.json

@@ -14,7 +14,7 @@
     "marked": "^3.0.2",
     "node-sass": "^4.14.1",
     "typescript": "^4.3.5",
-    "vue": "^3.0.0",
+    "vue": "^3.2.0",
     "vue-router": "^4.0.0-0",
     "vuex": "^4.0.0-0"
   },

+ 18 - 9
src/api/axios.config.js

@@ -1,6 +1,13 @@
 import axios, { AxiosError, AxiosResponse } from 'axios'
 import store from '@/store/index'
 
+// const axios = axios.create({
+//     baseURL:"http://localhost:8080",
+// })
+// const axios_prod = axios.create({
+//     baseURL: "https://bok.seec.seecoder.cn",
+// })
+
 export default function axiosConfig() {
     axios.defaults.withCredentials = true
 
@@ -24,7 +31,7 @@ export default function axiosConfig() {
         },
         function(error) {
             if (process.env.NODE_ENV === 'development') {
-                console.error('[AXIOS] response error: ', error.response)
+                console.error('[AXIOS] response error: ', error)
             }
 
             if (error.response) {
@@ -63,18 +70,18 @@ export default function axiosConfig() {
 
 axiosConfig()
 
-// const portal = 'http://p.seec.seecoder.cn'
-const portal = 'http://p.seecoder.cn' //如果新门户出问题就是用老门户,注意修改后端密钥
+const portal = 'http://p.seec.seecoder.cn'
+// const portal = 'http://p.seecoder.cn' //如果新门户出问题就是用老门户,注意修改后端密钥
 
 export const getLoginUrl = () => {
     const location = window.location
-    // return `${portal}/interaction?client_id=seec-mooc&redirect_uri=${encodeURIComponent(
-    //     location.origin + '/'
-    // )}&scope=openid`
-
-    return `${portal}/api/interaction?client_id=seec-mooc&redirect_uri=${encodeURIComponent(
+    return `${portal}/interaction?client_id=seec-mooc&redirect_uri=${encodeURIComponent(
         location.origin + '/'
-    )}&scope=openid` //如果新门户出问题就是用老门户
+    )}&scope=openid`
+
+    // return `${portal}/api/interaction?client_id=seec-mooc&redirect_uri=${encodeURIComponent(
+    //     location.origin + '/'
+    // )}&scope=openid` //如果新门户出问题就是用老门户
 }
 
 /**
@@ -83,3 +90,5 @@ export const getLoginUrl = () => {
 export const jumpToLogin = () => {
     window.location.href = getLoginUrl()
 }
+
+// export {axios, axios_prod}

+ 6 - 1
src/api/index.js

@@ -6,6 +6,7 @@ import {
     getStateQuestion,
     updateQuestion,
     requestQuestion,
+    createBokQuestion
 } from "./question";
 
 import {getUserById,
@@ -16,9 +17,9 @@ import {createRecord,
     getRecordByQid,
 } from "./operation_record";
 
-
 const api = {
     createQuestion: createQuestion,
+    createBokQuestion: createBokQuestion,
     deleteQuestionById: deleteQuestionById,
     getTargetQuestionList: getTargetQuestionList,
     getStateQuestion: getStateQuestion,
@@ -31,4 +32,8 @@ const api = {
     getRecordByQid: getRecordByQid,
 }
 
+export function useApi(){
+    return api;
+}
+
 export {api}

+ 2 - 2
src/api/operation_record.js

@@ -6,12 +6,12 @@ import axios from "axios";
  * @returns {Promise<AxiosResponse<any>>}
  */
 export function createRecord(ope_record) {
-    return axios.post("/api/api/ope_record", ope_record);
+    return axios.post("/one/api/ope_record", ope_record);
 }
 
 
 export function getRecordByQid(qid) {
-    return axios.get("/api/api/ope_record/"+qid,{
+    return axios.get("/one/api/ope_record/"+qid,{
         params:{
             offset: 0,
             pageSize: 1000,

+ 19 - 6
src/api/question.js

@@ -1,4 +1,6 @@
 import axios from 'axios'
+// import {axios_dev,axios_prod} from "@/api/axios.config";
+
 
 /**
  * 用于测试$api是否可以使用
@@ -17,7 +19,7 @@ export function testFunc(name) {
  * @returns {Promise<AxiosResponse<any>>}
  */
 export function getTargetQuestionList(offset, pageSize) {
-    return axios.get("/api/api/pageQuestion", {
+    return axios.get("/one/api/pageQuestion", {
         params:{
             offset: offset,
             pageSize: pageSize
@@ -31,7 +33,7 @@ export function getTargetQuestionList(offset, pageSize) {
  * @returns {Promise<AxiosResponse<any>>}
  */
 export function requestQuestion(stem, ...items) {
-    return axios.get("/api/api/searchQuestion", {
+    return axios.get("/one/api/searchQuestion", {
         params: {
             stem: stem,
             tags: items[0],
@@ -50,7 +52,7 @@ export function requestQuestion(stem, ...items) {
  * @returns {Promise<AxiosResponse<any>>}
  */
 export function deleteQuestionById(id) {
-    return axios.delete("/api/api/question/"+id);
+    return axios.delete("/one/api/question/"+id);
 }
 
 
@@ -60,7 +62,7 @@ export function deleteQuestionById(id) {
  * @returns {Promise<AxiosResponse<any>>}
  */
 export function createQuestion(questionvo) {
-    return axios.post("/api/api/question", questionvo);
+    return axios.post("/one/api/question", questionvo);
 }
 
 
@@ -70,7 +72,7 @@ export function createQuestion(questionvo) {
  * @returns {Promise<AxiosResponse<any>>}
  */
 export function updateQuestion(questionvo) {
-    return axios.put("/api/api/question/"+questionvo.id, questionvo);
+    return axios.put("/one/api/question/"+questionvo.id, questionvo);
 }
 
 
@@ -80,7 +82,7 @@ export function updateQuestion(questionvo) {
  * @returns {Promise<AxiosResponse<any>>}
  */
 export function getStateQuestion(states, offset, pageSize) {
-    return axios.get("/api/api/state", {
+    return axios.get("/one/api/state", {
         params:{
             state: states,
             offset: offset,
@@ -88,4 +90,15 @@ export function getStateQuestion(states, offset, pageSize) {
         }});
 }
 
+/**
+ * 上传题目列表到线上Bok
+ * @param questions
+ * @returns {Promise<AxiosResponse<any>>}
+ */
+export function createBokQuestion(questions){
+    return axios.post("/two/api/questions", questions);
+}
+
+
+
 

+ 3 - 2
src/api/user.js

@@ -1,4 +1,5 @@
 import axios from "axios";
+// import {axios} from "@/api/axios.config";
 
 /**
  * 根据用户ID获得用户对象
@@ -6,13 +7,13 @@ import axios from "axios";
  * @returns {Promise<AxiosResponse<any>>}
  */
 export function getUserById(id) {
-    return axios.get("api/api/user/uid", {params:{
+    return axios.get("/one/user/uid", {params:{
             uid: id
         }});
 }
 
 
 export function getUserInfo(){
-    return axios.get("api/api/user");
+    return axios.get("/one/user");
 }
 

+ 5 - 1
src/components/QuestionGroupCreater.vue

@@ -49,6 +49,10 @@
             submitQuestions(){
                 console.log(JSON.parse(this.questionJson));
                 let questions = JSON.parse(this.questionJson).questions;
+              for (let question of questions) {
+                question.state = "CHECKING";
+                question.savedUserId = this.$store.state.user.id;
+              }
                 axios.post("/api/api/questions", questions)
                     .then(res => {
                         console.log(res);
@@ -72,7 +76,7 @@
                 reader.readAsText(file.raw);
                 reader.onload = () => {
                     this.questionJson = reader.result;
-                    console.log(this.questionJson);
+                    // console.log(this.questionJson);
                 }
 
             }

+ 5 - 0
src/router/index.js

@@ -44,6 +44,11 @@ const routes = [
         name: "Check",
         component: () => import("../views/Bok/Main/Check"),
       },
+      {
+        path: "operation",
+        name: "Operation",
+        component: () => import("../views/Bok/Main/Operation"),
+      },
       {
         path: "setting",
         name: "Setting",

+ 90 - 0
src/views/Bok/Main/Operation.vue

@@ -0,0 +1,90 @@
+<template>
+  <h1>This is Operation Page!</h1>
+  <el-tabs v-model="data.activeName" @tab-click="handleClick">
+    <el-tab-pane label="新建题目" name="create">
+      <div>新建题目</div>
+    </el-tab-pane>
+    <el-tab-pane label="批量新建题目" name="groupCreate">
+      <div>
+        <div class="creator-mode-body">
+          <el-upload
+              class="upload-demo"
+              :auto-upload="false"
+              :on-change="openFile"
+              drag
+              action=""
+              multiple>
+            <i class="el-icon-upload"></i>
+            <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
+            <template #tip>
+              <div class="el-upload__tip">
+                上传 json 文件,且不超过 500kb
+              </div>
+            </template>
+          </el-upload>
+        </div>
+
+        <div class="question-drawer__footer">
+<!--          <el-button @click="cancelForm">取 消</el-button>-->
+          <el-button type="primary" @click="submitQuestions">确 定</el-button>
+        </div>
+      </div>
+    </el-tab-pane>
+  </el-tabs>
+</template>
+
+<script setup>
+import {reactive} from "vue";
+import {useApi} from "@/api";
+
+let data = reactive({
+  activeName: "create",
+  questionJson: null,
+  questions: [],
+})
+
+const api = useApi();
+
+function handleClick(tab, event) {
+  switch (tab.props.name) {
+    case "create":
+      break;
+    case "refused":
+      break;
+  }
+}
+
+function openFile(file, fileList){
+  let reader = new FileReader();
+  reader.readAsText(file.raw);
+  reader.onload = () => {
+    data.questionJson = reader.result;
+  }
+}
+
+function submitQuestions(){
+  console.log(JSON.parse(data.questionJson));
+  data.questions = JSON.parse(data.questionJson).content;
+  if(data.questions.length === 0){
+    alert("请先选择文件");
+  }else {
+    api.createBokQuestion(data.questions)
+        .then(res => {
+          alert("创建成功");
+          console.log(res);
+        }).catch(err => {
+      alert("创建失败");
+      console.log(err);
+    })
+  }
+
+}
+
+</script>
+
+<style scoped>
+  .creator-mode-body{
+    margin: 20px;
+  }
+
+</style>

+ 4 - 0
src/views/Bok/SideBar.vue

@@ -17,6 +17,10 @@
         <i class="el-icon-box"></i>
         <template #title>题库</template>
       </el-menu-item>
+      <el-menu-item index="operation">
+        <i class="el-icon-box"></i>
+        <template #title>操作</template>
+      </el-menu-item>
       <el-menu-item index="knowledgePoint">
         <i class="el-icon-menu"></i>
         <template #title>知识点</template>

+ 10 - 4
vue.config.js

@@ -7,14 +7,20 @@ module.exports = {
   // 选项...
     devServer: {
         proxy: {
-            "/api": {
+            "/two": {
+                target: "https://bok.seec.seecoder.cn",
+                changeOrigin: true,
+                pathRewrite: {
+                    "^/two": ""
+                }
+            },
+            "/one": {
                 target: "http://localhost:8080",
-                ws: true,
                 changeOrigin: true,
                 pathRewrite: {
-                    "^/api": ""
+                    "^/one": ""
                 }
-            }
+            },
         },
         port: 8000,
     },