Skip to content
Open
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
}
})
15 changes: 15 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -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"
}
11 changes: 11 additions & 0 deletions app.wxss
Original file line number Diff line number Diff line change
@@ -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;
}
55 changes: 55 additions & 0 deletions pages/index/index.js
Original file line number Diff line number Diff line change
@@ -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)
}
})
4 changes: 4 additions & 0 deletions pages/index/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"usingComponents": {
}
}
25 changes: 25 additions & 0 deletions pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--index.wxml-->
<view class='frame' bindtap="resButton">
<view class="search">
<view class="search_frame">
<icon class="symbol" size='20' type='search'></icon>
<input class="placeholder" placeholder="请输入关键字" bindfocus="search"></input>
</view>
</view>
<view class="icon-box-title">搜索</view>
</view>
<view class="API">
<view class="item" wx:for="{{list}}">
<text>信息:</text>
<view>
<view>课程名称:{{item.name}}</view>
<view>授课教师:{{item.teacher}}</view>
<view>授课时间:{{item.create_time}}</view>
<view>下载数量:{{item.download}}</view>
</view>
</view>
</view>

<view class="pagenation">
<view class="x" wx:for="{{pp}}" wx:key="this" bindtap="handlePageChange" data-page="{{item}}">{{item}}</view>
</view>
86 changes: 86 additions & 0 deletions pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -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;
}
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;
}
48 changes: 48 additions & 0 deletions pages/search/search.js
Original file line number Diff line number Diff line change
@@ -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'
})
}
});
3 changes: 3 additions & 0 deletions pages/search/search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"usingComponents": {}
}
24 changes: 24 additions & 0 deletions pages/search/search.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--pages/search/search.wxml-->
<view>
<view>
<view class="search">
<view class="search_frame">
<view class="search_box">
<icon class="search_icon" type="search" size="18"></icon>
<input type="text" class="input" bindinput="inputchar" value="{{inputValue}}" placeholder="请输入关键字"/>
</view>
</view>
<view class="icon_box_title" bindtap="searchButton">搜索</view>
<view class="search_cancel" bindtap='hideInput'>取消</view>
</view>
</view>
</view>
<view class="data">
<block wx:for="{{list}}">
<view>
<view class="name">课程名称:{{item.name}}</view>
<view calss="teacher">授课教师:{{item.teacher}}</view>
<view class="download">下载数量:{{item.download}}</view>
</view>
</block>
</view>
Loading