TP5后端,VUE前端请求聚合数据驾照题库

选择效果:
TP5后端,VUE前端请求聚合数据驾照题库演示效果

演示效果:
TP5后端,VUE前端请求聚合数据驾照题库演示效果

1: Vue 配置: /config/index.js

'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')

module.exports = {
   
  dev: {
   

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
   
      '/api_1': {
   
        target:'http://www.chaxun.com/joke', // 你请求的第三方接口
        changeOrigin:true,  // 在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样服务端和服务端进行数据的交互就不会有跨域问题
        pathRewrite:{
          // 路径重写,
          '^/api_1': '/api_1'       // 替换target中的请求地址,也就是说以后你在请求 target 的地址的时候直接写成 /api_1 即可。
        }
      },
      '/api_2': {
   
        target: 'http://www.chaxun.com/constellation',
        changeOrigin: true,
        pathRewrite: {
   
          '^/api_2': '/api_2'
        }
      },
      '/api_3': {
   
        target: 'http://www.chaxun.com/weather',
        changeOrigin: true,
        pathRewrite: {
   
          '^/api_3': '/api_3'
        }
      },
      '/api_4': {
   
        target: 'http://www.chaxun.com/news',
        changeOrigin: true,
        pathRewrite: {
   
          '^/api_4': '/api_4'
        }
      },
      '/api_5': {
   
        target: 'http://www.chaxun.com/videos',
        changeOrigin: true,
        pathRewrite: {
   
          '^/api_5': '/api_5'
        }
      },
      '/api_6': {
   
        target: 'http://www.chaxun.com/driverlicense',
        changeOrigin: true,
        pathRewrite: {
   
          '^/api_6': '/api_6'
        }
      }
    },

    // Various Dev Server settings
    host: '0.0.0.0', // can be overwritten by process.env.HOST
    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

    // Use Eslint Loader?
    // If true, your code will be linted during bundling and
    // linting errors and warnings will be shown in the console.
    useEslint: true,
    // If true, eslint errors and warnings will also be shown in the error overlay
    // in the browser.
    showEslintErrorsInOverlay: false,

    /**
     * Source Maps
     */

    // https://webpack.js.org/configuration/devtool/#development
    devtool: 'cheap-module-eval-source-map',

    // If you have problems debugging vue-files in devtools,
    // set this to false - it *may* help
    // https://vue-loader.vuejs.org/en/options.html#cachebusting
    cacheBusting: true,

    cssSourceMap: true
  },

  build: {
   
    // Template for index.html
    index: path.resolve(__dirname, '../dist/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',

    /**
     * Source Maps
     */

    productionSourceMap: true,
    // https://webpack.js.org/configuration/devtool/#production
    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],

    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  }
}

2: Vue 页面代码: Api6.vue 文件

<template>
    <div class="driver-license">
        <!--
1 : 请求结果如下:
{
   
    "error_code": 0,
    "reason": "ok",
    "result": [
        {
   
            "id": 12,
            "question": "这个标志是何含义?",//问题
            "answer": "4",//答案
            "item1": "前方40米减速",//选项,当内容为空时表示判断题正确选项
            "item2": "最低时速40公里",//选项,当内容为空时表示判断题错误选项
            "item3": "限制40吨轴重",
            "item4": "限制最高时速40公里",
            "explains": "限制最高时速40公里:表示该标志至前方限制速度标志的路段内,机动车行驶速度不得超过标志所示数值。此标志设在需要限制车辆速度的路段的起点。以图为例:限制行驶时速不得超过40公里。",//答案解释
            "url": "http://images.juheapi.com/jztk/c1c2subject1/12.jpg"//图片url
        },
        {
   
			"id":"357",
			"question":"驾驶人违反交通运输管理法规发生重大事故使公私财产遭受重大损失的可能处3年以下徒刑或拘役。",
			"answer":"1",
			"item1":"正确",
			"item2":"错误",
			"item3":"",
			"item4":"",
			"explains":"《中华人民共和国刑法》第一百三十三条:违反交通运输管理法规,因而发生重大事故,致人重伤、死亡或者使公私财产遭受重大损失的,处三年以下有期徒刑或者拘役。",
			"url":""
		},
    ]
}

    参数说明
