完善请求
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
<!-- 富文本编辑器 -->
|
||||
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
||||
<el-form-item label="产品详情" prop="content">
|
||||
<Editor v-model="formData.content" height="400px" placeholder="请输入产品详细描述..." />
|
||||
<Editor v-model="formData.description" height="400px" placeholder="请输入产品详细描述..." />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -35,10 +35,8 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, toRefs, nextTick } from 'vue';
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus';
|
||||
import { getproductAdd, updateProduct, getproductOne } from '/@/api/customerService/product';
|
||||
import { getproductAdd, updateProduct } from '/@/api/customerService/product';
|
||||
import Editor from '/@/components/editor/index.vue';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import { log } from 'node:console';
|
||||
|
||||
/**
|
||||
* 产品表单数据接口
|
||||
@@ -46,7 +44,7 @@ import { log } from 'node:console';
|
||||
interface ProductFormData {
|
||||
id: number; // 产品ID
|
||||
name: string; // 产品名称
|
||||
content?: string; // 产品详情(富文本内容)
|
||||
description: string; // 产品详情(富文本内容)
|
||||
creator: '';
|
||||
modifier: '';
|
||||
}
|
||||
@@ -75,7 +73,7 @@ const state = reactive<ComponentState>({
|
||||
formData: {
|
||||
id: 0,
|
||||
name: '',
|
||||
content: '',
|
||||
description: '',
|
||||
creator: '',
|
||||
modifier: '',
|
||||
},
|
||||
@@ -87,7 +85,7 @@ const rules: FormRules = {
|
||||
{ required: true, message: '产品名称不能为空', trigger: 'blur' },
|
||||
{ min: 2, max: 50, message: '产品名称长度在 2 到 50 个字符', trigger: 'blur' },
|
||||
],
|
||||
content: [{ required: true, message: '产品详情不能为空', trigger: 'blur' }],
|
||||
description: [{ required: true, message: '产品详情不能为空', trigger: 'blur' }],
|
||||
};
|
||||
|
||||
// 模板引用
|
||||
@@ -107,7 +105,7 @@ const openDialog = async (row?: ProductFormData) => {
|
||||
try {
|
||||
if (row && row.id) {
|
||||
// 编辑模式:获取产品详情
|
||||
await handleEditMode(row.id);
|
||||
await handleEditMode(row);
|
||||
}
|
||||
|
||||
// 显示对话框
|
||||
@@ -122,14 +120,13 @@ const openDialog = async (row?: ProductFormData) => {
|
||||
* 处理编辑模式的数据获取
|
||||
* @param id - 产品ID
|
||||
*/
|
||||
const handleEditMode = async (id: number) => {
|
||||
const handleEditMode = async (row) => {
|
||||
try {
|
||||
const res = await getproductOne({ id: id });
|
||||
if (res.data) {
|
||||
// 填充表单数据
|
||||
// state.formData.content=
|
||||
console.log(res.data, 'for');
|
||||
}
|
||||
state.formData.id = row.id;
|
||||
state.formData.description = row.description;
|
||||
state.formData.name = row.name;
|
||||
|
||||
console.log(row, '编辑');
|
||||
} catch (error) {
|
||||
console.error('获取产品详情失败:', error);
|
||||
throw new Error('获取产品详情失败');
|
||||
@@ -167,14 +164,13 @@ const onSubmit = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置加载状态
|
||||
state.loading = true;
|
||||
|
||||
// 根据ID判断是新增还是修改
|
||||
if (state.formData.id === 0) {
|
||||
// 新增产品
|
||||
await getproductAdd(state.formData);
|
||||
ElMessage.success('产品添加成功');
|
||||
|
||||
await getproductAdd(state.formData).then((res) => {
|
||||
ElMessage.success('产品添加成功');
|
||||
});
|
||||
} else {
|
||||
// 修改产品
|
||||
await updateProduct(state.formData);
|
||||
@@ -200,7 +196,7 @@ const resetForm = () => {
|
||||
state.formData = {
|
||||
id: 0,
|
||||
name: '',
|
||||
content: '',
|
||||
description: '',
|
||||
creator: '',
|
||||
modifier: '',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user