diff --git a/app.js b/app.js deleted file mode 100644 index aac0ff4..0000000 --- a/app.js +++ /dev/null @@ -1,16 +0,0 @@ -//app.js -App({ - onLaunch: function () { - wx.getSystemInfo({ - success: res => { - //导航高度 - this.globalData.navHeight = res.statusBarHeight + 46; - }, fail(err) { - console.log(err); - } - }) - }, - globalData: { - navHeight:0 - } -}) \ No newline at end of file diff --git a/app.json b/app.json deleted file mode 100644 index e346407..0000000 --- a/app.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "pages":[ - "pages/main/main", - "pages/index/index" - ], - "window":{ - "backgroundTextStyle":"light", - "navigationBarBackgroundColor": "#fff", - "navigationBarTitleText": "WeChat", - "navigationBarTextStyle":"write", - "navigationStyle":"custom" - } -} - - - - - - - - - - - - diff --git a/cloudfunctions/sD_login/index.js b/cloudfunctions/sD_login/index.js new file mode 100644 index 0000000..3475912 --- /dev/null +++ b/cloudfunctions/sD_login/index.js @@ -0,0 +1,31 @@ +// 云函数入口文件 +const cloud = require('wx-server-sdk') + +cloud.init() +const db = cloud.database() +const _ = db.command +const wxContext = cloud.getWXContext() + +// 云函数入口函数 +exports.main = async (event, context) => { + var allData = '',state = -1 //有个人记录就是1,无就是0, 下面执行出错就是-1 + await db.collection('sD_personal').where({ + _openid: wxContext.OPENID + }).get().then(async res => { + //where查询如果为空,返回[] + if (res.data.length){ + allData = res.data[0].allData; + state = 1; + } else { + //如果不存在则调取默认模板 + await db.collection('sD_common').doc('XKg1i1sqTi00tq1N').get().then(res1 => { + allData = res1.data.allData; + state = 0; + }) + } + }) + return { + allData: allData, + state:state + } +} \ No newline at end of file diff --git a/cloudfunctions/sD_login/package.json b/cloudfunctions/sD_login/package.json new file mode 100644 index 0000000..01e363e --- /dev/null +++ b/cloudfunctions/sD_login/package.json @@ -0,0 +1,14 @@ +{ + "name": "sD_login", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "wx-server-sdk": "latest" + } +} \ No newline at end of file diff --git a/cloudfunctions/sD_submit/index.js b/cloudfunctions/sD_submit/index.js new file mode 100644 index 0000000..a6ebe1c --- /dev/null +++ b/cloudfunctions/sD_submit/index.js @@ -0,0 +1,39 @@ +// 云函数入口文件 +const cloud = require('wx-server-sdk') + +cloud.init() +const db = cloud.database() +const _ = db.command +const wxContext = cloud.getWXContext() + +var commonUpload = async (data) => { + let rightAnswer = [] + await db.collection('sD_common').doc('XKg1i1sqTi00tq1N').get().then(res => { + rightAnswer = res.data.rightAnswer //这玩意的返回值莫名其妙会套上一层right,,但是不影响使用 + }) + //event.data是对象!妈的坑人! + for (let i in data) { + i = parseInt(i) + if (data[i] === rightAnswer[i]) { + let object = {} + object[i + 1] = _.inc(1)//不能直接传进去,在外边构造然后传进去 + db.collection('sD_common').doc('XKjJSXkPDdDCJ8rz').update({ + data: object + }).catch(err => { + return err; + }) + } + } + db.collection('sD_common').doc('XKjJSXkPDdDCJ8rz').update({ + data: { + total: _.inc(1) + } + }).catch(err => { + return err; + }) +} +// 云函数入口函数 +exports.main = async (event, context) => { + let common = await commonUpload(event.data); + return common; +} \ No newline at end of file diff --git a/cloudfunctions/sD_submit/package.json b/cloudfunctions/sD_submit/package.json new file mode 100644 index 0000000..18f1b61 --- /dev/null +++ b/cloudfunctions/sD_submit/package.json @@ -0,0 +1,14 @@ +{ + "name": "sD_submit", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "wx-server-sdk": "latest" + } +} \ No newline at end of file diff --git a/database_export-yq88LuJx60Rg.json b/database_export-yq88LuJx60Rg.json new file mode 100644 index 0000000..3650889 --- /dev/null +++ b/database_export-yq88LuJx60Rg.json @@ -0,0 +1,2 @@ +{"_id":"XKg1i1sqTi00tq1N","allData":[{"illustrate":"‘信心’应为‘信赖’","classState":"\"\"","pngAdd":"cloud://cloud-83621f.636c-cloud-83621f/styleDay/question_1.png","question":"问题一:以下哪一项不是四信的内容?","answers":[{"name":{"$numberLong":"0"},"value":"A:信念"},{"name":{"$numberLong":"1"},"value":"B:信仰"},{"name":{"$numberLong":"2"},"value":"C:信任"},{"name":{"$numberLong":"3"},"value":"D:信心"}],"userAnswer":"\"\"","rightAnswer":{"$numberLong":"3"}},{"rightAnswer":{"$numberLong":"1"},"illustrate":"要成为新时代青年马克思主义者,必须练就高强的本领,“既要政治过硬, 也要本领高强, 这是党的十九大报告对全党的要求, 对于青年马克思主义者来讲也是完全适用的","classState":"\"\"","pngAdd":"cloud://cloud-83621f.636c-cloud-83621f/styleDay/question_2.png","question":"问题二:关于以下说法,哪一项是不正确的?","answers":[{"value":"A:要成为新时代青年马克思主义者, 必须坚定对共产主义和中国特色社会主义的执着信仰","name":{"$numberLong":"0"}},{"name":{"$numberLong":"1"},"value":"B:要成为新时代青年马克思主义者, 只须练就高强的本领。"},{"name":{"$numberLong":"2"},"value":"C:要成为新时代青年马克思主义者, 必须常葆对人民群众的赤子之心"},{"name":{"$numberLong":"3"},"value":"D:要成为新时代青年马克思主义者, 必须树立为实现中华民族伟大复兴的中国梦而奋斗的使命担当"}],"userAnswer":"\"\""},{"illustrate":"马克思主义之所以是科学,首先在于它不再把自己的理论建立在主观臆想的基础上,而是建立在对现实社会进行科学研究的基础之上。马克思主义之所以为科学,还在于它不断吸收科学研究的最新成果,而不是故步自封、自视为穷尽一切真理的宗教教义。","classState":"\"\"","pngAdd":"cloud://cloud-83621f.636c-cloud-83621f/styleDay/question3.jpg","question":"问题三:马克思主义之所以是科学,仅仅在于它不再把自己的理论建立在主观臆想的基础上,而是建立在对现实社会进行科学研究的基础之上。","answers":[{"name":{"$numberLong":"0"},"value":"A:正确"},{"name":{"$numberLong":"1"},"value":"B:错误"}],"userAnswer":"\"\"","rightAnswer":{"$numberLong":"1"}},{"userAnswer":"\"\"","rightAnswer":{"$numberLong":"0"},"illustrate":"2018年5月4日,习近平总书记在纪念马克思诞辰200周年大会上强调,对待科学的理论必须有科学的态度。","classState":"\"\"","pngAdd":"cloud://cloud-83621f.636c-cloud-83621f/styleDay/question4.jpg","question":"问题四:马克思主义始终是我们党和国家的指导思想,是我们认识世界、把握规律、追求真理、改造世界的强大思想武器。","answers":[{"name":{"$numberLong":"0"},"value":"A:正确"},{"name":{"$numberLong":"1"},"value":"B:错误"}]}],"rightAnswer":[{"$numberLong":"3"},{"$numberLong":"1"},{"$numberLong":"1"},{"$numberLong":"0"}]} +{"_id":"XKjJSXkPDdDCJ8rz","total":{"$numberLong":"19"},"1":{"$numberLong":"13"},"2":{"$numberLong":"13"},"3":{"$numberLong":"13"},"4":{"$numberLong":"13"}} diff --git a/pages/main/main.js b/miniprogram/app.js similarity index 65% rename from pages/main/main.js rename to miniprogram/app.js index 84eefaa..921b47d 100644 --- a/pages/main/main.js +++ b/miniprogram/app.js @@ -1,13 +1,62 @@ -// pages/main/main.js -const App = getApp(); -Page({ - - /** - * 页面的初始数据 - */ - data: { - title:"主题团日知识竞答", - allData: [ +//app.js +App({ + onLaunch: function () { + wx.getSystemInfo({ + success: res => { + //导航高度 + this.globalData.navHeight = res.statusBarHeight + 46; + }, fail(err) { + console.log(err); + } + }) + // this.judgeCloud(); + }, + globalData: { + navHeight:0, + cloudState:0, + allData:null, + }, + judgeCloud() { + if (!wx.cloud) { + //不支持云能力 + console.error('请使用 2.2.3 或以上的基础库以使用云能力') + this.rewriteAllData(); + wx.redirectTo({ + url: '../main/mian', + }) + } else { + //支持云能力 + this.globalData.cloudState = 1; + wx.cloud.init({ + traceUser: true, + }) + //先查看该学生是否已经答过题 + + wx.cloud.callFunction({ + name: 'sD_login', + data: {} + }).then(res => { + console.log(res.result) + this.globalData.allData = res.result.allData + //如果没答过题 + if(res.result.state == 0) wx.redirectTo({ + url: '../main/main', + }) + //如果答过题 + if(res.result.state == 1) wx.redirectTo({ + url: '../index/index', + }) + }).catch(err => { + console.log(err) + this.rewriteAllData(); + wx.redirectTo({ + url: '../main/main', + }) + }) + } + }, + rewriteAllData() { + this.globalData.allData = [ { pngAdd: "https://gss0.baidu.com/-fo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/9d82d158ccbf6c81962c9e57b13eb13533fa4071.jpg", // pngAdd: "http://powerrain.cn/styleDay/images/question_1.png", @@ -54,96 +103,16 @@ Page({ { pngAdd: "https://gss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/4e4a20a4462309f7381b1fad7f0e0cf3d7cad61d.jpg", // pngAdd: "http://powerrain.cn/styleDay/images/question_4.png", - question: "问题四:习主席曾言,办好中国的事情,关键在党。", + question: "问题四:马克思主义始终是我们党和国家的指导思想,是我们认识世界、把握规律、追求真理、改造世界的强大思想武器。", answers: [ { name: 0, value: 'A:正确' }, { name: 1, value: 'B:错误' }, ], userAnswer: "", rightAnswer: 0, - illustrate: "习主席确实这么说的。", + illustrate: "2018年5月4日,习近平总书记在纪念马克思诞辰200周年大会上强调,对待科学的理论必须有科学的态度。", classState: "" } - ], - disabled:true - }, - - /** - * 生命周期函数--监听页面加载 - */ - onLoad: function (options) { - wx.clearStorage(); - this.setData({ - navH: App.globalData.navHeight - }) - }, - - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { - - }, - - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - - }, - - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { - - }, - - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { - - }, - - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { - - }, - - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { - - }, - - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () { - - }, - radioChange: function (e) { - wx.setStorageSync(e.currentTarget.id, e.detail.value); - console.log(typeof e.detail.value) - this.setData({ - disabled:this.judge() - }) - }, - judge(){ - for(let i=0;iview ,.answer_title{ - font-size: 36rpx; - font-weight: bolder; - margin-bottom: 10rpx; -} - -.info .userNickName>open-data { - font-size: 36rpx; - font-weight: lighter; -} - - -.box_ticket { - position: relative; - height:auto; - width:650rpx; - background-color: #fff; - margin:0 auto; - border-radius: 20rpx; - margin-bottom:60rpx; - box-shadow: 0 1px 4px rgba(0,0,0,0.3),0 0 40px rgba(0,0,0,0.1) inset; -} - -.w { - height: 90%; - width:90%; - margin:auto auto; - padding-top: 30rpx; -} - -.answer { - height:auto; - width:100%; - margin-bottom:30rpx; -} - -.answer .question_answer { - font-size: 30rpx; - margin-bottom:18rpx; -} - -.answer .question_answer .question { - margin-bottom:18rpx; - font-weight: bold; -} - -.rightAnswer .item { - height:auto; - line-height: 60rpx; - background: rgba(153,204,50,0.3); - font-weight: lighter; -} - -.userAnswer { - margin-bottom:18rpx; -} - -.userAnswer .item_right { - height:auto; - line-height:60rpx; - background: rgba(153,204,50,0.3); - font-weight: lighter; - -} - -.userAnswer .item_error { - height:auto; - line-height:60rpx; - background: rgba(255, 0, 0, 0.3); - font-weight: lighter; - -} - -.illustrate_title { - margin-bottom:18rpx; -} - -.illustrate_item { - font-weight: lighter; -} - -.grade { - height:auto; -} - -.grade .item_1 { - font-size: 30rpx; - display: flex; - flex-direction: row; - justify-content: space-between; - align-items: center; - margin-bottom: 18rpx; -} - - -.grade .item_1 .item_item { - font-weight: bold; -} - -.grade .item_2 .item_item { - font-weight: bold; -} - -.grade .item_2 { - font-size: 30rpx; - display: flex; - flex-direction: row; - justify-content: space-between; - align-items: center; -} - -.grade .item_3 { - height:100rpx; - font-size: 36rpx; - display: flex; - flex-direction: row; - justify-content: space-between; - align-items: center; -} - -.grade .item_3 .item_item { - font-size: 40rpx; - font-weight: bold; -} - -.BT { - color: #7f8389; - font-size: 20rpx; - flex: 1; -} - -.banquan { - display: flex; - flex-direction: column; - align-items: center; - margin-bottom: 20rpx; -} +/* pages/index/index.wxss */ +Page { + background-color: #efefef; +} +.title { + width:100%; + margin:auto; + overflow:hidden; + position: fixed; + top:0; + z-index: 100; + background-image:url(https://gss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/3ac79f3df8dcd10095b44a9e7f8b4710b9122f60.jpg); + /* background-image:url(https://powerrain.cn/styleDay/images/title_bg.png); */ + color: #fff; +} + +.title_text { + text-align: center; + margin-top:30px; + color: #fff; + font-size: 40rpx; +} + +.title_bg { + width:100%; + height:170px; + text-align:center; + line-height:50px; + position: fixed; + top:0; + z-index: -99; +} + +.title_bg:after { + width: 120%; + height: 170px; + position: fixed; + left: -10%; + top:0; + z-index: -100; + content: ''; + border-radius: 0 0 50% 50%; + background-image:url(https://gss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/3ac79f3df8dcd10095b44a9e7f8b4710b9122f60.jpg); + /* background-image:url(https://powerrain.cn/styleDay/images/title_bg.png); */ +} + +.boundary { + height:30rpx; + width:100%; + border-bottom: #eee 1px solid; +} +.info { + display: flex; + flex-direction: row; + width:100%; + height:180rpx; + justify-content: space-between; + align-items: center; +} + +.info .userAvatar { + height: 150rpx; + width: 150rpx; + border-radius: 50%; + margin: 30rpx; + overflow: hidden; +} + +.info .userNickName>view ,.answer_title{ + font-size: 36rpx; + font-weight: bolder; + margin-bottom: 10rpx; +} + +.info .userNickName>open-data { + font-size: 36rpx; + font-weight: lighter; +} + + +.box_ticket { + position: relative; + height:auto; + width:650rpx; + background-color: #fff; + margin:0 auto; + border-radius: 20rpx; + margin-bottom:60rpx; + box-shadow: 0 1px 4px rgba(0,0,0,0.3),0 0 40px rgba(0,0,0,0.1) inset; +} + +.w { + height: 90%; + width:90%; + margin:auto auto; + padding-top: 30rpx; +} + +.answer { + height:auto; + width:100%; + margin-bottom:30rpx; +} + +.answer .question_answer { + font-size: 30rpx; + margin-bottom:18rpx; +} + +.answer .question_answer .question { + margin-bottom:18rpx; + font-weight: bold; +} + +.rightAnswer .item { + height:auto; + line-height: 60rpx; + background: rgba(153,204,50,0.3); + font-weight: lighter; +} + +.userAnswer { + margin-bottom:18rpx; +} + +.userAnswer .item_right { + height:auto; + line-height:60rpx; + background: rgba(153,204,50,0.3); + font-weight: lighter; + +} + +.userAnswer .item_error { + height:auto; + line-height:60rpx; + background: rgba(255, 0, 0, 0.3); + font-weight: lighter; + +} + +.illustrate_title { + margin-bottom:18rpx; +} + +.illustrate_item { + font-weight: lighter; +} + +.grade { + height:auto; +} + +.grade .item_1 { + font-size: 30rpx; + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + margin-bottom: 18rpx; +} + + +.grade .item_1 .item_item { + font-weight: bold; +} + +.grade .item_2 .item_item { + font-weight: bold; +} + +.grade .item_2 { + font-size: 30rpx; + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; +} + +.grade .item_3 { + height:100rpx; + font-size: 36rpx; + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; +} + +.grade .item_3 .item_item { + font-size: 40rpx; + font-weight: bold; +} + +.BT { + color: #7f8389; + font-size: 20rpx; + flex: 1; +} + +.banquan { + display: flex; + flex-direction: column; + align-items: center; + margin-bottom: 20rpx; +} diff --git a/miniprogram/pages/main/main.js b/miniprogram/pages/main/main.js new file mode 100644 index 0000000..73a3b26 --- /dev/null +++ b/miniprogram/pages/main/main.js @@ -0,0 +1,148 @@ +// pages/main/main.js +const App = getApp(); +Page({ + + /** + * 页面的初始数据 + */ + data: { + title:"主题团日知识竞答", + allData: [], + disabled:true, + interval:'', + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + wx.clearStorage(); + this.setData({ + navH: App.globalData.navHeight, + allData: App.globalData.allData + }) + // wx.showLoading({ + // title: '加载中', + // }) + // this.interval = setInterval(()=>{ + // if (App.globalData.allData !== null) { + // this.setData({ + // allData: App.globalData.allData, + // isShow:true + // }) + // this.stopInterval(); + // wx.hideLoading(); + // } + // }, 100); + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + }, + // stopInterval() { + // clearInterval(this.interval) + // }, + radioChange: function (e) { + wx.setStorageSync(e.currentTarget.id, e.detail.value); + // console.log(e.currentTarget.id, e.detail.value) + //将改变保存到globalData里边 + App.globalData.allData[e.currentTarget.id].userAnswer = parseInt(e.detail.value) ; + // console.log(App.globalData.allData) + this.setData({ + disabled:this.judge() + }) + + }, + judge(){ + for(let i=0;i{ + console.log(res.result) + }).catch(err =>{ + console.log(err) + }) + } + wx.cloud.database().collection('sD_personal').add({ + data:{ + allData: App.globalData.allData + } + }).then(res => { + wx.redirectTo({url:"../index/index"}) + }).catch(err =>{ + console.err(err); + wx.vibrateLong({}) + wx.showToast({ + title: '抱歉,请重试', + icon: 'success', + image: '../../images/info.png', + duration: 2000 + }) + }) + + } +}) \ No newline at end of file diff --git a/pages/main/main.json b/miniprogram/pages/main/main.json similarity index 75% rename from pages/main/main.json rename to miniprogram/pages/main/main.json index 405ba36..077404a 100644 --- a/pages/main/main.json +++ b/miniprogram/pages/main/main.json @@ -1,3 +1,3 @@ -{ - +{ + } \ No newline at end of file diff --git a/pages/main/main.wxml b/miniprogram/pages/main/main.wxml similarity index 99% rename from pages/main/main.wxml rename to miniprogram/pages/main/main.wxml index 2e70c06..4ecef68 100644 --- a/pages/main/main.wxml +++ b/miniprogram/pages/main/main.wxml @@ -4,7 +4,6 @@ - @@ -27,4 +26,4 @@ Designed by Rain Sun 计算机科学技术学院 团委学生会学习部 All Rights Reserved - \ No newline at end of file + diff --git a/pages/main/main.wxss b/miniprogram/pages/main/main.wxss similarity index 94% rename from pages/main/main.wxss rename to miniprogram/pages/main/main.wxss index e722439..1551dab 100644 --- a/pages/main/main.wxss +++ b/miniprogram/pages/main/main.wxss @@ -1,125 +1,125 @@ -/* pages/main/main.wxss */ -Page { - background-color: #efefef; -} -.title { - width:100%; - margin:auto; - overflow:hidden; - position: fixed; - top:0; - z-index: 100; - background-image:url(https://gss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/3ac79f3df8dcd10095b44a9e7f8b4710b9122f60.jpg); - /* background-image:url(https://powerrain.cn/styleDay/images/title_bg.png); */ - color: #fff; -} - -.title_text { - text-align: center; - margin-top:30px; - color: #fff; - font-size: 40rpx; -} - -.title_bg { - width:100%; - height:170px; - text-align:center; - line-height:50px; - position: fixed; - top:0; - z-index: -99; -} - -.title_bg:after { - width: 120%; - height: 170px; - position: fixed; - left: -10%; - top:0; - z-index: -100; - content: ''; - border-radius: 0 0 50% 50%; - background-image:url(https://gss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/3ac79f3df8dcd10095b44a9e7f8b4710b9122f60.jpg); - /* background-image:url(https://powerrain.cn/styleDay/images/title_bg.png); */ -} - -.box_select { - height:auto; - width:650rpx; - background-color: #fff; - margin:0 auto; - border-radius: 20rpx; - margin-bottom:60rpx; - box-shadow: 0 1px 4px rgba(0,0,0,0.3),0 0 40px rgba(0,0,0,0.1) inset; -} - -.box_select .w { - height: 90%; - width:90%; - margin:auto auto; - padding-top: 30rpx; -} - -.box_png_1 { - height:240rpx; - width:100%; - margin-bottom: 30rpx; - border-top-left-radius:20rpx; - border-top-right-radius:20rpx; -} - -.box_select .question { - font-size: 40rpx; -} - -.box_select .radio-group { - margin-top:40rpx; -} - -.box_select .radio-group .radio { - margin-bottom: 30rpx; - display: flex; - flex-direction: row; - align-items: center; - justify-content: space-between; - height:auto; - border-bottom:1px #eee solid; - font-weight: lighter; -} - -.box_select .radio-group .radio .answer { - width:80%; - margin-bottom: 30rpx; -} - -.box_select .radio-group .radio radio { - margin-bottom: 30rpx; -} - - -.BT { - color: #7f8389; - font-size: 20rpx; - flex: 1; -} - -.banquan { - display: flex; - flex-direction: column; - align-items: center; - margin-bottom: 20rpx; -} - -.button { - height:80rpx; - background-color: #c91b1e; - width: 650rpx; - margin:0 auto; - border-radius: 20rpx; - margin-bottom: 30rpx; - line-height: 80rpx; - color: #fff; - font-size: 40rpx; - text-align: center; +/* pages/main/main.wxss */ +Page { + background-color: #efefef; +} +.title { + width:100%; + margin:auto; + overflow:hidden; + position: fixed; + top:0; + z-index: 100; + background-image:url(https://gss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/3ac79f3df8dcd10095b44a9e7f8b4710b9122f60.jpg); + /* background-image:url(https://powerrain.cn/styleDay/images/title_bg.png); */ + color: #fff; +} + +.title_text { + text-align: center; + margin-top:30px; + color: #fff; + font-size: 40rpx; +} + +.title_bg { + width:100%; + height:170px; + text-align:center; + line-height:50px; + position: fixed; + top:0; + z-index: -99; +} + +.title_bg:after { + width: 120%; + height: 170px; + position: fixed; + left: -10%; + top:0; + z-index: -100; + content: ''; + border-radius: 0 0 50% 50%; + background-image:url(https://gss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/3ac79f3df8dcd10095b44a9e7f8b4710b9122f60.jpg); + /* background-image:url(https://powerrain.cn/styleDay/images/title_bg.png); */ +} + +.box_select { + height:auto; + width:650rpx; + background-color: #fff; + margin:0 auto; + border-radius: 20rpx; + margin-bottom:60rpx; + box-shadow: 0 1px 4px rgba(0,0,0,0.3),0 0 40px rgba(0,0,0,0.1) inset; +} + +.box_select .w { + height: 90%; + width:90%; + margin:auto auto; + padding-top: 30rpx; +} + +.box_png_1 { + height:240rpx; + width:100%; + margin-bottom: 30rpx; + border-top-left-radius:20rpx; + border-top-right-radius:20rpx; +} + +.box_select .question { + font-size: 40rpx; +} + +.box_select .radio-group { + margin-top:40rpx; +} + +.box_select .radio-group .radio { + margin-bottom: 30rpx; + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + height:auto; + border-bottom:1px #eee solid; + font-weight: lighter; +} + +.box_select .radio-group .radio .answer { + width:80%; + margin-bottom: 30rpx; +} + +.box_select .radio-group .radio radio { + margin-bottom: 30rpx; +} + + +.BT { + color: #7f8389; + font-size: 20rpx; + flex: 1; +} + +.banquan { + display: flex; + flex-direction: column; + align-items: center; + margin-bottom: 20rpx; +} + +.button { + height:80rpx; + background-color: #c91b1e; + width: 650rpx; + margin:0 auto; + border-radius: 20rpx; + margin-bottom: 30rpx; + line-height: 80rpx; + color: #fff; + font-size: 40rpx; + text-align: center; } \ No newline at end of file diff --git a/miniprogram/pages/report/report.js b/miniprogram/pages/report/report.js new file mode 100644 index 0000000..c2ce901 --- /dev/null +++ b/miniprogram/pages/report/report.js @@ -0,0 +1,64 @@ +var wxCharts = require('./utils/wxcharts.js'); +var App = getApp(); +var pieChart = null; +// px = rpx / 750 * wx.getSystemInfoSync().windowWidth; +Page({ + data: { + title:"数据分析" + }, + touchHandler: function (e) { + console.log(pieChart.getCurrentDataIndex(e)); + }, + onLoad: function (e) { + this.setData({ + navH: App.globalData.navHeight + }) + var windowWidth = 320; + try { + var res = wx.getSystemInfoSync(); + windowWidth = res.windowWidth; + console.log("屏幕宽度为:",windowWidth) + } catch (e) { + console.error('getSystemInfoSync failed!'); + } + var list = [{ + name: 'A选项', + data: 412, + }, { + name: 'B选项', + data: 35, + }, { + name: 'C选项', + data: 40, + }, { + name: 'D选项', + data: 63, + }] + pieChart = new wxCharts({ + animation: true, + canvasId: 'pieCanvas', + type: 'pie', + series: list , + width: windowWidth, + height: 300, + dataLabel: true, + }); + wx.startWifi({ + success: function (res) { + console.log("调起wifi",res) + wx.getWifiList({ + success: function (sList) { + console.log("sList",sList) + wx.onGetWifiList(res => { + console.log("获取到WiFilist", res) + }); + }, + fail: function (fList) { + console.log("flist",fList) + } + }) + } + }) + + } +}); \ No newline at end of file diff --git a/miniprogram/pages/report/report.json b/miniprogram/pages/report/report.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/miniprogram/pages/report/report.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/report/report.wxml b/miniprogram/pages/report/report.wxml new file mode 100644 index 0000000..3b2907c --- /dev/null +++ b/miniprogram/pages/report/report.wxml @@ -0,0 +1,9 @@ + + {{title}} + + + + + + + diff --git a/miniprogram/pages/report/report.wxss b/miniprogram/pages/report/report.wxss new file mode 100644 index 0000000..c22c4ff --- /dev/null +++ b/miniprogram/pages/report/report.wxss @@ -0,0 +1,58 @@ +/* pages/report/report.wxss */ +canvas { + width: 100%; +} +Page { + background-color: #efefef; +} +.title { + width:100%; + margin:auto; + overflow:hidden; + position: fixed; + top:0; + z-index: 100; + background-image:url(https://gss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/3ac79f3df8dcd10095b44a9e7f8b4710b9122f60.jpg); + /* background-image:url(https://powerrain.cn/styleDay/images/title_bg.png); */ + color: #fff; +} + +.title_text { + text-align: center; + margin-top:30px; + color: #fff; + font-size: 40rpx; +} + +.title_bg { + width:100%; + height:170px; + text-align:center; + line-height:50px; + position: fixed; + top:0; + z-index: -99; +} + +.title_bg:after { + width: 120%; + height: 170px; + position: fixed; + left: -10%; + top:0; + z-index: -100; + content: ''; + border-radius: 0 0 50% 50%; + background-image:url(https://gss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/3ac79f3df8dcd10095b44a9e7f8b4710b9122f60.jpg); + /* background-image:url(https://powerrain.cn/styleDay/images/title_bg.png); */ +} + +.box_select { + height:auto; + width:650rpx; + background-color: #fff; + margin:0 auto; + border-radius: 20rpx; + margin-bottom:60rpx; + box-shadow: 0 1px 4px rgba(0,0,0,0.3),0 0 40px rgba(0,0,0,0.1) inset; +} \ No newline at end of file diff --git a/miniprogram/pages/report/utils/wxcharts.js b/miniprogram/pages/report/utils/wxcharts.js new file mode 100644 index 0000000..1d54ec1 --- /dev/null +++ b/miniprogram/pages/report/utils/wxcharts.js @@ -0,0 +1,2048 @@ +/* + * charts for WeChat small app v1.0 + * + * https://github.com/xiaolin3303/wx-charts + * 2016-11-28 + * + * Designed and built with all the love of Web + */ + +'use strict'; + +var config = { + yAxisWidth: 15, + yAxisSplit: 5, + xAxisHeight: 15, + xAxisLineHeight: 15, + legendHeight: 15, + yAxisTitleWidth: 15, + padding: 12, + columePadding: 3, + fontSize: 10, + dataPointShape: ['diamond', 'circle', 'triangle', 'rect'], + colors: ['#00c1c8', '#0092ff', '#ff2788', '#fee449', '#f15c80', '#8085e9'], + pieChartLinePadding: 25, + pieChartTextPadding: 15, + xAxisTextPadding: 3, + titleColor: '#333333', + titleFontSize: 20, + subtitleColor: '#999999', + subtitleFontSize: 15, + toolTipPadding: 3, + toolTipBackground: '#000000', + toolTipOpacity: 0.7, + toolTipLineHeight: 14, + radarGridCount: 3, + radarLabelTextMargin: 15 +}; + +// Object.assign polyfill +// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign +function assign(target, varArgs) { + if (target == null) { + // TypeError if undefined or null + throw new TypeError('Cannot convert undefined or null to object'); + } + + var to = Object(target); + + for (var index = 1; index < arguments.length; index++) { + var nextSource = arguments[index]; + + if (nextSource != null) { + // Skip over if undefined or null + for (var nextKey in nextSource) { + // Avoid bugs when hasOwnProperty is shadowed + if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { + to[nextKey] = nextSource[nextKey]; + } + } + } + } + return to; +} + +var util = { + toFixed: function toFixed(num, limit) { + limit = limit || 2; + if (this.isFloat(num)) { + num = num.toFixed(limit); + } + return num; + }, + isFloat: function isFloat(num) { + return num % 1 !== 0; + }, + approximatelyEqual: function approximatelyEqual(num1, num2) { + return Math.abs(num1 - num2) < 1e-10; + }, + isSameSign: function isSameSign(num1, num2) { + return Math.abs(num1) === num1 && Math.abs(num2) === num2 || Math.abs(num1) !== num1 && Math.abs(num2) !== num2; + }, + isSameXCoordinateArea: function isSameXCoordinateArea(p1, p2) { + return this.isSameSign(p1.x, p2.x); + }, + isCollision: function isCollision(obj1, obj2) { + obj1.end = {}; + obj1.end.x = obj1.start.x + obj1.width; + obj1.end.y = obj1.start.y - obj1.height; + obj2.end = {}; + obj2.end.x = obj2.start.x + obj2.width; + obj2.end.y = obj2.start.y - obj2.height; + var flag = obj2.start.x > obj1.end.x || obj2.end.x < obj1.start.x || obj2.end.y > obj1.start.y || obj2.start.y < obj1.end.y; + + return !flag; + } +}; + +function findRange(num, type, limit) { + if (isNaN(num)) { + throw new Error('[wxCharts] unvalid series data!'); + } + limit = limit || 10; + type = type ? type : 'upper'; + var multiple = 1; + while (limit < 1) { + limit *= 10; + multiple *= 10; + } + if (type === 'upper') { + num = Math.ceil(num * multiple); + } else { + num = Math.floor(num * multiple); + } + while (num % limit !== 0) { + if (type === 'upper') { + num++; + } else { + num--; + } + } + + return num / multiple; +} + +function calValidDistance(distance, chartData, config, opts) { + + var dataChartAreaWidth = opts.width - config.padding - chartData.xAxisPoints[0]; + var dataChartWidth = chartData.eachSpacing * opts.categories.length; + var validDistance = distance; + if (distance >= 0) { + validDistance = 0; + } else if (Math.abs(distance) >= dataChartWidth - dataChartAreaWidth) { + validDistance = dataChartAreaWidth - dataChartWidth; + } + return validDistance; +} + +function isInAngleRange(angle, startAngle, endAngle) { + function adjust(angle) { + while (angle < 0) { + angle += 2 * Math.PI; + } + while (angle > 2 * Math.PI) { + angle -= 2 * Math.PI; + } + + return angle; + } + + angle = adjust(angle); + startAngle = adjust(startAngle); + endAngle = adjust(endAngle); + if (startAngle > endAngle) { + endAngle += 2 * Math.PI; + if (angle < startAngle) { + angle += 2 * Math.PI; + } + } + + return angle >= startAngle && angle <= endAngle; +} + +function calRotateTranslate(x, y, h) { + var xv = x; + var yv = h - y; + + var transX = xv + (h - yv - xv) / Math.sqrt(2); + transX *= -1; + + var transY = (h - yv) * (Math.sqrt(2) - 1) - (h - yv - xv) / Math.sqrt(2); + + return { + transX: transX, + transY: transY + }; +} + +function createCurveControlPoints(points, i) { + + function isNotMiddlePoint(points, i) { + if (points[i - 1] && points[i + 1]) { + return points[i].y >= Math.max(points[i - 1].y, points[i + 1].y) || points[i].y <= Math.min(points[i - 1].y, points[i + 1].y); + } else { + return false; + } + } + + var a = 0.2; + var b = 0.2; + var pAx = null; + var pAy = null; + var pBx = null; + var pBy = null; + if (i < 1) { + pAx = points[0].x + (points[1].x - points[0].x) * a; + pAy = points[0].y + (points[1].y - points[0].y) * a; + } else { + pAx = points[i].x + (points[i + 1].x - points[i - 1].x) * a; + pAy = points[i].y + (points[i + 1].y - points[i - 1].y) * a; + } + + if (i > points.length - 3) { + var last = points.length - 1; + pBx = points[last].x - (points[last].x - points[last - 1].x) * b; + pBy = points[last].y - (points[last].y - points[last - 1].y) * b; + } else { + pBx = points[i + 1].x - (points[i + 2].x - points[i].x) * b; + pBy = points[i + 1].y - (points[i + 2].y - points[i].y) * b; + } + + // fix issue https://github.com/xiaolin3303/wx-charts/issues/79 + if (isNotMiddlePoint(points, i + 1)) { + pBy = points[i + 1].y; + } + if (isNotMiddlePoint(points, i)) { + pAy = points[i].y; + } + + return { + ctrA: { x: pAx, y: pAy }, + ctrB: { x: pBx, y: pBy } + }; +} + +function convertCoordinateOrigin(x, y, center) { + return { + x: center.x + x, + y: center.y - y + }; +} + +function avoidCollision(obj, target) { + if (target) { + // is collision test + while (util.isCollision(obj, target)) { + if (obj.start.x > 0) { + obj.start.y--; + } else if (obj.start.x < 0) { + obj.start.y++; + } else { + if (obj.start.y > 0) { + obj.start.y++; + } else { + obj.start.y--; + } + } + } + } + return obj; +} + +function fillSeriesColor(series, config) { + var index = 0; + return series.map(function (item) { + if (!item.color) { + item.color = config.colors[index]; + index = (index + 1) % config.colors.length; + } + return item; + }); +} + +function getDataRange(minData, maxData) { + var limit = 0; + var range = maxData - minData; + if (range >= 10000) { + limit = 1000; + } else if (range >= 1000) { + limit = 100; + } else if (range >= 100) { + limit = 10; + } else if (range >= 10) { + limit = 5; + } else if (range >= 1) { + limit = 1; + } else if (range >= 0.1) { + limit = 0.1; + } else { + limit = 0.01; + } + return { + minRange: findRange(minData, 'lower', limit), + maxRange: findRange(maxData, 'upper', limit) + }; +} + +function measureText(text) { + var fontSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10; + + // wx canvas 未实现measureText方法, 此处自行实现 + text = String(text); + var text = text.split(''); + var width = 0; + text.forEach(function (item) { + if (/[a-zA-Z]/.test(item)) { + width += 7; + } else if (/[0-9]/.test(item)) { + width += 5.5; + } else if (/\./.test(item)) { + width += 2.7; + } else if (/-/.test(item)) { + width += 3.25; + } else if (/[\u4e00-\u9fa5]/.test(item)) { + width += 10; + } else if (/\(|\)/.test(item)) { + width += 3.73; + } else if (/\s/.test(item)) { + width += 2.5; + } else if (/%/.test(item)) { + width += 8; + } else { + width += 10; + } + }); + return width * fontSize / 10; +} + +function dataCombine(series) { + return series.reduce(function (a, b) { + return (a.data ? a.data : a).concat(b.data); + }, []); +} + +function getSeriesDataItem(series, index) { + var data = []; + series.forEach(function (item) { + if (item.data[index] !== null && typeof item.data[index] !== 'undefinded') { + var seriesItem = {}; + seriesItem.color = item.color; + seriesItem.name = item.name; + seriesItem.data = item.format ? item.format(item.data[index]) : item.data[index]; + data.push(seriesItem); + } + }); + + return data; +} + + + +function getMaxTextListLength(list) { + var lengthList = list.map(function (item) { + return measureText(item); + }); + return Math.max.apply(null, lengthList); +} + +function getRadarCoordinateSeries(length) { + var eachAngle = 2 * Math.PI / length; + var CoordinateSeries = []; + for (var i = 0; i < length; i++) { + CoordinateSeries.push(eachAngle * i); + } + + return CoordinateSeries.map(function (item) { + return -1 * item + Math.PI / 2; + }); +} + +function getToolTipData(seriesData, calPoints, index, categories) { + var option = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; + + var textList = seriesData.map(function (item) { + return { + text: option.format ? option.format(item, categories[index]) : item.name + ': ' + item.data, + color: item.color + }; + }); + var validCalPoints = []; + var offset = { + x: 0, + y: 0 + }; + calPoints.forEach(function (points) { + if (typeof points[index] !== 'undefinded' && points[index] !== null) { + validCalPoints.push(points[index]); + } + }); + validCalPoints.forEach(function (item) { + offset.x = Math.round(item.x); + offset.y += item.y; + }); + + offset.y /= validCalPoints.length; + return { textList: textList, offset: offset }; +} + +function findCurrentIndex(currentPoints, xAxisPoints, opts, config) { + var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; + + var currentIndex = -1; + if (isInExactChartArea(currentPoints, opts, config)) { + xAxisPoints.forEach(function (item, index) { + if (currentPoints.x + offset > item) { + currentIndex = index; + } + }); + } + + return currentIndex; +} + +function isInExactChartArea(currentPoints, opts, config) { + return currentPoints.x < opts.width - config.padding && currentPoints.x > config.padding + config.yAxisWidth + config.yAxisTitleWidth && currentPoints.y > config.padding && currentPoints.y < opts.height - config.legendHeight - config.xAxisHeight - config.padding; +} + +function findRadarChartCurrentIndex(currentPoints, radarData, count) { + var eachAngleArea = 2 * Math.PI / count; + var currentIndex = -1; + if (isInExactPieChartArea(currentPoints, radarData.center, radarData.radius)) { + var fixAngle = function fixAngle(angle) { + if (angle < 0) { + angle += 2 * Math.PI; + } + if (angle > 2 * Math.PI) { + angle -= 2 * Math.PI; + } + return angle; + }; + + var angle = Math.atan2(radarData.center.y - currentPoints.y, currentPoints.x - radarData.center.x); + angle = -1 * angle; + if (angle < 0) { + angle += 2 * Math.PI; + } + + var angleList = radarData.angleList.map(function (item) { + item = fixAngle(-1 * item); + + return item; + }); + + angleList.forEach(function (item, index) { + var rangeStart = fixAngle(item - eachAngleArea / 2); + var rangeEnd = fixAngle(item + eachAngleArea / 2); + if (rangeEnd < rangeStart) { + rangeEnd += 2 * Math.PI; + } + if (angle >= rangeStart && angle <= rangeEnd || angle + 2 * Math.PI >= rangeStart && angle + 2 * Math.PI <= rangeEnd) { + currentIndex = index; + } + }); + } + + return currentIndex; +} + +function findPieChartCurrentIndex(currentPoints, pieData) { + var currentIndex = -1; + if (isInExactPieChartArea(currentPoints, pieData.center, pieData.radius)) { + var angle = Math.atan2(pieData.center.y - currentPoints.y, currentPoints.x - pieData.center.x); + angle = -angle; + for (var i = 0, len = pieData.series.length; i < len; i++) { + var item = pieData.series[i]; + if (isInAngleRange(angle, item._start_, item._start_ + item._proportion_ * 2 * Math.PI)) { + currentIndex = i; + break; + } + } + } + + return currentIndex; +} + +function isInExactPieChartArea(currentPoints, center, radius) { + return Math.pow(currentPoints.x - center.x, 2) + Math.pow(currentPoints.y - center.y, 2) <= Math.pow(radius, 2); +} + +function splitPoints(points) { + var newPoints = []; + var items = []; + points.forEach(function (item, index) { + if (item !== null) { + items.push(item); + } else { + if (items.length) { + newPoints.push(items); + } + items = []; + } + }); + if (items.length) { + newPoints.push(items); + } + + return newPoints; +} + +function calLegendData(series, opts, config) { + if (opts.legend === false) { + return { + legendList: [], + legendHeight: 0 + }; + } + var padding = 5; + var marginTop = 8; + var shapeWidth = 15; + var legendList = []; + var widthCount = 0; + var currentRow = []; + series.forEach(function (item) { + var itemWidth = 3 * padding + shapeWidth + measureText(item.name || 'undefinded'); + if (widthCount + itemWidth > opts.width) { + legendList.push(currentRow); + widthCount = itemWidth; + currentRow = [item]; + } else { + widthCount += itemWidth; + currentRow.push(item); + } + }); + if (currentRow.length) { + legendList.push(currentRow); + } + + return { + legendList: legendList, + legendHeight: legendList.length * (config.fontSize + marginTop) + padding + }; +} + +function calCategoriesData(categories, opts, config) { + var result = { + angle: 0, + xAxisHeight: config.xAxisHeight + }; + + var _getXAxisPoints = getXAxisPoints(categories, opts, config), + eachSpacing = _getXAxisPoints.eachSpacing; + + // get max length of categories text + + + var categoriesTextLenth = categories.map(function (item) { + return measureText(item); + }); + + var maxTextLength = Math.max.apply(this, categoriesTextLenth); + + if (maxTextLength + 2 * config.xAxisTextPadding > eachSpacing) { + result.angle = 45 * Math.PI / 180; + result.xAxisHeight = 2 * config.xAxisTextPadding + maxTextLength * Math.sin(result.angle); + } + + return result; +} + +function getRadarDataPoints(angleList, center, radius, series, opts) { + var process = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1; + + var radarOption = opts.extra.radar || {}; + radarOption.max = radarOption.max || 0; + var maxData = Math.max(radarOption.max, Math.max.apply(null, dataCombine(series))); + + var data = []; + series.forEach(function (each) { + var listItem = {}; + listItem.color = each.color; + listItem.data = []; + each.data.forEach(function (item, index) { + var tmp = {}; + tmp.angle = angleList[index]; + + tmp.proportion = item / maxData; + tmp.position = convertCoordinateOrigin(radius * tmp.proportion * process * Math.cos(tmp.angle), radius * tmp.proportion * process * Math.sin(tmp.angle), center); + listItem.data.push(tmp); + }); + + data.push(listItem); + }); + + return data; +} + +function getPieDataPoints(series) { + var process = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + + var count = 0; + var _start_ = 0; + series.forEach(function (item) { + item.data = item.data === null ? 0 : item.data; + count += item.data; + }); + series.forEach(function (item) { + item.data = item.data === null ? 0 : item.data; + item._proportion_ = item.data / count * process; + }); + series.forEach(function (item) { + item._start_ = _start_; + _start_ += 2 * item._proportion_ * Math.PI; + }); + + return series; +} + +function getPieTextMaxLength(series) { + series = getPieDataPoints(series); + var maxLength = 0; + series.forEach(function (item) { + var text = item.format ? item.format(+item._proportion_.toFixed(2)) : util.toFixed(item._proportion_ * 100) + '%'; + maxLength = Math.max(maxLength, measureText(text)); + }); + + return maxLength; +} + +function fixColumeData(points, eachSpacing, columnLen, index, config, opts) { + return points.map(function (item) { + if (item === null) { + return null; + } + item.width = (eachSpacing - 2 * config.columePadding) / columnLen; + + if (opts.extra.column && opts.extra.column.width && +opts.extra.column.width > 0) { + // customer column width + item.width = Math.min(item.width, +opts.extra.column.width); + } else { + // default width should less tran 25px + // don't ask me why, I don't know + item.width = Math.min(item.width, 25); + } + item.x += (index + 0.5 - columnLen / 2) * item.width; + + return item; + }); +} + +function getXAxisPoints(categories, opts, config) { + var yAxisTotalWidth = config.yAxisWidth + config.yAxisTitleWidth; + var spacingValid = opts.width - 2 * config.padding - yAxisTotalWidth; + var dataCount = opts.enableScroll ? Math.min(5, categories.length) : categories.length; + var eachSpacing = spacingValid / dataCount; + + var xAxisPoints = []; + var startX = config.padding + yAxisTotalWidth; + var endX = opts.width - config.padding; + categories.forEach(function (item, index) { + xAxisPoints.push(startX + index * eachSpacing); + }); + if (opts.enableScroll === true) { + xAxisPoints.push(startX + categories.length * eachSpacing); + } else { + xAxisPoints.push(endX); + } + + return { xAxisPoints: xAxisPoints, startX: startX, endX: endX, eachSpacing: eachSpacing }; +} + +function getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config) { + var process = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 1; + + var points = []; + var validHeight = opts.height - 2 * config.padding - config.xAxisHeight - config.legendHeight; + data.forEach(function (item, index) { + if (item === null) { + points.push(null); + } else { + var point = {}; + point.x = xAxisPoints[index] + Math.round(eachSpacing / 2); + var height = validHeight * (item - minRange) / (maxRange - minRange); + height *= process; + point.y = opts.height - config.xAxisHeight - config.legendHeight - Math.round(height) - config.padding; + points.push(point); + } + }); + + return points; +} + +function getYAxisTextList(series, opts, config) { + var data = dataCombine(series); + // remove null from data + data = data.filter(function (item) { + return item !== null; + }); + var minData = Math.min.apply(this, data); + var maxData = Math.max.apply(this, data); + if (typeof opts.yAxis.min === 'number') { + minData = Math.min(opts.yAxis.min, minData); + } + if (typeof opts.yAxis.max === 'number') { + maxData = Math.max(opts.yAxis.max, maxData); + } + + // fix issue https://github.com/xiaolin3303/wx-charts/issues/9 + if (minData === maxData) { + var rangeSpan = maxData || 1; + minData -= rangeSpan; + maxData += rangeSpan; + } + + var dataRange = getDataRange(minData, maxData); + var minRange = dataRange.minRange; + var maxRange = dataRange.maxRange; + + var range = []; + var eachRange = (maxRange - minRange) / config.yAxisSplit; + + for (var i = 0; i <= config.yAxisSplit; i++) { + range.push(minRange + eachRange * i); + } + return range.reverse(); +} + +function calYAxisData(series, opts, config) { + + var ranges = getYAxisTextList(series, opts, config); + var yAxisWidth = config.yAxisWidth; + var rangesFormat = ranges.map(function (item) { + item = util.toFixed(item, 2); + item = opts.yAxis.format ? opts.yAxis.format(Number(item)) : item; + yAxisWidth = Math.max(yAxisWidth, measureText(item) + 5); + return item; + }); + if (opts.yAxis.disabled === true) { + yAxisWidth = 0; + } + + return { rangesFormat: rangesFormat, ranges: ranges, yAxisWidth: yAxisWidth }; +} + +function drawPointShape(points, color, shape, context) { + context.beginPath(); + context.setStrokeStyle("#ffffff"); + context.setLineWidth(1); + context.setFillStyle(color); + + if (shape === 'diamond') { + points.forEach(function (item, index) { + if (item !== null) { + context.moveTo(item.x, item.y - 4.5); + context.lineTo(item.x - 4.5, item.y); + context.lineTo(item.x, item.y + 4.5); + context.lineTo(item.x + 4.5, item.y); + context.lineTo(item.x, item.y - 4.5); + } + }); + } else if (shape === 'circle') { + points.forEach(function (item, index) { + if (item !== null) { + context.moveTo(item.x + 3.5, item.y); + context.arc(item.x, item.y, 4, 0, 2 * Math.PI, false); + } + }); + } else if (shape === 'rect') { + points.forEach(function (item, index) { + if (item !== null) { + context.moveTo(item.x - 3.5, item.y - 3.5); + context.rect(item.x - 3.5, item.y - 3.5, 7, 7); + } + }); + } else if (shape === 'triangle') { + points.forEach(function (item, index) { + if (item !== null) { + context.moveTo(item.x, item.y - 4.5); + context.lineTo(item.x - 4.5, item.y + 4.5); + context.lineTo(item.x + 4.5, item.y + 4.5); + context.lineTo(item.x, item.y - 4.5); + } + }); + } + context.closePath(); + context.fill(); + context.stroke(); +} + +function drawRingTitle(opts, config, context) { + var titlefontSize = opts.title.fontSize || config.titleFontSize; + var subtitlefontSize = opts.subtitle.fontSize || config.subtitleFontSize; + var title = opts.title.name || ''; + var subtitle = opts.subtitle.name || ''; + var titleFontColor = opts.title.color || config.titleColor; + var subtitleFontColor = opts.subtitle.color || config.subtitleColor; + var titleHeight = title ? titlefontSize : 0; + var subtitleHeight = subtitle ? subtitlefontSize : 0; + var margin = 5; + if (subtitle) { + var textWidth = measureText(subtitle, subtitlefontSize); + var startX = (opts.width - textWidth) / 2 + (opts.subtitle.offsetX || 0); + var startY = (opts.height - config.legendHeight + subtitlefontSize) / 2; + if (title) { + startY -= (titleHeight + margin) / 2; + } + context.beginPath(); + context.setFontSize(subtitlefontSize); + context.setFillStyle(subtitleFontColor); + context.fillText(subtitle, startX, startY); + context.stroke(); + context.closePath(); + } + if (title) { + var _textWidth = measureText(title, titlefontSize); + var _startX = (opts.width - _textWidth) / 2 + (opts.title.offsetX || 0); + var _startY = (opts.height - config.legendHeight + titlefontSize) / 2; + if (subtitle) { + _startY += (subtitleHeight + margin) / 2; + } + context.beginPath(); + context.setFontSize(titlefontSize); + context.setFillStyle(titleFontColor); + context.fillText(title, _startX, _startY); + context.stroke(); + context.closePath(); + } +} + +function drawPointText(points, series, config, context) { + // 绘制数据文案 + var data = series.data; + + context.beginPath(); + context.setFontSize(config.fontSize); + context.setFillStyle('#666666'); + points.forEach(function (item, index) { + if (item !== null) { + var formatVal = series.format ? series.format(data[index]) : data[index]; + context.fillText(formatVal, item.x - measureText(formatVal) / 2, item.y - 2); + } + }); + context.closePath(); + context.stroke(); +} + +function drawRadarLabel(angleList, radius, centerPosition, opts, config, context) { + var radarOption = opts.extra.radar || {}; + radius += config.radarLabelTextMargin; + context.beginPath(); + context.setFontSize(config.fontSize); + context.setFillStyle(radarOption.labelColor || '#666666'); + angleList.forEach(function (angle, index) { + var pos = { + x: radius * Math.cos(angle), + y: radius * Math.sin(angle) + }; + var posRelativeCanvas = convertCoordinateOrigin(pos.x, pos.y, centerPosition); + var startX = posRelativeCanvas.x; + var startY = posRelativeCanvas.y; + if (util.approximatelyEqual(pos.x, 0)) { + startX -= measureText(opts.categories[index] || '') / 2; + } else if (pos.x < 0) { + startX -= measureText(opts.categories[index] || ''); + } + context.fillText(opts.categories[index] || '', startX, startY + config.fontSize / 2); + }); + context.stroke(); + context.closePath(); +} + +function drawPieText(series, opts, config, context, radius, center) { + var lineRadius = radius + config.pieChartLinePadding; + var textObjectCollection = []; + var lastTextObject = null; + + var seriesConvert = series.map(function (item) { + var arc = 2 * Math.PI - (item._start_ + 2 * Math.PI * item._proportion_ / 2); + var text = item.format ? item.format(+item._proportion_.toFixed(2)) : util.toFixed(item._proportion_ * 100) + '%'; + var color = item.color; + return { arc: arc, text: text, color: color }; + }); + seriesConvert.forEach(function (item) { + // line end + var orginX1 = Math.cos(item.arc) * lineRadius; + var orginY1 = Math.sin(item.arc) * lineRadius; + + // line start + var orginX2 = Math.cos(item.arc) * radius; + var orginY2 = Math.sin(item.arc) * radius; + + // text start + var orginX3 = orginX1 >= 0 ? orginX1 + config.pieChartTextPadding : orginX1 - config.pieChartTextPadding; + var orginY3 = orginY1; + + var textWidth = measureText(item.text); + var startY = orginY3; + + if (lastTextObject && util.isSameXCoordinateArea(lastTextObject.start, { x: orginX3 })) { + if (orginX3 > 0) { + startY = Math.min(orginY3, lastTextObject.start.y); + } else if (orginX1 < 0) { + startY = Math.max(orginY3, lastTextObject.start.y); + } else { + if (orginY3 > 0) { + startY = Math.max(orginY3, lastTextObject.start.y); + } else { + startY = Math.min(orginY3, lastTextObject.start.y); + } + } + } + + if (orginX3 < 0) { + orginX3 -= textWidth; + } + + var textObject = { + lineStart: { + x: orginX2, + y: orginY2 + }, + lineEnd: { + x: orginX1, + y: orginY1 + }, + start: { + x: orginX3, + y: startY + }, + width: textWidth, + height: config.fontSize, + text: item.text, + color: item.color + }; + + lastTextObject = avoidCollision(textObject, lastTextObject); + textObjectCollection.push(lastTextObject); + }); + + textObjectCollection.forEach(function (item) { + var lineStartPoistion = convertCoordinateOrigin(item.lineStart.x, item.lineStart.y, center); + var lineEndPoistion = convertCoordinateOrigin(item.lineEnd.x, item.lineEnd.y, center); + var textPosition = convertCoordinateOrigin(item.start.x, item.start.y, center); + context.setLineWidth(1); + context.setFontSize(config.fontSize); + context.beginPath(); + context.setStrokeStyle(item.color); + context.setFillStyle(item.color); + context.moveTo(lineStartPoistion.x, lineStartPoistion.y); + var curveStartX = item.start.x < 0 ? textPosition.x + item.width : textPosition.x; + var textStartX = item.start.x < 0 ? textPosition.x - 5 : textPosition.x + 5; + context.quadraticCurveTo(lineEndPoistion.x, lineEndPoistion.y, curveStartX, textPosition.y); + context.moveTo(lineStartPoistion.x, lineStartPoistion.y); + context.stroke(); + context.closePath(); + context.beginPath(); + context.moveTo(textPosition.x + item.width, textPosition.y); + context.arc(curveStartX, textPosition.y, 2, 0, 2 * Math.PI); + context.closePath(); + context.fill(); + context.beginPath(); + context.setFillStyle('#666666'); + context.fillText(item.text, textStartX, textPosition.y + 3); + context.closePath(); + context.stroke(); + + context.closePath(); + }); +} + +function drawToolTipSplitLine(offsetX, opts, config, context) { + var startY = config.padding; + var endY = opts.height - config.padding - config.xAxisHeight - config.legendHeight; + context.beginPath(); + context.setStrokeStyle('#cccccc'); + context.setLineWidth(1); + context.moveTo(offsetX, startY); + context.lineTo(offsetX, endY); + context.stroke(); + context.closePath(); +} + +function drawToolTip(textList, offset, opts, config, context) { + var legendWidth = 4; + var legendMarginRight = 5; + var arrowWidth = 8; + var isOverRightBorder = false; + offset = assign({ + x: 0, + y: 0 + }, offset); + offset.y -= 8; + var textWidth = textList.map(function (item) { + return measureText(item.text); + }); + + var toolTipWidth = legendWidth + legendMarginRight + 4 * config.toolTipPadding + Math.max.apply(null, textWidth); + var toolTipHeight = 2 * config.toolTipPadding + textList.length * config.toolTipLineHeight; + + // if beyond the right border + if (offset.x - Math.abs(opts._scrollDistance_) + arrowWidth + toolTipWidth > opts.width) { + isOverRightBorder = true; + } + + // draw background rect + context.beginPath(); + context.setFillStyle(opts.tooltip.option.background || config.toolTipBackground); + context.setGlobalAlpha(config.toolTipOpacity); + if (isOverRightBorder) { + context.moveTo(offset.x, offset.y + 10); + context.lineTo(offset.x - arrowWidth, offset.y + 10 - 5); + context.lineTo(offset.x - arrowWidth, offset.y + 10 + 5); + context.moveTo(offset.x, offset.y + 10); + context.fillRect(offset.x - toolTipWidth - arrowWidth, offset.y, toolTipWidth, toolTipHeight); + } else { + context.moveTo(offset.x, offset.y + 10); + context.lineTo(offset.x + arrowWidth, offset.y + 10 - 5); + context.lineTo(offset.x + arrowWidth, offset.y + 10 + 5); + context.moveTo(offset.x, offset.y + 10); + context.fillRect(offset.x + arrowWidth, offset.y, toolTipWidth, toolTipHeight); + } + + context.closePath(); + context.fill(); + context.setGlobalAlpha(1); + + // draw legend + textList.forEach(function (item, index) { + context.beginPath(); + context.setFillStyle(item.color); + var startX = offset.x + arrowWidth + 2 * config.toolTipPadding; + var startY = offset.y + (config.toolTipLineHeight - config.fontSize) / 2 + config.toolTipLineHeight * index + config.toolTipPadding; + if (isOverRightBorder) { + startX = offset.x - toolTipWidth - arrowWidth + 2 * config.toolTipPadding; + } + context.fillRect(startX, startY, legendWidth, config.fontSize); + context.closePath(); + }); + + // draw text list + context.beginPath(); + context.setFontSize(config.fontSize); + context.setFillStyle('#ffffff'); + textList.forEach(function (item, index) { + var startX = offset.x + arrowWidth + 2 * config.toolTipPadding + legendWidth + legendMarginRight; + if (isOverRightBorder) { + startX = offset.x - toolTipWidth - arrowWidth + 2 * config.toolTipPadding + +legendWidth + legendMarginRight; + } + var startY = offset.y + (config.toolTipLineHeight - config.fontSize) / 2 + config.toolTipLineHeight * index + config.toolTipPadding; + context.fillText(item.text, startX, startY + config.fontSize); + }); + context.stroke(); + context.closePath(); +} + +function drawYAxisTitle(title, opts, config, context) { + var startX = config.xAxisHeight + (opts.height - config.xAxisHeight - measureText(title)) / 2; + context.save(); + context.beginPath(); + context.setFontSize(config.fontSize); + context.setFillStyle(opts.yAxis.titleFontColor || '#333333'); + context.translate(0, opts.height); + context.rotate(-90 * Math.PI / 180); + context.fillText(title, startX, config.padding + 0.5 * config.fontSize); + context.stroke(); + context.closePath(); + context.restore(); +} + +function drawColumnDataPoints(series, opts, config, context) { + var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; + + var _calYAxisData = calYAxisData(series, opts, config), + ranges = _calYAxisData.ranges; + + var _getXAxisPoints = getXAxisPoints(opts.categories, opts, config), + xAxisPoints = _getXAxisPoints.xAxisPoints, + eachSpacing = _getXAxisPoints.eachSpacing; + + var minRange = ranges.pop(); + var maxRange = ranges.shift(); + context.save(); + if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { + context.translate(opts._scrollDistance_, 0); + } + + series.forEach(function (eachSeries, seriesIndex) { + var data = eachSeries.data; + var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); + points = fixColumeData(points, eachSpacing, series.length, seriesIndex, config, opts); + + // 绘制柱状数据图 + context.beginPath(); + context.setFillStyle(eachSeries.color); + points.forEach(function (item, index) { + if (item !== null) { + var startX = item.x - item.width / 2 + 1; + var height = opts.height - item.y - config.padding - config.xAxisHeight - config.legendHeight; + context.moveTo(startX, item.y); + context.rect(startX, item.y, item.width - 2, height); + } + }); + context.closePath(); + context.fill(); + }); + series.forEach(function (eachSeries, seriesIndex) { + var data = eachSeries.data; + var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); + points = fixColumeData(points, eachSpacing, series.length, seriesIndex, config, opts); + if (opts.dataLabel !== false && process === 1) { + drawPointText(points, eachSeries, config, context); + } + }); + context.restore(); + return { + xAxisPoints: xAxisPoints, + eachSpacing: eachSpacing + }; +} + +function drawAreaDataPoints(series, opts, config, context) { + var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; + + var _calYAxisData2 = calYAxisData(series, opts, config), + ranges = _calYAxisData2.ranges; + + var _getXAxisPoints2 = getXAxisPoints(opts.categories, opts, config), + xAxisPoints = _getXAxisPoints2.xAxisPoints, + eachSpacing = _getXAxisPoints2.eachSpacing; + + var minRange = ranges.pop(); + var maxRange = ranges.shift(); + var endY = opts.height - config.padding - config.xAxisHeight - config.legendHeight; + var calPoints = []; + + context.save(); + if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { + context.translate(opts._scrollDistance_, 0); + } + + if (opts.tooltip && opts.tooltip.textList && opts.tooltip.textList.length && process === 1) { + drawToolTipSplitLine(opts.tooltip.offset.x, opts, config, context); + } + + series.forEach(function (eachSeries, seriesIndex) { + var data = eachSeries.data; + var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); + calPoints.push(points); + + var splitPointList = splitPoints(points); + + splitPointList.forEach(function (points) { + // 绘制区域数据 + context.beginPath(); + context.setStrokeStyle(eachSeries.color); + context.setFillStyle(eachSeries.color); + context.setGlobalAlpha(0.6); + context.setLineWidth(2); + if (points.length > 1) { + var firstPoint = points[0]; + var lastPoint = points[points.length - 1]; + + context.moveTo(firstPoint.x, firstPoint.y); + if (opts.extra.lineStyle === 'curve') { + points.forEach(function (item, index) { + if (index > 0) { + var ctrlPoint = createCurveControlPoints(points, index - 1); + context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y); + } + }); + } else { + points.forEach(function (item, index) { + if (index > 0) { + context.lineTo(item.x, item.y); + } + }); + } + + context.lineTo(lastPoint.x, endY); + context.lineTo(firstPoint.x, endY); + context.lineTo(firstPoint.x, firstPoint.y); + } else { + var item = points[0]; + context.moveTo(item.x - eachSpacing / 2, item.y); + context.lineTo(item.x + eachSpacing / 2, item.y); + context.lineTo(item.x + eachSpacing / 2, endY); + context.lineTo(item.x - eachSpacing / 2, endY); + context.moveTo(item.x - eachSpacing / 2, item.y); + } + context.closePath(); + context.fill(); + context.setGlobalAlpha(1); + }); + + if (opts.dataPointShape !== false) { + var shape = config.dataPointShape[seriesIndex % config.dataPointShape.length]; + drawPointShape(points, eachSeries.color, shape, context); + } + }); + if (opts.dataLabel !== false && process === 1) { + series.forEach(function (eachSeries, seriesIndex) { + var data = eachSeries.data; + var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); + drawPointText(points, eachSeries, config, context); + }); + } + + context.restore(); + + return { + xAxisPoints: xAxisPoints, + calPoints: calPoints, + eachSpacing: eachSpacing + }; +} + +function drawLineDataPoints(series, opts, config, context) { + var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; + + var _calYAxisData3 = calYAxisData(series, opts, config), + ranges = _calYAxisData3.ranges; + + var _getXAxisPoints3 = getXAxisPoints(opts.categories, opts, config), + xAxisPoints = _getXAxisPoints3.xAxisPoints, + eachSpacing = _getXAxisPoints3.eachSpacing; + + var minRange = ranges.pop(); + var maxRange = ranges.shift(); + var calPoints = []; + + context.save(); + if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { + context.translate(opts._scrollDistance_, 0); + } + + if (opts.tooltip && opts.tooltip.textList && opts.tooltip.textList.length && process === 1) { + drawToolTipSplitLine(opts.tooltip.offset.x, opts, config, context); + } + + series.forEach(function (eachSeries, seriesIndex) { + var data = eachSeries.data; + var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); + calPoints.push(points); + var splitPointList = splitPoints(points); + + splitPointList.forEach(function (points, index) { + context.beginPath(); + context.setStrokeStyle(eachSeries.color); + context.setLineWidth(2); + if (points.length === 1) { + context.moveTo(points[0].x, points[0].y); + context.arc(points[0].x, points[0].y, 1, 0, 2 * Math.PI); + } else { + context.moveTo(points[0].x, points[0].y); + if (opts.extra.lineStyle === 'curve') { + points.forEach(function (item, index) { + if (index > 0) { + var ctrlPoint = createCurveControlPoints(points, index - 1); + context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y); + } + }); + } else { + points.forEach(function (item, index) { + if (index > 0) { + context.lineTo(item.x, item.y); + } + }); + } + context.moveTo(points[0].x, points[0].y); + } + context.closePath(); + context.stroke(); + }); + + if (opts.dataPointShape !== false) { + var shape = config.dataPointShape[seriesIndex % config.dataPointShape.length]; + drawPointShape(points, eachSeries.color, shape, context); + } + }); + if (opts.dataLabel !== false && process === 1) { + series.forEach(function (eachSeries, seriesIndex) { + var data = eachSeries.data; + var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); + drawPointText(points, eachSeries, config, context); + }); + } + + context.restore(); + + return { + xAxisPoints: xAxisPoints, + calPoints: calPoints, + eachSpacing: eachSpacing + }; +} + +function drawToolTipBridge(opts, config, context, process) { + context.save(); + if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { + context.translate(opts._scrollDistance_, 0); + } + if (opts.tooltip && opts.tooltip.textList && opts.tooltip.textList.length && process === 1) { + drawToolTip(opts.tooltip.textList, opts.tooltip.offset, opts, config, context); + } + context.restore(); +} + +function drawXAxis(categories, opts, config, context) { + var _getXAxisPoints4 = getXAxisPoints(categories, opts, config), + xAxisPoints = _getXAxisPoints4.xAxisPoints, + startX = _getXAxisPoints4.startX, + endX = _getXAxisPoints4.endX, + eachSpacing = _getXAxisPoints4.eachSpacing; + + var startY = opts.height - config.padding - config.xAxisHeight - config.legendHeight; + var endY = startY + config.xAxisLineHeight; + + context.save(); + if (opts._scrollDistance_ && opts._scrollDistance_ !== 0) { + context.translate(opts._scrollDistance_, 0); + } + + context.beginPath(); + context.setStrokeStyle(opts.xAxis.gridColor || "#cccccc"); + + if (opts.xAxis.disableGrid !== true) { + if (opts.xAxis.type === 'calibration') { + xAxisPoints.forEach(function (item, index) { + if (index > 0) { + context.moveTo(item - eachSpacing / 2, startY); + context.lineTo(item - eachSpacing / 2, startY + 4); + } + }); + } else { + xAxisPoints.forEach(function (item, index) { + context.moveTo(item, startY); + context.lineTo(item, endY); + }); + } + } + context.closePath(); + context.stroke(); + + // 对X轴列表做抽稀处理 + var validWidth = opts.width - 2 * config.padding - config.yAxisWidth - config.yAxisTitleWidth; + var maxXAxisListLength = Math.min(categories.length, Math.ceil(validWidth / config.fontSize / 1.5)); + var ratio = Math.ceil(categories.length / maxXAxisListLength); + + categories = categories.map(function (item, index) { + return index % ratio !== 0 ? '' : item; + }); + + if (config._xAxisTextAngle_ === 0) { + context.beginPath(); + context.setFontSize(config.fontSize); + context.setFillStyle(opts.xAxis.fontColor || '#666666'); + categories.forEach(function (item, index) { + var offset = eachSpacing / 2 - measureText(item) / 2; + context.fillText(item, xAxisPoints[index] + offset, startY + config.fontSize + 5); + }); + context.closePath(); + context.stroke(); + } else { + categories.forEach(function (item, index) { + context.save(); + context.beginPath(); + context.setFontSize(config.fontSize); + context.setFillStyle(opts.xAxis.fontColor || '#666666'); + var textWidth = measureText(item); + var offset = eachSpacing / 2 - textWidth; + + var _calRotateTranslate = calRotateTranslate(xAxisPoints[index] + eachSpacing / 2, startY + config.fontSize / 2 + 5, opts.height), + transX = _calRotateTranslate.transX, + transY = _calRotateTranslate.transY; + + context.rotate(-1 * config._xAxisTextAngle_); + context.translate(transX, transY); + context.fillText(item, xAxisPoints[index] + offset, startY + config.fontSize + 5); + context.closePath(); + context.stroke(); + context.restore(); + }); + } + + context.restore(); +} + +function drawYAxisGrid(opts, config, context) { + var spacingValid = opts.height - 2 * config.padding - config.xAxisHeight - config.legendHeight; + var eachSpacing = Math.floor(spacingValid / config.yAxisSplit); + var yAxisTotalWidth = config.yAxisWidth + config.yAxisTitleWidth; + var startX = config.padding + yAxisTotalWidth; + var endX = opts.width - config.padding; + + var points = []; + for (var i = 0; i < config.yAxisSplit; i++) { + points.push(config.padding + eachSpacing * i); + } + points.push(config.padding + eachSpacing * config.yAxisSplit + 2); + + context.beginPath(); + context.setStrokeStyle(opts.yAxis.gridColor || "#cccccc"); + context.setLineWidth(1); + points.forEach(function (item, index) { + context.moveTo(startX, item); + context.lineTo(endX, item); + }); + context.closePath(); + context.stroke(); +} + +function drawYAxis(series, opts, config, context) { + if (opts.yAxis.disabled === true) { + return; + } + + var _calYAxisData4 = calYAxisData(series, opts, config), + rangesFormat = _calYAxisData4.rangesFormat; + + var yAxisTotalWidth = config.yAxisWidth + config.yAxisTitleWidth; + + var spacingValid = opts.height - 2 * config.padding - config.xAxisHeight - config.legendHeight; + var eachSpacing = Math.floor(spacingValid / config.yAxisSplit); + var startX = config.padding + yAxisTotalWidth; + var endX = opts.width - config.padding; + var endY = opts.height - config.padding - config.xAxisHeight - config.legendHeight; + + // set YAxis background + context.setFillStyle(opts.background || '#ffffff'); + if (opts._scrollDistance_ < 0) { + context.fillRect(0, 0, startX, endY + config.xAxisHeight + 5); + } + context.fillRect(endX, 0, opts.width, endY + config.xAxisHeight + 5); + + var points = []; + for (var i = 0; i <= config.yAxisSplit; i++) { + points.push(config.padding + eachSpacing * i); + } + + context.stroke(); + context.beginPath(); + context.setFontSize(config.fontSize); + context.setFillStyle(opts.yAxis.fontColor || '#666666'); + rangesFormat.forEach(function (item, index) { + var pos = points[index] ? points[index] : endY; + context.fillText(item, config.padding + config.yAxisTitleWidth, pos + config.fontSize / 2); + }); + context.closePath(); + context.stroke(); + + if (opts.yAxis.title) { + drawYAxisTitle(opts.yAxis.title, opts, config, context); + } +} + +function drawLegend(series, opts, config, context) { + if (!opts.legend) { + return; + } + // each legend shape width 15px + // the spacing between shape and text in each legend is the `padding` + // each legend spacing is the `padding` + // legend margin top `config.padding` + + var _calLegendData = calLegendData(series, opts, config), + legendList = _calLegendData.legendList; + + var padding = 5; + var marginTop = 8; + var shapeWidth = 15; + legendList.forEach(function (itemList, listIndex) { + var width = 0; + itemList.forEach(function (item) { + item.name = item.name || 'undefined'; + width += 3 * padding + measureText(item.name) + shapeWidth; + }); + var startX = (opts.width - width) / 2 + padding; + var startY = opts.height - config.padding - config.legendHeight + listIndex * (config.fontSize + marginTop) + padding + marginTop; + + context.setFontSize(config.fontSize); + itemList.forEach(function (item) { + switch (opts.type) { + case 'line': + context.beginPath(); + context.setLineWidth(1); + context.setStrokeStyle(item.color); + context.moveTo(startX - 2, startY + 5); + context.lineTo(startX + 17, startY + 5); + context.stroke(); + context.closePath(); + context.beginPath(); + context.setLineWidth(1); + context.setStrokeStyle('#ffffff'); + context.setFillStyle(item.color); + context.moveTo(startX + 7.5, startY + 5); + context.arc(startX + 7.5, startY + 5, 4, 0, 2 * Math.PI); + context.fill(); + context.stroke(); + context.closePath(); + break; + case 'pie': + case 'ring': + context.beginPath(); + context.setFillStyle(item.color); + context.moveTo(startX + 7.5, startY + 5); + context.arc(startX + 7.5, startY + 5, 7, 0, 2 * Math.PI); + context.closePath(); + context.fill(); + break; + default: + context.beginPath(); + context.setFillStyle(item.color); + context.moveTo(startX, startY); + context.rect(startX, startY, 15, 10); + context.closePath(); + context.fill(); + } + startX += padding + shapeWidth; + context.beginPath(); + context.setFillStyle(opts.extra.legendTextColor || '#333333'); + context.fillText(item.name, startX, startY + 9); + context.closePath(); + context.stroke(); + startX += measureText(item.name) + 2 * padding; + }); + }); +} +function drawPieDataPoints(series, opts, config, context) { + var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; + + var pieOption = opts.extra.pie || {}; + series = getPieDataPoints(series, process); + var centerPosition = { + x: opts.width / 2, + y: (opts.height - config.legendHeight) / 2 + }; + var radius = Math.min(centerPosition.x - config.pieChartLinePadding - config.pieChartTextPadding - config._pieTextMaxLength_, centerPosition.y - config.pieChartLinePadding - config.pieChartTextPadding); + if (opts.dataLabel) { + radius -= 10; + } else { + radius -= 2 * config.padding; + } + series = series.map(function (eachSeries) { + eachSeries._start_ += (pieOption.offsetAngle || 0) * Math.PI / 180; + return eachSeries; + }); + series.forEach(function (eachSeries) { + context.beginPath(); + context.setLineWidth(2); + context.setStrokeStyle('#ffffff'); + context.setFillStyle(eachSeries.color); + context.moveTo(centerPosition.x, centerPosition.y); + context.arc(centerPosition.x, centerPosition.y, radius, eachSeries._start_, eachSeries._start_ + 2 * eachSeries._proportion_ * Math.PI); + context.closePath(); + context.fill(); + if (opts.disablePieStroke !== true) { + context.stroke(); + } + }); + + if (opts.type === 'ring') { + var innerPieWidth = radius * 0.6; + if (typeof opts.extra.ringWidth === 'number' && opts.extra.ringWidth > 0) { + innerPieWidth = Math.max(0, radius - opts.extra.ringWidth); + } + context.beginPath(); + context.setFillStyle(opts.background || '#ffffff'); + context.moveTo(centerPosition.x, centerPosition.y); + context.arc(centerPosition.x, centerPosition.y, innerPieWidth, 0, 2 * Math.PI); + context.closePath(); + context.fill(); + } + + if (opts.dataLabel !== false && process === 1) { + // fix https://github.com/xiaolin3303/wx-charts/issues/132 + var valid = false; + for (var i = 0, len = series.length; i < len; i++) { + if (series[i].data > 0) { + valid = true; + break; + } + } + + if (valid) { + drawPieText(series, opts, config, context, radius, centerPosition); + } + } + + if (process === 1 && opts.type === 'ring') { + drawRingTitle(opts, config, context); + } + + return { + center: centerPosition, + radius: radius, + series: series + }; +} + +function drawRadarDataPoints(series, opts, config, context) { + var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; + + var radarOption = opts.extra.radar || {}; + var coordinateAngle = getRadarCoordinateSeries(opts.categories.length); + var centerPosition = { + x: opts.width / 2, + y: (opts.height - config.legendHeight) / 2 + }; + + var radius = Math.min(centerPosition.x - (getMaxTextListLength(opts.categories) + config.radarLabelTextMargin), centerPosition.y - config.radarLabelTextMargin); + + radius -= config.padding; + + // draw grid + context.beginPath(); + context.setLineWidth(1); + context.setStrokeStyle(radarOption.gridColor || "#cccccc"); + coordinateAngle.forEach(function (angle) { + var pos = convertCoordinateOrigin(radius * Math.cos(angle), radius * Math.sin(angle), centerPosition); + context.moveTo(centerPosition.x, centerPosition.y); + context.lineTo(pos.x, pos.y); + }); + context.stroke(); + context.closePath(); + + // draw split line grid + + var _loop = function _loop(i) { + var startPos = {}; + context.beginPath(); + context.setLineWidth(1); + context.setStrokeStyle(radarOption.gridColor || "#cccccc"); + coordinateAngle.forEach(function (angle, index) { + var pos = convertCoordinateOrigin(radius / config.radarGridCount * i * Math.cos(angle), radius / config.radarGridCount * i * Math.sin(angle), centerPosition); + if (index === 0) { + startPos = pos; + context.moveTo(pos.x, pos.y); + } else { + context.lineTo(pos.x, pos.y); + } + }); + context.lineTo(startPos.x, startPos.y); + context.stroke(); + context.closePath(); + }; + + for (var i = 1; i <= config.radarGridCount; i++) { + _loop(i); + } + + var radarDataPoints = getRadarDataPoints(coordinateAngle, centerPosition, radius, series, opts, process); + radarDataPoints.forEach(function (eachSeries, seriesIndex) { + // 绘制区域数据 + context.beginPath(); + context.setFillStyle(eachSeries.color); + context.setGlobalAlpha(0.6); + eachSeries.data.forEach(function (item, index) { + if (index === 0) { + context.moveTo(item.position.x, item.position.y); + } else { + context.lineTo(item.position.x, item.position.y); + } + }); + context.closePath(); + context.fill(); + context.setGlobalAlpha(1); + + if (opts.dataPointShape !== false) { + var shape = config.dataPointShape[seriesIndex % config.dataPointShape.length]; + var points = eachSeries.data.map(function (item) { + return item.position; + }); + drawPointShape(points, eachSeries.color, shape, context); + } + }); + // draw label text + drawRadarLabel(coordinateAngle, radius, centerPosition, opts, config, context); + + return { + center: centerPosition, + radius: radius, + angleList: coordinateAngle + }; +} + +function drawCanvas(opts, context) { + context.draw(); +} + +var Timing = { + easeIn: function easeIn(pos) { + return Math.pow(pos, 3); + }, + + easeOut: function easeOut(pos) { + return Math.pow(pos - 1, 3) + 1; + }, + + easeInOut: function easeInOut(pos) { + if ((pos /= 0.5) < 1) { + return 0.5 * Math.pow(pos, 3); + } else { + return 0.5 * (Math.pow(pos - 2, 3) + 2); + } + }, + + linear: function linear(pos) { + return pos; + } +}; + +function Animation(opts) { + this.isStop = false; + opts.duration = typeof opts.duration === 'undefined' ? 1000 : opts.duration; + opts.timing = opts.timing || 'linear'; + + var delay = 17; + + var createAnimationFrame = function createAnimationFrame() { + if (typeof requestAnimationFrame !== 'undefined') { + return requestAnimationFrame; + } else if (typeof setTimeout !== 'undefined') { + return function (step, delay) { + setTimeout(function () { + var timeStamp = +new Date(); + step(timeStamp); + }, delay); + }; + } else { + return function (step) { + step(null); + }; + } + }; + var animationFrame = createAnimationFrame(); + var startTimeStamp = null; + var _step = function step(timestamp) { + if (timestamp === null || this.isStop === true) { + opts.onProcess && opts.onProcess(1); + opts.onAnimationFinish && opts.onAnimationFinish(); + return; + } + if (startTimeStamp === null) { + startTimeStamp = timestamp; + } + if (timestamp - startTimeStamp < opts.duration) { + var process = (timestamp - startTimeStamp) / opts.duration; + var timingFunction = Timing[opts.timing]; + process = timingFunction(process); + opts.onProcess && opts.onProcess(process); + animationFrame(_step, delay); + } else { + opts.onProcess && opts.onProcess(1); + opts.onAnimationFinish && opts.onAnimationFinish(); + } + }; + _step = _step.bind(this); + + animationFrame(_step, delay); +} + +// stop animation immediately +// and tigger onAnimationFinish +Animation.prototype.stop = function () { + this.isStop = true; +}; + +function drawCharts(type, opts, config, context) { + var _this = this; + + var series = opts.series; + var categories = opts.categories; + series = fillSeriesColor(series, config); + + var _calLegendData = calLegendData(series, opts, config), + legendHeight = _calLegendData.legendHeight; + + config.legendHeight = legendHeight; + + var _calYAxisData = calYAxisData(series, opts, config), + yAxisWidth = _calYAxisData.yAxisWidth; + + config.yAxisWidth = yAxisWidth; + if (categories && categories.length) { + var _calCategoriesData = calCategoriesData(categories, opts, config), + xAxisHeight = _calCategoriesData.xAxisHeight, + angle = _calCategoriesData.angle; + + config.xAxisHeight = xAxisHeight; + config._xAxisTextAngle_ = angle; + } + if (type === 'pie' || type === 'ring') { + config._pieTextMaxLength_ = opts.dataLabel === false ? 0 : getPieTextMaxLength(series); + } + + var duration = opts.animation ? 1000 : 0; + this.animationInstance && this.animationInstance.stop(); + switch (type) { + case 'line': + this.animationInstance = new Animation({ + timing: 'easeIn', + duration: duration, + onProcess: function onProcess(process) { + drawYAxisGrid(opts, config, context); + + var _drawLineDataPoints = drawLineDataPoints(series, opts, config, context, process), + xAxisPoints = _drawLineDataPoints.xAxisPoints, + calPoints = _drawLineDataPoints.calPoints, + eachSpacing = _drawLineDataPoints.eachSpacing; + + _this.chartData.xAxisPoints = xAxisPoints; + _this.chartData.calPoints = calPoints; + _this.chartData.eachSpacing = eachSpacing; + drawXAxis(categories, opts, config, context); + drawLegend(opts.series, opts, config, context); + drawYAxis(series, opts, config, context); + drawToolTipBridge(opts, config, context, process); + drawCanvas(opts, context); + }, + onAnimationFinish: function onAnimationFinish() { + _this.event.trigger('renderComplete'); + } + }); + break; + case 'column': + this.animationInstance = new Animation({ + timing: 'easeIn', + duration: duration, + onProcess: function onProcess(process) { + drawYAxisGrid(opts, config, context); + + var _drawColumnDataPoints = drawColumnDataPoints(series, opts, config, context, process), + xAxisPoints = _drawColumnDataPoints.xAxisPoints, + eachSpacing = _drawColumnDataPoints.eachSpacing; + + _this.chartData.xAxisPoints = xAxisPoints; + _this.chartData.eachSpacing = eachSpacing; + drawXAxis(categories, opts, config, context); + drawLegend(opts.series, opts, config, context); + drawYAxis(series, opts, config, context); + drawCanvas(opts, context); + }, + onAnimationFinish: function onAnimationFinish() { + _this.event.trigger('renderComplete'); + } + }); + break; + case 'area': + this.animationInstance = new Animation({ + timing: 'easeIn', + duration: duration, + onProcess: function onProcess(process) { + drawYAxisGrid(opts, config, context); + + var _drawAreaDataPoints = drawAreaDataPoints(series, opts, config, context, process), + xAxisPoints = _drawAreaDataPoints.xAxisPoints, + calPoints = _drawAreaDataPoints.calPoints, + eachSpacing = _drawAreaDataPoints.eachSpacing; + + _this.chartData.xAxisPoints = xAxisPoints; + _this.chartData.calPoints = calPoints; + _this.chartData.eachSpacing = eachSpacing; + drawXAxis(categories, opts, config, context); + drawLegend(opts.series, opts, config, context); + drawYAxis(series, opts, config, context); + drawToolTipBridge(opts, config, context, process); + drawCanvas(opts, context); + }, + onAnimationFinish: function onAnimationFinish() { + _this.event.trigger('renderComplete'); + } + }); + break; + case 'ring': + case 'pie': + this.animationInstance = new Animation({ + timing: 'easeInOut', + duration: duration, + onProcess: function onProcess(process) { + _this.chartData.pieData = drawPieDataPoints(series, opts, config, context, process); + drawLegend(opts.series, opts, config, context); + drawCanvas(opts, context); + }, + onAnimationFinish: function onAnimationFinish() { + _this.event.trigger('renderComplete'); + } + }); + break; + case 'radar': + this.animationInstance = new Animation({ + timing: 'easeInOut', + duration: duration, + onProcess: function onProcess(process) { + _this.chartData.radarData = drawRadarDataPoints(series, opts, config, context, process); + drawLegend(opts.series, opts, config, context); + drawCanvas(opts, context); + }, + onAnimationFinish: function onAnimationFinish() { + _this.event.trigger('renderComplete'); + } + }); + break; + } +} + +// simple event implement + +function Event() { + this.events = {}; +} + +Event.prototype.addEventListener = function (type, listener) { + this.events[type] = this.events[type] || []; + this.events[type].push(listener); +}; + +Event.prototype.trigger = function () { + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + var type = args[0]; + var params = args.slice(1); + if (!!this.events[type]) { + this.events[type].forEach(function (listener) { + try { + listener.apply(null, params); + } catch (e) { + console.error(e); + } + }); + } +}; + +var Charts = function Charts(opts) { + opts.title = opts.title || {}; + opts.subtitle = opts.subtitle || {}; + opts.yAxis = opts.yAxis || {}; + opts.xAxis = opts.xAxis || {}; + opts.extra = opts.extra || {}; + opts.legend = opts.legend === false ? false : true; + opts.animation = opts.animation === false ? false : true; + var config$$1 = assign({}, config); + config$$1.yAxisTitleWidth = opts.yAxis.disabled !== true && opts.yAxis.title ? config$$1.yAxisTitleWidth : 0; + config$$1.pieChartLinePadding = opts.dataLabel === false ? 0 : config$$1.pieChartLinePadding; + config$$1.pieChartTextPadding = opts.dataLabel === false ? 0 : config$$1.pieChartTextPadding; + + this.opts = opts; + this.config = config$$1; + this.context = wx.createCanvasContext(opts.canvasId); + // store calcuated chart data + // such as chart point coordinate + this.chartData = {}; + this.event = new Event(); + this.scrollOption = { + currentOffset: 0, + startTouchX: 0, + distance: 0 + }; + + drawCharts.call(this, opts.type, opts, config$$1, this.context); +}; + +Charts.prototype.updateData = function () { + var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + this.opts.series = data.series || this.opts.series; + this.opts.categories = data.categories || this.opts.categories; + + this.opts.title = assign({}, this.opts.title, data.title || {}); + this.opts.subtitle = assign({}, this.opts.subtitle, data.subtitle || {}); + + drawCharts.call(this, this.opts.type, this.opts, this.config, this.context); +}; + +Charts.prototype.stopAnimation = function () { + this.animationInstance && this.animationInstance.stop(); +}; + +Charts.prototype.addEventListener = function (type, listener) { + this.event.addEventListener(type, listener); +}; + +Charts.prototype.getCurrentDataIndex = function (e) { + var touches = e.touches && e.touches.length ? e.touches : e.changedTouches; + if (touches && touches.length) { + var _touches$ = touches[0], + x = _touches$.x, + y = _touches$.y; + + if (this.opts.type === 'pie' || this.opts.type === 'ring') { + return findPieChartCurrentIndex({ x: x, y: y }, this.chartData.pieData); + } else if (this.opts.type === 'radar') { + return findRadarChartCurrentIndex({ x: x, y: y }, this.chartData.radarData, this.opts.categories.length); + } else { + return findCurrentIndex({ x: x, y: y }, this.chartData.xAxisPoints, this.opts, this.config, Math.abs(this.scrollOption.currentOffset)); + } + } + return -1; +}; + +Charts.prototype.showToolTip = function (e) { + var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + if (this.opts.type === 'line' || this.opts.type === 'area') { + var index = this.getCurrentDataIndex(e); + var currentOffset = this.scrollOption.currentOffset; + + var opts = assign({}, this.opts, { + _scrollDistance_: currentOffset, + animation: false + }); + if (index > -1) { + var seriesData = getSeriesDataItem(this.opts.series, index); + if (seriesData.length === 0) { + drawCharts.call(this, opts.type, opts, this.config, this.context); + } else { + var _getToolTipData = getToolTipData(seriesData, this.chartData.calPoints, index, this.opts.categories, option), + textList = _getToolTipData.textList, + offset = _getToolTipData.offset; + + opts.tooltip = { + textList: textList, + offset: offset, + option: option + }; + drawCharts.call(this, opts.type, opts, this.config, this.context); + } + } else { + drawCharts.call(this, opts.type, opts, this.config, this.context); + } + } +}; + +Charts.prototype.scrollStart = function (e) { + if (e.touches[0] && this.opts.enableScroll === true) { + this.scrollOption.startTouchX = e.touches[0].x; + } +}; + +Charts.prototype.scroll = function (e) { + // TODO throtting... + if (e.touches[0] && this.opts.enableScroll === true) { + var _distance = e.touches[0].x - this.scrollOption.startTouchX; + var currentOffset = this.scrollOption.currentOffset; + + var validDistance = calValidDistance(currentOffset + _distance, this.chartData, this.config, this.opts); + + this.scrollOption.distance = _distance = validDistance - currentOffset; + var opts = assign({}, this.opts, { + _scrollDistance_: currentOffset + _distance, + animation: false + }); + + drawCharts.call(this, opts.type, opts, this.config, this.context); + } +}; + +Charts.prototype.scrollEnd = function (e) { + if (this.opts.enableScroll === true) { + var _scrollOption = this.scrollOption, + currentOffset = _scrollOption.currentOffset, + distance = _scrollOption.distance; + + this.scrollOption.currentOffset = currentOffset + distance; + this.scrollOption.distance = 0; + } +}; + +module.exports = Charts; diff --git a/miniprogram/pages/welcome/welcome.js b/miniprogram/pages/welcome/welcome.js new file mode 100644 index 0000000..525dce7 --- /dev/null +++ b/miniprogram/pages/welcome/welcome.js @@ -0,0 +1,66 @@ +// pages/welcome/welcome.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/miniprogram/pages/welcome/welcome.json b/miniprogram/pages/welcome/welcome.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/miniprogram/pages/welcome/welcome.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/welcome/welcome.wxml b/miniprogram/pages/welcome/welcome.wxml new file mode 100644 index 0000000..42d0c04 --- /dev/null +++ b/miniprogram/pages/welcome/welcome.wxml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/miniprogram/pages/welcome/welcome.wxss b/miniprogram/pages/welcome/welcome.wxss new file mode 100644 index 0000000..9c41cfe --- /dev/null +++ b/miniprogram/pages/welcome/welcome.wxss @@ -0,0 +1,15 @@ +/* pages/welcome/welcome.wxss */ +.allPage { + height: 100%; + width:100%; + overflow: hidden; +} +.welcome { + width: 100%; + height: 350rpx; + position: fixed; + bottom: 0px; +} +page { + background-color: #890000; +} diff --git a/miniprogram/sitemap.json b/miniprogram/sitemap.json new file mode 100644 index 0000000..ca02add --- /dev/null +++ b/miniprogram/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js deleted file mode 100644 index ef9f6ce..0000000 --- a/pages/index/index.js +++ /dev/null @@ -1,157 +0,0 @@ -// pages/index/index.js -const App = getApp(); -Page({ - - /** - * 页面的初始数据 - */ - data: { - right_num:0, - grade:0, - title: "主题团日知识竞答", - allData: [ - { - pngAdd: "https://gss0.baidu.com/-fo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/9d82d158ccbf6c81962c9e57b13eb13533fa4071.jpg", - // pngAdd: "http://powerrain.cn/styleDay/images/question_1.png", - question: "问题一:以下哪一项不是四信的内容?", - answers: [ - { name: 0, value: 'A:信念' }, - { name: 1, value: 'B:信仰' }, - { name: 2, value: 'C:信任' }, - { name: 3, value: 'D:信心' }, - ], - userAnswer:"", - rightAnswer:3, - illustrate:"‘信心’应为‘信赖’", - classState:"" - }, - { - pngAdd: "https://gss0.baidu.com/-Po3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/3801213fb80e7becbff3b15e222eb9389b506b60.jpg", - // pngAdd: "http://powerrain.cn/styleDay/images/question_2.png", - question: "问题二:关于以下说法,哪一项是不正确的?", - answers: [ - { name: 0, value: 'A:要成为新时代青年马克思主义者, 必须坚定对共产主义和中国特色社会主义的执着信仰' }, - { name: 1, value: 'B:要成为新时代青年马克思主义者, 只须练就高强的本领。' }, - { name: 2, value: 'C:要成为新时代青年马克思主义者, 必须常葆对人民群众的赤子之心' }, - { name: 3, value: 'D:要成为新时代青年马克思主义者, 必须树立为实现中华民族伟大复兴的中国梦而奋斗的使命担当' }, - ], - userAnswer: "", - rightAnswer: 1, - illustrate: "要成为新时代青年马克思主义者,必须练就高强的本领,“既要政治过硬, 也要本领高强, 这是党的十九大报告对全党的要求, 对于青年马克思主义者来讲也是完全适用的", - classState: "" - }, - { - pngAdd: "https://gss0.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/b90e7bec54e736d1c23a3eb796504fc2d5626960.jpg", - // pngAdd: "http://powerrain.cn/styleDay/images/question_3.png", - question: "问题三:马克思主义之所以是科学,仅仅在于它不再把自己的理论建立在主观臆想的基础上,而是建立在对现实社会进行科学研究的基础之上。", - answers: [ - { name: 0, value: 'A:正确' }, - { name: 1, value: 'B:错误' }, - ], - userAnswer: "", - rightAnswer: 1, - illustrate: "马克思主义之所以是科学,首先在于它不再把自己的理论建立在主观臆想的基础上,而是建立在对现实社会进行科学研究的基础之上。马克思主义之所以为科学,还在于它不断吸收科学研究的最新成果,而不是故步自封、自视为穷尽一切真理的宗教教义。", - classState: "" - }, - { - pngAdd: "https://gss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/4e4a20a4462309f7381b1fad7f0e0cf3d7cad61d.jpg", - // pngAdd: "http://powerrain.cn/styleDay/images/question_4.png", - question: "问题四:习主席曾言,办好中国的事情,关键在党。", - answers: [ - { name: 0, value: 'A:正确' }, - { name: 1, value: 'B:错误' }, - ], - userAnswer: "", - rightAnswer: 0, - illustrate: "习主席确实这么说的。", - classState: "" - } - ], - disabled: true - }, - - /** - * 生命周期函数--监听页面加载 - */ - onLoad: function (options) { - // wx.clearStorage(); - this.setData({ - navH: App.globalData.navHeight - }) - for (let i = 0; i < this.data.allData.length; i++) { - var j = i.toString(); - var info = wx.getStorageSync(j) - var str = "allData[" + i + "].userAnswer" - this.setData({ - [str]: parseInt(info) - }) - // this.data.allData[i].userAnswer = parseInt(info); - } - for (let i = 0; i < this.data.allData.length; i++) { - if (this.data.allData[i].userAnswer != this.data.allData[i].rightAnswer){ - var str = "allData[" + i + "].classState"; - this.setData({ - [str]: "item_error" - }) - }else { - var str = "allData[" + i + "].classState"; - this.setData({ - [str]: "item_right", - right_num:this.data.right_num+1 - }) - } - } - this.setData({ - grade:this.data.right_num*25 - }) - }, - - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { - - }, - - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - - }, - - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { - - }, - - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { - - }, - - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { - - }, - - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { - - }, - - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () { - - }, -}) \ No newline at end of file diff --git a/project.config.json b/project.config.json index e796f7c..5f1041b 100644 --- a/project.config.json +++ b/project.config.json @@ -1,5 +1,8 @@ { "description": "项目配置文件", + "cloud": true, + "cloudfunctionRoot": "cloudfunctions/", + "miniprogramRoot": "miniprogram/", "packOptions": { "ignore": [] }, @@ -8,16 +11,19 @@ "es6": true, "postcss": true, "minified": true, - "newFeature": true + "newFeature": true, + "autoAudits": false }, "compileType": "miniprogram", - "libVersion": "2.4.1", + "libVersion": "2.5.0", "appid": "wx0df150c438e4c8f0", "projectname": "styleDay", "debugOptions": { "hidedInDevtools": [] }, "isGameTourist": false, + "simulatorType": "wechat", + "simulatorPluginLibVersion": {}, "condition": { "search": { "current": -1,