|
|
@@ -0,0 +1,111 @@
|
|
|
+<template>
|
|
|
+ <el-form
|
|
|
+ class="detail-camera"
|
|
|
+ label-placement="left"
|
|
|
+ label-width="auto"
|
|
|
+ ref="formRef"
|
|
|
+ :model="camerasForm"
|
|
|
+ :rules="rules"
|
|
|
+ :style="{
|
|
|
+ overflow: 'auto'
|
|
|
+ }"
|
|
|
+ >
|
|
|
+ <el-form-item :label="$t('sbmc')" prop="Name" label-style="color:#fff">
|
|
|
+ <el-input v-model="camerasForm.name" :placeholder="$t('qsr')" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item :label="$t('sbdz')" prop="Address" label-style="color:#fff">
|
|
|
+ <el-input v-model="camerasForm.ip_address" :placeholder="$t('qsr')" />
|
|
|
+ </el-form-item>
|
|
|
+ <div class="btns" flex flex-justify-end>
|
|
|
+ <el-button mr-15px @click="emits('update:modelValue', false)">{{ $t('qx') }}</el-button>
|
|
|
+ <el-button type="primary" @click="ok" :loading="loading">{{ $t('qd') }}</el-button>
|
|
|
+ </div>
|
|
|
+ </el-form>
|
|
|
+</template>
|
|
|
+<script setup>
|
|
|
+ import { ElMessage } from 'element-plus'
|
|
|
+ const { t: $t } = useI18n({ useScope: 'global' })
|
|
|
+ const msg = (type, text) => {
|
|
|
+ ElMessage[type](text)
|
|
|
+ }
|
|
|
+ const { API_TP_CAMERAS_POST, API_TP_CAMERAS_PUT } = useRequest()
|
|
|
+ const props = defineProps({
|
|
|
+ sign: {
|
|
|
+ type: String
|
|
|
+ },
|
|
|
+ modelValue: {
|
|
|
+ type: Boolean
|
|
|
+ },
|
|
|
+ camerasInfo: {
|
|
|
+ type: Object
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const emits = defineEmits(['update:modelValue', 'update'])
|
|
|
+
|
|
|
+ const formRef = ref(null)
|
|
|
+ const loading = ref(false)
|
|
|
+ const camerasForm = reactive({
|
|
|
+ name: '',
|
|
|
+ ip_address: ''
|
|
|
+ })
|
|
|
+ const rules = {
|
|
|
+ Name: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: $t('qsr'),
|
|
|
+ trigger: 'blur'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ Address: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: $t('qsr'),
|
|
|
+ trigger: 'blur'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ const ok = async () => {
|
|
|
+ let fn = (apiN, params, msgT) => {
|
|
|
+ loading.value = true
|
|
|
+ apiN(params)
|
|
|
+ .then(() => {
|
|
|
+ loading.value = false
|
|
|
+ emits('update:modelValue', false)
|
|
|
+ emits('update')
|
|
|
+ msg('success', msgT)
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ loading.value = false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ await formRef.value.validate((valid, fields) => {
|
|
|
+ if (valid) {
|
|
|
+ switch (props.sign) {
|
|
|
+ case 'add':
|
|
|
+ fn(API_TP_CAMERAS_POST, camerasForm, $t('tjcg'))
|
|
|
+ break
|
|
|
+ case 'edit':
|
|
|
+ fn(API_TP_CAMERAS_PUT, camerasForm, $t('xgcg'))
|
|
|
+ break
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.error(fields)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ const init = () => {
|
|
|
+ if (props.sign === 'add') {
|
|
|
+ Object.assign(camerasForm, {
|
|
|
+ name: '',
|
|
|
+ ip_address: ''
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ Object.assign(camerasForm, props.camerasInfo)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ onMounted(() => {
|
|
|
+ init()
|
|
|
+ })
|
|
|
+</script>
|
|
|
+<style scoped lang="scss"></style>
|