diff --git a/src/admin/problem/detail.vue b/src/admin/problem/detail.vue index 34e07f9..e91f7f0 100644 --- a/src/admin/problem/detail.vue +++ b/src/admin/problem/detail.vue @@ -91,16 +91,7 @@ const problem = useLocalStorage(STORAGE_KEY.ADMIN_PROBLEM, { // 从服务器来的tag列表 const tagList = shallowRef([]) -interface Tags { - select: string[] - upload: string[] -} -// 从 tagList 中选择的 和 新上传的 -const tags = useLocalStorage(STORAGE_KEY.ADMIN_PROBLEM_TAGS, { - select: [], - upload: [], -}) -const tagKeyword = ref("") +const tagValue = ref([]) // 这几个用的少,就不缓存本地了 const [needTemplate, toggleNeedTemplate] = useToggle(false) @@ -126,34 +117,9 @@ const languageOptions = [ { label: LANGUAGE_SHOW_VALUE["C++"], value: "C++" }, ] - -const filteredTagList = computed(() => { - const keyword = tagKeyword.value.trim().toLowerCase() - if (!keyword) return tagList.value - return tagList.value.filter((tag) => tag.name.toLowerCase().includes(keyword)) -}) - -const selectedTagSet = computed(() => new Set(tags.value.select)) - -function toggleExistingTag(tagName: string) { - const selected = new Set(tags.value.select) - if (selected.has(tagName)) { - selected.delete(tagName) - } else { - selected.add(tagName) - } - tags.value.select = Array.from(selected) -} - -function selectFilteredTags() { - const selected = new Set(tags.value.select) - filteredTagList.value.forEach((tag) => selected.add(tag.name)) - tags.value.select = Array.from(selected) -} - -function clearExistingTags() { - tags.value.select = [] -} +const tagOptions = computed(() => + tagList.value.map((tag) => ({ label: tag.name, value: tag.name })) +) async function getProblemDetail() { if (!props.problemID) { @@ -213,7 +179,7 @@ async function getProblemDetail() { } }) // 标签 - tags.value.select = data.tags + tagValue.value = data.tags toggleReady(true) } catch (error) { message.error("获取题目失败") @@ -226,22 +192,6 @@ async function getTagList() { tagList.value = res.data } -function updateNewTags(v: string[]) { - const blanks = [] - const uniqueTags = unique(v) - const items = tagList.value.map((t) => t.name) - for (let i = 0; i < uniqueTags.length; i++) { - const tag = uniqueTags[i] - if (items.indexOf(tag) < 0) { - blanks.push(tag) - } else { - message.error("已经存在标签:" + tag) - break - } - } - tags.value.upload = blanks -} - function addSample() { problem.value.samples.push({ input: "", output: "" }) } @@ -291,7 +241,7 @@ async function validateProblem() { hasErrors = true } // 标签 - else if (tags.value.upload.length === 0 && tags.value.select.length === 0) { + else if (tagValue.value.length === 0) { message.error("标签没有填写") hasErrors = true } @@ -394,7 +344,7 @@ async function submit() { try { await api!(problem.value) problem.value = null - tags.value = null + tagValue.value = [] if ( route.name === "admin problem create" || route.name === "admin contest problem create" @@ -429,7 +379,7 @@ const showClear = computed( function clear() { problem.value = null - tags.value = null + tagValue.value = [] // 为了给所有状态初始化,刷新页面 location.reload() } @@ -449,13 +399,9 @@ onMounted(() => { getProblemDetail() }) -watch( - () => [tags.value.select, tags.value.upload], - (tags) => { - const uniqueTags = unique(tags[0].concat(tags[1])) - problem.value.tags = uniqueTags - }, -) +watch(tagValue, (val) => { + problem.value.tags = val +}) watch( () => problem.value.languages, (langs) => { @@ -493,67 +439,17 @@ watch( - - - - - - -
- - - - 全选当前 - - - 清空 - - - - - - - {{ tag.name }} - - - -
-
-
- - -
- - - 只填写标签库里还没有的标签;已有标签请在左侧点击选择。 - -
-
-
-
+ + +