Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ReadProperties.vue #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 80 additions & 2 deletions src/views/rule-engine/Scene/Save/Device/ReadProperties.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,34 @@
/>
</j-form-item>
</j-col>
<j-col :span='14'>
<j-col :span='4'>
<a-popover v-model:open="visible" title="批量绑定属性" trigger="click">
<template #content>
<a-row :gutter="[10, 10]">
<a-col :span="24">
<a-switch v-model:checked="isAllSelect" checked-children="全选" un-checked-children="取消全选" />
</a-col>
<a-col :span="24">
<a-form :model="bind_value" name="basic" layout="inline" ref="formRef" :label-col="{ span: 8 }"
:wrapper-col="{ span: 16 }" autocomplete="off" @finish="handleBinding" :rules="rules">
<a-form-item name="start">
<a-input-number id="inputNumber" v-model:value="bind_value.start" :min="1"
:max="props.properties.length - 1" />
</a-form-item>
<div class="symbol">-</div>
<a-form-item name="end">
<a-input-number id="inputNumber" v-model:value="bind_value.end" :min="bind_value.start"
:max="props.properties.length" />
</a-form-item>
<a-button type="primary" html-type="submit">确定</a-button>
</a-form>
</a-col>
</a-row>
</template>
<a-button type="primary">批量绑定属性</a-button>
</a-popover>
</j-col>
<j-col :span='5'>
<j-form-item>定时读取所选属性值</j-form-item>
</j-col>
</j-row>
Expand All @@ -27,6 +54,8 @@
<script setup lang='ts' name='ReadProperties'>
import { filterSelectNode } from '@/utils/comm'
import type { PropType } from 'vue'
import { Rule } from 'ant-design-vue/es/form'
import type { FormInstance } from 'ant-design-vue';

type Emit = {
(e: 'update:value', data: Array<string>): void
Expand Down Expand Up @@ -73,7 +102,56 @@ const change = (values: string[], optionItems: any[]) => {
emit('update:value', values)
emit('update:action', `读取 ${extraStr}`)
}

//范围绑定属性
const visible = ref(false)
const bind_value: {
start: number | undefined
end: number | undefined
} = reactive({
start: undefined,
end: undefined,
})
const formRef = ref<FormInstance>()
const validate = {
start: async (_rule: Rule, value: number) => {
if (!value) {
return Promise.reject('请输入');
}
else {
return Promise.resolve();
}
},
end: async (_rule: Rule, value: number) => {
if (!value) {
return Promise.reject('请输入');
}
else {
return Promise.resolve();
}
}
}
const rules: Record<string, Rule[]> = {
start: [{ required: true, validator: validate.start, trigger: 'change' }],
end: [{ required: true, validator: validate.end, trigger: 'change' }],
};
const handleBinding = (values: any) => {
const valueObjArr = props.properties.slice(bind_value.start! - 1, bind_value.end)
const value = valueObjArr.map((item: any) => item.id)
change(value, valueObjArr)
readProperties.value = value
visible.value = false
}
//全选属性逻辑
const isAllSelect = ref<boolean>(false)
watch(isAllSelect, (newval) => {
if (newval) {
bind_value.start = 1
bind_value.end = props.properties.length
} else {
bind_value.start = undefined
bind_value.end = undefined
}
})
</script>

<style scoped>
Expand Down