超长表单分页校验,下一页和上一页功能

news2024/10/5 13:03:16

父组件(最外层)

<template>
    <xx-layout title="练习">
        <div
            slot="content"
            class="hierarchy-tag-main"
        >
            <el-steps
                :space="200"
                :active="currentComponentIndex + 1"
                align-center
                style="margin-bottom: 30px;"
            >
                <el-step
                    v-for="stepItem in steps"
                    :key="stepItem.compId"
                    :status="stepItem.status"
                    :title="stepItem.label"
                />
            </el-steps>
            <div>
                <keep-alive>
                    <component
                        :is="currentComponent"
                        :ref="currentComponent"
                        :entire-data="entireData"
                    />
                </keep-alive>
            </div>
            <div class="footer">
                <el-button
                    type="default"
                    @click="save"
                >
                    暂存
                </el-button>
                <el-button
                    type="primary"
                    :disabled="currentComponentIndex <= 0"
                    @click="pre"
                >
                    上一步
                </el-button>
                <!-- 最后一步时按钮隐藏 -->
                <el-button
                    v-if="currentComponentIndex < (steps.length-1)"
                    type="primary"
                    :disabled="currentComponentIndex >= (steps.length-1)"
                    @click="next"
                >
                    {{ nextStepButtonName }}
                </el-button>

                <el-button
                    v-if="currentComponentIndex == 4"
                    type="primary"
                    @click="onSubmit"
                >
                    提交
                </el-button>
            </div>
        </div>
    </xx-layout>
</template>
<script>
import PageOne from './pageOne';
import PageTwo from './pageTwo';
import PageThree from './pageThree';
import PageFour from './pageFour';
import PageFive from './pageFive';

const compsInfo = {
    pageOne: {
        compId: 'pageOne', label: '第一页', status: 'process', index: 1,
    },
    pageTwo: {
        compId: 'pageTwo', label: '第二页', status: 'process', index: 2,
    },
    pageThree: {
        compId: 'pageThree', label: '第三页', status: 'process', index: 3,
    },
    pageFour: {
        compId: 'pageFour', label: '第四页', status: 'process', index: 4,
    },
    pageFive: {
        compId: 'pageFive', label: '第五页', status: 'process', index: 5,
    },
};

const steps = Object.values(compsInfo).sort((a, b) => a.index - b.index);
export default {
    components: {
        PageOne,
        PageTwo,
        PageThree,
        PageFour,
        PageFive,

    },
    props: {},
    data() {
        return {
            currentComponentIndex: 0,
            entireData: {
                // 第一页数据
                pageOne: {
                    name: '',
                    region: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: '',
                },
                // 第二页数据
                pageTwo: {
                    name: '',
                    region: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: '',
                },
                // 第三页数据
                pageThree: {
                    name: '',
                    region: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: '',
                },
                // 第四页数据
                pageFour: {
                    name: '',
                    region: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: '',
                },
                // 第五页数据
                pageFive: {
                    name: '',
                    region: '',
                    delivery: false,
                    type: [],
                    resource: '',
                    desc: '',
                },
            },
        };
    },
    computed: {
        steps() {
            // 第一页
            if (this.currentComponentIndex === 0) {
                return steps;
            } else {
                // 如果存在内容信息页,则过滤掉steps中内容信息部分
                return steps;
            }
        },
        nextStepButtonName() {
            return '下一步';
        },
        // 下一个组件
        currentComponent() {
            return this.steps[this.currentComponentIndex] &&             
                   this.steps[this.currentComponentIndex].compId;
        },
    },
    methods: {
        // 上一步
        pre() {
            this.currentComponentIndex -= 1;
            this.steps[this.currentComponentIndex].status = 'process';
        },
        // 下一步
        async next() {
            // 第一页
            if (this.currentComponentIndex + 1 === 1) {
                await this.$refs.pageOne.pageOneSubmitForm();
            }
            // 第二页
            if (this.currentComponentIndex + 1 === 2) {
                await this.$refs.pageTwo.pageTwoSubmitForm();
            }
            // 第三页
            if (this.currentComponentIndex + 1 === 3) {
                await this.$refs.pageThree.pageThreeSubmitForm();
            }
            // 第四页
            if (this.currentComponentIndex + 1 === 4) {
                await this.$refs.pageFour.pageFourSubmitForm();
            }
            // 第五页
            if (this.currentComponentIndex + 1 === 5) {
                await this.$refs.pageFive.pageFiveSubmitForm();
            }

            // 下一步 要标记为完成
            this.steps[this.currentComponentIndex].status = 'success';
            this.currentComponentIndex += 1;
        },
        // 暂存  调接口把entireData传给接口即可
        save() {

        },
        // 提交  调接口把entireData传给接口即可
        onSubmit() {

        },
    },
};
</script>
<style lang="scss" scoped>
.footer {
    width: 100%;
    height: 40px;
    line-height: 40px;
    padding: 10px 0;
    background-color: #eee;
    text-align: center;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 2;
    box-sizing: content-box;
}
</style>

