This commit is contained in:
2025-05-04 22:22:20 +03:00
parent cda54b1e95
commit ebd77a3e66
54 changed files with 1194 additions and 2580 deletions

View File

@@ -4,23 +4,34 @@
<script setup lang="ts">
import { inject, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import type { WebApp } from '@twa-dev/types'
import { useTextSizeStore } from './stores/textSize'
import { useI18n } from 'vue-i18n'
const { locale } = useI18n()
const router = useRouter()
const tg = inject('tg') as WebApp
tg.onEvent('settingsButtonClicked', async () => {
await router.push({ name: 'settings' })
})
const getLocale = (): string => {
const localeMap = {
ru: 'ru-RU',
en: 'en-US'
} as const satisfies Record<string, string>
const textSizeStore = useTextSizeStore()
onMounted(async () => {
try {
await textSizeStore.initialize()
} catch (err) {
console.error('Error load font size:', err)
type LocaleCode = keyof typeof localeMap
const normLocale = (locale?: string): string | undefined => {
if (!locale) return undefined
const code = locale.split('-')[0] as LocaleCode
return localeMap[code] ?? undefined
}
const tgLang = tg?.initDataUnsafe?.user?.language_code
const normalizedTgLang = normLocale(tgLang)
return normalizedTgLang ?? normLocale(navigator.language) ?? 'en-US'
}
})
onMounted(() => {
locale.value = getLocale()
})
</script>

View File

@@ -1,6 +1,5 @@
import { defineBoot } from '#q-app/wrappers'
import axios, { type AxiosError } from 'axios'
import { useAuthStore } from 'src/stores/auth'
class ServerError extends Error {
constructor(
@@ -30,10 +29,6 @@ api.interceptors.response.use(
errorData.message
)
if (error.response?.status === 401) {
await useAuthStore().logout()
}
return Promise.reject(serverError)
}
)
@@ -42,4 +37,4 @@ export default defineBoot(({ app }) => {
app.config.globalProperties.$api = api
})
export { api, ServerError }
export { api, ServerError }

View File

@@ -1,33 +1,73 @@
export function isObjEqual (obj1: Record<string, string | number | boolean>, obj2: Record<string, string | number | boolean>): boolean {
const filteredObj1 = filterIgnored(obj1)
const filteredObj2 = filterIgnored(obj2)
function isDirty (
obj1: Record<string, unknown> | null | undefined,
obj2: Record<string, unknown> | null | undefined
): boolean {
const actualObj1 = obj1 ?? {}
const actualObj2 = obj2 ?? {}
const filteredObj1 = filterIgnored(actualObj1)
const filteredObj2 = filterIgnored(actualObj2)
const allKeys = new Set([...Object.keys(filteredObj1), ...Object.keys(filteredObj2)])
for (const key of allKeys) {
const hasKey1 = Object.prototype.hasOwnProperty.call(filteredObj1, key)
const hasKey2 = Object.prototype.hasOwnProperty.call(filteredObj2, key)
const hasKey1 = Object.hasOwn(filteredObj1, key)
const hasKey2 = Object.hasOwn(filteredObj2, key)
if (hasKey1 !== hasKey2) return false
if (hasKey1 && hasKey2 && filteredObj1[key] !== filteredObj2[key]) return false
if (hasKey1 && hasKey2) {
const val1 = filteredObj1[key]
const val2 = filteredObj2[key]
if (typeof val1 === 'string' && typeof val2 === 'string') {
if (val1.trim() !== val2.trim()) return false
} else if (val1 !== val2) {
return false
}
}
}
return true
}
function filterIgnored(obj: Record<string, string | number | boolean>): Record<string, string | number | boolean> {
function filterIgnored(obj: Record<string, unknown>): Record<string, string | number | boolean> {
const filtered: Record<string, string | number | boolean> = {}
for (const key in obj) {
const value = obj[key]
if (value !== "" && value !== 0 && value !== false) filtered[key] = value
const originalValue = obj[key]
// Пропускаем значения, которые не string, number или boolean
if (
typeof originalValue !== 'string' &&
typeof originalValue !== 'number' &&
typeof originalValue !== 'boolean'
) {
continue
}
let value = originalValue
if (typeof value === 'string') {
value = value.trim()
if (value === '') continue
}
if (value === 0 || value === false) continue
filtered[key] = value
}
return filtered
}
export function parseIntString (s: string | string[] | undefined) :number | null {
function parseIntString (s: string | string[] | undefined) :number | null {
if (typeof s !== 'string') return null
const regex = /^[+-]?\d+$/
return regex.test(s) ? Number(s) : null
}
export {
isDirty,
parseIntString
}

View File

@@ -1,11 +1,11 @@
import { defineBoot } from '#q-app/wrappers';
import { createI18n } from 'vue-i18n';
import { defineBoot } from '#q-app/wrappers'
import { createI18n } from 'vue-i18n'
import messages from 'src/i18n';
import messages from 'src/i18n'
export type MessageLanguages = keyof typeof messages;
export type MessageLanguages = keyof typeof messages
// Type-define 'en-US' as the master schema for the resource
export type MessageSchema = typeof messages['en-US'];
export type MessageSchema = typeof messages['en-US']
// See https://vue-i18n.intlify.dev/guide/advanced/typescript.html#global-resource-schema-type-definition
/* eslint-disable @typescript-eslint/no-empty-object-type */
@@ -26,8 +26,8 @@ export default defineBoot(({ app }) => {
locale: 'en-US',
legacy: false,
messages,
});
})
// Set i18n instance on app
app.use(i18n);
});
app.use(i18n)
})

View File

