| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- import { API_FAST_PLANS, API_FAST_CHECKS, API_FAST_CLOCKS, API_CLOCK_RECORDS, API_CLOCK_HOME, API_CLOCK_STATS, API_CLOCK_SUMMARY_RECORDS, API_CLOCK_RECORD_UPDATE, API_CLOCK_STREAKS, API_EAT_WAKES, API_FAST_WINDOW, API_SLEEP_WINDOW, API_SET_SCHEDULE } from './http/api'
- import { request } from './http/request';
- import { getLocalPush } from '@/features/trackTimeDuration/actions/TrackTimeActions';
- export const getPlans = () => {
- return new Promise((resolve, reject) => {
- request({
- url: API_FAST_PLANS, method: 'GET', data: {}
- }).then(res => {
- resolve(res);
- }).catch(e => {
- reject(e)
- })
- })
- }
- export const setPlan = (params: Record<string, any> | undefined) => {
- return new Promise((resolve, reject) => {
- request({
- url: API_FAST_PLANS, method: 'POST', data: { ...params }
- }).then(res => {
- resolve(res);
- // getLocalPush();
- }).catch(e => {
- reject(e)
- })
- })
- }
- export const getChecks = () => {
- return new Promise((resolve) => {
- request({
- url: API_FAST_CHECKS + `?scenario=${global.scenario}`, method: 'GET', data: {}
- }).then(res => {
- resolve(res);
- })
- })
- }
- export const clockHome = () => {
- return new Promise((resolve, reject) => {
- request({
- url: API_CLOCK_HOME, method: 'GET', data: {}
- }).then(res => {
- resolve(res);
- }).catch(e => {
- reject(e)
- })
- })
- }
- export const clockSummaryStats = (params: any) => {
- return new Promise((resolve) => {
- request({
- url: API_CLOCK_STATS, method: 'GET', data: { ...params }
- }).then(res => {
- resolve(res);
- })
- })
- }
- export const eatWakes = (params: any) => {
- return new Promise((resolve) => {
- request({
- url: API_EAT_WAKES, method: 'GET', data: { ...params }
- }).then(res => {
- resolve(res);
- })
- })
- }
- export const getClocks = () => {
- return new Promise((resolve, reject) => {
- request({
- url: API_FAST_CLOCKS, method: 'GET', data: {}
- }).then(res => {
- resolve(res);
- }).catch(e => {
- reject(e)
- })
- })
- }
- export const getClockRecords = (params: any) => {
- return new Promise((resolve) => {
- request({
- url: API_CLOCK_RECORDS, method: 'GET', data: { ...params }
- }).then(res => {
- resolve(res);
- })
- })
- }
- export const recordCheck = (params: Record<string, any>) => {
- if (params.real_check_time) {
- var date = new Date((params as any).real_check_time)
- var month = date.getMonth() + 1
- var day = date.getDate()
- params.real_check_date = date.getFullYear() + (month < 10 ? '0' + month : month + '') + (day < 10 ? '0' + day : day + '')
- }
- //如果是系统错误,不用toast而用alert
- params.showAlert = true
- return new Promise((resolve, reject) => {
- request({
- url: API_FAST_CLOCKS + `?scenario=${global.scenario}`, method: 'POST', data: { ...params }
- }).then(res => {
- resolve(res);
- }).catch(e => {
- if (global.postBtnUpdateStatus)
- global.postBtnUpdateStatus('idle')
- reject(e)
- })
- })
- }
- export const updateRecord = (params: any, id: any) => {
- return new Promise((resolve, reject) => {
- request({
- url: API_CLOCK_RECORD_UPDATE + '/' + id, method: 'POST', data: { ...params }
- }).then(res => {
- resolve(res);
- }).catch(e => {
- reject(e)
- })
- })
- }
- export const delRecord = (id: string,params?:any) => {
- return new Promise((resolve) => {
- request({
- url: API_CLOCK_RECORDS + '/' + id, method: 'DELETE', data: {...params}
- }).then(res => {
- resolve(res);
- })
- })
- }
- export const clearTimeRecords = () => {
- return new Promise((resolve) => {
- request({
- url: API_CLOCK_RECORDS, method: 'DELETE', data: {}
- }).then(res => {
- resolve(res);
- })
- })
- }
- export const getStreaks = (params: any) => {
- return new Promise((resolve) => {
- request({
- url: API_CLOCK_STREAKS, method: 'GET', data: { ...params }
- }).then(res => {
- resolve(res);
- })
- })
- }
- export const fastWindow = () => {
- return new Promise((resolve) => {
- request({
- url: API_FAST_WINDOW, method: 'GET', data: {}
- }).then(res => {
- resolve(res);
- })
- })
- }
- export const sleepWindow = () => {
- return new Promise((resolve) => {
- request({
- url: API_SLEEP_WINDOW, method: 'GET', data: {}
- }).then(res => {
- resolve(res);
- })
- })
- }
- export const setSchedule = (params: any) => {
- return new Promise((resolve) => {
- request({
- url: API_SET_SCHEDULE, method: 'POST', data: { ...params }
- }).then(res => {
- resolve(res);
- })
- })
- }
|