Skip to content
Open

i #2

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/jiemian/jiemian"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "搜索",
"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;
}
59 changes: 59 additions & 0 deletions pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// index.js
// 获取应用实例
const app = getApp()

Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs'
})
},
sousuo:function(){
wx.navigateTo({
url: '../jiemian/jiemian'
})
},
onLoad() {
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
},
getUserInfo(e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})
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": {}
}
14 changes: 14 additions & 0 deletions pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--index.wxml-->
<view class="container">
<view class="userinfo">
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view>
<view class="usermotto">
<button bindtap="sousuo">搜索</button>
<text class="user-motto">{{motto}}</text>
</view>
</view>
21 changes: 21 additions & 0 deletions pages/index/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**index.wxss**/
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
}

.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}

.userinfo-nickname {
color: #aaa;
}

.usermotto {
margin-top: 200px;
}
59 changes: 59 additions & 0 deletions pages/jiemian/jiemian.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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/jiemian/jiemian.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"usingComponents": {}
}
14 changes: 14 additions & 0 deletions pages/jiemian/jiemian.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<view class="header">
<input placeholder="请输入" type="text" confirm-type="search" bindinput="handleInput"></input>
<button bindtap="handleTap">搜索</button>
</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>
29 changes: 29 additions & 0 deletions pages/jiemian/jiemian.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.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;
}
.download{
margin-left: 1em;
}
.item{
width: 100%;
padding: 16px 24px;
border-bottom: 1px solid #eeeeee;
}
.pagenation{
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;
}
72 changes: 72 additions & 0 deletions project.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"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": false,
"useApiHook": 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": "wx907288a4e8fd0ac7",
"projectname": "homework2",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
}
}
Loading