feat(wms):增加 brand 模块的迁移

pull/345/head
YunaiV 2026-05-17 16:35:51 +08:00
parent 6b28518165
commit bb63ca9541
10 changed files with 857 additions and 0 deletions

View File

@ -0,0 +1 @@
export { default as WmsItemBrandSelect } from './item-brand-select.vue';

View File

@ -0,0 +1,85 @@
<script lang="ts" setup>
import type { SelectValue } from 'ant-design-vue/es/select';
import type { WmsItemBrandApi } from '#/api/wms/md/item/brand';
import { computed, onMounted, ref } from 'vue';
import { Select } from 'ant-design-vue';
import { getItemBrandSimpleList } from '#/api/wms/md/item/brand';
defineOptions({ name: 'WmsItemBrandSelect', inheritAttrs: false });
withDefaults(
defineProps<{
allowClear?: boolean;
disabled?: boolean;
modelValue?: number;
placeholder?: string;
}>(),
{
allowClear: true,
disabled: false,
modelValue: undefined,
placeholder: '请选择商品品牌',
},
);
const emit = defineEmits<{
change: [brand: undefined | WmsItemBrandApi.ItemBrand];
'update:modelValue': [value: number | undefined];
}>();
const loading = ref(false);
const brandList = ref<WmsItemBrandApi.ItemBrand[]>([]);
const options = computed(() =>
brandList.value
.filter((brand) => brand.id !== undefined)
.map((brand) => ({
label: brand.name,
value: brand.id,
})),
);
/** 选中变化 */
function handleChange(value: SelectValue) {
const brandId = typeof value === 'number' ? value : undefined;
emit('update:modelValue', brandId);
emit(
'change',
brandList.value.find((brand) => brand.id === brandId),
);
}
/** 查询商品品牌精简列表 */
async function getList() {
loading.value = true;
try {
brandList.value = await getItemBrandSimpleList();
} finally {
loading.value = false;
}
}
onMounted(() => {
getList();
});
</script>
<template>
<Select
v-bind="$attrs"
:allow-clear="allowClear"
:disabled="disabled"
:loading="loading"
:options="options"
:placeholder="placeholder"
:value="modelValue"
class="w-full"
option-filter-prop="label"
show-search
@change="handleChange"
/>
</template>

View File

@ -0,0 +1,107 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { h } from 'vue';
import { Button } from 'ant-design-vue';
import { z } from '#/adapter/form';
import { generateWmsCode } from '#/views/wms/utils/constants';
/** 新增/修改商品品牌的表单 */
export function useFormSchema(formApi?: any): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'id',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'code',
label: '品牌编号',
component: 'Input',
componentProps: {
maxLength: 20,
placeholder: '请输入品牌编号',
},
rules: z.string().min(1, '品牌编号不能为空').max(20),
suffix: () => {
return h(
Button,
{
type: 'default',
onClick: () => {
formApi?.setFieldValue('code', generateWmsCode('B'));
},
},
{ default: () => '生成' },
);
},
},
{
fieldName: 'name',
label: '品牌名称',
component: 'Input',
componentProps: {
maxLength: 30,
placeholder: '请输入品牌名称',
},
rules: z.string().min(1, '品牌名称不能为空').max(30),
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'code',
label: '品牌编号',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入品牌编号',
},
},
{
fieldName: 'name',
label: '品牌名称',
component: 'Input',
componentProps: {
allowClear: true,
placeholder: '请输入品牌名称',
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'code',
title: '品牌编号',
width: 160,
},
{
field: 'name',
title: '品牌名称',
minWidth: 160,
},
{
field: 'createTime',
title: '创建时间',
width: 180,
formatter: 'formatDateTime',
},
{
title: '操作',
width: 160,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@ -0,0 +1,145 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { WmsItemBrandApi } from '#/api/wms/md/item/brand';
import { Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteItemBrand,
exportItemBrand,
getItemBrandPage,
} from '#/api/wms/md/item/brand';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
defineOptions({ name: 'WmsItemBrand' });
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 创建商品品牌 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑商品品牌 */
function handleEdit(row: WmsItemBrandApi.ItemBrand) {
formModalApi.setData(row).open();
}
/** 删除商品品牌 */
async function handleDelete(row: WmsItemBrandApi.ItemBrand) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0,
});
try {
await deleteItemBrand(row.id!);
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
hideLoading();
}
}
/** 导出商品品牌 */
async function handleExport() {
const data = await exportItemBrand(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '商品品牌.xls', source: data });
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getItemBrandPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<WmsItemBrandApi.ItemBrand>,
});
</script>
<template>
<Page auto-content-height>
<FormModal @success="handleRefresh" />
<Grid table-title="">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['商品品牌']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['wms:item-brand:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['wms:item-brand:export'],
onClick: handleExport,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['wms:item-brand:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['wms:item-brand:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@ -0,0 +1,89 @@
<script lang="ts" setup>
import type { WmsItemBrandApi } from '#/api/wms/md/item/brand';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import {
createItemBrand,
getItemBrand,
updateItemBrand,
} from '#/api/wms/md/item/brand';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
defineOptions({ name: 'WmsItemBrandForm' });
const emit = defineEmits(['success']);
const formData = ref<WmsItemBrandApi.ItemBrand>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['商品品牌'])
: $t('ui.actionTitle.create', ['商品品牌']);
});
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
labelWidth: 100,
},
layout: 'horizontal',
schema: [],
showDefaultActions: false,
});
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
formApi.setState({ schema: useFormSchema(formApi) });
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
const data = (await formApi.getValues()) as WmsItemBrandApi.ItemBrand;
try {
await (formData.value?.id
? updateItemBrand(data)
: createItemBrand(data));
await modalApi.close();
emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
return;
}
await formApi.resetForm();
const data = modalApi.getData<WmsItemBrandApi.ItemBrand>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getItemBrand(data.id);
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal :title="getTitle" class="w-1/3">
<Form class="mx-4" />
</Modal>
</template>

