Parcourir la source

feat: 设备配置新增监护对象年龄与监护对象类型配置;

liujia il y a 1 mois
Parent
commit
5152d4d2d6

+ 4 - 0
src/api/device/types.ts

@@ -215,6 +215,8 @@ export interface DeviceDetailData {
   updateId: ID // 修改人
   createTime: string // 创建时间
   updateTime: string // 修改时间
+  age: ID // 监护对象年龄
+  guardianshipType: ID // 监护对象类型
 }
 
 /**
@@ -255,4 +257,6 @@ export interface UpdateDeviceParams {
   zzStart?: ID // 雷达监测范围z开始,范围:0-5 cm之内
   zzEnd?: ID // 雷达监测范围z结束,范围:200-300 cm之内
   fallingConfirm?: ID // 设备跌倒确认时间 通常180s
+  age?: number | null // 监护对象年龄
+  guardianshipType?: string | null // 监护对象类型
 }

+ 4 - 1
src/views/dashboard/index.vue

@@ -17,7 +17,10 @@
         </div>
         <div class="data-row">
           <ObjectDistributionCard :guardList="todayData.guardList"></ObjectDistributionCard>
-          <AlertFallCompareCard :fall-count="12" :alert-count="24"></AlertFallCompareCard>
+          <AlertFallCompareCard
+            :fall-count="todayData.fallingCount"
+            :alert-count="todayData.alarmCount"
+          ></AlertFallCompareCard>
         </div>
         <DeviceLocationCard :data="todayData.installPositionList"></DeviceLocationCard>
       </div>

+ 67 - 0
src/views/device/detail/components/deviceBaseConfig/index.vue

@@ -191,6 +191,7 @@
           placeholder="请选择归属租户"
           :options="tenantOptions"
           :style="inputStyle"
+          allow-clear
         >
         </a-select>
       </a-form-item>
@@ -210,6 +211,32 @@
           </template>
         </a-input>
       </a-form-item>
+      <a-form-item label="监护对象年龄" name="guardAge">
+        <a-input
+          v-model:value.trim="baseFormState.guardAge"
+          placeholder="请输入监护对象年龄"
+          :style="inputStyle"
+        >
+          <template #suffix>
+            <a-tooltip>
+              <template #title>
+                <div>年龄范围: 1 - 120</div>
+              </template>
+              <info-circle-outlined style="color: rgba(0, 0, 0, 0.45)" />
+            </a-tooltip>
+          </template>
+        </a-input>
+      </a-form-item>
+      <a-form-item label="监护对象类型" name="guardType">
+        <a-select
+          v-model:value="baseFormState.guardType"
+          placeholder="请选择监护对象类型"
+          :options="guardTypeOptions"
+          :style="inputStyle"
+          allow-clear
+        >
+        </a-select>
+      </a-form-item>
 
       <div class="footer" :style="{ marginLeft: '100px' }">
         <a-space>
@@ -236,6 +263,7 @@ import * as deviceApi from '@/api/device'
 import * as tenantAPI from '@/api/tenant'
 import type { TenantItem } from '@/api/tenant/types'
 import { useUserStore } from '@/stores/user'
+import { useDict } from '@/hooks/useDict'
 
 defineOptions({
   name: 'deviceBaseConfig',
@@ -271,6 +299,8 @@ interface BaseFormState {
   northAngle: NorthAngle // 正北向夹角
   tenantId: ID // 租户id
   fallingConfirm: ID // 跌倒确认
+  guardAge?: ID // 监护对象年龄
+  guardType?: ID // 监护对象类型
 }
 
 const spinning = ref(false)
@@ -288,6 +318,8 @@ const baseFormState = reactive<BaseFormState>({
   northAngle: 0,
   tenantId: null,
   fallingConfirm: 53,
+  guardAge: null,
+  guardType: null,
 })
 
 // 范围输入框尺寸
@@ -328,6 +360,8 @@ const saveBaseConfig = async () => {
             Number(baseFormState?.fallingConfirm) > 0
               ? Number(baseFormState?.fallingConfirm)
               : null,
+          age: baseFormState?.guardAge ? Number(baseFormState?.guardAge) : null,
+          guardianshipType: baseFormState?.guardType ? String(baseFormState?.guardType) : null,
         })
         saveBaseLoading.value = false
         message.success('保存成功')
@@ -383,6 +417,24 @@ const rules: Record<string, Rule[]> = {
       trigger: ['change', 'blur'],
     },
   ],
+  guardAge: [
+    {
+      validator: (_rule: Rule, value: string) => {
+        if (!value) {
+          return Promise.resolve()
+        }
+        if (!/^\d+$/.test(value)) {
+          return Promise.reject(new Error('必须为整数'))
+        }
+        const num = parseInt(value, 10)
+        if (num < 1 || num > 120) {
+          return Promise.reject(new Error('年龄范围: 1 - 120'))
+        }
+        return Promise.resolve()
+      },
+      trigger: ['change', 'blur'],
+    },
+  ],
   // xRangeStart: [
   //   {
   //     required: true,
@@ -449,6 +501,19 @@ const fetchTenantList = async () => {
 }
 fetchTenantList()
 
+const guardTypeOptions = ref<{ label: string; value: string }[]>([])
+const { dictList, fetchDict } = useDict('guardianship_type')
+
+const fetchGuardTypeOptions = async () => {
+  fetchDict().then(() => {
+    guardTypeOptions.value = dictList.value.map((item) => ({
+      label: item.label,
+      value: item.value as string,
+    }))
+  })
+}
+fetchGuardTypeOptions()
+
 // 获取设备回显数据
 const fetchDeviceBaseInfo = async () => {
   console.log('fetchDeviceDetail', props)
@@ -475,6 +540,8 @@ const fetchDeviceBaseInfo = async () => {
     baseFormState.northAngle = res.data.northAngle
     baseFormState.tenantId = res.data.tenantId
     baseFormState.fallingConfirm = res.data.fallingConfirm
+    baseFormState.guardAge = res.data.age
+    baseFormState.guardType = res.data.guardianshipType
   } catch (error) {
     console.error('❌获取设备详情失败', error)
   }