第一页的子组件   

<template>
    <xx-layout>
        <div
            slot="content"
            class="hierarchy-tag-main"
        >
            <h1>第一页</h1>
            <el-form
                ref="ruleForm"
                :model="ruleForm"
                :rules="rules"
                label-width="100px"
                class="demo-ruleForm"
            >
                <el-form-item
                    label="活动名称"
                    prop="name"
                >
                    <el-input v-model="ruleForm.name" />
                </el-form-item>
                <el-form-item
                    label="活动区域"
                    prop="region"
                >
                    <el-select
                        v-model="ruleForm.region"
                        placeholder="请选择活动区域"
                    >
                        <el-option
                            label="区域一"
                            value="shanghai"
                        />
                        <el-option
                            label="区域二"
                            value="beijing"
                        />
                    </el-select>
                </el-form-item>

                <el-form-item
                    label="即时配送"
                    prop="delivery"
                >
                    <el-switch v-model="ruleForm.delivery" />
                </el-form-item>
                <el-form-item
                    label="活动性质"
                    prop="type"
                >
                    <el-checkbox-group v-model="ruleForm.type">
                        <el-checkbox
                            label="美食/餐厅线上活动"
                            name="type"
                        />
                        <el-checkbox
                            label="地推活动"
                            name="type"
                        />
                        <el-checkbox
                            label="线下主题活动"
                            name="type"
                        />
                        <el-checkbox
                            label="单纯品牌曝光"
                            name="type"
                        />
                    </el-checkbox-group>
                </el-form-item>
                <el-form-item
                    label="特殊资源"
                    prop="resource"
                >
                    <el-radio-group v-model="ruleForm.resource">
                        <el-radio label="线上品牌商赞助" />
                        <el-radio label="线下场地免费" />
                    </el-radio-group>
                </el-form-item>
                <el-form-item
                    label="活动形式"
                    prop="desc"
                >
                    <el-input
                        v-model="ruleForm.desc"
                        type="textarea"
                    />
                </el-form-item>
            </el-form>
        </div>
    </xx-layout>
</template>
<script>
export default {
    props: {
        entireData: {
            type: Object,
            default: () => ({}),
        },
    },
    data() {
        return {
            ruleForm: this.entireData.pageOne,
            rules: {
                name: [
                    { required: true, message: '请输入活动名称', trigger: 'blur' },
                    {
                        min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur',
                    },
                ],
                region: [
                    { required: true, message: '请选择活动区域', trigger: 'change' },
                ],

                type: [
                    {
                        type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change',
                    },
                ],
                resource: [
                    { required: true, message: '请选择活动资源', trigger: 'change' },
                ],
                desc: [
                    { required: true, message: '请填写活动形式', trigger: 'blur' },
                ],
            },
        };
    },
    methods: {
        pageOneSubmitForm(formName = 'ruleForm') {
            return new Promise((resolve) => {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        resolve(true);
                    } else {
                        return false;
                    }
                });
            });
        },
    },
};
</script>
<style lang="scss" scoped>
.footer {
    width: 100%;
    height: 40px;
    line-height: 40px;
    padding: 10px 0;
    background-color: #eee;
    text-align: center;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 2;
    box-sizing: content-box;
}
</style>

