实现接口部分功能
This commit is contained in:
@@ -35,8 +35,10 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, toRefs, nextTick } from 'vue';
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus';
|
||||
import { addRole, editRole, getRole } from '/@/api/system/role';
|
||||
import { getproductAdd, updateProduct, getproductOne } from '/@/api/customerService/product';
|
||||
import Editor from '/@/components/editor/index.vue';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import { log } from 'node:console';
|
||||
|
||||
/**
|
||||
* 产品表单数据接口
|
||||
@@ -44,10 +46,9 @@ import Editor from '/@/components/editor/index.vue';
|
||||
interface ProductFormData {
|
||||
id: number; // 产品ID
|
||||
name: string; // 产品名称
|
||||
status: number; // 状态:1-启用,0-禁用
|
||||
listOrder: number; // 排序
|
||||
remark: string; // 备注
|
||||
content?: string; // 产品详情(富文本内容)
|
||||
creator: '';
|
||||
modifier: '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,10 +75,9 @@ const state = reactive<ComponentState>({
|
||||
formData: {
|
||||
id: 0,
|
||||
name: '',
|
||||
status: 1,
|
||||
listOrder: 0,
|
||||
remark: '',
|
||||
content: '',
|
||||
creator: '',
|
||||
modifier: '',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -124,13 +124,11 @@ const openDialog = async (row?: ProductFormData) => {
|
||||
*/
|
||||
const handleEditMode = async (id: number) => {
|
||||
try {
|
||||
const res = await getRole(id);
|
||||
if (res.data?.role) {
|
||||
const res = await getproductOne({ id: id });
|
||||
if (res.data) {
|
||||
// 填充表单数据
|
||||
state.formData = {
|
||||
...res.data.role,
|
||||
content: res.data.role.content || '',
|
||||
};
|
||||
// state.formData = res.data;
|
||||
console.log(res.data, 'for');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取产品详情失败:', error);
|
||||
@@ -175,11 +173,14 @@ const onSubmit = async () => {
|
||||
// 根据ID判断是新增还是修改
|
||||
if (state.formData.id === 0) {
|
||||
// 新增产品
|
||||
await addRole(state.formData);
|
||||
state.formData.creator = Session.get('userInfo').userNickname;
|
||||
await getproductAdd(state.formData);
|
||||
ElMessage.success('产品添加成功');
|
||||
} else {
|
||||
// 修改产品
|
||||
await editRole(state.formData);
|
||||
state.formData.modifier = Session.get('userInfo').userNickname;
|
||||
|
||||
await updateProduct(state.formData);
|
||||
ElMessage.success('产品修改成功');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user