第四章作业

文章详细描述了如何使用Canvas组件在WXML中绘制奥运五环,并展示了两个小程序界面设计,一个是书单页面,另一个是西安找拼车的部分界面,还包括一个编程题实例,计算人生进程中的月龄。
摘要由CSDN通过智能技术生成

1.使用canvas组件实现“奥运五环”的绘制。

wxml:

<!-- wxml文件 -->
<canvas canvas-id="txw"></canvas>

js:

// js文件
Page({
  onLoad: function (options) {
    const ctx = wx.createCanvasContext('txw');
 
    // 设置五环颜色
    const colors = ["blue", "black", "red", "yellow","green" ];
 
    // 绘制蓝色环
    ctx.beginPath();
    ctx.arc(50, 50, 40, 0, 2 * Math.PI);
    ctx.setStrokeStyle(colors[0]);
    ctx.stroke();
 
    // 绘制黑色环
    ctx.beginPath();
    ctx.arc(110, 50, 40, 0, 2 * Math.PI);
    ctx.setStrokeStyle(colors[1]);
    ctx.stroke();
 
    // 绘制红色环
    ctx.beginPath();
    ctx.arc(170, 50, 40, 0, 2 * Math.PI);
    ctx.setStrokeStyle(colors[2]);
    ctx.stroke();
 
    // 绘制黄色环
    ctx.beginPath();
    ctx.arc(80, 90, 40, 0, 2 * Math.PI);
    ctx.setStrokeStyle(colors[3]);
    ctx.stroke();
 
    // 绘制绿色环
    ctx.beginPath();
    ctx.arc(140, 90, 40, 0, 2 * Math.PI);
    ctx.setStrokeStyle(colors[4]);
    ctx.stroke();
 
    ctx.draw();
  }
})

wxss:

/* wxss文件 */
canvas{
  margin-left: 200rpx;
  margin-top: 200rpx;
}

运行效果:

2.使用相应软件,完成“书单”页面。

wxml:

<view class="head">← 书单</view>
<view class="p1">
  <view class="p2">培养商业意识,走出生活,职场和事业的困境</view>
  <view class="p3">创新者是如何思考问题的?本书单包括了互联网,思维方式,商业,文案,市场,营销等方方面面,是在思维方式上的创新,略去传统商学院的教条</view>
</view>
<view class="shu">
  <view class="imgone" style="display: flex;">
   <image class="img1" src="/image/1.jpg"/>
    <view class="textone">
      <view class="text1">金字塔原理</view>
      <view class="text2">芭芭拉.明托(Barbara Minto)</view>
      <view class="text3">金字塔原理是一种重点突出。逻辑清晰、主次分明的逻辑思路、表达方式和规范动作....</view>
    </view>
  </view>
  <view class="xian"></view>
  <view class="imgtwo" style="display: flex;">
    <image class="img2" src="/image/2.jpg"/>
    <view class="texttwo">
      <view class="text1">基业长青</view>
      <view class="text2">[英]古梅.柯林斯.杰里.波勒斯</view>
      <view class="text3">(基业长青(珍藏版))打破了旧有神话,提供了新颖的见解,并为那些有志于建立经得....</view>
    </view>
  </view>
</view>

wxss:

.head{
  font-size: 60rpx;
}
.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: 700rpx;
  height: 350rpx;
}
.img2{
  width: 700rpx;
  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.使用相应软件,完成“西安找拼车”小程序部分界面。

wxml:

<!--index.wxml-->
<view style="background-color: black;height: 60px;"><view style="color: white;padding-top: 20px;">×西安找拼车</view>
</view>
<view style="color:grey;padding-top: 10px;background-color: darkgray;height: 35px;">
联系方式(手机号和微信至少填一项)</view>
<view class="fo" 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="fo" 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="fo" 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="fo" style="border-bottom: 1px solid darkgrey;padding: 23px;"></view>
<view style="color:grey;padding-top: 10px;background-color: darkgray;height: 35px;">
拼车信息</view>
<view class="fo" 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="fo" 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="fo" 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="fo" style="border-bottom: 1px solid darkgrey;padding: 25px;"></view>
 
 
 

js:

{
  "usingComponents": {},
  "navigationBarBackgroundColor": "#F2F2F2",
  "backgroundTextStyle": "light",
  "disableScroll":true,
  "navigationStyle": "custom"
  
}

运行效果:

三、编程题

“人生进程”是一款极简的小程序,它只有一个功能:就是计算一个人从出生到现在已经度过了多少个月,请编写程序完成此功能。

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="input1"/>至今:{{people}}个月</view>
<view style="display: flex;">
<button formType="submit" class="button1">请输入后再点击此按钮</button>
<button formType="reset" style="width: 150px;font-size: 13px;">清除记录</button>
</view>
</form>
<view style="margin-top:50px;">
<image src="../../images1/renshengtiao.png" class="renshengtiao"/>
</view>
<view style="width: 350px;">
  <text bindtap="changeText1">{{ text1 }}</text>
</view>

js:

Page({ 
   data:{  
    text1: '能把在前面行走的机会抓住的人,十有八九都会成功。',
        people:new Date().toLocaleDateString()
  
      },
    changeText1: function() {
      this.setData({
   
      });
    },
      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
        })
      }
})

wxss:

.input1{
  width: 110px;
  padding-top: 18px;
  padding-left: 30px;
}
.button1{
  padding-right: 20px;
  width: 175px;
  font-size: 13px;
  font-weight: bold;
}
.renshengtiao{
  width: 150px;
  height: 300px;
  margin-left: 100px;
}

运行效果:

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值