From 083d15646f631e90363f13559a3f1cb2b9185bcb Mon Sep 17 00:00:00 2001 From: Zyronon Date: Mon, 22 Dec 2025 00:48:20 +0800 Subject: [PATCH] wip --- src/apis/dict.ts | 8 +- src/pages/word/DictDetail.vue | 54 ++--- src/pages/word/WordsPage.vue | 358 ++++++++++++++++++++++------------ 3 files changed, 265 insertions(+), 155 deletions(-) diff --git a/src/apis/dict.ts b/src/apis/dict.ts index 8b9ccac2..b2449300 100644 --- a/src/apis/dict.ts +++ b/src/apis/dict.ts @@ -1,6 +1,10 @@ import http from '@/utils/http.ts' import { Dict } from '@/types/types.ts' -export function addDict(params?, data?) { - return http('dict/addDict', data, params, 'post') +export function copyOfficialDict(params?, data?) { + return http('dict/copyOfficialDict', data, params, 'post') +} + +export function deleteDict(params?, data?) { + return http('dict/delete', data, params, 'post') } diff --git a/src/pages/word/DictDetail.vue b/src/pages/word/DictDetail.vue index 4c5ac861..35098a90 100644 --- a/src/pages/word/DictDetail.vue +++ b/src/pages/word/DictDetail.vue @@ -38,6 +38,7 @@ import { nanoid } from 'nanoid' import { computed, onMounted, reactive, ref, watch } from 'vue' import { useRoute, useRouter } from 'vue-router' import { wordDelete } from '@/apis/words.ts' +import { copyOfficialDict } from '@/apis/dict.ts' const runtimeStore = useRuntimeStore() const base = useBaseStore() @@ -147,32 +148,33 @@ async function batchDel(ids: string[]) { syncDictInMyStudyList() } + let cloudHandle = async dictId => { + let res = await wordDelete(null, { + wordIds: ids, + dictId, + }) + if (res.success) { + tableRef.value.getData() + } else { + return Toast.error(res.msg ?? '删除失败') + } + } + if (AppEnv.CAN_REQUEST) { if (dict.custom) { if (dict.sync) { - let res = await wordDelete(null, { - wordIds: ids, - userDictId: dict?.userDictId, - dictId: dict.id, - }) - if (res.success) { - tableRef.value.getData() - } else { - return Toast.error(res.msg ?? '删除失败') - } + await cloudHandle(dict.id) } else { localHandle() } } else { - let r = await add2MyDict({ - id: dict.id, - perDayStudyNumber: dict.perDayStudyNumber, - lastLearnIndex: dict.lastLearnIndex, - complete: dict.complete, - }) - if (!r.success) return Toast.error(r.msg) - else { - dict.userDictId = r.data + let r = await copyOfficialDict(null, { id: dict.id }) + if (r.success) { + await cloudHandle(r.data.id) + getDetail(r.data.id) + } else { + //todo 权限判断,能否复制 + return Toast.error(r.msg) } } } else { @@ -255,11 +257,7 @@ onMounted(async () => { } if (base.word.bookList.find(book => book.id === runtimeStore.editDict.id)) { if (AppEnv.CAN_REQUEST) { - //todo 优化:这里只返回详情 - let res = await detail({ id: runtimeStore.editDict.id }) - if (res.success) { - runtimeStore.editDict.statistics = res.data.statistics - } + getDetail(runtimeStore.editDict.id) } } loading = false @@ -270,6 +268,14 @@ onMounted(async () => { tableRef.value.getData() }) +async function getDetail(id) { + //todo 优化:这里只返回详情 + let res = await detail({ id }) + if (res.success) { + runtimeStore.editDict = res.data + } +} + function formClose() { if (isEdit) isEdit = false else router.back() diff --git a/src/pages/word/WordsPage.vue b/src/pages/word/WordsPage.vue index e7574981..babba760 100644 --- a/src/pages/word/WordsPage.vue +++ b/src/pages/word/WordsPage.vue @@ -1,38 +1,45 @@