|
|
@@ -7,24 +7,21 @@ import { formatIotValue } from '@/utils/useSocketBus'
|
|
|
import { useDebounceFn } from '@vueuse/core'
|
|
|
import { dayjs, ElMessage } from 'element-plus'
|
|
|
import { computed, ref } from 'vue'
|
|
|
-import { useI18n } from 'vue-i18n'
|
|
|
|
|
|
-const { t } = useI18n()
|
|
|
+defineOptions({ name: 'MonitoringQuery' })
|
|
|
|
|
|
const id = useUserStore().getUser.deptId ?? 157
|
|
|
const deptId = id
|
|
|
|
|
|
interface Query {
|
|
|
deptId?: number
|
|
|
- deviceName?: string
|
|
|
deviceCode?: string
|
|
|
time?: string[]
|
|
|
}
|
|
|
|
|
|
const query = ref<Query>({
|
|
|
- deviceName: '',
|
|
|
deviceCode: '',
|
|
|
- time: []
|
|
|
+ time: [...rangeShortcuts[0].value().map((item) => dayjs(item).format('YYYY-MM-DD HH:mm:ss'))]
|
|
|
})
|
|
|
|
|
|
const pageSize = ref(100)
|
|
|
@@ -46,13 +43,46 @@ const loading = ref(false)
|
|
|
|
|
|
const isConditionValid = computed(() => {
|
|
|
const hasTime = query.value.time && query.value.time.length === 2
|
|
|
- const hasIdentity = !!query.value.deviceName || !!query.value.deviceCode
|
|
|
+ const hasIdentity = !!query.value.deviceCode
|
|
|
return hasTime && hasIdentity
|
|
|
})
|
|
|
|
|
|
const canGoBack = computed(() => historyStack.value.length > 0)
|
|
|
const canGoNext = computed(() => list.value.length >= pageSize.value)
|
|
|
|
|
|
+const deviceOptions = ref<{ label: string; value: string }[]>([])
|
|
|
+
|
|
|
+const optionsLoading = ref(false)
|
|
|
+
|
|
|
+const loadOptions = useDebounceFn(async function () {
|
|
|
+ handleReset()
|
|
|
+ try {
|
|
|
+ optionsLoading.value = true
|
|
|
+ const data = await IotDeviceApi.getDevice({
|
|
|
+ deptId: query.value.deptId
|
|
|
+ })
|
|
|
+ deviceOptions.value = data.map((item: any) => {
|
|
|
+ return {
|
|
|
+ label: item.deviceCode + '-' + item.deviceName,
|
|
|
+ value: item.deviceCode
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error)
|
|
|
+ } finally {
|
|
|
+ optionsLoading.value = false
|
|
|
+ }
|
|
|
+}, 300)
|
|
|
+
|
|
|
+const handleNodeClick = (data: any) => {
|
|
|
+ query.value.deptId = data.id
|
|
|
+ loadOptions()
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ loadOptions()
|
|
|
+})
|
|
|
+
|
|
|
const loadList = useDebounceFn(async function () {
|
|
|
if (!isConditionValid.value) {
|
|
|
// list.value = []
|
|
|
@@ -82,8 +112,8 @@ const loadList = useDebounceFn(async function () {
|
|
|
})
|
|
|
|
|
|
function handleQuery() {
|
|
|
- if (!query.value.deviceName && !query.value.deviceCode) {
|
|
|
- ElMessage.warning('请输入设备名称或设备编码')
|
|
|
+ if (!query.value.deviceCode) {
|
|
|
+ ElMessage.warning('请选择设备')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -102,8 +132,7 @@ function handleQuery() {
|
|
|
function handleReset() {
|
|
|
query.value = {
|
|
|
deviceCode: '',
|
|
|
- deviceName: '',
|
|
|
- time: []
|
|
|
+ time: [...rangeShortcuts[0].value().map((item) => dayjs(item).format('YYYY-MM-DD HH:mm:ss'))]
|
|
|
}
|
|
|
list.value = []
|
|
|
historyStack.value = []
|
|
|
@@ -147,8 +176,8 @@ function handleSizeChange() {
|
|
|
const exportLoading = ref(false)
|
|
|
|
|
|
const handleExport = useDebounceFn(async function () {
|
|
|
- if (!query.value.deviceName && !query.value.deviceCode) {
|
|
|
- ElMessage.warning('请输入设备名称或设备编码')
|
|
|
+ if (!query.value.deviceCode) {
|
|
|
+ ElMessage.warning('请选择设备')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -189,7 +218,13 @@ function formatterValue(row: ListItem) {
|
|
|
class="grid grid-cols-[15%_1fr] grid-rows-[62px_1fr] gap-4 h-[calc(100vh-20px-var(--top-tool-height)-var(--tags-view-height)-var(--app-footer-height))]"
|
|
|
>
|
|
|
<div class="p-4 bg-white dark:bg-[#1d1e1f] shadow rounded-lg row-span-2">
|
|
|
- <DeptTreeSelect :top-id="156" :deptId="deptId" :init-select="false" :show-title="false" />
|
|
|
+ <DeptTreeSelect
|
|
|
+ :top-id="156"
|
|
|
+ :deptId="deptId"
|
|
|
+ :init-select="false"
|
|
|
+ :show-title="false"
|
|
|
+ @node-click="handleNodeClick"
|
|
|
+ />
|
|
|
</div>
|
|
|
|
|
|
<el-form
|
|
|
@@ -197,22 +232,13 @@ function formatterValue(row: ListItem) {
|
|
|
class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow px-8 gap-8 flex items-center justify-between"
|
|
|
>
|
|
|
<div class="flex items-center gap-8">
|
|
|
- <el-form-item :label="t('monitor.deviceName')">
|
|
|
- <el-input
|
|
|
- v-model="query.deviceName"
|
|
|
- :placeholder="t('monitor.nameHolder')"
|
|
|
- clearable
|
|
|
- @keyup.enter="handleQuery()"
|
|
|
- class="!w-240px"
|
|
|
- />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item :label="t('monitor.deviceCode')">
|
|
|
- <el-input
|
|
|
+ <el-form-item label="设备">
|
|
|
+ <el-select
|
|
|
+ :loading="optionsLoading"
|
|
|
v-model="query.deviceCode"
|
|
|
- :placeholder="t('monitor.codeHolder')"
|
|
|
- clearable
|
|
|
- @keyup.enter="handleQuery()"
|
|
|
- class="!w-240px"
|
|
|
+ :options="deviceOptions"
|
|
|
+ placeholder="请选择设备"
|
|
|
+ class="w-60!"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="时间">
|
|
|
@@ -224,7 +250,7 @@ function formatterValue(row: ListItem) {
|
|
|
end-placeholder="结束日期"
|
|
|
:shortcuts="rangeShortcuts"
|
|
|
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
|
|
|
- class="!w-352px"
|
|
|
+ class="!w-360px"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|