user.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import Taro from '@tarojs/taro'
  2. import { API_OAUTH_LOGIN, API_REGISTER, API_LOGIN, API_LOGOUT, API_CLEAR_USER, API_USER_INFO, API_CHECK_UNIQUE, API_CLIENT_ID, API_USER_PERMS, API_USER_LOCATION, API_PAY_UPLOAD, API_USER_ACCESS, API_PRODUCTS, API_CREATE_ORDER, API_ORDER_CHECK } from './http/api'
  3. import { request } from './http/request'
  4. import { clearSuccess, getInfoSuccess, loginSuccess, logoutSuccess, registerSuccess, updateSuccess } from '@/store/user'
  5. import { kIsIOS } from '@/utils/tools'
  6. export const checkUnique = (params: any) => {
  7. return new Promise((resolve, reject) => {
  8. request({
  9. url: API_CHECK_UNIQUE, method: 'POST', data: params
  10. }).then(res => {
  11. resolve(res);
  12. })
  13. })
  14. }
  15. export const login = (username: string, password: string) => {
  16. return new Promise((resolve, reject) => {
  17. request({
  18. url: API_LOGIN, method: 'POST', data: { username, password }
  19. }).then(res => {
  20. resolve(res)
  21. // dispatch(loginSuccess(res));
  22. }).catch(e => {
  23. reject(e)
  24. })
  25. })
  26. }
  27. export const uploadPerm = (params: any) => {
  28. return new Promise((resolve, reject) => {
  29. request({
  30. url: API_USER_PERMS, method: 'POST', data: { ...params }//{ push_enabled: push_enable }
  31. }).then(res => {
  32. resolve(res)
  33. // dispatch(loginSuccess(res));
  34. }).catch(e => {
  35. reject(e)
  36. })
  37. })
  38. }
  39. export const getPerm = () => {
  40. return new Promise((resolve, reject) => {
  41. request({
  42. url: API_USER_PERMS, method: 'GET', data: {}//{ push_enabled: push_enable }
  43. }).then(res => {
  44. resolve(res)
  45. // dispatch(loginSuccess(res));
  46. }).catch(e => {
  47. reject(e)
  48. })
  49. })
  50. }
  51. export const wxLogin = (code: string/*, encryptedData: string, iv: string*/) => {
  52. return new Promise((resolve, reject) => {
  53. request({
  54. url: API_OAUTH_LOGIN, method: 'POST',
  55. data: {
  56. code: code,
  57. type: 'WX_MP',
  58. app_version: '1',
  59. client_version: '1',
  60. client_type: 'WX_MP',
  61. // extra: {
  62. // encryptedData: encryptedData,
  63. // iv: iv
  64. // }
  65. }
  66. }).then(res => {
  67. resolve(res)
  68. // dispatch(loginSuccess(res));
  69. }).catch(e => {
  70. reject(e)
  71. })
  72. })
  73. };
  74. /*
  75. export const wxLogin = (code: string) => (dispatch: any) => {
  76. request({
  77. url: API_OAUTH_LOGIN, method: 'POST', data: { code,type:'WX_MP',app_version:'1',client_version:'1',client_type:'WXP_MP' }
  78. }).then(res => {
  79. console.log(res);
  80. dispatch(loginSuccess(res));
  81. })
  82. }*/
  83. export const register = (name: string, email: string, password: string) => {
  84. return new Promise((resolve, reject) => {
  85. request({
  86. url: API_REGISTER, method: 'POST', data: { client_type: 'IOS', username: name, email: email, password: password }
  87. }).then(res => {
  88. resolve(res);
  89. // dispatch(loginSuccess(res));
  90. }).catch(e => {
  91. reject(e)
  92. })
  93. })
  94. }
  95. export const logout = () => {
  96. return new Promise((resolve, reject) => {
  97. request({
  98. url: API_LOGOUT, method: 'GET', data: {}
  99. }).then(res => {
  100. return resolve(res)
  101. // dispatch(getInfoSuccess(res));
  102. }).catch(e => {
  103. return reject(e)
  104. })
  105. })
  106. }
  107. export const clear = () => (dispatch: any) => {
  108. request({
  109. url: API_CLEAR_USER, method: 'DELETE', data: {}
  110. }).then(_ => {
  111. dispatch(clearSuccess());
  112. Taro.navigateBack();
  113. console.log('clear navi back')
  114. })
  115. }
  116. export const latestLocation = (params) => {
  117. return new Promise((resolve, reject) => {
  118. request({
  119. url: API_USER_LOCATION, method: 'GET', data: { ...params }
  120. }).then(res => {
  121. return resolve(res)
  122. // dispatch(getInfoSuccess(res));
  123. }).catch(e => {
  124. return reject(e)
  125. })
  126. })
  127. }
  128. export const clearLocation = () => {
  129. return new Promise((resolve, reject) => {
  130. request({
  131. url: API_USER_LOCATION, method: 'DELETE', data: {}
  132. }).then(res => {
  133. return resolve(res)
  134. // dispatch(getInfoSuccess(res));
  135. }).catch(e => {
  136. return reject(e)
  137. })
  138. })
  139. }
  140. export const getInfo = () => {
  141. return new Promise((resolve, reject) => {
  142. request({
  143. url: API_USER_INFO, method: 'GET', data: {}
  144. }).then(res => {
  145. return resolve(res)
  146. // dispatch(getInfoSuccess(res));
  147. }).catch(e => {
  148. return reject(e)
  149. })
  150. })
  151. }
  152. export const update = (params: any) => {
  153. return new Promise((resolve, reject) => {
  154. request({
  155. url: API_USER_INFO, method: 'POST', data: params
  156. }).then(res => {
  157. // dispatch(updateSuccess(params));
  158. resolve(res)
  159. }).catch(e => {
  160. reject(e)
  161. })
  162. })
  163. }
  164. export const clientId = (isJiguang = true) => {
  165. if (isJiguang) {
  166. if (global.registerID) {
  167. request({
  168. url: API_CLIENT_ID, method: 'POST', data: {
  169. provider: 'JIGUANG',
  170. client_type: kIsIOS ? 'IOS' : 'ANDROID',
  171. client_id: global.registerID
  172. }
  173. })
  174. }
  175. }
  176. else {
  177. if (global.oneID) {
  178. request({
  179. url: API_CLIENT_ID, method: 'POST', data: {
  180. provider: 'ONESIGNAL',
  181. client_type: kIsIOS ? 'IOS' : 'ANDROID',
  182. client_id: global.oneID
  183. }
  184. })
  185. }
  186. }
  187. }
  188. export const payInfo = (params) => {
  189. return new Promise((resolve, reject) => {
  190. request({
  191. url: API_PAY_UPLOAD, method: 'POST', data: {
  192. ...params
  193. }
  194. }).then(res => {
  195. resolve(res)
  196. // dispatch(loginSuccess(res));
  197. }).catch(e => {
  198. reject(e)
  199. })
  200. })
  201. }
  202. export const products = (params) => {
  203. return new Promise((resolve, reject) => {
  204. request({
  205. url: API_PRODUCTS, method: 'GET', data: {
  206. ...params
  207. }
  208. }).then(res => {
  209. resolve(res)
  210. // dispatch(loginSuccess(res));
  211. }).catch(e => {
  212. reject(e)
  213. })
  214. })
  215. }
  216. export const order = (params) => {
  217. return new Promise((resolve, reject) => {
  218. request({
  219. url: API_CREATE_ORDER, method: 'POST', data: {
  220. ...params
  221. }
  222. }).then(res => {
  223. resolve(res)
  224. // dispatch(loginSuccess(res));
  225. }).catch(e => {
  226. reject(e)
  227. })
  228. })
  229. }
  230. export const orderCheck = (order_no) => {
  231. return new Promise((resolve, reject) => {
  232. request({
  233. url: API_ORDER_CHECK + order_no, method: 'GET', data: {
  234. }
  235. }).then(res => {
  236. resolve(res)
  237. // dispatch(loginSuccess(res));
  238. }).catch(e => {
  239. reject(e)
  240. })
  241. })
  242. }
  243. export const userAccess = () => {
  244. return new Promise((resolve, reject) => {
  245. request({
  246. url: API_USER_ACCESS, method: 'GET', data: {
  247. }
  248. }).then(res => {
  249. resolve(res)
  250. // dispatch(loginSuccess(res));
  251. }).catch(e => {
  252. reject(e)
  253. })
  254. })
  255. }