дату помним в localstorage
This commit is contained in:
@@ -29,8 +29,28 @@ import {
|
||||
VerificationConditionsValue,
|
||||
} from './types'
|
||||
|
||||
// Утилиты для работы с localStorage
|
||||
const getLocalStorageKey = (type: string, id: string) => `${type}_${id}`
|
||||
|
||||
const saveToLocalStorage = (key: string, value: string) => {
|
||||
try {
|
||||
localStorage.setItem(key, value)
|
||||
} catch (error) {
|
||||
console.warn('Failed to save to localStorage:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const getFromLocalStorage = (key: string): string => {
|
||||
try {
|
||||
return localStorage.getItem(key) || ''
|
||||
} catch (error) {
|
||||
console.warn('Failed to get from localStorage:', error)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
interface VerificationConditionsRenderProps {
|
||||
config: VerificationConditionsConfig
|
||||
config: VerificationConditionsConfig & { id?: string }
|
||||
value?: VerificationConditionsValue
|
||||
onChange?: (value: VerificationConditionsValue) => void
|
||||
onSave?: (value: VerificationConditionsValue) => Promise<void>
|
||||
@@ -42,9 +62,22 @@ export function VerificationConditionsRender({
|
||||
onChange,
|
||||
onSave,
|
||||
}: VerificationConditionsRenderProps) {
|
||||
const [selectedDate, setSelectedDate] = useState(
|
||||
value?.date || config.selectedDate || new Date().toISOString().split('T')[0]
|
||||
)
|
||||
// Инициализация даты с учетом localStorage
|
||||
const getInitialDate = () => {
|
||||
if (value?.date) return value.date
|
||||
if (config.selectedDate) return config.selectedDate
|
||||
|
||||
// Попытка загрузить из localStorage
|
||||
if (config.id) {
|
||||
const key = getLocalStorageKey('verification_conditions_date', config.id)
|
||||
const savedDate = getFromLocalStorage(key)
|
||||
if (savedDate) return savedDate
|
||||
}
|
||||
|
||||
return new Date().toISOString().split('T')[0]
|
||||
}
|
||||
|
||||
const [selectedDate, setSelectedDate] = useState(getInitialDate)
|
||||
const [editDialogOpen, setEditDialogOpen] = useState(false)
|
||||
const [editingConditions, setEditingConditions] = useState<
|
||||
Record<string, string>
|
||||
@@ -101,6 +134,12 @@ export function VerificationConditionsRender({
|
||||
const newDate = event.target.value
|
||||
setSelectedDate(newDate)
|
||||
|
||||
// Сохранение в localStorage
|
||||
if (config.id) {
|
||||
const key = getLocalStorageKey('verification_conditions_date', config.id)
|
||||
saveToLocalStorage(key, newDate)
|
||||
}
|
||||
|
||||
// Обновляем значение даты в value
|
||||
if (onChange) {
|
||||
onChange({
|
||||
|
||||
@@ -58,6 +58,7 @@ export const verificationConditionsElementDefinition: ElementDefinition<
|
||||
conditionMappings: [],
|
||||
showUnits: true,
|
||||
targetCells: [],
|
||||
id: '',
|
||||
},
|
||||
|
||||
// Компоненты
|
||||
@@ -65,10 +66,26 @@ export const verificationConditionsElementDefinition: ElementDefinition<
|
||||
Preview: VerificationConditionsPreview,
|
||||
Render: VerificationConditionsRender,
|
||||
|
||||
// Получение начальных значений из конфигурации
|
||||
// Получение начальных значений из конфигурации с учетом localStorage
|
||||
getInitialValue: config => {
|
||||
let initialDate =
|
||||
config.selectedDate || new Date().toISOString().split('T')[0]
|
||||
|
||||
// Попытка загрузить дату из localStorage
|
||||
if (config.id) {
|
||||
try {
|
||||
const key = `verification_conditions_date_${config.id}`
|
||||
const savedDate = localStorage.getItem(key)
|
||||
if (savedDate) {
|
||||
initialDate = savedDate
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to get date from localStorage:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
date: config.selectedDate || new Date().toISOString().split('T')[0],
|
||||
date: initialDate,
|
||||
conditions: {},
|
||||
}
|
||||
},
|
||||
|
||||
@@ -19,6 +19,8 @@ export interface VerificationConditionsConfig {
|
||||
showUnits?: boolean
|
||||
// Целевые ячейки
|
||||
targetCells?: any[]
|
||||
// Идентификатор для совместимости с TemplateElement
|
||||
id?: string
|
||||
}
|
||||
|
||||
// Значение элемента
|
||||
|
||||
Reference in New Issue
Block a user