后台管理系统通用页面抽离=>高阶组件+配置文件+hooks
目录结构



配置文件和通用页面组件
content.config.ts
const contentConfig = {pageName: "role",header: {title: "角色列表",btnText: "新建角色"},propsList: [{ type: "selection", label: "选择", width: "80px" },{ type: "index", label: "序号", width: "80px" },{ type: "normal", prop: "name", label: "角色名称", width: "180px" },{ type: "normal", prop: "intro", label: "角色权限", width: "180px" },{ type: "timer", prop: "createAt", label: "创建时间" },{ type: "timer", prop: "updateAt", label: "更新时间" },{ type: "handler", label: "操作", width: "180px" }]
};export default contentConfig;
modal.config.ts
const modalConfig = {pageName: "role",header: {newTitle: "新建角色",editTitle: "编辑角色"},formItems: [{type: "input",label: "角色名称",prop: "name",placeholder: "请输入角色名称"},{type: "input",label: "权限介绍",prop: "intro",placeholder: "请输入权限介绍"},{type: "custom",slotName: "menuList"}]
};export default modalConfig;
search.config.ts
const searchConfig = {formItems: [{type: 'input',prop: 'name',label: '角色名称',placeholder: '请输入查询的角色名称'},{type: 'input',prop: 'intro',label: '角色权限',placeholder: '请输入查询的角色权限'},{type: 'date-picker',prop: 'createAt',label: '创建时间'}]
}
export default searchConfig;
role.vue
<script setup lang="ts">
import PageSearch from "@/components/page-search/page-search.vue";
import PageModal from "@/components/page-modal/page-modal.vue";
import PageContent from "@/components/page-content/page-content.vue";
import searchConfig from "@/views/main/system/role/config/search.config";
import contentConfig from "@/views/main/system/role/config/content.config";
import modalConfig from "@/views/main/system/role/config/modal.config";
import usePageContent from "@/hooks/usePageContent";
import usePageModal from "@/hooks/usePageModal";
import useSystemStore from "@/stores/modules/main/system/system";
import { ref, useTemplateRef, nextTick } from "vue";
import { ElTree } from "element-plus";
import {mapMenuListToIds} from "@/utils/mapMenus";/*** 新增角色时,清空菜单列表*/
const newCallback = () => {nextTick(() => {treeRef.value?.setCheckedKeys([]);})
}/*** 编辑角色时,回显角色所拥有的菜单列表* @param itemData 当前编辑的角色信息*/
const editCallback = (itemData: any) => {nextTick(() => {const menuIds = mapMenuListToIds(itemData.menuList)treeRef.value?.setCheckedKeys(menuIds);})
}const { contentRef, handleQueryClick, handleResetClick } = usePageContent();
const { modalRef, handleNewClick, handleEditClick } = usePageModal(newCallback, editCallback); // editCallback 必须在 usePageModal() 方法前初始化const systemStore = useSystemStore();
const menuList = systemStore.menuList;const treeRef = useTemplateRef<InstanceType<typeof ElTree>>("treeRef");
const treeInfo = ref({});/*** 选择某菜单节点的回调函数* @param node 传递给 data 属性的数组中该节点所对应的对象* @param checked 树目前的选中状态对象*/
const handleElTreeCheck = (node: any, checked: any) => {const menuList = [...checked.checkedKeys, ...checked.halfCheckedKeys];treeInfo.value = { menuList };
};</script><template><div class="role"><page-search:searchConfig="searchConfig":query-click="handleQueryClick"@reset-click="handleResetClick"/><page-contentref="contentRef":content-config="contentConfig"@new-data-click="handleNewClick"@edit-data-click="handleEditClick"/><page-modal ref="modalRef" :modal-config="modalConfig" :treeInfo="treeInfo"><template #menuList><el-treeref="treeRef":data="menuList"show-checkboxnode-key="id":props="{ children: 'children', label: 'name' }"@check="handleElTreeCheck"/></template></page-modal></div>
</template><style scoped></style>
高阶组件
page-search.vue
<template><div class="search"><!-- 1.1.表单输入 --><el-form :model="searchForm" ref="formRef" label-width="120px" size="large"><el-row :gutter="20"><template v-for="item in searchConfig.formItems" :key="item.prop"><el-col :span="8"><el-form-item :label="item.label" :prop="item.prop"><template v-if="item.type === 'input'"><el-input v-model="searchForm[item.prop]" :placeholder="item.placeholder" /></template><template v-if="item.type === 'date-picker'"><el-date-pickerv-model="searchForm[item.prop]"type="daterange"range-separator="至"start-placeholder="开始日期"end-placeholder="结束日期"/></template></el-form-item></el-col></template></el-row></el-form><!-- 1.2.搜索按钮 --><div class="btns"><el-button size="large" icon="Refresh" @click="handleResetClick">重置</el-button><el-button size="large" icon="Search" type="primary" @click="handleQueryClick">查询</el-button></div></div>
</template><script setup lang="ts" name="page-search">
import type {ElForm} from 'element-plus'
import {reactive, ref} from 'vue'const emit = defineEmits(['queryClick', 'resetClick'])// 根据配置初始化表单数据
const {searchConfig} = defineProps(['searchConfig'])
const initialForm: any = {}
for (const item of searchConfig.formItems) {initialForm[item.prop] = ""
}
// console.log('初始化表单数据', initialForm)
// 1.创建表单的数据
const searchForm = reactive(initialForm)// 2.监听按钮的点击
const formRef = ref<InstanceType<typeof ElForm>>()function handleResetClick() {formRef.value?.resetFields()emit('resetClick')
}function handleQueryClick() {emit('queryClick', searchForm)
}
</script><style scoped lang="less">
.search {background-color: #fff;padding: 20px;border-radius: 5px;.el-form-item {padding: 20px 40px;margin-bottom: 0;}
}.btns {text-align: right;padding: 0 50px 10px 0;
}
</style>
page-content.vue
- header
- propList
- 插槽(定制化)=> 作用域插槽
- pageName
<template><div class="content"><div class="header"><h3 class="title">{{ contentConfig?.header?.title ?? "数据列表" }}</h3><el-button v-if="isCreate" type="primary" @click="handleNewData">{{contentConfig?.header?.btnText ?? "新建数据"}}</el-button></div><div class="table"><el-table:data="pageList":border="true":row-key="contentConfig?.childrenTree?.rowKey"style="width: 100%"><template v-for="item in contentConfig.propsList" :key="item.prop"><!-- <el-table-column align="center" :label="item.label" :prop="item.prop" :width="item.width ?? '150px'"></el-table-column>--><el-table-columnv-if="item.type === 'index' || item.type === 'selection'"align="center"v-bind="item"/><el-table-column v-else-if="item.type === 'custom'" align="center" v-bind="item"><template #default="scope"><slot :name="item.slotName" v-bind="scope" :prop="item.prop" :leaderRange="10" /></template></el-table-column><el-table-column v-else align="center" v-bind="item"><template #default="scope"><span v-if="item.type === 'timer'">{{ formatUTC(scope.row[item.prop]) }}</span><span v-else-if="item.type === 'handler'"><el-buttonv-if="isUpdate"type="primary"size="small"icon="EditPen"link@click="handleEditClick(scope.row)">编辑</el-button><el-buttonv-if="isDelete"type="danger"size="small"icon="Delete"link@click="handleDeleteClick(scope.row.id)">删除</el-button></span><span v-else>{{ scope.row[item.prop] }}</span></template></el-table-column></template></el-table></div><div class="footer"><el-paginationv-model:currentPage="currentPage"v-model:pageSize="pageSize":page-sizes="[10, 20, 30]"layout="total, sizes, prev, pager, next, jumper":total="pageTotalCount"@update:currentPage="handleCurrentChange"@update:pageSize="handlePageSizeChange"/></div></div>
</template><script setup lang="ts" name="content">
import { storeToRefs } from "pinia";
import { ref } from "vue";
import useSystemStore from "@/stores/modules/main/system/system";
import { formatUTC } from "@/utils/format";
import usePermission from "@/hooks/usePermission";const { contentConfig } = defineProps(["contentConfig"]);
const emit = defineEmits(["newDataClick", "editDataClick"]);// 0.判断是否有增删改查的权限
const isCreate = usePermission(contentConfig.pageName, "create");
const isDelete = usePermission(contentConfig.pageName, "delete");
const isUpdate = usePermission(contentConfig.pageName, "update");
const isQuery = usePermission(contentConfig.pageName, "query");// 1.请求数据
const systemStore = useSystemStore();
const currentPage = ref(1);
const pageSize = ref(10);systemStore.$onAction(({ name, after }) => {after(() => {if (name === "deletePageByIdAction" ||name === "editPageDataAction" ||name === "newPageDataAction") {currentPage.value = 1;}})
});function fetchPageListData(queryInfo: any = {}) {// 0.判断是否具有查询权限if (!isQuery) return;// 1.获取offset和sizeconst size = pageSize.value;const offset = (currentPage.value - 1) * size;// 2.发生网络请求systemStore.postPageListAction(contentConfig.pageName, { offset, size, ...queryInfo });
}fetchPageListData();// 2.展示数据
const { pageList, pageTotalCount } = storeToRefs(systemStore);// 3.绑定分页数据
function handleCurrentChange() {fetchPageListData();
}function handlePageSizeChange(newPageSize: number) {pageSize.value = newPageSize;fetchPageListData();
}function handleResetClick() {currentPage.value = 1;pageSize.value = 10;fetchPageListData();
}// 4.新建数据的处理
function handleNewData() {emit("newDataClick");
}// 5.删除和编辑操作
function handleDeleteClick(id: number) {systemStore.deletePageByIdAction(contentConfig.pageName, id);
}function handleEditClick(data: any) {emit("editDataClick", data);
}// 暴露函数
defineExpose({fetchPageListData,handleResetClick
});
</script><style scoped lang="less">
.content {margin-top: 20px;padding: 20px;background-color: #fff;.header {display: flex;height: 45px;padding: 0 5px;justify-content: space-between;align-items: center;.title {font-size: 20px;font-weight: 700;}.handler {align-items: center;}}.table {:deep(.el-table__cell) {padding: 14px 0;}}.footer {display: flex;justify-content: flex-end;margin-top: 15px;}
}
</style>
page-modal.vue
- header
- newTitle
- editTitle
- pageName
- formItems
<template><div class="modal"><el-dialog v-model="dialogVisible" :title="modalConfig.header.newTitle" width="30%" center><div class="form"><el-form :model="formData" label-width="80px" size="large"><template v-for="item in modalConfig.formItems" :key="item.prop"><el-form-item :label="item.label" :prop="item.prop"><template v-if="item.type === 'input'"><el-input v-model="formData[item.prop]" :placeholder="item.placeholder" /></template><template v-if="item.type === 'password'"><el-inputshow-passwordv-model="formData[item.prop]":placeholder="item.placeholder"/></template><template v-if="item.type === 'select'"><el-selectv-model="formData.parentId":placeholder="item.placeholder"style="width: 100%"><template v-for="value in item.options" :key="value.value"><el-option :value="value.value" :label="value.label" /></template></el-select></template><template v-if="item.type === 'date-picker'"><el-date-pickertype="daterange"range-separator="-"start-placeholder="开始时间"end-placeholder="结束时间"v-model="formData[item.prop]"/></template><template v-if="item.type === 'custom'"><slot :name="item.slotName"></slot></template></el-form-item></template></el-form></div><template #footer><span class="dialog-footer"><el-button @click="dialogVisible = false">取消</el-button><el-button type="primary" @click="handleConfirmClick">确定</el-button></span></template></el-dialog></div>
</template><script setup lang="ts" name="modal">
import { storeToRefs } from "pinia";
import { reactive, ref } from "vue";
import useSystemStore from "@/stores/modules/main/system/system";const dialogVisible = ref(false);
const isEdit = ref(false);
const editData = ref();// 定义数据绑定
const formData = reactive<any>({name: "",leader: "",parentId: ""
});const { modalConfig, treeInfo } = defineProps(["modalConfig", "treeInfo"]);
// 点击确定
const systemStore = useSystemStore();
const { departmentList } = storeToRefs(systemStore);const initialData: any = {};
for (const item of modalConfig?.formItems) {initialData[item.prop] = item.initialValue ?? "";
}function handleConfirmClick() {dialogVisible.value = false;// 判断是否存在含树形菜单权限的formDatalet treeFormData = { ...formData };if (treeInfo) {treeFormData = {...treeFormData,...treeInfo};}console.log(treeFormData);if (!isEdit.value) {systemStore.newPageDataAction(modalConfig.pageName, treeFormData);} else {systemStore.editPageDataAction(modalConfig.pageName, editData.value.id, treeFormData);}
}// 新建或者编辑
function setDialogVisible(isNew: boolean = true, data: any = {}) {dialogVisible.value = true;isEdit.value = !isNew;editData.value = data;for (const key in formData) {if (isNew) {formData[key] = "";} else {formData[key] = data[key];}}
}defineExpose({setDialogVisible
});
</script><style scoped lang="less">
.form {padding: 10px 30px;
}
</style>
hooks
usePageContent.ts
import { useTemplateRef } from "vue";
import PageContent from "@/components/page-content/page-content.vue";function usePageContent() {const contentRef = useTemplateRef<InstanceType<typeof PageContent>>("contentRef");const handleQueryClick = (queryInfo: any) => {contentRef.value?.fetchPageListData(queryInfo);};const handleResetClick = () => {contentRef.value?.fetchPageListData();};return {contentRef,handleQueryClick,handleResetClick};
}export default usePageContent;
usePageModal.ts
import { useTemplateRef } from "vue";
import PageModal from "@/components/page-modal/page-modal.vue";function usePageModal(newCallback?: () => void, editCallback?: (itemData: any) => void) {const modalRef = useTemplateRef<InstanceType<typeof PageModal>>("modalRef");const handleNewClick = () => {modalRef.value?.setDialogVisible(true);if (newCallback) newCallback();};const handleEditClick = (itemData: any) => {modalRef.value?.setDialogVisible(false, itemData);if (editCallback) editCallback(itemData)};return {modalRef,handleNewClick,handleEditClick};
}export default usePageModal;
最终呈现