名称	    必填	    类型	        说明
key	是	    string	您申请的appKey
subject	    是	        int	        选择考试科目类型,1:科目14:科目4
model	    是	        string	    驾照类型,可选择参数为:c1,c2,a1,a2,b1,b2;当subject=4时可省略
testType	否	        string  	测试类型,rand:随机测试(随机100个题目),order:顺序测试(所选科目全部题目)

    思路:
    1: 直接网上找一找,12123 里面看看选择题目的样式 【 头, 左边, 右边, 右边图片居中, 左边选项有间隔 】
    2: 当 json 里面 item3, item4 为空的时候,它是判断题
    3:这道题目点击了一次答案后,就不能再点击了 answeredArr, 把每次回答过的题号添加到该数组,每次点击的时候, answeredArr.indexOf(index) > -1 即存在, 在点击的时候,顺便把正确答案传入
    4: 驾照类型,科目类型,测试类型 【 当选择科目类型为 4(即科目4) 的时候 驾照类型就无关紧要了 】
    5:没有提交类型的话,就默认是C1, 科目一 100 题目
    6: 选择类型的时候,选不选都可以默认,不管是选择了做题类型还是没有选择
    7:错题重现 (做错的时候,添加进去)
    8:如果做错了,就把错题添加到错题的数组里面
    9: 做了题目就显示答案,不管对还是错,错的红色,对的绿色
    10: 选完科目的时候,把对的、错的场次清掉
         -->

        <el-card :span="12">
            <div class="sub-selection">

                <el-select v-model="licenseType" placeholder="驾照类型" class="licenseType" :disabled="licenseTypeDisable">
                    <el-option v-for="licenseTp in licenseTps" :key="licenseTp.id" :label="licenseTp.name" :value="licenseTp.name"></el-option>
                </el-select>

                <el-select v-model="subNmb" placeholder="选择科目" class="subNmb" :change="subNmbFn(subNmb)">
                    <el-option v-for="sub in subjects" :key="sub.id" :label="sub.name" :value="sub.id"></el-option>
                </el-select>

                <el-select v-model="doType" placeholder="做题类型" class="doType">
                    <el-option v-for="doTp in doTps" :key="doTp.id" :label="doTp.name" :value="doTp.rand"></el-option>
                </el-select>

                <el-button type="success" class="checkTestBtn" @click="checkDoFn">确定</el-button>

                <el-button type="warning" class="checkTestBtn" @click="errorExerciseFn">错题重现{
   {
    errDataArr.length }}</el-button>
            </div>
        </el-card>

        <el-card :span="12" v-show="normalEle">

            <h1>{
   {
    typeTitle }}</h1>

            <div class="item" v-for="(item, index) in dataArr" :key="index">
                <h3 class="title">{
   {
    index + 1 }}: {
   {
    item.question }}</h3>
                <div class="answers">
                    <div class="left">
                        <p class="answer" @click.once="chooseFn(index, 1, item.answer, $event.target, item.id)">{
   {
    item.item1 }}</p>
                        <p class="answer" @click.once="chooseFn(index, 2, item.answer, $event.target, item.id)">{
   {
    item.item2 }}</p>
                        <div v-if="item.item3 !=''">
                            <p class="answer" @click.once="chooseFn(index, 3, item.answer, $event.target, item.id)">{
   {
    item.item3 }}</p>
                        </div>
                        <div v-if="item.item4 !=''">
                            <p class="answer" @click.once="chooseFn(index, 4, item.answer, $event.target, item.id)">{
   {
    item.item4 }}</p>
                        </div>
                    </div>
                    <div class="right">
                        <img :src="item.url != '' ? item.url: '/static/imgs/default_null.png'" :alt="item.id" width="200">
                    </div>
                </div>

                <div :class="'judgeAns' + item.id" class="judgeAns">
                    <p><span>您的回答: </span> <span>正确</span></p>
                </div>

                <div :class="'showAnswer' + item.id" class="showAnswer">
                    <span>答案解释: </span>
                    <span>{
   {
    item.explains }}</span>
                </div>
                <br /><br />
            </div>

            <el-card :span="12" class="submitCard">
                <el-button type="primary" round @click="submitFn">提交</el-button>
            </el-card>

        </el-card>

        <el-card v-show="errEle">
            <h1>错题重现: {
   {
    errDataArr.length }}</h1>

            <div class="item" v-for="(item, index) in errDataArr" :key="index">
                <h3 class="title">{
   {
    index + 1 }}: {
   {
    item.question }}</h3>
                <div class="answers">
                    <div class="left">
                        <p class="answer" @click.once="errChooseFn(1, item.answer, $event.target, item.id)">{
   {
    item.item1 }}</p>
                        <p class="answer" @click.once="errChooseFn(2, item.answer, $event.target, item.id)">{
   {
    item.item2 }}</p>
                        <div v-if="item.item3 !=''">
                            <p class="answer" @click.once="errChooseFn(3, item.answer, $event.target, item.id)">{
   {
    item.item3 }}</p>
                        </div>
                        <div v-if="item.item4 !=''">
                            <p class="answer" @click.once="errChooseFn(4, item.answer, $event.target, item.id)">{
   {
    item.item4 }}</p>
                        </div>
                    </div>
                    <div class="right">
                        <img :src="item.url != '' ? item.url: '/static/imgs/default_null.png'" :alt="item.id" width="200">
                    </div>
                </div>

                <div :class="'errJudgeAns' + item.id" class="errJudgeAns">
                    <p class="bolderFont"></p>
                </div>

                <div :class="'errShowAnswer' + item.id" class="errShowAnswer">

                    <el-button type="success" round @click="removeErr(item.id)">移除错题</el-button>

                    <p class="explains">
                        <span>答案解释: </span>
                        <span>{
   {
    item.explains }}</span>
                    </p>
                </div>

                <br /><br />
            </div>

            <el-card :span="12" class="submitCard">
                <el-button type="primary" round @click="errSubmitFn">提交</el-button>
            </el-card>

        </el-card>

    </div>
