1404/10/28-base
This commit is contained in:
+172
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
import 'ant-design-vue/dist/antd.less'
|
||||
import './assets/css/main.less'
|
||||
import 'virtual:uno.css'
|
||||
import { computed, createApp, ref, watch } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import '@unocss/reset/tailwind-compat.css'
|
||||
import VueApexCharts from 'vue3-apexcharts'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import { authenticateWithFingerprint, getIsActiveFingerprint, getToken, isIphone, removeToken } from '@/utils'
|
||||
import { useUserStore } from '@/store/userStore'
|
||||
import { useWalletStore } from '@/store/walletStore'
|
||||
import { useFundUserStore } from '@/store/fundStore'
|
||||
import VueLazyLoad from 'vue3-lazyload'
|
||||
import { getMe } from '@/api/me'
|
||||
import type { NavigationGuardNext, RouteLocationNormalized } from 'vue-router'
|
||||
import { useAuthStore } from '@/store/useAuthStore'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(createPinia())
|
||||
app.use(VueLazyLoad, {
|
||||
// options...
|
||||
})
|
||||
app.use(router)
|
||||
app.use(VueApexCharts)
|
||||
|
||||
const userStore = useUserStore()
|
||||
const walletStore = useWalletStore()
|
||||
const fundStore = useFundUserStore()
|
||||
const authStore = useAuthStore()
|
||||
const isApple: boolean = isIphone()
|
||||
let isFirst: boolean = true
|
||||
let fingerPosition: boolean = false
|
||||
let timeoutId: ReturnType<typeof setTimeout> | null = null
|
||||
let hasFingerPrint: boolean = false
|
||||
const userInfo = ref()
|
||||
// userInfo.value = await getMe()
|
||||
// const token = getToken()
|
||||
|
||||
const currentRoute = computed(() => {
|
||||
return router.currentRoute.value.fullPath
|
||||
})
|
||||
|
||||
async function start() {
|
||||
// console.log('ffffffffffffffffffffffffffffffffffffffffff')
|
||||
if (getToken()) {
|
||||
await userStore.getMyInfo()
|
||||
await walletStore.getLimitedPrice()
|
||||
await walletStore.getLimitedBuyGold()
|
||||
await fundStore.getMyFund()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export function setTruth() {
|
||||
fingerPosition = true
|
||||
}
|
||||
|
||||
export function setEnableAuthenticate() {
|
||||
fingerPosition = false
|
||||
}
|
||||
|
||||
|
||||
function goToLogin(to: RouteLocationNormalized, next: NavigationGuardNext) {
|
||||
if (to.name !== 'login') {
|
||||
return next({ name: 'login' }) // Redirect to login
|
||||
} else {
|
||||
return next() // If already on the login page, don't redirect
|
||||
}
|
||||
}
|
||||
|
||||
function goToHome(to: RouteLocationNormalized, next: NavigationGuardNext) {
|
||||
if (to.name !== 'home') {
|
||||
return next({ name: 'home' }) // Redirect to login
|
||||
} else {
|
||||
return next() // If already on the login page, don't redirect
|
||||
}
|
||||
}
|
||||
|
||||
export function setFingerPosition(val) {
|
||||
fingerPosition = val
|
||||
}
|
||||
|
||||
export function setFingerTimeOut(to: RouteLocationNormalized){
|
||||
timeoutId = setTimeout(async () => {
|
||||
if (hasFingerPrint) {
|
||||
fingerPosition = false
|
||||
// console.log('Fingerprint authentication reset after 5 seconds of inactivity');
|
||||
await router.push({ name: 'login' })
|
||||
if (to.name !== 'login') {
|
||||
message.warn('شما مدت زیادی با گلد دات آی آر کار نکردید، لطفا دوباره وارد شوید.')
|
||||
}
|
||||
}
|
||||
}, 10000) // 3 minutess
|
||||
}
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// Set loading state to true
|
||||
authStore.setLoading(true)
|
||||
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId)
|
||||
}
|
||||
|
||||
setFingerTimeOut(to)
|
||||
|
||||
if (isFirst) {
|
||||
isFirst = false
|
||||
|
||||
if (getToken()) {
|
||||
const finger_print = getIsActiveFingerprint()
|
||||
hasFingerPrint = finger_print
|
||||
|
||||
if (isApple && finger_print) {
|
||||
removeToken()
|
||||
authStore.setLoading(false) // Remove loading
|
||||
return goToLogin(to, next)
|
||||
} else if (!isApple && finger_print) {
|
||||
// fingerPosition = await authenticateWithFingerprint();
|
||||
return goToLogin(to, next)
|
||||
/!* authStore.setLoading(false); // Remove loading
|
||||
if (fingerPosition) {
|
||||
return goToHome(to, next);
|
||||
} else {
|
||||
return goToLogin(to, next);
|
||||
}*!/
|
||||
} else {
|
||||
authStore.setLoading(false) // Remove loading
|
||||
return next()
|
||||
}
|
||||
} else {
|
||||
authStore.setLoading(false) // Remove loading
|
||||
if (['login', '404'].includes(to.name)) {
|
||||
return next()
|
||||
}
|
||||
return goToLogin(to, next)
|
||||
}
|
||||
} else {
|
||||
authStore.setLoading(false) // Remove loading
|
||||
if (fingerPosition) {
|
||||
if(getIsActiveFingerprint()){
|
||||
hasFingerPrint = true
|
||||
}
|
||||
if (getToken()) {
|
||||
if (to.name === 'login') {
|
||||
return goToHome(to, next)
|
||||
}
|
||||
return next()
|
||||
} else {
|
||||
if (['login', '404'].includes(to.name)) {
|
||||
return next()
|
||||
}
|
||||
return next({ name: 'login' })
|
||||
}
|
||||
} else {
|
||||
if (getToken() && !hasFingerPrint) {
|
||||
return next()
|
||||
} else {
|
||||
return goToLogin(to, next)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
app.mount('#app')
|
||||
// if (currentRoute.value !== '/') {
|
||||
// await start()
|
||||
// }
|
||||
watch(currentRoute, async () => userStore.userInfo ? '' : await start())*/
|
||||
Reference in New Issue
Block a user