美文网首页
vue 调试接口 json 格式分解实践

vue 调试接口 json 格式分解实践

作者: web30 | 来源:发表于2020-08-19 21:39 被阅读0次
需求:

根据后台返回的数据格式把报告展示在页面上。

环境:

vue3+vant

效果:
对应数组1效果图
对应对象2效果图
数据格式:
返回的整个数据格式
第1个数组格式分解
第2个对象格式分解
代码:
<template>
  <div class="container">
    <div class="order">
      <ul>
        <li class="order_Msg">
          <span class="orderlist_usernameLine"></span>
          <span>体检人:{{this.route_query.user_Name}}</span>
          <van-divider />
        <div class="sport_org">
          <span class="orderlist_usernameLine"></span>
          <span>体检机构:{{this.route_query.org_Name}}</span>
        </div>
        <div>
          <span class="orderlist_usernameLine"></span>
          <span>体检时间:{{this.route_query.check_Time | dateFmt }}</span>
        </div>
        </li>
      </ul>
    </div>
    <!--主要阳性结果及异常情况-->
    <div class="result_div" @click="goMainResult">
    <span class="result_one"><img src="../../../assets/projectImg/v2_projectImg/sport.png" /></span>
    <span class="result_two">主要阳性结果及异常情况</span>
    <span class="result_three">{{this.totalNum}}项</span>
    <span class="result_four"><van-icon name="arrow" /></span>
    </div>
    <!--折叠面板-->
    <div>
      <van-collapse v-model="activeName">
        <van-collapse-item name="index" title="体检项目及检查结果" icon="shop-o">
          <div v-for="(item, index) in eachCheckResult" :key="index">
            <template>
              <div class="resultChild" @click="eachResult(item.jsonItemsItems)">{{item.ItemTypeName}}<span class="result_child"><van-icon name="arrow" /></span></div>
              <van-divider />
            </template>
          </div>
        </van-collapse-item>
      </van-collapse>
    </div>
  </div>
