diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 6d845a0b4..fe8e96558 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1,4 +1,6 @@ { + "setDueTime": "设置到期时间", + "showCardDay": "要在多少天后显示卡片?", "forgetCount": "遗忘次数", "lastReviewTime": "最后复习时间", "cardStatus": "卡片状态", diff --git a/app/src/card/openCard.ts b/app/src/card/openCard.ts index 82cc7bc43..4637b8de4 100644 --- a/app/src/card/openCard.ts +++ b/app/src/card/openCard.ts @@ -61,6 +61,7 @@ export const genCardHTML = (options: { ${window.siyuan.languages.riffCard}
${genCardCount(options.cardsData)}
+ `; /// #else @@ -199,7 +200,6 @@ export const bindCardEvent = async (options: { }); } options.element.setAttribute("data-key", Constants.DIALOG_OPENCARD); - genCardCount(options.cardsData, index); const actionElements = options.element.querySelectorAll(".card__action"); if (options.index === 0) { actionElements[0].firstElementChild.setAttribute("disabled", "disabled"); @@ -210,7 +210,7 @@ export const bindCardEvent = async (options: { const filterElement = options.element.querySelector('[data-type="filter"]'); const fetchNewRound = () => { const currentCardType = filterElement.getAttribute("data-cardtype"); - const docId = filterElement.getAttribute("data-id"); + const docId = filterElement.getAttribute("data-id"); fetchPost(currentCardType === "all" ? "/api/riff/getRiffDueCards" : (currentCardType === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), { rootID: docId, @@ -236,11 +236,12 @@ export const bindCardEvent = async (options: { }); }; + countElement.innerHTML = genCardCount(options.cardsData, index); options.element.addEventListener("click", (event: MouseEvent) => { const target = event.target as HTMLElement; let type = ""; const currentCard = options.cardsData.cards[index]; - const docId = filterElement.getAttribute("data-id"); + const docId = filterElement.getAttribute("data-id"); if (typeof event.detail === "string") { if (["1", "j", "a"].includes(event.detail)) { type = "1"; @@ -280,26 +281,85 @@ export const bindCardEvent = async (options: { const menu = new Menu(); menu.addItem({ icon: "iconClock", - label: window.siyuan.languages.updatedTime, + label: window.siyuan.languages.setDueTime, click() { - - } - }); - menu.addItem({ - icon: "iconRefresh", - label: window.siyuan.languages.reset, - click() { - fetchPost("/api/riff/resetRiffCards", { - type: filterElement.getAttribute("data-cardtype"), - id: docId, - deckID: Constants.QUICK_DECK_ID, - blockIDs: [currentCard.blockID], - }, () => { - // currentCard. - // genCardCount(options.cardsData, index); + const dialog = new Dialog({ + title: window.siyuan.languages.setDueTime, + content: `
+
${window.siyuan.languages.showCardDay}
+
+ +
+
+
+ +
`, + width: isMobile() ? "92vw" : "520px", + }); + const inputElement = dialog.element.querySelector("input") as HTMLInputElement; + const btnsElement = dialog.element.querySelectorAll(".b3-button"); + dialog.bindInput(inputElement, () => { + (btnsElement[1] as HTMLButtonElement).click(); + }); + inputElement.focus(); + inputElement.select(); + btnsElement[0].addEventListener("click", () => { + dialog.destroy(); + }); + btnsElement[1].addEventListener("click", () => { + fetchPost("/api/riff/batchSetRiffCardsDueTime", { + cardDues: [{ + id: currentCard.blockID, + due: dayjs().day(parseInt(inputElement.value)).format("YYYYMMDDHHmmss") + }] + }, () => { + actionElements[0].classList.add("fn__none"); + actionElements[1].classList.remove("fn__none"); + if (currentCard.state === 0) { + options.cardsData.unreviewedNewCardCount--; + } else { + options.cardsData.unreviewedOldCardCount--; + } + options.element.dispatchEvent(new CustomEvent("click", {detail: "0"})); + options.cardsData.cards.splice(index, 1); + index--; + dialog.destroy(); + }); }); } }); + if (currentCard.state !== 0) { + menu.addItem({ + icon: "iconRefresh", + label: window.siyuan.languages.reset, + click() { + fetchPost("/api/riff/resetRiffCards", { + type: filterElement.getAttribute("data-cardtype"), + id: docId, + deckID: Constants.QUICK_DECK_ID, + blockIDs: [currentCard.blockID], + }, () => { + const minLang = window.siyuan.languages._time["1m"].replace("%s", "") + currentCard.lapses = 0; + currentCard.lastReview = -62135596800000; + currentCard.reps = 0; + currentCard.state = 0; + currentCard.nextDues = { + 1: minLang, + 2: minLang.replace("1", "5"), + 3: minLang.replace("1", "10"), + 4: window.siyuan.languages._time["1d"].replace("%s", "").replace("1", "6") + }; + actionElements[1].querySelectorAll(".b3-button").forEach((element, btnIndex) => { + element.previousElementSibling.textContent = currentCard.nextDues[btnIndex]; + }); + options.cardsData.unreviewedOldCardCount--; + options.cardsData.unreviewedNewCardCount++; + countElement.innerHTML = genCardCount(options.cardsData, index); + }); + } + }); + } menu.addItem({ icon: "iconTrashcan", label: `${window.siyuan.languages.remove} ${window.siyuan.languages.riffCard}`, @@ -329,28 +389,29 @@ export const bindCardEvent = async (options: {
${window.siyuan.languages.forgetCount}
${currentCard.lapses}
- -
+
${window.siyuan.languages.lastReviewTime}
${dayjs(currentCard.lastReview).format("YYYY-MM-DD")}
-
-
+
${window.siyuan.languages.revisionCount}
${currentCard.reps}
-
-
+
${window.siyuan.languages.cardStatus}
-
${window.siyuan.languages.cardStatus === 0 ? window.siyuan.languages.flashcardNewCard : window.siyuan.languages.flashcardReviewCard}
+
${currentCard.state === 0 ? window.siyuan.languages.flashcardNewCard : window.siyuan.languages.flashcardReviewCard}
`, }); + /// #if MOBILE + menu.fullscreen(); + /// #else const rect = target.getBoundingClientRect(); menu.open({ x: rect.left, y: rect.bottom }); + /// #endif return; } /// #if !MOBILE