feat-wip(components): 行政区划相关页面代码提交
This commit is contained in:
4
src/typings/api/sys/rbac.d.ts
vendored
4
src/typings/api/sys/rbac.d.ts
vendored
@ -10,9 +10,9 @@ declare namespace Api {
|
|||||||
rootCode: string | null;
|
rootCode: string | null;
|
||||||
name: string;
|
name: string;
|
||||||
code: string;
|
code: string;
|
||||||
extCode: string;
|
extCode: string | null;
|
||||||
sort: number;
|
sort: number;
|
||||||
description: string;
|
description: string | null;
|
||||||
createTime: string;
|
createTime: string;
|
||||||
updateTime: string;
|
updateTime: string;
|
||||||
children: RegionVO[];
|
children: RegionVO[];
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
<script setup lang="tsx">
|
<script setup lang="tsx">
|
||||||
import { reactive } from 'vue';
|
import { reactive } from 'vue';
|
||||||
import { NButton, NPopconfirm } from 'naive-ui';
|
import { NButton, NPopconfirm } from 'naive-ui';
|
||||||
|
import { jsonClone } from '@sa/utils';
|
||||||
import { fetchRegionDelete, fetchRegionDeleteBatch, fetchRegionPaginate } from '@/service/api';
|
import { fetchRegionDelete, fetchRegionDeleteBatch, fetchRegionPaginate } from '@/service/api';
|
||||||
import { useAppStore } from '@/store/modules/app';
|
import { useAppStore } from '@/store/modules/app';
|
||||||
import { defaultTransform, useNaivePaginatedTable, useTableOperate } from '@/hooks/common/table';
|
import { defaultTransform, useNaivePaginatedTable, useTableOperate } from '@/hooks/common/table';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
import RegionSearch from '@/views/sys/rbac/region/modules/region-search.vue';
|
import RegionSearch from '@/views/sys/rbac/region/modules/region-search.vue';
|
||||||
import RegionOperateDrawer from '@/views/sys/rbac/region/modules/region-operate-drawer.vue';
|
import RegionOperateDrawer from '@/views/sys/rbac/region/modules/region-operate-drawer.vue';
|
||||||
|
import RegionVO = Api.Sys.Rbac.RegionVO;
|
||||||
|
|
||||||
// ******************** 数据定义 ********************
|
// ******************** 数据定义 ********************
|
||||||
|
|
||||||
@ -43,13 +45,6 @@ const { columns, columnChecks, data, loading, getData, getDataByPage, pagination
|
|||||||
type: 'selection',
|
type: 'selection',
|
||||||
align: 'center'
|
align: 'center'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
key: 'index',
|
|
||||||
title: $t('common.index'),
|
|
||||||
width: 50,
|
|
||||||
align: 'center',
|
|
||||||
render: (_, index) => index + 1
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
key: 'name',
|
key: 'name',
|
||||||
title: $t('page.sys.rbac.region.fields.name'),
|
title: $t('page.sys.rbac.region.fields.name'),
|
||||||
@ -92,10 +87,10 @@ const { columns, columnChecks, data, loading, getData, getDataByPage, pagination
|
|||||||
align: 'center',
|
align: 'center',
|
||||||
render: row => (
|
render: row => (
|
||||||
<div class="flex-center gap-8px">
|
<div class="flex-center gap-8px">
|
||||||
<NButton type="primary" ghost size="small" onClick={() => handleAddChildren(row.id)}>
|
<NButton type="primary" ghost size="small" onClick={() => handleAddChildren(row)}>
|
||||||
{$t('common.children')}
|
{$t('common.children')}
|
||||||
</NButton>
|
</NButton>
|
||||||
<NButton type="primary" ghost size="small" onClick={() => edit(row.id)}>
|
<NButton type="primary" ghost size="small" onClick={() => edit(row)}>
|
||||||
{$t('common.edit')}
|
{$t('common.edit')}
|
||||||
</NButton>
|
</NButton>
|
||||||
<NPopconfirm onPositiveClick={() => handleDelete(row.id)}>
|
<NPopconfirm onPositiveClick={() => handleDelete(row.id)}>
|
||||||
@ -114,7 +109,7 @@ const { columns, columnChecks, data, loading, getData, getDataByPage, pagination
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
// 表格操作
|
// 表格操作
|
||||||
const { drawerVisible, operateType, editingData, checkedRowKeys, handleAdd, handleEdit, onDeleted, onBatchDeleted } =
|
const { drawerVisible, operateType, editingData, checkedRowKeys, openDrawer, onDeleted, onBatchDeleted } =
|
||||||
useTableOperate(data, 'id', getData);
|
useTableOperate(data, 'id', getData);
|
||||||
|
|
||||||
// ******************** 触发事件 ********************
|
// ******************** 触发事件 ********************
|
||||||
@ -131,11 +126,25 @@ function handleDelete(id: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function edit(id: string) {
|
function edit(row: RegionVO) {
|
||||||
handleEdit(id);
|
operateType.value = 'edit';
|
||||||
|
editingData.value = jsonClone(row);
|
||||||
|
openDrawer();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAddChildren(_: string) {}
|
function add() {
|
||||||
|
operateType.value = 'add';
|
||||||
|
editingData.value = null;
|
||||||
|
openDrawer();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleAddChildren(row: RegionVO) {
|
||||||
|
operateType.value = 'add';
|
||||||
|
// 数据准备
|
||||||
|
editingData.value = jsonClone(row);
|
||||||
|
// 打开抽屉
|
||||||
|
openDrawer();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -152,7 +161,7 @@ function handleAddChildren(_: string) {}
|
|||||||
v-model:columns="columnChecks"
|
v-model:columns="columnChecks"
|
||||||
:disabled-delete="checkedRowKeys.length === 0"
|
:disabled-delete="checkedRowKeys.length === 0"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
@add="handleAdd"
|
@add="add"
|
||||||
@delete="handleBatchDelete"
|
@delete="handleBatchDelete"
|
||||||
@refresh="getData"
|
@refresh="getData"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -46,12 +46,14 @@ function createDefaultModel(): Api.Sys.Rbac.RegionDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 抽屉标题
|
// 抽屉标题
|
||||||
|
const realOperateType = ref('');
|
||||||
const title = computed(() => {
|
const title = computed(() => {
|
||||||
const titles: Record<NaiveUI.TableOperateType, string> = {
|
const titles: Record<string, string> = {
|
||||||
add: $t('common.add'),
|
add: $t('common.add'),
|
||||||
edit: $t('common.edit')
|
edit: $t('common.edit'),
|
||||||
|
children: $t('common.children')
|
||||||
};
|
};
|
||||||
return titles[props.operateType];
|
return titles[realOperateType.value];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Form校验规则
|
// Form校验规则
|
||||||
@ -67,8 +69,17 @@ const rules: Record<RuleKey, App.Global.FormRule> = {
|
|||||||
// ******************** 事件定义 ********************
|
// ******************** 事件定义 ********************
|
||||||
function handleInitModel() {
|
function handleInitModel() {
|
||||||
model.value = createDefaultModel();
|
model.value = createDefaultModel();
|
||||||
|
|
||||||
|
realOperateType.value = 'add';
|
||||||
if (props.operateType === 'edit' && props.rowData) {
|
if (props.operateType === 'edit' && props.rowData) {
|
||||||
|
realOperateType.value = 'edit';
|
||||||
Object.assign(model.value, jsonClone(props.rowData));
|
Object.assign(model.value, jsonClone(props.rowData));
|
||||||
|
} else if (props.operateType === 'add' && props.rowData && props.rowData.id) {
|
||||||
|
realOperateType.value = 'children';
|
||||||
|
model.value.parentId = props.rowData.id;
|
||||||
|
model.value.parentCode = props.rowData.code;
|
||||||
|
model.value.rootId = props.rowData.rootId;
|
||||||
|
model.value.rootCode = props.rowData.rootCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user