第四章作业

操作题

1.使用canvas组件实现“五圈”的绘制

<view class="container">
  <canvas class="canvas" canvas-id="myCanvas"></canvas>
</view>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.canvas {
  width: 300px;
  height: 300px;
}
Page({
  onReady: function () {
    const ctx = wx.createCanvasContext('myCanvas');

    ctx.beginPath();
    ctx.arc(100, 100, 50, 0, 2 * Math.PI, false);
    ctx.closePath();
    ctx.setFillStyle('#0085C7');
    ctx.fill();

    ctx.beginPath();
    ctx.arc(160, 100, 50, 0, 2 * Math.PI, false);
    ctx.closePath();
    ctx.setFillStyle('#F4C300');
    ctx.fill();

    ctx.beginPath();
    ctx.arc(220, 100, 50, 0, 2 * Math.PI, false);
    ctx.closePath();
    ctx.setFillStyle('#000000');
    ctx.fill();

    ctx.beginPath();
    ctx.arc(130, 150, 50, 0, 2 * Math.PI, false);
    ctx.closePath();
    ctx.setFillStyle('#009F3D');
    ctx.fill();

    ctx.beginPath();
    ctx.arc(190, 150, 50, 0, 2 * Math.PI, false);
    ctx.closePath();
    ctx.setFillStyle('#DF0024');
    ctx.fill();

    ctx.draw();
  }
});

 

2.使用相应组件,实现“书单”页面

示例代码

<view class="container">
  <view class="header">
    <text class="back">←书单</text>
  </view>
  
  <view class="main-content">
    <view class="section">
      <text class="section-title">培养商业意识,走出生活、职场和事业的困境。</text>
    </view>
    
    <view class="section">
      <text class="section-subtitle">创新者是如何思考问题的?本书单包括了互联网、思维方式、商业、文案、市场、营销等方面,是在思维方式上的创新,略去传统商学院的教条。</text>
    </view>
    
    <view class="book-item">
      <image class="book-cover" src="/images/book1.jpg" mode="aspectFill"></image>
      <view class="book-info">
        <text class="book-title">《金字塔原理》</text>
        <text class="book-author">芭芭拉·明托(Barbara Minto)</text>
        <text class="book-description">金字塔原理是一种重点突出、逻辑清晰、主次分明的逻辑思路、表达方式和规范动作...</text>
      </view>
    </view>

    <view class="book-item">
      <image class="book-cover" src="/images/book2.jpg" mode="aspectFill"></image>
      <view class="book-info">
        <text class="book-title">《堇业长青》</text>
        <text class="book-author">[美]吉姆·柯林斯,杰里·波勒斯</text>
        <text class="book-description">《堇业长青(珍藏版)》大伯了旧有神话,提供了新颖的见解,并未那些有志于建立经得...</text>
      </view>
    </view>
  </view>
</view>
.container {
  padding: 20rpx;
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
}

.back {
  font-size: 16rpx;
  color: #007AFF;
}

.main-content {
  margin-bottom: 20rpx;
}

.section-title {
  font-size: 20rpx;
  font-weight: bold;
  margin-bottom: 10rpx;
}

.section-subtitle {
  font-size: 16rpx;
  color: #999999;
  line-height: 24rpx;
}

.book-item {
  display: flex;
  margin-bottom: 20rpx;
}

.book-cover {
  width: 100rpx;
  height: 120rpx;
  margin-right: 10rpx;
  border-radius: 5rpx;
}

.book-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.book-title {
  font-size: 16rpx;
  font-weight: bold;
  line-height: 20rpx;
  margin-bottom: 6rpx;
}

.book-author {
  font-size: 14rpx;
  color: #999999;
  line-height: 18rpx;
  margin-bottom: 6rpx;
}

.book-description {
  font-size: 14rpx;
  color: #666666;
  line-height: 18rpx;
}
Page({
  data: {
    books: [
      {
        title: '金字塔原理',
        author: '芭芭拉·明托(Barbara Minto)',
        cover: '/images/book1.jpg',
        description: '金字塔原理是一种重点突出、逻辑清晰、主次分明的逻辑思路、表达方式和规范动作...'
      },
      {
        title: '另类的思考方式',
        author: 'Edward de Bono',
        cover: '/images/book2.jpg',
        description: '本书介绍了如何通过创造性思维方法破除传统思维模式,培养出独特的思考能力...'
      }
    ]
  }
});

运行结果

 

3.使用相应 组件,完成“西安找拼车” 小程序部分页面

示例代码

