This commit is contained in:
Vanessa 2023-10-31 20:03:42 +08:00
parent 53dfc2f744
commit 12f20e74c2
2 changed files with 38 additions and 11 deletions

View file

@ -22,16 +22,11 @@ export const newCardModel = (options: {
tab: options.tab, tab: options.tab,
data: options.data, data: options.data,
init() { init() {
fetchPost(this.data.cardType === "all" ? "/api/riff/getRiffDueCards" : if (options.data.blocks) {
(this.data.cardType === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), {
rootID: this.data.id,
deckID: this.data.id,
notebook: this.data.id,
}, (response) => {
this.element.innerHTML = genCardHTML({ this.element.innerHTML = genCardHTML({
id: this.data.id, id: this.data.id,
cardType: this.data.cardType, cardType: this.data.cardType,
blocks: response.data.cards, blocks: options.data.blocks,
isTab: true, isTab: true,
}); });
@ -41,10 +36,35 @@ export const newCardModel = (options: {
id: this.data.id, id: this.data.id,
title: this.data.title, title: this.data.title,
cardType: this.data.cardType, cardType: this.data.cardType,
blocks: response.data.cards, blocks: options.data.blocks,
index: options.data.index,
}); });
customObj.data.editor = editor; this.data.editor = editor;
}); } else {
fetchPost(this.data.cardType === "all" ? "/api/riff/getRiffDueCards" :
(this.data.cardType === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), {
rootID: this.data.id,
deckID: this.data.id,
notebook: this.data.id,
}, (response) => {
this.element.innerHTML = genCardHTML({
id: this.data.id,
cardType: this.data.cardType,
blocks: response.data.cards,
isTab: true,
});
editor = bindCardEvent({
app: options.app,
element: this.element,
id: this.data.id,
title: this.data.title,
cardType: this.data.cardType,
blocks: response.data.cards,
});
customObj.data.editor = editor;
});
}
}, },
destroy() { destroy() {
if (editor) { if (editor) {

View file

@ -123,12 +123,16 @@ export const bindCardEvent = (options: {
cardType: TCardType, cardType: TCardType,
id?: string, id?: string,
dialog?: Dialog, dialog?: Dialog,
index?: number
}) => { }) => {
if (window.siyuan.storage[Constants.LOCAL_FLASHCARD].fullscreen) { if (window.siyuan.storage[Constants.LOCAL_FLASHCARD].fullscreen) {
fullscreen(options.element.querySelector(".card__main"), fullscreen(options.element.querySelector(".card__main"),
options.element.querySelector('[data-type="fullscreen"]')); options.element.querySelector('[data-type="fullscreen"]'));
} }
let index = 0; let index = 0;
if (typeof options.index === "number") {
index = options.index
}
const editor = new Protyle(options.app, options.element.querySelector("[data-type='render']") as HTMLElement, { const editor = new Protyle(options.app, options.element.querySelector("[data-type='render']") as HTMLElement, {
blockId: "", blockId: "",
action: [Constants.CB_GET_ALL], action: [Constants.CB_GET_ALL],
@ -158,6 +162,7 @@ export const bindCardEvent = (options: {
} }
options.element.setAttribute("data-key", window.siyuan.config.keymap.general.riffCard.custom); options.element.setAttribute("data-key", window.siyuan.config.keymap.general.riffCard.custom);
const countElement = options.element.querySelector('[data-type="count"]'); const countElement = options.element.querySelector('[data-type="count"]');
countElement.innerHTML = `${options.index + 1}/${options.blocks.length}`;
const actionElements = options.element.querySelectorAll(".card__action"); const actionElements = options.element.querySelectorAll(".card__action");
const filterElement = options.element.querySelector('[data-type="filter"]'); const filterElement = options.element.querySelector('[data-type="filter"]');
const fetchNewRound = () => { const fetchNewRound = () => {
@ -210,7 +215,7 @@ export const bindCardEvent = (options: {
options.element.querySelector('[data-type="fullscreen"]')); options.element.querySelector('[data-type="fullscreen"]'));
resize(editor.protyle); resize(editor.protyle);
window.siyuan.storage[Constants.LOCAL_FLASHCARD].fullscreen = !window.siyuan.storage[Constants.LOCAL_FLASHCARD].fullscreen; window.siyuan.storage[Constants.LOCAL_FLASHCARD].fullscreen = !window.siyuan.storage[Constants.LOCAL_FLASHCARD].fullscreen;
setStorageVal(Constants.LOCAL_FLASHCARD, window.siyuan.storage[Constants.LOCAL_FLASHCARD]); setStorageVal(Constants.LOCAL_FLASHCARD, window.siyuan.storage[Constants.LOCAL_FLASHCARD]);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
@ -225,6 +230,8 @@ export const bindCardEvent = (options: {
icon: "iconRiffCard", icon: "iconRiffCard",
title: window.siyuan.languages.spaceRepetition, title: window.siyuan.languages.spaceRepetition,
data: { data: {
blocks: options.blocks,
index,
cardType: filterElement.getAttribute("data-cardtype") as TCardType, cardType: filterElement.getAttribute("data-cardtype") as TCardType,
id: filterElement.getAttribute("data-id"), id: filterElement.getAttribute("data-id"),
title: options.title title: options.title