第二页-第五页和第一页结构一样. 只有(数据: ruleForm: this.entireData.pageOne)和(方法pageOneSubmitForm ) 这两个地方不一样, 稍微改一下就行.这里就不贴代码了. 

其他的地方可以根据自己的需求改.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1066602.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Flutter横屏实践

1、Flutter设置横屏 // 强制横屏 SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight ]); // 强制竖屏 SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);另…

【虹科分享】什么是Redis数据集成(RDI)?

大量的应用程序、日益增长的用户规模、不断扩展的技术需求&#xff0c;以及对即时响应的持续追求。想想这些是否正是你在经历的。也许你尝试过自己构建工具来应对这些需求&#xff0c;但是大量的编码和集成工作使你焦头烂额。那你是否知道&#xff0c;有这样一个工具可以帮助你…

数据结构-图-最小生成树问题

最小生成树 并查集定义举例说明查找某个元素属于哪个集合代码实现路径压缩 Kruskal算法原理代码实现 Prim算法原理代码实现 并查集 定义 &#x1f680;在一些应用问题中&#xff0c;需要将n个不同的元素分成一些不相交的集合。开始时&#xff0c;每个元素自成一个单元素集合&…

小商品公众号微信店铺搭建的作用是什么

小商品顾名思义就是价格低、需求广且数量多的日用产品&#xff0c;覆盖人群非常广&#xff0c;无论线上还是线下总能找到目标客户&#xff0c;铅笔、削皮刀、晾衣架等各式产品琳琅满目&#xff0c;不少商家也是热衷于小商品的售卖。 从整体来看&#xff0c;小商品商家也可线上…

tomcat整体架构

Tomcat介绍 Tomcat是Apache Software Foundation&#xff08;Apache软件基金会&#xff09;开发的一款开源的Java Servlet 容器。它是一种Web服务器&#xff0c;用于在服务器端运行Java Servlet和JavaServer Pages (JSP)技术。它可 以为Java Web应用程序提供运行环境&#x…

刚入职字节外包一个月,我却离职了...

有一种打工人的羡慕&#xff0c;叫做“大厂”。 真是年少不知大厂香&#xff0c;错把青春插稻秧。 但是&#xff0c;在深圳有一群比大厂员工更庞大的群体&#xff0c;他们顶着大厂的“名”&#xff0c;做着大厂的工作&#xff0c;还可以享受大厂的伙食&#xff0c;却没有大厂…

新手选MT4还是MT5,anzo capital昂首资本建议选择MT4,一个原因

在交易中就订单执行策略而言&#xff0c;MT4和MT5哪个更好&#xff0c;相信很多交易者和&#xff0c;anzo capital昂首资本一样很难做出判断。在MT5中&#xff0c;虽然开发人员对发送订单的流程进行了额外的复杂化&#xff0c;同时MT5在订单执行政策方面的优势在于其能够调整全…

告警繁杂迷人眼,多源分析见月明

随着数字化浪潮的蓬勃兴起&#xff0c;网络安全问题日趋凸显&#xff0c;面对指数级增长的威胁和告警&#xff0c;传统的安全防御往往力不从心。网内业务逻辑不规范、安全设备技术不成熟都会导致安全设备触发告警。如何在海量众多安全告警中识别出真正的网络安全攻击事件成为安…

Vue3项目使用Stimulsoft.Reports.js【项目实战】

Vue3项目使用Stimulsoft.Reports.js【项目实战】 相关阅读&#xff1a;vue-cli使用stimulsoft.reports.js&#xff08;保姆级教程&#xff09;_stimulsoft vue-CSDN博客 前言 在BS的项目中我们时常会用到报表打印、标签打印、单据打印&#xff0c;可是BS的通用打印解决方案又…

【JavaEE初阶】 多线程(初阶)——壹

文章目录 &#x1f332;线程的概念&#x1f6a9;线程是什么&#x1f6a9;为啥要有线程&#x1f6a9;进程和线程的区别&#x1f6a9;Java 的线程 和 操作系统线程 的关系 &#x1f60e;第一个多线程程序&#x1f6a9;使用 jconsole 命令观察线程 &#x1f38d;创建线程&#x1f…

