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

+8
View File
@@ -1,5 +1,6 @@
<template>
<el-config-provider :locale="locale">
<auth-panel v-if="authPopup" />
<router-view />
<el-tag v-if="isTest" size="large" class="tag" type="warning">{{ $t('index.button.testEnv') }}</el-tag>
</el-config-provider>
@@ -8,12 +9,14 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { ElConfigProvider, ElTag } from 'element-plus';
import AuthPanel from './components/common/AuthPanel.vue';
import locale from 'element-plus/dist/locale/zh-cn.mjs';
import { isTest } from '@/constants/endpoint';
export default defineComponent({
components: {
ElConfigProvider,
AuthPanel,
ElTag
},
data() {
@@ -21,6 +24,11 @@ export default defineComponent({
isTest,
locale
};
},
computed: {
authPopup() {
return this.$store.state.auth.flow === 'popup' && this.$store.state.auth.visible;
}
}
});
</script>
+1 -6
View File
@@ -113,12 +113,7 @@ export default defineComponent({
});
},
async onLogout() {
await this.$store.dispatch('resetToken');
await this.$store.dispatch('resetUser');
const url = window.location.href;
const baseUrlAuth = getBaseUrlAuth();
const redirectUrl = `${baseUrlAuth}/auth/logout?redirect=${url}`;
window.location.href = redirectUrl;
this.$store.dispatch('logout');
}
}
});
+1
View File
@@ -7,3 +7,4 @@ export * from './midjourney';
export * from './qrart';
export * from './suno';
export * from './mapping';
export * from './surface';
+3
View File
@@ -0,0 +1,3 @@
export const SURFACE_WEB = 'web';
export const SURFACE_ANDROID = 'android';
export const SURFACE_IOS = 'ios';
+7 -5
View File
@@ -1,5 +1,4 @@
<script lang="ts">
import { login } from '@/utils';
import { defineComponent } from 'vue';
interface IData {
@@ -10,12 +9,15 @@ export default defineComponent({
name: 'AuthLogin',
data(): IData {
return {
redirect: this.$route.query.redirect?.toString() || '/'
redirect: this.$route.query.redirect?.toString()
};
},
async mounted() {
login({ redirect: this.redirect });
},
methods: {}
if (!!this.$store.state.token.access) {
this.$router.push(this.redirect || '/');
} else {
this.$store.dispatch('login');
}
}
});
</script>
+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,
+7 -1
View File
@@ -15,7 +15,13 @@ export const getInviterId = () => {
return result;
};
export const login = ({ redirect = '/', site = window.location.origin }: { redirect?: string; site?: string }) => {
export const loginRedirect = ({
redirect = '/',
site = window.location.origin
}: {
redirect?: string;
site?: string;
}) => {
const hubBaseUrl = getBaseUrlHub();
const authBaseUrl = getBaseUrlAuth();
const inviterId = getInviterId();