@@ -13,7 +13,7 @@
tgUser?.first_name +
(tgUser?.first_name && tgUser?.last_name ? ' ' : '') +
tgUser?.last_name +
!(tgUser?.first_name || tgUser?.last_name) ? tgUser?.username : ''
(!(tgUser?.first_name || tgUser?.last_name) ? tgUser?.username : '')
}}
</span>
</div>

View File

@@ -12,23 +12,27 @@
no-error-icon
dense
filled
label-slot
class = "w100 fix-bottom-padding"
:label="$t('project_card__project_name')"
:rules="[rules.name]"
/>
>
<template #label>
{{ $t('project_card__project_name') }} <span class="text-red">*</span>
</template>
</q-input>
<q-input
v-model="modelValue.description"
dense
filled
autogrow
class="w100"
class="w100 q-pt-sm"
:label="$t('project_card__project_description')"
/>
<q-checkbox
v-if="modelValue.logo"
v-model="modelValue.logo_as_bg"
v-model="modelValue.is_logo_bg"
class="w100"
dense
>
@@ -41,7 +45,7 @@
<script setup lang="ts">
import { watch, computed } from 'vue'
import type { ProjectParams } from 'src/types'
import type { ProjectParams } from 'types/Project'
import { useI18n } from 'vue-i18n'
const { t }= useI18n()
@@ -68,7 +72,7 @@
</script>
<style>
.q-field--with-bottom.fix-bottom-padding {
padding-bottom: 0 !important
}
.q-field--with-bottom.fix-bottom-padding {
padding-bottom: 0 !important
}
</style>

View File

@@ -0,0 +1,22 @@
import { useQuasar } from 'quasar'
import { useI18n } from 'vue-i18n'
import type { ServerError } from 'boot/axios'
export type { ServerError }
export function useNotify() {
const $q = useQuasar()
const { t } = useI18n()
const notifyError = (error: ServerError) => {
$q.notify({
message: `${t(error.message)} (${t('code')}: ${error.code})`,
type: 'negative',
position: 'bottom',
timeout: 2000,
multiLine: true
})
}
return { notifyError}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -4,7 +4,6 @@
<div class="flex items-center no-wrap w100">
<pn-account-block-name/>
<q-btn
v-if="user?.email"
@click="logout()"
flat
round
@@ -53,7 +52,6 @@
const router = useRouter()
const authStore = useAuthStore()
const user = authStore.user
const items = computed(() => ([
{ id: 1, name: 'account__subscribe', description: 'account__subscribe_description', icon: 'mdi-crown-circle-outline', iconColor: 'orange', pathName: 'subscribe' },
@@ -73,6 +71,7 @@
async function logout () {
await authStore.logout()
await router.push({ name: 'login' })
}
</script>

View File

@@ -1,10 +1,11 @@
<template>
<q-page class="flex column items-center justify-center">
<q-page class="flex column items-center justify-between">
<div :style="{ height: `${blockHeight}px` }" />
<q-card
id="login_block"
flat
class="flex column items-center w80 justify-between q-py-lg login-card "
class="flex column items-center w80 justify-between q-py-md login-card "
>
<login-logo
class="col-grow q-pa-md"
@@ -88,30 +89,35 @@
<div
v-if="isTelegramApp"
id="alt_login"
class="w80 q-flex column items-center q-pt-xl"
class="w80 q-flex column items-center q-pt-md"
>
<div
class="orline w100 text-grey"
>
<span class="q-mx-sm">{{$t('login__or_continue_as')}}</span>
<span class="q-mx-sm text-caption">{{$t('login__or_continue_as')}}</span>
</div>
<q-btn
flat
sm
no-caps
color="primary"
:disabled="!acceptTermsOfUse || !isEmailValid || !isPasswordValid"
:disabled="!acceptTermsOfUse"
@click="handleTelegramLogin"
>
<div class="flex items-center text-blue">
<q-icon name="telegram" size="md" class="q-mx-none text-blue"/>
<div class="q-ml-xs ellipsis" style="max-width: 100px">
<q-avatar size="md" class="q-mr-sm">
<q-img v-if="tgUser?.photo_url" :src="tgUser.photo_url"/>
<q-icon v-else size="md" class="q-mr-none" name="telegram"/>
</q-avatar>
<span>
{{
tgUser?.first_name +
(tgUser?.first_name && tgUser?.last_name ? ' ' : '') +
tgUser?.last_name
tgUser?.first_name +
(tgUser?.first_name && tgUser?.last_name ? ' ' : '') +
tgUser?.last_name +
(!(tgUser?.first_name || tgUser?.last_name) ? tgUser?.username : '')
}}
</div>
</span>
</div>
</q-btn>
</div>
@@ -119,8 +125,10 @@
<div
id="term-of-use"
class="absolute-bottom q-py-lg text-white flex justify-center row"
class="q-pb-md text-white flex justify-center row text-caption"
ref="bottomBlock"
>
<q-resize-observer @resize="syncHeights" />
<q-checkbox
v-model="acceptTermsOfUse"
checked-icon="task_alt"
@@ -128,6 +136,7 @@
:color="acceptTermsOfUse ? 'brand' : 'red'"
dense
keep-color
size="sm"
/>
<span class="q-px-xs">
{{ $t('login__accept_terms_of_use') + ' ' }}
@@ -144,14 +153,14 @@
<script setup lang="ts">
import { ref, computed, inject, onUnmounted } from 'vue'
import { useQuasar } from 'quasar'
import { useRouter } from 'vue-router'
import loginLogo from 'components/login-page/loginLogo.vue'
import { useI18n } from "vue-i18n"
import { useAuthStore } from 'src/stores/auth'
import { useAuthStore } from 'stores/auth'
import type { WebApp } from '@twa-dev/types'
import { QInput } from 'quasar'
import type { ServerError } from 'boot/axios'
import { useNotify, type ServerError } from 'composables/useNotify'
const { notifyError } = useNotify()
type ValidationRule = (val: string) => boolean | string
@@ -160,7 +169,6 @@
const authStore = useAuthStore()
const router = useRouter()
const $q = useQuasar()
const { t } = useI18n()
const login = ref<string>('')
@@ -168,6 +176,9 @@
const isPwd = ref<boolean>(true)
const acceptTermsOfUse = ref<boolean>(true)
const bottomBlock = ref<HTMLDivElement | null>(null)
const blockHeight = ref<number>(0)
const emailInput = ref<InstanceType<typeof QInput>>()
const passwordInput = ref<InstanceType<typeof QInput>>()
@@ -203,32 +214,21 @@
if (validateTimerId.value[type] !== null) {
clearTimeout(validateTimerId.value[type])
}
if (type === 'login') await emailInput.value?.validate()
if (type === 'password') await passwordInput.value?.validate()
if (type === 'login' && login.value !== '') await emailInput.value?.validate()
if (type === 'password' && password.value !== '') await passwordInput.value?.validate()
})()
}, 300)
}
function onErrorLogin (error: ServerError) {
$q.notify({
message: t(error.message) + ' (' + t('code') + ':' + error.code + ')',
type: 'negative',
position: 'bottom',
timeout: 2000,
multiLine: true
})
}, 500)
}
async function sendAuth() {
try { void await authStore.loginWithCredentials(login.value, password.value) }
catch (error) {
console.log(error)
onErrorLogin(error as ServerError)
notifyError(error as ServerError)
}
await router.push({ name: 'projects' })
}
async function forgotPwd() {
sessionStorage.setItem('pendingLogin', login.value)
await router.push({ name: 'recovery_password' })
@@ -244,19 +244,22 @@
return !!window.Telegram?.WebApp?.initData
})
/* const handleSubmit = async () => {
await authStore.loginWithCredentials(email.value, password.value)
} */
async function handleTelegramLogin () {
// @ts-expect-ignore
const initData = window.Telegram.WebApp.initData
await authStore.loginWithTelegram(initData)
await router.push({ name: 'projects' })
}
async function handleTelegramLogin () {
// @ts-expect-ignore
const initData = window.Telegram.WebApp.initData
await authStore.loginWithTelegram(initData)
}
function syncHeights() {
if (bottomBlock.value) {
blockHeight.value = bottomBlock.value.offsetHeight
}
}
onUnmounted(() => {
Object.values(validateTimerId.value).forEach(timer => timer && clearTimeout(timer))
})
onUnmounted(() => {
Object.values(validateTimerId.value).forEach(timer => timer && clearTimeout(timer))
})
</script>

