|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
<script lang="ts" setup> |
|
|
|
|
import { useRoute } from 'vue-router' |
|
|
|
|
import { BasicModal, useModalInner } from '@/components/Modal' |
|
|
|
|
import type { FormSchema, FormSchemaInner, Rule } from '@/components/Form' |
|
|
|
|
import { BasicForm, useForm } from '@/components/Form' |
|
|
|
@ -9,8 +8,8 @@ import { sendCommandToDevice, sendMessageToDevice } from '@/api/device-manage/de
|
|
|
|
|
import CodeEditor from '@/components/CodeEditor/src/CodeEditor.vue' |
|
|
|
|
import { getAllModelAttributes } from '@/api/product/model' |
|
|
|
|
import { ModelAttributeDataTypesEnum, type SimpleAttribute } from '@/api/product/types' |
|
|
|
|
import { useMessage } from '@/hooks/web/useMessage' |
|
|
|
|
|
|
|
|
|
const props = defineProps<{ productId?: string, type?: CloudCommandType }>() |
|
|
|
|
const emit = defineEmits(['register', 'success']) |
|
|
|
|
|
|
|
|
|
const [registerForm, { updateSchema, resetSchema, validate, setFieldsValue, clearValidate }] = useForm({ |
|
|
|
@ -21,6 +20,9 @@ const [registerForm, { updateSchema, resetSchema, validate, setFieldsValue, clea
|
|
|
|
|
actionColOptions: { span: 23 }, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
let productId: string |
|
|
|
|
let deviceId: string |
|
|
|
|
let commandType: CloudCommandType |
|
|
|
|
const CommandAndAttributeSchemas: FormSchema[] = [ |
|
|
|
|
{ |
|
|
|
|
field: 'itemId', |
|
|
|
@ -28,7 +30,7 @@ const CommandAndAttributeSchemas: FormSchema[] = [
|
|
|
|
|
required: true, |
|
|
|
|
component: 'ApiSelect', |
|
|
|
|
componentProps: { |
|
|
|
|
api: () => getAllModelAttributes(props.productId!, props.type!), |
|
|
|
|
api: () => getAllModelAttributes(productId!, commandType), |
|
|
|
|
valueField: 'id', |
|
|
|
|
labelField: 'name', |
|
|
|
|
allowClear: false, |
|
|
|
@ -107,7 +109,7 @@ const MessageSchemas: FormSchema[] = [
|
|
|
|
|
required: true, |
|
|
|
|
component: 'ApiSelect', |
|
|
|
|
componentProps: { |
|
|
|
|
api: () => getAllTopics(props.productId!), |
|
|
|
|
api: () => getAllTopics(productId!), |
|
|
|
|
valueField: 'id', |
|
|
|
|
labelField: 'topic', |
|
|
|
|
}, |
|
|
|
@ -140,18 +142,21 @@ const MessageSchemas: FormSchema[] = [
|
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
] |
|
|
|
|
const [register, { closeModal, setModalProps }] = useModalInner((type: CloudCommandType) => { |
|
|
|
|
resetSchema(type === CloudCommandType.Message ? MessageSchemas : CommandAndAttributeSchemas) |
|
|
|
|
const [register, { closeModal, setModalProps }] = useModalInner((params: { type: CloudCommandType, productId: string, deviceId: string }) => { |
|
|
|
|
productId = params.productId |
|
|
|
|
deviceId = params.deviceId |
|
|
|
|
commandType = params.type |
|
|
|
|
resetSchema(commandType === CloudCommandType.Message ? MessageSchemas : CommandAndAttributeSchemas) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const route = useRoute() |
|
|
|
|
async function handleSubmit() { |
|
|
|
|
try { |
|
|
|
|
const values = await validate<any>() |
|
|
|
|
setModalProps({ confirmLoading: true }) |
|
|
|
|
values.deviceId = route.params.id |
|
|
|
|
const isSendMessage = props.type === CloudCommandType.Message |
|
|
|
|
values.deviceId = deviceId |
|
|
|
|
const isSendMessage = commandType === CloudCommandType.Message |
|
|
|
|
await (isSendMessage ? sendMessageToDevice(values) : sendCommandToDevice(values)) |
|
|
|
|
useMessage().createMessage.success('下发成功') |
|
|
|
|
emit('success') |
|
|
|
|
closeModal() |
|
|
|
|
} |
|
|
|
|