View File

@ -0,0 +1 @@
export { default as WmsItemBrandSelect } from './item-brand-select.vue';

View File

@ -0,0 +1,88 @@
<script lang="ts" setup>
import type { WmsItemBrandApi } from '#/api/wms/md/item/brand';
import { computed, onMounted, ref } from 'vue';
import { ElOption, ElSelect } from 'element-plus';
import { getItemBrandSimpleList } from '#/api/wms/md/item/brand';
defineOptions({ name: 'WmsItemBrandSelect', inheritAttrs: false });
withDefaults(
defineProps<{
clearable?: boolean;
disabled?: boolean;
modelValue?: number;
placeholder?: string;
}>(),
{
clearable: true,
disabled: false,
modelValue: undefined,
placeholder: '请选择商品品牌',
},
);
const emit = defineEmits<{
change: [brand: undefined | WmsItemBrandApi.ItemBrand];
'update:modelValue': [value: number | undefined];
}>();
const loading = ref(false);
const brandList = ref<WmsItemBrandApi.ItemBrand[]>([]);
const options = computed(() =>
brandList.value
.filter((brand) => brand.id !== undefined)
.map((brand) => ({
label: brand.name,
value: brand.id!,
})),
);
/** 选中变化 */
function handleChange(value: number | string | undefined) {
const brandId = typeof value === 'number' ? value : undefined;
emit('update:modelValue', brandId);
emit(
'change',
brandList.value.find((brand) => brand.id === brandId),
);
}
/** 查询商品品牌精简列表 */
async function getList() {
loading.value = true;
try {
brandList.value = await getItemBrandSimpleList();
} finally {
loading.value = false;
}
}
onMounted(() => {
getList();
});
</script>
<template>
<ElSelect
v-bind="$attrs"
:clearable="clearable"
:disabled="disabled"
:loading="loading"
:model-value="modelValue"
:placeholder="placeholder"
class="w-full"
filterable
@change="handleChange"
>
<ElOption
v-for="option in options"
:key="option.value"
:label="option.label"
:value="option.value"
/>
</ElSelect>
</template>

View File

