You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
872 B
JavaScript
32 lines
872 B
JavaScript
const STORAGE_KEY = "dutyTodos";
|
|
|
|
export const loadDutyTodos = () => {
|
|
try {
|
|
const raw = uni.getStorageSync(STORAGE_KEY);
|
|
const list = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
if (!Array.isArray(list)) return [];
|
|
return list
|
|
.map((item) => ({
|
|
id: String(item?.id || ""),
|
|
text: String(item?.text || "").trim(),
|
|
done: Boolean(item?.done),
|
|
}))
|
|
.filter((item) => item.id && item.text);
|
|
} catch (error) {
|
|
console.log("读取待办事项失败", error);
|
|
return [];
|
|
}
|
|
};
|
|
|
|
export const saveDutyTodos = (list) => {
|
|
const next = Array.isArray(list) ? list : [];
|
|
uni.setStorageSync(STORAGE_KEY, JSON.stringify(next));
|
|
return next;
|
|
};
|
|
|
|
export const createDutyTodo = (text) => ({
|
|
id: `${Date.now()}-${Math.random().toString(16).slice(2, 8)}`,
|
|
text: String(text || "").trim(),
|
|
done: false,
|
|
});
|