-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathParagraphDialog.vue
More file actions
185 lines (170 loc) · 5.19 KB
/
ParagraphDialog.vue
File metadata and controls
185 lines (170 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<template>
<el-dialog
:title="title"
v-model="dialogVisible"
width="80%"
class="paragraph-dialog"
destroy-on-close
:close-on-click-modal="false"
:close-on-press-escape="false"
@click.stop
>
<el-row v-loading="loading">
<el-col :span="18">
<el-scrollbar height="500" wrap-class="paragraph-scrollbar">
<div class="p-24" style="padding-bottom: 8px">
<div style="position: absolute; right: 20px; top: 20px">
<el-button text @click="isEdit = true" v-if="paragraphId && !isEdit">
<AppIcon iconName="app-edit"></AppIcon>
</el-button>
</div>
<ParagraphForm
ref="paragraphFormRef"
:data="detail"
:isEdit="isEdit"
:knowledge-id="id"
/>
</div>
</el-scrollbar>
<div class="text-right p-24 pt-0" v-if="paragraphId && isEdit">
<el-button @click.prevent="cancelEdit"> {{ $t('common.cancel') }} </el-button>
<el-button type="primary" :disabled="loading" @click="handleDebounceClick">
{{ $t('common.save') }}
</el-button>
</div>
</el-col>
<el-col :span="6" class="border-l" style="width: 300px">
<!-- 关联问题 -->
<ProblemComponent
v-if="permissionPrecise.problem_read(id)"
:paragraphId="paragraphId"
:docId="document_id"
:knowledgeId="id"
:apiType="apiType"
ref="ProblemRef"
/>
</el-col>
</el-row>
<template #footer v-if="!paragraphId">
<span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false"> {{ $t('common.cancel') }} </el-button>
<el-button :disabled="loading" type="primary" @click="handleDebounceClick">
{{ $t('common.submit') }}
</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, watch, nextTick, computed } from 'vue'
import { useRoute } from 'vue-router'
import { cloneDeep, debounce } from 'lodash'
import ParagraphForm from '@/views/paragraph/component/ParagraphForm.vue'
import ProblemComponent from '@/views/paragraph/component/ProblemComponent.vue'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import permissionMap from '@/permission'
const props = defineProps<{
title: String
apiType: 'systemShare' | 'workspace' | 'systemManage'
}>()
const route = useRoute()
const {
params: { id, documentId },
} = route as any
const apiType = computed(() => {
if (route.path.includes('shared')) {
return 'systemShare'
} else if (route.query.from == 'systemManage') {
return 'systemManage'
} else {
return 'workspace'
}
})
const permissionPrecise = computed(() => {
return permissionMap['knowledge'][apiType.value]
})
const emit = defineEmits(['refresh'])
const ProblemRef = ref()
const paragraphFormRef = ref<any>()
const dialogVisible = ref<boolean>(false)
const loading = ref(false)
const paragraphId = ref('')
const detail = ref<any>({})
const isEdit = ref(false)
const document_id = ref('')
const dataset_id = ref('')
const cloneData = ref(null)
const position = ref(null)
watch(dialogVisible, (bool) => {
if (!bool) {
paragraphId.value = ''
detail.value = {}
isEdit.value = false
document_id.value = ''
dataset_id.value = ''
cloneData.value = null
}
})
const cancelEdit = () => {
isEdit.value = false
detail.value = cloneDeep(cloneData.value)
}
const open = (data: any, str: any) => {
if (data && !str) {
detail.value.title = data.title
detail.value.content = data.content
cloneData.value = cloneDeep(detail.value)
paragraphId.value = data.id
document_id.value = data.document_id
dataset_id.value = data.dataset_id || id
} else {
isEdit.value = true
if (str === 'add') {
position.value = data.position
}
}
dialogVisible.value = true
}
const submitHandle = async () => {
if (await paragraphFormRef.value?.validate()) {
loading.value = true
if (paragraphId.value) {
loadSharedApi({ type: 'paragraph', systemType: props.apiType })
.putParagraph(
dataset_id.value,
documentId || document_id.value,
paragraphId.value,
paragraphFormRef.value?.form,
loading,
)
.then((res: any) => {
isEdit.value = false
emit('refresh', res.data)
})
} else {
const obj =
ProblemRef.value.problemList.length > 0
? {
position: String(position.value) ? position.value : null,
problem_list: ProblemRef.value.problemList,
...paragraphFormRef.value?.form,
}
: {
position: String(position.value) ? position.value : null,
...paragraphFormRef.value?.form,
}
loadSharedApi({ type: 'paragraph', systemType: props.apiType })
.postParagraph(id, documentId, obj, loading)
.then(() => {
dialogVisible.value = false
emit('refresh')
})
}
}
}
const handleDebounceClick = debounce(() => {
submitHandle()
}, 200)
defineExpose({ open, dialogVisible })
</script>
<style lang="scss" scoped></style>