【微信小程序】第四章作业

操作题:

1. 使用canvas组件实现aoyunwuhuan的绘制

.wxml

<canvas class="can" canvas-id="mycanvas" style="width: 600px; height: 600px;"  ></canvas>

.js

Page({
  onReady:function(){
    var can = wx.createCanvasContext('mycanvas');
    can.beginPath();
    can.arc(100, 230, 50,0, 2 * Math.PI);
    can.setStrokeStyle('blue');
    can.setLineWidth(10);
    can.stroke();

    can.beginPath();
    can.arc(215, 230, 50, 2 * Math.PI);
    can.setStrokeStyle('black');
    can.stroke();

    can.beginPath();
    can.arc(330, 230, 50, 2 * Math.PI);
    can.setStrokeStyle('red');
    can.stroke();
    
    can.beginPath();
    can.arc(150, 290, 50, 2 * Math.PI);
    can.setStrokeStyle('yellow');
    can.stroke();
    
    can.beginPath();
    can.arc(265, 290, 50, 2 * Math.PI);
    can.setStrokeStyle('green');
    can.stroke();
   
    can.draw();
  }
})

效果运行图:(原图违规,采用全红)

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

.wxml

<view class="banner">
<image class="shu" src="../img/shu.jpg"></image>

<view class="jianjie1">
<view class="text1">培养商业意识,走出生活,职场和事业的困境</view>

<text class="text2">创新者是如何思考问题的?本书单包括了互联网,
\n思维方式,商业,文案,市场,营销等方方面面,
\n是在思维方式上的创新,略去传统学院的教条</text>

</view>

</view>

<view class="boss">
<image mode="widthFix" class="boss-img" src="../img/lf.jpg"></image>
<view class="text3">金字塔原理</view>
<view class="text4">芭芭拉.明托(Barbara Minto)</view>
<view class="text5">金字塔原理是一种重点突破,逻辑清晰,主次分明的逻辑思路,表达方式和规范动作...</view>
</view>

<view class="boss2">
<image class="boss2-img" src="../img/sl.jpg"></image>
<view class="text3">基业长青</view>
<view class="text4">【美】吉姆.柯林斯,杰里.波勒斯</view>
<view class="text5">金字塔原理是一种重点突破,逻辑清晰,主次分明的逻辑思路,表达方式和规范动作...</view>
</view>

.wxss

