亚州天堂爱爱,做爱视频国产全过程在线观看,成人试看30分钟免费视频,女人无遮挡裸交性做爰视频网站

? ? ?

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

部分項目截圖

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

開發試題分類頁面

新增home頁面

pages目錄下新建home目錄,并添加4個文件,如圖所示:

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

其中: home.js

// pages/home/home.jsPage({ data: {? }, onLoad: function (options) {? }, toTestPage: function(e){   let testId = e.currentTarget.dataset['testid'];   wx.navigateTo({     url: '../test/test?testId=' testId   }) }})

home.wxml

<!--pages/home/home.wxml--><view class="page"> <view class="page-title">請選擇試題:</view> <view class="flex-box">   <view class="flex-item"><view class="item bc_green" bindtap="toTestPage" data-testId="18">IT知識</view></view>   <view class="flex-item"><view class="item bc_red" bindtap="toTestPage" data-testId="15">游戲知識</view></view>   <view class="flex-item"><view class="item bc_yellow" bindtap="toTestPage" data-testId="21">體育知識</view></view>   <view class="flex-item"><view class="item bc_blue" bindtap="toTestPage" data-testId="27">動物知識</view></view>   <view class="flex-item item-last"><view class="item bc_green" bindtap="toTestPage" data-testId="0">綜合知識</view></view> </view></view>?

home.json

{ "navigationBarTitleText": "試題分類", "usingComponents": {}}

home.wxss

