This commit is contained in:
xds
2026-03-22 14:26:45 +03:00
parent 33694d68db
commit 466a27907a
28 changed files with 1334 additions and 71 deletions

View File

@@ -5,6 +5,8 @@ import api from '../api/client'
export const useCalculatorStore = defineStore('calculator', () => {
const file = ref(null)
const materialId = ref(null)
const color = ref(null)
const multicolor = ref(false)
const settings = reactive({
infill_percent: 30,
layer_height_mm: 0.2,
@@ -30,6 +32,8 @@ export const useCalculatorStore = defineStore('calculator', () => {
formData.append('layer_height_mm', settings.layer_height_mm)
formData.append('quantity', settings.quantity)
formData.append('post_processing', settings.post_processing.join(','))
if (color.value) formData.append('color', color.value)
formData.append('multicolor', multicolor.value)
try {
const { data } = await api.post('/calculate', formData, {
@@ -50,6 +54,8 @@ export const useCalculatorStore = defineStore('calculator', () => {
function reset() {
file.value = null
materialId.value = null
color.value = null
multicolor.value = false
settings.infill_percent = 30
settings.layer_height_mm = 0.2
settings.quantity = 1
@@ -59,5 +65,5 @@ export const useCalculatorStore = defineStore('calculator', () => {
uploadProgress.value = 0
}
return { file, materialId, settings, result, loading, error, uploadProgress, calculate, reset }
return { file, materialId, color, multicolor, settings, result, loading, error, uploadProgress, calculate, reset }
})

View File

@@ -0,0 +1,54 @@
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import api from '../api/client'
export const useClientStore = defineStore('client', () => {
const token = ref(localStorage.getItem('client_token') || '')
const user = ref(null)
const isAuthenticated = computed(() => !!token.value)
function setAuth(tokenValue, userData) {
token.value = tokenValue
user.value = userData
localStorage.setItem('client_token', tokenValue)
}
function logout() {
token.value = ''
user.value = null
localStorage.removeItem('client_token')
}
async function login(email, password) {
const { data } = await api.post('/client/login', { email, password })
setAuth(data.token, data.client)
return data
}
async function register(form) {
const { data } = await api.post('/client/register', form)
setAuth(data.token, data.client)
return data
}
async function fetchMe() {
if (!token.value) return
try {
const { data } = await api.get('/client/me', {
headers: { Authorization: `Bearer ${token.value}` },
})
user.value = data
} catch {
logout()
}
}
async function fetchOrders() {
const { data } = await api.get('/client/orders', {
headers: { Authorization: `Bearer ${token.value}` },
})
return data
}
return { token, user, isAuthenticated, login, register, logout, fetchMe, fetchOrders, setAuth }
})