mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/student-h5.git
synced 2025-12-06 17:36:45 +08:00
feat:增加投票
This commit is contained in:
@@ -3,7 +3,9 @@ import { reactive, ref, toRefs, watch } from "vue";
|
||||
import axios from 'axios';
|
||||
import { getCookie } from "@/api/utils";
|
||||
import JSONBigInt from 'json-bigint';
|
||||
|
||||
const JSONBigIntStr = JSONBigInt({ storeAsString: true });
|
||||
|
||||
export function usePage(_url, param, callback) {
|
||||
|
||||
const state = reactive({
|
||||
@@ -38,27 +40,30 @@ export function usePage(_url, param, callback) {
|
||||
fetchData,
|
||||
};
|
||||
}
|
||||
|
||||
export function useRequest(_url, params = {}) {
|
||||
|
||||
const data = ref({})
|
||||
const loading = ref(false)
|
||||
const state = reactive({
|
||||
data: {},
|
||||
loading: false,
|
||||
|
||||
})
|
||||
|
||||
watch(params, () => {
|
||||
fetchData()
|
||||
})
|
||||
|
||||
function fetchData() {
|
||||
loading.value = true
|
||||
state.loading = true
|
||||
request(_url, params).then(r => {
|
||||
data.value = r.data
|
||||
loading.value = false
|
||||
state.data = r.data
|
||||
state.loading = false
|
||||
})
|
||||
}
|
||||
|
||||
fetchData()
|
||||
return {
|
||||
data,
|
||||
loading,
|
||||
...toRefs(state),
|
||||
fetchData,
|
||||
};
|
||||
}
|
||||
@@ -94,6 +99,12 @@ export async function request(_url, params) {
|
||||
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')
|
||||
}
|
||||
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'})
|
||||
// } else {
|
||||
@@ -103,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'})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -140,11 +147,5 @@ export async function boeRequest(_url, params) {
|
||||
return res.text()
|
||||
}).then(res => {
|
||||
return JSONBigIntStr.parse(res)
|
||||
}).then(res => {
|
||||
console.log(res)
|
||||
if (res.status === 500) {
|
||||
import.meta.env.MODE === 'development' ? router.push({ path: '/login', query: { returnUrl: router.currentRoute.value.fullPath } }) : window.open(import.meta.env.VITE_BASE_LOGIN_URL + window.location.url, '_top')
|
||||
}
|
||||
return res
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user