react-开发经验分享-Steps横竖业务进度条的具体使用方法

Author:Mr.柳上原

  • 付出不亚于任何的努力
  • 愿我们所有的努力,都不会被生活辜负
  • 不忘初心,方得始终

ant框架里,Steps横竖业务进度条的具体使用方法
在ant里介绍了Steps组件,进度条
不过没有具体的对接后端数据的使用方法
特别是Steps组件里最重要的status状态控制方法
分享一下在项目开发中遇到的问题以及解决方法
具体如下:

// 首先根据ant官方Steps组件使用方法引入到react里

// 使用state来存储后端数据并动态更新
this.state = {
    projectData: {}, // 业务数据
    reportFollow: [], // 流程数据
    newReportFollow: [], // 驻场数据
}

// 固定的静态进度条使用方法
crosswiseStep = [
        {
            title: "待确认",
            icon: <Icon type="contacts" />,
            // description: "This is a description.",
            id: 0,
        },
        {
            title: "待看房",
            icon: <Icon type="shop" />,
            // description: "This is a description.",
            id: 1,
        },
        {
            title: "带认购",
            icon: <Icon type="dashboard" />,
            // description: "This is a description.",
            id: 3,
        },
        {
            title: "已成交",
            icon: <Icon type="audit" />,
            // description: "This is a description.",
            id: 4,
        },
    ]

// 初始数据
    initialData = async () => {
        let reportId = this.props.location.state.id || '';

        let res = await ProjectDetailsApi.getReport(reportId);
        let data = res.extension || {}; // 后端请求到的数据
        console.log(res, '表格初始数据');
        if (res.code == '0') {
             let reportFollow = []; // 驻场流程
             let newLording = ''; // 横向进度条状态码

             reportFollow = data.reportFollow;

             // 固定进度条状态判断
             data.reportFollow.map((item, index) => {
                // 0 - 待确认 / 1 - 待看房 / 3 - 待认购 / 4 - 已成交
               if(item.transactionsStatus == 0 || item.transactionsStatus == 1 || item.transactionsStatus == 3 || item.transactionsStatus == 4) {
                    newLording = item.transactionsStatus;
                }

              this.setState({
                  reportFollow,
                  lording: newLording,
             })
        } else {
            message.error('获取列表数据失败');
        }
    }

// render渲染固定的静态进度条
<Steps direction={"horizontal"} labelPlacement={"vertical"} initial={0}>
      {
         this.crosswiseStep.map((item, index) => {
           return (
                <Step 
                    key={item.id}
                    status={
                        item.id <= lording 
                        ? 'process'
                         : 'wait'
                     }
                    title={item.title}
                    icon={item.icon}
                 />
               )
           })
        }
</Steps>

// render渲染动态进度条
<Steps direction={"vertical"} labelPlacement={"vertical"} initial={0}>
    {
        reportFollow.map((item, index) => {
           return (
                 <Step 
                    key={index}
                    status={
                        reportFollow.length -1 == index
                        ? (reportFollow[reportFollow.length - 1].transactionsStatus == 4 ? 'process' : 'wait')
                         : 'process'
                      }
                      title={item.contents}
                      icon={item.icon}
                      description={
                          <div>
                            <p>{item.createUser}</p>
                            <p>{item.createTime}</p>
                          </div>  
                       }
                  />
              )
          })
  }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,194评论 4 61
  • 我的人生思思语之一 作者:高英 2011年 01 今夏同事离职不断,令人伤感;但至少有三个以上的人考上了公办学校的...
    泠风思语阅读 2,962评论 0 2
  • 我想找一个有花、有树、有湖的山头,搭一间茅草屋,春耕、夏种、秋收、冬眠,不问世事,不理红尘,蓄一头长发,穿一身...
    龙胆阅读 2,563评论 0 2
  • 再一次被提起 旧伤疤下掩饰的痛 新生的粉肉还没有坚强 又被撕出血痕 他们以为 时间已经治愈 可以不用再小心翼翼地提...
    七龄晏笑阅读 2,662评论 3 5
  • 今天是1月1日,距离关注简书近一年,一年来只是默默地看着,心里却越看越慌乱,不论是网络里的大神还是周围的朋...
    清音羽墨阅读 2,801评论 0 0