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