View File

@@ -25,10 +25,11 @@
<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import projectInfoBlock from 'src/components/projectInfoBlock.vue'
import projectInfoBlock from 'components/projectInfoBlock.vue'
import { useProjectsStore } from 'stores/projects'
import type { ProjectParams } from 'src/types'
import type { ProjectParams } from 'types/Project'
import { useNotify, type ServerError } from 'composables/useNotify'
const { notifyError } = useNotify()
const router = useRouter()
const projectsStore = useProjectsStore()
@@ -37,7 +38,7 @@
name: '',
logo: '',
description: '',
logo_as_bg: false
is_logo_bg: false
}
const project = ref<ProjectParams>({ ...initialProject })
@@ -48,14 +49,18 @@
project.value.name !== initialProject.name ||
project.value.logo !== initialProject.logo ||
project.value.description !== initialProject.description ||
project.value.logo_as_bg !== initialProject.logo_as_bg
project.value.is_logo_bg !== initialProject.is_logo_bg
)
})
async function addProject (data: ProjectParams) {
const newProject = await projectsStore.addProject(data)
// await router.push({name: 'chats', params: { id: newProject.id}})
console.log(newProject)
try {
const newProject = await projectsStore.add(data)
await router.replace({ name: 'chats', params: { id: newProject.id }})
console.log(newProject)
} catch (error) {
notifyError(error as ServerError)
}
}
</script>

View File

