* fix: 子设备绑定与解绑

* fix: bug#19092、19086

* fix: 子设备绑定与解绑
This commit is contained in:
qiaochuLei 2023-10-23 18:11:14 +08:00 committed by GitHub
parent 8e5d797a40
commit d1dff88218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 126 additions and 135 deletions

View File

@ -29,7 +29,7 @@
</div>
</div>
<div class="editor">
<j-monaco-editor v-if="loading" v-model:model-value="_value" theme="vs" ref="editor" language="javascript" :registrationTypescript="typescriptTip"
<j-monaco-editor v-if="loading" v-model:model-value="_value" theme="vs" ref="editor" language="javascript" :registrationTypescript="typescriptTip" :registrationTips="registrationTips"
:init="editorInit"/>
</div>
</div>
@ -41,11 +41,13 @@ import {
} from '@/api/device/instance';
import { useInstanceStore } from '@/store/instance';
import { useProductStore } from '@/store/product';
import { cloneDeep } from 'lodash-es';
import { inject } from 'vue'
interface Props {
mode?: 'advance' | 'simple';
id?: string;
value?: string;
tips?: Array<any>
}
const props = defineProps<Props>()
const target = inject('target')
@ -71,28 +73,9 @@ type SymbolType = {
const typescriptTip = reactive({
typescript: ''
})
const queryCode = () => {
let id = ''
if(target==='device'){
id = instanceStore.current.id
queryTypescript(id).then(res => {
if (res.status===200) {
typescriptTip.typescript = res.result
}
})
}else if(target ==='product'){
id = productStore.current.id
queryProductTs(id).then(res => {
if (res.status===200) {
typescriptTip.typescript = res.result
}
})
}
}
queryCode()
const registrationTips = ref<any>({
name: 'javascript'
})
const editorInit = (editor: any, monaco: any) => {
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
noSemanticValidation: true,
@ -200,11 +183,27 @@ const _value = computed({
})
const loading = ref(false)
onMounted(() => {
setTimeout(() => {
loading.value = true;
}, 100);
})
const queryCode = () => {
registrationTips.value.suggestions = cloneDeep(props.tips)
let id = ''
if(target==='device'){
id = instanceStore.current.id
queryTypescript(id).then(res => {
if (res.status===200) {
typescriptTip.typescript = res.result
}
})
}else if(target ==='product'){
id = productStore.current.id
queryProductTs(id).then(res => {
if (res.status===200) {
typescriptTip.typescript = res.result
}
})
}
}
const addOperatorValue = (val: string) => {
editor.value?.insert(val)
@ -220,6 +219,13 @@ defineExpose({
addOperatorValue
})
onMounted(() => {
setTimeout(() => {
loading.value = true;
}, 100);
})
queryCode()
</script>
<style lang="less" scoped>
.editor-box {

View File

@ -32,6 +32,7 @@
mode="advance"
key="advance"
v-model:value="_value"
:tips="tips"
/>
</div>
</div>
@ -59,7 +60,8 @@ import Editor from './Editor/index.vue';
import Debug from './Debug/index.vue';
import Operator from './Operator/index.vue';
import { FULL_CODE } from 'jetlinks-ui-components/es/DataTable'
import { cloneDeep } from 'lodash-es';
import { PropertyMetadata } from '@/views/device/Product/typings';
interface Emits {
(e: 'save', data: string | undefined): void;
(e: 'close'): void;
@ -77,7 +79,7 @@ const props = defineProps({
const _value = ref<string | undefined>(props.value);
const _disabled = ref<boolean>(true);
const fullRef = inject(FULL_CODE);
const tips = ref<any[]>([])
const handleCancel = () => {
emit('close');
};
@ -98,6 +100,29 @@ const addOperatorValue = (val: string) => {
editor.value.addOperatorValue(val);
};
const getAllCrud = () => {
const list = cloneDeep(props.propertiesOptions)?.filter((i:any)=>
props?.id !== i.id
)
console.log(list,'list')
//
list.forEach(item => {
console.log(item)
const config = item
tips.value.push({
label: `${config.name}$recent实时值`,
insertText:`$recent ("${config.id}")`,
kind: 18,
})
tips.value.push({
label: `${config.name}上一值`,
insertText: `$lastState("${config.id}"))`,
kind: 18
})
})
}
watch(() => _value.value, () => {
_disabled.value = true
})
@ -105,6 +130,7 @@ watch(() => _value.value, () => {
const onSuccess = (bool: boolean) => {
_disabled.value = bool;
}
getAllCrud()
</script>
<style lang="less" scoped>
.header {

View File

@ -28,7 +28,7 @@
></j-col>
<j-col :span="6"
><TopCard
title="今日设备息量"
title="今日设备息量"
:footer="messageFooter"
:value="dayMessage"
>

View File

@ -1,106 +1,60 @@
<template>
<SaveChild
v-if="childVisible"
@close-child-save="closeChildSave"
:childData="_current"
/>
<SaveChild v-if="childVisible" @close-child-save="closeChildSave" :childData="_current" />
<div v-else>
<pro-search
:columns="columns"
target="child-device"
@search="handleSearch"
class="device-child-device-search"
/>
<pro-search :columns="columns" target="child-device" @search="handleSearch" class="device-child-device-search" />
<!-- <j-divider /> -->
<JProTable
ref="childDeviceRef"
:columns="columns"
:request="query"
:bodyStyle="{
padding: 0
}"
:defaultParams="{
terms: [
{
column: 'parentId',
value: detail?.id || '',
termType: 'eq',
},
],
}"
:rowSelection="{
selectedRowKeys: _selectedRowKeys,
onChange: onSelectChange,
}"
:params="params"
:model="'TABLE'"
>
<JProTable ref="childDeviceRef" :columns="columns" :request="query" :bodyStyle="{
padding: 0
}" :defaultParams="{
terms: [
{
column: 'parentId',
value: detail?.id || '',
termType: 'eq',
},
],
}" :rowSelection="{
selectedRowKeys: _selectedRowKeys,
onChange: onSelectChange,
}" :params="params" :model="'TABLE'">
<template #rightExtraRender>
<j-space>
<PermissionButton
type="primary"
v-if="
detail?.accessProvider === 'official-edge-gateway'
"
hasPermission="device/Instance:update"
@click="
_current = {};
childVisible = true;
"
>新增并绑定</PermissionButton
>
<PermissionButton
type="primary"
@click="visible = true"
hasPermission="device/Instance:update"
>
绑定</PermissionButton
>
<PermissionButton
type="primary"
hasPermission="device/Instance:update"
:popConfirm="{
title: '确定解绑吗?',
onConfirm: handleUnBind,
}"
>批量解除</PermissionButton
>
<PermissionButton type="primary" v-if="detail?.accessProvider === 'official-edge-gateway'
" hasPermission="device/Instance:update" @click="
_current = {};
childVisible = true;
">新增并绑定</PermissionButton>
<PermissionButton type="primary" @click="visible = true" hasPermission="device/Instance:update">
绑定</PermissionButton>
<PermissionButton type="primary" hasPermission="device/Instance:update" :popConfirm="{
title: '确定解绑吗?',
onConfirm: handleUnBind,
}">批量解除</PermissionButton>
</j-space>
</template>
<template #registryTime="slotProps">
{{
slotProps.registryTime
? moment(slotProps.registryTime).format(
'YYYY-MM-DD HH:mm:ss',
)
: ''
? moment(slotProps.registryTime).format(
'YYYY-MM-DD HH:mm:ss',
)
: ''
}}
</template>
<template #state="slotProps">
<j-badge
:text="slotProps.state.text"
:status="statusMap.get(slotProps.state.value)"
/>
<j-badge :text="slotProps.state.text" :status="statusMap.get(slotProps.state.value)" />
</template>
<template #action="slotProps">
<j-space :size="16">
<template
v-for="i in getActions(slotProps, 'table')"
:key="i.key"
>
<PermissionButton
v-if="i.key !== 'update' || detail.accessProvider === 'official-edge-gateway'"
:disabled="i.disabled"
:popConfirm="i.popConfirm"
:tooltip="{
<template v-for="i in getActions(slotProps, 'table')" :key="i.key">
<PermissionButton v-if="i.key !== 'update' || detail.accessProvider === 'official-edge-gateway'"
:disabled="i.disabled" :popConfirm="i.popConfirm" :tooltip="{
...i.tooltip,
}"
@click="i.onClick"
type="link"
style="padding: 0px"
:hasPermission="'device/Instance:' + i.key"
>
<template #icon><AIcon :type="i.icon" /></template>
}" @click="i.onClick" type="link" style="padding: 0px"
:hasPermission="'device/Instance:' + i.key">
<template #icon>
<AIcon :type="i.icon" />
</template>
</PermissionButton>
</template>
</j-space>
@ -113,7 +67,7 @@
<script setup lang="ts">
import moment from 'moment';
import type { ActionsType } from '@/components/Table';
import {query, unbindDevice, unbindBatchDevice, queryByParent , deleteDeviceMapping} from '@/api/device/instance';
import { query, unbindDevice, unbindBatchDevice, queryByParent, deleteDeviceMapping } from '@/api/device/instance';
import { useInstanceStore } from '@/store/instance';
import { storeToRefs } from 'pinia';
import BindChildDevice from './BindChildDevice/index.vue';
@ -241,10 +195,12 @@ const getActions = (data: Partial<Record<string, any>>): ActionsType[] => {
data.id,
{},
);
const res = await deleteDeviceMapping(
detail.value.id,
{ids:[data.id]}
)
if (instanceStore.current.accessProvider === 'official-edge-gateway') {
const res = await deleteDeviceMapping(
detail.value.id,
{ ids: [data.id] }
)
}
if (resp.status === 200) {
childDeviceRef.value?.reload();
onlyMessage('操作成功!');
@ -285,11 +241,13 @@ const handleUnBind = async () => {
detail.value.id,
_selectedRowKeys.value,
);
if (resp.status === 200) {
if (instanceStore.current.accessProvider === 'official-edge-gateway') {
const res = await deleteDeviceMapping(
detail.value.id,
{ids:[_selectedRowKeys.value]}
{ ids: [_selectedRowKeys.value] }
)
}
if (resp.status === 200) {
onlyMessage('操作成功!');
cancelSelect();
childDeviceRef.value?.reload();
@ -316,7 +274,7 @@ const closeBindDevice = (val: boolean) => {
const closeChildSave = () => {
childVisible.value = false;
};
onMounted(()=>{
onMounted(() => {
console.log(detail.value.accessProvider)
})
</script>

View File

@ -313,8 +313,9 @@ const submitData = () => {
if (form.id === '') {
form.id = undefined;
}
const res = await addProduct(form);
loading.value = false
const res = await addProduct(form).finally(()=>{
loading.value = false
});
if (res.status === 200) {
onlyMessage('保存成功!');
visible.value = false;

View File

@ -5,12 +5,12 @@ const Webhook = () => {
<div class={'doc'}>
<h1>1. </h1>
<div>
webhook是一个接收HTTP请求的URLHTTP
POST请求Webhook的第三方系统可以基于该URL订阅本平台系统信息便
WebHook是一个接收HTTP请求的URLHTTP
POST请求WebHook的第三方系统可以基于该URL订阅本平台系统信息便
</div>
<h1>2.</h1>
<h2>1Webhook</h2>
<div>Webhook地址</div>
<h2>1WebHook</h2>
<div>WebHook地址</div>
<h2>2</h2>
<div>

View File

@ -278,12 +278,12 @@
<!-- webhook -->
<template v-if="formData.type === 'webhook'">
<j-form-item
label="Webhook"
label="WebHook"
v-bind="validateInfos['configuration.url']"
>
<j-input
v-model:value="formData.configuration.url"
placeholder="请输入Webhook"
placeholder="请输入WebHook"
/>
</j-form-item>
<j-form-item label="请求头">

View File

@ -28,7 +28,7 @@ export const NOTICE_METHOD: INoticeMethod[] = [
value: 'sms',
},
{
label: 'webhook',
label: 'WebHook',
value: 'webhook',
},
];
@ -75,7 +75,7 @@ export const MSG_TYPE = {
],
webhook: [
{
label: 'webhook',
label: 'WebHook',
value: 'http',
logo: getImage('/notice/webhook.png'),
},