trackTimeDuration.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 } 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 getClocks = () => {
  57. return new Promise((resolve, reject) => {
  58. request({
  59. url: API_FAST_CLOCKS, method: 'GET', data: {}
  60. }).then(res => {
  61. resolve(res);
  62. }).catch(e => {
  63. reject(e)
  64. })
  65. })
  66. }
  67. export const getClockRecords = (params: any) => {
  68. return new Promise((resolve) => {
  69. request({
  70. url: API_CLOCK_RECORDS, method: 'GET', data: { ...params }
  71. }).then(res => {
  72. resolve(res);
  73. })
  74. })
  75. }
  76. export const recordCheck = (params: Record<string, any>) => {
  77. if (params.real_check_time) {
  78. var date = new Date((params as any).real_check_time)
  79. var month = date.getMonth() + 1
  80. var day = date.getDate()
  81. params.real_check_date = date.getFullYear() + (month < 10 ? '0' + month : month + '') + (day < 10 ? '0' + day : day + '')
  82. }
  83. //如果是系统错误,不用toast而用alert
  84. params.showAlert = true
  85. return new Promise((resolve, reject) => {
  86. request({
  87. url: API_FAST_CLOCKS + `?scenario=${global.scenario}`, method: 'POST', data: { ...params }
  88. }).then(res => {
  89. resolve(res);
  90. }).catch(e => {
  91. if (global.postBtnUpdateStatus)
  92. global.postBtnUpdateStatus('idle')
  93. reject(e)
  94. })
  95. })
  96. }
  97. export const updateRecord = (params: any, id: any) => {
  98. return new Promise((resolve, reject) => {
  99. request({
  100. url: API_CLOCK_RECORD_UPDATE + '/' + id, method: 'POST', data: { ...params }
  101. }).then(res => {
  102. resolve(res);
  103. }).catch(e => {
  104. reject(e)
  105. })
  106. })
  107. }
  108. export const delRecord = (id: string) => {
  109. return new Promise((resolve) => {
  110. request({
  111. url: API_CLOCK_RECORDS + '/' + id, method: 'DELETE', data: {}
  112. }).then(res => {
  113. resolve(res);
  114. })
  115. })
  116. }
  117. export const clearTimeRecords = () => {
  118. return new Promise((resolve) => {
  119. request({
  120. url: API_CLOCK_RECORDS, method: 'DELETE', data: {}
  121. }).then(res => {
  122. resolve(res);
  123. })
  124. })
  125. }
  126. export const getStreaks = (params:any)=>{
  127. return new Promise((resolve) => {
  128. request({
  129. url: API_CLOCK_STREAKS, method: 'GET', data: {...params}
  130. }).then(res => {
  131. resolve(res);
  132. })
  133. })
  134. }