Compare commits
No commits in common. "e12b7cedfabddef8c0e8f4af35a2563587e210fd" and "8cbd9cc530beebe6bd12fe919e53af8da5dd27a5" have entirely different histories.
e12b7cedfa
...
8cbd9cc530
@ -111,7 +111,6 @@ export type ComponentType =
|
|||||||
| 'CheckboxGroup'
|
| 'CheckboxGroup'
|
||||||
| 'DatePicker'
|
| 'DatePicker'
|
||||||
| 'DefaultButton'
|
| 'DefaultButton'
|
||||||
| 'DeviceSelect'
|
|
||||||
| 'Divider'
|
| 'Divider'
|
||||||
| 'IconPicker'
|
| 'IconPicker'
|
||||||
| 'Input'
|
| 'Input'
|
||||||
@ -169,10 +168,6 @@ async function initComponentAdapter() {
|
|||||||
Checkbox,
|
Checkbox,
|
||||||
CheckboxGroup,
|
CheckboxGroup,
|
||||||
DatePicker,
|
DatePicker,
|
||||||
// 自定义设备选择组件
|
|
||||||
DeviceSelect: defineAsyncComponent(() =>
|
|
||||||
import('../../views/dataManger/deviceData/DeviceSelect.vue')
|
|
||||||
),
|
|
||||||
// 自定义默认按钮
|
// 自定义默认按钮
|
||||||
DefaultButton: (props, { attrs, slots }) => {
|
DefaultButton: (props, { attrs, slots }) => {
|
||||||
return h(Button, { ...props, attrs, type: 'default' }, slots);
|
return h(Button, { ...props, attrs, type: 'default' }, slots);
|
||||||
|
|||||||
@ -1,9 +1,4 @@
|
|||||||
/*
|
|
||||||
* @Description: 文件内容描述
|
|
||||||
* @Author: 陈益
|
|
||||||
* @Date: 2025-06-19 15:33:54
|
|
||||||
* @LastEditors: 陈益
|
|
||||||
*/
|
|
||||||
export * from './auth';
|
export * from './auth';
|
||||||
export * from './menu';
|
export * from './menu';
|
||||||
|
export * from './onenet';
|
||||||
export * from './user';
|
export * from './user';
|
||||||
|
|||||||
@ -1,160 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref, computed } from 'vue';
|
|
||||||
import { Select, Divider, Row } from 'ant-design-vue';
|
|
||||||
import { ChevronLeft, ChevronRight } from '@vben/icons';
|
|
||||||
import { postMetersPage } from '#/api-client';
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
import { useDebounceFn } from '@vueuse/core';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
value?: string;
|
|
||||||
placeholder?: string;
|
|
||||||
disabled?: boolean;
|
|
||||||
allowClear?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
|
||||||
placeholder: $t('common.pleaseSelect') + $t('abp.log.deviceInfo'),
|
|
||||||
disabled: false,
|
|
||||||
allowClear: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
'update:value': [string];
|
|
||||||
change: [string];
|
|
||||||
'device-change': [any]; // 添加设备信息变化事件
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const VNodes = (_, { attrs }: any) => {
|
|
||||||
return attrs.vnodes;
|
|
||||||
};
|
|
||||||
|
|
||||||
const options = ref<any[]>([]);
|
|
||||||
const query = ref({
|
|
||||||
pageIndex: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
SearchKeyword: '',
|
|
||||||
});
|
|
||||||
const total = ref(0);
|
|
||||||
const loading = ref<boolean>(false);
|
|
||||||
|
|
||||||
// 最大页码
|
|
||||||
const maxPage = computed(() => {
|
|
||||||
return Math.ceil(total.value / query.value.pageSize);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取设备列表数据
|
|
||||||
*/
|
|
||||||
const fetchData = async () => {
|
|
||||||
loading.value = true;
|
|
||||||
try {
|
|
||||||
const { data } = await postMetersPage({
|
|
||||||
body: {
|
|
||||||
pageIndex: query.value.pageIndex,
|
|
||||||
pageSize: query.value.pageSize,
|
|
||||||
SearchKeyword: query.value.SearchKeyword,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (data?.items) {
|
|
||||||
options.value = data.items.map((item) => ({
|
|
||||||
label: item.meterName,
|
|
||||||
value: item.id,
|
|
||||||
...item, // 保留完整数据
|
|
||||||
}));
|
|
||||||
total.value = data.totalCount || 0;
|
|
||||||
}
|
|
||||||
loading.value = false;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('获取设备列表失败:', error);
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 上下页
|
|
||||||
* @param type 1: 下一页, 0: 上一页
|
|
||||||
*/
|
|
||||||
const changePage = (type: number) => {
|
|
||||||
if (type === 1) {
|
|
||||||
if (query.value.pageIndex >= maxPage.value) return;
|
|
||||||
query.value.pageIndex += 1;
|
|
||||||
fetchData();
|
|
||||||
} else {
|
|
||||||
if (query.value.pageIndex <= 1) return;
|
|
||||||
query.value.pageIndex -= 1;
|
|
||||||
fetchData();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备搜索
|
|
||||||
*/
|
|
||||||
const fetchDevice = useDebounceFn((value: string) => {
|
|
||||||
query.value.pageIndex = 1;
|
|
||||||
query.value.SearchKeyword = value;
|
|
||||||
fetchData();
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
// 处理值变化
|
|
||||||
const handleValueChange = (value: string) => {
|
|
||||||
emit('update:value', value);
|
|
||||||
emit('change', value);
|
|
||||||
|
|
||||||
// 发送选中的设备信息
|
|
||||||
if (value) {
|
|
||||||
const selectedDevice = options.value.find(option => option.value === value);
|
|
||||||
if (selectedDevice) {
|
|
||||||
emit('device-change', selectedDevice);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
emit('device-change', null);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 初始化加载数据
|
|
||||||
fetchData();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Select
|
|
||||||
:value="value"
|
|
||||||
:showSearch="true"
|
|
||||||
@search="fetchDevice"
|
|
||||||
:options="options"
|
|
||||||
:placeholder="placeholder"
|
|
||||||
:filter-option="false"
|
|
||||||
:disabled="disabled"
|
|
||||||
:allowClear="allowClear"
|
|
||||||
:loading="loading"
|
|
||||||
@change="handleValueChange"
|
|
||||||
>
|
|
||||||
<template #dropdownRender="{ menuNode: menu }">
|
|
||||||
<v-nodes :vnodes="menu" />
|
|
||||||
<Divider style="margin: 4px 0" />
|
|
||||||
<div @mousedown="(e) => e.preventDefault()">
|
|
||||||
<Row type="flex" justify="space-around" align="middle">
|
|
||||||
<ChevronLeft
|
|
||||||
@click="changePage(0)"
|
|
||||||
:class="{ 'text-gray-400': query.pageIndex <= 1 }"
|
|
||||||
style="cursor: pointer; width: 16px; height: 16px;"
|
|
||||||
/>
|
|
||||||
<div>{{ `${query.pageIndex}/${maxPage}` }}</div>
|
|
||||||
<ChevronRight
|
|
||||||
@click="changePage(1)"
|
|
||||||
:class="{ 'text-gray-400': query.pageIndex >= maxPage }"
|
|
||||||
style="cursor: pointer; width: 16px; height: 16px;"
|
|
||||||
/>
|
|
||||||
</Row>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</Select>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style lang="less" scoped>
|
|
||||||
.text-gray-400 {
|
|
||||||
color: #9ca3af;
|
|
||||||
cursor: not-allowed !important;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@ -20,10 +20,8 @@ defineOptions({
|
|||||||
|
|
||||||
// 存储设备信息选项的完整数据
|
// 存储设备信息选项的完整数据
|
||||||
const deviceOptions = ref<any[]>([]);
|
const deviceOptions = ref<any[]>([]);
|
||||||
// 当前选中的设备信息
|
|
||||||
const selectedDeviceInfo = ref<any>(null);
|
|
||||||
|
|
||||||
// 获取设备信息的完整数据(用于根据设备ID获取设备信息)
|
// 获取设备信息的完整数据
|
||||||
const fetchDeviceOptions = async () => {
|
const fetchDeviceOptions = async () => {
|
||||||
try {
|
try {
|
||||||
const { data } = await postMetersPage({
|
const { data } = await postMetersPage({
|
||||||
@ -47,12 +45,6 @@ const getDeviceInfoById = (deviceId: string) => {
|
|||||||
return deviceOptions.value.find((device) => device.id === deviceId);
|
return deviceOptions.value.find((device) => device.id === deviceId);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理设备选择变化
|
|
||||||
const handleDeviceChange = (deviceInfo: any) => {
|
|
||||||
selectedDeviceInfo.value = deviceInfo;
|
|
||||||
console.log('设备选择变化:', deviceInfo);
|
|
||||||
};
|
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { DeviceType, DeviceId, FocusAddress, SystemName } = route.query;
|
const { DeviceType, DeviceId, FocusAddress, SystemName } = route.query;
|
||||||
|
|
||||||
@ -130,10 +122,6 @@ const formOptions: VbenFormProps = {
|
|||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 添加事件处理函数
|
|
||||||
events: {
|
|
||||||
handleDeviceChange,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const gridOptions: VxeGridProps<any> = {
|
const gridOptions: VxeGridProps<any> = {
|
||||||
@ -185,9 +173,8 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
// 处理DeviceId,当设备类型为集中器(10)时,使用focusId
|
// 处理DeviceId,当设备类型为集中器(10)时,使用focusId
|
||||||
let finalDeviceId = formValues.DeviceId || DeviceId;
|
let finalDeviceId = formValues.DeviceId || DeviceId;
|
||||||
let finalFocusAddress = formValues.FocusAddress;
|
let finalFocusAddress = formValues.FocusAddress;
|
||||||
|
if (formValues.DeviceId) {
|
||||||
// 优先使用选中的设备信息
|
const deviceInfo = getDeviceInfoById(formValues.DeviceId);
|
||||||
const deviceInfo = selectedDeviceInfo.value || (formValues.DeviceId ? getDeviceInfoById(formValues.DeviceId) : null);
|
|
||||||
if (deviceInfo) {
|
if (deviceInfo) {
|
||||||
finalFocusAddress = deviceInfo.focusAddress;
|
finalFocusAddress = deviceInfo.focusAddress;
|
||||||
if (deviceTypeNumber === 10) {
|
if (deviceTypeNumber === 10) {
|
||||||
@ -202,6 +189,7 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const { data } = await postTreeModelDeviceDataInfoPage({
|
const { data } = await postTreeModelDeviceDataInfoPage({
|
||||||
body: {
|
body: {
|
||||||
|
|||||||
@ -106,13 +106,46 @@ export const querySchema = computed(() => [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'DeviceSelect',
|
component: 'ApiSelect',
|
||||||
fieldName: 'DeviceId',
|
fieldName: 'DeviceId',
|
||||||
label: $t('abp.log.deviceInfo'),
|
label: $t('abp.log.deviceInfo'),
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: $t('common.pleaseSelect') + $t('abp.log.deviceInfo'),
|
api: postMetersPage,
|
||||||
|
params: {
|
||||||
|
body: {
|
||||||
|
pageIndex: 1,
|
||||||
|
pageSize: 1000, // 获取足够多的数据用于下拉选择
|
||||||
|
},
|
||||||
|
},
|
||||||
|
labelField: 'meterName',
|
||||||
|
valueField: 'id', // 使用id作为值,这样可以获取完整的对象
|
||||||
|
optionsPropName: 'options',
|
||||||
|
immediate: true,
|
||||||
|
showSearch: true,
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
onDeviceChange: 'handleDeviceChange',
|
placeholder: $t('common.pleaseSelect') + $t('abp.log.deviceInfo'),
|
||||||
|
filterOption: false, // 禁用本地过滤,使用服务端搜索
|
||||||
|
optionFilterProp: 'label', // 根据 label 进行过滤
|
||||||
|
afterFetch: (res: any) => {
|
||||||
|
// 确保返回的是数组格式
|
||||||
|
if (Array.isArray(res)) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
// 如果是包装在 items 中的,提取出来
|
||||||
|
if (res && Array.isArray(res.items)) {
|
||||||
|
return res.items;
|
||||||
|
}
|
||||||
|
// 如果是包装在 data 中的,提取出来
|
||||||
|
if (res && Array.isArray(res.data)) {
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
// 如果是包装在 data.items 中的,提取出来
|
||||||
|
if (res && res.data && Array.isArray(res.data.items)) {
|
||||||
|
return res.data.items;
|
||||||
|
}
|
||||||
|
// 如果都不是,返回空数组
|
||||||
|
return [];
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user