优化代码结构

This commit is contained in:
WUSIJIAN
2025-12-05 15:45:14 +08:00
parent e41884fc60
commit 134ea96340
14 changed files with 67 additions and 75 deletions

View File

@@ -1,5 +1,5 @@
<template>
<div class="system-edit-role-container">
<div class="product-edit-dialog">
<el-dialog :title="(formData.id === 0 ? '添加' : '修改') + '产品'" v-model="isShowDialog" width="1000px">
<el-form ref="formRef" :model="formData" :rules="rules" size="default" label-width="90px">
<el-row :gutter="35">
@@ -35,7 +35,7 @@
<script lang="ts" setup>
import { ref, reactive, toRefs, nextTick } from 'vue';
import { ElMessage, type FormInstance, type FormRules } from 'element-plus';
import { getproductAdd, updateProduct } from '/@/api/customerService/product';
import { addProduct, updateProduct } from '/@/api/customerService/product';
import Editor from '/@/components/editor/index.vue';
/**
@@ -61,9 +61,9 @@ interface ComponentState {
// 定义组件事件
const emit = defineEmits<{
/**
* 获取产品列表事件 - 用于刷新父组件列表
* 刷新产品列表事件
*/
(e: 'getRoleList'): void;
(e: 'refresh'): void;
}>();
// 响应式状态
@@ -173,10 +173,8 @@ const onSubmit = async () => {
// 根据ID判断是新增还是修改
if (state.formData.id === 0) {
// 新增产品
await getproductAdd(state.formData).then((res) => {
ElMessage.success('产品添加成功');
});
await addProduct(state.formData);
ElMessage.success('产品添加成功');
} else {
// 修改产品
await updateProduct(state.formData);
@@ -185,7 +183,7 @@ const onSubmit = async () => {
// 关闭对话框并刷新列表
closeDialog();
emit('getRoleList');
emit('refresh');
} catch (error) {
console.error('提交失败:', error);
ElMessage.error(state.formData.id === 0 ? '添加失败' : '修改失败');