| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- import Taro from '@tarojs/taro'
- 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 } from './http/api'
- import { request } from './http/request'
- import { clearSuccess, getInfoSuccess, loginSuccess, logoutSuccess, registerSuccess, updateSuccess } from '@/store/user'
- import { kIsIOS } from '@/utils/tools'
- export const checkUnique = (params: any) => {
- return new Promise((resolve, reject) => {
- request({
- url: API_CHECK_UNIQUE, method: 'POST', data: params
- }).then(res => {
- resolve(res);
- })
- })
- }
- export const login = (username: string, password: string) => {
- return new Promise((resolve, reject) => {
- request({
- url: API_LOGIN, method: 'POST', data: { username, password }
- }).then(res => {
- resolve(res)
- // dispatch(loginSuccess(res));
- }).catch(e => {
- reject(e)
- })
- })
- }
- export const uploadPerm = (params: any) => {
- return new Promise((resolve, reject) => {
- request({
- url: API_USER_PERMS, method: 'POST', data: { ...params }//{ push_enabled: push_enable }
- }).then(res => {
- resolve(res)
- // dispatch(loginSuccess(res));
- }).catch(e => {
- reject(e)
- })
- })
- }
- export const getPerm = (params: any) => {
- return new Promise((resolve, reject) => {
- request({
- url: API_USER_PERMS, method: 'GET', data: { ...params }//{ push_enabled: push_enable }
- }).then(res => {
- resolve(res)
- // dispatch(loginSuccess(res));
- }).catch(e => {
- reject(e)
- })
- })
- }
- export const wxLogin = (code: string/*, encryptedData: string, iv: string*/) => {
- return new Promise((resolve, reject) => {
- request({
- url: API_OAUTH_LOGIN, method: 'POST',
- data: {
- code: code,
- type: 'WX_MP',
- app_version: '1',
- client_version: '1',
- client_type: 'WX_MP',
- // extra: {
- // encryptedData: encryptedData,
- // iv: iv
- // }
- }
- }).then(res => {
- resolve(res)
- // dispatch(loginSuccess(res));
- }).catch(e => {
- reject(e)
- })
- })
- };
- /*
- export const wxLogin = (code: string) => (dispatch: any) => {
-
- request({
- url: API_OAUTH_LOGIN, method: 'POST', data: { code,type:'WX_MP',app_version:'1',client_version:'1',client_type:'WXP_MP' }
- }).then(res => {
- console.log(res);
- dispatch(loginSuccess(res));
- })
- }*/
- export const register = (name: string, email: string, password: string) => {
- return new Promise((resolve, reject) => {
- request({
- url: API_REGISTER, method: 'POST', data: { client_type: 'IOS', username: name, email: email, password: password }
- }).then(res => {
- resolve(res);
- // dispatch(loginSuccess(res));
- }).catch(e => {
- reject(e)
- })
- })
- }
- export const logout = () => {
- return new Promise((resolve, reject) => {
- request({
- url: API_LOGOUT, method: 'GET', data: {}
- }).then(res => {
- return resolve(res)
- // dispatch(getInfoSuccess(res));
- }).catch(e => {
- return reject(e)
- })
- })
- }
- export const clear = () => (dispatch: any) => {
- request({
- url: API_CLEAR_USER, method: 'DELETE', data: {}
- }).then(_ => {
- dispatch(clearSuccess());
- Taro.navigateBack();
- console.log('clear navi back')
- })
- }
- export const latestLocation = (params) => {
- return new Promise((resolve, reject) => {
- request({
- url: API_USER_LOCATION, method: 'GET', data: { ...params }
- }).then(res => {
- return resolve(res)
- // dispatch(getInfoSuccess(res));
- }).catch(e => {
- return reject(e)
- })
- })
- }
- export const clearLocation = () => {
- return new Promise((resolve, reject) => {
- request({
- url: API_USER_LOCATION, method: 'DELETE', data: {}
- }).then(res => {
- return resolve(res)
- // dispatch(getInfoSuccess(res));
- }).catch(e => {
- return reject(e)
- })
- })
- }
- export const getInfo = () => {
- return new Promise((resolve, reject) => {
- request({
- url: API_USER_INFO, method: 'GET', data: {}
- }).then(res => {
- return resolve(res)
- // dispatch(getInfoSuccess(res));
- }).catch(e => {
- return reject(e)
- })
- })
- }
- export const update = (params: any) => {
- return new Promise((resolve, reject) => {
- request({
- url: API_USER_INFO, method: 'POST', data: params
- }).then(res => {
- // dispatch(updateSuccess(params));
- resolve(res)
- }).catch(e => {
- reject(e)
- })
- })
- }
- export const clientId = (isJiguang = true) => {
- if (isJiguang) {
- if (global.registerID) {
- request({
- url: API_CLIENT_ID, method: 'POST', data: {
- provider: 'JIGUANG',
- client_type: kIsIOS ? 'IOS' : 'ANDROID',
- client_id: global.registerID
- }
- })
- }
- }
- else {
- if (global.oneID) {
- request({
- url: API_CLIENT_ID, method: 'POST', data: {
- provider: 'ONESIGNAL',
- client_type: kIsIOS ? 'IOS' : 'ANDROID',
- client_id: global.oneID
- }
- })
- }
- }
- }
|