fix: bug#10833

This commit is contained in:
xieyonghong 2023-03-27 15:24:53 +08:00
parent c0d72a3863
commit ffdee18c34
10 changed files with 53 additions and 150 deletions

View File

@ -3,6 +3,8 @@ import { systemVersion } from '@/api/comm'
import { useMenuStore } from './menu'
import { getDetails_api } from '@/api/system/basis';
import type { ConfigInfoType } from '@/views/system/Basis/typing';
import { LocalStore } from '@/utils/comm'
import { SystemConst } from '@/utils/consts'
type SystemStateType = {
isCommunity: boolean;
@ -22,6 +24,7 @@ export const useSystem = defineStore('system', {
const resp = await systemVersion()
if (resp.success && resp.result) {
const isCommunity = resp.result.edition === 'community'
LocalStore.set(SystemConst.VERSION_CODE, resp.result.edition)
this.isCommunity = isCommunity
// 获取菜单
const menu = useMenuStore()

15
src/utils/setting.ts Normal file
View File

@ -0,0 +1,15 @@
import { isNoCommunity } from '@/utils/utils';
// 过滤网关类型
export const accessConfigTypeFilter = (data: any[], filterKey: string = 'id'): any[] => {
if (!data) return []
const filterKeys = !isNoCommunity ?
[
'mqtt-server-gateway',
'http-server-gateway',
'mqtt-client-gateway',
'tcp-server-gateway',
'plugin_gateway'
] : ['plugin_gateway']
return data.filter(item => !filterKeys.includes(item[filterKey])).map( item => ({ ...item, label: item.name, value: item.id}))
}

View File

@ -309,6 +309,7 @@ import BadgeStatus from '@/components/BadgeStatus/index.vue';
import BatchDropdown from '@/components/BatchDropdown/index.vue';
import { BatchActionsType } from '@/components/BatchDropdown/types';
import {useRouterParams} from "@/utils/hooks/useParams";
import { accessConfigTypeFilter } from '@/utils/setting'
const instanceRef = ref<Record<string, any>>({});
const params = ref<Record<string, any>>({});
@ -417,12 +418,17 @@ const columns = [
options: () =>
new Promise((resolve) => {
getProviders().then((resp: any) => {
resolve(
resp.result.map((item: any) => ({
label: item.name,
value: `accessProvider is ${item.id}`,
})),
);
const data = resp.result || []
resolve(accessConfigTypeFilter(data).map(item => ({
...item,
value: `accessProvider is ${item.id}`
})))
// resolve(
// resp.result.map((item: any) => ({
// label: item.name,
// value: `accessProvider is ${item.id}`,
// })),
// );
});
}),
},

View File

@ -419,7 +419,7 @@ import { marked } from 'marked';
import type { TableColumnType } from 'ant-design-vue';
import { useMenuStore } from '@/store/menu';
import _ from 'lodash';
import encodeQuery from '@/utils/encodeQuery';
import { accessConfigTypeFilter } from '@/utils/setting'
const tableRef = ref();
const formRef = ref();
@ -434,7 +434,6 @@ marked.setOptions({
});
const simpleImage = ref(Empty.PRESENTED_IMAGE_SIMPLE);
const visible = ref<boolean>(false);
const listData = ref<string[]>([]);
const access = ref({});
const config = ref<any>({});
const metadata = ref<ConfigMetadata>({ properties: [] });
@ -501,35 +500,10 @@ const query = reactive({
search: {
type: 'select',
options: async () => {
return new Promise((res) => {
return new Promise((resolve) => {
getProviders().then((resp: any) => {
listData.value = [];
if (isNoCommunity) {
(resp?.result || []).map((item: any) => {
if (item.id != 'plugin_gateway') {
listData.value.push({
label: item.name,
value: item.id,
});
}
});
} else {
listData.value = (resp?.result || [])
.filter((i: any) =>
[
'mqtt-server-gateway',
'http-server-gateway',
'mqtt-client-gateway',
'tcp-server-gateway',
].includes(i.id),
)
.map((item: any) => ({
label: item.name,
value: item.id,
}));
// }
}
res(listData.value);
const data = resp.result || []
resolve(accessConfigTypeFilter(data))
});
});
},
@ -961,7 +935,8 @@ const getData = async (accessId?: string) => {
);
getProviders().then((resp) => {
if (resp.status === 200) {
dataSource.value = resp.result;
const data = resp.result || []
dataSource.value = accessConfigTypeFilter(data as any[]);
}
});
}

View File

@ -182,6 +182,7 @@ import Save from './Save/index.vue';
import { useMenuStore } from 'store/menu';
import { useRoute } from 'vue-router';
import {useRouterParams} from "@/utils/hooks/useParams";
import { accessConfigTypeFilter } from '@/utils/setting'
/**
* 表格数据
*/
@ -442,37 +443,11 @@ const query = reactive({
dataIndex: 'accessProvider',
search: {
type: 'select',
options: async () => {
return new Promise((res) => {
options: () => {
return new Promise((resolve) => {
getProviders().then((resp: any) => {
listData.value = [];
// const list = () => {
if (isNoCommunity) {
(resp?.result || []).map((item: any) => {
if (item.id != 'plugin_gateway') {
listData.value.push({
label: item.name,
value: item.id,
});
}
});
} else {
listData.value = (resp?.result || [])
.filter((i: any) =>
[
'mqtt-server-gateway',
'http-server-gateway',
'mqtt-client-gateway',
'tcp-server-gateway',
].includes(i.id),
)
.map((item: any) => ({
label: item.name,
value: item.id,
}));
// }
}
res(listData.value);
const data = resp.result || []
resolve(accessConfigTypeFilter(data))
});
});
},

View File

@ -51,6 +51,7 @@ import Channel from '../components/Channel/index.vue';
import Edge from '../components/Edge/index.vue';
import Cloud from '../components/Cloud/index.vue';
import { getProviders, detail } from '@/api/link/accessConfig';
import { accessConfigTypeFilter } from '@/utils/setting'
const route = useRoute();
const id = route.params.id as string;
@ -140,7 +141,8 @@ const getTypeList = (result: Record<string, any>) => {
const queryProviders = async () => {
const resp: any = await getProviders();
if (resp.status === 200) {
dataSource.value = getTypeList(resp.result);
const data = resp.result || []
dataSource.value = getTypeList(accessConfigTypeFilter(data as any[]));
// dataSource.value = getTypeList(resp.result)[0].list.filter(
// (item) => item.name !== '',
// );
@ -151,7 +153,8 @@ const getProvidersData = async () => {
if (id !== ':id') {
getProviders().then((response: any) => {
if (response.status === 200) {
const list = getTypeList(response.result);
const data = response.result || []
const list = getTypeList(accessConfigTypeFilter(data as any[]));
dataSource.value = list.filter(
(item: any) =>
item.channel === 'network' ||

View File

@ -188,6 +188,7 @@ import {
} from '@/api/link/accessConfig';
import { onlyMessage } from '@/utils/comm';
import { useMenuStore } from 'store/menu';
import { accessConfigTypeFilter } from '@/utils/setting'
const menuStory = useMenuStore();
const tableRef = ref<Record<string, any>>({});
@ -318,12 +319,7 @@ const getActions = (data: Partial<Record<string, any>>): ActionsType[] => {
const getProvidersList = async () => {
const res: any = await getProviders();
providersList.value = res.result;
providersOptions.value = (res?.result || [])
?.map((item: any) => ({
label: item.name,
value: item.id,
}))
.filter((item: any) => item.value !== 'plugin_gateway'); // todo
providersOptions.value = accessConfigTypeFilter(res.result || [])
};
getProvidersList();

View File

@ -62,6 +62,7 @@ import { queryTree } from '@/api/device/category'
import { getTreeData_api } from '@/api/system/department'
import { isNoCommunity } from '@/utils/utils'
import { getImage } from '@/utils/comm'
import { accessConfigTypeFilter } from '@/utils/setting'
type Emit = {
(e: 'update:rowKey', data: string): void
@ -115,23 +116,7 @@ const columns = [
search: {
type: 'select',
options: () => getProviders().then((resp: any) => {
if (isNoCommunity) {
return (resp?.result || []).map((item: any) => ({
label: item.name,
value: item.id
}))
} else {
return (resp?.result || []).filter((item: any) => [
'mqtt-server-gateway',
'http-server-gateway',
'mqtt-client-gateway',
'tcp-server-gateway',
].includes(item.id))
.map((item: any) => ({
label: item.name,
value: item.id,
}))
}
return accessConfigTypeFilter(resp.result || [])
})
}
},

View File

@ -74,6 +74,7 @@ import { queryTree } from '@/api/device/category';
import { getTreeData_api } from '@/api/system/department';
import { isNoCommunity } from '@/utils/utils';
import { getImage } from '@/utils/comm';
import { accessConfigTypeFilter } from '@/utils/setting'
type Emit = {
(e: 'update:rowKey', data: string): void;
@ -127,26 +128,8 @@ const columns = [
type: 'select',
options: () =>
getProviders().then((resp: any) => {
if (isNoCommunity) {
return (resp?.result || []).map((item: any) => ({
label: item.name,
value: item.id,
}));
} else {
return (resp?.result || [])
.filter((item: any) =>
[
'mqtt-server-gateway',
'http-server-gateway',
'mqtt-client-gateway',
'tcp-server-gateway',
].includes(item.id),
)
.map((item: any) => ({
label: item.name,
value: item.id,
}));
}
const data = resp.result || []
return accessConfigTypeFilter(data)
}),
},
},

View File

@ -572,44 +572,6 @@ const rules = [{
}
}]
const formTouchOff = () => {
console.log('formTouchOff')
formItemContext.onFieldChange()
}
/**
* 校验当前执行动作的设备或者产品是否删除
*/
const checkDeviceDelete = async () => {
const item = _data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device
const proResp = await queryProductList({ terms: [{ terms: [{ column: 'id', termType: 'eq', value: item!.productId }]}]})
if (proResp.success && (proResp.result as any)?.total === 0) { //
_data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device!.productId = undefined
formTouchOff()
return
}
const deviceList = item!.selectorValues?.map(item => item.value) || []
const deviceResp = await deviceQuery({ terms: [{ terms: [{ column: 'id', termType: 'in', value: deviceList.toString() }]}]})
if (deviceResp.success && (deviceResp.result as any)?.total < (item!.selectorValues?.length || 0)) { //
_data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device!.selectorValues = undefined
formTouchOff()
return
}
}
/**
* 校验当前执行动作的通知配置消息模板是否删除
*/
const checkNoticeDelete = () => {
}
nextTick(() => {
if (_data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.executor === 'device') {
checkDeviceDelete()
}
})
</script>
<style lang="less" scoped>