diff --git a/src/api/apis.js b/src/api/apis.js new file mode 100644 index 00000000..ef3088b2 --- /dev/null +++ b/src/api/apis.js @@ -0,0 +1 @@ +export const STUDENT_LIST = '/admin/student/getStudent' \ No newline at end of file diff --git a/src/api/indexTaskManage.js b/src/api/indexTaskManage.js index d7ba25c4..e6690e52 100644 --- a/src/api/indexTaskManage.js +++ b/src/api/indexTaskManage.js @@ -37,3 +37,9 @@ export const QueryVoteManagementDetail = (obj) => http.post('/admin/vote/manage/ // 根据投票任务Id获取投票任务信息 export const QueryVoteTaskDetailById = (obj) => http.post('/voteSubmit/queryVoteTaskDetailById', obj) + +// 直播考勤请假 +export const AttendanceLeave = (obj) => http.post('/stu/task/attendance/leave', obj) + +// 直播考勤签到 +export const AttendanceSign = (obj) => http.post('/stu/task/attendance/sign', obj) diff --git a/src/api/request.js b/src/api/request.js index 54b97d64..707aba9f 100644 --- a/src/api/request.js +++ b/src/api/request.js @@ -1,4 +1,4 @@ -import {reactive, ref, toRefs, watch} from "vue"; +import {isRef, reactive, ref, toRefs, unref, watch, watchEffect} from "vue"; import {getCookieForName, throttle} from "@/api/method"; import JSONBigInt from 'json-bigint'; @@ -22,7 +22,7 @@ export function useBoeApiPage(_url, params = {}, config = { function fetch() { state.loading = true - return request(_url, params).then(r => { + return boeRequest(_url, params).then(r => { state.data = config.result(r) state.totalPage = config.totalPage(r) state.total = config.total(r) @@ -62,7 +62,7 @@ export function useBoeApi(_url, params = {}, config = { function fetch() { state.loading = true - return request(_url, params).then(r => { + return boeRequest(_url, params).then(r => { state.data = config.result(r) state.loading = false }) @@ -95,7 +95,7 @@ export function useBoeUserListPage(_url, params = {}, init = true) { state.loading = false return } - return request(_url, params).then(r => { + return boeRequest(_url, params).then(r => { state.data = params.page === 1 ? r.result.userInfoList : [...state.data, ...r.result.userInfoList] state.totalPage = r.result.totalPage state.total = r.result.totalElement @@ -110,31 +110,48 @@ export function useBoeUserListPage(_url, params = {}, init = true) { }; } -export function usePage(_url, params = {}, init = true) { +export function usePage(_url, params, init = true) { const state = reactive({ data: [], + total:1, + current:1, + pages:1, loading: false }) - watch(params, () => { - fetch() - }) + if (isRef(params)) { + watch(params, () => { + fetch() + }) + } + + function reset(){ + state.data = [] + state.loading = false + } function fetch() { state.loading = true - return request(_url, params).then(r => { - console.log('fetch') - console.log(r) - state.data = r.result + return request(unref(_url), unref(params)).then(r => { + state.data = r.data.records + state.current = r.data.current + state.pages = r.data.pages + state.total = r.data.total state.loading = false }) } - init && fetch() + if (isRef(_url)) { + watchEffect(fetch) + } else { + init && fetch() + } + return { ...toRefs(state), fetch, + reset, }; } @@ -163,7 +180,7 @@ export function useRequest(_url, params = {}, init = true) { }; } -export async function request(_url, params) { +export async function boeRequest(_url, params) { const s = _url.split(' ') let url = s[0] const method = s[1]?.toLowerCase() || 'get' @@ -193,23 +210,34 @@ export async function request(_url, params) { }).then(res => { return JSONBigIntStr.parse(res) }) - // return axios({ - // url, - // method, - // headers: { - // token: getCookie('token'), - // ...method !== 'get' ? {'Content-Type': 'application/json'} : {} - // }, - // baseURL: '', - // ...method !== 'get' ? {data: JSON.stringify(body)} : {} - // }).then(resp => { - // return resp.data - // }).then(response => { - // console.log(response) - // return response - // }).catch(e => { - // console.log(2222) - // console.log(e) - // // router.push({path: '/login'}) - // }) +} + +export async function request(_url, params) { + const s = _url.split(' ') + let url = s[0] + const method = s[1]?.toLowerCase() || 'get' + if (method === 'get') { + let paramsArray = []; + if (params) { + Object.keys(params).forEach(key => paramsArray.push(key + '=' + params[key])) + if (url.search(/\?/) === -1) { + url += '?' + paramsArray.join('&') + } else { + url += '&' + paramsArray.join('&') + } + } + } + const body = method !== 'get' ? params || {} : {} + return fetch(process.env.VUE_APP_BASE_API + url, { + method, + headers: { + token: getCookieForName('token'), + ...method !== 'get' ? {'Content-Type': 'application/json'} : {} + }, + ...method !== 'get' ? {body: JSON.stringify(body)} : {} + }).then(res => { + return res.text() + }).then(res => { + return JSONBigIntStr.parse(res) + }) } \ No newline at end of file diff --git a/src/components/drawers/ActiveAttendance.vue b/src/components/drawers/ActiveAttendance.vue index 4b51a340..7b780f05 100644 --- a/src/components/drawers/ActiveAttendance.vue +++ b/src/components/drawers/ActiveAttendance.vue @@ -8,7 +8,7 @@ >