1.使用canvas组件实现“元”的绘制
index.js
Page({
onReady:function (e){
const ctx = wx.createCanvasContext('BAKA')
ctx.beginPath()
ctx.arc(90, 70, 50, 0, 2 * Math.PI)
ctx.setStrokeStyle('#0000FF')
ctx.stroke()
ctx.beginPath()
ctx.arc(150, 70, 50, 0, 2 * Math.PI)
ctx.setStrokeStyle('#FFFF00')
ctx.stroke()
ctx.beginPath()
ctx.arc(120, 100, 50, 0, 2 * Math.PI)
ctx.setStrokeStyle('#00FF00')
ctx.stroke()
ctx.beginPath()
ctx.arc(220, 70, 50, 0, 2 * Math.PI)
ctx.setStrokeStyle('#000000')
ctx.stroke()
ctx.beginPath()
ctx.arc(190, 100, 50, 0, 2 * Math.PI)
ctx.setStrokeStyle('#FF0000')
ctx.stroke()
ctx.draw()
}
})
index.wxml
<canvas canvas-id="BAKA"></canvas>
运行效果图
2.使用相应组件,完成如图4-29所示的“书单”页面
index.wxml
<view style="font-size: 24px;position: absolute;top: 100px;top: 30px;"> ⬅书单</view>
<view>
<view class="KALA">
<image src="/image/klbq.jpg" mode="mao" class="qwa"style="position:absolute;top:70px"/>
</view>
</view>
<view>
<view style="position: absolute;top:100px;color: rgb(12, 12, 12);font-size: 40px;justify-content: center;left:4px;">培养商业意识,走出生活,职场和事业的困境。</view>
<view style="position: absolute;top: 85px;color: rgb(192, 165, 165);left: 15px;top: 220px;font-size: 18px;">创新者是如何思考问题的?本书单包括了互联网,思维方式,商业,文案,市场,营销等方方面面,是在思维方式上的创新,略去传统商学院的教条</view>
</view>
<view class="nian">
<view class="nian"><image src="/image/mao.jpg"
mode=""class="mao"/></view></view>
<view class="MAO" style="border-bottom: 1px solid darkgrey;padding: 10px;"></view>
<view class="bainian">
<view class="bai">百年孤独</view>
<view class="baz">加西亚·马尔克斯</view>
<view class="baw">《百年孤独》,是哥伦比亚作家加西亚·马尔克斯创作的长篇小说,是其代表作,也是拉丁美洲魔幻现实主义文学的代表作,被誉为“再现拉丁美洲历史社会图景的鸿篇巨著”...</view>
</view>
<view class="xxzh">
<view><image src="/image/mao.jpg"
mode=""class="mao2"/></view></view>
<view class="xx">
<view class="zh">星星之火,可以燎原</view>
<view class="ze">毛泽东</view>
<view class="dou">《星星之火,可以燎原》,是毛泽东在1930年写给林彪的一封信。是为答复林彪散发一封对红军前途究竟应该如何估计征求意见的信。毛泽东在这封信中批评了林彪以及党内一些同志对时局一种悲观的思想...</view>
</view>
index.wxss
.qwa{
float: left;
margin-top: 8px;
width: 450px;
height: 220px;
}
.mao{
margin: 0 auto;
float: left;
display: block;
width: 180px;
height: 160px;
}
.bainian{
margin-top: 10px;
}
.KALA{
margin-top: 5px;
}
.nian {
position: absolute;
}
.nian image{
position: relative;
top: 300px;
left: 2px;
}
.xxzh{
margin-top: 30px;
position: absolute;
}
.xxzh image{
position: relative;
top: 400px;
}
.bainian{
margin-top: 5px;
float: right;
}
.xx{
margin-top: 5px;
float: right;
}
.mao2{
margin: 0 auto;
float: left;
display: block;
width: 180px;
height: 160px;
margin-top: 60px;
}
.bai{
margin: 0 auto;
display: block;
font-size: 20px;
float: none;
display: block;
margin-left: 200px;
margin-top: 310px;
}
.zh{
position: absolute;
left: 195px;
top: 500px;
font-size: 20px;
}
.ze{
color: black;
position: absolute;
left: 200px;
top:540px;
font-size: 15px;
}
.dou{
position: absolute;
left: 200px;
top:570px;
font-size: 12px;
color: gray;
}
.baz{
display: block;
font-size: 15px;
float: none;
display: block;
margin-left: 200px;
margin-top: 10px;
}
.baw{
display: block;
font-size: 10px;
float: right;
display: block;
margin-left: 200px;
margin-top: 10px;
color: grey;
}
index.json
{
"usingComponents": {},
"navigationBarBackgroundColor": "#F2F2F2",
"backgroundTextStyle": "light",
"disableScroll":true,
"navigationStyle": "custom"
}
运行效果图:
3.使用相应组件,完成如图4-30的“西安找拼车”小程序部分界面
index.wxml
<view style="background-color: black;height: 60px;"><view style="color: white;padding-top: 25px;font-size: 25px;">×西安找拼车</view>
</view>
<view style="color:grey;padding-top: 10px;background-color: darkgray;height: 35px;">
联系方式(手机号和微信至少填一项)</view>
<view class="mao" style="border-bottom: 1px solid darkgrey;padding: 0px;"></view>
<view>
<view style="font-size: 20px;position: absolute;top: 115px;">称呼*</view>
<view style="font-size: 20px;color: grey;position: absolute;left: 140px;top:115px">请输入称呼</view>
</view>
<view class="mao" style="border-bottom: 1px solid darkgrey;padding: 20px;"></view>
<view>
<view style="font-size: 20px;position: absolute;top:150px">手机号</view>
<view style="font-size: 20px;color: grey;position: absolute;left: 140px;top:150px">请输入手机号</view>
</view>
<view class="mao" style="border-bottom: 1px solid darkgrey;padding: 20px;"></view>
<view>
<view style="font-size: 20px;position: absolute;top: 195px;">微信号</view>
<view style="font-size: 20px;color: grey;position: absolute;left: 140px;top:195px">请输入微信号</view>
</view>
<view class="mao" style="border-bottom: 1px solid darkgrey;padding: 23px;"></view>
<view style="color:grey;padding-top: 10px;background-color: darkgray;height: 35px;">
拼车信息</view>
<view class="mao" style="border-bottom: 1px solid darkgrey;padding: 0px;">
</view>
<view>
<view style="font-size: 20px;position: absolute;top: 290px;">出发地点*</view>
<view style="font-size: 20px;color: grey;position: absolute;left: 140px;top:290px">限7个字</view>
</view>
<view class="mao" style="border-bottom: 1px solid darkgrey;padding: 25px;"></view>
<view>
<view style="font-size: 20px;position: absolute;top: 340px;">目的地*</view>
<view style="font-size: 20px;color: grey;position: absolute;left: 140px;top:340px">限7个字</view>
</view>
<view class="mao" style="border-bottom: 1px solid darkgrey;padding: 25px;"></view>
<view>
<view style="font-size: 20px;position: absolute;top: 390px;">空座位*</view>
<view style="font-size: 20px;color: grey;position: absolute;left: 140px;top:390px">请输入空座位</view>
</view>
<view class="mao" style="border-bottom: 1px solid darkgrey;padding: 25px;"></view>
index.json
{
"usingComponents": {},
"navigationStyle": "custom"
}
运行效果图:
编程题:“人生进程”是一款极简的小程序,它只有一个功能:就是计算一个人从出生到现在已经度过了多少个月,如图4-31所示。请编写程序完成此功能。
index.wxml
view>
<view style=" border:1px solid black;width: 100px;position: absolute;height: 20px;top: 92px;left: 85px;"></view>
<view style="position: absolute;padding-top: 90px;font-size: 16px;padding-left: 188px;"></view><view style="border: 5px;color: black;position: absolute;left: 240px;top: 92px;">清除记录</view>
<view style=" border:1px solid black;width: 100px;position: absolute;height: 20px;top: 92px;left: 230px;"></view>
<view style="position: absolute;padding-top: 90px;font-size: 16px;padding-left: 490px;"><view style="position: absolute;left: 100px;top: 92px;">换一个日期</view></view>
<view><image src="/images/mao.jpg" mode="" style="position: absolute;top:140px;left: 85px;height: 370px;width: 250px;"/></view>
<view style="position: absolute;top:540px;font-size: 18px;left:10px;">能把后面前行行走的机会抓住的人,十有八九都会成功</view>
wj2.wxml
<view style="text-align: center;">中国现阶段人均寿命900个月</view>
<form bindsubmit="bind" style="line-height: 60px;">
<view style="display: flex; font-size: 20px;">
<input type="text" name="time" placeholder="请输入时间" class="BAKA"/>至今:{{people}}个月</view>
<view style="display: flex;">
<button formType="submit" class="BA">请输入后再点击此按钮</button>
<button formType="reset" style="width: 150px;font-size: 13px;">清除记录</button>
</view>
</form>
<view style="margin-top:50px;">
<image src="/images/mao.jpg" class="KA" />
</view>
<view style="width: 350px;">
<text bindtap="changeText1">{{ text1 }}</text>
</view>
wj2.wxss
.BAKA{
width: 100px;
padding-top: 18px;
padding-left: 30px;
}
.BA{
padding-right: 20px;
width: 170px;
font-size: 15px;
font-weight: bold;
}
.KA{
width: 150px;
height: 300px;
margin-left: 100px;
}
wj2.js
Page({
data:{
text1: '点击',
people:new Date().toLocaleDateString()
},
changeText1: function() {
this.setData({
text1: '能把在前面行走的机会抓住的人,十有八九都会成功。'
});
},
bind:function(e){
var time = new Date().toLocaleDateString()
var year = time.substring(0,time.indexOf("/"))
var mo = time.substring(time.indexOf("/")+1,time.lastIndexOf("/"))
var value = e.detail.value.time
var year2 = value.substring(0,time.indexOf("/"))
var mo2 = value.substring(time.indexOf("/")+1,time.lastIndexOf("/"))
var m1 = (year - year2 -1)*12+12-(mo2-mo)
this.setData({
people : m1
})
}
})
app.json
{
"pages": [
"pages/index/index",
"pages/wj2/wj2",
"pages/wj3/wj3",
"pages/wj4/wj4"
],
"tabBar": {
"color": "#666666",
"selectedColor": "#ff0000",
"borderStyle":"black",
"backgroundColor": "#ffffff",
"list": [{
"pagePath": "pages/index/index",
"iconPath": "/pages/image/mao.jpg",
"selectedIconPath": "/pages/image/mao.jpg",
"text": "首页"
},
{
"pagePath": "pages/wj2/wj2",
"iconPath": "/pages/image/mao.jpg",
"selectedIconPath": "/pages/image/mao.jpg",
"text": "年月日"
},
{
"pagePath": "pages/wj3/wj3",
"iconPath": "/pages/image/mao.jpg",
"selectedIconPath": "/pages/image/mao.jpg",
"text": "静思"
},
{
"pagePath": "pages/wj4/wj4",
"iconPath": "/pages/image/mao.jpg",
"selectedIconPath": "/pages/image/mao.jpg",
"text": "关于"
}]
},
"style": "v2",
"componentFramework": "glass-easel",
"lazyCodeLoading": "requiredComponents"
}
运行效果图: