trackTimeDuration.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. 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'
  2. import { request } from './http/request';
  3. import { getLocalPush } from '@/features/trackTimeDuration/actions/TrackTimeActions';
  4. export const getPlans = () => {
  5. return new Promise((resolve, reject) => {
  6. request({
  7. url: API_FAST_PLANS, method: 'GET', data: {}
  8. }).then(res => {
  9. resolve(res);
  10. }).catch(e => {
  11. reject(e)
  12. })
  13. })
  14. }
  15. export const setPlan = (params: Record<string, any> | undefined) => {
  16. return new Promise((resolve, reject) => {
  17. request({
  18. url: API_FAST_PLANS, method: 'POST', data: { ...params }
  19. }).then(res => {
  20. resolve(res);
  21. // getLocalPush();
  22. }).catch(e => {
  23. reject(e)
  24. })
  25. })
  26. }
  27. export const getChecks = () => {
  28. return new Promise((resolve) => {
  29. request({
  30. url: API_FAST_CHECKS + `?scenario=${global.scenario}`, method: 'GET', data: {}
  31. }).then(res => {
  32. resolve(res);
  33. })
  34. })
  35. }
  36. export const clockHome = () => {
  37. return new Promise((resolve, reject) => {
  38. request({
  39. url: API_CLOCK_HOME, method: 'GET', data: {}
  40. }).then(res => {
  41. resolve(res);
  42. }).catch(e => {
  43. reject(e)
  44. })
  45. })
  46. }
  47. export const clockSummaryStats = (params: any) => {
  48. return new Promise((resolve) => {
  49. request({
  50. url: API_CLOCK_STATS, method: 'GET', data: { ...params }
  51. }).then(res => {
  52. resolve(res);
  53. })
  54. })
  55. }
  56. export const eatWakes = (params: any) => {
  57. return new Promise((resolve) => {
  58. request({
  59. url: API_EAT_WAKES, method: 'GET', data: { ...params }
  60. }).then(res => {
  61. resolve(res);
  62. })
  63. })
  64. }
  65. export const getClocks = () => {
  66. return new Promise((resolve, reject) => {
  67. request({
  68. url: API_FAST_CLOCKS, method: 'GET', data: {}
  69. }).then(res => {
  70. resolve(res);
  71. }).catch(e => {
  72. reject(e)
  73. })
  74. })
  75. }
  76. export const getClockRecords = (params: any) => {
  77. return new Promise((resolve) => {
  78. request({
  79. url: API_CLOCK_RECORDS, method: 'GET', data: { ...params }
  80. }).then(res => {
  81. resolve(res);
  82. })
  83. })
  84. }
  85. export const recordCheck = (params: Record<string, any>) => {
  86. if (params.real_check_time) {
  87. var date = new Date((params as any).real_check_time)
  88. var month = date.getMonth() + 1
  89. var day = date.getDate()
  90. params.real_check_date = date.getFullYear() + (month < 10 ? '0' + month : month + '') + (day < 10 ? '0' + day : day + '')
  91. }
  92. //如果是系统错误,不用toast而用alert
  93. params.showAlert = true
  94. return new Promise((resolve, reject) => {
  95. request({
  96. url: API_FAST_CLOCKS + `?scenario=${global.scenario}`, method: 'POST', data: { ...params }
  97. }).then(res => {
  98. resolve(res);
  99. }).catch(e => {
  100. if (global.postBtnUpdateStatus)
  101. global.postBtnUpdateStatus('idle')
  102. reject(e)
  103. })
  104. })
  105. }
  106. export const updateRecord = (params: any, id: any) => {
  107. return new Promise((resolve, reject) => {
  108. request({
  109. url: API_CLOCK_RECORD_UPDATE + '/' + id, method: 'POST', data: { ...params }
  110. }).then(res => {
  111. resolve(res);
  112. }).catch(e => {
  113. reject(e)
  114. })
  115. })
  116. }
  117. export const delRecord = (id: string,params?:any) => {
  118. return new Promise((resolve) => {
  119. request({
  120. url: API_CLOCK_RECORDS + '/' + id, method: 'DELETE', data: {...params}
  121. }).then(res => {
  122. resolve(res);
  123. })
  124. })
  125. }
  126. export const clearTimeRecords = () => {
  127. return new Promise((resolve) => {
  128. request({
  129. url: API_CLOCK_RECORDS, method: 'DELETE', data: {}
  130. }).then(res => {
  131. resolve(res);
  132. })
  133. })
  134. }
  135. export const getStreaks = (params: any) => {
  136. return new Promise((resolve) => {
  137. request({
  138. url: API_CLOCK_STREAKS, method: 'GET', data: { ...params }
  139. }).then(res => {
  140. resolve(res);
  141. })
  142. })
  143. }
  144. export const fastWindow = () => {
  145. return new Promise((resolve) => {
  146. request({
  147. url: API_FAST_WINDOW, method: 'GET', data: {}
  148. }).then(res => {
  149. resolve(res);
  150. })
  151. })
  152. }
  153. export const sleepWindow = () => {
  154. return new Promise((resolve) => {
  155. request({
  156. url: API_SLEEP_WINDOW, method: 'GET', data: {}
  157. }).then(res => {
  158. resolve(res);
  159. })
  160. })
  161. }
  162. export const setSchedule = (params: any) => {
  163. return new Promise((resolve) => {
  164. request({
  165. url: API_SET_SCHEDULE, method: 'POST', data: { ...params }
  166. }).then(res => {
  167. resolve(res);
  168. })
  169. })
  170. }