diff --git a/src/api/platform/system/controller/region.ts b/src/api/platform/system/controller/region.ts index a71d882..65e5671 100644 --- a/src/api/platform/system/controller/region.ts +++ b/src/api/platform/system/controller/region.ts @@ -3,38 +3,31 @@ * Copyright © 2020-2022 entfrm 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) => { - 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) => { + 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) =>defHttp.post({url:Api.add,data:params}); +export const listRegionAll = () => defHttp.get({ url: Api.list }); + +export const addRegion =(params:Partial) => defHttp.post({ url: Api.add,data:params }); -/**修改 */ -export const editAddr =(params:Partial) =>defHttp.put({url:Api.edit,data:params}); +export const editRegion =(params:Partial) => defHttp.put({ url: Api.edit,data:params }); -/**查询详细 */ -export const getAddr = (id: string) => defHttp.get({ url: `${Api.get}/${id}` }); +export const getRegion = (id: string) => defHttp.get({ 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}` }); diff --git a/src/api/platform/system/entity/region.ts b/src/api/platform/system/entity/region.ts index b0f1b77..e2818bf 100644 --- a/src/api/platform/system/entity/region.ts +++ b/src/api/platform/system/entity/region.ts @@ -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; \ No newline at end of file +export type RegionResult = R; diff --git a/src/views/system/region/RegionModal.vue b/src/views/system/region/RegionModal.vue index bed820e..3a2e3d4 100644 --- a/src/views/system/region/RegionModal.vue +++ b/src/views/system/region/RegionModal.vue @@ -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>(''); @@ -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); // 处理清除脏数据 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 = { confirmLoading: false }; + const regionId = data.record?.id; + const props: Partial = { 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 @@ // 采用tag标签区分操作 switch (unref(tag)) { case 'add': - await addAddr(formData); + await addRegion(formData); break; case 'edit': - await editAddr(formData); + await editRegion(formData); break; } // 处理提交完成之后逻辑 diff --git a/src/views/system/region/index.vue b/src/views/system/region/index.vue index 68f0c2d..0dfdd18 100644 --- a/src/views/system/region/index.vue +++ b/src/views/system/region/index.vue @@ -5,35 +5,25 @@ @expand="onExpandClick" > diff --git a/src/views/system/region/region.data.ts b/src/views/system/region/region.data.ts index e166771..79748e7 100644 --- a/src/views/system/region/region.data.ts +++ b/src/views/system/region/region.data.ts @@ -1,133 +1,117 @@ 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, - }, - { - title: '排序', - dataIndex: 'sort', - width:50 - }, - { - title: '创建时间', - dataIndex: 'createTime', - width:200 - }, - + { + title: '区域名称', + dataIndex: 'name', + align: 'left' + }, + { + title: '区域编码', + dataIndex: 'code' + }, + { + title: '区域排序', + dataIndex: 'sort' + }, + { + title: '创建时间', + dataIndex: 'createTime', + width:200 + }, + { + title: '备注', + dataIndex: 'remarks' + }, ]; export const searchFormSchema: FormSchema[] = [ - { - field: 'name', - label: '区域名称', - component: 'Input', - componentProps: { - placeholder: '请输入区域名称', - }, - colProps: { span: 5 }, + { + field: 'name', + label: '区域名称', + component: 'Input', + componentProps: { + placeholder: '请输入区域名称', }, - { - field:'id', - label:'区域ID', - component:'Input', - componentProps:{ - placeholder:'请输入区域ID', - }, - colProps:{span:5} + colProps: { span: 8 } + }, + { + field:'code', + label:'区域编码', + component:'Input', + componentProps:{ + placeholder:'请输入区域编码', }, - { - field: 'dateRange', - label: '创建时间', - component: 'RangePicker', - componentProps: { - style: { width:'100%' }, - valueFormat: 'YYYY-MM-DD', - placeholder: ['开始日期','结束日期'] - }, - colProps: { span: 8 } - }, - + colProps:{ span:7 } + }, + { + field: 'dateRange', + label: '创建时间', + component: 'RangePicker', + componentProps: { + style: { width:'100%' }, + valueFormat: 'YYYY-MM-DD', + 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, - // }, - // - { - field: 'parentId', - label: '上级地区', - component: 'TreeSelect', - defaultValue: '0', - required: true, - componentProps:{ - replaceFields: { - title: 'name', - key: 'id', - value: 'id', - }, - getPopupContainer: () => document.body, +export const regionFormSchema: FormSchema[] = [ + { + field: 'id', + label: 'ID', + component: 'Input', + show: false + }, + { + field: 'parentId', + label: '上级区域', + component: 'TreeSelect', + defaultValue: '0', + componentProps: { + replaceFields: { + title: 'name', + key: 'id', + value: 'id' + }, + getPopupContainer: () => document.body, } + }, + { + field: 'name', + label: '区域名称', + component: 'Input', + required: true, + colProps: { + span: 12 + } + }, + { + field: 'code', + label: '区域编码', + component: 'Input', + colProps: { + span: 12 + } + }, + { + field: 'sort', + label: '区域排序', + component: 'InputNumber', + componentProps: { + style: { width:'100%' }, + min: 0 }, - { - field: 'id', - label: '区域ID', - component: 'Input', - helpMessage: ['区域ID'], - required: true - }, - // { - // field: 'code', - // label: '区域编码', - // component: 'Input', - // required: true, - // - // }, - { - field:'sort', - label:'排序', - component:'Input', - required:true - }, - { - label: '区域名称', - field: 'name', - component: 'Input', - }, - - { - label: '备注', - field: 'remarks', - component: 'InputTextArea', + required: true, + colProps: { + span: 12 } -]; \ No newline at end of file + }, + { + label: '备注', + field: 'remarks', + component: 'InputTextArea', + } +];