Skip to content

Commit 3a7270c

Browse files
committed
fix: data unexpected marked changed
1 parent e71824a commit 3a7270c

File tree

5 files changed

+24
-31
lines changed

5 files changed

+24
-31
lines changed

packages/hexon-web/src/components/editors/HCategoriesEditor.vue

+7-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { HBadge } from "@/ui/badge"
55
import { HInput } from "@/ui/input"
66
import { useThemeVars } from "@/ui/theme"
77
import { uniq } from "lodash-es"
8+
import { stringArrayEqual } from "~/utils/string"
89
const props = defineProps<{
910
availableCats: string[]
1011
categories: string[]
@@ -18,29 +19,19 @@ const allCategories = computed(() => {
1819
return uniq(categories.value.concat(props.availableCats)).sort()
1920
})
2021
watch(
21-
() => props.categories,
22-
(v) => {
23-
categories.value = v
24-
},
25-
{
26-
deep: true,
22+
() => [...props.categories],
23+
(v, old) => {
24+
if (!stringArrayEqual(v, old)) categories.value = v
2725
}
2826
)
2927
watch(
30-
() => categories.value,
31-
(v) => {
32-
emits("update:categories", v)
33-
},
34-
{
35-
deep: true,
28+
() => [...categories.value],
29+
(v, old) => {
30+
if (!stringArrayEqual(v, old)) emits("update:categories", v)
3631
}
3732
)
38-
// setTimeout(() => {
39-
// categories.value.push("1")
40-
// }, 1000)
4133
const onNewCat = () => {
4234
if (newCat.value) {
43-
// categories.value = [newCat.value]
4435
categories.value.push(newCat.value)
4536
newCat.value = ""
4637
}

packages/hexon-web/src/components/editors/HMonacoEditor.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ onMounted(() => {
3030
3131
resetModal()
3232
instance.onDidChangeModelContent(() => {
33-
emits("update:value", instance.getValue())
33+
const newValue = instance.getValue()
34+
if (newValue !== props.value) emits("update:value", newValue)
3435
})
3536
3637
setTimeout(() => {

packages/hexon-web/src/components/editors/HTagEditor.vue

+7-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { HInput } from "@/ui/input"
55
import { HIcon, HIconName } from "@/ui/icon"
66
import { HBadge } from "@/ui/badge"
77
import { useThemeVars } from "@/ui/theme"
8+
89
const props = defineProps<{
910
availableTags: string[]
1011
tags: string[]
@@ -17,21 +18,15 @@ const newTag = ref("")
1718
1819
const tags = ref<string[]>(props.tags)
1920
watch(
20-
() => props.tags,
21-
(ts) => {
22-
tags.value = ts
23-
},
24-
{
25-
deep: true,
21+
() => [...props.tags],
22+
(ts, old) => {
23+
if (ts.join("") !== old.join("")) tags.value = ts
2624
}
2725
)
2826
watch(
29-
() => tags.value,
30-
(ts) => {
31-
emits("update:tags", ts)
32-
},
33-
{
34-
deep: true,
27+
() => [...tags.value],
28+
(ts, old) => {
29+
if (ts.join("") !== old.join("")) emits("update:tags", ts)
3530
}
3631
)
3732
const allTags = computed(() => {
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function stringArrayEqual(n: string[], o: string[]) {
2+
return n.join("") === o.join("")
3+
}

packages/hexon-web/src/views/EditorView.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import HToolbar from "@/HToolbar.vue"
2020
import HLayoutEditor from "@/editors/HLayoutEditor.vue"
2121
import HNavTitle from "@/ui/nav-list/src/HNavTitle.vue"
2222
import ErroredView from "./ErroredView.vue"
23-
import dayjs from "dayjs"
24-
import HDatePicker from "~/components/ui/date-picker/src/HDatePicker.vue"
2523
2624
const [HMonacoEditor, monacoLoading] = useAsyncComponentWithLoading(
2725
() => import("@/editors/HMonacoEditor.vue")
@@ -104,18 +102,23 @@ const updateFromObj = (obj: any) => {
104102
setChanged()
105103
}
106104
const updateTitle = (title: string = "") => {
105+
console.log("updateTitle")
107106
updateFromObj({ title })
108107
}
109108
const updateContent = (_content: string) => {
109+
console.log("updateContent")
110110
updateFromObj({ _content })
111111
}
112112
const updateTags = (tags: string[] = []) => {
113+
console.log("updateTags")
113114
updateFromObj({ tags })
114115
}
115116
const updateCategories = (categories: string[] = []) => {
117+
console.log("updateCategories")
116118
updateFromObj({ categories })
117119
}
118120
const updateLayout = (layout: string = "") => {
121+
console.log("updateLayout")
119122
updateFromObj({ layout })
120123
}
121124
//#endregion

0 commit comments

Comments
 (0)