|
@@ -0,0 +1,97 @@
|
|
|
+<template>
|
|
|
+ <CommonPage show-footer>
|
|
|
+ <template #action>
|
|
|
+ <NButton type="primary" @click="handleEdit">
|
|
|
+ 保存文章
|
|
|
+ </NButton>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <div class="editor-wrap">
|
|
|
+ <n-form ref="modalFormRef" class="form wh-full" label-placement="left" label-align="left" :label-width="80"
|
|
|
+ :model="modalForm">
|
|
|
+ <n-form-item label="文章名称" path="title" :rule="{
|
|
|
+ required: true,
|
|
|
+ message: '请输入文章名称',
|
|
|
+ trigger: ['input', 'blur'],
|
|
|
+ }">
|
|
|
+ <n-input v-model:value="modalForm.title" />
|
|
|
+ </n-form-item>
|
|
|
+
|
|
|
+ <n-form-item label="文章分类" path="categoryId" :rule="{
|
|
|
+ required: true,
|
|
|
+ type: 'number',
|
|
|
+ trigger: ['change', 'blur'],
|
|
|
+ message: '请输入文章分类',
|
|
|
+ }">
|
|
|
+ <n-select v-model:value="modalForm.categoryId" :options="allCategory" clearable filterable tag
|
|
|
+ style="max-width: 300px;" />
|
|
|
+ </n-form-item>
|
|
|
+
|
|
|
+ <VividEditor v-model="modalForm.content" :dark="isDark">
|
|
|
+ <SlashCommand />
|
|
|
+ <DragHandle />
|
|
|
+ </VividEditor>
|
|
|
+ </n-form>
|
|
|
+ </div>
|
|
|
+ </CommonPage>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { DragHandle, SlashCommand, VividEditor } from '@4dkankan/vivid'
|
|
|
+import { useUserStore } from '@/store/index.js'
|
|
|
+import { useDark } from '@vueuse/core'
|
|
|
+import { NButton, useThemeVars } from 'naive-ui'
|
|
|
+import { ref } from 'vue'
|
|
|
+import { useRoute, useRouter } from 'vue-router'
|
|
|
+import categoryApi from '../category/api'
|
|
|
+import articleApi from './api'
|
|
|
+import '@4dkankan/vivid/dist/style.css'
|
|
|
+
|
|
|
+const isDark = useDark()
|
|
|
+const vars = useThemeVars()
|
|
|
+const modalFormRef = ref('')
|
|
|
+const { userId } = useUserStore()
|
|
|
+const router = useRouter()
|
|
|
+const route = useRoute()
|
|
|
+const modalForm = ref({
|
|
|
+ title: '',
|
|
|
+ categoryId: null,
|
|
|
+ content: '',
|
|
|
+ userId,
|
|
|
+})
|
|
|
+
|
|
|
+onMounted(async () => {
|
|
|
+ console.log('edit', route.params.id)
|
|
|
+ const { data } = await articleApi.getOne(route.params.id)
|
|
|
+ if (data) {
|
|
|
+ modalForm.value = {
|
|
|
+ ...modalForm.value,
|
|
|
+ ...data,
|
|
|
+ userId,
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+const allCategory = ref([])
|
|
|
+categoryApi.getAll().then(({ data = [] }) => (allCategory.value = data.map(item => ({ label: item.title, value: item.id }))))
|
|
|
+
|
|
|
+function handleEdit() {
|
|
|
+ modalFormRef.value?.validate((errors) => {
|
|
|
+ if (!errors) {
|
|
|
+ articleApi.update(modalForm.value)
|
|
|
+ $message.success('保存成功!')
|
|
|
+ router.push('/article')
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $message.error('请填写对应项!')
|
|
|
+ console.log('errors', errors)
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style>
|
|
|
+.editor-wrap {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+}
|
|
|
+</style>
|