行政区划

This commit is contained in:
陈红丽 2024-07-22 14:32:03 +08:00
parent 9423c882f7
commit f5f5167f69
3 changed files with 24 additions and 26 deletions

View File

@ -157,7 +157,7 @@ const handleSubmit = async () => {
props.cityId ? await cityUpdate(formData) : await cityAdd(formData); props.cityId ? await cityUpdate(formData) : await cityAdd(formData);
message("操作成功"); message("操作成功");
emit("update:visible", false); emit("update:visible", false);
emit("success"); emit("success",formData.parentCode);
}; };
const { isLock: subLoading, lockFn: submit } = useLockFn(handleSubmit); const { isLock: subLoading, lockFn: submit } = useLockFn(handleSubmit);

View File

@ -10,7 +10,6 @@
</template> </template>
新增 新增
</el-button> </el-button>
<!-- <el-button @click="handleExpand"> 展开/折叠</el-button> -->
</div> </div>
</el-card> </el-card>
<el-card :bordered="false" class="pt-3 mb-3 proCard"> <el-card :bordered="false" class="pt-3 mb-3 proCard">
@ -39,7 +38,7 @@
<el-button type="primary" link @click="handleEdit(row)"> <el-button type="primary" link @click="handleEdit(row)">
编辑 编辑
</el-button> </el-button>
<el-button type="danger" link @click="handleDelete(row.id)"> <el-button type="danger" link @click="handleDelete(row)">
删除 删除
</el-button> </el-button>
</template> </template>
@ -52,7 +51,7 @@
:cityId="cityId" :cityId="cityId"
:parentData="parentData" :parentData="parentData"
v-model:visible="editVisible" v-model:visible="editVisible"
@success="getDataList(0)" @success="refreshDataList"
> >
</editDialog> </editDialog>
</div> </div>
@ -63,24 +62,25 @@ import {defineAsyncComponent, nextTick, onMounted, ref, shallowRef} from "vue";
import {cityDelete} from "@/api/data/city"; import {cityDelete} from "@/api/data/city";
import {getCityByList} from "@/api/system/user"; import {getCityByList} from "@/api/system/user";
import type {ElTable} from "element-plus"; import type {ElTable} from "element-plus";
const tableRef = shallowRef<InstanceType<typeof ElTable>>(); // const tableRef = shallowRef<InstanceType<typeof ElTable>>();
const tableRef = ref()
import {confirm, message} from "@/utils/auth"; import {confirm, message} from "@/utils/auth";
const editDialog = defineAsyncComponent(() => const editDialog = defineAsyncComponent(() =>
import('./edit.vue') import('./edit.vue')
) )
const isExpand = ref(false);
const loading = ref(false); const loading = ref(false);
const editVisible=ref(false); const editVisible=ref(false);
const cityId=ref(0); const cityId=ref(0);
const parentData=ref() const parentData=ref()
const lists = ref([]); const lists = ref([]);
const maps = ref(new Map())
const getDataList = async (typeId: any, resolve?: any) => { const getDataList = async (code: any, resolve?: any) => {
try { try {
loading.value = true; loading.value = true;
let res = await getCityByList(typeId); let res = await getCityByList(code);
let data = res.length>0 ?res: []; let data = res.length>0 ?res: [];
data.map(item => { data.map(item => {
if (item.level <=3) { if (item.level <=3) {
@ -105,7 +105,18 @@ const getDataList = async (typeId: any, resolve?: any) => {
} }
}; };
const refreshDataList=(code)=>{
if(code==0) {
getDataList(0);
} else if( maps.value.get(code)) {
const { tree, treeNode, resolve } = maps.value.get(code)
if (tree) {
loadTree(tree, treeNode, resolve);
}
}
}
const loadTree = (tree: any, treeNode: any, resolve: any) => { const loadTree = (tree: any, treeNode: any, resolve: any) => {
maps.value.set(tree.areaCode, { tree, treeNode, resolve })
getDataList(tree.areaCode, resolve); getDataList(tree.areaCode, resolve);
}; };
const handleAdd = async (data:any) => { const handleAdd = async (data:any) => {
@ -121,32 +132,18 @@ const handleEdit = async (data: any) => {
editVisible.value=true editVisible.value=true
}; };
const handleDelete = async (cityId: number) => { const handleDelete = async (row: any) => {
await confirm("确定要删除?"); await confirm("确定要删除?");
try { try {
loading.value = true; loading.value = true;
await cityDelete(cityId); await cityDelete(row.id);
message("删除成功"); message("删除成功");
getDataList(0); loading.value = false;
refreshDataList(row.parentCode);
} catch (e) { } catch (e) {
loading.value = false; loading.value = false;
} }
}; };
const handleExpand = () => {
isExpand.value = !isExpand.value;
toggleExpand(lists.value, isExpand.value);
};
const toggleExpand = (children: any[], unfold = true) => {
for (const key in children) {
tableRef.value?.toggleRowExpansion(children[key], unfold);
if (children[key].children) {
toggleExpand(children[key].children!, unfold);
}
}
};
onMounted(() => { onMounted(() => {
getDataList(0) getDataList(0)
}); });

View File

@ -40,6 +40,7 @@ export const schemas: FormSchema[] = [
label: '状态', label: '状态',
componentProps: { componentProps: {
placeholder: '请选择状态', placeholder: '请选择状态',
clearable: true,
options: [ options: [
{ {
label: '正常', label: '正常',