feat: 重构设备管理页面并添加新功能、获取默认设备图片保存到vuex
- 重构了设备列表页面的布局和样式,增加了卡片视图和列表视图的切换功能 - 添加了设备默认图片功能,新建或编辑设备时自动加载默认图片 - 优化了设备列表的搜索、筛选和分页功能 - 更新了设备详情和编辑页面的样式 - 调整了产品列表和设备列表的关联逻辑
This commit is contained in:
parent
c48501610b
commit
ac343f006a
|
@ -28,12 +28,14 @@ import { TenantToggle } from '#/components/tenant-toggle';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import { resetRoutes } from '#/router';
|
import { resetRoutes } from '#/router';
|
||||||
import { useAuthStore, useNotifyStore } from '#/store';
|
import { useAuthStore, useNotifyStore } from '#/store';
|
||||||
|
import { useDeviceStore } from '#/store/device';
|
||||||
import { useTenantStore } from '#/store/tenant';
|
import { useTenantStore } from '#/store/tenant';
|
||||||
import LoginForm from '#/views/_core/authentication/login.vue';
|
import LoginForm from '#/views/_core/authentication/login.vue';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
|
const deviceStore = useDeviceStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { destroyWatermark, updateWatermark } = useWatermark();
|
const { destroyWatermark, updateWatermark } = useWatermark();
|
||||||
|
|
||||||
|
@ -106,7 +108,10 @@ async function handleLogout() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const notifyStore = useNotifyStore();
|
const notifyStore = useNotifyStore();
|
||||||
onMounted(() => notifyStore.startListeningMessage());
|
onMounted(() => {
|
||||||
|
notifyStore.startListeningMessage();
|
||||||
|
deviceStore.updateDefaultDeviceImgId(); // 这样调用
|
||||||
|
});
|
||||||
|
|
||||||
function handleViewAll() {
|
function handleViewAll() {
|
||||||
message.warning('暂未开放');
|
message.warning('暂未开放');
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
import { deviceInfo } from '#/api/device/device';
|
import { deviceInfo } from '#/api/device/device';
|
||||||
|
import { configInfoByKey } from '#/api/system/config';
|
||||||
|
|
||||||
export const useDeviceStore = defineStore('device', {
|
export const useDeviceStore = defineStore('device', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
currentDevice: {} as any,
|
currentDevice: {} as any,
|
||||||
tabActiveKey: 'BasicInfo',
|
tabActiveKey: 'BasicInfo',
|
||||||
deviceCount: 0,
|
deviceCount: 0,
|
||||||
|
defaultDeviceImgId: '',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
getCurrentDevice: (state) => state.currentDevice,
|
getCurrentDevice: (state) => state.currentDevice,
|
||||||
getTabActiveKey: (state) => state.tabActiveKey,
|
getTabActiveKey: (state) => state.tabActiveKey,
|
||||||
getDeviceCount: (state) => state.deviceCount,
|
getDeviceCount: (state) => state.deviceCount,
|
||||||
|
getDefaultDeviceImgId: (state) => state.defaultDeviceImgId,
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -32,6 +35,17 @@ export const useDeviceStore = defineStore('device', {
|
||||||
this.currentDevice.deviceState = state;
|
this.currentDevice.deviceState = state;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async updateDefaultDeviceImgId() {
|
||||||
|
try {
|
||||||
|
const res = await configInfoByKey('device.defaultDeviceImgId');
|
||||||
|
this.defaultDeviceImgId = res;
|
||||||
|
return res;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取设备默认图片失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async getDetail(id: string) {
|
async getDetail(id: string) {
|
||||||
try {
|
try {
|
||||||
const res = await deviceInfo(id);
|
const res = await deviceInfo(id);
|
||||||
|
|
|
@ -103,6 +103,7 @@ const loadList = async () => {
|
||||||
productKey: props.deviceInfo.productObj.productKey,
|
productKey: props.deviceInfo.productObj.productKey,
|
||||||
msgId: messageId.value?.trim() || undefined,
|
msgId: messageId.value?.trim() || undefined,
|
||||||
funcId: selectedFuncId.value || undefined,
|
funcId: selectedFuncId.value || undefined,
|
||||||
|
orderByColumn: 'createTime',
|
||||||
isAsc: 'desc',
|
isAsc: 'desc',
|
||||||
pageNum: pagination.value.current,
|
pageNum: pagination.value.current,
|
||||||
pageSize: pagination.value.pageSize,
|
pageSize: pagination.value.pageSize,
|
||||||
|
|
|
@ -8,12 +8,15 @@ import { cloneDeep } from '@vben/utils';
|
||||||
import { useVbenForm } from '#/adapter/form';
|
import { useVbenForm } from '#/adapter/form';
|
||||||
import { deviceAdd, deviceInfo, deviceUpdate } from '#/api/device/device';
|
import { deviceAdd, deviceInfo, deviceUpdate } from '#/api/device/device';
|
||||||
import { productList } from '#/api/device/product';
|
import { productList } from '#/api/device/product';
|
||||||
|
import { useDeviceStore } from '#/store/device';
|
||||||
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||||
|
|
||||||
import { drawerSchema } from './data';
|
import { drawerSchema } from './data';
|
||||||
|
|
||||||
const emit = defineEmits<{ reload: [] }>();
|
const emit = defineEmits<{ reload: [] }>();
|
||||||
|
|
||||||
|
const deviceStore = useDeviceStore();
|
||||||
|
|
||||||
const isUpdate = ref(false);
|
const isUpdate = ref(false);
|
||||||
const title = computed(() => {
|
const title = computed(() => {
|
||||||
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||||
|
@ -35,10 +38,12 @@ const [BasicForm, formApi] = useVbenForm({
|
||||||
wrapperClass: 'grid-cols-2',
|
wrapperClass: 'grid-cols-2',
|
||||||
});
|
});
|
||||||
|
|
||||||
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff({
|
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||||
initializedGetter: defaultFormValueGetter(formApi),
|
{
|
||||||
currentGetter: defaultFormValueGetter(formApi),
|
initializedGetter: defaultFormValueGetter(formApi),
|
||||||
});
|
currentGetter: defaultFormValueGetter(formApi),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const [BasicDrawer, drawerApi] = useVbenDrawer({
|
const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||||
// 在这里更改宽度
|
// 在这里更改宽度
|
||||||
|
@ -63,7 +68,10 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||||
if (isUpdate.value && id) {
|
if (isUpdate.value && id) {
|
||||||
const record = await deviceInfo(id);
|
const record = await deviceInfo(id);
|
||||||
await formApi.setValues(record);
|
await formApi.setValues(record);
|
||||||
|
} else {
|
||||||
|
await formApi.setFieldValue('imgId', deviceStore.getDefaultDeviceImgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
await markInitialized();
|
await markInitialized();
|
||||||
|
|
||||||
drawerApi.drawerLoading(false);
|
drawerApi.drawerLoading(false);
|
||||||
|
@ -80,6 +88,9 @@ async function handleConfirm() {
|
||||||
}
|
}
|
||||||
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
|
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
|
||||||
const data = cloneDeep(await formApi.getValues());
|
const data = cloneDeep(await formApi.getValues());
|
||||||
|
if (data.imgId === undefined || data.imgId === '') {
|
||||||
|
data.imgId = deviceStore.getDefaultDeviceImgId;
|
||||||
|
}
|
||||||
await (isUpdate.value ? deviceUpdate(data) : deviceAdd(data));
|
await (isUpdate.value ? deviceUpdate(data) : deviceAdd(data));
|
||||||
resetInitialized();
|
resetInitialized();
|
||||||
emit('reload');
|
emit('reload');
|
||||||
|
@ -120,7 +131,9 @@ async function getProductOptionList() {
|
||||||
onChange: (value: number | string) => {
|
onChange: (value: number | string) => {
|
||||||
// 当产品选择变化时,自动设置设备图片
|
// 当产品选择变化时,自动设置设备图片
|
||||||
if (value) {
|
if (value) {
|
||||||
const selectedProduct = productOptions.find((option) => option.value === value);
|
const selectedProduct = productOptions.find(
|
||||||
|
(option) => option.value === value,
|
||||||
|
);
|
||||||
formApi.setFieldValue('imgId', selectedProduct?.imgId || '');
|
formApi.setFieldValue('imgId', selectedProduct?.imgId || '');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,274 +1,634 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts" name="DeviceIndex">
|
||||||
import type { VbenFormProps } from '@vben/common-ui';
|
|
||||||
|
|
||||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
|
||||||
import type { DeviceForm } from '#/api/device/device/model';
|
import type { DeviceForm } from '#/api/device/device/model';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
|
||||||
import { getVxePopupContainer } from '@vben/utils';
|
|
||||||
|
|
||||||
import { AppstoreOutlined, MenuOutlined } from '@ant-design/icons-vue';
|
|
||||||
import {
|
import {
|
||||||
|
h,
|
||||||
|
nextTick,
|
||||||
|
onActivated,
|
||||||
|
onMounted,
|
||||||
|
onUnmounted,
|
||||||
|
reactive,
|
||||||
|
ref,
|
||||||
|
} from 'vue';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import { EllipsisText, Page, useVbenDrawer } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AppstoreOutlined,
|
||||||
|
DeleteOutlined,
|
||||||
|
EditOutlined,
|
||||||
|
MenuOutlined,
|
||||||
|
ReloadOutlined,
|
||||||
|
} from '@ant-design/icons-vue';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Form,
|
||||||
|
FormItem,
|
||||||
|
Input,
|
||||||
|
List,
|
||||||
|
ListItem,
|
||||||
Modal,
|
Modal,
|
||||||
|
Pagination,
|
||||||
Popconfirm,
|
Popconfirm,
|
||||||
RadioButton,
|
RadioButton,
|
||||||
RadioGroup,
|
RadioGroup,
|
||||||
|
Select,
|
||||||
|
SelectOption,
|
||||||
Space,
|
Space,
|
||||||
|
Table,
|
||||||
Tag,
|
Tag,
|
||||||
} from 'ant-design-vue';
|
} from 'ant-design-vue';
|
||||||
|
|
||||||
import { useVbenVxeGrid, vxeCheckboxChecked } from '#/adapter/vxe-table';
|
|
||||||
import { deviceExport, deviceList, deviceRemove } from '#/api/device/device';
|
import { deviceExport, deviceList, deviceRemove } from '#/api/device/device';
|
||||||
import { productList } from '#/api/device/product';
|
import { productList } from '#/api/device/product';
|
||||||
import { deviceStateOptions, deviceTypeOptions } from '#/constants/dicts';
|
import { deviceStateOptions, deviceTypeOptions } from '#/constants/dicts';
|
||||||
import { commonDownloadExcel } from '#/utils/file/download';
|
import { commonDownloadExcel } from '#/utils/file/download';
|
||||||
|
|
||||||
import { columns, querySchema } from './data';
|
|
||||||
import deviceDrawer from './device-drawer.vue';
|
import deviceDrawer from './device-drawer.vue';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const route = useRoute();
|
||||||
|
// 视图模式:card | list
|
||||||
|
const activeListType = ref<'card' | 'list'>('card');
|
||||||
|
|
||||||
|
// 搜索表单
|
||||||
|
const formModel = reactive({
|
||||||
|
deviceKey: undefined as string | undefined,
|
||||||
|
deviceName: undefined as string | undefined,
|
||||||
|
productId: undefined as string | undefined,
|
||||||
|
deviceState: undefined as string | undefined,
|
||||||
|
deviceType: undefined as string | undefined,
|
||||||
|
});
|
||||||
|
|
||||||
const productOptions = ref<{ label: string; value: string }[]>([]);
|
const productOptions = ref<{ label: string; value: string }[]>([]);
|
||||||
|
|
||||||
const activeListType = ref('list');
|
// 表格/卡片数据与分页
|
||||||
|
const loading = ref(false);
|
||||||
|
const dataSource = ref<Required<DeviceForm>[]>([] as any);
|
||||||
|
const pagination = reactive({
|
||||||
|
current: 1,
|
||||||
|
pageSize: 12,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
|
|
||||||
const changeListType = (e: any) => {
|
const pageSizeOptions = ref<string[]>(['12', '24', '36', '48', '60']);
|
||||||
console.log('切换表格类型', e.target.value);
|
|
||||||
|
// 选中行
|
||||||
|
const selectedRowKeys = ref<(number | string)[]>([]);
|
||||||
|
const onSelectChange = (keys: (number | string)[]) => {
|
||||||
|
selectedRowKeys.value = keys;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formOptions: VbenFormProps = {
|
// 列定义
|
||||||
collapsed: true,
|
const columns = [
|
||||||
commonConfig: {
|
{ title: '设备KEY', dataIndex: 'deviceKey', align: 'center' },
|
||||||
labelWidth: 80,
|
{ title: '设备名称', dataIndex: 'deviceName', align: 'center' },
|
||||||
componentProps: {
|
{
|
||||||
allowClear: true,
|
title: '所属产品',
|
||||||
|
dataIndex: ['productObj', 'productName'],
|
||||||
|
align: 'center',
|
||||||
|
},
|
||||||
|
{ title: '设备类型', dataIndex: 'deviceType', width: 100, align: 'center' },
|
||||||
|
{ title: '设备状态', dataIndex: 'deviceState', width: 100, align: 'center' },
|
||||||
|
{ title: '描述', dataIndex: 'description', align: 'center' },
|
||||||
|
{ title: '操作', key: 'action', width: 200, fixed: 'right', align: 'center' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const getDeviceTypeLabel = (value?: string) => {
|
||||||
|
const match = deviceTypeOptions.find((option) => option.value === value);
|
||||||
|
return match ? match.label : '-';
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDeviceStateMeta = (value?: string) => {
|
||||||
|
const match = deviceStateOptions.find((option) => option.value === value);
|
||||||
|
return {
|
||||||
|
label: match ? match.label : '-',
|
||||||
|
type: match ? match.type : 'default',
|
||||||
|
} as any;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchData = async () => {
|
||||||
|
try {
|
||||||
|
loading.value = true;
|
||||||
|
const { rows = [], total = 0 } = (await deviceList({
|
||||||
|
pageNum: pagination.current,
|
||||||
|
pageSize: pagination.pageSize,
|
||||||
|
...formModel,
|
||||||
|
})) as any;
|
||||||
|
dataSource.value = rows as any;
|
||||||
|
pagination.total = total as number;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSearch = () => {
|
||||||
|
pagination.current = 1;
|
||||||
|
fetchData();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onReset = () => {
|
||||||
|
formModel.deviceKey = undefined;
|
||||||
|
formModel.deviceName = undefined;
|
||||||
|
formModel.productId = undefined;
|
||||||
|
formModel.deviceType = undefined;
|
||||||
|
formModel.deviceState = undefined;
|
||||||
|
pagination.current = 1;
|
||||||
|
fetchData();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAdd = () => {
|
||||||
|
drawerApi.setData({});
|
||||||
|
drawerApi.open();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleView = async (row: any) => {
|
||||||
|
router.push(`/device/device/detail/${row.id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEdit = async (row: any) => {
|
||||||
|
drawerApi.setData({ id: row.id });
|
||||||
|
drawerApi.open();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = async (row: Required<DeviceForm>) => {
|
||||||
|
await deviceRemove(row.id);
|
||||||
|
await fetchData();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMultiDelete = () => {
|
||||||
|
if (selectedRowKeys.value.length === 0) return;
|
||||||
|
Modal.confirm({
|
||||||
|
title: '提示',
|
||||||
|
okType: 'danger',
|
||||||
|
content: `确认删除选中的${selectedRowKeys.value.length}条记录吗?`,
|
||||||
|
onOk: async () => {
|
||||||
|
await deviceRemove(selectedRowKeys.value);
|
||||||
|
selectedRowKeys.value = [];
|
||||||
|
await fetchData();
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
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 = {
|
const handleDownloadExcel = () => {
|
||||||
checkboxConfig: {
|
commonDownloadExcel(deviceExport, '设备数据', { ...formModel }, {});
|
||||||
// 高亮
|
|
||||||
highlight: true,
|
|
||||||
// 翻页时保留选中状态
|
|
||||||
reserve: true,
|
|
||||||
// 点击行选中
|
|
||||||
// trigger: 'row',
|
|
||||||
},
|
|
||||||
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
|
|
||||||
// columns: columns(),
|
|
||||||
columns,
|
|
||||||
height: 'auto',
|
|
||||||
keepSource: true,
|
|
||||||
pagerConfig: {},
|
|
||||||
proxyConfig: {
|
|
||||||
ajax: {
|
|
||||||
query: async ({ page }, formValues = {}) => {
|
|
||||||
return await deviceList({
|
|
||||||
pageNum: page.currentPage,
|
|
||||||
pageSize: page.pageSize,
|
|
||||||
...formValues,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
rowConfig: {
|
|
||||||
keyField: 'id',
|
|
||||||
},
|
|
||||||
// 表格全局唯一表示 保存列配置需要用到
|
|
||||||
id: 'device-device-index',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
const tableScrollHeight = ref(400);
|
||||||
formOptions,
|
|
||||||
gridOptions,
|
const updateTableHeight = () => {
|
||||||
|
nextTick(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
const container: any = document.querySelector('.table-container');
|
||||||
|
if (container) {
|
||||||
|
const height = container?.offsetHeight - 40;
|
||||||
|
tableScrollHeight.value = Math.max(height, 200);
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadProducts = async () => {
|
||||||
|
const res = await productList({ pageNum: 1, pageSize: 1000 } as any);
|
||||||
|
productOptions.value = (res?.rows || []).map((item: any) => ({
|
||||||
|
label: item.productName,
|
||||||
|
value: item.id,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
// 2. 在顶层直接调用
|
||||||
|
onActivated(() => {
|
||||||
|
console.log('组件被激活了!');
|
||||||
|
// 这里可以执行重新加载数据等操作
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
console.log('onMounted');
|
||||||
|
updateTableHeight();
|
||||||
|
window.addEventListener('resize', updateTableHeight);
|
||||||
|
await Promise.all([loadProducts(), fetchData()]);
|
||||||
|
if (
|
||||||
|
route.query.productId !== undefined &&
|
||||||
|
route.query.productId !== formModel.productId
|
||||||
|
) {
|
||||||
|
formModel.productId = route.query.productId as string;
|
||||||
|
onSearch();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener('resize', updateTableHeight);
|
||||||
});
|
});
|
||||||
|
|
||||||
const [DeviceDrawer, drawerApi] = useVbenDrawer({
|
const [DeviceDrawer, drawerApi] = useVbenDrawer({
|
||||||
connectedComponent: deviceDrawer,
|
connectedComponent: deviceDrawer,
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleAdd() {
|
|
||||||
drawerApi.setData({});
|
|
||||||
drawerApi.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查看设备详情
|
|
||||||
async function handleView(row: any) {
|
|
||||||
router.push(`/device/device/detail/${row.id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 编辑设备
|
|
||||||
async function handleEdit(row: any) {
|
|
||||||
drawerApi.setData({ id: row.id });
|
|
||||||
drawerApi.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleDelete(row: Required<DeviceForm>) {
|
|
||||||
await deviceRemove(row.id);
|
|
||||||
await tableApi.query();
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleMultiDelete() {
|
|
||||||
const rows = tableApi.grid.getCheckboxRecords();
|
|
||||||
const ids = rows.map((row: Required<DeviceForm>) => row.id);
|
|
||||||
Modal.confirm({
|
|
||||||
title: '提示',
|
|
||||||
okType: 'danger',
|
|
||||||
content: `确认删除选中的${ids.length}条记录吗?`,
|
|
||||||
onOk: async () => {
|
|
||||||
await deviceRemove(ids);
|
|
||||||
await tableApi.query();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleDownloadExcel() {
|
|
||||||
commonDownloadExcel(deviceExport, '设备数据', tableApi.formApi.form.values, {
|
|
||||||
fieldMappingTime: formOptions.fieldMappingTime,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getProductOptionList() {
|
|
||||||
try {
|
|
||||||
const res = await productList({
|
|
||||||
pageNum: 1,
|
|
||||||
pageSize: 1000,
|
|
||||||
});
|
|
||||||
productOptions.value = res.rows.map((item) => ({
|
|
||||||
label: item.productName,
|
|
||||||
value: item.id,
|
|
||||||
}));
|
|
||||||
const placeholder = productOptions.value.length > 0 ? '请选择' : '暂无产品';
|
|
||||||
tableApi.formApi.updateSchema([
|
|
||||||
{
|
|
||||||
componentProps: {
|
|
||||||
options: productOptions.value || [],
|
|
||||||
placeholder,
|
|
||||||
},
|
|
||||||
fieldName: 'productId',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('获取产品列表失败:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getProductOptionList();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page :auto-content-height="true">
|
<Page :auto-content-height="true" content-class="flex flex-col">
|
||||||
<BasicTable table-title="设备列表">
|
<Space class="bg-background main-box-header mb-3 rounded-lg p-5">
|
||||||
<template #toolbar-tools>
|
<Form layout="inline" :model="formModel">
|
||||||
|
<FormItem label="设备KEY">
|
||||||
|
<Input
|
||||||
|
v-model:value="formModel.deviceKey"
|
||||||
|
allow-clear
|
||||||
|
placeholder="请输入"
|
||||||
|
/>
|
||||||
|
</FormItem>
|
||||||
|
<FormItem label="设备名称">
|
||||||
|
<Input
|
||||||
|
v-model:value="formModel.deviceName"
|
||||||
|
allow-clear
|
||||||
|
placeholder="请输入"
|
||||||
|
/>
|
||||||
|
</FormItem>
|
||||||
|
<FormItem label="所属产品">
|
||||||
|
<Select
|
||||||
|
v-model:value="formModel.productId"
|
||||||
|
allow-clear
|
||||||
|
style="min-width: 200px"
|
||||||
|
>
|
||||||
|
<SelectOption
|
||||||
|
v-for="opt in productOptions"
|
||||||
|
:key="opt.value"
|
||||||
|
:value="opt.value"
|
||||||
|
>
|
||||||
|
{{ opt.label }}
|
||||||
|
</SelectOption>
|
||||||
|
</Select>
|
||||||
|
</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.deviceState"
|
||||||
|
allow-clear
|
||||||
|
style="min-width: 120px"
|
||||||
|
>
|
||||||
|
<SelectOption
|
||||||
|
v-for="opt in deviceStateOptions"
|
||||||
|
:key="opt.value"
|
||||||
|
:value="opt.value"
|
||||||
|
>
|
||||||
|
{{ opt.label }}
|
||||||
|
</SelectOption>
|
||||||
|
</Select>
|
||||||
|
</FormItem>
|
||||||
|
<div class="search-box">
|
||||||
|
<FormItem>
|
||||||
|
<Space>
|
||||||
|
<Button type="primary" @click="onSearch">查询</Button>
|
||||||
|
<Button @click="onReset">重置</Button>
|
||||||
|
</Space>
|
||||||
|
</FormItem>
|
||||||
|
</div>
|
||||||
|
</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>
|
<Space>
|
||||||
<a-button
|
<Button
|
||||||
v-access:code="['device:device:export']"
|
v-access:code="['device:device:export']"
|
||||||
@click="handleDownloadExcel"
|
@click="handleDownloadExcel"
|
||||||
>
|
>
|
||||||
{{ $t('pages.common.export') }}
|
{{ $t('pages.common.export') }}
|
||||||
</a-button>
|
</Button>
|
||||||
<a-button
|
<Button
|
||||||
:disabled="!vxeCheckboxChecked(tableApi)"
|
:disabled="selectedRowKeys.length === 0"
|
||||||
danger
|
danger
|
||||||
type="primary"
|
type="primary"
|
||||||
v-access:code="['device:device:remove']"
|
v-access:code="['device:device:remove']"
|
||||||
@click="handleMultiDelete"
|
@click="handleMultiDelete"
|
||||||
>
|
>
|
||||||
{{ $t('pages.common.delete') }}
|
{{ $t('pages.common.delete') }}
|
||||||
</a-button>
|
</Button>
|
||||||
<a-button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
v-access:code="['device:device:add']"
|
v-access:code="['device:device:add']"
|
||||||
@click="handleAdd"
|
@click="handleAdd"
|
||||||
>
|
>
|
||||||
{{ $t('pages.common.add') }}
|
{{ $t('pages.common.add') }}
|
||||||
</a-button>
|
</Button>
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
v-model:value="activeListType"
|
v-model:value="activeListType"
|
||||||
option-type="button"
|
option-type="button"
|
||||||
button-style="solid"
|
button-style="solid"
|
||||||
@change="changeListType"
|
|
||||||
>
|
>
|
||||||
<RadioButton value="card"><AppstoreOutlined /></RadioButton>
|
<RadioButton value="card"><AppstoreOutlined /></RadioButton>
|
||||||
<RadioButton value="list"><MenuOutlined /></RadioButton>
|
<RadioButton value="list"><MenuOutlined /></RadioButton>
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
|
<Button :loading="loading" @click="fetchData">
|
||||||
|
<ReloadOutlined />
|
||||||
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
</template>
|
</Space>
|
||||||
<template #deviceType="{ row }">
|
<div class="table-container p-2 pb-0 pt-0">
|
||||||
<Tag color="processing">
|
<template v-if="activeListType === 'list'">
|
||||||
{{
|
<Table
|
||||||
deviceTypeOptions.find((option) => option.value === row.deviceType)
|
class="content-table"
|
||||||
?.label
|
row-key="id"
|
||||||
}}
|
:loading="loading"
|
||||||
</Tag>
|
:columns="columns"
|
||||||
</template>
|
:data-source="dataSource"
|
||||||
<template #deviceState="{ row }">
|
size="small"
|
||||||
<Tag
|
:scroll="{ y: tableScrollHeight }"
|
||||||
:color="
|
:row-selection="{ selectedRowKeys, onChange: onSelectChange }"
|
||||||
deviceStateOptions.find(
|
:pagination="false"
|
||||||
(option) => option.value === row.deviceState,
|
>
|
||||||
)?.type
|
<template #bodyCell="{ column, record, text }">
|
||||||
|
<template v-if="column.dataIndex === 'deviceType'">
|
||||||
|
<Tag color="processing">{{ getDeviceTypeLabel(text) }}</Tag>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="column.dataIndex === 'deviceState'">
|
||||||
|
<Tag :color="getDeviceStateMeta(text).type">
|
||||||
|
{{ getDeviceStateMeta(text).label }}
|
||||||
|
</Tag>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="column.key === 'action'">
|
||||||
|
<Space>
|
||||||
|
<ghost-button
|
||||||
|
v-access:code="['device:device:view']"
|
||||||
|
@click.stop="handleView(record)"
|
||||||
|
>
|
||||||
|
详情
|
||||||
|
</ghost-button>
|
||||||
|
<ghost-button
|
||||||
|
v-access:code="['device:device:edit']"
|
||||||
|
@click.stop="handleEdit(record)"
|
||||||
|
>
|
||||||
|
{{ $t('pages.common.edit') }}
|
||||||
|
</ghost-button>
|
||||||
|
<Popconfirm
|
||||||
|
title="确认删除?"
|
||||||
|
@confirm="handleDelete(record)"
|
||||||
|
>
|
||||||
|
<ghost-button
|
||||||
|
danger
|
||||||
|
v-access:code="['device:device:remove']"
|
||||||
|
>
|
||||||
|
{{ $t('pages.common.delete') }}
|
||||||
|
</ghost-button>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
</template>
|
||||||
|
</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 min-w-0 flex-1">
|
||||||
|
<!-- <div class="mb-1 text-lg font-medium">
|
||||||
|
{{ item.deviceName || '-' }}
|
||||||
|
</div> -->
|
||||||
|
<EllipsisText class="mb-1 text-lg font-medium">
|
||||||
|
{{ item.deviceName || '-' }}
|
||||||
|
</EllipsisText>
|
||||||
|
<div>
|
||||||
|
所属产品:{{ item.productObj?.productName || '-' }}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
设备类型:{{ getDeviceTypeLabel(item.deviceType) }}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="card-status"
|
||||||
|
:class="
|
||||||
|
getDeviceStateMeta(item.deviceState).type ===
|
||||||
|
'success'
|
||||||
|
? 'enabled'
|
||||||
|
: 'disabled'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{{ getDeviceStateMeta(item.deviceState).label }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<template #actions>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
v-access:code="['device:device:edit']"
|
||||||
|
:icon="h(EditOutlined)"
|
||||||
|
@click.stop="handleEdit(item)"
|
||||||
|
>
|
||||||
|
{{ $t('pages.common.edit') }}
|
||||||
|
</Button>
|
||||||
|
<Popconfirm
|
||||||
|
title="确认删除?"
|
||||||
|
@confirm.stop="handleDelete(item)"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
:icon="h(DeleteOutlined)"
|
||||||
|
danger
|
||||||
|
@click.stop
|
||||||
|
v-access:code="['device:device: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) => {
|
||||||
deviceStateOptions.find(
|
pagination.current = 1;
|
||||||
(option) => option.value === row.deviceState,
|
pagination.pageSize = s;
|
||||||
)?.label
|
fetchData();
|
||||||
}}
|
}
|
||||||
</Tag>
|
"
|
||||||
</template>
|
/>
|
||||||
<template #action="{ row }">
|
</div>
|
||||||
<Space>
|
</div>
|
||||||
<ghost-button
|
|
||||||
v-access:code="['device:device:view']"
|
<DeviceDrawer @reload="fetchData()" />
|
||||||
@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
|
|
||||||
:get-popup-container="getVxePopupContainer"
|
|
||||||
placement="left"
|
|
||||||
title="确认删除?"
|
|
||||||
@confirm="handleDelete(row)"
|
|
||||||
>
|
|
||||||
<ghost-button
|
|
||||||
danger
|
|
||||||
v-access:code="['device:device:remove']"
|
|
||||||
@click.stop=""
|
|
||||||
>
|
|
||||||
{{ $t('pages.common.delete') }}
|
|
||||||
</ghost-button>
|
|
||||||
</Popconfirm>
|
|
||||||
</Space>
|
|
||||||
</template>
|
|
||||||
</BasicTable>
|
|
||||||
<DeviceDrawer @reload="tableApi.query()" />
|
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style scoped lang="scss">
|
||||||
.ant-radio-button-wrapper {
|
.main-box-header {
|
||||||
padding: 0 10px;
|
width: 100%;
|
||||||
|
padding: 20px;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.main-box-header .ant-space-item) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box {
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-list-item) {
|
||||||
|
padding: 12px 0;
|
||||||
|
margin-bottom: 20px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.ant-card-body) {
|
||||||
|
padding: 25px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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>
|
</style>
|
||||||
|
|
|
@ -23,7 +23,6 @@ const productStore = useProductStore();
|
||||||
|
|
||||||
const productId = computed(() => route.params.id as string);
|
const productId = computed(() => route.params.id as string);
|
||||||
const activeTab = computed(() => productStore.getTabActiveKey);
|
const activeTab = computed(() => productStore.getTabActiveKey);
|
||||||
const deviceCount = computed(() => productStore.getDeviceCount);
|
|
||||||
const currentProduct = computed(() => productStore.getCurrentProduct);
|
const currentProduct = computed(() => productStore.getCurrentProduct);
|
||||||
|
|
||||||
// 加载产品信息
|
// 加载产品信息
|
||||||
|
@ -74,9 +73,9 @@ const handleApplyConfig = async () => {
|
||||||
// 跳转到设备列表
|
// 跳转到设备列表
|
||||||
const jumpToDevices = () => {
|
const jumpToDevices = () => {
|
||||||
router.push({
|
router.push({
|
||||||
path: '/device/instance',
|
path: '/device/device',
|
||||||
query: {
|
query: {
|
||||||
productId: productId.value,
|
productId: currentProduct.value.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -148,7 +147,8 @@ onUnmounted(() => {
|
||||||
<Image :width="55" :src="currentProduct.imgUrl" />
|
<Image :width="55" :src="currentProduct.imgUrl" />
|
||||||
</div>
|
</div>
|
||||||
<div class="basic-item">
|
<div class="basic-item">
|
||||||
<span>设备数量:</span><a @click="jumpToDevices">{{ deviceCount }}</a>
|
<span>设备数量:</span>
|
||||||
|
<a @click="jumpToDevices">{{ currentProduct.deviceCount }}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts" name="ProductIndex">
|
||||||
import type { ProductForm } from '#/api/device/product/model';
|
import type { ProductForm } from '#/api/device/product/model';
|
||||||
|
|
||||||
import { h, nextTick, onMounted, onUnmounted, reactive, ref } from 'vue';
|
import { h, nextTick, onMounted, onUnmounted, reactive, ref } from 'vue';
|
||||||
|
@ -80,9 +80,9 @@ const pageSizeOptions = ref<string[]>(['12', '24', '36', '48', '60']);
|
||||||
|
|
||||||
// 选中行
|
// 选中行
|
||||||
const selectedRowKeys = ref<(number | string)[]>([]);
|
const selectedRowKeys = ref<(number | string)[]>([]);
|
||||||
function onSelectChange(keys: (number | string)[]) {
|
const onSelectChange = (keys: (number | string)[]) => {
|
||||||
selectedRowKeys.value = keys;
|
selectedRowKeys.value = keys;
|
||||||
}
|
};
|
||||||
|
|
||||||
// 列定义
|
// 列定义
|
||||||
const columns = [
|
const columns = [
|
||||||
|
@ -95,12 +95,12 @@ const columns = [
|
||||||
{ title: '操作', key: 'action', width: 200, fixed: 'right', align: 'center' },
|
{ title: '操作', key: 'action', width: 200, fixed: 'right', align: 'center' },
|
||||||
];
|
];
|
||||||
|
|
||||||
function getDeviceTypeLabel(value?: string) {
|
const getDeviceTypeLabel = (value?: string) => {
|
||||||
const match = deviceTypeOptions.find((option) => option.value === value);
|
const match = deviceTypeOptions.find((option) => option.value === value);
|
||||||
return match ? match.label : '-';
|
return match ? match.label : '-';
|
||||||
}
|
};
|
||||||
|
|
||||||
async function fetchData() {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const { rows = [], total = 0 } = (await productList({
|
const { rows = [], total = 0 } = (await productList({
|
||||||
|
@ -113,14 +113,14 @@ async function fetchData() {
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function onSearch() {
|
const onSearch = () => {
|
||||||
pagination.current = 1;
|
pagination.current = 1;
|
||||||
fetchData();
|
fetchData();
|
||||||
}
|
};
|
||||||
|
|
||||||
function onReset() {
|
const onReset = () => {
|
||||||
formModel.productKey = undefined;
|
formModel.productKey = undefined;
|
||||||
formModel.productName = undefined;
|
formModel.productName = undefined;
|
||||||
formModel.categoryId = undefined;
|
formModel.categoryId = undefined;
|
||||||
|
@ -128,30 +128,30 @@ function onReset() {
|
||||||
formModel.enabled = undefined;
|
formModel.enabled = undefined;
|
||||||
pagination.current = 1;
|
pagination.current = 1;
|
||||||
fetchData();
|
fetchData();
|
||||||
}
|
};
|
||||||
|
|
||||||
function handleAdd() {
|
const handleAdd = () => {
|
||||||
drawerApi.setData({});
|
drawerApi.setData({});
|
||||||
drawerApi.open();
|
drawerApi.open();
|
||||||
}
|
};
|
||||||
|
|
||||||
async function handleView(row: Required<ProductForm>) {
|
const handleView = async (row: Required<ProductForm>) => {
|
||||||
productStore.setCurrent(row);
|
productStore.setCurrent(row);
|
||||||
productStore.setTabActiveKey('BasicInfo');
|
productStore.setTabActiveKey('BasicInfo');
|
||||||
router.push(`/device/product/detail/${row.id}`);
|
router.push(`/device/product/detail/${row.id}`);
|
||||||
}
|
};
|
||||||
|
|
||||||
async function handleEdit(row: Required<ProductForm>) {
|
const handleEdit = async (row: Required<ProductForm>) => {
|
||||||
drawerApi.setData({ id: row.id });
|
drawerApi.setData({ id: row.id });
|
||||||
drawerApi.open();
|
drawerApi.open();
|
||||||
}
|
};
|
||||||
|
|
||||||
async function handleDelete(row: Required<ProductForm>) {
|
const handleDelete = async (row: Required<ProductForm>) => {
|
||||||
await productRemove(row.id);
|
await productRemove(row.id);
|
||||||
await fetchData();
|
await fetchData();
|
||||||
}
|
};
|
||||||
|
|
||||||
function handleMultiDelete() {
|
const handleMultiDelete = () => {
|
||||||
if (selectedRowKeys.value.length === 0) return;
|
if (selectedRowKeys.value.length === 0) return;
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
|
@ -163,18 +163,18 @@ function handleMultiDelete() {
|
||||||
await fetchData();
|
await fetchData();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function handleDownloadExcel() {
|
const handleDownloadExcel = () => {
|
||||||
commonDownloadExcel(productExport, '设备产品数据', { ...formModel }, {});
|
commonDownloadExcel(productExport, '设备产品数据', { ...formModel }, {});
|
||||||
}
|
};
|
||||||
|
|
||||||
async function handleToggleEnabled(row: Required<ProductForm>) {
|
const handleToggleEnabled = async (row: Required<ProductForm>) => {
|
||||||
const next = row.enabled === '1' ? '0' : '1';
|
const next = row.enabled === '1' ? '0' : '1';
|
||||||
await (productUpdateStatus as any)({ id: row.id, enabled: next });
|
await (productUpdateStatus as any)({ id: row.id, enabled: next });
|
||||||
message.success(next === '1' ? '已启用' : '已禁用');
|
message.success(next === '1' ? '已启用' : '已禁用');
|
||||||
await fetchData();
|
await fetchData();
|
||||||
}
|
};
|
||||||
|
|
||||||
const tableScrollHeight = ref(400);
|
const tableScrollHeight = ref(400);
|
||||||
|
|
||||||
|
@ -191,9 +191,9 @@ const updateTableHeight = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
async function loadCategories() {
|
const loadCategories = async () => {
|
||||||
categoryTree.value = await productCategoryTreeList();
|
categoryTree.value = await productCategoryTreeList();
|
||||||
}
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
updateTableHeight();
|
updateTableHeight();
|
||||||
|
@ -272,12 +272,14 @@ const [ProductDrawer, drawerApi] = useVbenDrawer({
|
||||||
</SelectOption>
|
</SelectOption>
|
||||||
</Select>
|
</Select>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem>
|
<div class="search-box">
|
||||||
<Space>
|
<FormItem>
|
||||||
<Button type="primary" @click="onSearch">查询</Button>
|
<Space>
|
||||||
<Button @click="onReset">重置</Button>
|
<Button type="primary" @click="onSearch">查询</Button>
|
||||||
</Space>
|
<Button @click="onReset">重置</Button>
|
||||||
</FormItem>
|
</Space>
|
||||||
|
</FormItem>
|
||||||
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
</Space>
|
</Space>
|
||||||
<div class="bg-background main-box-content">
|
<div class="bg-background main-box-content">
|
||||||
|
@ -505,6 +507,14 @@ const [ProductDrawer, drawerApi] = useVbenDrawer({
|
||||||
padding-bottom: 8px;
|
padding-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:deep(.main-box-header .ant-space-item) {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box {
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.main-box-content {
|
.main-box-content {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|
|
@ -8,12 +8,15 @@ import { cloneDeep } from '@vben/utils';
|
||||||
import { useVbenForm } from '#/adapter/form';
|
import { useVbenForm } from '#/adapter/form';
|
||||||
import { productAdd, productInfo, productUpdate } from '#/api/device/product';
|
import { productAdd, productInfo, productUpdate } from '#/api/device/product';
|
||||||
import { productCategoryTreeList } from '#/api/device/productCategory';
|
import { productCategoryTreeList } from '#/api/device/productCategory';
|
||||||
|
import { useDeviceStore } from '#/store/device';
|
||||||
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||||
|
|
||||||
import { drawerSchema } from './data';
|
import { drawerSchema } from './data';
|
||||||
|
|
||||||
const emit = defineEmits<{ reload: [] }>();
|
const emit = defineEmits<{ reload: [] }>();
|
||||||
|
|
||||||
|
const deviceStore = useDeviceStore();
|
||||||
|
|
||||||
const isUpdate = ref(false);
|
const isUpdate = ref(false);
|
||||||
const title = computed(() => {
|
const title = computed(() => {
|
||||||
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||||
|
@ -35,10 +38,12 @@ const [BasicForm, formApi] = useVbenForm({
|
||||||
wrapperClass: 'grid-cols-2',
|
wrapperClass: 'grid-cols-2',
|
||||||
});
|
});
|
||||||
|
|
||||||
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff({
|
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||||
initializedGetter: defaultFormValueGetter(formApi),
|
{
|
||||||
currentGetter: defaultFormValueGetter(formApi),
|
initializedGetter: defaultFormValueGetter(formApi),
|
||||||
});
|
currentGetter: defaultFormValueGetter(formApi),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const [BasicDrawer, drawerApi] = useVbenDrawer({
|
const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||||
// 在这里更改宽度
|
// 在这里更改宽度
|
||||||
|
@ -55,11 +60,15 @@ const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||||
|
|
||||||
const { id } = drawerApi.getData() as { id?: number | string };
|
const { id } = drawerApi.getData() as { id?: number | string };
|
||||||
isUpdate.value = !!id;
|
isUpdate.value = !!id;
|
||||||
formApi.updateSchema([{ componentProps: { disabled: isUpdate.value }, fieldName: 'productKey' }]);
|
formApi.updateSchema([
|
||||||
|
{ componentProps: { disabled: isUpdate.value }, fieldName: 'productKey' },
|
||||||
|
]);
|
||||||
|
|
||||||
if (isUpdate.value && id) {
|
if (isUpdate.value && id) {
|
||||||
const record = await productInfo(id);
|
const record = await productInfo(id);
|
||||||
await formApi.setValues(record);
|
await formApi.setValues(record);
|
||||||
|
} else {
|
||||||
|
await formApi.setFieldValue('imgId', deviceStore.getDefaultDeviceImgId);
|
||||||
}
|
}
|
||||||
await markInitialized();
|
await markInitialized();
|
||||||
|
|
||||||
|
@ -77,6 +86,9 @@ async function handleConfirm() {
|
||||||
}
|
}
|
||||||
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
|
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
|
||||||
const data = cloneDeep(await formApi.getValues());
|
const data = cloneDeep(await formApi.getValues());
|
||||||
|
if (data.imgId === undefined || data.imgId === '') {
|
||||||
|
data.imgId = deviceStore.getDefaultDeviceImgId;
|
||||||
|
}
|
||||||
await (isUpdate.value ? productUpdate(data) : productAdd(data));
|
await (isUpdate.value ? productUpdate(data) : productAdd(data));
|
||||||
resetInitialized();
|
resetInitialized();
|
||||||
emit('reload');
|
emit('reload');
|
||||||
|
|
|
@ -29,7 +29,8 @@ export default defineConfig(async () => {
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/api/, ''),
|
rewrite: (path) => path.replace(/^\/api/, ''),
|
||||||
// mock代理目标地址
|
// mock代理目标地址
|
||||||
target: 'http://192.168.1.17:6666',
|
// target: 'http://192.168.1.17:6666',
|
||||||
|
target: 'http://192.168.1.100:6666',
|
||||||
ws: true,
|
ws: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue