1。使用canvas组件实现五环的绘制。
在index.js中输入代码:
Page({
onReady: function () {
const ctx = wx.createCanvasContext('myCanvas')
ctx.beginPath()
ctx.arc(60, 60, 50, 0, 2 * Math.PI)
ctx.setStrokeStyle('blue')
ctx.setLineWidth(10)
ctx.stroke()
ctx.beginPath()
ctx.arc(165, 60, 50, 0, 2 * Math.PI)
ctx.setStrokeStyle('yellow')
ctx.stroke()
ctx.beginPath()
ctx.arc(270, 60, 50, 0, 2 * Math.PI)
ctx.setStrokeStyle('green')
ctx.stroke()
ctx.beginPath()
ctx.arc(110,120, 50, 0, 2 * Math.PI)
ctx.setStrokeStyle('red')
ctx.stroke()
ctx.beginPath()
ctx.arc(220, 120, 50, 0, 2 * Math.PI)
ctx.setStrokeStyle('black')
ctx.stroke()
ctx.draw()
}
})
在index.wxml中输入代码:
<view>
<canvas canvas-id="myCanvas" style="width: 350px; height: 350px;"/>
</view>
运行效果图如下:
2.使用相应组件,完成书单页面
在index.wxml中输入代码:
<!-- wxml文件 -->
<view class="head">← 书单</view>
<!-- 上面的结构 -->
<view class="z1">
<view class="z2">《进击的巨人》讲述的故事是一个人类正被一</view>
<view class="z3">种称作巨人的不明生物袭击,残杀及捕食的世界</view>
</view>
<!-- 中间的结构 -->
<view class="shu">
<view class="imgone" style="display: flex;">
<image class="img" src="../img/ailun.jpg"/>
<view class="one">
<view class="t1">艾伦 耶格尔</view>
<view class="t2">第104期训练兵团毕业生的NO.5</view>
<view class="text3">进击的巨人的男主,性格属于开朗型,心性坚毅的少年</view>
</view>
</view>
<view class="xian"></view>
<!-- 下面的结构 -->
<view class="imgtwo" style="display: flex;">
<image class="img" src="../img/sanli.jpg"/>
<view class="two">
<view class="t1">三笠 阿克曼</view>
<view class="t2">第104期训练兵团毕业生的NO.1</view>
<view class="t3">进击的巨人女主,她为人沉着冷静,英武果断,敢爱敢恨</view>
</view>
</view>
</view>
在index.wxss中输入代码:
/* wxss文件 */
/* 上面的样式 */
.head{
font-size: 55rpx;
margin-top: 100rpx;
}
.p1{
background-color: black;
}
.p2{
color: aliceblue;
text-align: center;
font-size: 45rpx;
padding: 30rpx;
}
.p3{
color: aliceblue;
padding: 20rpx;
}
/* 中间的样式 */
.shu{
margin: 50rpx;
}
.textone{
margin-left: 50rpx;
}
.img1{
width: 600rpx;
height: 350rpx;
}
.img2{
width: 600rpx;
height: 350rpx;
}
.text1{
font-size: 70rpx;
font-weight: 700;
}
.text2{
font-size: 40rpx;
font-weight: 600;
}
.xian{
margin-top: 50rpx;
border-bottom: 4px solid #ccc;
}
/* 下面的样式 */
.imgtwo{
margin-top: 50rpx;
}
.texttwo{
margin-left: 50rpx;
}
运行效果图如下:
3. 使用相应组件,完成西安找拼车页面
在index.wxml中输入代码:
<view style="text-align: left; font-size: 16px;background-color: black;color: white;width:100%;height:68px"><text style="position: absolute;top:30px;left:18px;">✖ 西安找拼车</text></view>
<view>
<view style="top:80px;left:10px;background-color: #BABABA;height:40px"><text style="position:absolute;top:80px;left: 10px;color: #474747;">联系方式(手机和微信至少填一项)</text></view>
<view style="font-size:18px;top:80px;left:10px;background-color: white;height:50px"><text style="position:absolute;top:120px;left: 15px;">称呼*</text><text style="position:absolute;top:120px;left:100px">请输入称呼</text></view>
<view style="border-bottom: 1px solid darkgrey;"></view>
<view style="font-size:16px;top:80px;left:10px;background-color: white;height:50px"><text style="position:absolute;top:180px;left: 15px;">手机号</text><text style="position:absolute;top:180px;left:100px">请输入手机号</text></view>
<view style="border-bottom: 1px solid darkgrey;"></view>
<view style="font-size:18px;top:80px;left:10px;background-color: white;height:50px"><text style="position:absolute;top:230px;left: 15px;">微信号</text><text style="position:absolute;top:230px;left:90px">请输入微信号</text></view>
<view style="border-bottom: 1px solid darkgrey;"></view>
<view style="height: 50px; background-color: darkgray;width:100%;position: absolute;top:262px"><text style="font-size: 16px;position: absolute;top:10px;left: 15px;color: #474747;">拼车信息</text></view>
<view style="border-bottom: 1px solid darkgrey;"></view>
<view style="font-size:18px;top:80px;left:10px;background-color: white;height:50px"><text style="position:absolute;top:330px;left: 14px;">出发地点*</text><text style="position:absolute;top:330px;left:110px">限七个字</text></view>
<view style="border-bottom: 1px solid darkgrey;"></view>
<view style="font-size:18px;top:80px;left:10px;background-color: white;height:50px"><text style="position:absolute;top:380px;left: 15px;">目的地*</text><text style="position:absolute;top:380px;left:110px">限七个字</text></view>
<view style="border-bottom: 1px solid darkgrey;"></view>
<view style="font-size:18px;top:80px;left:10px;background-color: white;height:50px"><text style="position:absolute;top:430px;left: 15px;">空座数*</text><text style="position:absolute;top:430px;left:110px">请输入空座数</text></view>
<view style="border-bottom: 1px solid darkgrey;"></view>
</view>
运行效果图如下:
编程题
“人生进程”是一款极简的小程序,它只有一个功能:就是计算一个人从出生到现在已经度过了多少个月,请编写程序完成此功能。
在app.json中输入添加代码:
<view class="doodle" wx:if="{{!bgsrc_index.length}}">
<image mode="aspectFit" src="{{doodle}}"></image>
</view>
<view class="theme{{canHideNavigation?' customtopnav':''}} {{platform}}">
<view class="btn-changetheme" style="top: {{navigationTopValue}}px;">
<view wx:if="{{canHideNavigation}}">
<button class="topshare" hoverClass="none" openType="share" plain="true">
<image mode="scaleToFill" src="../../images/ico_share_customtopnav.png"></image>
</button>
</view>
<image bindtap="choseBackground" mode="scaleToFill" src="../../images/ico_theme{{canHideNavigation?'_customtopnav':''}}.png"></image>
</view>
<view class="bg-theme">
<image mode="aspectFill" src="{{bgsrc_index}}"></image>
</view>
</view>
<view class="container{{bgsrc_index?' zoomout':''}}{{isiPhoneX?' ct-iphonex':''}}">
<view class="header">
<view class="note">中国现阶段人均寿命 900 个月</view>
<view class="past">
<view wx:if="{{birthday}}">{{birthday}}至今{{langMoreThan}} {{pastMonth}} 个月</view>
</view>
<view class="settings">
<picker bindchange="bindDateChange" end="{{endMonth}}" fields="month" mode="date" start="1949-10" value="{{endMonth}}">
<view class="btn-setting">
<view wx:if="{{birthday}}">换一个日期</view>
<view wx:else>点此设置出生年月,查看人生进度</view>
</view>
</picker>
<view bindtap="clearHistory" class="btn-del" hoverClass="none" hoverStartTime="0" hoverStayTime="0" wx:if="{{birthday}}">清除记录</view>
</view>
</view>
<view bindtap="viewHistory" class="main">
<view class="cell"></view>
<view class="months">
<view class="remaining">
<view class="remaining-before" style="top: {{100-remaining}}%;"></view>
<view class="remaining-after" style="top: {{100-remaining}}%;"></view>
<view class="remaining-txt" style="height: {{remaining-3}}%;" wx:if="{{remaining>=6}}">{{remaining}}%</view>
</view>
</view>
<view class="indicator-block indicator-{{activeIndex}}">
<view class="indicator" wx:for="{{history}}" wx:key="indicator"></view>
</view>
</view>
<view class="footer">
<text bindtap="changeMotto" class="motto">{{motto}}</text>
</view>
</view>
<block wx:if="{{canHideTabBar}}">
<import src="../../templates/nav.wxml"></import>
<view class="{{platform}}{{isiPhoneX?' nav-iphonex':''}}">
<template is="nav" data="{{pagename:'home'}}"></template>
</view>
</block>
<navigator appId="{{adAppid}}" bindtap="clickCustomAd" class="ad-index-float{{canHideNavigation?' custom-ad':''}}{{isiPhoneX?' custom-ad-iphonex':''}} {{platform}}" hoverClass="none" openType="navigate" path="{{adPagePath}}" target="miniProgram" version="release" wx:if="{{adAppid}}">
<image mode="scaleToFill" src="../../images/ad_acadsoc.png"></image>
</navigator>
<ad class="ad{{isiPhoneX?' ad-iphonex':''}}" unitId="adunit-9033ae8aa80f0225"></ad>
在index.wxml中输入代码:
<view class="doodle" wx:if="{{!bgsrc_index.length}}">
<image mode="aspectFit" src="{{doodle}}"></image>
</view>
<view class="theme{{canHideNavigation?' customtopnav':''}} {{platform}}">
<view class="btn-changetheme" style="top: {{navigationTopValue}}px;">
<view wx:if="{{canHideNavigation}}">
<button class="topshare" hoverClass="none" openType="share" plain="true">
<image mode="scaleToFill" src="../../images/ico_share_customtopnav.png"></image>
</button>
</view>
<image bindtap="choseBackground" mode="scaleToFill" src="../../images/ico_theme{{canHideNavigation?'_customtopnav':''}}.png"></image>
</view>
<view class="bg-theme">
<image mode="aspectFill" src="{{bgsrc_index}}"></image>
</view>
</view>
<view class="container{{bgsrc_index?' zoomout':''}}{{isiPhoneX?' ct-iphonex':''}}">
<view class="header">
<view class="note">中国现阶段人均寿命 900 个月</view>
<view class="past">
<view wx:if="{{birthday}}">{{birthday}}至今{{langMoreThan}} {{pastMonth}} 个月</view>
</view>
<view class="settings">
<picker bindchange="bindDateChange" end="{{endMonth}}" fields="month" mode="date" start="1949-10" value="{{endMonth}}">
<view class="btn-setting">
<view wx:if="{{birthday}}">换一个日期</view>
<view wx:else>点此设置出生年月,查看人生进度</view>
</view>
</picker>
<view bindtap="clearHistory" class="btn-del" hoverClass="none" hoverStartTime="0" hoverStayTime="0" wx:if="{{birthday}}">清除记录</view>
</view>
</view>
<view bindtap="viewHistory" class="main">
<view class="cell"></view>
<view class="months">
<view class="remaining">
<view class="remaining-before" style="top: {{100-remaining}}%;"></view>
<view class="remaining-after" style="top: {{100-remaining}}%;"></view>
<view class="remaining-txt" style="height: {{remaining-3}}%;" wx:if="{{remaining>=6}}">{{remaining}}%</view>
</view>
</view>
<view class="indicator-block indicator-{{activeIndex}}">
<view class="indicator" wx:for="{{history}}" wx:key="indicator"></view>
</view>
</view>
<view class="footer">
<text bindtap="changeMotto" class="motto">{{motto}}</text>
</view>
</view>
<block wx:if="{{canHideTabBar}}">
<import src="../../templates/nav.wxml"></import>
<view class="{{platform}}{{isiPhoneX?' nav-iphonex':''}}">
<template is="nav" data="{{pagename:'home'}}"></template>
</view>
</block>
<navigator appId="{{adAppid}}" bindtap="clickCustomAd" class="ad-index-float{{canHideNavigation?' custom-ad':''}}{{isiPhoneX?' custom-ad-iphonex':''}} {{platform}}" hoverClass="none" openType="navigate" path="{{adPagePath}}" target="miniProgram" version="release" wx:if="{{adAppid}}">
<image mode="scaleToFill" src="../../images/ad_acadsoc.png"></image>
</navigator>
<ad class="ad{{isiPhoneX?' ad-iphonex':''}}" unitId="adunit-9033ae8aa80f0225"></ad>
在countdown.wxml中输入代码:
<view class="doodle" wx:if="{{!bgsrc.length}}">
<image mode="aspectFill" src="{{doodle}}"></image>
</view>
<view class="theme{{canHideNavigation?' customtopnav':''}} {{platform}}">
<view class="btn-changetheme" style="top: {{navigationTopValue}}px;">
<view wx:if="{{canHideNavigation}}">
<button class="topshare" hoverClass="none" openType="share" plain="true">
<image mode="scaleToFill" src="../../images/ico_share_customtopnav.png"></image>
</button>
</view>
<image bindtap="choseBackground" mode="scaleToFill" src="../../images/ico_theme{{canHideNavigation?'_customtopnav':''}}.png"></image>
</view>
<view class="bg-theme">
<image mode="aspectFill" src="{{bgsrc}}"></image>
</view>
</view>
<view class="container{{bgsrc?' zoomout':''}}{{isiPhoneX?' ct-iphonex':''}}">
<view class="header">
<view class="past">
<view>{{today}}</view>
</view>
</view>
<view bindtap="viewHistory" class="main">
<view class="cell"></view>
<view class="months">
<view class="remaining">
<view class="remaining-before" style="top: {{100-remaining}}px;"></view>
<view class="remaining-after" style="top: {{100-remaining}}px;"></view>
<view class="remaining-txt" style="height: {{remaining-3}}px;" wx:if="{{remaining>=6}}">{{remaining}}%</view>
</view>
</view>
<view class="indicator-block indicator-{{activeIndex}}">
<view class="indicator" wx:for="{{history}}" wx:key="indicator"></view>
</view>
</view>
</view>
<block wx:if="{{canHideTabBar}}">
<import src="../../templates/nav.wxml"></import>
<view class="{{platform}}{{isiPhoneX?' nav-iphonex':''}}">
<template is="nav" data="{{pagename:'countdown'}}"></template>
</view>
</block>
<ad class="ad{{isiPhoneX?' ad-iphonex':''}}" unitId="adunit-338e6be140a1d835"></ad>
在countdown.js中输入代码:
var a = getApp(), t = require("../../4E683285C190288C280E5A82494C27D6.js");
Page({
data: {
history: [],
activeIndex: 2,
today: "",
remaining: 0,
timer: null,
doodle: "",
bgsrc: wx.getStorageSync("__bgsrc") || "",
canHideTabBar: a.globalData.canHideTabBar,
canHideNavigation: a.globalData.canHideNavigation,
navigationTopValue: a.globalData.statusBarHeight ? "ios" == a.globalData.res.platform ? a.globalData.statusBarHeight + 4 : a.globalData.statusBarHeight + 8 : 0,
isiPhoneX: a.globalData.isiPhoneX,
platform: a.globalData.res.platform
},
calProgress: function(a, e) {
var i = a.split("-"), s = "", o = 0, n = t.formatDay();
switch (clearInterval(this.timer), i.length) {
case 1:
s = i[0] + " 年", o = t.fixedDecimal(100 * (1 - n.past_days / n.year_total), 2);
break;
case 2:
s = i[0] + " 年 " + i[1] + " 月", o = t.fixedDecimal(100 * (1 - (n.day - 1) / n.month_total), 2);
break;
case 3:
s = i[0] + " 年 " + i[1] + " 月 " + i[2] + " 日", o = t.fixedDecimal(100 * (1 - n.past_time / 864e5), 4),
this.timer = setInterval(function() {
o <= .01 && (this.handleData(), this.handleDoodle()), this.init();
}.bind(this), 1e3);
}
this.setData({
activeIndex: e,
today: s,
remaining: o
});
},
viewHistory: function() {
var a = this.data.history, t = this.data.activeIndex ? this.data.activeIndex - 1 : a.length - 1;
a.length && this.calProgress(a[t], t);
},
init: function() {
this.calProgress(this.data.history[this.data.activeIndex], this.data.activeIndex);
},
handleData: function() {
var a = t.formatDay(), e = [ a.year.toString(), a.year + "-" + a.month, a.year + "-" + a.month + "-" + a.day ];
this.setData({
history: e
});
},
handleDoodle: function() {
var a = t.formatDay();
this.setData({
doodle: t.holidayPhoto(a.month + "-" + a.day)
});
},
clearSavedFile: function() {
wx.removeSavedFile({
filePath: this.data.bgsrc,
complete: function(a) {
console.log(a);
}
}), this.setData({
bgsrc: ""
}), wx.setStorageSync("__bgsrc", "");
},
choseBackground: function() {
var a = this;
wx.showActionSheet({
itemList: [ "更换背景", "恢复初始样式" ],
success: function(t) {
switch (t.tapIndex) {
case 0:
wx.chooseImage({
count: 1,
sizeType: [ "compressed" ],
sourceType: [ "album" ],
success: function(t) {
var e = t.tempFilePaths;
a.clearSavedFile(), wx.saveFile({
tempFilePath: e[0],
success: function(t) {
var e = t.savedFilePath;
a.setData({
bgsrc: e
}), wx.setStorageSync("__bgsrc", e);
}
});
}
});
break;
case 1:
a.clearSavedFile();
}
},
fail: function(a) {
console.log(a.errMsg);
}
});
},
onShareAppMessage: function() {
return wx.showShareMenu({
withShareTicket: !0
}), {
title: "奋斗没有终点,任何时候都是一个起点",
desc: "",
path: "pages/index/index",
imageUrl: "../../images/share.png",
success: function(a) {}
};
},
onLoad: function() {
this.handleData(), this.handleDoodle(), this.init();
},
onShow: function() {
this.handleData(), this.handleDoodle(), this.init();
}
});
在countdown.json中输入代码:
.past {
margin: 100rpx auto -105rpx;
padding: 0 10rpx;
font-size: 160%;
font-weight: 300;
}
.main {
position: relative;
display: flex;
flex: 2;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
opacity: .9;
}
运行效果图如下: