refactor: 重构产品页添加卡片视图,功能和事件物模型添加参数查看弹窗
- 设备功能、上下线日志添加排序字段 - 调整页面、清除无用代码 - 重构产品管理页,添加表格和卡片视图切换功能,搜索表单、分页等功能。 - 产品物模型功能和事件参数查看弹窗 - 新增了参数弹窗组件用于展示参数详情。
This commit is contained in:
parent
2925fce7fb
commit
c48501610b
|
@ -74,6 +74,7 @@ const loadList = async () => {
|
|||
productKey: props.deviceInfo.productObj.productKey,
|
||||
msgId: messageId.value?.trim() || undefined,
|
||||
isAsc: 'desc',
|
||||
orderByColumn: 'createTime',
|
||||
pageNum: pagination.value.current,
|
||||
pageSize: pagination.value.pageSize,
|
||||
params: {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { Button, DatePicker, Input, Modal, Space, Table } from 'ant-design-vue';
|
||||
import dayjs, { Dayjs } from 'dayjs';
|
||||
|
|
|
@ -10,7 +10,15 @@ import { useRouter } from 'vue-router';
|
|||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
||||
import { getVxePopupContainer } from '@vben/utils';
|
||||
|
||||
import { Modal, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||
import { AppstoreOutlined, MenuOutlined } from '@ant-design/icons-vue';
|
||||
import {
|
||||
Modal,
|
||||
Popconfirm,
|
||||
RadioButton,
|
||||
RadioGroup,
|
||||
Space,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid, vxeCheckboxChecked } from '#/adapter/vxe-table';
|
||||
import { deviceExport, deviceList, deviceRemove } from '#/api/device/device';
|
||||
|
@ -25,7 +33,14 @@ const router = useRouter();
|
|||
|
||||
const productOptions = ref<{ label: string; value: string }[]>([]);
|
||||
|
||||
const activeListType = ref('list');
|
||||
|
||||
const changeListType = (e: any) => {
|
||||
console.log('切换表格类型', e.target.value);
|
||||
};
|
||||
|
||||
const formOptions: VbenFormProps = {
|
||||
collapsed: true,
|
||||
commonConfig: {
|
||||
labelWidth: 80,
|
||||
componentProps: {
|
||||
|
@ -161,7 +176,10 @@ getProductOptionList();
|
|||
<BasicTable table-title="设备列表">
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<a-button v-access:code="['device:device:export']" @click="handleDownloadExcel">
|
||||
<a-button
|
||||
v-access:code="['device:device:export']"
|
||||
@click="handleDownloadExcel"
|
||||
>
|
||||
{{ $t('pages.common.export') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
|
@ -173,25 +191,59 @@ getProductOptionList();
|
|||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
<a-button type="primary" v-access:code="['device:device:add']" @click="handleAdd">
|
||||
<a-button
|
||||
type="primary"
|
||||
v-access:code="['device:device:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
<RadioGroup
|
||||
v-model:value="activeListType"
|
||||
option-type="button"
|
||||
button-style="solid"
|
||||
@change="changeListType"
|
||||
>
|
||||
<RadioButton value="card"><AppstoreOutlined /></RadioButton>
|
||||
<RadioButton value="list"><MenuOutlined /></RadioButton>
|
||||
</RadioGroup>
|
||||
</Space>
|
||||
</template>
|
||||
<template #deviceType="{ row }">
|
||||
<Tag color="processing">
|
||||
{{ deviceTypeOptions.find((option) => option.value === row.deviceType)?.label }}
|
||||
{{
|
||||
deviceTypeOptions.find((option) => option.value === row.deviceType)
|
||||
?.label
|
||||
}}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #deviceState="{ row }">
|
||||
<Tag :color="deviceStateOptions.find((option) => option.value === row.deviceState)?.type">
|
||||
{{ deviceStateOptions.find((option) => option.value === row.deviceState)?.label }}
|
||||
<Tag
|
||||
:color="
|
||||
deviceStateOptions.find(
|
||||
(option) => option.value === row.deviceState,
|
||||
)?.type
|
||||
"
|
||||
>
|
||||
{{
|
||||
deviceStateOptions.find(
|
||||
(option) => option.value === row.deviceState,
|
||||
)?.label
|
||||
}}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<ghost-button v-access:code="['device:device:view']" @click.stop="handleView(row)"> 详情 </ghost-button>
|
||||
<ghost-button v-access:code="['device:device:edit']" @click.stop="handleEdit(row)">
|
||||
<ghost-button
|
||||
v-access:code="['device:device:view']"
|
||||
@click.stop="handleView(row)"
|
||||
>
|
||||
详情
|
||||
</ghost-button>
|
||||
<ghost-button
|
||||
v-access:code="['device:device:edit']"
|
||||
@click.stop="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</ghost-button>
|
||||
<Popconfirm
|
||||
|
@ -200,7 +252,11 @@ getProductOptionList();
|
|||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<ghost-button danger v-access:code="['device:device:remove']" @click.stop="">
|
||||
<ghost-button
|
||||
danger
|
||||
v-access:code="['device:device:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</ghost-button>
|
||||
</Popconfirm>
|
||||
|
@ -210,3 +266,9 @@ getProductOptionList();
|
|||
<DeviceDrawer @reload="tableApi.query()" />
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
.ant-radio-button-wrapper {
|
||||
padding: 0 10px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -348,7 +348,7 @@ onBeforeRouteLeave((to, from, next) => {
|
|||
<div class="header-left">
|
||||
<h3>物模型</h3>
|
||||
<span class="desc">
|
||||
设备会默认继承产品的物模型,继承的物模型不支持删改
|
||||
设备会默认继承产品的物模型,设备继承的物模型不支持删改
|
||||
</span>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
|
|
|
@ -244,7 +244,7 @@ watch(
|
|||
}}
|
||||
</template>
|
||||
<template v-if="column.key === 'required'">
|
||||
<Tag color="processing">
|
||||
<Tag :color="record.required ? 'red' : 'processing'">
|
||||
{{ record.required ? '是' : '否' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
|
|
@ -311,7 +311,7 @@ watch(
|
|||
}}
|
||||
</template>
|
||||
<template v-if="column.key === 'required'">
|
||||
<Tag color="processing">
|
||||
<Tag :color="record.required ? 'red' : 'processing'">
|
||||
{{ record.required ? '是' : '否' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
|
|
@ -8,6 +8,7 @@ import { dataTypeOptions, readWriteTypeOptions } from '#/constants/dicts';
|
|||
|
||||
import EventDrawer from './EventDrawer.vue';
|
||||
import FunctionDrawer from './FunctionDrawer.vue';
|
||||
import ParameterViewModal from './ParameterViewModal.vue';
|
||||
import PropertyDrawer from './PropertyDrawer.vue';
|
||||
import PropertyGroupDrawer from './PropertyGroupDrawer.vue';
|
||||
|
||||
|
@ -34,6 +35,11 @@ const tableData = ref<any[]>([]);
|
|||
|
||||
const formData = ref<any>(null);
|
||||
|
||||
// 参数查看
|
||||
const viewParamsVisible = ref(false);
|
||||
const viewParamsTitle = ref('');
|
||||
const viewParams = ref<any[]>([]);
|
||||
|
||||
// 生成稳定主键
|
||||
const generatePk = (): string =>
|
||||
`${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
||||
|
@ -103,7 +109,7 @@ const columns = computed(() => {
|
|||
});
|
||||
}
|
||||
|
||||
// 功能定义特殊列
|
||||
// 属性定义特殊列
|
||||
if (props.type === 'properties') {
|
||||
baseColumns.splice(
|
||||
3,
|
||||
|
@ -140,7 +146,7 @@ const columns = computed(() => {
|
|||
title: '输入参数',
|
||||
dataIndex: 'inputs',
|
||||
key: 'inputs',
|
||||
width: 100,
|
||||
width: 120,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -151,7 +157,7 @@ const columns = computed(() => {
|
|||
title: '输出参数',
|
||||
dataIndex: 'outputs',
|
||||
key: 'outputs',
|
||||
width: 100,
|
||||
width: 120,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -252,6 +258,14 @@ const handleSave = async (data: any) => {
|
|||
}
|
||||
};
|
||||
|
||||
// 打开参数查看
|
||||
const handleOpenViewParams = (record: any, key: 'inputs' | 'outputs') => {
|
||||
const params = Array.isArray(record?.[key]) ? record[key] : [];
|
||||
viewParams.value = params;
|
||||
viewParamsTitle.value = key === 'inputs' ? '查看输入参数' : '查看输出参数';
|
||||
viewParamsVisible.value = true;
|
||||
};
|
||||
|
||||
// 重置表单
|
||||
const resetForm = () => {
|
||||
formData.value = null;
|
||||
|
@ -345,6 +359,27 @@ onMounted(() => {
|
|||
{{ record.async ? '异步' : '同步' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'inputs'">
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="handleOpenViewParams(record, 'inputs')"
|
||||
>
|
||||
点击查看
|
||||
</Button>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'outputs'">
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="handleOpenViewParams(record, 'outputs')"
|
||||
>
|
||||
点击查看
|
||||
</Button>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'count'">
|
||||
{{ record.properties?.length || 0 }}
|
||||
</template>
|
||||
</template>
|
||||
</Table>
|
||||
|
||||
|
@ -384,6 +419,14 @@ onMounted(() => {
|
|||
:available-properties="props.availableProperties || []"
|
||||
@save="handleSave"
|
||||
/>
|
||||
|
||||
<!-- 参数查看弹窗 -->
|
||||
<ParameterViewModal
|
||||
:open="viewParamsVisible"
|
||||
:title="viewParamsTitle"
|
||||
:params="viewParams"
|
||||
@update:open="(v) => (viewParamsVisible = v)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { Modal, Table, Tag } from 'ant-design-vue';
|
||||
|
||||
import { dataTypeOptions, formTypeOptions } from '#/constants/dicts';
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
title?: string;
|
||||
params: any[];
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:open', value: boolean): void;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.open,
|
||||
set: (val: boolean) => emit('update:open', val),
|
||||
});
|
||||
|
||||
const columns = [
|
||||
{ title: '标识符', dataIndex: 'id', key: 'id' },
|
||||
{ title: '名称', dataIndex: 'name', key: 'name' },
|
||||
{ title: '数据类型', dataIndex: 'dataType', key: 'dataType', width: 160 },
|
||||
{ title: '是否必填', dataIndex: 'required', key: 'required', width: 100 },
|
||||
{ title: '表单类型', dataIndex: 'formType', key: 'formType', width: 140 },
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
:title="title || '查看参数'"
|
||||
width="800px"
|
||||
:footer="null"
|
||||
>
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="params"
|
||||
:pagination="false"
|
||||
:scroll="{ x: false, y: '70vh' }"
|
||||
row-key="id"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'dataType'">
|
||||
{{
|
||||
dataTypeOptions.find(
|
||||
(item) => item.value === record?.valueParams?.dataType,
|
||||
)?.label || '-'
|
||||
}}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'required'">
|
||||
<Tag :color="record.required ? 'red' : 'processing'">
|
||||
{{ record.required ? '是' : '否' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'formType'">
|
||||
{{
|
||||
formTypeOptions.find(
|
||||
(item) => item.value === record?.valueParams?.formType,
|
||||
)?.label || '-'
|
||||
}}
|
||||
</template>
|
||||
</template>
|
||||
</Table>
|
||||
</Modal>
|
||||
</template>
|
|
@ -1,115 +1,134 @@
|
|||
<script setup lang="ts">
|
||||
import type { VbenFormProps } from '@vben/common-ui';
|
||||
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { ProductForm } from '#/api/device/product/model';
|
||||
|
||||
import { h, nextTick, onMounted, onUnmounted, reactive, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
||||
import { getVxePopupContainer } from '@vben/utils';
|
||||
|
||||
import { Modal, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||
import {
|
||||
AppstoreOutlined,
|
||||
CheckCircleOutlined,
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
MenuOutlined,
|
||||
ReloadOutlined,
|
||||
StopOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Form,
|
||||
FormItem,
|
||||
Input,
|
||||
List,
|
||||
ListItem,
|
||||
message,
|
||||
Modal,
|
||||
Pagination,
|
||||
Popconfirm,
|
||||
RadioButton,
|
||||
RadioGroup,
|
||||
Select,
|
||||
SelectOption,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
TreeSelect,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid, vxeCheckboxChecked } from '#/adapter/vxe-table';
|
||||
import {
|
||||
productExport,
|
||||
productList,
|
||||
productRemove,
|
||||
productUpdateStatus,
|
||||
} from '#/api/device/product';
|
||||
import { productCategoryTreeList } from '#/api/device/productCategory';
|
||||
import { deviceTypeOptions } from '#/constants/dicts';
|
||||
import { deviceTypeOptions, enabledOptions } from '#/constants/dicts';
|
||||
import { useProductStore } from '#/store/product';
|
||||
import { commonDownloadExcel } from '#/utils/file/download';
|
||||
|
||||
import { columns, querySchema } from './data';
|
||||
import productDrawer from './product-drawer.vue';
|
||||
|
||||
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 router = useRouter();
|
||||
const productStore = useProductStore();
|
||||
|
||||
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 productList({
|
||||
pageNum: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
// 表格全局唯一表示 保存列配置需要用到
|
||||
id: 'device-product-index',
|
||||
};
|
||||
// 视图模式:card | list
|
||||
const activeListType = ref<'card' | 'list'>('card');
|
||||
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
// 搜索表单
|
||||
const formModel = reactive({
|
||||
productKey: undefined as string | undefined,
|
||||
productName: undefined as string | undefined,
|
||||
categoryId: undefined as number | string | undefined,
|
||||
deviceType: undefined as string | undefined,
|
||||
enabled: undefined as string | undefined,
|
||||
});
|
||||
|
||||
const [ProductDrawer, drawerApi] = useVbenDrawer({
|
||||
connectedComponent: productDrawer,
|
||||
const categoryTree = ref<any[]>([]);
|
||||
|
||||
// 表格/卡片数据与分页
|
||||
const loading = ref(false);
|
||||
const dataSource = ref<Required<ProductForm>[]>([] as any);
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
pageSize: 12,
|
||||
total: 0,
|
||||
});
|
||||
|
||||
// 动态加载表单选项
|
||||
async function loadFormOptions() {
|
||||
const pageSizeOptions = ref<string[]>(['12', '24', '36', '48', '60']);
|
||||
|
||||
// 选中行
|
||||
const selectedRowKeys = ref<(number | string)[]>([]);
|
||||
function onSelectChange(keys: (number | string)[]) {
|
||||
selectedRowKeys.value = keys;
|
||||
}
|
||||
|
||||
// 列定义
|
||||
const columns = [
|
||||
{ title: '产品KEY', dataIndex: 'productKey', align: 'center' },
|
||||
{ title: '产品名称', dataIndex: 'productName', align: 'center' },
|
||||
{ title: '产品分类', dataIndex: 'categoryName', align: 'center' },
|
||||
{ title: '设备类型', dataIndex: 'deviceType', width: 100, align: 'center' },
|
||||
{ title: '启用状态', dataIndex: 'enabled', width: 100, align: 'center' },
|
||||
{ title: '描述', dataIndex: 'description', align: 'center' },
|
||||
{ title: '操作', key: 'action', width: 200, fixed: 'right', align: 'center' },
|
||||
];
|
||||
|
||||
function getDeviceTypeLabel(value?: string) {
|
||||
const match = deviceTypeOptions.find((option) => option.value === value);
|
||||
return match ? match.label : '-';
|
||||
}
|
||||
|
||||
async function fetchData() {
|
||||
try {
|
||||
const categoryOptions = await productCategoryTreeList();
|
||||
const placeholder = categoryOptions.length > 0 ? '请选择' : '暂无产品分类';
|
||||
tableApi.formApi.updateSchema([
|
||||
{
|
||||
componentProps: {
|
||||
treeData: categoryOptions || [],
|
||||
placeholder,
|
||||
},
|
||||
fieldName: 'categoryId',
|
||||
},
|
||||
]);
|
||||
} catch (error) {
|
||||
console.error('加载表单选项失败:', error);
|
||||
loading.value = true;
|
||||
const { rows = [], total = 0 } = (await productList({
|
||||
pageNum: pagination.current,
|
||||
pageSize: pagination.pageSize,
|
||||
...formModel,
|
||||
})) as any;
|
||||
dataSource.value = rows as any;
|
||||
pagination.total = total as number;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 组件挂载后加载选项
|
||||
loadFormOptions();
|
||||
function onSearch() {
|
||||
pagination.current = 1;
|
||||
fetchData();
|
||||
}
|
||||
|
||||
function onReset() {
|
||||
formModel.productKey = undefined;
|
||||
formModel.productName = undefined;
|
||||
formModel.categoryId = undefined;
|
||||
formModel.deviceType = undefined;
|
||||
formModel.enabled = undefined;
|
||||
pagination.current = 1;
|
||||
fetchData();
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
drawerApi.setData({});
|
||||
|
@ -117,11 +136,8 @@ function handleAdd() {
|
|||
}
|
||||
|
||||
async function handleView(row: Required<ProductForm>) {
|
||||
// 保存产品信息到 store
|
||||
productStore.setCurrent(row);
|
||||
// 设置默认选中的 tab
|
||||
productStore.setTabActiveKey('BasicInfo');
|
||||
// 跳转到详情页
|
||||
router.push(`/device/product/detail/${row.id}`);
|
||||
}
|
||||
|
||||
|
@ -132,108 +148,474 @@ async function handleEdit(row: Required<ProductForm>) {
|
|||
|
||||
async function handleDelete(row: Required<ProductForm>) {
|
||||
await productRemove(row.id);
|
||||
await tableApi.query();
|
||||
await fetchData();
|
||||
}
|
||||
|
||||
function handleMultiDelete() {
|
||||
const rows = tableApi.grid.getCheckboxRecords();
|
||||
const ids = rows.map((row: Required<ProductForm>) => row.id);
|
||||
if (selectedRowKeys.value.length === 0) return;
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
okType: 'danger',
|
||||
content: `确认删除选中的${ids.length}条记录吗?`,
|
||||
content: `确认删除选中的${selectedRowKeys.value.length}条记录吗?`,
|
||||
onOk: async () => {
|
||||
await productRemove(ids);
|
||||
await tableApi.query();
|
||||
await productRemove(selectedRowKeys.value);
|
||||
selectedRowKeys.value = [];
|
||||
await fetchData();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function handleDownloadExcel() {
|
||||
commonDownloadExcel(
|
||||
productExport,
|
||||
'设备产品数据',
|
||||
tableApi.formApi.form.values,
|
||||
{
|
||||
fieldMappingTime: formOptions.fieldMappingTime,
|
||||
},
|
||||
);
|
||||
commonDownloadExcel(productExport, '设备产品数据', { ...formModel }, {});
|
||||
}
|
||||
|
||||
async function handleToggleEnabled(row: Required<ProductForm>) {
|
||||
const next = row.enabled === '1' ? '0' : '1';
|
||||
await (productUpdateStatus as any)({ id: row.id, enabled: next });
|
||||
message.success(next === '1' ? '已启用' : '已禁用');
|
||||
await fetchData();
|
||||
}
|
||||
|
||||
const tableScrollHeight = ref(400);
|
||||
|
||||
const updateTableHeight = () => {
|
||||
nextTick(() => {
|
||||
setTimeout(() => {
|
||||
const container: any = document.querySelector('.table-container');
|
||||
if (container) {
|
||||
// 获取容器高度,减去表头高度(约55px)
|
||||
const height = container?.offsetHeight - 40;
|
||||
tableScrollHeight.value = Math.max(height, 200); // 最小高度200px
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
||||
async function loadCategories() {
|
||||
categoryTree.value = await productCategoryTreeList();
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
updateTableHeight();
|
||||
window.addEventListener('resize', updateTableHeight);
|
||||
await Promise.all([loadCategories(), fetchData()]);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', updateTableHeight);
|
||||
});
|
||||
|
||||
const [ProductDrawer, drawerApi] = useVbenDrawer({
|
||||
connectedComponent: productDrawer,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page :auto-content-height="true">
|
||||
<BasicTable table-title="设备产品列表">
|
||||
<template #toolbar-tools>
|
||||
<Page :auto-content-height="true" content-class="flex flex-col">
|
||||
<Space class="bg-background main-box-header mb-3 rounded-lg p-5">
|
||||
<Form layout="inline" :model="formModel">
|
||||
<FormItem label="产品KEY">
|
||||
<Input
|
||||
v-model:value="formModel.productKey"
|
||||
allow-clear
|
||||
placeholder="请输入"
|
||||
/>
|
||||
</FormItem>
|
||||
<FormItem label="产品名称">
|
||||
<Input
|
||||
v-model:value="formModel.productName"
|
||||
allow-clear
|
||||
placeholder="请输入"
|
||||
/>
|
||||
</FormItem>
|
||||
<FormItem label="产品分类">
|
||||
<TreeSelect
|
||||
v-model:value="formModel.categoryId"
|
||||
:tree-data="categoryTree"
|
||||
:field-names="{
|
||||
children: 'children',
|
||||
label: 'label',
|
||||
value: 'id',
|
||||
}"
|
||||
allow-clear
|
||||
placeholder="请选择"
|
||||
style="min-width: 200px"
|
||||
/>
|
||||
</FormItem>
|
||||
<FormItem label="设备类型">
|
||||
<Select
|
||||
v-model:value="formModel.deviceType"
|
||||
allow-clear
|
||||
style="min-width: 160px"
|
||||
>
|
||||
<SelectOption
|
||||
v-for="opt in deviceTypeOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</SelectOption>
|
||||
</Select>
|
||||
</FormItem>
|
||||
<FormItem label="启用状态">
|
||||
<Select
|
||||
v-model:value="formModel.enabled"
|
||||
allow-clear
|
||||
style="min-width: 120px"
|
||||
>
|
||||
<SelectOption
|
||||
v-for="opt in enabledOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</SelectOption>
|
||||
</Select>
|
||||
</FormItem>
|
||||
<FormItem>
|
||||
<Space>
|
||||
<a-button
|
||||
<Button type="primary" @click="onSearch">查询</Button>
|
||||
<Button @click="onReset">重置</Button>
|
||||
</Space>
|
||||
</FormItem>
|
||||
</Form>
|
||||
</Space>
|
||||
<div class="bg-background main-box-content">
|
||||
<Space class="mb-2 flex justify-between p-2 pb-0">
|
||||
<div class="mr-1 pl-1 text-[1rem]">产品列表</div>
|
||||
<Space>
|
||||
<Button
|
||||
v-access:code="['device:product:export']"
|
||||
@click="handleDownloadExcel"
|
||||
>
|
||||
{{ $t('pages.common.export') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
:disabled="!vxeCheckboxChecked(tableApi)"
|
||||
</Button>
|
||||
<Button
|
||||
:disabled="selectedRowKeys.length === 0"
|
||||
danger
|
||||
type="primary"
|
||||
v-access:code="['device:product:remove']"
|
||||
@click="handleMultiDelete"
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
v-access:code="['device:product:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Button>
|
||||
<RadioGroup
|
||||
v-model:value="activeListType"
|
||||
option-type="button"
|
||||
button-style="solid"
|
||||
>
|
||||
<RadioButton value="card"><AppstoreOutlined /></RadioButton>
|
||||
<RadioButton value="list"><MenuOutlined /></RadioButton>
|
||||
</RadioGroup>
|
||||
<Button :loading="loading" @click="fetchData">
|
||||
<ReloadOutlined />
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
<template #deviceType="{ row }">
|
||||
</Space>
|
||||
<div class="table-container p-2 pb-0 pt-0">
|
||||
<template v-if="activeListType === 'list'">
|
||||
<Table
|
||||
class="content-table"
|
||||
row-key="id"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
:data-source="dataSource"
|
||||
size="small"
|
||||
:scroll="{ y: tableScrollHeight }"
|
||||
:row-selection="{
|
||||
selectedRowKeys,
|
||||
onChange: onSelectChange,
|
||||
}"
|
||||
:pagination="false"
|
||||
>
|
||||
<template #bodyCell="{ column, record, text }">
|
||||
<template v-if="column.dataIndex === 'deviceType'">
|
||||
<Tag color="processing">
|
||||
{{
|
||||
deviceTypeOptions.find((option) => option.value === row.deviceType)
|
||||
?.label
|
||||
}}
|
||||
{{ getDeviceTypeLabel(text) }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #enabled="{ row }">
|
||||
<Tag :color="row.enabled === '1' ? 'success' : 'error'">
|
||||
{{ row.enabled === '1' ? '启用' : '禁用' }}
|
||||
<template v-else-if="column.dataIndex === 'enabled'">
|
||||
<Tag :color="record.enabled === '1' ? 'success' : 'error'">
|
||||
{{ record.enabled === '1' ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<Space>
|
||||
<ghost-button
|
||||
v-access:code="['device:product:view']"
|
||||
@click.stop="handleView(row)"
|
||||
@click.stop="handleView(record)"
|
||||
>
|
||||
详情
|
||||
</ghost-button>
|
||||
<ghost-button
|
||||
v-access:code="['device:product:edit']"
|
||||
@click.stop="handleEdit(row)"
|
||||
@click.stop="handleEdit(record)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</ghost-button>
|
||||
<!-- <Button
|
||||
type="default"
|
||||
@click.stop="handleToggleEnabled(record)"
|
||||
>
|
||||
{{ record.enabled === '1' ? '禁用' : '启用' }}
|
||||
</Button> -->
|
||||
<Popconfirm
|
||||
:get-popup-container="getVxePopupContainer"
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
<ghost-button
|
||||
danger
|
||||
v-access:code="['device:product:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</ghost-button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<ProductDrawer @reload="tableApi.query()" />
|
||||
</template>
|
||||
</Table>
|
||||
</template>
|
||||
<template v-else>
|
||||
<List
|
||||
:loading="loading"
|
||||
class="content-list"
|
||||
:grid="{ gutter: 20, xs: 1, sm: 1, md: 2, lg: 3, xl: 4, xxl: 4 }"
|
||||
:data-source="dataSource"
|
||||
>
|
||||
<template #renderItem="{ item }">
|
||||
<ListItem>
|
||||
<Card
|
||||
class="relative cursor-pointer hover:shadow-lg"
|
||||
@click.stop="handleView(item)"
|
||||
>
|
||||
<div class="text-muted-foreground flex text-sm">
|
||||
<div class="card-img">
|
||||
<img
|
||||
:src="item.imgUrl || '/images/device/device-card.png'"
|
||||
alt="产品图片"
|
||||
class="h-full w-full"
|
||||
/>
|
||||
</div>
|
||||
<div class="ml-3 flex-1">
|
||||
<div class="mb-1 text-lg font-medium">
|
||||
{{ item.productName || '-' }}
|
||||
</div>
|
||||
<div>产品分类:{{ item.categoryName || '-' }}</div>
|
||||
<div>
|
||||
设备类型:{{ getDeviceTypeLabel(item.deviceType) }}
|
||||
</div>
|
||||
<div
|
||||
class="card-status"
|
||||
:class="item.enabled === '1' ? 'enabled' : 'disabled'"
|
||||
>
|
||||
{{ item.enabled === '1' ? '启用' : '禁用' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<template #actions>
|
||||
<Button
|
||||
type="link"
|
||||
v-access:code="['device:product:edit']"
|
||||
:icon="h(EditOutlined)"
|
||||
@click.stop="handleEdit(item)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
:title="
|
||||
item.enabled === '1' ? '确认禁用?' : '确认启用?'
|
||||
"
|
||||
@confirm.stop="handleToggleEnabled(item)"
|
||||
>
|
||||
<Button
|
||||
type="link"
|
||||
:icon="
|
||||
item.enabled === '1'
|
||||
? h(StopOutlined)
|
||||
: h(CheckCircleOutlined)
|
||||
"
|
||||
@click.stop
|
||||
>
|
||||
{{ item.enabled === '1' ? '禁用' : '启用' }}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
<Popconfirm
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(item)"
|
||||
>
|
||||
<Button
|
||||
type="link"
|
||||
:icon="h(DeleteOutlined)"
|
||||
danger
|
||||
@click.stop
|
||||
v-access:code="['device:product:remove']"
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</template>
|
||||
</Card>
|
||||
</ListItem>
|
||||
</template>
|
||||
</List>
|
||||
</template>
|
||||
</div>
|
||||
<div class="flex justify-end p-2">
|
||||
<Pagination
|
||||
:current="pagination.current"
|
||||
:page-size="pagination.pageSize"
|
||||
:total="pagination.total"
|
||||
:page-size-options="pageSizeOptions"
|
||||
:show-total="(total) => `共 ${total} 条记录`"
|
||||
show-size-changer
|
||||
size="small"
|
||||
@change="
|
||||
(p, s) => {
|
||||
pagination.current = p;
|
||||
pagination.pageSize = s;
|
||||
fetchData();
|
||||
}
|
||||
"
|
||||
@show-size-change="
|
||||
(p, s) => {
|
||||
pagination.current = 1;
|
||||
pagination.pageSize = s;
|
||||
fetchData();
|
||||
}
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ProductDrawer @reload="fetchData()" />
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.main-box-header {
|
||||
width: 100%;
|
||||
padding: 20px;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.main-box-content {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
overflow: hidden auto; // 防止内容溢出
|
||||
}
|
||||
|
||||
.content-table {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
border: 1px solid hsl(var(--border)) !important;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
:deep(.ant-pagination) {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
text-align: right;
|
||||
|
||||
.ant-pagination-total-text {
|
||||
position: absolute;
|
||||
left: 5px;
|
||||
}
|
||||
|
||||
.ant-pagination-options {
|
||||
position: absolute;
|
||||
left: 95px;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.ant-form-inline .ant-form-item) {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
:deep(.ant-table .ant-table-tbody > tr.ant-table-row-selected td) {
|
||||
background-color: hsl(var(--accent)) !important;
|
||||
}
|
||||
|
||||
:deep(.ant-table .ant-table-tbody > tr:hover td) {
|
||||
background-color: hsl(var(--accent-hover)) !important;
|
||||
}
|
||||
|
||||
.content-list {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.card-img {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
:deep(.ant-list-item) {
|
||||
padding: 12px 0;
|
||||
margin-bottom: 20px !important;
|
||||
}
|
||||
|
||||
:deep(.ant-card-body) {
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
.card-status {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 70px;
|
||||
height: 30px;
|
||||
font-size: 12px;
|
||||
color: #000;
|
||||
text-indent: 10px;
|
||||
border-radius: 0 6px;
|
||||
|
||||
&::after {
|
||||
position: absolute;
|
||||
top: 11px;
|
||||
left: 11px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
content: '';
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
&.enabled {
|
||||
background-color: #d9dffd;
|
||||
|
||||
&::after {
|
||||
background-color: hsl(var(--primary));
|
||||
}
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
background-color: #fad7d9;
|
||||
|
||||
&::after {
|
||||
background-color: hsl(var(--destructive));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.ant-card .ant-card-actions > li) {
|
||||
padding: 8px 0 !important;
|
||||
margin: 0 !important;
|
||||
}
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue