zc 3 months ago
parent fa8478d6e3
commit eb54315eb9
  1. 124
      web/src/views/system/question/index.vue
  2. 5
      web/vite.config.js

@ -57,10 +57,10 @@
<NFormItem label="状态" path="status">
<NSwitch
v-model:value="modalForm.status"
:checked-value="'1'"
:unchecked-value="'0'"
:checked-value="'0'"
:unchecked-value="'1'"
/>
<span class="ml-2">{{ modalForm.status === '1' ? '启用' : '停用' }}</span>
<span class="ml-2">{{ modalForm.status === '0' ? '启用' : '停用' }}</span>
</NFormItem>
<NFormItem
label="问题内容"
@ -86,7 +86,8 @@
</template>
<script setup>
import { h, onMounted, ref, resolveDirective, withDirectives, onUnmounted } from 'vue'
// 1watch
import { h, onMounted, ref, resolveDirective, withDirectives, onUnmounted, watch } from 'vue'
import {
NButton, NForm, NFormItem, NInput, NPopconfirm, NTag, NSwitch
} from 'naive-ui'
@ -112,7 +113,7 @@ const editorConfig = ref({
placeholder: '请输入问题内容...',
MENU_CONF: {
uploadImage: {
server: '/api/upload/image', // 使
server: '/api/upload/image',
fieldName: 'file',
maxFileSize: 2 * 1024 * 1024, // 2MB
headers: {
@ -120,7 +121,7 @@ const editorConfig = ref({
}
},
uploadVideo: {
server: '/api/upload/video', // 使
server: '/api/upload/video',
fieldName: 'file',
maxFileSize: 100 * 1024 * 1024, // 100MB
headers: {
@ -130,18 +131,31 @@ const editorConfig = ref({
}
})
//
const editorCreated = ref(false)
const handleEditorCreated = (editor) => {
editorRef.value = editor // editor
editorRef.value = editor
editorCreated.value = true //
}
//
//
onUnmounted(() => {
const editor = editorRef.value
if (editor) {
editor.destroy()
if (editorRef.value) {
editorRef.value.destroy()
editorRef.value = null
editorCreated.value = false
}
})
//
const getSafeEditor = () => {
if (editorCreated.value && editorRef.value) {
return editorRef.value
}
return null
}
const $table = ref(null)
const queryItems = ref({})
const vPermission = resolveDirective('permission')
@ -162,7 +176,7 @@ const {
initForm: {
title: '',
order_num: 0,
status: '0',
status: '0', //
content: ''
},
doCreate: api.createQuestion,
@ -171,6 +185,50 @@ const {
refresh: () => $table.value?.handleSearch(),
})
// 2使
// handleSave
const originalHandleSave = handleSave
// 3customHandleSave
const customHandleSave = async () => {
if (modalFormRef.value) {
try {
//
const editor = getSafeEditor()
if (editor) {
modalForm.value.content = editor.getHtml()
}
await modalFormRef.value.validate()
originalHandleSave()
} catch (error) {
console.error('验证失败:', error)
}
}
}
// 4handleEdit
const handleEdit = async (row) => {
originalHandleEdit(row);
try {
modalLoading.value = true;
const res = await api.getQuestion({ question_id: row.id });
if (res && res.data) {
modalForm.value = { ...res.data };
//
setTimeout(() => {
const editor = getSafeEditor()
if (editor) {
editor.setHtml(res.data.content || '')
}
}, 300)
}
} catch (error) {
console.error('获取问题详情失败:', error);
} finally {
modalLoading.value = false;
}
}
onMounted(() => {
$table.value?.handleSearch()
})
@ -270,26 +328,6 @@ const columns = [
},
},
]
// handleSave
const originalHandleSave = handleSave
// handleSave
const customHandleSave = async () => {
if (modalFormRef.value) {
try {
//
if (editorRef.value) {
modalForm.value.content = editorRef.value.getHtml()
}
await modalFormRef.value.validate()
originalHandleSave()
} catch (error) {
//
console.error('验证失败:', error)
}
}
}
// watch
watch(
() => modalForm.content,
@ -305,28 +343,6 @@ watch(
// immediate
{ immediate: true }
)
// handleEditAPI
const handleEdit = async (row) => {
originalHandleEdit(row);
try {
modalLoading.value = true;
// getQuestion API
const res = await api.getQuestion({ question_id: row.id });
if (res && res.data) {
// modalForm
modalForm.value = { ...res.data };
//
if (editorRef.value) {
//
editorRef.value.setHtml(res.data.content || '');
}
}
} catch (error) {
console.error('获取问题详情失败:', error);
} finally {
modalLoading.value = false;
}
}
</script>
<style scoped>

@ -31,11 +31,6 @@ export default defineConfig(({ command, mode }) => {
proxy: VITE_USE_PROXY
? {
[VITE_BASE_API]: PROXY_CONFIG[VITE_BASE_API],
// 添加对/api/upload路径的代理配置
'/api/upload': {
target: 'http://127.0.0.1:8111',
changeOrigin: true,
},
}
: undefined,
},

Loading…
Cancel
Save