【I Love Vue 】 Day 28 爱荷华博弈任务(九) - 结算画面

离完成就只差最後一个结算画面了...
咱们废话不多说,直接继续开发下去。


结算画面

先来看看昨天完成的测试画面:
https://ithelp.ithome.com.tw/upload/images/20201012/20115941VGlOPyrXwm.jpg

这边有两种设计方式进入到结算的画面:

  • 当游戏到达执行次数,直接进入结算画面
  • 当达到执行次数上限,按下结算後进入结算画面

我们选择第二个方式进行设计。
所以在这部分我们要完成的是,当达到上限时点击结算跳到结算画面。
并在结算画面上显示测验的讯息。

先来设计让画面可以跳转到结算画面

  1. 修改 test.vue :
    template:
<template>
  <userInfo></userInfo>
  <div id="starting-game">
    <table>
      <thead>
        <tr>
          <th colspan="4">剩下游戏次数:{{ times }}</th>
        </tr>
        <tr>
          <th colspan="4">目前积分:{{ getPoint() }}</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>
            <card :id="1" @getcard="increase"></card>
          </td>
          <td>
            <card :id="2" @getcard="increase"></card>
          </td>
          <td>
            <card :id="3" @getcard="increase"></card>
          </td>
          <td>
            <card :id="4" @getcard="increase"></card>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <div>
    <table id="op_table" cellpadding="10" border="1">
      <thead>
        <tr>
          <th>
            <router-link to="/">回首页</router-link>
          </th>
          <th>
            <div v-show="isover">
              <router-link to="/settlement">结算</router-link>
            </div>
          </th>
        </tr>
      </thead>
    </table>
  </div>
</template>

在画面上新增一个栏位,用来让受测者知道剩余次数还剩多少
2. 接下来修改 test.vue 里面的 increase():

increase(card) {
      if (this.times > 0) {
        store.state.point = store.state.point + card.dividend;
        store.state.gameTimes--;
        this.times = store.state.gameTimes;
        var historyData = {
          point : this.getPoint(),
          id : card.id,
          dividend : card.dividend
        };
        store.state.history[store.state.history.length] = historyData
        if (this.times == 0) {
          this.isover = true;
        }
      } else {
        alert('已完成测验,请点击 "结算" 观看结果');
      }
    },

我们把受测的历史资料记录到history里面,
并且用isover来记录是否已经完成测验。

  1. test.vuemounted 设定预设值:
mounted: function () {
    
    this.times = store.state.gameTimes;
    if(this.times > 0 ){
      this.isover = false;
    }
    else{
      this.isover = true;
    }
  },
  1. test.vue中设定变数:
data: function () {
    return {
      times: 0,
      isover: false,
    };
  },

到这边完成之後,当受测人员完成测验之後,可以按下 结算 进入结算画面

  1. 在设计结算画面之前我们先到router.js 新增我们的路由
{
        path : '/settlement',
        component : settlement
      },
  1. 刚刚用到的全域变数加入到vuex.jsstatus里面:
history:[],
point:2000,

设定初始分数point 2000分,及一个用来记录所有操作的阵列history

  1. 开始来设计结算画面 settlement.vue:
    template:
<template>
<div>
<table>
    <tbody>
        <tr>
            <th>
                姓名:
            </th>
            <td>
                {{name}}
            </td>
        </tr>
        <tr>
            <th>
                年纪:
            </th>
            <td>
                {{age}}
            </td>
        </tr>
        <tr>
            <th>
                性别:
            </th>
            <td>
                {{sex}}
            </td>
        </tr>
    </tbody>
</table>
</div>
<div>
    <table cellpadding="10px" border="1px">
        <thead>
            <th>编号</th>
            <th>牌组</th>
            <th>积分</th>
            <th>总分</th>
        </thead>
        <tbody>
            <tr v-for="(item, index) in history" :key="index" >
                <td>{{index+1}}</td>
                <td>第{{item.id}}副牌</td>
                <td>{{item.dividend}}</td>
                <td>{{item.point}}</td>
            </tr>
        </tbody>
    </table>

</div>

</template>

在上面显示基本讯息,再用v-for把我们都操作纪录都显示在table上。

script:

<script>
import store from "../vuex"; // 引用 store
export default {
  name: "settlement",
  store:store,
  components: {
  },
  data:function(){
      return{
          name: "",
          sex:"",
          age:0,
          history:[],
      }
  },
  mounted:function(){
      this.name = store.state.userInfo.name
      this.sex = store.state.userInfo.sex
      this.age = store.state.userInfo.age
      this.history = store.state.history
  }
};
</script>

mounted 设定资料

到这边我们就大功告成拉。


结语

setting.vue部分 的 姓名 及 年龄 的事件应该改用 @change
这边我当时写错没有发现,可以到git上面看看我有做那些修改。

到这篇就差不多完结了,下一篇会稍微Demo一下成品以及有哪些可以修改的部分

git : https://github.com/kyminjob72/iowa_gambling_task/tree/version05


<<:  (Day 29) DevOps Challenges

>>:  IT铁人第28天 Elasticsearch 使用python查询资料 Aggregations:Sum/Value Count

Leetcode 挑战 Day 03 [20. Valid Parentheses]

20. Valid Parentheses 今天要挑战是第二十题合法括号,这题也是非常经典而且有趣的...

Day 16 for-each

在写for回圈的时候,每次都需要输入for回圈的条件式,宣告int I, i<某数, i++ ...

Day11 Internet-Protocol

在开发网页服务器之前,必须了解网际网路资料传输的基本背景知识。今天的内容是简单介绍常被忽略的网际网路...

[Day 9]从零开始学习 JS 的连续-30 Days---物件

宣告变数的资料型别--物件 1.数值( Number ) 2.字串( String ) 3.布林值(...

CLI名词解释

命令列介面命令列介面(英语:Command-Line Interface,缩写:CLI)是在图形使用...