Add support for Android and iOS (#96)

Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
GermeyandAceDataCloud authored and GitHub committed 2024-08-04 13:13:13 +08:00
1 parent 5843f9c837
commit af0c3db0f4
73 files changed
+2163 -21

No files matched your search

+14 -3
View File
@@ -3,7 +3,8 @@ import { IRootState } from '../common/models';
import { userOperator, oauthOperator, siteOperator, exchangeOperator } from '@/operators';
import { IToken, IUser } from '@/models';
import { getSiteOrigin } from '@/utils/site';
import { login as authLogin } from '@/utils';
import { loginRedirect } from '@/utils';
import { SURFACE_ANDROID, SURFACE_IOS } from '@/constants';
export const resetAll = ({ commit }: ActionContext<IRootState, IRootState>) => {
commit('resetToken');
@@ -122,9 +123,19 @@ export const getSite = async ({ state, commit }: ActionContext<IRootState, IRoot
}
};
export const login = async ({ state }: ActionContext<IRootState, IRootState>) => {
export const login = async ({ state, commit }: ActionContext<IRootState, IRootState>) => {
const site = state?.site?.origin;
authLogin({ redirect: window.location.pathname, site });
if (import.meta.env.VITE_SURFACE === SURFACE_IOS || import.meta.env.VITE_SURFACE === SURFACE_ANDROID) {
commit('setAuth', {
flow: 'popup',
visible: true
});
} else {
commit('setAuth', {
flow: 'redirect'
});
loginRedirect({ redirect: window.location.pathname, site });
}
};
export const logout = async ({ dispatch }: ActionContext<IRootState, IRootState>) => {
+4
View File
@@ -13,6 +13,10 @@ export interface ICommonState {
setting?: ISetting;
site?: ISite;
currency: string;
auth: {
flow: 'popup' | 'redirect';
visible: boolean;
};
exchange:
| {
[key: string]: number;
+8
View File
@@ -15,6 +15,13 @@ export const setToken = (state: IRootState, payload: any): void => {
};
};
export const setAuth = (state: IRootState, payload: any): void => {
state.auth = {
...state.auth,
...payload
};
};
export const resetToken = (state: IRootState): void => {
state.token = {};
};
@@ -48,6 +55,7 @@ export const setCurrency = (state: IRootState, payload: string): void => {
export default {
setUser,
setSite,
setAuth,
setCurrency,
setExchange,
resetUser,
+4
View File
@@ -10,6 +10,10 @@ export default (): IRootState => {
currency: 'usd',
exchange: undefined,
user: {},
auth: {
flow: 'redirect',
visible: false
},
token: {
access: undefined,
refresh: undefined,