UnisKB/ui/src/views/paragraph/component/ParagraphDialog.vue

136 lines
3.6 KiB
Vue
Raw Normal View History

2023-11-14 10:12:55 +00:00
<template>
<el-dialog
:title="title"
v-model="dialogVisible"
width="800"
class="paragraph-dialog"
destroy-on-close
>
2023-11-15 06:27:25 +00:00
<el-row v-loading="loading">
2023-11-14 10:12:55 +00:00
<el-col :span="16" class="p-24">
2023-11-15 06:27:25 +00:00
<el-scrollbar>
<div style="height: 350px">
<div class="flex-between mb-16">
<div class="bold title align-center">分段内容</div>
<el-button text @click="isEdit = true" v-if="problemId && !isEdit">
<el-icon><EditPen /></el-icon>
</el-button>
</div>
2023-11-14 10:12:55 +00:00
2023-11-15 06:27:25 +00:00
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="isEdit" />
</div>
<div class="text-right" v-if="problemId && isEdit">
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
<el-button type="primary" :disabled="loading" @click="submitHandle"> </el-button>
</div>
</el-scrollbar>
2023-11-14 10:12:55 +00:00
</el-col>
<el-col :span="8" class="border-l p-24">
2023-11-15 06:27:25 +00:00
<!-- 关联问题 -->
<ProblemComponent :problemId="problemId" ref="ProblemRef" />
2023-11-14 10:12:55 +00:00
</el-col>
</el-row>
2023-11-15 06:27:25 +00:00
<template #footer v-if="!problemId">
<span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
<el-button type="primary" @click="submitHandle"> </el-button>
</span>
</template>
2023-11-14 10:12:55 +00:00
</el-dialog>
</template>
<script setup lang="ts">
2023-11-15 06:27:25 +00:00
import { ref, watch, nextTick } from 'vue'
2023-11-14 10:12:55 +00:00
import { useRoute } from 'vue-router'
import ParagraphForm from '@/views/paragraph/component/ParagraphForm.vue'
2023-11-15 06:27:25 +00:00
import ProblemComponent from '@/views/paragraph/component/ProblemComponent.vue'
2023-11-22 10:37:08 +00:00
import paragraphApi from '@/api/paragraph'
2023-11-14 10:12:55 +00:00
import useStore from '@/stores'
const props = defineProps({
title: String
})
const { paragraph } = useStore()
const route = useRoute()
const {
2023-11-24 11:02:52 +00:00
params: { id, documentId }
2023-11-14 10:12:55 +00:00
} = route as any
const emit = defineEmits(['refresh'])
2023-11-15 06:27:25 +00:00
const ProblemRef = ref()
2023-11-17 03:36:16 +00:00
const paragraphFormRef = ref<any>()
2023-11-14 10:12:55 +00:00
const dialogVisible = ref<boolean>(false)
const loading = ref(false)
2023-11-15 06:27:25 +00:00
const problemId = ref('')
2023-11-14 10:12:55 +00:00
const detail = ref<any>({})
const isEdit = ref(false)
watch(dialogVisible, (bool) => {
if (!bool) {
2023-11-15 06:27:25 +00:00
problemId.value = ''
2023-11-14 10:12:55 +00:00
detail.value = {}
isEdit.value = false
}
})
const open = (data: any) => {
if (data) {
detail.value.title = data.title
detail.value.content = data.content
2023-11-15 06:27:25 +00:00
problemId.value = data.id
} else {
2023-11-14 10:12:55 +00:00
isEdit.value = true
}
dialogVisible.value = true
}
const submitHandle = async () => {
if (await paragraphFormRef.value?.validate()) {
2023-11-15 06:27:25 +00:00
if (problemId.value) {
2023-11-14 10:12:55 +00:00
paragraph
2023-12-15 03:04:10 +00:00
.asyncPutParagraph(id, documentId, problemId.value, paragraphFormRef.value?.form, loading)
2023-12-07 07:22:07 +00:00
.then((res: any) => {
emit('refresh', res.data)
2023-12-05 11:21:13 +00:00
isEdit.value = false
2023-11-14 10:12:55 +00:00
})
} else {
2023-11-15 06:27:25 +00:00
const obj =
ProblemRef.value.problemList.length > 0
? {
problem_list: ProblemRef.value.problemList,
...paragraphFormRef.value?.form
}
: paragraphFormRef.value?.form
2023-12-15 03:04:10 +00:00
paragraphApi.postParagraph(id, documentId, obj, loading).then((res) => {
emit('refresh')
dialogVisible.value = false
})
2023-11-14 10:12:55 +00:00
}
}
}
defineExpose({ open })
</script>
<style lang="scss" scope>
.paragraph-dialog {
.el-dialog__header {
padding-bottom: 16px;
}
.el-dialog__body {
border-top: 1px solid var(--el-border-color);
padding: 0 !important;
}
2023-11-15 06:27:25 +00:00
.el-dialog__footer {
padding-top: 16px;
border-top: 1px solid var(--el-border-color);
}
2023-11-14 10:12:55 +00:00
.title {
color: var(--app-text-color);
}
}
</style>