相关文章:
后台管理系统通用页面抽离=>高阶组件+配置文件+hooks
目录结构 配置文件和通用页面组件 content.config.ts const contentConfig {pageName: "role",header: {title: "角色列表",btnText: "新建角色"},propsList: [{ type: "selection", label: "选择", width: "80px&q…...
Spring Boot项目如何使用MyBatis实现分页查询
写在前面:大家好!我是晴空๓。如果博客中有不足或者的错误的地方欢迎在评论区或者私信我指正,感谢大家的不吝赐教。我的唯一博客更新地址是:https://ac-fun.blog.csdn.net/。非常感谢大家的支持。一起加油,冲鸭&#x…...
[Java]多态
1. 多态的基本概念 1.1 定义: 多态是指同一操作作用于不同的对象时,能够表现出不同的行为。多态通常通过以下两种方式实现: 方法重载(Overloading)方法重写(Overriding) 1.2 示例࿱…...
用Impala对存储在HDFS中的大规模数据集进行快速、实时的交互式SQL查询的具体步骤和关键代码
AWS EMR(Elastic MapReduce)中应用Impala的典型案例,主要体现在大型企业和数据密集型组织如何利用Impala对存储在Hadoop分布式文件系统(HDFS)中的大规模数据集进行快速、实时的交互式SQL查询。以下是一个具体的案例说明…...
Intellij 插件开发-快速开始
目录 一、开发环境搭建以及创建action1. 安装 Plugin DevKit 插件2. 新建idea插件项目3. 创建 Action4. 向新的 Action 表单注册 Action5. Enabling Internal Mode 二、插件实战开发[不推荐]UI Designer 基础JBPanel类(JPanel面板)需求:插件设…...
GIt使用笔记大全
Git 使用笔记大全 1. 安装 Git 在终端或命令提示符中,输入以下命令检查是否已安装 Git: git --version如果未安装,可以从 Git 官方网站 下载并安装适合你操作系统的版本。 2. 配置 Git 首次使用 Git 时,需要配置用户名和邮箱…...
语言月赛 202412【题目名没活了】题解(AC)
》》》点我查看「视频」详解》》》 [语言月赛 202412] 题目名没活了 题目描述 在 XCPC 竞赛里,会有若干道题目,一支队伍可以对每道题目提交若干次。我们称一支队伍对一道题目的一次提交是有效的,当且仅当: 在本次提交以前&…...
MySQL锁类型(详解)
锁的分类图,如下: 锁操作类型划分 读锁 : 也称为共享锁 、英文用S表示。针对同一份数据,多个事务的读操作可以同时进行而不会互相影响,相互不阻塞的。 写锁 : 也称为排他锁 、英文用X表示。当前写操作没有完成前,它会…...
面经--C语言——static,volatile,malloc,使用异或进行数据交换
文章目录 static静态变量和全局变量的区别volatile主要作用 malloc1. 内存分配器的作用2. 内存分配过程(1) 查找空闲内存块(2) 扩展堆空间(3) 元数据 3. 内存释放过程(1) 标记为可用(2) 合并相邻空闲块(3) 延迟释放 4. 内存管理策略(1) 分配缓存(Allocation Caching…...
stm32小白成长为高手的学习步骤和方法
我们假定大家已经对STM32的书籍或者文档有一定的理解。如不理解,请立即阅读STM32的文档,以获取最基本的知识点。STM32单片机自学教程 这篇博文也是一篇不错的入门教程,初学者可以看看,讲的真心不错。 英文好的同学…...
OSCP - Proving Grounds - Roquefort
主要知识点 githook 注入Linux path覆盖 具体步骤 依旧是nmap扫描开始,3000端口不是很熟悉,先看一下 Nmap scan report for 192.168.54.67 Host is up (0.00083s latency). Not shown: 65530 filtered tcp ports (no-response) PORT STATE SERV…...
集合通讯概览
(1)通信的算法 是根据通讯的链路组成的 (2)因为通信链路 跟硬件强相关,所以每个CCL的库都不一样 芯片与芯片、不同U之间是怎么通信的!!!!!! 很重要…...
【贪心算法篇】:“贪心”之旅--算法练习题中的智慧与策略(二)
✨感谢您阅读本篇文章,文章内容是个人学习笔记的整理,如果哪里有误的话还请您指正噢✨ ✨ 个人主页:余辉zmh–CSDN博客 ✨ 文章所属专栏:贪心算法篇–CSDN博客 文章目录 前言例题1.买卖股票的最佳时机2.买卖股票的最佳时机23.k次取…...
oracle: 表分区>>范围分区,列表分区,散列分区/哈希分区,间隔分区,参考分区,组合分区,子分区/复合分区/组合分区
分区表 是将一个逻辑上的大表按照特定的规则划分为多个物理上的子表,这些子表称为分区。 分区可以基于不同的维度,如时间、数值范围、字符串值等,将数据分散存储在不同的分区 中,以提高数据管理的效率和查询性能,同时…...
基于SpringBoot 前端接收中文显示解决方案
一. 问题 返回给前端的的中文值会变成“???” 二. 解决方案 1. 在application.yml修改字符编码 (无效) 在网上看到说修改servlet字符集编码,尝试了不行 server:port: 8083servlet:encoding:charset: UTF-8enabled: trueforce: true2. …...
java练习(5)
ps:题目来自力扣 给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。 请你将两个数相加,并以相同形式返回一个表示和的链表。 你可以假设除了数字 0 之外,这…...
python算法和数据结构刷题[3]:哈希表、滑动窗口、双指针、回溯算法、贪心算法
回溯算法 「所有可能的结果」,而不是「结果的个数」,一般情况下,我们就知道需要暴力搜索所有的可行解了,可以用「回溯法」。 回溯算法关键在于:不合适就退回上一步。在回溯算法中,递归用于深入到所有可能的分支&…...
大数据数仓实战项目(离线数仓+实时数仓)1
目录 1.课程目标 2.电商行业与电商系统介绍 3.数仓项目整体技术架构介绍 4.数仓项目架构-kylin补充 5.数仓具体技术介绍与项目环境介绍 6.kettle的介绍与安装 7.kettle入门案例 8.kettle输入组件之JSON输入与表输入 9.kettle输入组件之生成记录组件 10.kettle输出组件…...
【开源免费】基于Vue和SpringBoot的公寓报修管理系统(附论文)
本文项目编号 T 186 ,文末自助获取源码 \color{red}{T186,文末自助获取源码} T186,文末自助获取源码 目录 一、系统介绍二、数据库设计三、配套教程3.1 启动教程3.2 讲解视频3.3 二次开发教程 四、功能截图五、文案资料5.1 选题背景5.2 国内…...
使用QMUI实现用户协议对话框
使用QMUI实现用户协议对话框 懒加载用于初始化 TermServiceDialogController 对象。 懒加载 lazy var 的作用 lazy var dialogController: TermServiceDialogController {let r TermServiceDialogController()r.primaryButton.addTarget(self, action: #selector(primaryC…...
女生年薪12万,算不算属于高收入人群
在繁华喧嚣的都市中,我们时常会听到关于收入、高薪与生活质量等话题的讨论。尤其是对于年轻女性而言,薪资水平不仅关乎个人价值的体现,更直接影响到生活质量与未来的规划。那么,女生年薪12万,是否可以被划入高收入人群…...
初识Cargo:Rust的强大构建工具与包管理器
初识Cargo:Rust的强大构建工具与包管理器 如果你刚刚开始学习Rust,一定会遇到一个名字:Cargo。Cargo是Rust的官方构建工具和包管理器,它让Rust项目的创建、编译、测试和依赖管理变得非常简单。本文将带你快速了解Cargo的基本用法…...
【Windows7和Windows10下从零搭建Qt+Leaflet开发环境】
Windows7和Windows10下从零搭建QtLeaflet开发环境 本文开始编写于2025年1月27日星期一(农历:腊月二十八,苦逼的人,过年了还在忙工作)。 第一章 概述 整个开发环境搭建需要的资源: 操作系统 Windows7_x6…...
关于MySQL InnoDB存储引擎的一些认识
文章目录 一、存储引擎1.MySQL中执行一条SQL语句的过程是怎样的?1.1 MySQL的存储引擎有哪些?1.2 MyIsam和InnoDB有什么区别? 2.MySQL表的结构是什么?2.1 行结构是什么样呢?2.1.1 NULL列表?2.1.2 char和varc…...
WSL2中安装的ubuntu开启与关闭探讨
1. PC开机后,查询wsl状态 在cmd或者powersell中输入 wsl -l -vNAME STATE VERSION * Ubuntu Stopped 22. 从windows访问WSL2 wsl -l -vNAME STATE VERSION * Ubuntu Stopped 23. 在ubuntu中打开一个工作区后…...
LeetCode435周赛T2贪心
题目描述 给你一个由字符 N、S、E 和 W 组成的字符串 s,其中 s[i] 表示在无限网格中的移动操作: N:向北移动 1 个单位。S:向南移动 1 个单位。E:向东移动 1 个单位。W:向西移动 1 个单位。 初始时&#…...
π0:仅有3B数据模型打通Franka等7种机器人形态适配,实现0样本的完全由模型自主控制方法
Chelsea Finn引领的Physical Intelligence公司,专注于打造先进的机器人大模型,近日迎来了一个令人振奋的里程碑。在短短不到一年的时间内,该公司成功推出了他们的首个演示版本。这一成就不仅展示了团队的卓越技术实力,也预示着机器…...
DeepSeek-R1 低成本训练的根本原因是?
在人工智能领域,大语言模型(LLM)正以前所未有的速度发展,驱动着自然语言处理、内容生成、智能客服等众多应用的革新。然而,高性能的背后往往是高昂的训练成本,动辄数百万美元的投入让许多企业和研究机构望而…...
pandas(二)读取数据
一、读取数据 示例代码 import pandaspeople pandas.read_excel(../002/People.xlsx) #读取People数据 print(people.shape) # 打印people表的行数、列数 print(people.head(3)) # 默认打印前5行,当前打印前3行 print("") print(people.tail(3)) # 默…...
北京门头沟区房屋轮廓shp的arcgis数据建筑物轮廓无偏移坐标测评
在IT行业中,地理信息系统(GIS)是用于处理、分析和展示地理空间数据的重要工具,而ArcGIS则是GIS领域中的一款知名软件。本文将详细解析标题和描述中提及的知识点,并结合“门头沟区建筑物数据”这一标签,深入…...
