-- fix 课程公开报名

This commit is contained in:
yuping
2023-01-17 04:32:33 +08:00
parent 56e935dfce
commit b4458895ee
6 changed files with 56 additions and 95 deletions

View File

@@ -1,9 +1,11 @@
import router from "@/router";
import { reactive, ref, toRefs, watch } from "vue";
import {reactive, ref, toRefs, watch} from "vue";
import axios from 'axios';
import { getCookie } from "@/api/utils";
import {getCookie} from "@/api/utils";
import JSONBigInt from 'json-bigint';
const JSONBigIntStr = JSONBigInt({ storeAsString: true });
const JSONBigIntStr = JSONBigInt({storeAsString: true});
export function usePage(_url, param, callback) {
const state = reactive({
@@ -12,11 +14,11 @@ export function usePage(_url, param, callback) {
total: 0,
size: 10,
current: 1,
params: { pageNo: 1, pageSize: 10, ...param }
params: {pageNo: 1, pageSize: 10, ...param}
})
watch(param, () => {
state.params = { ...state.params, ...param }
state.params = {...state.params, ...param}
fetchData()
})
@@ -88,14 +90,20 @@ export async function request(_url, params) {
method,
headers: {
'token': getCookie('token'),
...method !== 'get' ? { 'Content-Type': 'application/json' } : {}
...method !== 'get' ? {'Content-Type': 'application/json'} : {}
},
baseURL: import.meta.env.VITE_BASE_API,
...method !== 'get' ? { data: JSON.stringify(body) } : {}
...method !== 'get' ? {data: JSON.stringify(body)} : {}
}).then(resp => resp.data).then(response => {
if (response.code !== 200 && response.code !== 0) {
if (response.code === 1000) {
(import.meta.env.MODE === 'development' || import.meta.env.MODE === 'test') ? router.push({ path: '/login' }) : window.open(import.meta.env.VITE_BASE_LOGIN_URL,'_top')
(import.meta.env.MODE === 'development' || import.meta.env.MODE === 'test') ? router.push({path: '/login'}) : window.open(import.meta.env.VITE_BASE_LOGIN_URL, '_top')
}
if (response.code === 2001) {
router.push({path: '/FaceTeachSignUp', query: {courseId: router.currentRoute.value.query.courseId,type:3}})
}
if (response.code === 2002) {
router.push({path: '/FaceTeachNoCommon', query: {courseId: router.currentRoute.value.query.courseId,type:3}})
}
// if (import.meta.env.DEV && response.code === 1000) {
// router.push({path: '/login'})
@@ -106,12 +114,8 @@ export async function request(_url, params) {
// duration: 2,
// });
// }
throw new Error('接口异常')
}
return response
}).catch(e => {
console.log('eeeee', e)
// router.push({path: '/login'})
})
}
@@ -132,16 +136,16 @@ export async function boeRequest(_url, params) {
}
}
const body = method !== 'get' ? params || {} : {}
return fetch(url,{
return fetch(url, {
method,
headers:{
headers: {
token: getCookie('token'),
...method !== 'get' ? {'Content-Type': 'application/json'} : {}
},
...method !== 'get' ? {body: JSON.stringify(body)} : {}
}).then(res=>{
}).then(res => {
return res.text()
}).then(res=>{
}).then(res => {
return JSONBigIntStr.parse(res)
})
}