ffplayout/pages/index.vue

157 lines
5.5 KiB
Vue
Raw Normal View History

2020-01-29 11:40:15 -05:00
<template>
2024-04-08 03:35:31 -04:00
<div class="w-full min-h-screen xs:h-full flex justify-center items-center">
2024-04-16 08:07:50 -04:00
<div v-if="authStore.isLogin" class="flex flex-wrap justify-center text-center w-full max-w-[1024px] p-5">
2024-04-04 17:28:25 -04:00
<SystemStats v-if="configStore.configGui.length > 0" />
2024-04-11 15:34:03 -04:00
<div class="flex flex-wrap justify-center gap-1 md:gap-0 md:join mt-5">
<NuxtLink :to="localePath({ name: 'player' })" class="btn join-item btn-primary px-2">
{{ $t('button.player') }}
</NuxtLink>
<NuxtLink :to="localePath({ name: 'media' })" class="btn join-item btn-primary px-2">
2024-04-11 15:34:03 -04:00
{{ $t('button.media') }}
</NuxtLink>
<NuxtLink :to="localePath({ name: 'message' })" class="btn join-item btn-primary px-2">
2024-04-11 15:34:03 -04:00
{{ $t('button.message') }}
</NuxtLink>
<NuxtLink :to="localePath({ name: 'logging' })" class="btn join-item btn-primary px-2">
2024-04-11 15:34:03 -04:00
{{ $t('button.logging') }}
</NuxtLink>
2024-04-08 03:35:31 -04:00
<NuxtLink
v-if="authStore.role.toLowerCase() == 'admin'"
2024-04-11 15:34:03 -04:00
:to="localePath({ name: 'configure' })"
class="btn join-item btn-primary px-2"
2024-04-08 03:35:31 -04:00
>
2024-04-11 15:34:03 -04:00
{{ $t('button.configure') }}
2024-04-04 17:28:25 -04:00
</NuxtLink>
2024-04-11 15:34:03 -04:00
<button class="btn join-item btn-primary px-2" @click="logout()">
{{ $t('button.logout') }}
</button>
<select
v-model="selectedLang"
2024-04-16 12:13:28 -04:00
class="select select-primary select-bordered join-item max-w-xs ps-2"
2024-04-11 15:34:03 -04:00
@change="changeLang(selectedLang)"
>
<option v-for="(loc, index) in locales" :key="index" :value="/* @ts-ignore */ loc.code">
{{
/* @ts-ignore */
loc.name
}}
</option>
</select>
<label class="join-item btn btn-primary swap swap-rotate me-2">
<input type="checkbox" :checked="indexStore.darkMode" @change="toggleDarkTheme" />
2024-04-09 15:08:25 -04:00
<SvgIcon name="swap-on" classes="w-5 h-5" />
<SvgIcon name="swap-off" classes="w-5 h-5" />
</label>
2023-01-11 04:54:25 -05:00
</div>
</div>
2024-04-08 03:35:31 -04:00
<div v-else class="w-96 min-w-full flex flex-col justify-center items-center px-4">
<h1 class="text-6xl xs:text-8xl">ffplayout</h1>
2024-04-04 17:28:25 -04:00
<form class="mt-10" @submit.prevent="login">
<input
v-model="formUsername"
2024-04-16 12:13:28 -04:00
type="text"
2024-04-11 15:34:03 -04:00
:placeholder="$t('input.username')"
2024-04-04 17:28:25 -04:00
class="input input-bordered w-full"
required
/>
2024-04-04 17:28:25 -04:00
<input
v-model="formPassword"
2024-04-16 12:13:28 -04:00
type="password"
2024-04-11 15:34:03 -04:00
:placeholder="$t('input.password')"
2024-04-04 17:28:25 -04:00
class="input input-bordered w-full mt-5"
required
/>
2024-04-04 17:28:25 -04:00
<div class="w-full mt-4 grid grid-flow-row-dense grid-cols-12 grid-rows-1 gap-2">
<div class="col-span-3">
2024-04-11 15:34:03 -04:00
<button type="submit" class="btn btn-primary">
{{ $t('button.login') }}
</button>
2024-04-04 17:28:25 -04:00
</div>
<div class="col-span-12 sm:col-span-9">
<div
v-if="showLoginError"
role="alert"
2024-04-09 15:08:25 -04:00
class="alert alert-error w-auto rounded z-2 h-12 p-[0.7rem]"
2024-04-04 17:28:25 -04:00
>
2024-04-09 15:08:25 -04:00
<SvgIcon name="error" />
2024-04-04 17:28:25 -04:00
<span>{{ formError }}</span>
2023-01-11 04:54:25 -05:00
</div>
2024-04-04 17:28:25 -04:00
</div>
2023-01-11 04:54:25 -05:00
</div>
2024-04-04 17:28:25 -04:00
</form>
2020-01-29 11:40:15 -05:00
</div>
</div>
2020-01-29 11:40:15 -05:00
</template>
2023-01-11 04:54:25 -05:00
<script setup lang="ts">
const colorMode = useColorMode()
2024-04-11 15:34:03 -04:00
const { locale, locales, t } = useI18n()
const localePath = useLocalePath()
const switchLocalePath = useSwitchLocalePath()
const router = useRouter()
2023-01-11 04:54:25 -05:00
const authStore = useAuth()
const configStore = useConfig()
const indexStore = useIndex()
2023-01-11 04:54:25 -05:00
2024-04-11 15:34:03 -04:00
const selectedLang = ref(locale)
2023-01-11 04:54:25 -05:00
const formError = ref('')
2024-04-04 17:28:25 -04:00
const showLoginError = ref(false)
2023-01-11 04:54:25 -05:00
const formUsername = ref('')
const formPassword = ref('')
authStore.inspectToken()
async function login() {
try {
const status = await authStore.obtainToken(formUsername.value, formPassword.value)
formUsername.value = ''
formPassword.value = ''
formError.value = ''
if (status === 401 || status === 400 || status === 403) {
2024-04-11 15:34:03 -04:00
formError.value = t('alert.wrongLogin')
2024-04-04 17:28:25 -04:00
showLoginError.value = true
setTimeout(() => {
showLoginError.value = false
}, 3000)
2020-01-29 11:40:15 -05:00
}
2023-01-11 04:54:25 -05:00
await configStore.nuxtClientInit()
} catch (e) {
formError.value = e as string
}
}
function toggleDarkTheme() {
indexStore.darkMode = !indexStore.darkMode
if (indexStore.darkMode) {
colorMode.preference = 'dark'
} else {
colorMode.preference = 'light'
}
}
2023-01-11 04:54:25 -05:00
async function logout() {
try {
authStore.removeToken()
} catch (e) {
formError.value = e as string
2020-01-29 11:40:15 -05:00
}
}
2024-04-11 15:34:03 -04:00
async function changeLang(code: string) {
const path = switchLocalePath(code)
const cookie = useCookie('i18n_redirected')
cookie.value = code
router.push(path)
}
2020-01-29 11:40:15 -05:00
</script>