64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
|
|
export const useParamsStore = defineStore('params', {
|
|
|
|
state: () => ({
|
|
paramsData: false,
|
|
}),
|
|
|
|
actions:
|
|
{
|
|
async findAll(data = null)
|
|
{
|
|
if (data){
|
|
this.paramsData = JSON.parse(data)
|
|
//console.log(data)
|
|
}
|
|
else{
|
|
this.paramsData = JSON.parse(await paramsService.findAll())
|
|
//if (this.paramsData)
|
|
}
|
|
//console.log(this.paramsData)
|
|
},
|
|
|
|
updateParams(){
|
|
paramsService.update(JSON.stringify(this.paramsData))
|
|
},
|
|
|
|
changePage(page){
|
|
this.paramsData.profil_and_params_view = page
|
|
this.updateParams();
|
|
},
|
|
|
|
deleteColor(){
|
|
|
|
if(this.paramsData.colors.length > 1){
|
|
|
|
const deletedColor = this.paramsData.colors.pop()
|
|
if (this.paramsData.unavailable_colors == undefined){
|
|
this.paramsData = {
|
|
colors : this.paramsData.colors,
|
|
unavailable_colors : [],
|
|
profil_and_params_view : this.paramsData.profil_and_params_view
|
|
}
|
|
}
|
|
this.paramsData.unavailable_colors.push(deletedColor)
|
|
}
|
|
this.updateParams();
|
|
|
|
},
|
|
|
|
addColor(){
|
|
if(this.paramsData.colors.length < 8){
|
|
const color = this.paramsData.unavailable_colors.pop()
|
|
this.paramsData.colors.push(color)
|
|
this.updateParams();
|
|
}
|
|
},
|
|
|
|
modifyColor(colorIndex, newColorValue) {
|
|
this.paramsData.colors[colorIndex] = newColorValue
|
|
this.updateParams();
|
|
},
|
|
}
|
|
}) |