@@ -6,7 +6,7 @@
<span>{{ $t('project_card__project_card') }}</span>
</div>
<q-btn
v-if="isFormValid && isDirty()"
v-if="isFormValid && (!isDirty(originalProject, project))"
@click="updateProject()"
flat
round
@@ -29,39 +29,33 @@
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useProjectsStore } from 'stores/projects'
import projectInfoBlock from 'src/components/projectInfoBlock.vue'
import type { Project } from '../types'
import { parseIntString, isObjEqual } from 'boot/helpers'
import projectInfoBlock from 'components/projectInfoBlock.vue'
import { parseIntString, isDirty } from 'boot/helpers'
import type { ProjectParams } from 'types/Project'
const router = useRouter()
const route = useRoute()
const projectsStore = useProjectsStore()
const project = ref<Project>()
const project = ref<ProjectParams>()
const originalProject = ref<ProjectParams>()
const id = parseIntString(route.params.id)
const isFormValid = ref(false)
const originalProject = ref<Project>({} as Project)
const isDirty = () => {
return true // project.value && !isObjEqual(originalProject.value, project.value)
}
onMounted(async () => {
if (id && projectsStore.projectById(id)) {
const initial = projectsStore.projectById(id)
project.value = { ...initial } as Project
originalProject.value = JSON.parse(JSON.stringify(project.value))
project.value = { ...initial } as ProjectParams
originalProject.value = {...project.value}
} else {
await abort()
}
})
function updateProject () {
async function updateProject () {
if (id && project.value) {
projectsStore.updateProject(id, project.value)
await projectsStore.update(id, project.value)
router.back()
}
}

View File

@@ -63,11 +63,11 @@
<div class="flex items-center column">
<div class="flex items-center">
<q-icon name="mdi-chat-outline"/>
<span>{{ item.chats }} </span>
<span>{{ item.chat_count }} </span>
</div>
<div class="flex items-center">
<q-icon name="mdi-account-outline"/>
<span>{{ item.persons }}</span>
<span>{{ item.user_count }}</span>
</div>
</div>
</q-item-section>
@@ -113,10 +113,16 @@
class="flex w100 column q-pt-xl q-pa-md"
>
<div class="flex column justify-center col-grow items-center text-grey">
<q-icon name="mdi-briefcase-plus-outline" size="160px" class="q-pb-md"/>
<div class="text-h6">
{{$t('projects__lets_start')}}
</div>
<q-btn flat no-caps @click="createNewProject">
<div class="flex column justify-center col-grow items-center">
<q-icon name="mdi-briefcase-plus-outline" size="160px" class="q-pb-md"/>
<div class="text-h6 text-brand">
{{$t('projects__lets_start')}}
</div>
</div>
</q-btn>
<div class="text-caption" align="center">
{{$t('projects__lets_start_description')}}
</div>
@@ -169,9 +175,12 @@
import { ref, computed, watch, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useProjectsStore } from 'stores/projects'
import { useSettingsStore } from 'stores/settings'
import type { Project } from 'types/Project'
const router = useRouter()
const projectsStore = useProjectsStore()
const settingsStore = useSettingsStore()
const projects = projectsStore.projects
const searchProject = ref('')
@@ -197,20 +206,14 @@
}
function restoreFromArchive () {
if (archiveProjectId.value) {
const projectTemp = projectsStore.projectById(archiveProjectId.value)
if (projectTemp) {
projectTemp.is_archive = false
projectsStore.updateProject(archiveProjectId.value, projectTemp)
}
}
if (archiveProjectId.value) projectsStore.restore(archiveProjectId.value)
}
const displayProjects = computed(() => {
if (!searchProject.value || !(searchProject.value && searchProject.value.trim())) return projects
const searchChatValue = searchProject.value.trim().toLowerCase()
const arrOut = projects
.filter(el =>
.filter((el: Project) =>
el.name.toLowerCase().includes(searchChatValue) ||
el.description && el.description.toLowerCase().includes(searchProject.value)
)
@@ -218,17 +221,20 @@
})
const activeProjects = computed(() => {
return displayProjects.value.filter(el => !el.is_archive)
return displayProjects.value.filter((el: Project) => !el.is_archived)
})
const archiveProjects = computed(() => {
return displayProjects.value.filter(el => el.is_archive)
return displayProjects.value.filter((el: Project) => el.is_archived)
})
onMounted(async () => {
if (!projectsStore.isInit) {
await projectsStore.init()
}
if (!settingsStore.isInit) {
await settingsStore.init()
}
})
watch(showDialogArchive, (newD :boolean) => {

View File

@@ -40,18 +40,18 @@
<q-item-section>
<div class="flex justify-end">
<q-btn
@click="textSizeStore.decreaseFontSize()"
@click="settingsStore.decreaseFontSize()"
color="negative" flat
icon="mdi-format-font-size-decrease"
class="q-pa-sm q-mx-xs"
:disable="currentTextSize <= minTextSize"
:disable="!settingsStore.canDecrease"
/>
<q-btn
@click="textSizeStore.increaseFontSize()"
@click="settingsStore.increaseFontSize()"
color="positive" flat
icon="mdi-format-font-size-increase"
class="q-pa-sm q-mx-xs"
:disable="currentTextSize >= maxTextSize"
:disable="!settingsStore.canIncrease"
/>
</div>
</q-item-section>
@@ -62,28 +62,22 @@
</template>
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { watch, ref } from 'vue'
import { useTextSizeStore } from 'src/stores/textSize'
const { locale } = useI18n()
const savedLocale = localStorage.getItem('locale') || 'en-US'
locale.value = savedLocale
import { ref, computed } from 'vue'
import { useSettingsStore } from 'stores/settings'
const localeOptions = ref([
{ value: 'en-US', label: 'English' },
{ value: 'ru-RU', label: 'Русский' }
])
watch(locale, (newLocale) => {
localStorage.setItem('locale', newLocale)
const locale = computed({
get: () => settingsStore.settings.locale,
// eslint-disable-next-line @typescript-eslint/no-misused-promises
set: (value: string) => settingsStore.updateLocale(value)
})
const textSizeStore = useTextSizeStore()
const currentTextSize = textSizeStore.currentFontSize
const maxTextSize = textSizeStore.maxFontSize
const minTextSize = textSizeStore.minFontSize
const settingsStore = useSettingsStore()
</script>
<style scoped>

View File

@@ -71,20 +71,12 @@
<q-card class="q-pa-none q-ma-none">
<q-card-section align="center">
<div class="text-h6 text-negative ">
{{ $t(
dialogType === 'archive'
? 'project__archive_warning'
: 'project__delete_warning'
)}}
{{ $t('project__archive_warning')}}
</div>
</q-card-section>
<q-card-section class="q-pt-none" align="center">
{{ $t(
dialogType === 'archive'
? 'project__archive_warning_message'
: 'project__delete_warning_message'
)}}
{{ $t('project__archive_warning_message')}}
</q-card-section>
<q-card-actions align="center">
@@ -96,14 +88,10 @@
/>
<q-btn
flat
:label="$t(
dialogType === 'archive'
? 'project__archive'
: 'project__delete'
)"
:label="$t('project__archive')"
color="negative"
v-close-popup
@click="dialogType === 'archive' ? archiveProject() : deleteProject()"
@click="archiveProject"
/>
</q-card-actions>
</q-card>
@@ -122,22 +110,22 @@
const expandProjectInfo = ref<boolean>(false)
const showDialog = ref<boolean>(false)
const dialogType = ref<null | 'archive' | 'delete'>(null)
const dialogType = ref<null | 'archive'>(null)
const headerHeight = ref<number>(0)
const menuItems = [
{ id: 1, title: 'project__edit', icon: 'mdi-square-edit-outline', iconColor: '', func: editProject },
// { id: 2, title: 'project__backup', icon: 'mdi-content-save-outline', iconColor: '', func: () => {} },
{ id: 3, title: 'project__archive', icon: 'mdi-archive-outline', iconColor: '', func: () => { showDialog.value = true; dialogType.value = 'archive' }},
{ id: 4, title: 'project__delete', icon: 'mdi-trash-can-outline', iconColor: 'red', func: () => { showDialog.value = true; dialogType.value = 'delete' }},
{ id: 3, title: 'project__archive', icon: 'mdi-archive-outline', iconColor: 'red', func: () => { showDialog.value = true; dialogType.value = 'archive' }}
]
const projectId = computed(() => parseIntString(route.params.id))
const project =ref({
name: '',
description: '',
logo: ''
logo: '',
is_logo_bg: false
})
const loadProjectData = async () => {
@@ -154,7 +142,8 @@
project.value = {
name: projectFromStore.name,
description: projectFromStore.description || '',
logo: projectFromStore.logo || ''
logo: projectFromStore.logo || '',
is_logo_bg: projectFromStore.is_logo_bg || false
}
}
}
@@ -164,15 +153,13 @@ async function abort () {
}
async function editProject () {
if (projectId.value) void projectsStore.update(projectId.value, project.value)
await router.push({ name: 'project_info' })
}
function archiveProject () {
console.log('archive project')
}
function deleteProject () {
console.log('delete project')
async function archiveProject () {
if (projectId.value) void projectsStore.archive(projectId.value)
await router.replace({ name: 'projects' })
}
function toggleExpand () {

View File

@@ -8,10 +8,10 @@ import {
import routes from './routes'
import { useAuthStore } from 'stores/auth'
import { useProjectsStore } from 'stores/projects'
const tg = window.Telegram?.WebApp
declare module 'vue-router' {
interface RouteMeta {
public?: boolean
guestOnly?: boolean
hideBackButton?: boolean
backRoute?: string
@@ -32,29 +32,14 @@ export default defineRouter(function (/* { store, ssrContext } */) {
history: createHistory(process.env.VUE_ROUTER_BASE)
})
Router.beforeEach(async (to) => {
Router.beforeEach((to) => {
const authStore = useAuthStore()
if (!authStore.isInitialized) {
await authStore.initialize()
}
if (to.meta.guestOnly && authStore.isAuthenticated) {
if (to.meta.guestOnly && authStore.isAuth) {
return { name: 'projects' }
}
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
return {
name: 'login',
replace: true
}
}
if (to.meta.public) {
return true
}
if (!to.meta.public && !authStore.isAuthenticated) {
if (to.meta.requiresAuth && !authStore.isAuth) {
return {
name: 'login',
replace: true
@@ -67,17 +52,19 @@ export default defineRouter(function (/* { store, ssrContext } */) {
if (currentRoute.meta.backRoute) {
await Router.push({ name: currentRoute.meta.backRoute })
} else {
if (window.history.length > 1) Router.go(-1)
if (window.history.length > 1) Router.go(-1)
else await Router.push({ name: 'projects' })
}
}
Router.afterEach((to) => {
const BackButton = window.Telegram?.WebApp?.BackButton
if (BackButton) {
BackButton[to.meta.hideBackButton ? 'hide' : 'show']()
BackButton.offClick(handleBackButton as () => void)
BackButton.onClick(handleBackButton as () => void)
if (tg) {
const BackButton = tg?.BackButton
if (BackButton) {
BackButton[to.meta.hideBackButton ? 'hide' : 'show']()
BackButton.offClick(handleBackButton as () => void)
BackButton.onClick(handleBackButton as () => void)
}
}
if (!to.params.id) {

View File

@@ -111,10 +111,7 @@ const routes: RouteRecordRaw[] = [
name: 'create_account',
path: '/create-account',
component: () => import('src/pages/AccountCreatePage.vue'),
meta: {
public: true,
guestOnly: true
}
meta: { guestOnly: true }
},
{
name: 'change_account_password',
@@ -138,13 +135,11 @@ const routes: RouteRecordRaw[] = [
name: 'terms',
path: '/terms-of-use',
component: () => import('pages/TermsPage.vue'),
meta: { public: true }
},
{
name: 'privacy',
path: '/privacy',
component: () => import('pages/PrivacyPage.vue'),
meta: { public: true }
},
{
name: 'your_company',
@@ -157,18 +152,15 @@ const routes: RouteRecordRaw[] = [
path: '/login',
component: () => import('pages/LoginPage.vue'),
meta: {
public: true,
guestOnly: true
hideBackButton: true,
guestOnly: true
}
},
{
name: 'recovery_password',
path: '/recovery-password',
component: () => import('src/pages/AccountForgotPasswordPage.vue'),
meta: {
public: true,
guestOnly: true
}
meta: { guestOnly: true }
},
{
name: 'add_company',
@@ -187,7 +179,6 @@ const routes: RouteRecordRaw[] = [
{
path: '/:catchAll(.*)*',
component: () => import('pages/ErrorNotFound.vue'),
meta: { public: true }
}
]

View File

@@ -12,7 +12,7 @@ interface User {
}
const ENDPOINT_MAP = {
register: '/auth/register',
register: '/auth/email/register',
forgot: '/auth/forgot',
change: '/auth/change'
} as const
@@ -23,46 +23,33 @@ export const useAuthStore = defineStore('auth', () => {
const user = ref<User | null>(null)
const isInitialized = ref(false)
const isAuthenticated = computed(() => !!user.value)
const isAuth = computed(() => !!user.value)
const initialize = async () => {
try {
const { data } = await api.get('/customer/profile')
user.value = data.data
} catch (error) {
handleAuthError(error as ServerError)
} finally {
} catch (error) { if (isAuth.value) console.log(error) }
finally {
isInitialized.value = true
}
}
const handleAuthError = (error: ServerError) => {
if (error.code === '401') {
user.value = null
} else {
console.error('Authentication error:', error)
}
}
const loginWithCredentials = async (email: string, password: string) => {
await api.post('/auth/email', { email, password }, { withCredentials: true })
await initialize()
}
const loginWithTelegram = async (initData: string) => {
await api.post('/auth/telegram', { initData }, { withCredentials: true })
await api.post('/auth/telegram?'+ initData, {}, { withCredentials: true })
console.log(initData)
await initialize()
}
const logout = async () => {
try {
await api.get('/auth/logout', {})
user.value = null
isInitialized.value = false
} finally {
// @ts-expect-ignore
// window.Telegram?.WebApp.close()
}
await api.get('/auth/logout', {})
user.value = null
isInitialized.value = false
}
const initRegistration = async (flowType: AuthFlowType, email: string) => {
@@ -84,7 +71,7 @@ export const useAuthStore = defineStore('auth', () => {
return {
user,
isAuthenticated,
isAuth,
isInitialized,
initialize,
loginWithCredentials,

View File

@@ -1,35 +1,18 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { Project, ProjectParams } from '../types'
import { api } from 'boot/axios'
import { clientConverter, serverConverter } from 'types/booleanConvertor'
import type { Project, ProjectParams, RawProject, RawProjectParams } from 'types/Project'
export const useProjectsStore = defineStore('projects', () => {
const projects = ref<Project[]>([])
const currentProjectId = ref<number | null>(null)
const isInit = ref<boolean>(false)
/* projects.value.push(
{ id: 1, name: 'Тестовый проект', description: 'Пример тестового проекта - тут описание чего-то', logo: 'https://cdn.quasar.dev/img/boy-avatar.png', chats: 3, companies: 1, persons: 5, is_archive: false, logo_as_bg: false },
{ id: 2, name: 'Разделка бобра на куски', description: 'Пример тестового проекта - тут описание чего-то', logo: '', chats: 8, companies: 12, persons: 1, is_archive: false, logo_as_bg: false },
{ id: 3, name: 'Комплекс мер', description: '', logo: '', chats: 8, companies: 3, persons: 4, is_archive: true, logo_as_bg: false },
{ id: 4, name: 'Тестовый проект 2', description: 'Пример тестового проекта - тут описание чего-то', logo: '', chats: 12, companies: 11, persons: 15, is_archive: false, logo_as_bg: false },
{ id: 11, name: 'Тестовый проект 12', description: 'Пример тестового проекта - тут описание чего-то', logo: 'https://cdn.quasar.dev/img/boy-avatar.png', chats: 5, companies: 2, persons: 5, is_archive: false, logo_as_bg: false },
{ id: 12, name: 'Разделка бобра на куски 11 Ох как много кусков пипец каааак много - резать тяжело', description: '', logo: '', chats: 8, companies: 3, persons: 1, is_archive: false, logo_as_bg: false },
{ id: 13, name: 'Тестовый проект и что-то еще', description: 'Пример тестового проекта - тут описание чего-то Ох как много кусков пипец каааак много - резать тяжело Ох как много кусков пипец каааак много - резать тяжело', logo: 'https://cdn.quasar.dev/img/mountains.jpg', chats: 8, companies: 3, persons: 4, is_archive: false, logo_as_bg: true },
{ id: 14, name: 'Тестовый проект', description: 'Пример тестового проекта - тут описание чего-то', logo: 'https://cdn.quasar.dev/img/mountains.jpg', chats: 12, companies: 11, persons: 15, is_archive: false, logo_as_bg: false },
{ id: 112, name: 'Разделка бобра на куски 11 Ох как много кусков пипец каааак много - резать тяжело', description: '', logo: '', chats: 8, companies: 3, persons: 1, is_archive: false, logo_as_bg: false},
{ id: 113, name: 'Тестовый проект и что-то еще', description: 'Пример тестового проекта - тут описание чего-то Ох как много кусков пипец каааак много - резать тяжело Ох как много кусков пипец каааак много - резать тяжело', logo: 'https://cdn.quasar.dev/img/mountains.jpg', chats: 8, companies: 3, persons: 4, is_archive: false, logo_as_bg: false },
{ id: 114, name: 'Тестовый проект', description: 'Пример тестового проекта - тут описание чего-то', logo: 'https://cdn.quasar.dev/img/mountains.jpg', chats: 12, companies: 11, persons: 15, is_archive: true, logo_as_bg: false },
{ id: 1112, name: 'Разделка бобра на куски 11 Ох как много кусков пипец каааак много - резать тяжело', description: '', logo: '', chats: 8, companies: 3, persons: 1, is_archive: false, logo_as_bg: false },
{ id: 1113, name: 'Тестовый проект и что-то еще', description: 'Пример тестового проекта - тут описание чего-то Ох как много кусков пипец каааак много - резать тяжело Ох как много кусков пипец каааак много - резать тяжело', logo: 'https://cdn.quasar.dev/img/mountains.jpg', chats: 8, companies: 3, persons: 4, is_archive: false, logo_as_bg: false },
{ id: 1114, name: 'Тестовый проект', description: 'Пример тестового проекта - тут описание чего-то', logo: 'https://cdn.quasar.dev/img/mountains.jpg', chats: 12, companies: 11, persons: 15, is_archive: false, logo_as_bg: false },
) */
async function init() {
const prjs = await api.get('/project')
console.log(2222, prjs)
if (Array.isArray(prjs)) projects.value.push(...prjs)
const response = await api.get('/project')
const projectsAPI = response.data.data.map((el: RawProject) => clientConverter<Project, RawProject>(el, ['is_logo_bg', 'is_archived']))
projects.value.push(...projectsAPI)
isInit.value = true
}
@@ -37,27 +20,32 @@ export const useProjectsStore = defineStore('projects', () => {
return projects.value.find(el =>el.id === id)
}
async function addProject (projectData: ProjectParams) {
const newProject = await api.put('/project', projectData)
console.log(newProject)
// projects.value.push(newProject)
async function add (projectData: ProjectParams) {
const response = await api.post('/project', serverConverter<ProjectParams, RawProjectParams>(projectData, ['is_logo_bg']))
const newProject = clientConverter<Project, RawProject>(response.data.data, ['is_logo_bg', 'is_archived'])
projects.value.push(newProject)
return newProject
}
function updateProject (id :number, project :Project) {
async function update (id :number, projectData :ProjectParams) {
const response = await api.put('/project/'+ id, serverConverter<ProjectParams, RawProjectParams>(projectData, ['is_logo_bg']))
const projectAPI = clientConverter<Project, RawProject>(response.data.data, ['is_logo_bg', 'is_archived'])
const idx = projects.value.findIndex(item => item.id === id)
Object.assign(projects.value[idx] || {}, project)
if (projects.value[idx]) Object.assign(projects.value[idx], projectAPI)
}
function archiveProject (id :number, status :boolean) {
const idx = projects.value.findIndex(item => item.id === id)
if (projects.value[idx]) projects.value[idx].is_archive = status
async function archive (id :number) {
const response = await api.put('/project/'+ id + '/archive')
const projectAPI = clientConverter<Project, RawProject>(response.data.data, ['is_logo_bg', 'is_archived'])
const idx = projects.value.findIndex(item => item.id === projectAPI.id)
if (projects.value[idx] && projectAPI.is_archived) Object.assign(projects.value[idx], projectAPI)
}
function deleteProject (id :number) {
const idx = projects.value.findIndex(item => item.id === id)
projects.value.splice(idx, 1)
async function restore (id :number) {
const response = await api.put('/project/'+ id + '/restore')
const projectAPI = clientConverter<Project, RawProject>(response.data.data, ['is_logo_bg', 'is_archived'])
const idx = projects.value.findIndex(item => item.id === projectAPI.id)
if (projects.value[idx] && !projectAPI.is_archived) Object.assign(projects.value[idx], projectAPI)
}
function setCurrentProjectId (id: number | null) {
@@ -74,10 +62,10 @@ export const useProjectsStore = defineStore('projects', () => {
projects,
currentProjectId,
projectById,
addProject,
updateProject,
archiveProject,
deleteProject,
add,
update,
archive,
restore,
setCurrentProjectId,
getCurrentProject
}

105
src/stores/settings.ts Normal file
View File

@@ -0,0 +1,105 @@
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { api } from 'boot/axios'
import { useI18n } from 'vue-i18n'
interface AppSettings {
fontSize?: number
locale?: string
}
const defaultFontSize = 16
const minFontSize = 12
const maxFontSize = 20
const fontSizeStep = 2
export const useSettingsStore = defineStore('settings', () => {
const { locale: i18nLocale } = useI18n()
const settings = ref<AppSettings>({
fontSize: defaultFontSize,
locale: i18nLocale.value // Инициализация из i18n
})
// State
const isInit = ref(false)
// Getters
const currentFontSize = computed(() => settings.value.fontSize ?? defaultFontSize)
const canIncrease = computed(() => currentFontSize.value < maxFontSize)
const canDecrease = computed(() => currentFontSize.value > minFontSize)
// Helpers
const clampFontSize = (size: number) =>
Math.max(minFontSize, Math.min(size, maxFontSize))
const updateCssVariable = () => {
document.documentElement.style.setProperty(
'--dynamic-font-size',
`${currentFontSize.value}px`
)
}
const applyLocale = () => {
if (settings.value.locale && i18nLocale) {
i18nLocale.value = settings.value.locale
}
}
const saveSettings = async () => {
await api.put('/custome/settings', settings.value)
}
// Actions
const init = async () => {
if (isInit.value) return
try {
const { data } = await api.get<AppSettings>('/customer/settings')
settings.value = {
...settings.value,
...data
}
updateCssVariable()
applyLocale()
} finally {
isInit.value = true
}
}
const updateSettings = async (newSettings: Partial<AppSettings>) => {
settings.value = { ...settings.value, ...newSettings }
updateCssVariable()
applyLocale()
await saveSettings()
}
const updateLocale = async (newLocale: string) => {
settings.value.locale = newLocale
applyLocale()
await saveSettings()
}
const increaseFontSize = async () => {
const newSize = clampFontSize(currentFontSize.value + fontSizeStep)
await updateSettings({ fontSize: newSize })
}
const decreaseFontSize = async () => {
const newSize = clampFontSize(currentFontSize.value - fontSizeStep)
await updateSettings({ fontSize: newSize })
}
return {
settings,
isInit,
currentFontSize,
canIncrease,
canDecrease,
init,
increaseFontSize,
decreaseFontSize,
updateSettings,
updateLocale
}
})

View File

@@ -1,121 +0,0 @@
import { api } from 'boot/axios'
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
interface FontSizeResponse {
fontSize: number
}
interface FontSizeError {
message: string
code: number
}
export const useTextSizeStore = defineStore('textSize', () => {
// State
const baseSize = ref<number>(16) // Значение по умолчанию
const isLoading = ref<boolean>(false)
const error = ref<FontSizeError | null>(null)
const isInitialized = ref<boolean>(false)
// Константы
const minFontSize = 12
const maxFontSize = 20
const fontSizeStep = 2
// Getters
const currentFontSize = computed(() => baseSize.value)
const canIncrease = computed(() => baseSize.value < maxFontSize)
const canDecrease = computed(() => baseSize.value > minFontSize)
// Actions
const fetchFontSize = async () => {
try {
isLoading.value = true
const response = await api.get<FontSizeResponse>('customer/settings')
baseSize.value = clampFontSize(response.data.fontSize)
updateCssVariable()
} catch (err) {
handleError(err, 'Failed to fetch font size')
baseSize.value = 16 // Fallback к значению по умолчанию
throw err
} finally {
isLoading.value = false
}
}
const updateFontSize = async (newSize: number) => {
try {
const validatedSize = clampFontSize(newSize)
await api.put('customer/settings', { fontSize: validatedSize })
baseSize.value = validatedSize
updateCssVariable()
error.value = null
} catch (err) {
handleError(err, 'Failed to update font size')
throw err
}
}
const increaseFontSize = async () => {
if (!canIncrease.value) return
await updateFontSize(baseSize.value + fontSizeStep)
}
const decreaseFontSize = async () => {
if (!canDecrease.value) return
await updateFontSize(baseSize.value - fontSizeStep)
}
// Helpers
const clampFontSize = (size: number): number => {
return Math.max(minFontSize, Math.min(size, maxFontSize))
}
const updateCssVariable = () => {
document.documentElement.style.setProperty(
'--dynamic-font-size',
`${baseSize.value}px`
)
}
const handleError = (err: unknown, defaultMessage: string) => {
const apiError = err as { response?: { data: { message: string; code: number } } }
error.value = {
message: apiError?.response?.data?.message || defaultMessage,
code: apiError?.response?.data?.code || 500
}
console.error('FontSize Error:', error.value)
}
// Инициализация при первом использовании
const initialize = async () => {
if (isInitialized.value) return
try {
await fetchFontSize()
} catch {
// Оставляем значение по умолчанию
} finally {
isInitialized.value = true
}
}
return {
baseSize,
currentFontSize,
minFontSize,
maxFontSize,
isLoading,
error,
canIncrease,
canDecrease,
fetchFontSize,
increaseFontSize,
decreaseFontSize,
updateFontSize,
initialize
}
})

View File

@@ -12,15 +12,14 @@ interface ProjectParams {
name: string
description?: string
logo?: string
logo_as_bg: boolean
is_logo_bg: boolean
}
interface Project extends ProjectParams {
id: number
is_archive: boolean
chats: number
companies: number
persons: number
is_archived: boolean
chat_count: number
user_count: number
}
interface Chat {

18
src/types/Chats.ts Normal file
View File

@@ -0,0 +1,18 @@
interface Chat {
id: number
project_id: number
telegram_id: number
name: string
is_channel: boolean
bot_can_ban: boolean
user_count: number
last_update_time: number
description?: string
logo?: string
owner_id: number
[key: string]: unknown
}
export type {
Chat
}

21
src/types/Company.ts Normal file
View File

@@ -0,0 +1,21 @@
interface User {
id: number
project_id: number
telegram_id: number
firstname?: string
lastname?: string
username?: string
photo: string
phone: string
settings?: {
language?: string
fontSize?: number
timezone: number
}
[key: string]: unknown
}
export type {
Company,
CompanyParams
}

38
src/types/Project.ts Normal file
View File

@@ -0,0 +1,38 @@
interface ProjectParams {
name: string
description?: string
logo?: string
is_logo_bg: boolean
[key: string]: unknown
}
interface Project extends ProjectParams {
id: number
is_archived: boolean
chat_count: number
user_count: number
[key: string]: unknown
}
interface RawProjectParams {
name: string
description?: string
logo?: string
is_logo_bg: number
[key: string]: unknown
}
interface RawProject extends RawProjectParams{
id: number
is_archived: number
chat_count: number
user_count: number
[key: string]: unknown
}
export type {
Project,
ProjectParams,
RawProject,
RawProjectParams
}

20
src/types/Users.ts Normal file
View File

@@ -0,0 +1,20 @@
interface User {
id: number
project_id: number
telegram_id: number
firstname?: string
lastname?: string
username?: string
photo: string
phone: string
settings?: {
language?: string
fontSize?: number
timezone: number
}
[key: string]: unknown
}
export type {
User
}

View File

@@ -0,0 +1,38 @@
export function clientConverter<TClient, TServer extends Record<string, unknown>>(
data: TServer | null | undefined,
booleanFields: Array<keyof TClient>
): TClient {
if (!data) {
throw new Error("Invalid data: null or undefined");
}
return Object.entries(data).reduce((acc, [key, value]) => {
const typedKey = key as keyof TClient;
return {
...acc,
[typedKey]: booleanFields.includes(typedKey)
? Boolean(value)
: value
};
}, {} as TClient);
}
export function serverConverter<TClient, TServer extends Record<string, unknown>>(
data: TClient | null | undefined,
booleanFields: Array<keyof TClient>
): TServer {
if (!data) {
throw new Error("Invalid data: null or undefined");
}
return Object.entries(data).reduce((acc, [key, value]) => {
const typedKey = key as keyof TClient;
return {
...acc,
[key]: booleanFields.includes(typedKey)
? value ? 1 : 0
: value
};
}, {} as TServer);
}