完善请求
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: '',
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="system-user-search mb15">
|
||||
<el-form :inline="true">
|
||||
<el-form-item label="产品名称">
|
||||
<el-input size="default" v-model="tableData.param.productName" placeholder="请输入产品名称" class="w-50 m-2" clearable />
|
||||
<el-input size="default" v-model="tableData.param.name" placeholder="请输入产品名称" class="w-50 m-2" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button size="default" type="primary" class="ml10" @click="handleSearch">
|
||||
@@ -43,11 +43,19 @@
|
||||
<el-table-column prop="name" label="产品名称" show-overflow-tooltip />
|
||||
<el-table-column prop="creator" label="创建人" show-overflow-tooltip />
|
||||
<el-table-column prop="updater" label="修改人" show-overflow-tooltip />
|
||||
<el-table-column prop="createdAtString" label="创建时间" show-overflow-tooltip />
|
||||
<el-table-column prop="updatedAtString" label="修改时间" show-overflow-tooltip />
|
||||
<el-table-column prop="createdAtString" label="创建时间" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
{{ formatTime(row.createdAt) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="updatedAtString" label="修改时间" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
{{ formatTime(row.createdAt) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="220">
|
||||
<template #default="scope">
|
||||
<el-button size="small" text type="primary" @click="onOpenEditRole(scope.row)">
|
||||
<el-button style="color: deepskyblue" size="small" text type="primary" @click="onOpenEditRole(scope.row)">
|
||||
<el-icon><ele-EditPen /></el-icon>修改
|
||||
</el-button>
|
||||
<el-button size="small" text type="primary" @click="onRowDel(scope.row)">
|
||||
@@ -63,7 +71,7 @@
|
||||
:total="tableData.total"
|
||||
v-model:page="tableData.param.pageNum"
|
||||
v-model:limit="tableData.param.pageSize"
|
||||
@pagination="handlePaginationChange"
|
||||
@pagination="getProductList"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
@@ -104,7 +112,7 @@ interface ProductData {
|
||||
* 查询参数接口
|
||||
*/
|
||||
interface QueryParam {
|
||||
productName: string; // 产品名称
|
||||
name: string; // 产品名称
|
||||
roleStatus: string; // 状态
|
||||
pageNum: number; // 页码
|
||||
pageSize: number; // 每页大小
|
||||
@@ -130,7 +138,7 @@ const tableData = reactive<TableState>({
|
||||
total: 0,
|
||||
loading: false,
|
||||
param: {
|
||||
productName: '',
|
||||
name: '',
|
||||
roleStatus: '',
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
@@ -162,6 +170,49 @@ const getProductList = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// ==================== 时间处理函数 ====================
|
||||
/**
|
||||
* 格式化时间显示
|
||||
*/
|
||||
const formatTime = (time: string | number | Date): string => {
|
||||
if (!time) return '-';
|
||||
|
||||
try {
|
||||
let date: Date;
|
||||
|
||||
if (time instanceof Date) {
|
||||
date = time;
|
||||
} else if (typeof time === 'string') {
|
||||
date = new Date(time);
|
||||
} else {
|
||||
let timestamp = time;
|
||||
if (timestamp > 1000000000000) {
|
||||
// 已经是毫秒时间戳
|
||||
} else if (timestamp > 1000000000) {
|
||||
// 秒时间戳,转换为毫秒
|
||||
timestamp = timestamp * 1000;
|
||||
}
|
||||
date = new Date(timestamp);
|
||||
}
|
||||
|
||||
if (isNaN(date.getTime())) {
|
||||
return String(time);
|
||||
}
|
||||
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
} catch (error) {
|
||||
console.error('时间格式化错误:', error);
|
||||
return String(time);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 处理搜索
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user