|
@@ -3,7 +3,7 @@
|
|
<a-modal
|
|
<a-modal
|
|
:get-container="() => $refs.mod"
|
|
:get-container="() => $refs.mod"
|
|
:open="props.open"
|
|
:open="props.open"
|
|
- :title="modelTitle"
|
|
|
|
|
|
+ :title="props.title"
|
|
:mask-closable="false"
|
|
:mask-closable="false"
|
|
width="600px"
|
|
width="600px"
|
|
@cancel="cancel"
|
|
@cancel="cancel"
|
|
@@ -217,7 +217,7 @@
|
|
</a-form-item>
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item
|
|
<a-form-item
|
|
- v-if="[1, 2, 3, 9].includes(formState?.eventType as number)"
|
|
|
|
|
|
+ v-if="props.type === 'plan' && [1, 2, 3, 9].includes(formState?.eventType as number)"
|
|
label="检测区域"
|
|
label="检测区域"
|
|
name="region"
|
|
name="region"
|
|
style="user-select: none"
|
|
style="user-select: none"
|
|
@@ -268,6 +268,12 @@
|
|
</a-form-item-rest>
|
|
</a-form-item-rest>
|
|
</a-form-item>
|
|
</a-form-item>
|
|
|
|
|
|
|
|
+ <a-form-item label="告警联动">
|
|
|
|
+ <a-checkbox v-model:checked="formState.linkagePushWechatService">
|
|
|
|
+ 微信服务号推送
|
|
|
|
+ </a-checkbox>
|
|
|
|
+ </a-form-item>
|
|
|
|
+
|
|
<a-form-item label="是否启用">
|
|
<a-form-item label="是否启用">
|
|
<a-switch v-model:checked="formState.enable" />
|
|
<a-switch v-model:checked="formState.enable" />
|
|
</a-form-item>
|
|
</a-form-item>
|
|
@@ -288,6 +294,8 @@ import { ref, reactive, watch, computed } from 'vue'
|
|
import { message, type FormInstance } from 'ant-design-vue'
|
|
import { message, type FormInstance } from 'ant-design-vue'
|
|
import * as alarmApi from '@/api/alarm'
|
|
import * as alarmApi from '@/api/alarm'
|
|
import { getOriginPosition } from '@/utils/index'
|
|
import { getOriginPosition } from '@/utils/index'
|
|
|
|
+import type { AlarmPlanParams } from '@/api/alarm/types'
|
|
|
|
+import dayjs from 'dayjs'
|
|
|
|
|
|
defineOptions({
|
|
defineOptions({
|
|
name: 'AlarmPlanModal',
|
|
name: 'AlarmPlanModal',
|
|
@@ -328,8 +336,9 @@ type AlarmPlan = {
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
open: boolean
|
|
open: boolean
|
|
|
|
+ type?: 'plan' | 'template'
|
|
title?: string
|
|
title?: string
|
|
- clientId: string // 设备ID
|
|
|
|
|
|
+ clientId?: string // 设备ID
|
|
alarmPlanId?: number | null // 告警计划ID 编辑时传入
|
|
alarmPlanId?: number | null // 告警计划ID 编辑时传入
|
|
data?: AlarmPlan // 编辑数据
|
|
data?: AlarmPlan // 编辑数据
|
|
area?: {
|
|
area?: {
|
|
@@ -345,15 +354,16 @@ const emit = defineEmits<{
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
open: false,
|
|
open: false,
|
|
|
|
+ type: 'plan',
|
|
title: '告警计划',
|
|
title: '告警计划',
|
|
clientId: '',
|
|
clientId: '',
|
|
alarmPlanId: null,
|
|
alarmPlanId: null,
|
|
data: undefined,
|
|
data: undefined,
|
|
})
|
|
})
|
|
|
|
|
|
-const modelTitle = computed(() => {
|
|
|
|
- return props.alarmPlanId ? '编辑告警计划' : '新增告警计划'
|
|
|
|
-})
|
|
|
|
|
|
+// const modelTitle = computed(() => {
|
|
|
|
+// return props.alarmPlanId ? '编辑告警计划' : '新增告警计划'
|
|
|
|
+// })
|
|
|
|
|
|
// 检测区域宽度
|
|
// 检测区域宽度
|
|
const areaWidth = computed(() => {
|
|
const areaWidth = computed(() => {
|
|
@@ -465,6 +475,7 @@ type FormState = {
|
|
effectTimeFrame: string[] // 生效时段 单条 00:00:00 - 23:59:59
|
|
effectTimeFrame: string[] // 生效时段 单条 00:00:00 - 23:59:59
|
|
effectTimeFrames: { startTime: string; endTime: string }[] // 生效时段 多条
|
|
effectTimeFrames: { startTime: string; endTime: string }[] // 生效时段 多条
|
|
enable: boolean // 是否启用
|
|
enable: boolean // 是否启用
|
|
|
|
+ linkagePushWechatService: boolean // 是否开启服务号消息推送
|
|
statisticsTime: string[] // 统计时间
|
|
statisticsTime: string[] // 统计时间
|
|
count?: number | null // 异常阈值
|
|
count?: number | null // 异常阈值
|
|
timeThreshold?: number | null // 异常消失时间阈值(单位:秒)
|
|
timeThreshold?: number | null // 异常消失时间阈值(单位:秒)
|
|
@@ -483,6 +494,7 @@ const formState = reactive<FormState>({
|
|
effectTimeFrame: [],
|
|
effectTimeFrame: [],
|
|
effectTimeFrames: [],
|
|
effectTimeFrames: [],
|
|
enable: true,
|
|
enable: true,
|
|
|
|
+ linkagePushWechatService: true,
|
|
statisticsTime: [],
|
|
statisticsTime: [],
|
|
count: 3,
|
|
count: 3,
|
|
timeThreshold: 300,
|
|
timeThreshold: 300,
|
|
@@ -493,10 +505,10 @@ const initBlocks = () => {
|
|
{
|
|
{
|
|
x: 0,
|
|
x: 0,
|
|
y: 0,
|
|
y: 0,
|
|
- ox: formState.region[0] ?? 0,
|
|
|
|
- oy: formState.region[1] ?? 0,
|
|
|
|
- width: formState.region[2] ?? 50,
|
|
|
|
- height: formState.region[3] ?? 50,
|
|
|
|
|
|
+ ox: formState.region[0],
|
|
|
|
+ oy: formState.region[1],
|
|
|
|
+ width: formState.region[2],
|
|
|
|
+ height: formState.region[3],
|
|
},
|
|
},
|
|
]
|
|
]
|
|
}
|
|
}
|
|
@@ -586,17 +598,57 @@ interface SourceData {
|
|
eventVal?: number | null
|
|
eventVal?: number | null
|
|
param?: string
|
|
param?: string
|
|
alarmTimePlan?: AlarmTimePlan
|
|
alarmTimePlan?: AlarmTimePlan
|
|
|
|
+ alarmTimePlanTpl?: AlarmTimePlan
|
|
region?: string
|
|
region?: string
|
|
enable?: number
|
|
enable?: number
|
|
|
|
+ linkagePushWechatService?: number
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 是否为有效json字符串
|
|
|
|
+const isValidJSON = (str: string) => {
|
|
|
|
+ try {
|
|
|
|
+ JSON.parse(str)
|
|
|
|
+ return true
|
|
|
|
+ } catch {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
const echoFormState = (val: SourceData) => {
|
|
const echoFormState = (val: SourceData) => {
|
|
const paramObj = safeParse<ParamType>(val.param, {})
|
|
const paramObj = safeParse<ParamType>(val.param, {})
|
|
- const weekdays = safeParse<string[]>(val.alarmTimePlan?.weekdays, [])
|
|
|
|
- const monthDays = safeParse<string[]>(val.alarmTimePlan?.monthDays, [])
|
|
|
|
- const timeFrames = safeParse<TimeFrame[]>(val.alarmTimePlan?.timeRange, [])
|
|
|
|
|
|
+ let weekdays: string[] = []
|
|
|
|
+ let monthDays: string[] = []
|
|
|
|
+ let timeFrames: TimeFrame[] = []
|
|
|
|
+ let planTimes: string[] = []
|
|
|
|
+ if (props.type === 'plan') {
|
|
|
|
+ weekdays = safeParse<string[]>(val.alarmTimePlan?.weekdays, [])
|
|
|
|
+ monthDays = safeParse<string[]>(val.alarmTimePlan?.monthDays, [])
|
|
|
|
+ timeFrames = safeParse<TimeFrame[]>(val.alarmTimePlan?.timeRange, [])
|
|
|
|
+ planTimes = [
|
|
|
|
+ dayjs(val.alarmTimePlan?.startDate).format('YYYY-MM-DD') ?? '',
|
|
|
|
+ dayjs(val.alarmTimePlan?.stopDate).format('YYYY-MM-DD') ?? '',
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ if (props.type === 'template') {
|
|
|
|
+ weekdays = safeParse<string[]>(val.alarmTimePlanTpl?.weekdays, [])
|
|
|
|
+ monthDays = safeParse<string[]>(val.alarmTimePlanTpl?.monthDays, [])
|
|
|
|
+ timeFrames = safeParse<TimeFrame[]>(val.alarmTimePlanTpl?.timeRange, [])
|
|
|
|
+ planTimes = [
|
|
|
|
+ dayjs(val.alarmTimePlanTpl?.startDate).format('YYYY-MM-DD') ?? '',
|
|
|
|
+ dayjs(val.alarmTimePlanTpl?.stopDate).format('YYYY-MM-DD') ?? '',
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+
|
|
plainOptions.value = weekdays.length === 0 ? monthOptions : weekOptions
|
|
plainOptions.value = weekdays.length === 0 ? monthOptions : weekOptions
|
|
|
|
|
|
|
|
+ let effectTimeRanges: (number | string)[] = []
|
|
|
|
+ try {
|
|
|
|
+ effectTimeRanges =
|
|
|
|
+ weekdays.length === 0 ? monthDays : weekdays.map((item: string) => numToWeekMap[Number(item)])
|
|
|
|
+ } catch {
|
|
|
|
+ effectTimeRanges = []
|
|
|
|
+ }
|
|
|
|
+
|
|
return {
|
|
return {
|
|
planName: val.name ?? '',
|
|
planName: val.name ?? '',
|
|
remark: val.remark ?? '',
|
|
remark: val.remark ?? '',
|
|
@@ -606,20 +658,18 @@ const echoFormState = (val: SourceData) => {
|
|
statisticsTime: [paramObj.start_time ?? null, paramObj.end_time ?? null] as string[],
|
|
statisticsTime: [paramObj.start_time ?? null, paramObj.end_time ?? null] as string[],
|
|
count: paramObj.count ?? null,
|
|
count: paramObj.count ?? null,
|
|
timeThreshold: paramObj.time_threshold ?? null,
|
|
timeThreshold: paramObj.time_threshold ?? null,
|
|
- planTime: [val.alarmTimePlan?.startDate ?? '', val.alarmTimePlan?.stopDate ?? ''],
|
|
|
|
|
|
+ planTime: planTimes,
|
|
effectType: (weekdays.length === 0 ? 'month' : 'week') as 'week' | 'month',
|
|
effectType: (weekdays.length === 0 ? 'month' : 'week') as 'week' | 'month',
|
|
- effectTimeRanges:
|
|
|
|
- weekdays.length === 0
|
|
|
|
- ? monthDays
|
|
|
|
- : weekdays.map((item: string) => numToWeekMap[Number(item)]),
|
|
|
|
|
|
+ effectTimeRanges,
|
|
effectTimeFrames: Array.isArray(timeFrames)
|
|
effectTimeFrames: Array.isArray(timeFrames)
|
|
? timeFrames.map((item) => ({
|
|
? timeFrames.map((item) => ({
|
|
startTime: item?.start_time ?? '',
|
|
startTime: item?.start_time ?? '',
|
|
endTime: item?.end_time ?? '',
|
|
endTime: item?.end_time ?? '',
|
|
}))
|
|
}))
|
|
: [],
|
|
: [],
|
|
- region: JSON.parse(val.region ?? '[0, 0, 50, 50]'),
|
|
|
|
|
|
+ region: isValidJSON(val?.region ?? '') && JSON.parse(val?.region ?? '[0, 0, 50, 50]'),
|
|
enable: val?.enable === 1,
|
|
enable: val?.enable === 1,
|
|
|
|
+ linkagePushWechatService: val?.linkagePushWechatService === 1,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -642,6 +692,8 @@ watch(
|
|
formState.effectTimeRanges = echoFormState(val).effectTimeRanges
|
|
formState.effectTimeRanges = echoFormState(val).effectTimeRanges
|
|
formState.effectTimeFrames = echoFormState(val).effectTimeFrames
|
|
formState.effectTimeFrames = echoFormState(val).effectTimeFrames
|
|
formState.region = echoFormState(val).region
|
|
formState.region = echoFormState(val).region
|
|
|
|
+ formState.enable = echoFormState(val).enable
|
|
|
|
+ formState.linkagePushWechatService = echoFormState(val).linkagePushWechatService
|
|
initBlocks()
|
|
initBlocks()
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -703,6 +755,7 @@ const cancel = () => {
|
|
formState.effectTimeFrame = []
|
|
formState.effectTimeFrame = []
|
|
formState.effectTimeFrames = []
|
|
formState.effectTimeFrames = []
|
|
formState.enable = true
|
|
formState.enable = true
|
|
|
|
+ formState.linkagePushWechatService = true
|
|
formState.statisticsTime = []
|
|
formState.statisticsTime = []
|
|
formState.count = 3
|
|
formState.count = 3
|
|
formState.timeThreshold = 300
|
|
formState.timeThreshold = 300
|
|
@@ -796,8 +849,8 @@ const submit = () => {
|
|
region: [1, 2, 3, 9].includes(formState.eventType as number)
|
|
region: [1, 2, 3, 9].includes(formState.eventType as number)
|
|
? JSON.stringify(formState.region)
|
|
? JSON.stringify(formState.region)
|
|
: '[]', // 检测区域
|
|
: '[]', // 检测区域
|
|
|
|
+ linkagePushWechatService: Number(formState.linkagePushWechatService) as 0 | 1, // 是否开启服务号消息推送 1:开启 0:关闭
|
|
enable: Number(formState.enable) as 0 | 1, // 是否启用 0否 1是
|
|
enable: Number(formState.enable) as 0 | 1, // 是否启用 0否 1是
|
|
-
|
|
|
|
// 生效方式
|
|
// 生效方式
|
|
alarmTimePlan: {
|
|
alarmTimePlan: {
|
|
startDate: formState.planTime[0], // 计划开始时间
|
|
startDate: formState.planTime[0], // 计划开始时间
|
|
@@ -834,23 +887,79 @@ const submit = () => {
|
|
// }
|
|
// }
|
|
|
|
|
|
submitLoading.value = true
|
|
submitLoading.value = true
|
|
- alarmApi
|
|
|
|
- .saveAlarmPlan(params)
|
|
|
|
- .then((res) => {
|
|
|
|
- console.log('添加成功', res)
|
|
|
|
- submitLoading.value = false
|
|
|
|
- message.success('添加成功')
|
|
|
|
- emit('success')
|
|
|
|
- cancel()
|
|
|
|
- })
|
|
|
|
- .catch(() => {
|
|
|
|
- submitLoading.value = false
|
|
|
|
- })
|
|
|
|
|
|
+ // alarmApi
|
|
|
|
+ // .saveAlarmPlan(params)
|
|
|
|
+ // .then((res) => {
|
|
|
|
+ // console.log('添加成功', res)
|
|
|
|
+ // submitLoading.value = false
|
|
|
|
+ // message.success('添加成功')
|
|
|
|
+ // emit('success')
|
|
|
|
+ // cancel()
|
|
|
|
+ // })
|
|
|
|
+ // .catch(() => {
|
|
|
|
+ // submitLoading.value = false
|
|
|
|
+ // })
|
|
|
|
+ if (props.type === 'plan') savePlan(params)
|
|
|
|
+ if (props.type === 'template') saveTemplate(params)
|
|
})
|
|
})
|
|
.catch((err) => {
|
|
.catch((err) => {
|
|
console.log('校验失败', err)
|
|
console.log('校验失败', err)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 保存计划
|
|
|
|
+const savePlan = async (params: AlarmPlanParams) => {
|
|
|
|
+ console.log('保存计划')
|
|
|
|
+ try {
|
|
|
|
+ await alarmApi
|
|
|
|
+ .saveAlarmPlan(params)
|
|
|
|
+ .then((res) => {
|
|
|
|
+ console.log('添加成功', res)
|
|
|
|
+ submitLoading.value = false
|
|
|
|
+ message.success('添加成功')
|
|
|
|
+ emit('success')
|
|
|
|
+ cancel()
|
|
|
|
+ })
|
|
|
|
+ .catch(() => {
|
|
|
|
+ submitLoading.value = false
|
|
|
|
+ })
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log('添加失败', error)
|
|
|
|
+ message.error('添加失败')
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 保存模板
|
|
|
|
+const saveTemplate = async (params: AlarmPlanParams) => {
|
|
|
|
+ console.log('saveTemplate', formState)
|
|
|
|
+ try {
|
|
|
|
+ await alarmApi
|
|
|
|
+ .saveAlarmPlanTemplate({
|
|
|
|
+ ...params,
|
|
|
|
+ id: props.alarmPlanId as number,
|
|
|
|
+ name: params.name,
|
|
|
|
+ eventVal: params.eventVal,
|
|
|
|
+ param: params.param,
|
|
|
|
+ region: params.region,
|
|
|
|
+ linkagePushWechatService: params.linkagePushWechatService,
|
|
|
|
+ enable: params.enable,
|
|
|
|
+ alarmTimePlanTpl: params.alarmTimePlan,
|
|
|
|
+ })
|
|
|
|
+ .then((res) => {
|
|
|
|
+ console.log('添加成功', res)
|
|
|
|
+ submitLoading.value = false
|
|
|
|
+ message.success('添加成功')
|
|
|
|
+ emit('success')
|
|
|
|
+ cancel()
|
|
|
|
+ })
|
|
|
|
+ .catch(() => {
|
|
|
|
+ submitLoading.value = false
|
|
|
|
+ })
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log('添加失败', error)
|
|
|
|
+ message.error('添加失败')
|
|
|
|
+ }
|
|
|
|
+}
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style scoped lang="less">
|
|
<style scoped lang="less">
|