微信小程序开发四章作业

1.使用canvas组件实现"五色圈"的绘制

代码示例:

wxml代码:

canvas奥运五环
<view class="container">
  <canvas canvas-id="olympic-rings" style="width: 300px; height: 300px;"></canvas>
</view>

js代码:

Page({ 
  onReady: function () {
  const ctx = wx.createCanvasContext('olympic-rings');
  // 绘制蓝色圆
  ctx.beginPath();
  ctx.arc(80, 80, 40, 0, 2 * Math.PI);
  ctx.moveTo(80,80)
  ctx.lineWidth=5;
  ctx.strokeStyle='#0099FF'
  ctx.stroke();

  // 绘制黑色圆
  ctx.beginPath();
  ctx.arc(140, 80, 40, 0, 2 * Math.PI);
  ctx.moveTo(140,80)
  ctx.lineWidth=5;
  ctx.strokeStyle='#000000'
  ctx.stroke();


  // 绘制红色圆
  ctx.beginPath();
  ctx.arc(200, 80, 40, 0, 2 * Math.PI);
  ctx.moveTo(200,80)
  ctx.lineWidth=5;
  ctx.strokeStyle='#FF0000'
  ctx.stroke();
  

  // 绘制黄色圆
  ctx.beginPath();
  ctx.arc(110, 120, 40, 0, 2 * Math.PI);
  ctx.moveTo(110,120)
  ctx.lineWidth=5;
  ctx.strokeStyle='#FFCC00'
  ctx.stroke();


  // 绘制绿色圆
  ctx.beginPath();
  ctx.arc(170, 120, 40, 0, 2 * Math.PI);
  ctx.moveTo(170,120)
  ctx.lineWidth=5;
  ctx.strokeStyle='#00CC00'
  ctx.stroke();
  ctx.draw();
}
})

运行效果:

2.所有相应组件,完成书单页面

代码示例:

wxml代码:

书单
<view >

<image src="../../images1/dbfd83c30e9d3cf789ff0bd3c4ef165.png" mode=""class="shudan"/>


<view class="yi">
<image src="../../images1/jinzita.png" mode="" class="jinzita"/>
<view class="wenzi1">
<view class="t1">金字塔原理</view>
<view class="t2">芭芭拉.明托(Barbara Minto)</view>
<view class="t3">金字塔原理是一种重点突出。逻辑清晰、主次分明的逻辑思路、表达方式和规范动作....</view>
</view>
</view>

<view class="er">
<image src="../../images1/jiyechangqing.png" mode="" class="jiyechangqing"/>
<view class="wenzi2">
<view class="t1">基业长青</view>
<view class="t2">[英]古梅.柯林斯.杰里.波勒斯</view>
<view class="t3">(基业长青(珍藏版))打破了旧有神话,提供了新颖的见解,并为那些有志于建立经得....</view>
</view>
</view>
</view>

wxss代码:

.shudan{
  width: 100%;
  height: 150px;
}
.yi{
  width: 400px;
  height: 120px;
  display: flex;
  margin-left: 20px;
  margin-top: 20px;
}
.jinzita{
  width: 50px;
  height: 75px;
  padding-top: 5px;
}
.wenzi1{
  padding-left: 10px;
  font-family: "微软雅黑";
}
.wenzi1 .t1{
font-weight: bold;
font-size: 17px;
}
.wenzi1 .t2{
  font-weight: bold;
  font-size: 13px;
  line-height: 30px;
}
.wenzi1 .t3{
  width: 250px;
font-size: 13px;
}
.line{
  height: 1px;
  background-color: #ccc;
  margin-left: 20px;
  margin-right: 20px;
}
.er{
  width: 400px;
  height: 120px;
  display: flex;
  margin-left: 20px;
  margin-top: 20px;
}
.jiyechangqing{
  width: 50px;
  height: 75px;
  padding-top: 5px;
}
.wenzi2{
  padding-left: 10px;
  font-family: "微软雅黑";
}
.wenzi2 .t1{
  font-weight: bold;
  font-size: 17px;
   
  }
  .wenzi2 .t2{
    font-weight: bold;
    font-size: 13px;
    line-height: 30px;
  }
  .wenzi2 .t3{
    width: 250px;
  font-size: 13px;
  }

运行效果:

3.使用相应组件,完成西安找拼车页面

代码示例:

wxml:

西安找拼车
<view class="pinchetou">
联系方式(手机和微信至少填一项</view>
<view class="daview">
<view class="xinximing">称呼*</view>
<input type="text" placeholder="请输入称呼" style="margin-top: 12px;margin-left: 83px;"/>
</view>
<view class=".line"></view>
<view class="daview">
<view class="xinximing">手机号*</view>
<input type="text" placeholder="请输入手机号" style="margin-top: 12px;margin-left: 65px;"/>
</view>
<view class=".line"></view>
<view style="display: flex; line-height: 50px;border-bottom: 1px solid #ccc;">
<view class="xinximing">微信号*</view>
<input type="text" placeholder="请输入微信号" style="margin-top: 12px;margin-left: 65px;"/>
</view>
<view class="pinchetou">拼车信息</view>
<view class="daview">
<view class="xinximing">出发地点*</view>
<input type="text" placeholder="限7个字" style="margin-top: 12px;margin-left: 50px;"/>
</view>
<view class=".line"></view>
<view class="daview">
<view class="xinximing">目的地*</view>
<input type="text" placeholder="限7个字" style="margin-top: 12px;margin-left: 65px;"/>
</view>
<view class=".line"></view>
<view style="display: flex; line-height: 50px;border-bottom: 1px solid #ccc;">
<view style="font-size: 17px;  font-weight: bold;margin-left:20px ;">空座数*</view>
<input type="text" placeholder="限7个字" style="margin-top: 12px;margin-left: 65px;"/>
</view>

wxss代码:

.pinchetou{
    background-color: #F5F5F5;line-height: 50px;color: #B1AFB0;border-bottom: 1px solid #ccc;padding-left: 20px;
  }
.daview{
  display: flex;line-height: 50px;
}
.xinximing{
  font-size: 17px; 
  font-weight: bold;
  margin-left:20px 
}

运行效果:

4.人生进程

代码示例:

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({
        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
        })
      }
})

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;
}

运行效果:

  • 7
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值