.banner{
  width: 100%;
  height: 250px;
  position: relative;
}
.shu{
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.jianjie1{
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.text1{
  width: 68%;
  color: #ffffff;
  font-size: 20px;
  text-align: center;
  margin-left: 60px;
  line-height: 40px;
}
.text2{
  color: #ffffff;
  display: flex;
  margin-top: 30px;
  margin-left: 40px;
}

.boss{
  width: 400px;
  height: 170px;
  margin: 0 auto;
  border-bottom: 1px solid #000000;
}
.boss-img{
  float: left;
  width: 130px;
  padding-top: 20px;
  padding-left: 20px;
  padding-right: 20px;
}
.text3{
  font-size: 20px;
  font-weight: bolder;
  padding-top: 20px;
}
.text4{
  font-weight: bold;
  padding-top: 10px;
}
.text5{
  padding-top: 10px;
}

.boss2{
  width: 400px;
  height: 170px;
  margin: 0 auto;
}
.boss2-img{
  float: left;
  width: 130px;
  height: 125px;
  padding-top: 20px;
  padding-left: 20px;
  padding-right: 20px;
}

效果图如下:

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

 .wxml

<view class="bonner">
<text decode="{{true}}">&ensp;&ensp;联系方式(手机和微信至少填一项)</text>
</view>

<view class="boss">
<text class="name">称呼*</text>
<input class="biao" type="text" placeholder="请输入称呼" /> 
</view>

<view class="boss">
<text class="name">手机号</text>
<input class="biao" type="number" placeholder="请输入手机号" /> 
</view>

<view class="boss">
<text class="name">微信号</text>
<input class="biao" type="text" placeholder="请输入微信号" /> 
</view>

<view class="bonner">
<text decode="{{true}}">&ensp;&ensp;拼车信息</text></view>

<view class="boss">
<text class="name">出发地点*</text>
<input class="biao" type="text" maxlength="7" placeholder="限7个字" /> 
</view>

<view class="boss">
<text class="name">目的地*</text>
<input class="biao" type="text" maxlength="7" placeholder="限7个字" /> 
</view>

<view class="boss">
<text class="name">空座数*</text>
<input class="biao" type="number" placeholder="请输入空座数" /> 
</view>

.wxss

.boss{
  width: 100%;
  height: 40px;
  margin-top: 20px;
  line-height: 40px;
  border-bottom: 1px solid rgb(116, 114, 114);
}
.biao{
  margin-top: 10px;
  margin-left: 140px;
}
.name{
  line-height: 20px;
  margin-left: 20px;
  font-weight: bold;
  float: left;
}
.bonner{
  width: 100%;
  height: 40px;
  background: rgb(207, 202, 202);
  line-height: 40px;
  color: rgb(59, 58, 58);
  border-bottom: 2px solid rgb(139, 138, 138);
}

效果图如下:

编程题

4. 人生进程 

 .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>

.js

var t = getApp(), a = require("../../4E683285C190288C280E5A82494C27D6.js");

Page({
    data: {
        motto: a.randomMotto(),
        endMonth: a.formatTime(new Date()),
        birthday: wx.getStorageSync("__birth") || "",
        history: wx.getStorageSync("__history") || function() {
            var t = [], a = [], e = wx.getStorageSync("__birth");
            return e && (a = e.split(" "), t.push(a[0] + "-" + a[2])), t;
        }() || [],
        activeIndex: wx.getStorageSync("__activeIndex") || 0,
        pastMonth: wx.getStorageSync("__pastMonth") || 1,
        remaining: a.fixedDecimal("" === wx.getStorageSync("__remaining") ? 100 : 1 * wx.getStorageSync("__remaining"), 2),
        langMoreThan: wx.getStorageSync("__langMoreThan") || "",
        doodle: "",
        bgsrc_index: wx.getStorageSync("__bgsrc_index") || "",
        canHideTabBar: t.globalData.canHideTabBar,
        canHideNavigation: t.globalData.canHideNavigation,
        navigationTopValue: t.globalData.statusBarHeight ? "ios" == t.globalData.res.platform ? t.globalData.statusBarHeight + 4 : t.globalData.statusBarHeight + 8 : 0,
        isiPhoneX: t.globalData.isiPhoneX,
        platform: t.globalData.res.platform,
        adAppid: "",
        adPagePath: ""
    },
    calProgress: function(t, e, i) {
        var n = t.split("-"), o = this.data.endMonth.split("-"), s = n[0] + " 年 " + (n[1] - 0) + " 月", r = this.data.history, g = 12 * (o[0] - n[0]) + (o[1] - n[1]) + 1, c = "";
        r.push(t), (r = a.arrayUnique(r)).length > 5 && r.shift(), e && (i = r.length - 1, 
        this.setData({
            motto: a.randomMotto()
        })), g > 900 && (g = 900, c = "超过");
        var h = a.fixedDecimal(100 - 100 * g / 900, 2);
        this.setData({
            birthday: s,
            history: r,
            pastMonth: g,
            remaining: h,
            langMoreThan: c,
            doodle: n[1] == o[1] ? "../../images/holiday/shengri.png" : ""
        }), wx.setStorageSync("__birth", s), wx.setStorageSync("__history", r), wx.setStorageSync("__pastMonth", g), 
        wx.setStorageSync("__remaining", h), wx.setStorageSync("__langMoreThan", c), "undefined" !== i && (this.setData({
            activeIndex: i
        }), wx.setStorageSync("__activeIndex", i));
    },
    bindDateChange: function(t) {
        this.calProgress(t.detail.value, !0);
    },
    viewHistory: function() {
        var t = this.data.history, e = this.data.activeIndex ? this.data.activeIndex - 1 : t.length - 1, i = a.formatDay();
        t.length && (this.calProgress(t[e], !1, e), this.setData({
            doodle: t[e].split("-")[1] == i.month ? "../../images/holiday/shengri.png" : ""
        }));
    },
    clearHistory: function() {
        var t = this;
        wx.showModal({
            title: "注意",
            content: "即将清除「人生进度」历史记录",
            success: function(a) {
                a.confirm && (t.setData({
                    birthday: "",
                    history: [],
                    activeIndex: 0,
                    pastMonth: 1,
                    remaining: 100,
                    langMoreThan: "",
                    doodle: ""
                }), wx.setStorageSync("__birth", ""), wx.setStorageSync("__history", []), wx.setStorageSync("__pastMonth", 1), 
                wx.setStorageSync("__remaining", 100), wx.setStorageSync("__langMoreThan", ""));
            }
        });
    },
    changeMotto: function() {
        this.setData({
            motto: a.randomMotto()
        });
    },
    clearSavedFile: function() {
        wx.removeSavedFile({
            filePath: this.data.bgsrc_index,
            complete: function(t) {
                console.log(t);
            }
        }), this.setData({
            bgsrc_index: ""
        }), wx.setStorageSync("__bgsrc_index", "");
    },
    choseBackground: function() {
        var t = this;
        wx.showActionSheet({
            itemList: [ "更换背景", "恢复初始样式" ],
            success: function(a) {
                switch (a.tapIndex) {
                  case 0:
                    wx.chooseImage({
                        count: 1,
                        sizeType: [ "compressed" ],
                        sourceType: [ "album" ],
                        success: function(a) {
                            var e = a.tempFilePaths;
                            t.clearSavedFile(), wx.saveFile({
                                tempFilePath: e[0],
                                success: function(a) {
                                    var e = a.savedFilePath;
                                    t.setData({
                                        bgsrc_index: e
                                    }), wx.setStorageSync("__bgsrc_index", e);
                                }
                            });
                        }
                    });
                    break;

                  case 1:
                    t.clearSavedFile();
                }
            },
            fail: function(t) {
                console.log(t.errMsg);
            }
        });
    },
    clickCustomAd: function() {
        var e = t.globalData.res.SDKVersion;
        a.compareVersion(e, "1.3.0") >= 0 && a.compareVersion(e, "2.0.7") <= 0 && wx.navigateToMiniProgram({
            appId: this.data.adAppid,
            path: this.data.adPagePath,
            envVersion: "release"
        });
    },
    onShareAppMessage: function() {
        wx.showShareMenu({
            withShareTicket: !0
        });
        (this.data.birthday || "7777 年 7 月").split(" ")[0];
        return {
            title: "奋斗没有终点,任何时候都是一个起点",
            desc: "",
            path: "pages/index/index",
            imageUrl: "../../images/share.png",
            success: function(t) {}
        };
    },
    onLoad: function() {
        var t = wx.getStorageSync("__history") || [], e = wx.getStorageSync("__activeIndex") || 0, i = a.formatDay(), n = wx.getStorageSync("__visiter") || "new";
        try {
            t.length && (this.calProgress(t[e], !1, e), t[e].split("-")[1] == i.month && this.setData({
                doodle: "../../images/holiday/shengri.png"
            })), "new" == n && (a.showAd(), wx.setStorageSync("__visiter", "old"));
        } catch (t) {}
    }
});

.wxss

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

效果图如下:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值