用 AirPower4T,我们来写个前端管理后台吧:) - V2EX
Hamm

用 AirPower4T,我们来写个前端管理后台吧:)

  •  
  •   Hamm Aug 14, 2023 1517 views
    This topic created in 1010 days ago, the information mentioned may be changed or developed.

    一、写在前面

    前一篇文章《用 AirPower4J ,我们来写个后端服务吧》 是来水一篇,主要是顺带给前端项目写个后端的 api 服务, 略简单,入门级。后续再丰富吧:)

    前端主要使用的是 Vue3 TypeScript 等技术栈,行,开整。

    二、初始化项目

    老规矩,先新建个目录 frontend,再把宿主项目和依赖项目都拉下来,还是在 Github :)

    我们直接使用 宿主项目 提供的一键脚本吧:)

    我不知道你是不是习惯 ssh 方式,反正我挺喜欢:)

    git clone [email protected]:HammCn/AirPowerWebDemo.git && cd AirPowerWebDemo/src && git clone [email protected]:HammCn/AirPower4T.git airpower && cd ../ && yarn && cp .env.dev .env && yarn s 

    不出意外应该会装完依赖启动项目,直接跑起来了。

    截屏 2023-08-07 22.43.11.png

    这一套前后端是配套设计的,所以环境变量默认配置的就是上一篇后端服务文章里的本地服务。

    三、开始写代码

    先创建个菜单吧:)

    截屏 2023-08-07 22.54.08.png

    好,依然是先来创建一下 Service Entity View 部分:

    SupplierEntity 实体

    @ClassName('供应商') export class SupplierEntity extends BaseEntity { @TableField({ copyField: true, forceShow: true, }) @FormField({ requiredString: true, }) @FieldName('供应商编码') code!: string @TableField() @FormField({ requiredString: true, }) @FieldName('供应商名称') name!: string @Dictionary(SupplierLevelDictionary) @TableField({ showColor: true, }) @FormField({ requiredNumber: true, defaultValue: SupplierLevel.GOLD, }) @FieldName('供应商级别') level!: SupplierLevel @TableField() @FormField({ mobilePhone: true, }) @FieldName('联系电话') phone!: string } 

    SupplierLevel 枚举

    export enum SupplierLevel { GOLD = 1, SILVER = 2, COPPER = 3 } 

    SupplierLevelDictionary 枚举翻译字典

    export const SupplierLevelDictiOnary= AirDictionaryArray.create([ { key: SupplierLevel.GOLD, label: '金牌', color: AirColor.SUCCESS, }, { key: SupplierLevel.SILVER, label: '银牌', color: AirColor.WARNING, }, { key: SupplierLevel.COPPER, label: '铜牌', color: AirColor.NORMAL, }, ]) 

    上面我们按需求配置了一些表单、表格以及一些验证,还提供了一个供应商级别的枚举以及字典。

    SupplierService 接口请求服务

    export class SupplierService extends AbstractBaseService<SupplierEntity> { entityClass = SupplierEntity baseUrl = 'supplier' } 

    View 层

    我们创建了 edit.vue list.vue 这些视图:)

    list.vue

    <template> <APanel> <AToolBar :loading="isLoading" :entity="SupplierEntity" :service="SupplierService" @on-add="onAdd" @on-search="onSearch" > <template #afterButton> <AButton v-if="selectList.length>0" type="DELETE_LIST" danger @click="AirNotification.warning('就是玩');selectList=[]" > 批量删除 </AButton> </template> </AToolBar> <ATable v-loading="isLoading" :data-list="response.list" :entity="SupplierEntity" :select-list="selectList" show-select @on-edit="onEdit" @on-delete="onDelete" @on-sort-change="onSortChanged" @on-select="onSelected" /> <template #footerLeft> <APage :respOnse="response" @on-change="onPageChanged" /> </template> </APanel> </template> <script lang="ts" setup> import { APanel, APage, ATable, AToolBar, AButton, } from '@/airpower/component' import { useAirTable } from '@/airpower/hook/useAirTable' import { SupplierEntity } from '@/model/supplier/SupplierEntity' import { SupplierService } from '@/model/supplier/SupplierService' import { SupplierEditor } from './component' import { AirRequest } from '@/airpower/model/AirRequest' import { AirNotification } from '@/airpower/feedback/AirNotification' const { isLoading, response, selectList, onSearch, onAdd, onDelete, onEdit, onPageChanged, onSortChanged, onSelected, } = useAirTable(SupplierEntity, SupplierService, { editor: SupplierEditor, }) </script> 

    实现的效果如下图

    截屏 2023-08-07 23.21.44.png

    关键词搜索、高级筛选,这些基本都可以直接在装饰器中配置,后续再讲。

    edit.vue

    <template> <ADialog :title="title" :form-ref="formRef" :loading="isLoading" @on-cOnfirm="onSubmit()" @on-cancel="onCancel()" > <el-form ref="formRef" :model="formData" label-width="120px" :rules="rules" @submit.prevent > <el-form-item :label="SupplierEntity.getFormFieldLabel('code')" prop="code" > <AInput v-model.code="formData.code" :entity="SupplierEntity" /> </el-form-item> <el-form-item :label="SupplierEntity.getFormFieldLabel('name')" prop="name" > <AInput v-model.name="formData.name" :entity="SupplierEntity" /> </el-form-item> <el-form-item :label="SupplierEntity.getFormFieldLabel('level')" prop="level" > <AInput v-model.level="formData.level" :entity="SupplierEntity" /> </el-form-item> <el-form-item :label="SupplierEntity.getFormFieldLabel('phone')" prop="phone" > <AInput v-model.phOne="formData.phone" :entity="SupplierEntity" /> </el-form-item> </el-form> </ADialog> </template> <script lang="ts" setup> import { ADialog, AInput } from '@/airpower/component' import { airPropsParam } from '@/airpower/config/AirProps' import { useAirEditor } from '@/airpower/hook/useAirEditor' import { SupplierEntity } from '@/model/supplier/SupplierEntity' import { SupplierService } from '@/model/supplier/SupplierService' const props = defineProps(airPropsParam(new SupplierEntity())) const { title, formData, rules, onSubmit, formRef, isLoading, } = useAirEditor(props, SupplierEntity, SupplierService) </script> 

    截屏 2023-08-07 23.18.47.png

    实现了创建和修改两个需求,接下来试试配置的验证是否生效:)

    image.png

    好,搞定,看起来没什么问题。

    四、就这样

    That's all ,今天的水文又有了。

    上面所有的代码都在 Github 欢迎食用。

    文中提到几个开源地址:

    依赖仓库: https://github.com/HammCn/AirPower4T

    宿主项目: https://github.com/HammCn/AirPowerWebDemo

    No Comments Yet
    About     Help     Advertise     Blog     API     FAQ     Solana     5677 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 50ms UTC 06:26 PVG 14:26 LAX 23:26 JFK 02:26
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86