tplink项目、分组同步机构和区域

This commit is contained in:
曹磊 2025-03-27 14:13:59 +08:00
parent 3e949eff0b
commit 668e346e5e
7 changed files with 129 additions and 27 deletions

View File

@ -16,7 +16,7 @@ export const columns: BasicColumn[] = [
{ {
title: '机构名称', title: '机构名称',
align: 'center', align: 'center',
dataIndex: 'institutionalId_dictText', dataIndex: 'institutionId_dictText',
}, },
{ {
title: '创建时间', title: '创建时间',
@ -56,10 +56,10 @@ export const columns: BasicColumn[] = [
export const searchFormSchema: FormSchema[] = [ export const searchFormSchema: FormSchema[] = [
{ {
label: '机构', label: '机构',
field: 'institutionalId', field: 'institutionId',
component: 'JDictSelectTag', component: 'JDictSelectTag',
componentProps: { componentProps: {
dictCode: 'sys_depart,depart_name,id,org_category = 1 order by depart_name asc', dictCode: 'nu_admin_institution_area,inst_name,id,org_category = 1 order by inst_name asc',
placeholder: '请选择机构', placeholder: '请选择机构',
}, },
}, },
@ -104,10 +104,10 @@ export const formSchema: FormSchema[] = [
}, },
{ {
label: '机构名称', label: '机构名称',
field: 'institutionalId', field: 'institutionId',
component: 'JDictSelectTag', component: 'JDictSelectTag',
componentProps: { componentProps: {
dictCode: 'sys_depart,depart_name,id,org_category = 1 order by depart_name asc', dictCode: 'nu_admin_institution_area,inst_name,id,org_category = 1 order by inst_name asc',
placeholder: '请选择机构', placeholder: '请选择机构',
}, },
}, },

View File

@ -11,6 +11,7 @@ enum Api {
add = '/iot/regionInfo/add', add = '/iot/regionInfo/add',
edit = '/iot/regionInfo/edit', edit = '/iot/regionInfo/edit',
delete = '/iot/regionInfo/delete', delete = '/iot/regionInfo/delete',
queryChildrenByParentId = '/admin/institutionArea/queryChildrenByParentId',
} }
@ -21,7 +22,7 @@ enum Api {
export const queryProjectTreeSync = (params?) => defHttp.get({ url: Api.queryProjectTreeSync, params }); export const queryProjectTreeSync = (params?) => defHttp.get({ url: Api.queryProjectTreeSync, params });
/** /**
* *
* @param params * @param params
*/ */
export const queryRegionTreeSync = (params?) => defHttp.get({ url: Api.queryRegionTreeSync, params }); export const queryRegionTreeSync = (params?) => defHttp.get({ url: Api.queryRegionTreeSync, params });
@ -33,17 +34,23 @@ export const queryRegionTreeSync = (params?) => defHttp.get({ url: Api.queryRegi
export const syncProject = (params?) => defHttp.get({ url: Api.syncProject, params }); export const syncProject = (params?) => defHttp.get({ url: Api.syncProject, params });
/** /**
* *
* @param params * @param params
*/ */
export const syncRegionChildren = (params?) => defHttp.get({ url: Api.syncRegionChildren, params }); export const syncRegionChildren = (params?) => defHttp.get({ url: Api.syncRegionChildren, params });
/** /**
* *
* @param params * @param params
*/ */
export const syncRegion = (params?) => defHttp.get({ url: Api.syncRegion, params }); export const syncRegion = (params?) => defHttp.get({ url: Api.syncRegion, params });
/**
* parentId获取区域列表
* @param params
*/
export const queryArea = (params?) => defHttp.get({ url: Api.queryChildrenByParentId, params });
/** /**
* *
* @param params * @param params
@ -57,7 +64,7 @@ export const list = (params) => defHttp.get({ url: Api.list, params });
export const sync = (params) => defHttp.get({ url: Api.sync, params }); export const sync = (params) => defHttp.get({ url: Api.sync, params });
/** /**
* *
* @param params * @param params
*/ */
export const saveOrUpdateRegion = (params, isUpdate) => { export const saveOrUpdateRegion = (params, isUpdate) => {
@ -66,7 +73,7 @@ export const saveOrUpdateRegion = (params, isUpdate) => {
}; };
/** /**
* *
*/ */
export const deleteRegion = (params,handleSuccess) => { export const deleteRegion = (params,handleSuccess) => {
return defHttp.post({ url: Api.delete, params }, { joinParamsToUrl: true }).then(() => { return defHttp.post({ url: Api.delete, params }, { joinParamsToUrl: true }).then(() => {

View File

@ -4,17 +4,17 @@ import {FormSchema} from '/@/components/Table';
//列表数据 //列表数据
export const columns: BasicColumn[] = [ export const columns: BasicColumn[] = [
{ {
title: '区域序号', title: '分组序号',
align: "center", align: "center",
dataIndex: 'regionId' dataIndex: 'regionId'
}, },
{ {
title: '区域名称', title: '分组名称',
align: "center", align: "center",
dataIndex: 'regionName' dataIndex: 'regionName'
}, },
{ {
title: '区域层级', title: '分组层级',
align: "center", align: "center",
dataIndex: 'regionLevel' dataIndex: 'regionLevel'
}, },
@ -24,7 +24,7 @@ export const columns: BasicColumn[] = [
dataIndex: 'parentName' dataIndex: 'parentName'
}, },
{ {
title: '机构名称', title: '项目名称',
align: "center", align: "center",
dataIndex: 'projectName' dataIndex: 'projectName'
}, },
@ -34,7 +34,7 @@ export const columns: BasicColumn[] = [
dataIndex: 'updateTime' dataIndex: 'updateTime'
}, },
{ {
title: '区域次序', title: '分组次序',
align: "center", align: "center",
dataIndex: 'sort' dataIndex: 'sort'
}, },
@ -42,7 +42,7 @@ export const columns: BasicColumn[] = [
export const searchFormSchema: FormSchema[] = [ export const searchFormSchema: FormSchema[] = [
{ {
label: '机构', label: '项目',
field: 'projectId', field: 'projectId',
component: 'JDictSelectTag', component: 'JDictSelectTag',
componentProps: { componentProps: {
@ -67,6 +67,12 @@ export const formSchema: FormSchema[] = [
component: 'Input', component: 'Input',
show: false, show: false,
}, },
{
label: '',
field: 'institutionId',
component: 'Input',
show: false,
},
{ {
label: '', label: '',
field: 'parentId', field: 'parentId',
@ -74,18 +80,24 @@ export const formSchema: FormSchema[] = [
show: false, show: false,
}, },
{ {
label: '区域序号', label: '分组序号',
field: 'regionId', field: 'regionId',
component: 'Input', component: 'Input',
dynamicDisabled: true dynamicDisabled: true
}, },
{ {
label: '区域名称', label: '分组名称',
field: 'regionName', field: 'regionName',
component: 'Input', component: 'Input',
}, },
{ {
label: '区域层级', label: '区域名称',
field: 'areaId',
component: 'Input',
slot: 'areaSelect'
},
{
label: '分组层级',
field: 'regionLevel', field: 'regionLevel',
component: 'Input', component: 'Input',
dynamicDisabled: true dynamicDisabled: true
@ -97,7 +109,7 @@ export const formSchema: FormSchema[] = [
dynamicDisabled: true dynamicDisabled: true
}, },
{ {
label: '机构名称', label: '项目名称',
field: 'projectName', field: 'projectName',
component: 'Input', component: 'Input',
dynamicDisabled: ({model})=>{ dynamicDisabled: ({model})=>{
@ -115,7 +127,7 @@ export const formSchema: FormSchema[] = [
dynamicDisabled: true dynamicDisabled: true
}, },
{ {
label: '区域次序', label: '分组次序',
field: 'sort', field: 'sort',
component: 'Input', component: 'Input',
dynamicDisabled: true dynamicDisabled: true

View File

@ -1,6 +1,17 @@
<template> <template>
<a-spin :spinning="loading"> <a-spin :spinning="loading">
<BasicForm @register="registerForm" /> <BasicForm @register="registerForm">
<template #areaSelect ="{model,field}">
<a-select v-model:value="model[field]" @change="(value,option) => handleChange(value,option,model)">
<a-select-option :value="null">请选择</a-select-option>
<template v-for="item in areaOptions" :key="`${item.id}`">
<a-select-option :value="item.id" :label="item.instName">
{{item.instName}}
</a-select-option>
</template>
</a-select>
</template>
</BasicForm>
<div class="j-box-bottom-button offset-20" style="margin-top: 30px"> <div class="j-box-bottom-button offset-20" style="margin-top: 30px">
<div class="j-box-bottom-button-float"> <div class="j-box-bottom-button-float">
<a-button preIcon="ant-design:sync-outlined" @click="onReset">重置</a-button> <a-button preIcon="ant-design:sync-outlined" @click="onReset">重置</a-button>
@ -13,15 +24,22 @@
<script lang="ts" setup> <script lang="ts" setup>
import { watch, computed, inject, ref, unref, onMounted } from 'vue'; import { watch, computed, inject, ref, unref, onMounted } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index'; import { BasicForm, useForm } from '/@/components/Form/index';
import { saveOrUpdateRegion } from '@/views/iot/tplink/region/RegionInfo.api'; import {
queryArea,
queryRegionTreeSync,
saveOrUpdateRegion
} from '@/views/iot/tplink/region/RegionInfo.api';
import { formSchema } from '@/views/iot/tplink/region/RegionInfo.data'; import { formSchema } from '@/views/iot/tplink/region/RegionInfo.data';
import { useDesign } from '/@/hooks/web/useDesign'; import { useDesign } from '/@/hooks/web/useDesign';
import { useMessage } from '/@/hooks/web/useMessage';
import {propTypes} from "@/utils/propTypes";
const { createMessage, createSuccessModal } = useMessage();
const emit = defineEmits(['success']); const emit = defineEmits(['success']);
const props = defineProps({ const props = defineProps({
data: { type: Object, default: () => ({}) }, data: { type: Object, default: () => ({}) },
rootTreeData: { type: Array, default: () => [] }, rootTreeData: { type: Array, default: () => [] },
}); });
const areaOptions = ref<any[]>([]);
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
// //
const isUpdate = ref<boolean>(true); const isUpdate = ref<boolean>(true);
@ -46,6 +64,7 @@
model.value = record; model.value = record;
await resetFields(); await resetFields();
await setFieldsValue({ ...record }); await setFieldsValue({ ...record });
await fetchArea(record.institutionId);
}, },
{ deep: true, immediate: true } { deep: true, immediate: true }
); );
@ -72,6 +91,26 @@
loading.value = false; loading.value = false;
} }
} }
const fetchArea = async (institutionId) => {
if (!institutionId){
institutionId = '-1';
}
areaOptions.value = [];
const data = await queryArea({ pid : institutionId });
Object.assign(areaOptions.value, data);
}
async function handleChange(value,option:Option,formData){
if(value == null){
formData["regionName"] = model.value["regionName"];
}else{
formData["regionName"] = option.label;
}
console.log(formData);
}
</script> </script>
<style lang="less"> <style lang="less">

View File

@ -8,7 +8,17 @@
:showFooter="showFooter" :showFooter="showFooter"
destroyOnClose destroyOnClose
> >
<BasicForm @register="registerForm" /> <BasicForm @register="registerForm">
<template #areaSelect ="{model,field}">
<a-select v-model:value="model[field]" @change="(value,option) => handleChange(value,option,model)">
<template v-for="item in areaOptions" :key="`${item.id}`">
<a-select-option :value="item.id" :label="item.instName">
{{item.instName}}
</a-select-option>
</template>
</a-select>
</template>
</BasicForm>
</BasicDrawer> </BasicDrawer>
</template> </template>
@ -19,14 +29,13 @@ import { formSchema } from "@/views/iot/tplink/region/RegionInfo.data";
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
import { useDrawerAdaptiveWidth } from '/@/hooks/jeecg/useAdaptiveWidth'; import { useDrawerAdaptiveWidth } from '/@/hooks/jeecg/useAdaptiveWidth';
import { getTenantId } from "/@/utils/auth"; import { getTenantId } from "/@/utils/auth";
import { saveOrUpdateRegion } from "@/views/iot/tplink/region/RegionInfo.api"; import {queryArea, saveOrUpdateRegion} from "@/views/iot/tplink/region/RegionInfo.api";
// Emits // Emits
const emit = defineEmits(['success', 'register']); const emit = defineEmits(['success', 'register']);
const attrs = useAttrs(); const attrs = useAttrs();
const isUpdate = ref(true); const isUpdate = ref(true);
const rowId = ref(''); const rowId = ref('');
const departOptions = ref([]);
let isFormDepartUser = false; let isFormDepartUser = false;
// //
const [registerForm, { setProps, resetFields, setFieldsValue, validate, updateSchema }] = useForm({ const [registerForm, { setProps, resetFields, setFieldsValue, validate, updateSchema }] = useForm({
@ -35,6 +44,7 @@ const [registerForm, { setProps, resetFields, setFieldsValue, validate, updateSc
showActionButtonGroup: false, showActionButtonGroup: false,
}); });
const showFooter = ref(true); const showFooter = ref(true);
const areaOptions = ref<any[]>([]);
// //
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => { const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
await resetFields(); await resetFields();
@ -46,6 +56,7 @@ const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (
setFieldsValue({ setFieldsValue({
...data.record, ...data.record,
}); });
await fetchArea(data.record.institutionId);
} }
// //
setProps({ disabled: !showFooter.value }); setProps({ disabled: !showFooter.value });
@ -76,6 +87,26 @@ async function handleSubmit() {
setDrawerProps({ confirmLoading: false }); setDrawerProps({ confirmLoading: false });
} }
} }
const fetchArea = async (institutionId) => {
if (!institutionId){
institutionId = '-1';
}
areaOptions.value = [];
const data = await queryArea({ pid : institutionId });
Object.assign(areaOptions.value, data);
}
async function handleChange(value,option:Option,formData){
if(value == null){
formData["regionName"] = "";
}else{
formData["regionName"] = option.label;
}
console.log(formData);
}
</script> </script>
<style scoped> <style scoped>

View File

@ -260,12 +260,19 @@ import {
createMessage.warning('请先选择一个节点'); createMessage.warning('请先选择一个节点');
return; return;
} }
console.log(data);
let record = { let record = {
projectId: data.projectId, projectId: data.projectId,
projectName: data.projectName, projectName: data.projectName,
parentId: data.regionId, parentId: data.regionId,
parentName: data.regionName, parentName: data.regionName,
}; };
if(data.regionId != null){
record["institutionId"] = data.areaId;
}else{
record["institutionId"] = data.institutionId;
}
console.log(record);
openRegionDrawer(true, { openRegionDrawer(true, {
record, record,
isUpdate: false, isUpdate: false,
@ -289,6 +296,11 @@ import {
parentId: data.regionId, parentId: data.regionId,
parentName: data.regionName, parentName: data.regionName,
}; };
if(data.regionId != null){
record["institutionId"] = data.areaId;
}else{
record["institutionId"] = data.institutionId;
}
console.log(record); console.log(record);
openRegionDrawer(true, { openRegionDrawer(true, {
record, record,

View File

@ -42,6 +42,7 @@
} }
// rootTreeData // rootTreeData
function onRootTreeData(data) { function onRootTreeData(data) {
console.log(data);
rootTreeData.value = data; rootTreeData.value = data;
} }