Files
resugen-frontend/src/stores/questionnaires.js
2026-04-12 15:55:04 +03:00

128 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineStore } from 'pinia'
// Моковая анкета для примера
const mockDetailedQuestionnaire = {
id: 1,
name: 'Основная анкета',
description: 'Полные данные для IT-специальностей',
createdAt: '2026-03-15',
updatedAt: '2026-04-01',
fields: {
first_name: 'Иван',
last_name: 'Иванов',
patronymic: 'Иванович',
age: '30',
title: 'Ведущий разработчик',
salary: '300000',
worktime: 'Полный день',
phone: '+7 (999) 123-45-67',
email: 'ivan@example.com',
city: 'Москва',
about: 'Опытный full-stack разработчик с фокусом на Vue и Python.',
experience: '8 лет коммерческой разработки...',
education: 'МГУ, факультет ВМК, 2015',
courses: 'Vue Advanced, Python Pro',
skills: 'Vue, React, Python, Django, PostgreSQL',
languages: 'Русский (родной), English (B2)',
projects: 'Разработка CRM-системы, мобильное приложение для банка',
},
}
const mockQuestionnaires = [
{
id: 1,
name: 'Основная анкета',
description: 'Полные данные для IT-специальностей',
createdAt: '2026-03-15',
updatedAt: '2026-04-01',
fieldsCount: 12,
},
{
id: 2,
name: 'Анкета для менеджмента',
description: 'Акцент на управленческие навыки',
createdAt: '2026-03-20',
updatedAt: '2026-03-25',
fieldsCount: 10,
},
]
export const useQuestionnairesStore = defineStore('questionnaires', {
state: () => ({
questionnaires: [...mockQuestionnaires],
// Детальные данные анкет храним отдельно (можно объединить, но для простоты отдельный объект)
details: {
1: { ...mockDetailedQuestionnaire.fields },
},
nextId: 3,
}),
actions: {
// Получить детальные поля анкеты по id
getQuestionnaireDetails(id) {
return this.details[id] || this.createEmptyFields()
},
// Создать или обновить анкету
saveQuestionnaire(id, data) {
const { name, description, fields } = data
const existing = this.questionnaires.find(q => q.id === id)
if (existing) {
// Обновление существующей
existing.name = name
existing.description = description
existing.updatedAt = new Date().toISOString().split('T')[0]
existing.fieldsCount = Object.keys(fields).filter(k => fields[k]).length
this.details[id] = { ...fields }
} else {
// Создание новой
const newId = this.nextId++
const newQuestionnaire = {
id: newId,
name,
description,
createdAt: new Date().toISOString().split('T')[0],
updatedAt: new Date().toISOString().split('T')[0],
fieldsCount: Object.keys(fields).filter(k => fields[k]).length,
}
this.questionnaires.push(newQuestionnaire)
this.details[newId] = { ...fields }
return newId
}
return id
},
createEmptyFields() {
return {
first_name: '',
last_name: '',
patronymic: '',
age: '',
title: '',
salary: '',
worktime: '',
phone: '',
email: '',
city: '',
about: '',
experience: '',
education: '',
courses: '',
skills: '',
languages: '',
projects: '',
}
},
deleteQuestionnaire(id) {
this.questionnaires = this.questionnaires.filter(q => q.id !== id)
delete this.details[id]
},
},
persist: {
key: 'questionnaires-storage',
storage: localStorage,
},
})