/* pages/home/home.wxss */.page-title { padding-top: 20rpx; padding-left: 40rpx; font-size: 16px;}.flex-box { display: flex; align-items:center; flex-wrap: wrap; justify-content: space-between; padding: 20rpx; box-sizing:border-box;}.flex-item { width: 50%; height: 200rpx; padding: 20rpx; box-sizing:border-box;}.item { width:100%; height:100%; border-radius:8rpx; display: flex; align-items:center; justify-content: center; color: #fff;}.item-last { flex: 1;}

修改app.json,注意:pages/home/home一定要放到pages數組的最前,以成為首頁。

{ "pages": [   "pages/home/home",   "pages/index/index",   "pages/logs/logs", ], "window": {   "backgroundTextStyle": "light",   "navigationBarBackgroundColor": "#fff",   "navigationBarTitleText": "WeChat",   "navigationBarTextStyle": "black" }, "style": "v2", "sitemapLocation": "sitemap.json"}

修改app.wxss,定義全局樣式

/**app.wxss**/.container { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 200rpx 0; box-sizing: border-box;} ?.bc_green{   background-color: #09BB07;}.bc_red{   background-color: #F76260;}.bc_blue{   background-color: #10AEFF;}.bc_yellow{   background-color: #FFBE00;}.bc_gray{   background-color: #C9C9C9;}

運行結果

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

開發試題展示功能

新增test頁面

pages目錄下新建test目錄,并添加4個文件,如圖所示:

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

修改test.js

// pages/test/test.jsPage({? /**   * 頁面的初始數據   */ data: {   test_id:0 },? /**   * 生命周期函數--監聽頁面加載   */ onLoad: function (options) {   this.setData({test_id:options.testId}) } })?

修改test.wxml

<!--pages/test/test.wxml--><text>我是{{test_id}}</text>?

運行結果

在試題分類頁點擊某一分類,跳轉到試題頁,試題頁顯示分類id

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

Mock試題數據

項目目錄下新增data目錄,data目錄新增json.js,存放我們的試題模擬數據。

var json = { "18": [ { "question": "This mobile OS held the largest market share in 2012.?", "option": { "A": "iOS", "B": "Android", "C": "BlackBerry", "D": "Symbian" }, "true": "A", "scores": 10, "checked": false }, { "question": "This mobile OS held the largest market share in 2012.?", "option": { "A": "iOS", "B": "Android", "C": "BlackBerry", "D": "Symbian" }, "true": "A", "scores": 10, "checked": false } ], "0": [ { "question": "This mobile OS held the largest market share in 2012.?", "option": { "A": "iOS", "B": "Android", "C": "BlackBerry", "D": "Symbian" }, "true": "A", "scores": 10, "checked": false }, { "question": "This mobile OS held the largest market share in 2012.?", "option": { "A": "iOS", "B": "Android", "C": "BlackBerry", "D": "Symbian" }, "true": "A", "scores": 10, "checked": false } ]}module.exports = { questionList: json}

修改app.js

var jsonList = require('data/json.js');App({... }, globalData: { questionList: jsonList.questionList, // 拿到答題數據 // questionList:{}, quizCategory:{ "0": "綜合知識", "18": "IT知識", "21": "體育知識", "15": "游戲知識", "27":"動物知識", } }})

修改test.js

// import he from "he";var app = getApp();Page({ data: { bIsReady: false, // 頁面是否準備就緒 index: 0, // 題目序列 chooseValue: [], // 選擇的答案序列 }, shuffle(array) { return array.sort(() => Math.random() - 0.5); }, /** * 生成一個從 start 到 end 的連續數組 * @param start * @param end */ generateArray: function (start, end) { return Array.from(new Array(end 1).keys()).slice(start) }, onLoad: function (options) { wx.setNavigationBarTitle({ title: options.testId }) // 動態設置導航條標題 this.setData({ questionList: app.globalData.questionList[options.testId], // 拿到答題數據 testId: options.testId // 課程ID }) let countArr = this.generateArray(0, this.data.questionList.length - 1); // 生成題序 this.setData({ bIsReady: true, shuffleIndex: this.shuffle(countArr).slice(0, countArr.length) // 生成隨機題序 [2,0,3] 并截取num道題 }) }, /* * 單選事件 */ radioChange: function (e) { console.log('checkbox發生change事件,攜帶value值為:', e.detail.value) this.data.chooseValue[this.data.index] = e.detail.value; console.log(this.data.chooseValue); }, /* * 退出答題 按鈕 */ outTest: function () { wx.showModal({ title: '提示', content: '你真的要退出答題嗎?', success(res) { if (res.confirm) { console.log('用戶點擊確定') wx.switchTab({ url: '../home/home' }) } else if (res.cancel) { console.log('用戶點擊取消') } } }) }, /* * 下一題/提交 按鈕 */ nextSubmit: function () { // 如果沒有選擇 if (this.data.chooseValue[this.data.index] == undefined) { wx.showToast({ title: '請選擇至少一個答案!', icon: 'none', duration: 2000, success: function () { return; } }) return; } // 判斷是不是最后一題 if (this.data.index < this.data.shuffleIndex.length - 1) { // 渲染下一題 this.setData({ index: this.data.index 1 }) } else { console.log('ok') } }})

test.wxml

<!--pages/test/test.wxml--><view wx:if="{{bIsReady}}" class="page"> <!--標題--> <view class='page__hd'> <view class="page__title"> {{index 1}}、{{questionList[shuffleIndex[index]].question}} ({{questionList[shuffleIndex[index]].scores}}分) </view> </view> <!--內容--> <view class="page__bd"> <radio-group class="radio-group" bindchange="radioChange"> <label class="radio my-choosebox" wx:for="{{questionList[shuffleIndex[index]].option}}" wx:for-index="key" wx:for-item="value"> <radio value="{{key}}" checked="{{questionList[shuffleIndex[index]].checked}}"/>{{key}}、{{value}} </label> </radio-group> </view> <!--按鈕--> <view class='page_ft'> <view class='mybutton'> <button bindtap='nextSubmit' wx:if="{{index == questionList.length-1}}">提交</button> <button bindtap='nextSubmit' wx:else>下一題</button> <text bindtap='outTest' class="toindex-btn">退出答題</text> </view> </view></view>

test.wxss

/* pages/test/test.wxss */.page { padding: 20rpx;}.page__bd { padding: 20rpx;}.my-choosebox { display: block; margin-bottom: 20rpx;}.toindex-btn { margin-top: 20rpx; display:inline-block; line-height:2.3; font-size:13px; padding:0 1.34em; color:#576b95; text-decoration:underline; float: right;}

項目運行結果:

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

請求真實數據

修改test.js

getQuestions(testId) { // 顯示標題欄加載效果 wx.showNavigationBarLoading(); wx.request({ // url: 'https://opentdb.com/api.php?amount=10&difficulty=easy&type=multiple&category=' testId, url: 'https://opentdb.com/api.php?amount=10&difficulty=easy&type=multiple&category=' testId, method: "GET", success: res => { if (res.data.response_code === 0) { this.setData({ questionList: this.parseQuestion(res.data.results), // 拿到答題數據 testId: testId // 課程ID }) console.log(this.data.questionList); app.globalData.questionList[testId] = this.data.questionList let count = this.generateArray(0, this.data.questionList.length - 1); // 生成題序 this.setData({ bIsReady: true, shuffleIndex: this.shuffle(count).slice(0, 10) // 生成隨機題序 [2,0,3] 并截取num道題 }) } else { ; } // 停止加載效果 wx.stopPullDownRefresh(); wx.hideNavigationBarLoading(); }, fail: err => { // 停止加載效果 wx.stopPullDownRefresh(); wx.hideNavigationBarLoading(); } }); }, onLoad: function (options) { this.getQuestions(options.testId) console.log(options); wx.setNavigationBarTitle({ title: app.globalData.quizCategory[options.testId] }) // 動態設置導航條標題 },

解析返回的數據:

// 主題列表數據模型 parseQuestion(aList) { let aTopicList = []; if (!aList || (aList && !Array.isArray(aList))) { aList = []; } aTopicList = aList.map(oItem => { const answers = [oItem.correct_answer, oItem.incorrect_answers].flat() let optionArr = ['A', 'B', 'C', 'D'] let options = {} let optionArrShuffle = this.shuffle(optionArr) for (let i = 0; i < answers.length; i ) { options[optionArr[i]] = String(answers[i]); } const ordered_options = {}; Object.keys(options).sort().forEach(function (key) { ordered_options[key] = options[key]; }); return { "question": String(oItem.question), // id "scores": 10, "checked": false, "option": ordered_options, "true": optionArr[0] }; }); return aTopicList; },

這里解析的原因是,接口返回的json數據和我們自己設計的數據格式略有不同,我們要轉換成自己的數據格式: 接口返回的數據格式:

{ "response_code": 0, "results": [{ "category": "Science: Computers", "type": "multiple", "difficulty": "easy", "question": "The numbering system with a radix of 16 is more commonly referred to as ", "correct_answer": "Hexidecimal", "incorrect_answers": ["Binary", "Duodecimal", "Octal"] }, { "category": "Science: Computers", "type": "multiple", "difficulty": "easy", "question": "This mobile OS held the largest market share in 2012.", "correct_answer": "iOS", "incorrect_answers": ["Android", "BlackBerry", "Symbian"] }, { "category": "Science: Computers", "type": "multiple", "difficulty": "easy", "question": "How many values can a single byte represent?", "correct_answer": "256", "incorrect_answers": ["8", "1", "1024"] }, { "category": "Science: Computers", "type": "multiple", "difficulty": "easy", "question": "In computing, what does MIDI stand for?", "correct_answer": "Musical Instrument Digital Interface", "incorrect_answers": ["Musical Interface of Digital Instruments", "Modular Interface of Digital Instruments", "Musical Instrument Data Interface"] }, { "category": "Science: Computers", "type": "multiple", "difficulty": "easy", "question": "In computing, what does LAN stand for?", "correct_answer": "Local Area Network", "incorrect_answers": ["Long Antenna Node", "Light Access Node", "Land Address Navigation"] }]}

我們自己的數據格式:

var json = { "18": [ { "question": "This mobile OS held the largest market share in 2012.?", "option": { "A": "iOS", "B": "Android", "C": "BlackBerry", "D": "Symbian" }, "true": "A", "scores": 10, "checked": false }, { "question": "This mobile OS held the largest market share in 2012.?", "option": { "A": "iOS", "B": "Android", "C": "BlackBerry", "D": "Symbian" }, "true": "A", "scores": 10, "checked": false } ], "0": [ { "question": "This mobile OS held the largest market share in 2012.?", "option": { "A": "iOS", "B": "Android", "C": "BlackBerry", "D": "Symbian" }, "true": "A", "scores": 10, "checked": false }, { "question": "This mobile OS held the largest market share in 2012.?", "option": { "A": "iOS", "B": "Android", "C": "BlackBerry", "D": "Symbian" }, "true": "A", "scores": 10, "checked": false } ]}

注意:

開發期間:不校驗合法域名,web-view…..這里不要勾選。

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

引入第三方庫

細心的朋友可能會發現,有些題目中有亂碼,如下圖所示':

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

有一個很好的第三方庫He可以處理這個問題。

我們需要使用npm導入一個第三方庫處理這個問題,大家會學習到在小程序開發中如何使用npm引入第三方庫。

項目根目錄下新建package.json文件

{ "name": "wechatanswer-master", "version": "1.0.0", "description": "答題類微信小程序", "main": "app.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "repository": { "type": "git", "url": "https://gitee.com/kamiba/my_quiz_wechat_app.git" }, "author": "", "license": "ISC", "dependencies": { "he": "^1.2.0" }}

2、執行npm install –production xxx,這個xxx就是你想使用的npm 包。此時在當前文件夾下會生成一個node_modules文件夾。PS:此處請務必使用–production選項,可以減少安裝一些業務無關的 npm 包,從而減少整個小程序包的大小。

npm install --production he

3、在微信開發者工具–>工具–>構建npm,此時會生成一個miniprogram_npm文件夾。

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

4、構建完成后就可以使用 npm 包了。首先把使用npm模塊勾起來,然后在js文件中引入即可。

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

然后修改test.js

import he from "he"; // 主題列表數據模型 parseQuestion(aList) { let aTopicList = []; if (!aList || (aList && !Array.isArray(aList))) { aList = []; } aTopicList = aList.map(oItem => { const answers = [oItem.correct_answer, oItem.incorrect_answers].flat() let optionArr = ['A', 'B', 'C', 'D'] let options = {} let optionArrShuffle = this.shuffle(optionArr) for (let i = 0; i < answers.length; i ) { options[optionArr[i]] = he.decode(String(answers[i])); } const ordered_options = {}; Object.keys(options).sort().forEach(function (key) { ordered_options[key] = options[key]; }); return { "question": he.decode(String(oItem.question)), // id "scores": 10, "checked": false, "option": ordered_options, "true": optionArr[0] }; }); return aTopicList; },

上面和以前有三處修改

import he from "he";options[optionArr[i]] = he.decode(String(answers[i]));"question": he.decode(String(oItem.question)),

計算用戶得分,記錄錯題

修改test.js

Page({ data: { bIsReady: false, // 頁面是否準備就緒 index: 0, // 題目序列 chooseValue: [], // 選擇的答案序列 totalScore: 100, // 總分 wrong: 0, // 錯誤的題目數量 wrongListSort: [], // 錯誤的題目集合 },

/* * 下一題/提交 按鈕 */ nextSubmit: function () { // 如果沒有選擇 if (this.data.chooseValue[this.data.index] == undefined) { wx.showToast({ title: '請選擇至少一個答案!', icon: 'none', duration: 2000, success: function () { return; } }) return; } // 判斷答案是否正確 this.chooseError(); // 判斷是不是最后一題 if (this.data.index < this.data.shuffleIndex.length - 1) { // 渲染下一題 this.setData({ index: this.data.index 1 }) } else { let wrongListSort = JSON.stringify(this.data.wrongListSort); let chooseValue = JSON.stringify(this.data.chooseValue); let shuffleIndex = JSON.stringify(this.data.shuffleIndex); console.log('wrongListSort:' wrongListSort) wx.navigateTo({ url: '../results/results?totalScore=' this.data.totalScore '&shuffleIndex=' shuffleIndex '&chooseValue=' chooseValue '&wrongListSort=' wrongListSort '&testId=' this.data.testId }) // 設置緩存 var logs = wx.getStorageSync('logs') || [] let logsList = { "date": Date.now(), "testId": app.globalData.quizCategory[this.data.testId], "score": this.data.totalScore } logs.unshift(logsList); wx.setStorageSync('logs', logs); } }, /** 錯題處理*/ chooseError: function () { var trueValue = this.data.questionList[this.data.shuffleIndex[this.data.index]]['true']; var chooseVal = this.data.chooseValue[this.data.index]; console.log('選擇了' chooseVal '答案是' trueValue); if (chooseVal.toString() != trueValue.toString()) { console.log('錯了'); this.data.wrong ; this.data.wrongListSort.push(this.data.index); this.setData({ totalScore: this.data.totalScore - this.data.questionList[this.data.shuffleIndex[this.data.index]]['scores'] // 扣分操作 }) } },

實現結果展示頁面

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

pages目錄下新增page—results

results.js

// pages/results/results.jsvar app = getApp();Page({ data: { totalScore: null, // 分數 shuffleIndex: [], // 錯誤的題數-亂序 wrongListSort: [], // 錯誤的題數-正序 chooseValue: [], // 選擇的答案 remark: ["好極了!你很棒棒哦", "哎喲不錯哦", "別灰心,繼續努力哦!"], // 評語 modalShow: false }, onLoad: function (options) { console.log(options); wx.setNavigationBarTitle({ title: app.globalData.quizCategory[options.testId] }) // 動態設置導航條標題 let shuffleIndex = JSON.parse(options.shuffleIndex); let wrongListSort = JSON.parse(options.wrongListSort); let chooseValue = JSON.parse(options.chooseValue); this.setData({ totalScore: options.totalScore != "" ? options.totalScore : "無", shuffleIndex: shuffleIndex, wrongListSort: wrongListSort, chooseValue: chooseValue, questionList: app.globalData.questionList[options.testId], // 拿到答題數據 testId: options.testId // 課程ID }) console.log(this.data.chooseValue); }, // 查看錯題 toView: function () { // 顯示彈窗 this.setData({ modalShow: true }) }, // 返回首頁 toIndex: function () { wx.switchTab({ url: '../home/home' }) }})

results.json

{ "navigationBarTitleText": "WeChatTest", "usingComponents": { "wrong-modal":"/components/wrongModal/wrongModal" }}

results.wxml

<view class="page"> <!--標題--> <view class='page-head'> <view class="page-title"> 答題結束!您的得分為: </view> <!--分數--> <view class='page-score'> <text class="score-num">{{totalScore}}</text> <text class="score-text">分</text> </view> <text class="score-remark">{{totalScore==100?remark[0]:(totalScore>=80?remark[1]:remark[2])}}</text> <!-- 評價 --> </view> <!--查詢錯誤--> <view class='page-footer'> <view class="wrong-view" wx:if="{{wrongListSort.length > 0}}"> <text>錯誤的題數:</text> <text wx:for="{{wrongListSort}}">[{{item-0 1}}]</text> 題 </view> <view class="wrong-btns"> <button type="default" bindtap="toView" hover-class="other-button-hover" class="wrong-btn" wx:if="{{wrongListSort.length > 0}}"> 點擊查看 </button> <button type="default" bindtap="toIndex" hover-class="other-button-hover" class="wrong-btn"> 返回首頁 </button> </view> </view> <wrong-modal modalShow="{{modalShow}}" shuffleIndex="{{shuffleIndex}}" wrongListSort="{{wrongListSort}}" chooseValue="{{chooseValue}}" questionList="{{questionList}}" testId="{{testId}}" ></wrong-modal></view>

results.wxss

/* pages/results/results.wxss */.page { padding: 20rpx;}.page-head { text-align: center;}.page-title {}.page-score { display: flex; justify-content: center; align-items: flex-end; padding-top:40rpx; padding-bottom:40rpx;}.score-num { font-size:100rpx;}.page-footer { margin-top:60rpx; text-align: center;}.wrong-btns { display:flex; align-items:center; justify-content:center; margin-top: 60rpx;}.wrong-btn { margin-left:20rpx; margin-right:20rpx; height:70rpx; line-height:70rpx; font-size:14px;}

實現錯題查看頁面

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

項目目錄下新增components目錄。components目錄下新增wrongModal目錄,wrongModal目錄下新增page—wrongModal

wrongModal.js

// components/wrongModal/wrongModal.jsComponent({ /** * 組件的屬性列表 */ properties: { // 是否顯示 modalShow: { type: Boolean, value: false }, // 題庫 questionList: { type: Array, value: [] }, // 課程ID testId: { type: String, value: '101-1' }, // 題庫亂序index shuffleIndex: { type: Array, value: [] }, // 錯題題數-正序 wrongListSort: { type: Array, value: [] }, // 選擇的答案 chooseValue: { type: Array, value: [] } }, /** * 組件的初始數據 */ data: { index: 0 // wrongList的index }, /** * 組件所在頁面的生命周期 */ pageLifetimes: { show: function () { // 頁面被展示 console.log('show') console.log(this.data.questionList) // console.log(this.data.wrongList) }, hide: function () { // 頁面被隱藏 }, resize: function (size) { // 頁面尺寸變化 } }, /** * 組件的方法列表 */ methods: { // 下一題 next: function(){ if (this.data.index < this.data.wrongListSort.length - 1){ // 渲染下一題 this.setData({ index: this.data.index 1 }) } }, // 關閉彈窗 closeModal: function(){ this.setData({ modalShow: false }) }, // 再來一次 again: function(){ wx.reLaunch({ url: '../test/test?testId=' this.data.testId }) }, // 返回首頁 toIndex: function () { wx.reLaunch({ url: '../home/home' }) }, }})

wrongModal.json

{ "component": true, "usingComponents": {}}

wrongModal.wxml

<!--components/wrongModal/wrongModal.wxml--><view class="modal-page" wx:if="{{modalShow}}"> <view class="modal-mask" bindtap="closeModal"></view> <!-- 內容 --> <view class="modal-content"> <view class="modal-title"> 題目: {{questionList[shuffleIndex[wrongListSort[index]]].question}} </view> <view class="modal-body"> <radio-group class="radio-group" bindchange="radioChange"> <label class="radio my-choosebox" wx:for="{{questionList[shuffleIndex[wrongListSort[index]]].option}}" wx:for-index="key" wx:for-item="value"> <radio disabled="{{true}}" value="{{key}}" checked="{{questionList[shuffleIndex[wrongListSort[index]]].checked}}"/>{{key}}、{{value}} </label> </radio-group> </view> <!-- 答案解析 --> <view class="modal-answer"> <text class="answer-text wrong-answer"> 您的答案為 {{chooseValue[wrongListSort[index]]}} </text> <text class="answer-text true-answer"> 正確答案為 {{questionList[shuffleIndex[wrongListSort[index]]]['true']}} </text> </view> <!-- 操作按鈕 --> <view class="modal-button"> <view wx:if="{{index == wrongListSort.length-1}}" class="modal-btns"> <button bindtap='again' class="modal-btn">再來一次</button> <button bindtap='toIndex' class="modal-btn">返回首頁</button> </view> <button bindtap='next' wx:else class="modal-btn">下一題</button> </view> </view></view>

wrongModal.wxss

/* components/wrongModal/wrongModal.wxss */.modal-mask { position:fixed; width:100%; height:100%; top:0; left:0; z-index:10; background: #000; opacity: 0.5; overflow: hidden;}.modal-page { display:flex; align-items:center; justify-content:center; width:100%; height:100%; top:0; position:absolute; left:0;}.modal-content { width: 80%; min-height: 80%; background: #fff; border-radius: 8rpx; z-index:11; padding: 20rpx;}.modal-title { font-size: 14px;}.modal-body { padding: 20rpx;}.my-choosebox { display: block; margin-bottom: 20rpx; font-size: 14px;}.modal-answer { display: flex;}.answer-text { font-size: 14px; margin-right: 20rpx;}.modal-button { display: flex; align-items:center; justify-content:center; margin-top:60rpx;}.modal-btns { display: flex; align-items:center; justify-content:center;}.modal-btn { margin-left:20rpx; margin-right:20rpx; height:70rpx; line-height:70rpx; font-size:12px;}

實現成績記錄頁面

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

修改項目目錄下的app.json,增加底部導航欄

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

{ "pages": [ "pages/home/home", "pages/logs/logs", "pages/test/test", "pages/results/results", "pages/index/index" ], "window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "WeChat", "navigationBarTextStyle": "black" }, "tabBar": { "color": "#666666", "selectedColor": "#3cc51f", "borderStyle": "black", "backgroundColor": "#ffffff", "list": [ { "pagePath": "pages/home/home", "iconPath": "image/icon_component.png", "selectedIconPath": "image/icon_component_HL.png", "text": "答題" }, { "pagePath": "pages/logs/logs", "iconPath": "image/icon_API.png", "selectedIconPath": "image/icon_API_HL.png", "text": "記錄" } ] }, "sitemapLocation": "sitemap.json"}

項目目錄下新增image文件夾,并添加以下文件,具體文件請下載源碼獲取:

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

修改pages目錄下logs頁面

logs.js

//logs.jsconst util = require('../../utils/util.js')Page({ data: { logs: [], }, onShow: function() { this.setData({ logs: this.formatLogs() }) }, // 拿到緩存并格式化日期數據 formatLogs: function(){ let newList = []; (wx.getStorageSync('logs') || []).forEach(log => { if(log.date){ log['date'] = util.formatTime(new Date(log.date)); newList.push(log); } }) return newList; }})

logs.json

{ "navigationBarTitleText": "查看日志", "usingComponents": {}}

logs.wxml

<!--logs.wxml--><view class="page"> <view class="table" wx:if="{{logs.length>0}}"> <view class="tr bg-w"> <view class="th first">時間</view> <view class="th">試題</view> <view class="th ">得分</view> </view> <block wx:for="{{logs}}" wx:for-item="item"> <view class="tr"> <view class="td first">{{item.date}}</view> <view class="td">{{item.testId}}</view> <view class="td">{{item.score}}</view> </view> </block> </view> <view class="no-record" wx:else> <image src="/image/wechat.png" class="no-image"></image> <text class="no-text">沒有數據哦~</text> </view></view>

logs.wxss

.table { border: 0px solid darkgray; font-size: 12px;}.tr { display: flex; width: 100%; justify-content: center; height: 2rem; align-items: center;}.td { width:40%; justify-content: center; text-align: center;}.bg-w{ background: snow;}.th { width: 40%; justify-content: center; background: #3366FF; color: #fff; display: flex; height: 2rem; align-items: center;}.first { flex:1 0 auto;}.no-record { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center;}.no-image { width: 200rpx; height: 200rpx; margin-top: 200rpx; margin-bottom: 40rpx;}.no-text { font-size: 16px; color: #ccc; display: block;}

修改test.js

/* * 下一題/提交 按鈕 */ nextSubmit: function () { // 如果沒有選擇 ..... // 設置緩存 var logs = wx.getStorageSync('logs') || [] let logsList = { "date": Date.now(), "testId": app.globalData.quizCategory[this.data.testId], "score": this.data.totalScore } logs.unshift(logsList); wx.setStorageSync('logs', logs); } },

最終項目結構

從0開始,手把手教你開發一個答題微信小程序(如何開發答題小程序)

版權聲明:本文內容由互聯網用戶自發貢獻,該文觀點僅代表作者本人。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如發現本站有涉嫌抄襲侵權/違法違規的內容, 請發送郵件至 舉報,一經查實,本站將立刻刪除。

(0)
上一篇 2024年5月9日 下午1:25
下一篇 2024年5月9日 下午1:36

相關推薦

  • 成都 項目管理軟件

    成都,作為中國西南地區的一座重要城市,一直以來備受關注。作為一座現代化的城市,成都不僅在經濟發展上取得了巨大的成就,還在信息技術領域取得了重要進展。其中,成都的項目管理軟件市場已經…

    科研百科 2024年7月22日
    34
  • 江西省教育廳教學科研

    江西省教育廳教學科研 江西省教育廳是江西省教育廳的簡稱,主要負責江西省的教育教學工作和教育事業的科學研究。本文將介紹江西省教育廳在教學科研方面所做的工作,以及未來的發展方向。 近年…

    科研百科 2024年12月7日
    0
  • 園藝科研項目

    園藝科研項目 隨著城市化進程的加速,人們越來越注重生態文明建設。園藝科研項目作為一種新興的綠色療法,也逐漸被人們所認知。 園藝科研項目的研究對象是植物,通過人工培育和設計,使植物在…

    科研百科 2025年2月8日
    1
  • 促進重大項目落地 增強經濟發展動力——深化投資領域“放管服”改革經驗綜述

    新華社北京10月24日電 題:促進重大項目落地 增強經濟發展動力——深化投資領域“放管服”改革經驗綜述 新華社記者王優玲、趙文君 深化“放管服”改革、持續優化營商環境,是穩住經濟大…

    科研百科 2023年10月27日
    103
  • 城市基層黨建如何做精做細做實?水東街道以“1234+N”工作法答題(城市基層黨建工作怎么做)

    全面鋪開網格化管理、組團式服務工作,到高州市根子鎮調研學習,到廣州舉行干部能力全面提升研修班,舉行2023年度村(居)民小組長能力提升專題培訓班……最近,茂名市電白區水東街道在基層…

    科研百科 2023年7月25日
    105
  • 小兒推拿科研項目

    小兒推拿科研項目 近年來,隨著醫學科技的不斷進步,小兒推拿作為一種傳統的中醫療法,逐漸得到了人們的關注和認可。小兒推拿不僅能夠有效地治療許多兒童疾病,還能夠增強兒童的免疫力,促進兒…

    科研百科 2025年2月8日
    1
  • 基層工會經費收支管理

    基層工會經費收支管理 基層工會是工會組織的基本單位,經費收支管理是工會工作的重要組成部分。基層工會經費收支管理的重要性不言而喻,它關系到工會組織的正常運轉,關系到職工的合法權益,關…

    科研百科 2024年8月17日
    34
  • 項目app管理系統價位

    項目app管理系統價位是多少? 項目app管理系統是一種用于管理項目應用程序的軟件系統。這種系統可以幫助項目經理和開發人員更好地組織和管理項目,提高開發效率和質量。不同的項目app…

    科研百科 2024年12月23日
    0
  • 信息系統管理項目工程師

    信息系統管理項目工程師:信息技術管理的核心角色 隨著信息技術的不斷發展,信息系統管理項目工程師的重要性也越來越凸顯。作為一個負責信息技術管理的核心角色,他們負責確保信息技術系統的有…

    科研百科 2025年1月24日
    2
  • 女性科研項目

    女性科研項目:從入門到精通 近年來,女性參與科研項目的比例逐漸提高,但是女性科研項目仍然相對較少。在這個項目中,女性研究人員將分享她們的經驗和知識,為女性科研項目的發展做出貢獻。 …

    科研百科 2025年2月8日
    1