feat: 完善编辑组件以及新增更新后的回调删除

This commit is contained in:
JaguarJack 2023-03-01 18:16:48 +08:00
parent 4d5d5c3121
commit 1e51e00840
2 changed files with 19 additions and 8 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<Editor :api-key="aipKey" :init="config" v-model="content" /> <Editor :api-key="aipKey" :init="config" v-model="content" v-bind="$attrs" />
</div> </div>
</template> </template>
@ -52,6 +52,7 @@ const props = defineProps({
], ],
}, },
}) })
const aipKey: string = 's1ntkmnev0ggx0hhaqnubrdxhv0ly99uyrdbckeaycx7iz6v' const aipKey: string = 's1ntkmnev0ggx0hhaqnubrdxhv0ly99uyrdbckeaycx7iz6v'
const uploaded = (blobInfo, progress) => const uploaded = (blobInfo, progress) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
@ -88,9 +89,18 @@ const config = {
const emits = defineEmits(['update:modelValue']) const emits = defineEmits(['update:modelValue'])
const content = ref(props.modelValue) const content = ref(props.modelValue)
//
watch(content, value => { watch(content, value => {
emits('update:modelValue', value) emits('update:modelValue', value)
}) })
//
watch(
() => props.modelValue,
value => {
content.value = value
},
)
</script> </script>
<style scoped> <style scoped>

View File

@ -19,7 +19,7 @@ export function useCreate(path: string, id: string | number | null = null, _form
const beforeUpdate = ref() const beforeUpdate = ref()
const afterCreate = ref() const afterCreate = ref()
const afterUpdate = ref()
// store // store
function store(path: string, id: string | number | null = null) { function store(path: string, id: string | number | null = null) {
loading.value = true loading.value = true
@ -43,12 +43,13 @@ export function useCreate(path: string, id: string | number | null = null, _form
if (r.data.code === Code.SUCCESS) { if (r.data.code === Code.SUCCESS) {
isClose.value = true isClose.value = true
Message.success(r.data.message) Message.success(r.data.message)
// 创建后的操作 // 创建后的操作
if (!id) { if (!id && isFunction(afterCreate.value)) {
if (isFunction(afterCreate.value)) {
afterCreate.value() afterCreate.value()
} }
// 更新后的操作
if (id && isFunction(afterUpdate.value)) {
afterUpdate.value()
} }
} else { } else {
Message.error(r.data.message) Message.error(r.data.message)
@ -81,5 +82,5 @@ export function useCreate(path: string, id: string | number | null = null, _form
}) })
} }
return { formData, loading, form, submitForm, close, beforeCreate, beforeUpdate, afterCreate } return { formData, loading, form, submitForm, close, beforeCreate, beforeUpdate, afterCreate, afterUpdate }
} }