vue2企业级项目(八)
vue2企业级项目(八)
组件封装(二)
4、searchForm
-
创建
components/searchForm/index.js
import XSearchForm from "./index.vue"; export default XSearchForm;
-
使用案例
<template><div class="wrap"><h3>基础搜索</h3><div class="box"><x-search-form :columns="columns1" @search="handleSearch"></x-search-form></div><h3>自动布局</h3><div class="box"><x-search-form:columns="columns2"@search="handleSearch":lineNum="4"></x-search-form></div><h3>自定义搜索按钮</h3><div class="box"><x-search-form:columns="columns3":hasSearch="false"@search="handleSearch"ref="search"></x-search-form></div></div> </template><script> export default {name: "Page7",data() {return {searchLoading: false,resetLoading: false,columns1: [{ type: "input", label: "姓名", prop: "name" },{ type: "input", label: "年龄", prop: "age" },{type: "select",label: "性别",prop: "sex",options: [{ label: "男", value: "1" },{ label: "女", value: "0" },],},],columns2: [{ type: "input", label: "姓名1", prop: "name1" },{ type: "input", label: "姓名2", prop: "name2" },{ type: "input", label: "姓名3", prop: "name3" },{ type: "input", label: "姓名4", prop: "name4" },{ type: "input", label: "姓名5", prop: "name5" },],columns3: [{ type: "input", label: "姓名", prop: "name" },{span: 16,align: "right",render: () => {return (<div><el-button type="success" icon="el-icon-upload">导入</el-button><el-button type="warning" icon="el-icon-download">导出</el-button><el-buttontype="primary"icon="el-icon-search"loading={this.searchLoading}onClick={this.triggerSearch}>搜索</el-button><el-buttonicon="el-icon-refresh"loading={this.resetLoading}onClick={this.triggerReset}>重置</el-button></div>);},},],};},mounted() {},methods: {handleSearch(searchForm, callback) {if (searchForm) {console.log(searchForm);this.$message.success("搜索成功");} else {this.$message.success("重置成功");}setTimeout(() => {callback();this.searchLoading = false;this.resetLoading = false;}, 1000);},triggerSearch() {this.searchLoading = true;this.$refs.search.triggerSearch();},triggerReset() {this.resetLoading = true;this.$refs.search.triggerReset();},}, }; </script><style lang="less" scoped> .wrap {width: 100%;height: 100%;display: flex;align-items: center;flex-direction: column; }.box {width: 800px;height: 200px;padding: 10px;margin-bottom: 20px;background: #1f03034d; } </style>
5、searchTable
-
创建
components/searchTable/index.js
import XSearchTable from "./index.vue"; export default XSearchTable;
-
创建
components/searchTable/index.vue
<template><div class="x-search-table"><x-search-formv-bind="searchConfig":columns="searchFields"@search="handleSearch"ref="search"></x-search-form><div class="x-search-table-box"><x-tablev-bind="tableConfig":columns="tableFields":api="api":tableData="data"ref="table"></x-table></div></div> </template><script> /*** @param { Array } columns: 配置* @param { Array } data: 数据* @param { Function } api: 接口* @param { Object } searchForm: search的配置* @param { Object } tableForm: table的配置** @event { Function } getSearchForm: 获取搜索值* @event { Function } setSearchForm: 获取搜索值* @event { function } toggleSelection:设置默认多选* @event { function } setCurrent: 设置单选* @event { function } clearFilter:清空筛选项* @event { function } getSelection: 获取选中结果* @event { function } getTableData: 获取表格值*/export default {name: "XSearchTable",props: {columns: {type: Array,default: () => [],},data: {type: Array,default: () => [],},api: {type: Function,default: null,},searchConfig: {type: Object,default: () => ({}),},tableConfig: {type: Object,default: () => ({}),},},data() {return {searchFields: [],tableFields: [],searchForm: null,};},watch: {columns: {immediate: true,deep: true,handler() {this.handleFields();},},},methods: {handleFields() {this.searchFields = this.columns.map((item) => {let searchItem = { ...item, ...item.search };delete searchItem.form;delete searchItem.table;delete searchItem.search;delete searchItem.dialog;return searchItem;});this.tableFields = this.columns.map((item) => {let tableItem = { ...item, ...item.table };delete tableItem.form;delete tableItem.table;delete tableItem.search;delete tableItem.dialog;return tableItem;});},handleSearch(searchForm, callback) {this.searchForm = searchForm;this.$refs.table.setTableData(searchForm).then(callback);},getSearchForm() {return this.$refs.search.getSearchForm();},setSearchForm(form) {this.$refs.search.setSearchForm(form);},toggleSelection(rows) {this.$refs.table.toggleSelection(rows);},setCurrent(row) {this.$refs.table.setCurrent(row);},clearFilter() {this.$refs.table.clearFilter();},getSelection() {return this.$refs.table.getSelection();},getTableData() {return this.$refs.table.getTableData();},}, }; </script><style lang="less" scoped> .x-search-table {width: 100%;height: 100%;display: flex;align-items: center;flex-direction: column;.x-search-table-box {width: 100%;flex: 1;} } </style>
-
使用案例
<template><div class="wrap"><!-- 基础搜索 --><h3>基础搜索</h3><div class="box"><x-search-table :columns="columns" :data="data"></x-search-table></div><!-- 接口搜索 --><h3>接口搜索</h3><div class="box"><x-search-table :columns="columns2" :api="getList"></x-search-table></div></div> </template><script> import { getList } from "@/api/mock.js";export default {name: "Page8",data() {return {columns: [{ type: "input", label: "姓名", prop: "name" },{ type: "input", label: "年龄", prop: "age" },{type: "select",label: "性别",prop: "sex",options: [{ label: "男", value: "1" },{ label: "女", value: "0" },],},{type: "input",label: "地址",prop: "address",search: { isShow: false },},],data: [],columns2: [{ type: "input", label: "姓名", prop: "name" },{ type: "input", label: "年龄", prop: "age" },{type: "select",label: "性别",prop: "sex",options: [{ label: "男", value: "1" },{ label: "女", value: "0" },],},{ label: "日期", prop: "date", props: { valueFormat: "yyyy-MM-DD" } },{type: "input",label: "地址",prop: "address",search: { isShow: false },},],};},created() {this.init();},methods: {getList: getList,init() {let list = new Array(99).fill({});list = list.map((item, index) => {return {name: index > 20 ? `张三${index}` : "张三",age: index.toString(),sex: (index % 2).toString(),address: `北京市朝阳区${index}号`,};});this.data = list;},}, }; </script><style lang="less" scoped> .wrap {width: 100%;height: 100%;display: flex;align-items: center;flex-direction: column; }.box {width: 800px;height: 700px;padding: 10px;margin-bottom: 20px;background: #1f03034d; } </style>
6、dialogForm
-
创建
components/dialogForm/index.js
import XSearchTable from "./index.vue"; export default XSearchTable;
-
创建
components/dialogForm/index.vue
<template><x-dialogsubmitText="提交":submitLoading="true":title="title"v-bind="dialogConfig"ref="dialog"><x-formlabelWidth="100px"v-bind="formConfig":columns="formFields":defaultValue="defaultForm":ctrl="false"ref="form"></x-form></x-dialog> </template><script> /*** @param { Array } columns: 配置* @param { String } defaultTitle: 默认标题* @param { String } addTitle: 新增标题* @param { String } editTitle: 编辑标题* @param { Boolean } saveAdd: 是否暂存新增的内容* @param { Object } dialogConfig: dialog的配置* @param { Object } formConfig: form的配置** @event { Function } open: 打开dialogform* @event { Function } triggerSubmit: 手动触发表单校验,校验通过后关闭dialog* @evnet { Function } triggerReset: 手动触发表单重置,完成后关闭dialog**/export default {name: "XDialogForm",props: {columns: {type: Array,default: () => [],},defaultTitle: {type: String,default: "弹框",},addTitle: {type: String,default: "新增",},editTitle: {type: String,default: "编辑",},saveAdd: {type: Boolean,default: false,},dialogConfig: {type: Object,default: () => ({}),},formConfig: {type: Object,default: () => ({}),},},data() {return {title: "",formFields: [],defaultForm: {},handleResolve: null,handleReject: null,handleCallback: null,};},watch: {columns: {immediate: true,deep: true,handler() {this.init();},},},methods: {init() {this.formFields = this.columns.map((item) => {const formItem = { ...item, ...item.dialog };delete formItem.form;delete formItem.table;delete formItem.search;delete formItem.dialog;return formItem;});this.formFields = this.formFields.filter((item) => item.isShow !== false);},open(form) {if (!this.saveAdd || form) {this.defaultForm = form || {};}if (form) this.title = this.editTitle || this.defaultTitle;else this.title = this.addTitle || this.defaultTitle;this.$refs.dialog.open().then((callback) => {this.handleCallback = callback;this.triggerSubmit();}).catch(this.triggerReset.bind(this));return new Promise((resolve, reject) => {this.handleResolve = resolve;this.handleReject = reject;});},triggerSubmit() {this.$refs.form.submit().then(({ form, valid }) => {console.log(form, valid);if (valid) {this.handleResolve(form);this.handleCallback();this.closeBefore();} else {this.handleCallback(false);}}).finally(() => {this.handleCallback = null;});},triggerReset() {if (this.addTitle && this.title === this.addTitle) {this.close();return true;}this.closeBefore();},closeBefore() {this.defaultForm = {};this.$refs.form.reset().then(() => {this.handleReject();this.close();});},close() {this.title = "";this.handleResolve = null;this.handleReject = null;this.handleCallback = null;},}, }; </script>
-
使用案例
<template><div><el-button type="primary" @click="openDialog()">新增</el-button><el-button type="primary" @click="openDialog(data)">编辑</el-button><x-dialog-form :columns="columns" ref="dialogForm"></x-dialog-form></div> </template><script> export default {name: "Page9",data() {return {columns: [{ type: "input", label: "用户", prop: "name", required: true },{ type: "input", label: "年龄", prop: "age" },{type: "radio",label: "性别",prop: "sex",options: [{ label: "男", value: "1" },{ label: "女", value: "0" },],},],data: {name: "张三",age: "20",sex: "1",},};},methods: {openDialog(data) {this.$refs.dialogForm.open(data).then((form) => {console.log(form, "------编辑后的值");}).catch(() => {console.log("-----------取消");});},}, }; </script>
相关文章:

vue2企业级项目(八)
vue2企业级项目(八) 组件封装(二) 4、searchForm 创建components/searchForm/index.js import XSearchForm from "./index.vue"; export default XSearchForm;使用案例 <template><div class"wrap"…...

小研究 - 主动式微服务细粒度弹性缩放算法研究(二)
微服务架构已成为云数据中心的基本服务架构。但目前关于微服务系统弹性缩放的研究大多是基于服务或实例级别的水平缩放,忽略了能够充分利用单台服务器资源的细粒度垂直缩放,从而导致资源浪费。为此,本文设计了主动式微服务细粒度弹性缩放算法…...

【雕爷学编程】Arduino动手做(177)---ESP-32 掌控板
37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的&am…...

使用Gunicorn+Nginx部署Flask项目
部署-开发机上的准备工作 确认项目没有bug。用pip freeze > requirements.txt将当前环境的包导出到requirements.txt文件中,方便部署的时候安装。将项目上传到服务器上的/srv目录下。这里以git为例。使用git比其他上传方式(比如使用pycharmÿ…...

【12】STM32·HAL库开发-STM32时钟系统 | F1/F4/F7时钟树 | 配置系统时钟
目录 1.认识时钟树(掌握)1.1什么是时钟?1.2认识时钟树(F1)1.2.1STM32F103时钟树简图1.2.2STM32CubeMX时钟树(F103) 1.3认识时钟树(F4)1.3.1F407时钟树1.3.2F429时钟树1.3…...

Kotlin基础(十):函数进阶
前言 本文主要讲解kotlin函数,之前系列文章中提到过函数,本文是kotlin函数的进阶内容。 Kotlin文章列表 Kotlin文章列表: 点击此处跳转查看 目录 1.1 函数基本用法 Kotlin 是一种现代的静态类型编程语言,它在函数的定义和使用上有一些特点…...

计算机视觉(四)神经网络与典型的机器学习步骤
文章目录 神经网络生物神经元人工神经元激活函数导数 人工神经网络“层”的通俗理解 前馈神经网络Delta学习规则前馈神经网络的目标函数梯度下降输出层权重改变量 误差方向传播算法误差传播迭代公式简单的BP算例随机梯度下降(SGD)Mini-batch Gradient De…...

使用easyui的tree组件实现给角色快捷分配权限功能
这篇文章主要介绍怎么实现角色权限的快捷分配功能,不需要像大多数项目的授权一样,使用类似穿梭框的组件来授权。 具体实现:通过菜单树的勾选和取消勾选来给角色分配权限,在这之前,需要得到角色的菜单树,角色…...

Postman打不开/黄屏/一直转圈/Windows
环境背景 内网环境Postman-win64-8.11.1-Setup.exe 问题描述 电脑重启后,打开Postman后,出现加载弹窗:Preparing your workspaces…This might take a few minutes; 等待数分钟后,还是没有反应,于是关闭…...

使用SVM模型完成分类任务
SVM,即支持向量机(Support Vector Machine),是一种常见的机器学习算法,用于分类和回归分析。SVM的基本思想是将数据集映射到高维空间中,在该空间中找到一个最优的超平面,将不同类别的数据点分开…...

计算机毕设 深度学习实现行人重识别 - python opencv yolo Reid
文章目录 0 前言1 课题背景2 效果展示3 行人检测4 行人重识别5 其他工具6 最后 0 前言 🔥 这两年开始毕业设计和毕业答辩的要求和难度不断提升,传统的毕设题目缺少创新和亮点,往往达不到毕业答辩的要求,这两年不断有学弟学妹告诉…...

开发经验分享之:import引入包和@Autowired注入类有什么区别
大家好,我是三叔,很高兴这期又和大家见面了,一个奋斗在互联网的打工人。 import 和 Autowired 想必大家在 Java 开发中使用频率最多的关键字之一了把,这篇博客将解释这两个概念的区别和作用,帮助你更好地理解它们在Ja…...

MySQL和Oracle区别
由于SQL Server不常用,所以这里只针对MySQL数据库和Oracle数据库的区别 (1) 对事务的提交 MySQL默认是自动提交,而Oracle默认不自动提交,需要用户手动提交,需要在写commit;指令或者点击commit按钮 (2) 分页查询 MySQL是直接在SQL…...

QT--day6(人脸识别、图像处理)
人脸识别: /***********************************************************************************头文件****************************************************************************************/#ifndef WIDGET_H #define WIDGET_H#include <QWidget>…...

深度学习:常用优化器Optimizer简介
深度学习:常用优化器Optimizer简介 随机梯度下降SGD带动量的随机梯度下降SGD-MomentumSGDWAdamAdamW 随机梯度下降SGD 梯度下降算法是使权重参数沿着整个训练集的梯度方向下降,但往往深度学习的训练集规模很大,计算整个训练集的梯度需要很大…...

【算法心得】二维dp的状态转移狂练
LCS: LCS变式:使两个字符串变成一样的,删除的和最小 https://leetcode.cn/problems/minimum-ascii-delete-sum-for-two-strings/ 建表 m ∗ n m*n m∗n or ( m 1 ) ∗ ( n 1 ) (m1)*(n1) (m1)∗(n1)? 感觉 ( m 1 ) ∗ ( n …...

JMeter常用内置对象:vars、ctx、prev
在前文 Beanshell Sampler 与 Beanshell 断言 中,初步阐述了JMeter beanshell的使用,接下来归集整理了JMeter beanshell 中常用的内置对象及其使用。 注:示例使用JMeter版本为5.1 1. vars 如 API 文档 所言,这是定义变量的类&a…...

【C++从0到王者】第十四站:list基本使用及其介绍
文章目录 一、list基本介绍二、list基本使用1.尾插头插接口使用2.insert接口使用3.查找某个值所在的位置4.erase接口使用以及迭代器失效5.reverse6.sort7.merge8.unique9.remove11.splice 三、list基本使用完整代码 一、list基本介绍 如下所示,是库里面对list的基本…...

正则表达式、常用的正则
文章目录 正则表达式字符含意义RegExp函数RegExp属性RegExp对象方法RegExp构造函数的第二个参数 常用的正则例子只包含数字(包括正数、负数、零)只包含中英文数字及键盘上的特殊字符校验密码是否符合规则的正则校验http或者https端口号的正则只校验端口号…...

ST官方基于米尔STM32MP135开发板培训课程(一)
本文将以Myirtech的MYD-YF13X以及STM32MP135F-DK为例,讲解如何使用STM32CubeMX结合Developer package实现最小系统启动。 1.开发准备 1.1 Developer package准备 a.Developer package下载: https://www.st.com/en/embedded-software/stm32mp1dev.ht…...

组件(lvs,keeplive,orm,mysql,分布式事务)
lvs LVS 已经集成到Linux内核系统中,ipvsadm 是 LVS 的命令行管理工具。 目前有三种 IP 负载均衡技术( VS/NAT 网络地址转换 、VS/TUN IP 隧道技术实现虚拟服务器 和 VS/DR 直接路由); 八种调度算法:轮询 …...

《视觉SLAM十四讲》报错信息和解决方案
文章目录 ch4-Sophus编译报错ch5/imageBasics安装opencv4.x报错ch5/joinMap/CMakeLists.txt编译报错ch5/joinMap-pcl_viewer map.pcd报错 ch4-Sophus编译报错 报错信息: error: lvalue required as left operand of assignmentunit_complex_.real() 1.;^~ error:…...

golang 设置http请求代理
tinypoxy 搭建http代理服务可参考:tinyproxy搭建http代理_wangxiaoangg的博客-CSDN博客 需求背景: 项目需要访问一国外服务接口,地址被墙。购买香港ecs服务器,并在上面搭建http代理服务。 一 使用http和https代理 func main() {pr…...

我的会议(会议通知)
前言: 我们在实现了发布会议功能,我的会议功能的基础上,继续来实现会议通知的功能。 4.1实现的特色功能: 当有会议要参加时,通过查询会议通知可以知道会议的内容,以及当前会议状态(未读) 4.2思路…...

css实现水平居中
代码示例 <div class"box"><div class"box1"></div> </div>1.弹性布局:(推荐) display:flex; 这些要添加在父级的,是父级的属性 //父级添加display:flex; //父级添加jus…...

c刷题(一)
目录 1.输出100以内3的倍数 2.将3个数从大到小输出 3.打印100~200素数 方法一 方法二 4.显示printf的返回值 最大公约数 试除法 辗转相除法 九九乘法表 求十个数的最大值 1.输出100以内3的倍数 法一: int n 0; while (n*3 < 100){printf("%d &q…...

webpack
文章目录 webpack概念打包的场景为什么要打包在打包之外 - 翻译在打包之外 - 小动作 课程重点模块化利用立即执行函数来改变 作用域模块化的优点模块化方案的进化史AMD(成型比较早,应用不是很广泛)COMMONJSES6 MODULE webpack 的打包机制webp…...

反复 Failed to connect to github.com port 443 after xxx ms
前提:使用了代理,浏览器能稳定访问github,但git clone一直超时 解决方案: 1. git config --global http.proxy http://127.0.0.1:1080 2. 代理设置端口1080 3. 1080可自定义 感谢来自这篇博客和评论区的提醒:解决…...

ARM裸机-11
1、安装交叉编译工具工具 1.1、windows中装软件的特点 windows中装软件使用安装包,安装包解压后有两种情况:一种是一个安装文件 (.exe/.msi),双击进行安装,下一步直到安装完毕。安装完毕后会在桌面上生成快捷方式,我们平时使用快…...

centos7升级glibc
作者:吴业亮 博客:wuyeliang.blog.csdn.net 安装bison: yum install bison -y安装wget、bzip2、gcc、gcc-c和glibc-headers: yum -y install wget bzip2 gcc gcc-c glibc-headers安装make-4.2.1: wget http://ftp.…...