产品管理
This commit is contained in:
parent
7371da5f48
commit
8d3f5331a5
61
apps/web-antd/src/api/property/productManagement/index.ts
Normal file
61
apps/web-antd/src/api/property/productManagement/index.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import type { PropertyVO, PropertyForm, PropertyQuery } from './model';
|
||||
|
||||
import type { ID, IDS } from '#/api/common';
|
||||
import type { PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 查询绿植租赁-绿植产品列表
|
||||
* @param params
|
||||
* @returns 绿植租赁-绿植产品列表
|
||||
*/
|
||||
export function plantsProductList(params?: PropertyQuery) {
|
||||
return requestClient.get<PageResult<PropertyVO>>('/property/plantsProduct/list', { params });
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出绿植租赁-绿植产品列表
|
||||
* @param params
|
||||
* @returns 绿植租赁-绿植产品列表
|
||||
*/
|
||||
export function plantsProductExport(params?: PropertyQuery) {
|
||||
return commonExport('/property/plantsProduct/export', params ?? {});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询绿植租赁-绿植产品详情
|
||||
* @param id id
|
||||
* @returns 绿植租赁-绿植产品详情
|
||||
*/
|
||||
export function plantsProductInfo(id: ID) {
|
||||
return requestClient.get<PropertyVO>(`/property/plantsProduct/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增绿植租赁-绿植产品
|
||||
* @param data
|
||||
* @returns void
|
||||
*/
|
||||
export function plantsProductAdd(data: PropertyForm) {
|
||||
return requestClient.postWithMsg<void>('/property/plantsProduct', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新绿植租赁-绿植产品
|
||||
* @param data
|
||||
* @returns void
|
||||
*/
|
||||
export function plantsProductUpdate(data: PropertyForm) {
|
||||
return requestClient.putWithMsg<void>('/property/plantsProduct', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除绿植租赁-绿植产品
|
||||
* @param id id
|
||||
* @returns void
|
||||
*/
|
||||
export function plantsProductRemove(id: ID | IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`/property/plantsProduct/${id}`);
|
||||
}
|
154
apps/web-antd/src/api/property/productManagement/model.d.ts
vendored
Normal file
154
apps/web-antd/src/api/property/productManagement/model.d.ts
vendored
Normal file
@ -0,0 +1,154 @@
|
||||
import type { PageQuery, BaseEntity } from '#/api/common';
|
||||
|
||||
export interface PropertyVO {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
id: string | number;
|
||||
|
||||
/**
|
||||
* 产品编号
|
||||
*/
|
||||
plantCode: string;
|
||||
|
||||
/**
|
||||
* 产品名称
|
||||
*/
|
||||
plantName: string;
|
||||
|
||||
/**
|
||||
* 产品分类
|
||||
*/
|
||||
plantType: number;
|
||||
|
||||
/**
|
||||
* 产品图片
|
||||
*/
|
||||
imgPath: string;
|
||||
|
||||
/**
|
||||
* 规格
|
||||
*/
|
||||
specification: string;
|
||||
|
||||
/**
|
||||
* 租金
|
||||
*/
|
||||
rent: number;
|
||||
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
inventory: number;
|
||||
|
||||
/**
|
||||
* 状态(0下架 1上架 )
|
||||
*/
|
||||
state: number;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
remark: string;
|
||||
|
||||
}
|
||||
|
||||
export interface PropertyForm extends BaseEntity {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
id?: string | number;
|
||||
|
||||
/**
|
||||
* 产品编号
|
||||
*/
|
||||
plantCode?: string;
|
||||
|
||||
/**
|
||||
* 产品名称
|
||||
*/
|
||||
plantName?: string;
|
||||
|
||||
/**
|
||||
* 产品分类
|
||||
*/
|
||||
plantType?: number;
|
||||
|
||||
/**
|
||||
* 产品图片
|
||||
*/
|
||||
imgPath?: string;
|
||||
|
||||
/**
|
||||
* 规格
|
||||
*/
|
||||
specification?: string;
|
||||
|
||||
/**
|
||||
* 租金
|
||||
*/
|
||||
rent?: number;
|
||||
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
inventory?: number;
|
||||
|
||||
/**
|
||||
* 状态(0下架 1上架 )
|
||||
*/
|
||||
state?: number;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
remark?: string;
|
||||
|
||||
}
|
||||
|
||||
export interface PropertyQuery extends PageQuery {
|
||||
/**
|
||||
* 产品编号
|
||||
*/
|
||||
plantCode?: string;
|
||||
|
||||
/**
|
||||
* 产品名称
|
||||
*/
|
||||
plantName?: string;
|
||||
|
||||
/**
|
||||
* 产品分类
|
||||
*/
|
||||
plantType?: number;
|
||||
|
||||
/**
|
||||
* 产品图片
|
||||
*/
|
||||
imgPath?: string;
|
||||
|
||||
/**
|
||||
* 规格
|
||||
*/
|
||||
specification?: string;
|
||||
|
||||
/**
|
||||
* 租金
|
||||
*/
|
||||
rent?: number;
|
||||
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
inventory?: number;
|
||||
|
||||
/**
|
||||
* 状态(0下架 1上架 )
|
||||
*/
|
||||
state?: number;
|
||||
|
||||
/**
|
||||
* 日期范围参数
|
||||
*/
|
||||
params?: any;
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
import type { FormSchemaGetter } from '#/adapter/form';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { getDictOptions } from '#/utils/dict';
|
||||
import { renderDict } from '#/utils/render';
|
||||
|
||||
export const querySchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'plantName',
|
||||
label: '产品名称:',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'specification',
|
||||
label: '规格:',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
// 可选从DictEnum中获取 DictEnum.PRODUCT_MANAGEMENT_STATUS 便于维护
|
||||
options: getDictOptions('product_management_status'),
|
||||
},
|
||||
fieldName: 'state',
|
||||
label: '状态:',
|
||||
},
|
||||
];
|
||||
|
||||
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
|
||||
// export const columns: () => VxeGridProps['columns'] = () => [
|
||||
export const columns: VxeGridProps['columns'] = [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{
|
||||
title: '主键',
|
||||
field: 'id',
|
||||
},
|
||||
{
|
||||
title: '产品编号',
|
||||
field: 'plantCode',
|
||||
},
|
||||
{
|
||||
title: '产品名称',
|
||||
field: 'plantName',
|
||||
},
|
||||
{
|
||||
title: '产品分类',
|
||||
field: 'plantType',
|
||||
},
|
||||
{
|
||||
title: '图片',
|
||||
field: 'imgPath',
|
||||
},
|
||||
{
|
||||
title: '规格',
|
||||
field: 'specification',
|
||||
},
|
||||
{
|
||||
title: '租金',
|
||||
field: 'rent',
|
||||
},
|
||||
{
|
||||
title: '库存数量',
|
||||
field: 'inventory',
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
field: 'state',
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
// 可选从DictEnum中获取 DictEnum.PRODUCT_MANAGEMENT_STATUS 便于维护
|
||||
return renderDict(row.state, 'product_management_status');
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
field: 'remark',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
field: 'createTime',
|
||||
},
|
||||
{
|
||||
field: 'action',
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
title: '操作',
|
||||
width: 180,
|
||||
},
|
||||
];
|
||||
|
||||
export const modalSchema: FormSchemaGetter = () => [
|
||||
{
|
||||
label: '主键',
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
show: () => false,
|
||||
triggerFields: [''],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '产品编号',
|
||||
fieldName: 'plantCode',
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
label: '产品名称',
|
||||
fieldName: 'plantName',
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
label: '产品分类',
|
||||
fieldName: 'plantType',
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
label: '图片',
|
||||
fieldName: 'imgPath',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
label: '规格',
|
||||
fieldName: 'specification',
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
label: '租金',
|
||||
fieldName: 'rent',
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
label: '库存数量',
|
||||
fieldName: 'inventory',
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
fieldName: 'state',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
// 可选从DictEnum中获取 DictEnum.PRODUCT_MANAGEMENT_STATUS 便于维护
|
||||
options: getDictOptions('product_management_status'),
|
||||
},
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
label: '备注',
|
||||
fieldName: 'remark',
|
||||
component: 'Input',
|
||||
},
|
||||
// {
|
||||
// label: '创建时间',
|
||||
// fieldName: 'creatTime',
|
||||
// component: 'Input',
|
||||
// },
|
||||
];
|
@ -1,5 +1,176 @@
|
||||
<script setup lang="ts">
|
||||
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
|
||||
import { getVxePopupContainer } from '@vben/utils';
|
||||
import { Modal, Popconfirm, Space } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
useVbenVxeGrid,
|
||||
vxeCheckboxChecked,
|
||||
type VxeGridProps
|
||||
} from '#/adapter/vxe-table';
|
||||
|
||||
import {
|
||||
plantsProductExport,
|
||||
plantsProductList,
|
||||
plantsProductRemove,
|
||||
} from '#/api/property/productManagement';
|
||||
import type { PropertyForm } from '#/api/property/productManagement/model';
|
||||
import { commonDownloadExcel } from '#/utils/file/download';
|
||||
|
||||
import propertyModal from './property-modal.vue';
|
||||
import { columns, querySchema } from './data';
|
||||
|
||||
const formOptions: VbenFormProps = {
|
||||
commonConfig: {
|
||||
labelWidth: 80,
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
schema: querySchema(),
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||
// 处理区间选择器RangePicker时间格式 将一个字段映射为两个字段 搜索/导出会用到
|
||||
// 不需要直接删除
|
||||
// fieldMappingTime: [
|
||||
// [
|
||||
// 'createTime',
|
||||
// ['params[beginTime]', 'params[endTime]'],
|
||||
// ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'],
|
||||
// ],
|
||||
// ],
|
||||
};
|
||||
|
||||
const gridOptions: VxeGridProps = {
|
||||
checkboxConfig: {
|
||||
// 高亮
|
||||
highlight: true,
|
||||
// 翻页时保留选中状态
|
||||
reserve: true,
|
||||
// 点击行选中
|
||||
// trigger: 'row',
|
||||
},
|
||||
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
|
||||
// columns: columns(),
|
||||
columns,
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues = {}) => {
|
||||
return await plantsProductList({
|
||||
pageNum: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
// 表格全局唯一表示 保存列配置需要用到
|
||||
id: 'property-property-index'
|
||||
};
|
||||
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
});
|
||||
|
||||
const [PropertyModal, modalApi] = useVbenModal({
|
||||
connectedComponent: propertyModal,
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
modalApi.setData({});
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
async function handleEdit(row: Required<PropertyForm>) {
|
||||
modalApi.setData({ id: row.id });
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
async function handleDelete(row: Required<PropertyForm>) {
|
||||
await plantsProductRemove(row.id);
|
||||
await tableApi.query();
|
||||
}
|
||||
|
||||
function handleMultiDelete() {
|
||||
const rows = tableApi.grid.getCheckboxRecords();
|
||||
const ids = rows.map((row: Required<PropertyForm>) => row.id);
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
okType: 'danger',
|
||||
content: `确认删除选中的${ids.length}条记录吗?`,
|
||||
onOk: async () => {
|
||||
await plantsProductRemove(ids);
|
||||
await tableApi.query();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function handleDownloadExcel() {
|
||||
commonDownloadExcel(plantsProductExport, '绿植租赁-绿植产品数据', tableApi.formApi.form.values, {
|
||||
fieldMappingTime: formOptions.fieldMappingTime,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
产品管理
|
||||
</div>
|
||||
</template>
|
||||
<Page :auto-content-height="true">
|
||||
<BasicTable table-title="绿植租赁-绿植产品列表">
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<a-button
|
||||
v-access:code="['property:property:export']"
|
||||
@click="handleDownloadExcel"
|
||||
>
|
||||
{{ $t('pages.common.export') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
:disabled="!vxeCheckboxChecked(tableApi)"
|
||||
danger
|
||||
type="primary"
|
||||
v-access:code="['property:property:remove']"
|
||||
@click="handleMultiDelete">
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-access:code="['property:property:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Space>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<ghost-button
|
||||
v-access:code="['property:property:edit']"
|
||||
@click.stop="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</ghost-button>
|
||||
<Popconfirm
|
||||
:get-popup-container="getVxePopupContainer"
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<ghost-button
|
||||
danger
|
||||
v-access:code="['property:property:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</ghost-button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<PropertyModal @reload="tableApi.query()" />
|
||||
</Page>
|
||||
</template>
|
||||
|
@ -0,0 +1,101 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { cloneDeep } from '@vben/utils';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { plantsProductAdd, plantsProductInfo, plantsProductUpdate } from '#/api/property/productManagement';
|
||||
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||
|
||||
import { modalSchema } from './data';
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const title = computed(() => {
|
||||
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||
});
|
||||
|
||||
const [BasicForm, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
// 默认占满两列
|
||||
formItemClass: 'col-span-2',
|
||||
// 默认label宽度 px
|
||||
labelWidth: 80,
|
||||
// 通用配置项 会影响到所有表单项
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
}
|
||||
},
|
||||
schema: modalSchema(),
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||
{
|
||||
initializedGetter: defaultFormValueGetter(formApi),
|
||||
currentGetter: defaultFormValueGetter(formApi),
|
||||
},
|
||||
);
|
||||
|
||||
const [BasicModal, modalApi] = useVbenModal({
|
||||
// 在这里更改宽度
|
||||
class: 'w-[550px]',
|
||||
fullscreenButton: false,
|
||||
onBeforeClose,
|
||||
onClosed: handleClosed,
|
||||
onConfirm: handleConfirm,
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
modalApi.modalLoading(true);
|
||||
|
||||
const { id } = modalApi.getData() as { id?: number | string };
|
||||
isUpdate.value = !!id;
|
||||
|
||||
if (isUpdate.value && id) {
|
||||
const record = await plantsProductInfo(id);
|
||||
await formApi.setValues(record);
|
||||
}
|
||||
await markInitialized();
|
||||
|
||||
modalApi.modalLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
modalApi.lock(true);
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
|
||||
const data = cloneDeep(await formApi.getValues());
|
||||
await (isUpdate.value ? plantsProductUpdate(data) : plantsProductAdd(data));
|
||||
resetInitialized();
|
||||
emit('reload');
|
||||
modalApi.close();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
modalApi.lock(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClosed() {
|
||||
await formApi.resetForm();
|
||||
resetInitialized();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BasicModal :title="title">
|
||||
<BasicForm />
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
@ -28,7 +28,7 @@ export default defineConfig(async () => {
|
||||
rewrite: (path) => path.replace(/^\/api/, ''),
|
||||
// mock代理目标地址
|
||||
// target: 'http://by.missmoc.top:3010/',
|
||||
target: 'http://127.0.0.1:8080/',
|
||||
target: 'http://47.109.37.87:3010',
|
||||
ws: true,
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user