test #10
1
bo/components.d.ts
vendored
1
bo/components.d.ts
vendored
@@ -17,6 +17,7 @@ declare module 'vue' {
|
|||||||
En_TermsAndConditionsView: typeof import('./src/components/terms/en_TermsAndConditionsView.vue')['default']
|
En_TermsAndConditionsView: typeof import('./src/components/terms/en_TermsAndConditionsView.vue')['default']
|
||||||
LangSwitch: typeof import('./src/components/inner/langSwitch.vue')['default']
|
LangSwitch: typeof import('./src/components/inner/langSwitch.vue')['default']
|
||||||
PageAddresses: typeof import('./src/components/customer/PageAddresses.vue')['default']
|
PageAddresses: typeof import('./src/components/customer/PageAddresses.vue')['default']
|
||||||
|
PageCart: typeof import('./src/components/customer/PageCart.vue')['default']
|
||||||
PageProductCardFull: typeof import('./src/components/customer/PageProductCardFull.vue')['default']
|
PageProductCardFull: typeof import('./src/components/customer/PageProductCardFull.vue')['default']
|
||||||
Pl_PrivacyPolicyView: typeof import('./src/components/terms/pl_PrivacyPolicyView.vue')['default']
|
Pl_PrivacyPolicyView: typeof import('./src/components/terms/pl_PrivacyPolicyView.vue')['default']
|
||||||
Pl_TermsAndConditionsView: typeof import('./src/components/terms/pl_TermsAndConditionsView.vue')['default']
|
Pl_TermsAndConditionsView: typeof import('./src/components/terms/pl_TermsAndConditionsView.vue')['default']
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ import type { NuxtUIOptions } from '@nuxt/ui/unplugin'
|
|||||||
|
|
||||||
export const uiOptions: NuxtUIOptions = {
|
export const uiOptions: NuxtUIOptions = {
|
||||||
ui: {
|
ui: {
|
||||||
colors: {
|
|
||||||
primary: 'blue',
|
|
||||||
neutral: 'zink',
|
|
||||||
},
|
|
||||||
pagination: {
|
pagination: {
|
||||||
slots: {
|
slots: {
|
||||||
root: '',
|
root: '',
|
||||||
@@ -56,6 +52,12 @@ export const uiOptions: NuxtUIOptions = {
|
|||||||
tr: 'border-b! border-(--border-light)! dark:border-(--border-dark)! outline-0! ring-0! text-(--black)! dark:text-white!',
|
tr: 'border-b! border-(--border-light)! dark:border-(--border-dark)! outline-0! ring-0! text-(--black)! dark:text-white!',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
modal: {
|
||||||
|
slots: {
|
||||||
|
content: 'border! border-(--border-light)! dark:border-(--border-dark)! outline-0! ring-0! bg-(--second-light) dark:bg-(--main-dark)',
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ const authStore = useAuthStore()
|
|||||||
<template>
|
<template>
|
||||||
<header
|
<header
|
||||||
class="fixed top-0 left-0 right-0 z-50 bg-white/80 dark:bg-(--black) backdrop-blur-md border-b border-(--border-light) dark:border-(--border-dark)">
|
class="fixed top-0 left-0 right-0 z-50 bg-white/80 dark:bg-(--black) backdrop-blur-md border-b border-(--border-light) dark:border-(--border-dark)">
|
||||||
<div class="container px-4 sm:px-6 lg:px-8">
|
<div class="container mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
<div class="flex items-center justify-between h-14">
|
<div class="flex items-center justify-between h-14">
|
||||||
<!-- Logo -->
|
<!-- Logo -->
|
||||||
<RouterLink :to="{ name: 'home' }" class="flex items-center gap-2">
|
<RouterLink :to="{ name: 'home' }" class="flex items-center gap-2">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="container my-10 ">
|
<div class="container my-10 mx-auto ">
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="flex items-end justify-between gap-4 mb-6 bg-(--second-light) dark:bg-(--main-dark) border border-(--border-light) dark:border-(--border-dark) p-4 rounded-md">
|
class="flex items-end justify-between gap-4 mb-6 bg-(--second-light) dark:bg-(--main-dark) border border-(--border-light) dark:border-(--border-dark) p-4 rounded-md">
|
||||||
|
|||||||
@@ -1,118 +1,148 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="container">
|
<div class="container mx-auto mt-10">
|
||||||
<div class="p-6 bg-white dark:bg-(--black) min-h-screen font-sans">
|
<div class="flex flex-col mb-6">
|
||||||
<div class="flex justify-between items-center mb-6">
|
<h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Addresses') }}</h1>
|
||||||
<h1 class="text-2xl font-bold text-black dark:text-white">
|
<div class="flex justify-between items-center">
|
||||||
{{ t('addresses.title') }}
|
<div class="flex gap-2 items-center">
|
||||||
</h1>
|
<UInput v-model="searchQuery" type="text" :placeholder="t('Search address')"
|
||||||
<UButton @click="showModal = true"
|
class="bg-white dark:bg-gray-800 text-black dark:text-white absolute" />
|
||||||
class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-blue-600 transition-colors flex items-center gap-2">
|
<UIcon name="ic:baseline-search"
|
||||||
<span class="i-lucide-plus" />
|
class="text-[20px] text-(--accent-blue-light) dark:text-(--accent-blue-dark) relative left-40" />
|
||||||
{{ t('addresses.addNew') }}
|
</div>
|
||||||
|
<UButton color="primary" @click="openCreateModal"
|
||||||
|
class="bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) text-white hover:bg-(--accent-blue-dark) dark:hover:bg-(--accent-blue-light)">
|
||||||
|
<UIcon name="mdi:add-bold" />
|
||||||
|
{{ t('Add Address') }}
|
||||||
</UButton>
|
</UButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="paginatedAddresses.length" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||||
|
<div v-for="address in paginatedAddresses" :key="address.id"
|
||||||
|
class="border border-(--border-light) dark:border-(--border-dark) rounded-md p-4 bg-(--second-light) dark:bg-(--main-dark) hover:shadow-md transition-shadow">
|
||||||
|
<p class="text-black dark:text-white">{{ address.street }}</p>
|
||||||
|
<p class="text-black dark:text-white">{{ address.zipCode }}, {{ address.city }}</p>
|
||||||
|
<p class="text-black dark:text-white">{{ address.country }}</p>
|
||||||
|
<div class="flex gap-2 mt-2">
|
||||||
|
<UButton size="sm" color="neutral" variant="outline" @click="openEditModal(address)"
|
||||||
|
class="text-(--accent-blue-light) dark:text-(--accent-blue-dark)">{{ t('edit') }}
|
||||||
|
</UButton>
|
||||||
|
<button size="sm" color="destructive" variant="outline" @click="confirmDelete(address.id)"
|
||||||
|
class="text-red-500 hover:bg-red-100 dark:hover:bg-red-900 dark:hover:text-red-100 rounded transition-colors p-2">
|
||||||
|
<UIcon name="material-symbols:delete" class="text-[16px]" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-6">
|
</div>
|
||||||
<UInput v-model="searchQuery" type="text" :placeholder="t('addresses.searchPlaceholder')"
|
<div v-else class="text-center py-8 text-gray-500 dark:text-gray-400">{{ t('No addresses found') }}</div>
|
||||||
class="bg-white dark:bg-gray-800 text-black dark:text-white w-[30%]" />
|
|
||||||
</div>
|
<div class="mt-6 flex justify-center">
|
||||||
<div v-if="paginatedAddresses.length > 0" class="space-y-4">
|
<UPagination v-model:page="page" :total="totalItems" :page-size="pageSize" />
|
||||||
<div v-for="address in paginatedAddresses" :key="address.id"
|
</div>
|
||||||
class="border border-gray-200 dark:border-gray-700 rounded-lg p-4 bg-white dark:bg-gray-800 hover:shadow-md transition-shadow">
|
|
||||||
<div class="flex justify-between items-start">
|
<UModal v-model:open="showModal" :overlay="true" class="max-w-md mx-auto">
|
||||||
<div class="flex-1">
|
<template #content>
|
||||||
<p class="text-black dark:text-white mt-1">
|
<div class="p-6 flex flex-col gap-6">
|
||||||
{{ address.street }}
|
<p class="text-[20px] text-black dark:text-white ">Address</p>
|
||||||
</p>
|
<UForm @submit.prevent="saveAddress" class="space-y-4" :validate="validate">
|
||||||
<p class="text-black dark:text-white flex gap-2">
|
<div>
|
||||||
{{ address.zipCode }}, <span>{{ address.city }}</span>
|
<label class="block text-sm font-medium text-black dark:text-white mb-1">Street *</label>
|
||||||
</p>
|
<UInput v-model="formData.street" placeholder="Enter street" name="street" class="w-full" />
|
||||||
<p class="text-black dark:text-white">{{ address.country }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-black dark:text-white mb-1">Zip Code *</label>
|
||||||
|
<UInput v-model="formData.zipCode" placeholder="Enter zip code" name="zipCode"
|
||||||
|
class="w-full" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-black dark:text-white mb-1">City *</label>
|
||||||
|
<UInput v-model="formData.city" placeholder="Enter city" name="city" class="w-full" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-black dark:text-white mb-1">Country *</label>
|
||||||
|
<UInput v-model="formData.country" placeholder="Enter country" name="country"
|
||||||
|
class="w-full" />
|
||||||
|
</div>
|
||||||
|
</UForm>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<UButton variant="outline" color="neutral" @click="closeModal"
|
||||||
|
class="text-black dark:text-white">{{ t('Cancel') }}</UButton>
|
||||||
|
<UButton variant="outline" color="neutral" @click="saveAddress"
|
||||||
|
class="text-white bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) hover:bg-(--accent-blue-dark) dark:hover:bg-(--accent-blue-light)">
|
||||||
|
{{ t('Save') }}</UButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</template>
|
||||||
<div v-else class="text-center py-12 text-gray-500 dark:text-gray-400">
|
</UModal>
|
||||||
<span class="i-lucide-map-pin text-4xl mb-4 block" />
|
|
||||||
<p class="text-lg">{{ t('addresses.noAddresses') }}</p>
|
|
||||||
<UButton @click="showModal"
|
|
||||||
class="mt-4 px-4 py-2 bg-primary text-white rounded-lg hover:bg-blue-600 transition-colors">
|
|
||||||
{{ t('addresses.addFirst') }}
|
|
||||||
</UButton>
|
|
||||||
</div>
|
|
||||||
<form @submit.prevent="saveAddress" class="space-y-4 mt-4">
|
|
||||||
<div>
|
|
||||||
<label class="block text-sm font-medium text-black dark:text-white mb-1">Street *</label>
|
|
||||||
<UInput v-model="formData.street" placeholder="Enter street" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<UModal v-model:open="showDeleteConfirm" :overlay="true" class="max-w-md mx-auto">
|
||||||
<label class="block text-sm font-medium text-black dark:text-white mb-1">Zip Code *</label>
|
<template #content>
|
||||||
<UInput v-model="formData.zipCode" placeholder="Enter zip code" />
|
<div class="p-6 flex flex-col gap-3">
|
||||||
|
<div class="flex flex-col gap-2 justify-center items-center">
|
||||||
|
<p class="flex items-end gap-2 dark:text-white text-black">
|
||||||
|
<UIcon name='f7:exclamationmark-triangle' class="text-[35px] text-red-700" />
|
||||||
|
Confirm Delete
|
||||||
|
</p>
|
||||||
|
<p class="text-gray-700 dark:text-gray-300">
|
||||||
|
{{ t('Are you sure you want to delete this address?') }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-center gap-5">
|
||||||
|
<UButton variant="outline" color="neutral" @click="showDeleteConfirm = false"
|
||||||
|
class="dark:text-white text-black">{{ t('Cancel') }}
|
||||||
|
</UButton>
|
||||||
|
<UButton variant="outline" color="neutral" @click="deleteAddress" class="text-red-700">
|
||||||
|
{{ t('Delete') }}</UButton>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</template>
|
||||||
<div>
|
</UModal>
|
||||||
<label class="block text-sm font-medium text-black dark:text-white mb-1">City *</label>
|
|
||||||
<UInput v-model="formData.city" placeholder="Enter city" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label class="block text-sm font-medium text-black dark:text-white mb-1">Country *</label>
|
|
||||||
<UInput v-model="formData.country" placeholder="Enter country" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex justify-end gap-3 pt-4 border-t border-gray-200 dark:border-gray-700">
|
|
||||||
<UButton color="neutral" variant="outline" @click="closeModal">Cancel</UButton>
|
|
||||||
<UButton type="submit" color="primary">Save</UButton>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch } from 'vue'
|
import { ref, computed, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useAddressStore } from '@/stores/address'
|
||||||
import { useAddressStore, type Address, type AddressFormData } from '@/stores/address'
|
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
const addressStore = useAddressStore()
|
const addressStore = useAddressStore()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const searchQuery = ref('')
|
||||||
const showModal = ref(false)
|
const showModal = ref(false)
|
||||||
const isEditing = ref(false)
|
const isEditing = ref(false)
|
||||||
const editingAddressId = ref<number | null>(null)
|
const editingAddressId = ref<number | null>(null)
|
||||||
|
const formData = ref({ street: '', zipCode: '', city: '', country: '' })
|
||||||
|
|
||||||
const formData = ref<AddressFormData>({
|
const showDeleteConfirm = ref(false)
|
||||||
street: '',
|
const addressToDelete = ref<number | null>(null)
|
||||||
zipCode: '',
|
|
||||||
city: '',
|
|
||||||
country: ''
|
|
||||||
})
|
|
||||||
|
|
||||||
const formErrors = ref<Record<string, string>>({})
|
|
||||||
const searchQuery = ref('')
|
|
||||||
|
|
||||||
let searchTimeout: ReturnType<typeof setTimeout> | null = null
|
|
||||||
|
|
||||||
watch(searchQuery, (newValue) => {
|
|
||||||
if (searchTimeout) clearTimeout(searchTimeout)
|
|
||||||
searchTimeout = setTimeout(() => {
|
|
||||||
addressStore.setSearchQuery(newValue)
|
|
||||||
}, 300)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
const page = ref(addressStore.currentPage)
|
||||||
const paginatedAddresses = computed(() => addressStore.paginatedAddresses)
|
const paginatedAddresses = computed(() => addressStore.paginatedAddresses)
|
||||||
|
const totalItems = computed(() => addressStore.totalItems)
|
||||||
|
const pageSize = addressStore.pageSize
|
||||||
|
|
||||||
|
watch(page, (newPage) => addressStore.setPage(newPage))
|
||||||
|
|
||||||
|
watch(searchQuery, (val) => {
|
||||||
|
addressStore.setSearchQuery(val)
|
||||||
|
})
|
||||||
|
|
||||||
|
function openCreateModal() {
|
||||||
|
resetForm()
|
||||||
|
isEditing.value = false
|
||||||
|
showModal.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEditModal(address: any) {
|
||||||
|
formData.value = { ...address }
|
||||||
|
isEditing.value = true
|
||||||
|
editingAddressId.value = address.id
|
||||||
|
showModal.value = true
|
||||||
|
}
|
||||||
|
|
||||||
function resetForm() {
|
function resetForm() {
|
||||||
formData.value = {
|
formData.value = { street: '', zipCode: '', city: '', country: '' }
|
||||||
street: '',
|
editingAddressId.value = null
|
||||||
zipCode: '',
|
|
||||||
city: '',
|
|
||||||
country: ''
|
|
||||||
}
|
|
||||||
formErrors.value = {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
@@ -120,35 +150,35 @@ function closeModal() {
|
|||||||
resetForm()
|
resetForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateForm(): boolean {
|
function validate() {
|
||||||
formErrors.value = {}
|
const errors = []
|
||||||
|
if (!formData.value.street) errors.push({ name: 'street', message: 'Street required' })
|
||||||
if (!formData.value.street.trim()) {
|
if (!formData.value.zipCode) errors.push({ name: 'zipCode', message: 'Zip Code required' })
|
||||||
formErrors.value.street = 'Street is required'
|
if (!formData.value.city) errors.push({ name: 'city', message: 'City required' })
|
||||||
}
|
if (!formData.value.country) errors.push({ name: 'country', message: 'Country required' })
|
||||||
if (!formData.value.zipCode.trim()) {
|
return errors.length ? errors : null
|
||||||
formErrors.value.zipCode = 'Zip Code is required'
|
|
||||||
}
|
|
||||||
if (!formData.value.city.trim()) {
|
|
||||||
formErrors.value.city = 'City is required'
|
|
||||||
}
|
|
||||||
if (!formData.value.country.trim()) {
|
|
||||||
formErrors.value.country = 'Country is required'
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object.keys(formErrors.value).length === 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveAddress() {
|
function saveAddress() {
|
||||||
if (!validateForm()) return
|
if (validate()) return
|
||||||
|
|
||||||
if (isEditing.value && editingAddressId.value) {
|
if (isEditing.value && editingAddressId.value) {
|
||||||
(editingAddressId.value, formData.value)
|
addressStore.updateAddress(editingAddressId.value, formData.value)
|
||||||
} else {
|
} else {
|
||||||
addressStore.addAddress(formData.value)
|
addressStore.addAddress(formData.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
closeModal()
|
closeModal()
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
function confirmDelete(id: number) {
|
||||||
|
addressToDelete.value = id
|
||||||
|
showDeleteConfirm.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteAddress() {
|
||||||
|
if (addressToDelete.value) {
|
||||||
|
addressStore.deleteAddress(addressToDelete.value)
|
||||||
|
}
|
||||||
|
showDeleteConfirm.value = false
|
||||||
|
addressToDelete.value = null
|
||||||
|
}
|
||||||
|
</script>
|
||||||
9
bo/src/components/customer/PageCart.vue
Normal file
9
bo/src/components/customer/PageCart.vue
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<template>
|
||||||
|
<div class="container mx-auto">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
|
||||||
|
</script>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="container mt-14">
|
<div class="container mt-14 mx-auto">
|
||||||
<div class="flex justify-between gap-8 mb-6">
|
<div class="flex justify-between gap-8 mb-6">
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<div class="bg-gray-100 dark:bg-gray-800 rounded-lg p-8 flex items-center justify-center min-h-[300px]">
|
<div class="bg-gray-100 dark:bg-gray-800 rounded-lg p-8 flex items-center justify-center min-h-[300px]">
|
||||||
|
|||||||
@@ -22,42 +22,20 @@ export const useAddressStore = defineStore('address', () => {
|
|||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
|
|
||||||
const currentPage = ref(1)
|
const currentPage = ref(1)
|
||||||
const pageSize = 10
|
const pageSize = 20
|
||||||
const totalItems = computed(() => filteredAddresses.value.length)
|
|
||||||
const totalPages = computed(() => Math.ceil(totalItems.value / pageSize))
|
|
||||||
|
|
||||||
const searchQuery = ref('')
|
const searchQuery = ref('')
|
||||||
|
|
||||||
function initMockData() {
|
function initMockData() {
|
||||||
addresses.value = [
|
addresses.value = [
|
||||||
{
|
{ id: 1, street: 'Main Street 123', zipCode: '10-001', city: 'New York', country: 'United States' },
|
||||||
id: 1,
|
{ id: 2, street: 'Oak Avenue 123', zipCode: '90-001', city: 'Los Angeles', country: 'United States' },
|
||||||
street: 'Main Street 123',
|
{ id: 3, street: 'Pine Road 123', zipCode: '60-601', city: 'Chicago', country: 'United States' }
|
||||||
zipCode: '10-001',
|
|
||||||
city: 'New York',
|
|
||||||
country: 'United States'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
street: 'Oak Avenue 123',
|
|
||||||
zipCode: '90-001',
|
|
||||||
city: 'Los Angeles',
|
|
||||||
country: 'United States'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
street: 'Pine Road 123 ',
|
|
||||||
zipCode: '60-601',
|
|
||||||
city: 'Chicago',
|
|
||||||
country: 'United States'
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredAddresses = computed(() => {
|
const filteredAddresses = computed(() => {
|
||||||
if (!searchQuery.value) {
|
if (!searchQuery.value) return addresses.value
|
||||||
return addresses.value
|
|
||||||
}
|
|
||||||
|
|
||||||
const query = searchQuery.value.toLowerCase()
|
const query = searchQuery.value.toLowerCase()
|
||||||
|
|
||||||
@@ -68,34 +46,62 @@ export const useAddressStore = defineStore('address', () => {
|
|||||||
addr.zipCode.toLowerCase().includes(query)
|
addr.zipCode.toLowerCase().includes(query)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const totalItems = computed(() => filteredAddresses.value.length)
|
||||||
|
const totalPages = computed(() => Math.ceil(totalItems.value / pageSize))
|
||||||
|
|
||||||
const paginatedAddresses = computed(() => {
|
const paginatedAddresses = computed(() => {
|
||||||
const start = (currentPage.value - 1) * pageSize
|
const start = (currentPage.value - 1) * pageSize
|
||||||
const end = start + pageSize
|
return filteredAddresses.value.slice(start, start + pageSize)
|
||||||
return filteredAddresses.value.slice(start, end)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function getAddressById(id: number): Address | undefined {
|
function getAddressById(id: number) {
|
||||||
return addresses.value.find(addr => addr.id === id)
|
return addresses.value.find(addr => addr.id === id)
|
||||||
}
|
}
|
||||||
|
|
||||||
function addAddress(formData: AddressFormData): Address {
|
function normalize(data: AddressFormData): AddressFormData {
|
||||||
const now = new Date().toISOString()
|
return {
|
||||||
|
street: data.street.trim(),
|
||||||
|
zipCode: data.zipCode.trim(),
|
||||||
|
city: data.city.trim(),
|
||||||
|
country: data.country.trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateId(): number {
|
||||||
|
return Math.max(0, ...addresses.value.map(a => a.id)) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function addAddress(formData: AddressFormData): Address {
|
||||||
const newAddress: Address = {
|
const newAddress: Address = {
|
||||||
id: Date.now(),
|
id: generateId(),
|
||||||
...formData,
|
...normalize(formData)
|
||||||
}
|
}
|
||||||
|
|
||||||
addresses.value.push(newAddress)
|
addresses.value.unshift(newAddress)
|
||||||
|
resetPagination()
|
||||||
|
|
||||||
return newAddress
|
return newAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateAddress(id: number, formData: AddressFormData): boolean {
|
||||||
|
const index = addresses.value.findIndex(a => a.id === id)
|
||||||
|
if (index === -1) return false
|
||||||
|
|
||||||
|
addresses.value[index] = {
|
||||||
|
...addresses.value[index],
|
||||||
|
...normalize(formData)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
function deleteAddress(id: number): boolean {
|
function deleteAddress(id: number): boolean {
|
||||||
const index = addresses.value.findIndex(addr => addr.id === id)
|
const index = addresses.value.findIndex(a => a.id === id)
|
||||||
if (index === -1) return false
|
if (index === -1) return false
|
||||||
|
|
||||||
addresses.value.splice(index, 1)
|
addresses.value.splice(index, 1)
|
||||||
|
resetPagination()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -128,9 +134,10 @@ export const useAddressStore = defineStore('address', () => {
|
|||||||
paginatedAddresses,
|
paginatedAddresses,
|
||||||
getAddressById,
|
getAddressById,
|
||||||
addAddress,
|
addAddress,
|
||||||
|
updateAddress,
|
||||||
deleteAddress,
|
deleteAddress,
|
||||||
setPage,
|
setPage,
|
||||||
setSearchQuery,
|
setSearchQuery,
|
||||||
resetPagination
|
resetPagination
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user