字段位置顺序对值的影响

Unity中验证AB加载场景时报错&#xff1a; Cannot load scene: Invalid scene name (empty string) and invalid build index -1 报错原因是因为把字段放在了Start函数后面(图一)改成(图二)就好了。图一中协程使用的sceneBName字段值为null。 图一&#xff1a; 图二&#xff1a…

【C++】List -- 详解

一、list的介绍及使用 https://cplusplus.com/reference/list/list/?kwlist list 是可以在常数范围内在任意位置进行插入和删除的序列式容器&#xff0c;并且该容器可以前后双向迭代。 list 的底层是双向链表结构&#xff0c;双向链表中每个元素存储在互不相关的独立节点中&…

Windows10点击开始菜单没反应的四种解决方法

在Windows10电脑中&#xff0c;用户点击开始菜单却出现了没反映的情况&#xff0c;这样用户就无法通过开始菜单来展开操作哦&#xff0c;会给用户的正常操作带来一定程序的影响&#xff0c;下面小编给大家带来四种简单的解决方法&#xff0c;帮助大家轻松恢复Windows10电脑开始…

Selenium 高级定位 CSS

一、CSS选择器概念 CSS拥有自己的语法规则和表达式 CSS通常分为相对定位和绝对定位 CSS常和XPATH一起用于UI自动化测试 二、CSS相对定位使用场景 支持web场景支持app端的webview 三、CSS语法实战 3.1、CSS相对定位的优点 可维护性强语法简洁可以解决各种复杂的定位场景 # …

ARMv7-A 那些事 - 6.常用汇编指令

By: Ailson Jack Date: 2023.10.07 个人博客&#xff1a;http://www.only2fire.com/ 本文在我博客的地址是&#xff1a;http://www.only2fire.com/archives/158.html&#xff0c;排版更好&#xff0c;便于学习&#xff0c;也可以去我博客逛逛&#xff0c;兴许有你想要的内容呢。…

【二叉树练习题】

欢迎来到我的&#xff1a;世界 希望作者的文章对你有所帮助&#xff0c;有不足的地方还请指正&#xff0c;大家一起学习交流 ! 目录 前言初阶题二叉树的节点个数二叉树的叶子节点个数二叉树第k层节点个数二叉树查找值为x的节点 进阶题完全二叉树的节点个数翻转二叉树检验两个树…

修炼k8s+flink+hdfs+dlink(一:安装dlink)

一&#xff1a;mysql初始化。 mysql -uroot -p123456 create database dinky; grant all privileges on dinky.* to dinky% identified by dinky with grant option; flush privileges;二&#xff1a;上传dinky。 上传至目录/opt/app/dlink tar -zxvf dlink-release-0.7.4.t…

医学访问学者面试技巧

医学访问学者面试是一个非常重要的环节&#xff0c;它决定了你是否能够获得这个宝贵的机会去国外的大学或研究机构学习和研究。在这篇文章中&#xff0c;知识人网小编将分享一些关于医学访问学者面试的技巧&#xff0c;帮助你在面试中表现出色。 1. 准备充分 在参加医学访问学…

Multisim:JFET混频器设计(含完整程序)

目录 前言实验内容一、先看作业题目要求二、作业正文IntroductionPre-lab work3.13.2 Experiment Work4.1(2)circuit setup4.1(3)add 12V DC4.1(4)set input x1 and x24.1(5)4.1(6)4.1(7)4.2(1)(2)4.2(3)4.2(4)4.3(1)(2)4.3(3) Conclusion 三、资源包内容 前言 花了好大心血完成…

【线性代数及其应用 —— 第一章 线性代数中的线性方程组】-1.线性方程组

所有笔记请看&#xff1a; 博客学习目录_Howe_xixi的博客-CSDN博客https://blog.csdn.net/weixin_44362628/article/details/126020573?spm1001.2014.3001.5502思维导图如下&#xff1a; 内容笔记如下&#xff1a;