feat:【mall 商城】商品评论的迁移(ele)
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
import type { VxeGridPropTypes } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { MallCommentApi } from '#/api/mall/product/comment';
|
import type { MallCommentApi } from '#/api/mall/product/comment';
|
||||||
|
|
||||||
|
import { z } from '#/adapter/form';
|
||||||
import { getSpuSimpleList } from '#/api/mall/product/spu';
|
import { getSpuSimpleList } from '#/api/mall/product/spu';
|
||||||
import { getRangePickerDefaultProps } from '#/utils';
|
import { getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
show: () => false,
|
show: () => false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// TODO @puhui999:商品的选择
|
||||||
{
|
{
|
||||||
fieldName: 'spuId',
|
fieldName: 'spuId',
|
||||||
label: '商品',
|
label: '商品',
|
||||||
@@ -24,6 +26,20 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
api: getSpuSimpleList,
|
api: getSpuSimpleList,
|
||||||
labelField: 'name',
|
labelField: 'name',
|
||||||
valueField: 'id',
|
valueField: 'id',
|
||||||
|
placeholder: '请选择商品',
|
||||||
|
},
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldName: 'skuId',
|
||||||
|
label: '商品规格',
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择商品规格',
|
||||||
|
},
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: ['spuId'],
|
||||||
|
show: (values) => !!values.spuId,
|
||||||
},
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
@@ -31,31 +47,47 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
fieldName: 'userAvatar',
|
fieldName: 'userAvatar',
|
||||||
label: '用户头像',
|
label: '用户头像',
|
||||||
component: 'ImageUpload',
|
component: 'ImageUpload',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请上传用户头像',
|
||||||
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'userNickname',
|
fieldName: 'userNickname',
|
||||||
label: '用户名称',
|
label: '用户名称',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入用户名称',
|
||||||
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'content',
|
fieldName: 'content',
|
||||||
label: '评论内容',
|
label: '评论内容',
|
||||||
component: 'Textarea',
|
component: 'Textarea',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入评论内容',
|
||||||
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
|
// TODO @xingyu:无法使用 Rate 组件,会报 TypeError: Cannot read properties of undefined (reading 'prefixCls')
|
||||||
{
|
{
|
||||||
fieldName: 'descriptionScores',
|
fieldName: 'descriptionScores',
|
||||||
label: '描述星级',
|
label: '描述星级',
|
||||||
component: 'Rate',
|
component: 'InputNumber',
|
||||||
rules: 'required',
|
componentProps: {
|
||||||
|
placeholder: '请选择描述星级',
|
||||||
|
},
|
||||||
|
rules: z.number().min(1).max(5).default(5),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'benefitScores',
|
fieldName: 'benefitScores',
|
||||||
label: '服务星级',
|
label: '服务星级',
|
||||||
component: 'Rate',
|
component: 'InputNumber',
|
||||||
rules: 'required',
|
componentProps: {
|
||||||
|
placeholder: '请选择服务星级',
|
||||||
|
},
|
||||||
|
rules: z.number().min(1).max(5).default(5),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'picUrls',
|
fieldName: 'picUrls',
|
||||||
@@ -63,6 +95,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
component: 'ImageUpload',
|
component: 'ImageUpload',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
maxNumber: 9,
|
maxNumber: 9,
|
||||||
|
placeholder: '请上传评论图片',
|
||||||
},
|
},
|
||||||
rules: 'required',
|
rules: 'required',
|
||||||
},
|
},
|
||||||
@@ -81,22 +114,36 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||||||
{ label: '已回复', value: true },
|
{ label: '已回复', value: true },
|
||||||
{ label: '未回复', value: false },
|
{ label: '未回复', value: false },
|
||||||
],
|
],
|
||||||
|
placeholder: '请选择回复状态',
|
||||||
|
allowClear: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'spuName',
|
fieldName: 'spuName',
|
||||||
label: '商品名称',
|
label: '商品名称',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入商品名称',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'userNickname',
|
fieldName: 'userNickname',
|
||||||
label: '用户名称',
|
label: '用户名称',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入用户名称',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'orderId',
|
fieldName: 'orderId',
|
||||||
label: '订单编号',
|
label: '订单编号',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入订单编号',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'createTime',
|
fieldName: 'createTime',
|
||||||
@@ -110,23 +157,24 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 表格列配置 */
|
/** 列表的字段 */
|
||||||
// TODO @xingyu:列表的宽度需要优化下,样式~
|
|
||||||
export function useGridColumns<T = MallCommentApi.Comment>(
|
export function useGridColumns<T = MallCommentApi.Comment>(
|
||||||
onStatusChange?: (
|
onStatusChange?: (
|
||||||
newStatus: boolean,
|
newStatus: boolean,
|
||||||
row: T,
|
row: T,
|
||||||
) => PromiseLike<boolean | undefined>,
|
) => PromiseLike<boolean | undefined>,
|
||||||
): VxeGridPropTypes.Columns {
|
): VxeTableGridOptions['columns'] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '评论编号',
|
title: '评论编号',
|
||||||
fixed: 'left',
|
fixed: 'left',
|
||||||
|
minWidth: 80,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'skuPicUrl',
|
field: 'skuPicUrl',
|
||||||
title: '商品图片',
|
title: '商品图片',
|
||||||
|
minWidth: 100,
|
||||||
cellRender: {
|
cellRender: {
|
||||||
name: 'CellImage',
|
name: 'CellImage',
|
||||||
},
|
},
|
||||||
@@ -134,7 +182,7 @@ export function useGridColumns<T = MallCommentApi.Comment>(
|
|||||||
{
|
{
|
||||||
field: 'spuName',
|
field: 'spuName',
|
||||||
title: '商品名称',
|
title: '商品名称',
|
||||||
minWidth: 200,
|
minWidth: 250,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'skuProperties',
|
field: 'skuProperties',
|
||||||
@@ -151,22 +199,27 @@ export function useGridColumns<T = MallCommentApi.Comment>(
|
|||||||
{
|
{
|
||||||
field: 'userNickname',
|
field: 'userNickname',
|
||||||
title: '用户名称',
|
title: '用户名称',
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'descriptionScores',
|
field: 'descriptionScores',
|
||||||
title: '商品评分',
|
title: '商品评分',
|
||||||
|
minWidth: 90,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'benefitScores',
|
field: 'benefitScores',
|
||||||
title: '服务评分',
|
title: '服务评分',
|
||||||
|
minWidth: 90,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'content',
|
field: 'content',
|
||||||
title: '评论内容',
|
title: '评论内容',
|
||||||
|
minWidth: 210,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'picUrls',
|
field: 'picUrls',
|
||||||
title: '评论图片',
|
title: '评论图片',
|
||||||
|
minWidth: 120,
|
||||||
cellRender: {
|
cellRender: {
|
||||||
name: 'CellImages',
|
name: 'CellImages',
|
||||||
},
|
},
|
||||||
@@ -174,15 +227,18 @@ export function useGridColumns<T = MallCommentApi.Comment>(
|
|||||||
{
|
{
|
||||||
field: 'replyContent',
|
field: 'replyContent',
|
||||||
title: '回复内容',
|
title: '回复内容',
|
||||||
|
minWidth: 250,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'createTime',
|
field: 'createTime',
|
||||||
title: '评论时间',
|
title: '评论时间',
|
||||||
|
minWidth: 180,
|
||||||
formatter: 'formatDateTime',
|
formatter: 'formatDateTime',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'visible',
|
field: 'visible',
|
||||||
title: '是否展示',
|
title: '是否展示',
|
||||||
|
minWidth: 110,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
cellRender: {
|
cellRender: {
|
||||||
attrs: { beforeChange: onStatusChange },
|
attrs: { beforeChange: onStatusChange },
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const [FormModal, formModalApi] = useVbenModal({
|
|||||||
});
|
});
|
||||||
|
|
||||||
/** 刷新表格 */
|
/** 刷新表格 */
|
||||||
function onRefresh() {
|
function handleRefresh() {
|
||||||
gridApi.query();
|
gridApi.query();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,9 @@ function handleCreate() {
|
|||||||
function handleReply(row: MallCommentApi.Comment) {
|
function handleReply(row: MallCommentApi.Comment) {
|
||||||
prompt({
|
prompt({
|
||||||
component: () => {
|
component: () => {
|
||||||
return h(Textarea, {});
|
return h(Textarea, {
|
||||||
|
placeholder: '请输入回复内容',
|
||||||
|
});
|
||||||
},
|
},
|
||||||
content: row.content
|
content: row.content
|
||||||
? `用户评论:${row.content}\n请输入回复内容:`
|
? `用户评论:${row.content}\n请输入回复内容:`
|
||||||
@@ -48,10 +50,10 @@ function handleReply(row: MallCommentApi.Comment) {
|
|||||||
}).then(async (val) => {
|
}).then(async (val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
await replyComment({
|
await replyComment({
|
||||||
id: row.id as number,
|
id: row.id!,
|
||||||
replyContent: val,
|
replyContent: val,
|
||||||
});
|
});
|
||||||
onRefresh();
|
handleRefresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -64,12 +66,12 @@ async function handleStatusChange(
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const text = newStatus ? '展示' : '隐藏';
|
const text = newStatus ? '展示' : '隐藏';
|
||||||
confirm({
|
confirm({
|
||||||
content: `确认要${text + row.id}评论吗?`,
|
content: `确认要${text}该评论吗?`,
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
// 更新状态
|
// 更新状态
|
||||||
const res = await updateCommentVisible({
|
const res = await updateCommentVisible({
|
||||||
id: row.id as number,
|
id: row.id!,
|
||||||
visible: newStatus,
|
visible: newStatus,
|
||||||
});
|
});
|
||||||
if (res) {
|
if (res) {
|
||||||
@@ -107,6 +109,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
},
|
},
|
||||||
rowConfig: {
|
rowConfig: {
|
||||||
keyField: 'id',
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
},
|
},
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
refresh: true,
|
refresh: true,
|
||||||
@@ -124,7 +127,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
url="https://doc.iocoder.cn/mall/product-comment/"
|
url="https://doc.iocoder.cn/mall/product-comment/"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<FormModal @success="onRefresh" />
|
<FormModal @success="handleRefresh" />
|
||||||
<Grid table-title="评论列表">
|
<Grid table-title="评论列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<TableAction
|
<TableAction
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ const emit = defineEmits(['success']);
|
|||||||
const formData = ref<MallCommentApi.Comment>();
|
const formData = ref<MallCommentApi.Comment>();
|
||||||
const getTitle = computed(() => {
|
const getTitle = computed(() => {
|
||||||
return formData.value?.id
|
return formData.value?.id
|
||||||
? $t('ui.actionTitle.edit', ['商品品牌'])
|
? $t('ui.actionTitle.edit', ['虚拟评论'])
|
||||||
: $t('ui.actionTitle.create', ['商品品牌']);
|
: $t('ui.actionTitle.create', ['虚拟评论']);
|
||||||
});
|
});
|
||||||
|
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
|
|||||||
Reference in New Issue
Block a user