Skip to content
Open

i #5

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -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
}
})
14 changes: 14 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pages":[
"pages/index/index",
"pages/logs/logs"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle":"black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
10 changes: 10 additions & 0 deletions app.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
55 changes: 55 additions & 0 deletions pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const app =getApp
Page({
data: {
data: [],
info: {
page: 1,
total: 0
},
text: '',
pp: []
},
bindViewTap(){
wx.navigateTo({
url: '../logs/logs',
})
},
onLoad() {
this.handleRefresh()
},
handleRefresh(page){
wx.request({
url: 'http://api.hunsh.net/s1/',
data: {
q: this.data.text,
page: page || 1
},
success: (res) => {
for (let i of res.data.data) {
i.create_time = (new Date(i.create_time*1000).toLocaleDateString())
}
const ap = Math.ceil(res.data.info.total / 30);
const start = Math.max(res.data.info.page - 2, 1);
const end = Math.min(res.data.info.page + 2, ap);
console.log (ap,start,end)
this.setData({
...res.data,
pp:Array.from({
length:end - start + 1
}, (x,i)=>i+start)
})
}
})
},
handleInput(e){
this.setData({
text: e.detail.value
})
},
handleTap(){
this.handleRefresh()
},
handlePageChange(e){
this.handleRefresh(e.target.dataset.page)
}
})
3 changes: 3 additions & 0 deletions pages/index/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"usingComponents": {}
}
15 changes: 15 additions & 0 deletions pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--index.wxml-->
<view class="header">
<input placeholder=" 请输入课程名称" type="text" confirm-type="search" bindinput="handleInput"></input>
<view class="button"><button bindtap="handleTap">搜索</button></view>
</view>
<view class="list">
<view class="item" wx:for="{{data}}">
<view class="name">{{item.name}}</view>
<view class="meta"><view class="teacher">{{item.teacher}}</view><view class="download">{{item.download}}</view></view>
<view class="time">{{item.create_time}}</view>
</view>
</view>
<view class="pagenation">
<view class="i" wx:for="{{pp}}" wx:key="*this" bindtap="handlePageChange" data-page="{{item}}">{{item}}</view>
</view>
31 changes: 31 additions & 0 deletions pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**index.wxss**/
.header,meta,.list,.item,.meta,.pagenation{
display:flex;
justify-content: center;
align-items: center;
}
.meta {
display:flex;
justify-content: center;
align-items: center;
}
.list,
.item {
flex-direction: column;
align-items: flex-start;
width: 100%;
padding: 16px 24px;
border-bottom: 1px solid #eeeeee;
}
.download {
margin-left: 1em;
}
.pagenation {
width: 80%;
margin: auto;
margin-bottom: 100px;
justify-content: space-around;
}
.button {
margin-right: 25rpx;
}
15 changes: 15 additions & 0 deletions pages/logs/logs.js
Original file line number Diff line number Diff line change
@@ -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))
})
})
}
})
4 changes: 4 additions & 0 deletions pages/logs/logs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"navigationBarTitleText": "查看启动日志",
"usingComponents": {}
}
6 changes: 6 additions & 0 deletions pages/logs/logs.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log}}</text>
</block>
</view>
8 changes: 8 additions & 0 deletions pages/logs/logs.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
71 changes: 71 additions & 0 deletions project.config.json
Original file line number Diff line number Diff line change
@@ -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": false,
"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": "wx1753a643a845b44a",
"projectname": "miniprogram-8",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"isGameTourist": false,
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
}
}
7 changes: 7 additions & 0 deletions sitemap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
19 changes: 19 additions & 0 deletions utils/util.js
Original file line number Diff line number Diff line change
@@ -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
}