-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(north group): mqtt and gewu plugin support edit group
- Loading branch information
Showing
8 changed files
with
438 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<template> | ||
<emqx-select | ||
v-model="driver" | ||
clearable | ||
:size="size" | ||
class="plugin_select" | ||
:placeholder="selectorPlaceholder" | ||
:disabled="disabled" | ||
@change="changeDriver" | ||
> | ||
<emqx-option v-for="item in driverList" :key="item.name" :value="item.name" :label="item.name" /> | ||
</emqx-select> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { computed, defineEmits, defineProps, watch, ref, nextTick } from 'vue' | ||
import type { PropType, Ref } from 'vue' | ||
import { useI18n } from 'vue-i18n' | ||
import { DriverDirection } from '@/types/enums' | ||
import { querySouthDriverList, queryNorthDriverList } from '@/api/config' | ||
import type { RawDriverData } from '@/types/config' | ||
const props = defineProps({ | ||
modelValue: { type: String, default: '' }, | ||
type: { type: Number as PropType<DriverDirection | null>, default: null }, | ||
placeholder: { type: String, default: '' }, | ||
size: { type: String, default: '' }, | ||
disabled: { type: Boolean, default: false }, | ||
width: { type: String, default: '220px' }, | ||
}) | ||
const emits = defineEmits(['update:modelValue', 'change']) | ||
const { t } = useI18n() | ||
const driverList: Ref<Array<RawDriverData>> = ref([]) | ||
const driver = computed({ | ||
get: () => props.modelValue, | ||
set: (val) => { | ||
emits('update:modelValue', val) | ||
}, | ||
}) | ||
watch( | ||
() => props.type, | ||
(newV) => { | ||
nextTick(() => { | ||
getList(newV) | ||
}) | ||
}, | ||
{ immediate: true }, | ||
) | ||
const getAllDrivers = async (): Promise<Array<RawDriverData>> => { | ||
try { | ||
const listArray = await Promise.all([await queryNorthDriverList(), await querySouthDriverList()]) | ||
const list = listArray.reduce((ret, cur) => { | ||
return ret.concat(cur) | ||
}, []) | ||
return Promise.resolve(list) | ||
} catch (error) { | ||
console.error(error) | ||
return Promise.reject(error) | ||
} | ||
} | ||
const getList = async (type: DriverDirection | null | undefined) => { | ||
try { | ||
if (!type) { | ||
driverList.value = await getAllDrivers() | ||
} | ||
if (type === DriverDirection.South) { | ||
driverList.value = await querySouthDriverList() | ||
} | ||
if (type === DriverDirection.North) { | ||
driverList.value = await queryNorthDriverList() | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
const selectorPlaceholder = computed(() => { | ||
return props.placeholder || t('config.southDeviceRequired') | ||
}) | ||
const changeDriver = (val: string) => { | ||
emits('change', val) | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.plugin_select { | ||
width: v-bind(width); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<template> | ||
<emqx-select | ||
v-model="group" | ||
clearable | ||
:size="size" | ||
class="plugin_select" | ||
:placeholder="selectorPlaceholder" | ||
:disabled="disabled" | ||
@change="changeGroup" | ||
> | ||
<emqx-option v-for="{ name } in groupList" :key="name" :value="name" :label="name" /> | ||
</emqx-select> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { computed, defineEmits, defineProps, watch, ref, nextTick } from 'vue' | ||
import type { Ref } from 'vue' | ||
import { useI18n } from 'vue-i18n' | ||
import { queryGroupList } from '@/api/config' | ||
import type { GroupData } from '@/types/config' | ||
const props = defineProps({ | ||
modelValue: { type: String, default: '' }, | ||
driver: { type: String, required: true }, | ||
placeholder: { type: String, default: '' }, | ||
size: { type: String, default: '' }, | ||
disabled: { type: Boolean, default: false }, | ||
width: { type: String, default: '220px' }, | ||
}) | ||
const emits = defineEmits(['update:modelValue', 'change']) | ||
const { t } = useI18n() | ||
const groupList: Ref<Array<GroupData>> = ref([]) | ||
const group = computed({ | ||
get: () => props.modelValue, | ||
set: (val) => { | ||
emits('update:modelValue', val) | ||
}, | ||
}) | ||
watch( | ||
() => props.driver, | ||
(newV) => { | ||
nextTick(() => { | ||
getList(newV) | ||
}) | ||
}, | ||
{ immediate: true }, | ||
) | ||
const getList = async (driver: string) => { | ||
try { | ||
groupList.value = driver ? await queryGroupList(driver as string) : [] | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
const selectorPlaceholder = computed(() => { | ||
return props.placeholder || t('config.groupPlaceholder') | ||
}) | ||
const changeGroup = (val: string) => { | ||
emits('change', val) | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.plugin_select { | ||
width: v-bind(width); | ||
} | ||
</style> |
Oops, something went wrong.