Skip to content

Commit 7215a3e

Browse files
committed
migrate: store
1 parent e0d00d6 commit 7215a3e

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

app/store/alert.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useModalStore } from ".";
2+
3+
export interface AlertState {
4+
type: "success" | "error";
5+
title: string;
6+
text: string;
7+
}
8+
9+
export function useAlertStore() {
10+
const { open: openModal, close: closeModal } = useModalStore();
11+
12+
function open(payload: AlertState) {
13+
openModal({ name: "alert", data: payload });
14+
}
15+
16+
function close() {
17+
closeModal();
18+
}
19+
20+
return { open, close };
21+
};

app/store/dialog.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useModalStore } from ".";
2+
3+
export interface DialogState {
4+
title: string;
5+
}
6+
7+
export function useDialogStore() {
8+
const { open: openModal, close: closeModal } = useModalStore();
9+
10+
function open(payload: DialogState) {
11+
openModal({ name: "dialog", data: payload });
12+
}
13+
14+
function close() {
15+
closeModal();
16+
}
17+
18+
return { open, close };
19+
};

app/store/index.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ref } from "vue";
2+
import { useState } from "#app";
3+
4+
export function useBackDropStore() {
5+
const isShowed = useState("backDrop", () => ref(false));
6+
function show() {
7+
isShowed.value = true;
8+
}
9+
10+
function hide() {
11+
isShowed.value = false;
12+
}
13+
14+
return { isShowed, show, hide };
15+
};
16+
17+
export interface ModalState {
18+
name: string;
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20+
data?: Record<string, any>;
21+
}
22+
23+
export function useModalStore() {
24+
const { show, hide } = useBackDropStore();
25+
const state = useState<ModalState>("modal", () => ref<ModalState>({ name: "", data: {} }));
26+
27+
function open(payload: ModalState) {
28+
show();
29+
state.value = payload;
30+
}
31+
32+
function close() {
33+
state.value = { name: "", data: {} };
34+
hide();
35+
}
36+
37+
return { state, open, close };
38+
};

0 commit comments

Comments
 (0)