diff --git a/app.js b/app.js new file mode 100644 index 0000000..f9db25d --- /dev/null +++ b/app.js @@ -0,0 +1,39 @@ +// app.js +App({ + onLaunch() { + // 展示本地存储能力 + const logs = wx.getStorageSync('logs') || [] + logs.unshift(Date.now()) + wx.setStorageSync('logs', logs) + + // 登录 + wx.login({ + success: res => { + // 发送 res.code 到后台换取 openId, sessionKey, unionId + } + }) + // 获取用户信息 + wx.getSetting({ + success: res => { + if (res.authSetting['scope.userInfo']) { + // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 + wx.getUserInfo({ + success: res => { + // 可以将 res 发送给后台解码出 unionId + this.globalData.userInfo = res.userInfo + + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + if (this.userInfoReadyCallback) { + this.userInfoReadyCallback(res) + } + } + }) + } + } + }) + }, + globalData: { + userInfo: null + } +}) diff --git a/app.json b/app.json new file mode 100644 index 0000000..bbc33e3 --- /dev/null +++ b/app.json @@ -0,0 +1,15 @@ +{ + "pages":[ + "pages/index/index", + "pages/logs/logs", + "pages/search/search" + ], + "window":{ + "backgroundTextStyle":"light", + "navigationBarBackgroundColor": "#FFE066", + "navigationBarTitleText": "二期作业", + "navigationBarTextStyle":"black" + }, + "style": "v2", + "sitemapLocation": "sitemap.json" +} diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..581baf4 --- /dev/null +++ b/app.wxss @@ -0,0 +1,11 @@ +/**app.wxss**/ +.container { + background:blue; + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 200rpx 0; + box-sizing: border-box; +} diff --git a/pages/index/index.js b/pages/index/index.js new file mode 100644 index 0000000..e005412 --- /dev/null +++ b/pages/index/index.js @@ -0,0 +1,55 @@ +// index.js +Page({ + data: { + list:[], + info:{ + page:1, + total:0 + } + }, + + search: function () { + wx.navigateTo({ + url: '../search/search' + }) + }, + + onLoad:function(options){ + this.handleSearch() + }, + handleSearch: function (page) { +   var that=this +   wx.request({ +     url:'http://api.hunsh.net/s1/?page=1&q=', + method: 'GET', + data: { + page:page||1, + q:'', + }, +     header: { +       'Content-Type': 'json' +     }, + +    success: (result)=> { + const ap= Math.ceil(result.data.info.total/30); + const start=Math.max(result.data.info.page-2,1); + const end=Math.min(result.data.info.page+2,ap); + +       this.setData(({ + list:result.data.data, + pp: Array.from({ + length:end-start+1 + },(x,i)=>i + start) + })) + wx.setStorage({ + key: 'list', + data: result.data, + }) +     }, +   }) + }, + handlePageChange(e){ + console.log(e) + this.handleSearch(e.target.dataset.page) + } +}) diff --git a/pages/index/index.json b/pages/index/index.json new file mode 100644 index 0000000..fc7165f --- /dev/null +++ b/pages/index/index.json @@ -0,0 +1,4 @@ +{ + "usingComponents": { + } +} \ No newline at end of file diff --git a/pages/index/index.wxml b/pages/index/index.wxml new file mode 100644 index 0000000..d895c5e --- /dev/null +++ b/pages/index/index.wxml @@ -0,0 +1,25 @@ + + + + + + + + + 搜索 + + + + 信息: + + 课程名称:{{item.name}} + 授课教师:{{item.teacher}} + 授课时间:{{item.create_time}} + 下载数量:{{item.download}} + + + + + + {{item}} + diff --git a/pages/index/index.wxss b/pages/index/index.wxss new file mode 100644 index 0000000..ee15e24 --- /dev/null +++ b/pages/index/index.wxss @@ -0,0 +1,86 @@ +page{ + background:rgb(230, 229, 229); +} +.frame{ + display: flex; + flex-direction: row; + background:rgb(230, 229, 229) +} + +.search{ + width: 80%; +} + +.search_frame { + border: 1px solid rgb(190, 190, 190); + border-radius: 10rpx; + margin-left: 20rpx; +} + +.search_frame input{ + background:white; + margin-left: 60rpx; + height: 60rpx; + border-radius: 5px; +} + +.bc_text { + line-height: 68rpx; + height: 68rpx; + margin-top: 34rpx; +} + + +.icon-box-title { + background:rgb(255, 255, 255); + margin-left: 15rpx; + width: 15%; + line-height:185%; + color:rgb(0, 0, 0); + text-align: center; + border:1px solid rgb(179, 176, 176); + border-radius: 15rpx; +} + +.symbol{ + background:rgb(255, 255, 255); + margin: 10rpx 10rpx 10rpx 10rpx; + position: absolute; + left:13px; + width: 20px; + height: 20px; +} +.item>text{ + background:rgb(197, 193, 193); + color:rgb(22, 22, 22); + margin:10 0 0 0; + line-height:50rpx; + border-radius:15rpx; + font-weight:bolder; + font-size:110%; + padding:1px 16px + +} + +.item>view{ + display:block; + background:rgb(245, 221, 221); + border:1px solid rgb(167, 163, 163); + border-radius: 15rpx; + padding:1px 8px 0px 8px; +} + +.item{ + width:100%; + padding: 8px 8px; + border-bottom:1px solid #eeeeee +} + +.pagenation{ + display:flex; + align-items:center; + width:80%; + margin:auto; + margin-bottom:100px; + justify-content:space-around; +} \ No newline at end of file diff --git a/pages/logs/logs.js b/pages/logs/logs.js new file mode 100644 index 0000000..3c7cb60 --- /dev/null +++ b/pages/logs/logs.js @@ -0,0 +1,15 @@ +// logs.js +const util = require('../../utils/util.js') + +Page({ + data: { + logs: [] + }, + onLoad() { + this.setData({ + logs: (wx.getStorageSync('logs') || []).map(log => { + return util.formatTime(new Date(log)) + }) + }) + } +}) diff --git a/pages/logs/logs.json b/pages/logs/logs.json new file mode 100644 index 0000000..3ee76c1 --- /dev/null +++ b/pages/logs/logs.json @@ -0,0 +1,4 @@ +{ + "navigationBarTitleText": "查看启动日志", + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/logs/logs.wxml b/pages/logs/logs.wxml new file mode 100644 index 0000000..b5a85ac --- /dev/null +++ b/pages/logs/logs.wxml @@ -0,0 +1,6 @@ + + + + {{index + 1}}. {{log}} + + diff --git a/pages/logs/logs.wxss b/pages/logs/logs.wxss new file mode 100644 index 0000000..94d4b88 --- /dev/null +++ b/pages/logs/logs.wxss @@ -0,0 +1,8 @@ +.log-list { + display: flex; + flex-direction: column; + padding: 40rpx; +} +.log-item { + margin: 10rpx; +} diff --git a/pages/search/search.js b/pages/search/search.js new file mode 100644 index 0000000..321b307 --- /dev/null +++ b/pages/search/search.js @@ -0,0 +1,48 @@ +// pages/search/search.js +Page({ + inputValue:'', + list:[], + data: { + info:{ + page:1, + total:0 + } + }, + + inputchar: function (e) { + this.setData({ + inputValue:e.detail.value + }) + }, + searchButton: function () { +   const APIurl='http://api.hunsh.net/s1/', +   that=this +   wx.request({ +     url:APIurl, + method: 'GET', + data:{ + page:'1', + q:this.data.inputValue, + }, +     header: { +       'Content-Type': 'json' +     }, +  success: (res)=>{ + console.log(res) + that.setData({ + list:res.data.data + }) + }, + + fail: function (e) { + console.log("接口调用失败"); + } +   }) + }, + + hideInput: function () { // 返回主页面 + wx.navigateTo({ + url: '../index/index' + }) + } +}); diff --git a/pages/search/search.json b/pages/search/search.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/search/search.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/search/search.wxml b/pages/search/search.wxml new file mode 100644 index 0000000..8965cbe --- /dev/null +++ b/pages/search/search.wxml @@ -0,0 +1,24 @@ + + + + + + + + + + + 搜索 + 取消 + + + + + + + 课程名称:{{item.name}} + 授课教师:{{item.teacher}} + 下载数量:{{item.download}} + + + diff --git a/pages/search/search.wxss b/pages/search/search.wxss new file mode 100644 index 0000000..9667df7 --- /dev/null +++ b/pages/search/search.wxss @@ -0,0 +1,64 @@ +/* pages/search/search.wxss */ +.search{ + position: relative; + padding: 8px 10px; + display: flex; + box-sizing: border-box; + background-color: #EFEFF4; + border-top: 1rpx solid #D7D6DC; + border-bottom: 1rpx solid #D7D6DC; +} +.search_icon { + position: absolute; + left: 10px; + top: 7px; +} +.search_frame { + position: relative; + flex: 1; + border-radius: 5px; + background: #FFFFFF; + border: 1rpx solid #ffffff; +} +.search_box { + position: relative; + padding-left: 30px; + padding-right: 30px; + width: 100%; + box-sizing: border-box; + z-index: 1; +} +.input { + height: 28px; + line-height: 28px; + font-size: 14px; +} +.search_cancel { + margin-left: 1rpx; + width: 15%; + line-height:185%; + color:rgb(29, 151, 29); + text-align: center; + border:1px solid rgb(163, 167, 165); + border-radius: 15rpx; +} + +.data>view{ + color:rgb(0, 0, 0); + margin:0 0 0 0; + display:block; + line-height:50rpx; + border:1px solid rgb(163, 167, 165); + border-radius: 15rpx; + font-size:85% +} + +.icon_box_title { + margin-left: 1rpx; + width: 15%; + line-height:185%; + color:rgb(0, 0, 0); + text-align: center; + border:1px solid rgb(167, 163, 163); + border-radius: 15rpx; +} diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..610e440 --- /dev/null +++ b/project.config.json @@ -0,0 +1,71 @@ +{ + "description": "项目配置文件", + "packOptions": { + "ignore": [] + }, + "setting": { + "urlCheck": false, + "es6": true, + "enhance": false, + "postcss": true, + "preloadBackgroundData": false, + "minified": true, + "newFeature": false, + "coverView": true, + "nodeModules": false, + "autoAudits": false, + "showShadowRootInWxmlPanel": true, + "scopeDataCheck": false, + "uglifyFileName": false, + "checkInvalidKey": true, + "checkSiteMap": true, + "uploadWithSourceMap": true, + "compileHotReLoad": false, + "useMultiFrameRuntime": true, + "useApiHook": true, + "useApiHostProcess": true, + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "enableEngineNative": false, + "bundle": false, + "useIsolateContext": true, + "useCompilerModule": true, + "userConfirmedUseCompilerModuleSwitch": false, + "userConfirmedBundleSwitch": false, + "packNpmManually": false, + "packNpmRelationList": [], + "minifyWXSS": true + }, + "compileType": "miniprogram", + "libVersion": "2.14.4", + "appid": "wxd2a3746dfa2f088d", + "projectname": "%E4%BA%8C%E6%9C%9F%E4%BD%9C%E4%B8%9A1", + "debugOptions": { + "hidedInDevtools": [] + }, + "scripts": {}, + "isGameTourist": false, + "condition": { + "search": { + "list": [] + }, + "conversation": { + "list": [] + }, + "game": { + "list": [] + }, + "plugin": { + "list": [] + }, + "gamePlugin": { + "list": [] + }, + "miniprogram": { + "list": [] + } + } +} \ No newline at end of file diff --git a/sitemap.json b/sitemap.json new file mode 100644 index 0000000..ca02add --- /dev/null +++ b/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/utils/util.js b/utils/util.js new file mode 100644 index 0000000..764bc2c --- /dev/null +++ b/utils/util.js @@ -0,0 +1,19 @@ +const formatTime = date => { + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + const hour = date.getHours() + const minute = date.getMinutes() + const second = date.getSeconds() + + return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` +} + +const formatNumber = n => { + n = n.toString() + return n[1] ? n : `0${n}` +} + +module.exports = { + formatTime +}