</template>

<script>

export default {
   
    name: 'driverLicense',
    mounted: function () {
   
        this.getData()
    },
    data () {
   
        return {
   
            errEle: false, // 错误元素
            normalEle: true, // 正常元素
            apiUrl: '/api_6', // 接口地址
            dataArr: [], // 请求返回的数据数组
            errDataArr: [], // 错误的数据数组
            errDataIdArr: [], // 错误的题目ID数组
            answering: true, //
            answeredArr: [], // 回答过的数组
            errAnsweredArr: [], // 错题回答过的数组
            errRightNmb: 0, // 错题重现做对的 number
            errRightIdArr: [], // 错题重现做对的 Id 数组
            errErrNmb: 0, // 错题重现又错的 number
            errErrIdArr: [], // 错题重现做对的 Id 数组
            answerIndex: 0, // 用户在回答当前的题目
            subNmb: '', // 科目几的值默认是1
            subjects: [ // 科目几的选择
                {
    id: 1, name: '科目一' },
                {
    id: 4, name: '科目四' }
            ],
            licenseType: '', // 驾照类型
            licenseTypeDisable: false, // 驾照类型是否可供选择(如果选择的科目四就不能选择)
            licenseTps: [ // 驾照类型选项 c1,c2,a1,a2,b1,b2
                {
   id: 1, name: 'A1'},
                {
   id: 2, name: 'A2'},
                {
   id: 3, name: 'B1'},
                {
   id: 4, name: 'B2'},
                {
   id: 5, name: 'C1'},
                {
   id: 6, name: 'C2'}
            ],
            doType: '', // 做题类型
            doTps: [
                {
    id: 1, name: '随机100题', rand: true },
                {
    id: 2, name: '顺序做题', rand: false }
            ],
            typeTitle: 'C1:科目一随机100题考试(默认)' // 题目类型
        }
    },
    methods: {
   
        // chooseFn(index, userAns, referenceAns, ele) :: index: 题目下标;  userAns: 用户的答案; referenceAns: 参考答案; ele: 该元素本身; id: 题目的自身ID
        chooseFn: function (index, userAns, referenceAns, ele, itemId) {
   
            // 遍历数组如果有这个 index, 就不改变样式了[ 变向点击失效 ]
            let judgeEle = document.getElementsByClassName('judgeAns' + itemId)[0]
            judgeEle.style.display = 'block'
            document.getElementsByClassName('showAnswer' + itemId)[0].style.display = 'block'
            let judgeEleP = judgeEle.getElementsByTagName('p')[0]
            if (this.answeredArr.indexOf(itemId) > -1) 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值