@ -0,0 +1,107 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { h } from 'vue';
import { ElButton } from 'element-plus';
import { z } from '#/adapter/form';
import { generateWmsCode } from '#/views/wms/utils/constants';
/** 新增/修改商品品牌的表单 */
export function useFormSchema(formApi?: any): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'id',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'code',
label: '品牌编号',
component: 'Input',
componentProps: {
maxLength: 20,
placeholder: '请输入品牌编号',
},
rules: z.string().min(1, '品牌编号不能为空').max(20),
suffix: () => {
return h(
ElButton,
{
type: 'default',
onClick: () => {
formApi?.setFieldValue('code', generateWmsCode('B'));
},
},
{ default: () => '生成' },
);
},
},
{
fieldName: 'name',
label: '品牌名称',
component: 'Input',
componentProps: {
maxLength: 30,
placeholder: '请输入品牌名称',
},
rules: z.string().min(1, '品牌名称不能为空').max(30),
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'code',
label: '品牌编号',
component: 'Input',
componentProps: {
clearable: true,
placeholder: '请输入品牌编号',
},
},
{
fieldName: 'name',
label: '品牌名称',
component: 'Input',
componentProps: {
clearable: true,
placeholder: '请输入品牌名称',
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'code',
title: '品牌编号',
width: 160,
},
{
field: 'name',
title: '品牌名称',
minWidth: 160,
},
{
field: 'createTime',
title: '创建时间',
width: 180,
formatter: 'formatDateTime',
},
{
title: '操作',
width: 160,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@ -0,0 +1,145 @@
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { WmsItemBrandApi } from '#/api/wms/md/item/brand';
import { Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart } from '@vben/utils';
import { ElLoading, ElMessage } from 'element-plus';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteItemBrand,
exportItemBrand,
getItemBrandPage,
} from '#/api/wms/md/item/brand';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
defineOptions({ name: 'WmsItemBrand' });
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 刷新表格 */
function handleRefresh() {
gridApi.query();
}
/** 创建商品品牌 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑商品品牌 */
function handleEdit(row: WmsItemBrandApi.ItemBrand) {
formModalApi.setData(row).open();
}
/** 删除商品品牌 */
async function handleDelete(row: WmsItemBrandApi.ItemBrand) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.name]),
});
try {
await deleteItemBrand(row.id!);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
handleRefresh();
} finally {
loadingInstance.close();
}
}
/** 导出商品品牌 */
async function handleExport() {
const data = await exportItemBrand(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '商品品牌.xls', source: data });
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getItemBrandPage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<WmsItemBrandApi.ItemBrand>,
});
</script>
<template>
<Page auto-content-height>
<FormModal @success="handleRefresh" />
<Grid table-title="">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['商品品牌']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['wms:item-brand:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['wms:item-brand:export'],
onClick: handleExport,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'primary',
link: true,
icon: ACTION_ICON.EDIT,
auth: ['wms:item-brand:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['wms:item-brand:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@ -0,0 +1,89 @@
<script lang="ts" setup>
import type { WmsItemBrandApi } from '#/api/wms/md/item/brand';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { ElMessage } from 'element-plus';
import { useVbenForm } from '#/adapter/form';
import {
createItemBrand,
getItemBrand,
updateItemBrand,
} from '#/api/wms/md/item/brand';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
defineOptions({ name: 'WmsItemBrandForm' });
const emit = defineEmits(['success']);
const formData = ref<WmsItemBrandApi.ItemBrand>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['商品品牌'])
: $t('ui.actionTitle.create', ['商品品牌']);
});
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
labelWidth: 100,
},
layout: 'horizontal',
schema: [],
showDefaultActions: false,
});
/** 表单 schema 需要 formApi 引用,所以通过 setState 设置 schema */
formApi.setState({ schema: useFormSchema(formApi) });
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
const data = (await formApi.getValues()) as WmsItemBrandApi.ItemBrand;
try {
await (formData.value?.id
? updateItemBrand(data)
: createItemBrand(data));
await modalApi.close();
emit('success');
ElMessage.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
return;
}
await formApi.resetForm();
const data = modalApi.getData<WmsItemBrandApi.ItemBrand>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getItemBrand(data.id);
await formApi.setValues(formData.value);
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal :title="getTitle" class="w-1/3">
<Form class="mx-4" />
</Modal>
</template>