|
@@ -1,224 +1,104 @@
|
|
|
-import {createAction, NavigationActions, Storage} from '../utils'
|
|
|
+import {createAction, NavigationActions, Storage} from '../utils';
|
|
|
import SyncStorage from 'sync-storage';
|
|
|
-import * as authService from '../services/user'
|
|
|
-import {REFRESH_STATE} from "react-native-refresh-flatlist";
|
|
|
-import {userfetch} from '../services/user'
|
|
|
-import TurnPage from "../components/TurnPage";
|
|
|
-import ResponseError from "../components/ResponseError";
|
|
|
+import * as authService from '../services/user';
|
|
|
+import ResponseError from '../components/ResponseError';
|
|
|
|
|
|
-let noticeData = [], receiveMessageData = [], sendMessageData = []
|
|
|
export default {
|
|
|
namespace: 'auth',
|
|
|
state: {
|
|
|
- login: false,
|
|
|
loading: false,
|
|
|
- fetching: false,
|
|
|
- errorMessage: '',
|
|
|
- infoData: {},
|
|
|
- noticeData: [],
|
|
|
- noticeRState: "",
|
|
|
- sendMessageData: [],
|
|
|
- sendMessageRState: '',
|
|
|
- receiveMessageData: [],
|
|
|
- receiveMessageRState: ""
|
|
|
+ tipsCount: {},
|
|
|
+ homeCount: {},
|
|
|
},
|
|
|
reducers: {
|
|
|
updateState(state, {payload}) {
|
|
|
- return {...state, ...payload}
|
|
|
+ return {...state, ...payload};
|
|
|
},
|
|
|
queryList(state, {payload}) {
|
|
|
- return {...state, ...payload}
|
|
|
+ return {...state, ...payload};
|
|
|
},
|
|
|
},
|
|
|
effects: {
|
|
|
* authLogin({payload, callback, unLogin}, {call, put}) {
|
|
|
- const result = yield call(authService.authLogin, payload)
|
|
|
- if (result.success) {
|
|
|
- SyncStorage.set('credential', result.data);
|
|
|
+ const result = yield call(authService.authLogin, payload);
|
|
|
+ if (!result.code) {
|
|
|
+ const data = {
|
|
|
+ token: result.data.token,
|
|
|
+ username: result.data.username,
|
|
|
+ user_id: result.data.user_id,
|
|
|
+ manager_stores: result.data.manager_stores,
|
|
|
+ };
|
|
|
+ SyncStorage.set('credential', data);
|
|
|
+ SyncStorage.set('premissions', result.data.permissions);
|
|
|
if (callback) {
|
|
|
- callback()
|
|
|
+ callback();
|
|
|
}
|
|
|
} else {
|
|
|
SyncStorage.remove('credential');
|
|
|
- unLogin()
|
|
|
+ unLogin();
|
|
|
}
|
|
|
},
|
|
|
* login({payload, callback, unLogin}, {call, put}) {
|
|
|
- yield put(createAction('updateState')({fetching: true}))
|
|
|
- const result = yield call(authService.login, payload)
|
|
|
- if (result.success) {
|
|
|
+ yield put(createAction('updateState')({loading: true}));
|
|
|
+ const result = yield call(authService.login, payload);
|
|
|
+ if (!result.code) {
|
|
|
+ const data = {
|
|
|
+ token: result.data.token,
|
|
|
+ username: result.data.username,
|
|
|
+ user_id: result.data.user_id,
|
|
|
+ manager_stores: result.data.manager_stores,
|
|
|
+ };
|
|
|
+ SyncStorage.set('credential', data);
|
|
|
+ SyncStorage.set('premissions', result.data.permissions);
|
|
|
if (callback) {
|
|
|
- callback()
|
|
|
+ callback();
|
|
|
}
|
|
|
- SyncStorage.set('credential', result.data);
|
|
|
- yield put(NavigationActions.navigate({
|
|
|
- routeName: "Main",
|
|
|
- actions: [NavigationActions.navigate({routeName: 'SalesHome'})],
|
|
|
- }))
|
|
|
} else {
|
|
|
- if (result.errors) {
|
|
|
- unLogin(result.errors)
|
|
|
+ if (result.msg) {
|
|
|
+ unLogin(result.msg);
|
|
|
}
|
|
|
}
|
|
|
- yield put(createAction('updateState')({fetching: false}))
|
|
|
+ yield put(createAction('updateState')({loading: false}));
|
|
|
},
|
|
|
* logout({payload}, {call, put}) {
|
|
|
- yield call(authService.loginOut)
|
|
|
+ yield call(authService.loginOut);
|
|
|
SyncStorage.remove('credential');
|
|
|
yield put(NavigationActions.navigate({
|
|
|
- routeName: "Login",
|
|
|
+ routeName: 'Login',
|
|
|
actions: [NavigationActions.navigate({routeName: 'Login'})],
|
|
|
}));
|
|
|
},
|
|
|
- * fetchrnPermissions({payload}, {call, put}) {
|
|
|
- const response = yield call(authService.queryPermissions);
|
|
|
- if (response.success) {
|
|
|
- SyncStorage.set('premissions', response.data);
|
|
|
- }
|
|
|
- },
|
|
|
- * fetchRNInfo({payload}, {call, put}) {
|
|
|
- yield put(createAction('updateState')({infoData: {}, loading: true}))
|
|
|
- const response = yield call(authService.queryInfo);
|
|
|
- if (response.success) {
|
|
|
- yield put(createAction('updateState')({infoData: response.data, loading: false}))
|
|
|
- }else {
|
|
|
- ResponseError(response)
|
|
|
- yield put(createAction('updateState')({infoData: {}, loading: false}))
|
|
|
- }
|
|
|
- },
|
|
|
- //公告列表
|
|
|
- * fetchNoticeList({payload}, {call, put}) {
|
|
|
- if (payload.getParm.page > 1) {
|
|
|
- yield put(createAction('queryList')({noticeRState: REFRESH_STATE.FooterRefreshing,}));
|
|
|
- } else {
|
|
|
- yield put(createAction('queryList')({noticeRState: REFRESH_STATE.HeaderRefreshing,}));
|
|
|
- }
|
|
|
- const response = yield call(authService.queryNoticeList, payload);
|
|
|
- if (response.success) {
|
|
|
- const result = TurnPage(response, payload.getParm, noticeData)
|
|
|
- noticeData = result.data
|
|
|
- yield put(createAction('queryList')({
|
|
|
- noticeData: noticeData, noticeRState: result.state,
|
|
|
- total: response.total, page: payload.getParm.page
|
|
|
- }));
|
|
|
- } else {
|
|
|
- ResponseError(response)
|
|
|
- yield put(createAction('queryList')({noticeRState: REFRESH_STATE.Ready,}));
|
|
|
- }
|
|
|
-
|
|
|
- },
|
|
|
- //公告详情
|
|
|
- * fetchrNoticeDetail({payload, callback}, {call, put}) {
|
|
|
- const response = yield call(authService.queryNoticeDetail, payload);
|
|
|
- if (response.success) {
|
|
|
- if (callback) {
|
|
|
- callback(response)
|
|
|
- }
|
|
|
- } else {
|
|
|
- ResponseError(response)
|
|
|
- }
|
|
|
- },
|
|
|
- //回复公告
|
|
|
- * fetchReplyNotice({payload, callback}, {call, put}) {
|
|
|
- yield put(createAction('queryList')({loading: true,}));
|
|
|
- const response = yield call(authService.replyNotice, payload);
|
|
|
- if (response.success) {
|
|
|
- if (callback) {
|
|
|
- callback()
|
|
|
- }
|
|
|
- } else {
|
|
|
- ResponseError(response)
|
|
|
- }
|
|
|
- yield put(createAction('queryList')({loading: false,}));
|
|
|
- },
|
|
|
- //私信列表
|
|
|
- * fetchReceiveMessageList({payload}, {call, put}) {
|
|
|
- if (payload.getParm.page > 1) {
|
|
|
- yield put(createAction('queryList')({receiveMessageRState: REFRESH_STATE.FooterRefreshing,}));
|
|
|
- } else {
|
|
|
- yield put(createAction('queryList')({receiveMessageRState: REFRESH_STATE.HeaderRefreshing,}));
|
|
|
- }
|
|
|
- const response = yield call(authService.queryReceiveMessageList, payload);
|
|
|
- if (response.success) {
|
|
|
- const result = TurnPage(response, payload.getParm, receiveMessageData)
|
|
|
- receiveMessageData = result.data
|
|
|
- yield put(createAction('queryList')({
|
|
|
- receiveMessageData: receiveMessageData, receiveMessageRState: result.state,
|
|
|
- receiveTotal: response.total, receivePage: payload.getParm.page
|
|
|
- }));
|
|
|
- } else {
|
|
|
- ResponseError(response)
|
|
|
- yield put(createAction('queryList')({receiveMessageRState: REFRESH_STATE.Ready,}));
|
|
|
- }
|
|
|
- },
|
|
|
- //私信列表
|
|
|
- * fetchSendMessageList({payload}, {call, put}) {
|
|
|
- if (payload.getParm.page > 1) {
|
|
|
- yield put(createAction('queryList')({sendMessageRState: REFRESH_STATE.FooterRefreshing,}));
|
|
|
- } else {
|
|
|
- yield put(createAction('queryList')({sendMessageRState: REFRESH_STATE.HeaderRefreshing,}));
|
|
|
- }
|
|
|
- const response = yield call(authService.querySendMessageList, payload);
|
|
|
- if (response.success) {
|
|
|
- const result = TurnPage(response, payload.getParm, sendMessageData)
|
|
|
- sendMessageData = result.data
|
|
|
- yield put(createAction('queryList')({
|
|
|
- sendMessageData: sendMessageData, sendMessageRState: result.state,
|
|
|
- sendTotal: response.total, sendPage: payload.getParm.page
|
|
|
- }));
|
|
|
- } else {
|
|
|
- ResponseError(response)
|
|
|
- yield put(createAction('queryList')({sendMessageRState: REFRESH_STATE.Ready,}));
|
|
|
- }
|
|
|
- },
|
|
|
- //读私信
|
|
|
- * fetchReadReceiveMessage({payload, callback}, {call, put}) {
|
|
|
- const response = yield call(authService.readReceiveMessage, payload);
|
|
|
- if (response.success) {
|
|
|
- if (callback) {
|
|
|
- callback(response)
|
|
|
- }
|
|
|
- } else {
|
|
|
- ResponseError(response)
|
|
|
- }
|
|
|
- },
|
|
|
- //回复私信
|
|
|
- * fetchReplyMessage({payload, callback}, {call, put}) {
|
|
|
- yield put(createAction('queryList')({loading: true,}));
|
|
|
- const response = yield call(authService.replyMessage, payload);
|
|
|
- if (response.success) {
|
|
|
- if (callback) {
|
|
|
- callback()
|
|
|
- }
|
|
|
- } else {
|
|
|
- ResponseError(response)
|
|
|
- }
|
|
|
- yield put(createAction('queryList')({loading: false,}));
|
|
|
- },
|
|
|
//修改密码
|
|
|
* changePassword({payload, callback}, {call, put}) {
|
|
|
- yield put(createAction('queryList')({loading: true,}));
|
|
|
+ yield put(createAction('queryList')({loading: true}));
|
|
|
const response = yield call(authService.changePassword, payload);
|
|
|
- if (response.success) {
|
|
|
+ if (!response.code) {
|
|
|
if (callback) {
|
|
|
- callback()
|
|
|
+ callback();
|
|
|
}
|
|
|
} else {
|
|
|
- ResponseError(response)
|
|
|
+ ResponseError(response);
|
|
|
}
|
|
|
- yield put(createAction('queryList')({loading: false,}));
|
|
|
+ yield put(createAction('queryList')({loading: false}));
|
|
|
},
|
|
|
- //验证登录地址
|
|
|
- * checkBaseURL({payload, callback}, {call, put}) {
|
|
|
- const response = yield call(authService.checkBaseURL, payload);
|
|
|
- if (response.success) {
|
|
|
- if (response.data === 'carwin') {
|
|
|
- callback(true)
|
|
|
- } else {
|
|
|
- callback(false)
|
|
|
- }
|
|
|
+ * fetchHomeCount({payload}, {call, put}) {
|
|
|
+ yield put(createAction('updateState')({homeCount: {}, loading: true}));
|
|
|
+ const response = yield call(authService.queryHomeCount);
|
|
|
+ if (!response.code) {
|
|
|
+ yield put(createAction('updateState')({homeCount: response.data, loading: false}));
|
|
|
+ } else {
|
|
|
+ ResponseError(response);
|
|
|
+ yield put(createAction('updateState')({homeCount: {}, loading: false}));
|
|
|
+ }
|
|
|
+ },
|
|
|
+ * fetchTipsCount({payload}, {call, put}) {
|
|
|
+ yield put(createAction('updateState')({loading: true}));
|
|
|
+ const response = yield call(authService.queryTipsCount);
|
|
|
+ if (!response.code) {
|
|
|
+ yield put(createAction('updateState')({tipsCount: response.data, loading: false}));
|
|
|
} else {
|
|
|
- callback(false)
|
|
|
+ ResponseError(response);
|
|
|
+ yield put(createAction('updateState')({tipsCount: {}, loading: false}));
|
|
|
}
|
|
|
},
|
|
|
},
|
|
@@ -227,4 +107,4 @@ export default {
|
|
|
//dispatch({ type: 'loadStorage' })
|
|
|
},
|
|
|
},
|
|
|
-}
|
|
|
+};
|