Browse Source

🚀 重新调整架构

master
wangxiang 3 years ago
parent
commit
a4dcf3897d
  1. 41
      src/api/platform/system/controller/region.ts
  2. 35
      src/api/platform/system/entity/region.ts
  3. 50
      src/views/system/region/RegionModal.vue
  4. 44
      src/views/system/region/index.vue
  5. 116
      src/views/system/region/region.data.ts

41
src/api/platform/system/controller/region.ts

@ -3,38 +3,31 @@ @@ -3,38 +3,31 @@
* Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved.
* author entfrm开发团队-
*/
import {AddressParams, AddressItem, AddressItemListResult} from '/@/api/platform/system/entity/region';
import { RegionParams, Region, RegionResult } from '/@/api/platform/system/entity/region';
import { defHttp } from '/@/utils/http/axios';
import { isEmpty } from '/@/utils/is';
enum Api {
list = '/system_proxy/system/address/list',
lazyList= '/system_proxy/system/address/lazyList',
get = '/system_proxy/system/address',
add = '/system_proxy/system/address/add',
edit = '/system_proxy/system/address/update',
del = '/system_proxy/system/address/remove'
list = '/system_proxy/system/region/list',
lazyList= '/system_proxy/system/region/lazyList',
get = '/system_proxy/system/region',
add = '/system_proxy/system/region/save',
edit = '/system_proxy/system/region/update',
del = '/system_proxy/system/region/remove'
}
export const listAddr = (params?: Partial<AddressParams>) => {
if (params?.name || params?.id || !isEmpty(params?.dateRange)) {
defHttp.get({url: Api.list, params});
} else
defHttp.get({url: Api.lazyList, params});
export const listRegion = (params?: Partial<RegionParams>) => {
let url = Api.lazyList;
if (params?.name || params?.code || params?.beginTime || params?.endTime) url = Api.list;
return defHttp.get({ url: url, params });
};
/**新增 */
export const addAddr =(params:Partial<AddressItem>) =>defHttp.post({url:Api.add,data:params});
export const listRegionAll = () => defHttp.get({ url: Api.list });
export const addRegion =(params:Partial<Region>) => defHttp.post({ url: Api.add,data:params });
/**修改 */
export const editAddr =(params:Partial<AddressItem>) =>defHttp.put({url:Api.edit,data:params});
export const editRegion =(params:Partial<Region>) => defHttp.put({ url: Api.edit,data:params });
/**查询详细 */
export const getAddr = (id: string) => defHttp.get<AddressItem>({ url: `${Api.get}/${id}` });
export const getRegion = (id: string) => defHttp.get<Region>({ url: `${Api.get}/${id}` });
/**删除 */
export const delAddr = (id: string) => defHttp.delete({ url: `${Api.del}/${id}` });
export const delRegion = (id: string) => defHttp.delete({ url: `${Api.del}/${id}` });

35
src/api/platform/system/entity/region.ts

@ -1,29 +1,20 @@ @@ -1,29 +1,20 @@
// 引入基础包
import type { R } from '/#/axios';
import type { CommonEntity,Page } from '/@/api/common/data/entity';
/**
* @program: kicc-ui
* @description:
*
* @author: entfrm开发团队-
* @create: 2022/4/8
*/
export type AddressParams =AddressItem & Page;
import type { R } from '/#/axios';
import type { TreeEntity, Page } from '/@/api/common/data/entity';
export type RegionParams = Region & Page;
export interface AddressItem extends CommonEntity{
id: string;
parentId: string;
export interface Region extends TreeEntity {
code: string;
sort: number;
name: string;
// level: number;
// lastLevel: boolean;
//level?:string;
// beginTime?: string;
// endTime?: string;
level: number;
[key: string]: any
}
export type AddressItemListResult = R<AddressItem[]>;
export type RegionResult = R<Region[]>;

50
src/views/system/region/RegionModal.vue

@ -16,11 +16,10 @@ @@ -16,11 +16,10 @@
*/
import { ref, unref } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { addressFormSchema } from './region.data';
import { regionFormSchema } from './region.data';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import { listAddr, addAddr, editAddr, getAddr} from '/@/api/platform/system/controller/region';
import { listRegionAll, addRegion, editRegion, getRegion } from '/@/api/platform/system/controller/region';
import { listToTree } from '/@/utils/helper/treeHelper';
import {AddressItem} from '/@/api/platform/system/entity/region';
/** 通用变量统一声明区域 */
const tag = ref<Nullable<string>>('');
@ -28,61 +27,42 @@ @@ -28,61 +27,42 @@
const emit = defineEmits(['success', 'register']);
const [registerForm, { resetFields, setFieldsValue, updateSchema, validate, clearValidate }] = useForm({
labelWidth: 100,
schemas: addressFormSchema,
schemas: regionFormSchema,
showActionButtonGroup: false,
baseColProps: { span: 24 }
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: WindowInnerData = { _tag: '' }) => {
setModalProps({ loading: true } as Partial<ModalProps>);
//
await resetFields();
await clearValidate();
//
tag.value = data._tag;
const topAddr = { id: '0', name: '级区域', children: [] };
topAddr.children = listToTree(await listAddr());
const topRegion = { id: '0', name: '顶级区域', children: [] };
topRegion.children = listToTree(await listRegionAll());
await updateSchema({
field: 'parentId',
componentProps: {
treeData: [topAddr]
treeData: [topRegion]
}
});
await updateSchema({
field: 'id',
componentProps: {
disabled: tag.value == 'edit'
},
});
const addrId = data.record?.id;
const props: Partial<ModalProps> = { confirmLoading: false };
const regionId = data.record?.id;
const props: Partial<ModalProps> = { confirmLoading: false, loading: false };
// tag
switch (unref(tag)) {
case 'add':
props.title = '新增地址';
addrId && await setFieldsValue({ parentId: addrId });
props.title = '新增区域';
regionId && await setFieldsValue({ parentId: regionId });
break;
case 'edit':
props.title = '编辑地址';
await setFieldsValue(await getAddr(addrId));
props.title = '编辑区域';
await setFieldsValue(await getRegion(regionId));
break;
}
// :
setModalProps(props);
});
/** 处理弹出框提交 */
async function handleSubmit() {
try {
@ -93,10 +73,10 @@ @@ -93,10 +73,10 @@
// tag
switch (unref(tag)) {
case 'add':
await addAddr(formData);
await addRegion(formData);
break;
case 'edit':
await editAddr(formData);
await editRegion(formData);
break;
}
//

44
src/views/system/region/index.vue

@ -5,35 +5,25 @@ @@ -5,35 +5,25 @@
@expand="onExpandClick"
>
<template #toolbar>
<a-button
type="primary"
<a-button type="primary"
@click="handleAdd()"
>新增地址</a-button>
<a-button type="default"
@click="expandAll"
>展开全部</a-button>
<a-button type="default"
@click="collapseAll"
>折叠全部</a-button>
>新增区域</a-button>
</template>
<template #action="{ record }">
<TableAction :actions="[
{
label: '编辑',
icon: 'fa6-regular:pen-to-square',
onClick: handleEdit.bind(null, record)
},
{
label: '新增',
icon: 'ant-design:plus-circle-outlined',
onClick: handleAdd.bind(null, record)
},
{
label: '删除',
icon: 'ant-design:delete-outlined',
color: 'error',
popConfirm: {
title: '是否确认删除',
@ -43,7 +33,7 @@ @@ -43,7 +33,7 @@
/>
</template>
</BasicTable>
<DeptModal @register="registerModal" @success="handleRefreshTable"/>
<RegionModal @register="registerModal" @success="handleRefreshTable"/>
</div>
</template>
<script lang="ts" setup>
@ -55,18 +45,17 @@ @@ -55,18 +45,17 @@
*/
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import DeptModal from './RegionModal.vue';
import RegionModal from './RegionModal.vue';
import { columns, searchFormSchema } from './region.data';
import {delAddr, getAddr, listAddr} from '/@/api/platform/system/controller/region';
import { delRegion, listRegion } from '/@/api/platform/system/controller/region';
import { useMessage } from '/@/hooks/web/useMessage';
import { listToTree } from '/@/utils/helper/treeHelper';
/** 通用变量统一声明区域 */
const { createMessage } = useMessage();
const [registerModal, { openModal }] = useModal();
const [registerTable, { reload, expandAll, collapseAll,getDataSource }] = useTable({
title: '地址列表',
api: listAddr,
const [registerTable, { reload, getDataSource }] = useTable({
title: '区域列表',
api: listRegion,
rowKey: 'id',
columns,
formConfig: {
@ -90,25 +79,13 @@ const [registerTable, { reload, expandAll, collapseAll,getDataSource }] = useTab @@ -90,25 +79,13 @@ const [registerTable, { reload, expandAll, collapseAll,getDataSource }] = useTab
slots: { customRender: 'action' },
fixed: false
},
// afterFetch: (result) => listToTree(result, { id: 'id' }),
searchInfo: { parentId: '0' }
});
function onExpandClick(e, info) {
let reqObj = {
parentId: info.id, // ID
};
listAddr(reqObj).then((res) => {
getDataSource().forEach((item) =>{ //IDchildren
if(info.id == item.id){
item.children = res;
}
});
});
listRegion({ parentId: info.id }).then((res) => info.children = res);
}
/** 新增按钮操作,行内新增与工具栏局域新增通用 */
function handleAdd(record?: Recordable) {
openModal(true,{ _tag: 'add', record });
@ -121,7 +98,7 @@ function handleEdit(record: Recordable) { @@ -121,7 +98,7 @@ function handleEdit(record: Recordable) {
/** 删除按钮操作,行内删除 */
async function handleDel(record: Recordable) {
await delAddr(record.id);
await delRegion(record.id);
createMessage.success('删除成功!');
handleRefreshTable();
}
@ -130,5 +107,4 @@ async function handleDel(record: Recordable) { @@ -130,5 +107,4 @@ async function handleDel(record: Recordable) {
function handleRefreshTable() {
reload();
}
</script>

116
src/views/system/region/region.data.ts

@ -1,32 +1,29 @@ @@ -1,32 +1,29 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import {h} from 'vue';
import {Tag} from 'ant-design-vue';
export const columns: BasicColumn[] = [
{
title: '区域ID',
dataIndex: 'id',
width: 50,
},
{
title: '区域名称',
dataIndex: 'name',
width: 120,
align: 'left'
},
{
title: '区域编码',
dataIndex: 'code'
},
{
title: '排序',
dataIndex: 'sort',
width:50
title: '区域排序',
dataIndex: 'sort'
},
{
title: '创建时间',
dataIndex: 'createTime',
width:200
},
{
title: '备注',
dataIndex: 'remarks'
},
];
export const searchFormSchema: FormSchema[] = [
@ -37,16 +34,16 @@ export const searchFormSchema: FormSchema[] = [ @@ -37,16 +34,16 @@ export const searchFormSchema: FormSchema[] = [
componentProps: {
placeholder: '请输入区域名称',
},
colProps: { span: 5 },
colProps: { span: 8 }
},
{
field:'id',
label:'区域ID',
field:'code',
label:'区域编码',
component:'Input',
componentProps:{
placeholder:'请输入区域ID',
placeholder:'请输入区域编码',
},
colProps:{span:5}
colProps:{ span:7 }
},
{
field: 'dateRange',
@ -58,73 +55,60 @@ export const searchFormSchema: FormSchema[] = [ @@ -58,73 +55,60 @@ export const searchFormSchema: FormSchema[] = [
placeholder: ['开始日期','结束日期']
},
colProps: { span: 8 }
},
}
];
/*表单配置*/
export const addressFormSchema: FormSchema[] = [
// {
// field: 'parentId',
// label: '地区',
// component: 'ApiTreeSelect',
// //component: 'TreeSelect',
// //defaultValue:'一级区域',
// componentProps: {
// api: treeList,
// resultField: 'list',
// labelField: 'name',
// valueField: 'code',
// // ReplaceFields:{
// // title: 'name',
// // key: 'code',
// // value: 'code'
// // }
// },
// required: true,
// },
//
export const regionFormSchema: FormSchema[] = [
{
field: 'id',
label: 'ID',
component: 'Input',
show: false
},
{
field: 'parentId',
label: '上级区',
label: '上级区域',
component: 'TreeSelect',
defaultValue: '0',
required: true,
componentProps: {
replaceFields: {
title: 'name',
key: 'id',
value: 'id',
value: 'id'
},
getPopupContainer: () => document.body,
}
},
{
field: 'id',
label: '区域ID',
field: 'name',
label: '区域名称',
component: 'Input',
helpMessage: ['区域ID'],
required: true
},
// {
// field: 'code',
// label: '区域编码',
// component: 'Input',
// required: true,
//
// },
required: true,
colProps: {
span: 12
}
},
{
field:'sort',
label:'排序',
field: 'code',
label: '区域编码',
component: 'Input',
required:true
colProps: {
span: 12
}
},
{
label: '区域名称',
field: 'name',
component: 'Input',
field: 'sort',
label: '区域排序',
component: 'InputNumber',
componentProps: {
style: { width:'100%' },
min: 0
},
required: true,
colProps: {
span: 12
}
},
{
label: '备注',
field: 'remarks',

Loading…
Cancel
Save