<view class="container">
  <view class="header">
    <text class="close">×西安找拼车</text>
  </view>
  
  <view class="main-content">
    <view class="section">
      <text class="section-title">联系方式(手机和微信至少填一项)</text>
    </view>
    
    <view class="section">
      <view class="form-item">
        <text class="label">称呼*</text>
        <input class="input" placeholder="请输入称呼"></input>
      </view>
      
      <view class="form-item">
        <text class="label">手机号</text>
        <input class="input" type="number" placeholder="请输入手机号"></input>
      </view>
      
      <view class="form-item">
        <text class="label">微信号</text>
        <input class="input" placeholder="请输入微信号"></input>
      </view>
    </view>
  </view>

  <view class="main-content">
    <view class="section">
      <text class="section-title">拼车信息</text>
    </view>
    
    <view class="section">
      <view class="form-item">
        <text class="label">出发地点*</text>
        <input class="input" placeholder="限7个字"></input>
      </view>
      
      <view class="form-item">
        <text class="label">目的地*</text>
        <input class="input" type="number" placeholder="限7个字"></input>
      </view>
      
      <view class="form-item">
        <text class="label">空座位*</text>
        <input class="input" placeholder="请输入空座位数"></input>
      </view>
    </view>
  </view>
</view>
.container {
  padding: 20rpx;
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
}

.close {
  font-size: 16rpx;
  color: #007AFF;
}

.main-content {
  margin-bottom: 20rpx;
}

.section {
  margin-bottom: 20rpx;
}

.section-title {
  font-size: 16rpx;
  font-weight: bold;
  margin-bottom: 10rpx;
}

.form-item {
  display: flex;
  align-items: center;
  margin-bottom: 10rpx;
}

.label {
  font-size: 14rpx;
  color: #999999;
  width: 80rpx;
}

.input {
  flex: 1;
  border: 1rpx solid #999999;
  border-radius: 4rpx;
  padding: 6rpx 10rpx;
  font-size: 14rpx;
}

 

编程题

<view class="container">
  <view class="header">
    <text class="lifespan">中国现阶段人均寿命 900 个月</text>
  </view>
  
  <view class="main-content">
    <text class="duration">{{durationText}}</text>
    
    <view class="buttons">
      <button class="btn" bindtap="changeDate">换一个日期</button>
      <button class="btn" bindtap="clearRecords">清除记录</button>
    </view>
    
    <image class="battery" src="/images/battery.png"></image>
    
    <text class="quote">能把在面前心走的机会抓住的人,十有八九都会成功</text>
  </view>
  
  <view class="bottom-buttons">
    <button class="icon-btn">
      <image class="icon" src="/images/home.png"></image>
      <text class="icon-label">首页</text>
    </button>
    
    <button class="icon-btn">
      <image class="icon" src="/images/calendar.png"></image>
      <text class="icon-label">年月日</text>
    </button>
    
    <button class="icon-btn">
      <image class="icon" src="/images/thought.png"></image>
      <text class="icon-label">静思</text>
    </button>
    
    <button class="icon-btn">
      <image class="icon" src="/images/about.png"></image>
      <text class="icon-label">关于</text>
    </button>
  </view>
</view>
.container {
  padding: 20rpx;
}

.header {
  margin-bottom: 20rpx;
}

.lifespan {
  font-size: 16rpx;
  color: #333333;
}

.main-content {
  margin-bottom: 20rpx;
}

.duration {
  font-size: 24rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
}

.buttons {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20rpx;
}

.btn {
  display: inline-block;
  padding: 10rpx 20rpx;
  background-color: #007AFF;
  color: #FFFFFF;
  font-size: 14rpx;
  border-radius: 4rpx;
}

.battery {
  width: 30rpx;
  height: 30rpx;
  margin-bottom: 20rpx;
}

.quote {
  font-size: 14rpx;
  color: #999999;
  margin-bottom: 20rpx;
}

.bottom-buttons {
  display: flex;
  justify-content: space-between;
}

.icon-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.icon {
  width: 30rpx;
  height: 30rpx;
  margin-bottom: 5rpx;
}

.icon-label {
  font-size: 12rpx;
  color: #333333;
}
Page({
  data: {
    durationText: '' // 用于显示时间间隔的文本
  },
  
  changeDate: function() {
    // TODO: 根据你的逻辑更改日期并更新durationText
  },
  
  clearRecords: function() {
    // TODO: 根据你的逻辑清除记录
  },
  
  onLoad: function(options) {
    // 计算时间间隔并更新durationText
    const startDate = new Date('2005-08-01');
    const today = new Date();
    const monthsPassed = (today.getFullYear() - startDate.getFullYear()) * 12 + (today.getMonth() - startDate.getMonth());
    this.setData({
      durationText: `2005年8月至今 ${monthsPassed} 个月`
    });
  }
});

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值