</template>
<script>
export default {
  name: "checkresult",
  data(){
    return{
      //接收路由传过来的值
      route_query:{
        sport_Type: '',
        org_Name: '',
        user_Name: '',
        check_Time: '',
        ser_Number: '', //服务号
        user_Vid: '' //VID
      },
      //折叠面板
      activeName: ['index'], //默认展开所有项
      totalItems: [], //返回的所有结果
      eachCheckResult: [], //体检项目的每项大类
      totalNum: '',
      mainResult: []
    }
  },
  methods:{
    //获取所有检查结果
    getReportJson(){
      ApiGetReportJson(this.$http,{
        url: 'api/view/GetReportJson',
        method: 'post',
        data: {
          ReportType: this.route_query.sport_Type,
          ServiceNumber: this.route_query.ser_Number,
          VID: this.route_query.user_Vid
        }
      }).then(res =>{
        if(res.data.Code === 200){
          //把后台返回的结果赋值给一个变量
          this.totalItems = res.data.Result;
          //判断返回结果里的数组和对象是否为空,不为空进入方法并且把返回数组或对象赋值给一个变量
          if(this.totalItems.checkItems || this.totalItems.generalInspectionJson.GeneralInspectionItem != null) {
            this.eachCheckResult = this.totalItems.checkItems;
            // 获取主要结果数组,带到下个子页面
            this.mainResult = this.totalItems.generalInspectionJson.GeneralInspectionItem;
            // 获取主要结果的总项数
            this.totalNum = this.totalItems.generalInspectionJson.ItemCount;
          }
        }
      })
    },
    // 跳转体检项目及检查结果--每项子项
    // jsonItemsItems是从页面div传下来的,eachResult方法里的参数可以与页面保持一致,也可以写成aa,如写成aa的话,就相当于是赋值操作了,建议还是保持一致不易混乱
    eachResult(jsonItemsItems){
     // 缓存数据可以在ApiGetReportJson接口调成功后直接存储,也可以在需要用到的地方缓存
     // 缓存当前点击的每项子页的数据
     // 把返回的对象转换为字符串,方便其它地方调用,如不转换的话保存的是整个对象,后面调用获取不到对象的键值,然后在接收页面JSON.parse转换为数组
     window.localStorage.setItem('childReport',JSON.stringify(jsonItemsItems));
      this.$router.push({path: '/eachresult',});
    },
    // 跳转主要阳性结果及异常情况页面
    goMainResult(){
      // 缓存主要阳性结果页面数据
      window.localStorage.setItem('mainReport',JSON.stringify(this.mainResult));
      this.$router.push({path: '/mainresult',})
    },
  },
  created() {
    this.route_query.sport_Type = this.$route.query.sport_Type;
    this.route_query.org_Name = this.$route.query.org_Name;
    this.route_query.user_Name = this.$route.query.user_Name;
    this.route_query.check_Time = this.$route.query.check_Time;
    this.route_query.ser_Number = this.$route.query.ser_Number;
    this.route_query.user_Vid = this.$route.query.user_Vid;
    this.getReportJson()
  }
}
</script>
第1个数组大类里的子页面代码:
<template>
    <div class="order">
      <ul>
        <li class="order_Msg">
          <span class="orderlist_usernameLine"></span>
          <span class="size_div">{{this.Category}}</span>
          <div class="size_div1">医生:{{this.Doctor}}</div>
          <van-divider />
        </li>
        <li class="order_Msg" v-for="(item,index) in childReportList" :key="index">
          <div class="size_div2" v-if="!isShowChoose">{{item.Name}}<span style="float: right">{{item.Result}}</span></div>
          <div class="size_div2" v-if="isShowChoose">
            <div>{{item.Name}}</div>
            <div>{{item.Result}}</div>
          </div>
          <van-divider />
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
export default {
  name: 'eachresult',
  data () {
    return {
      isShowChoose: false,
      childReportList: [],
      Category: '', // 当前点击的某项大类
      Doctor: ''
    }
  },
  methods: {
    getCheckItem () {
      // 获取缓存参数
      this.childReportList = JSON.parse(window.localStorage.getItem('childReport'))
      // 取每个大类中的子数组的第1个展示,因为每个大类中的Category和Doctor是一样的
      this.Category = this.childReportList[0].Category
      this.Doctor = this.childReportList[0].Doctor
    },
    // 体检项目中子项样式字体重叠时,根据当前点击子项来判断并获取新的样式
    getType () {
      if (this.Category == '甲状腺彩超' || this.Category == '颈动脉彩超') {
        this.isShowChoose = true
      } else {
        this.isShowChoose = false
      }
    }
  },
  created () {
    this.getCheckItem()
    this.getType()
  }
}
</script>

相关文章

  • vue 调试接口 json 格式分解实践

    需求: 根据后台返回的数据格式把报告展示在页面上。 环境: vue3+vant 效果: 数据格式: 代码: 第1个...

  • python小功能-递归解析Json

    目的:解析Json格式的接口参数用途:用于接口自动化测试,避免手工录入接口参数 1 Json格式的接口参数会有多种...

  • 判断一个字符串是否为json 字符串(jsoncpp)

    主要使用json 的Json::Reader parse()接口来进行判断:parse()接口:将json格式的字...

  • golang中json.Number妙用

    最近跟某斯调试一个API接口,接口返回数据是json格式 ,按文档描述是一个整型数据,于是定义如下 在入参相同的情...

  • Jmeter对Json数据的三种处理方式

    现在的接口测试中,大多数请求响应的报文格式都为json格式。那么在Jmeter接口测试中如何对json格式的数据进...

  • 后台返回 code = 3840错误码

    跟后台调试接口的时候,后台返回了code = 3840的错误 这是由于后台返回Json数据格式不正确导致的,后台调...

  • 怎么管理接口文档

    1、利用swagger生成接口文档(json格式) 2、利用yapi进行展示 把用swagger生成的json格式...

  • 九、Spring MVC Json 数据交互

    Json数据交互 json数据格式在接口调用中、html页面中较常用,json格式比较简单,解析还比较方便。 比如...

  • Spring14-JSON

    为什么要使用json数据进行交互 json数据格式在接口调用中 html页面中比较常用,因为json格式比较简单,...

  • JSON数据交互

    一、为什么要进行json数据交互? json数据格式在接口调用中、html页面中较常用,json格式比较简单,解析...

网友评论

      本文标题:vue 调试接口 json 格式分解实践

      本文链接:https://www.haomeiwen.com/subject/luuvrktx.html