提交 | 用户 | 时间
|
30566d
|
1 |
<template> |
H |
2 |
<Dialog v-model="dialogVisible" :title="dialogTitle" width="50%"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
v-loading="formLoading" |
|
6 |
:model="formData" |
|
7 |
:rules="formRules" |
|
8 |
label-width="80px" |
|
9 |
> |
|
10 |
<el-row> |
|
11 |
<el-col :span="12"> |
|
12 |
<el-form-item label="编码" prop="code"> |
|
13 |
<el-input v-model="formData.code" placeholder="请输入编码" /> |
|
14 |
</el-form-item> |
|
15 |
</el-col> |
c3e84e
|
16 |
<el-col :span="12"> |
H |
17 |
<el-form-item label="抓图方式"> |
|
18 |
<el-select v-model="formData.captureType" placeholder="请选择"> |
|
19 |
<el-option |
|
20 |
v-for="dict in getStrDictOptions(DICT_TYPE.CAPTURE_TYPE)" |
|
21 |
:key="dict.value" |
|
22 |
:label="dict.label" |
|
23 |
:value="dict.value" |
|
24 |
/> |
|
25 |
</el-select> |
|
26 |
</el-form-item> |
|
27 |
</el-col> |
30566d
|
28 |
</el-row> |
H |
29 |
<el-row> |
|
30 |
<el-col :span="12"> |
|
31 |
<el-form-item label="通道" prop="channel"> |
|
32 |
<el-input v-model="formData.channel" placeholder="请输入通道" /> |
|
33 |
</el-form-item> |
|
34 |
</el-col> |
|
35 |
<el-col :span="12"> |
|
36 |
<el-form-item label="监控区域" prop="location"> |
|
37 |
<el-input v-model="formData.location" placeholder="请输入监控区域" /> |
|
38 |
</el-form-item> |
|
39 |
</el-col> |
|
40 |
</el-row> |
|
41 |
|
|
42 |
<el-row> |
|
43 |
<el-col :span="24"> |
|
44 |
<el-form-item label="备注" prop="remark"> |
|
45 |
<el-input v-model="formData.remark" clearable type="textarea" /> |
|
46 |
</el-form-item> |
|
47 |
</el-col> |
|
48 |
</el-row> |
|
49 |
</el-form> |
|
50 |
<template #footer> |
|
51 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
52 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
53 |
</template> |
|
54 |
</Dialog> |
|
55 |
</template> |
|
56 |
<script lang="ts" setup> |
f0028c
|
57 |
import * as CameraApi from '@/api/data/video/camera' |
H |
58 |
import {DICT_TYPE, getStrDictOptions} from "@/utils/dict"; |
30566d
|
59 |
|
f0028c
|
60 |
defineOptions({ name: 'NvrCameraForm' }) |
30566d
|
61 |
|
H |
62 |
const { t } = useI18n() // 国际化 |
|
63 |
const message = useMessage() // 消息弹窗 |
|
64 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
65 |
const dialogTitle = ref('') // 弹窗的标题 |
|
66 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
67 |
const nvrId = ref('') // 录像机id |
|
68 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
69 |
const formData = ref({ |
|
70 |
id: undefined, |
|
71 |
nvrId: '', |
f0028c
|
72 |
type: 2, |
30566d
|
73 |
code: undefined, |
c3e84e
|
74 |
captureType: '', |
30566d
|
75 |
channel: undefined, |
H |
76 |
location: undefined, |
|
77 |
remark: undefined |
|
78 |
}) |
|
79 |
const formRules = reactive({ |
|
80 |
code: [{ required: true, message: '编码不能为空', trigger: 'blur' }], |
c3e84e
|
81 |
captureType: [{ required: true, message: '抓图方式不能为空', trigger: 'blur' }], |
30566d
|
82 |
channel: [{ required: true, message: '通道不能为空', trigger: 'blur' }], |
H |
83 |
location: [{ required: true, message: '监控区域不能为空', trigger: 'blur' }] |
|
84 |
}) |
|
85 |
const formRef = ref() // 表单 Ref |
|
86 |
|
|
87 |
/** 打开弹窗 */ |
|
88 |
const open = async (type: string, id?: number, nvr_id?: string) => { |
|
89 |
dialogVisible.value = true |
|
90 |
if (nvr_id != null) { |
|
91 |
nvrId.value = nvr_id |
|
92 |
} |
|
93 |
dialogTitle.value = t('action.' + type) |
|
94 |
formType.value = type |
|
95 |
resetForm() |
|
96 |
// 修改时,设置数据 |
|
97 |
if (id) { |
|
98 |
formLoading.value = true |
|
99 |
try { |
|
100 |
formData.value = await CameraApi.getCamera(id) |
|
101 |
} finally { |
|
102 |
formLoading.value = false |
|
103 |
} |
|
104 |
} |
|
105 |
} |
|
106 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
107 |
|
|
108 |
/** 提交表单 */ |
|
109 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
110 |
const submitForm = async () => { |
|
111 |
// 校验表单 |
|
112 |
if (!formRef) return |
|
113 |
const valid = await formRef.value.validate() |
|
114 |
if (!valid) return |
|
115 |
// 提交请求 |
|
116 |
formLoading.value = true |
|
117 |
try { |
|
118 |
const data = formData.value as unknown as CameraApi.CameraVO |
|
119 |
if (formType.value === 'create') { |
|
120 |
data.nvrId = nvrId.value |
f0028c
|
121 |
data.type = 2 |
30566d
|
122 |
await CameraApi.createCamera(data) |
H |
123 |
message.success(t('common.createSuccess')) |
|
124 |
} else { |
|
125 |
await CameraApi.updateCamera(data) |
|
126 |
message.success(t('common.updateSuccess')) |
|
127 |
} |
|
128 |
dialogVisible.value = false |
|
129 |
// 发送操作成功的事件 |
|
130 |
emit('success') |
|
131 |
} finally { |
|
132 |
formLoading.value = false |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
/** 重置表单 */ |
|
137 |
const resetForm = () => { |
|
138 |
formData.value = { |
|
139 |
id: undefined, |
c3e84e
|
140 |
nvrId: '', |
30566d
|
141 |
code: undefined, |
c3e84e
|
142 |
captureType: '', |
H |
143 |
channel: undefined, |
|
144 |
location: undefined, |
30566d
|
145 |
remark: undefined |
H |
146 |
} |
|
147 |
formRef.value?.resetFields() |
|
148 |
} |
|
149 |
</script> |