一. 操作题
1.用canvas绘制
在index.wxml中输入代码:
<canvas canvas-id="myCanvas"></canvas>
在index.js中输入代码:
Page({
onReady:function(e){
const ctx = wx.createCanvasContext('myCanvas')
ctx.beginPath()
ctx.arc(70,50,40,0,Math.PI * 2)
ctx.stroke()
ctx.setStrokeStyle('blue')
ctx.beginPath()
ctx.arc(155,50,40,0,Math.PI * 2)
ctx.stroke()
ctx.setStrokeStyle('red')
ctx.beginPath()
ctx.arc(240,50,40,0,Math.PI * 2)
ctx.stroke()
ctx.setStrokeStyle('yellow')
ctx.beginPath()
ctx.arc(110,100,40,0,Math.PI * 2)
ctx.stroke()
ctx.setStrokeStyle('green')
ctx.beginPath()
ctx.arc(195,100,40,0,Math.PI * 2)
ctx.stroke()
ctx.setStrokeStyle('black')
ctx.draw()
}
})
执行效果:
2. 书单页面
在index.wxml中输入代码:
<view style="font-size: 20px;"> ⬅书单</view>
<view class="xx"><image src="/img/h10.jpg"/></view>
<view class="qq">
<text>培养商业意识,走出生活、职场和事业的困扰。</text>
</view>
<view class="ww">
<text>创新者是如何思考问题的?本书单包括了互联网、思维方式、商业、文案、市场、营销等方方面面,是在思维方式上的创新,略去传统商学院的教条</text>
</view>
<view class="ee"><image src="/img/h7.jpg"/>
<view class="ll">
<text class="tt">城南旧事 </text>
<text class="yy">林海音 </text>
<text class="uu"> 《城南旧事》该作品中描写20世纪20年代,北京城南一座四合院里,住着英子温暖和睦的一家。它透过主角英子...</text>
</view>
</view>
<view class="rr"><image src="/img/h8.jpg"/>
<view class="ll">
<text class="tt">狂人日记 </text>
<text class="yy">鲁迅</text>
<text class="uu"> 《狂人日记》是鲁迅创作的第一篇短篇白话文日记体小说,也是中国第一部现代白话小说,写于1918年4月...</text>
</view>
</view>
在index.less中输入代码:
.xx{
width: 100%;
height: 170px;
}
.xx image{
width: 100%;
height: 160px;
}
.qq{
text-align: center;
position: absolute;
top:38px;
color:white;
font-size: 26px;
}
.ww{
left:22px;
position: absolute;
top:120px;
color:white;
font-size: 13px;
}
.ee{
width: 100%;
height: 180px;
}
.ee image{
width: 50%;
height: 150px;
float: left;
}
.rr{
width: 100%;
height: 180px;
}
.rr image{
width: 50%;
height: 150px;
float: left;
}
.ll{
width: 50%;
height: 180;
float: right;
}
.tt{
font-size: 20px;
margin-left: 20px;
}
.yy{
font-size: 13px;
margin-left: 45px;
}
.uu{
font-size: 9px;
margin-left:70px;
}
执行效果:
3.西安找拼车界面
在index.wxml中输入代码:
<view class="jj"><text style="color: aliceblue;">x 西安找拼车</text></view>
<view class="gg">联系方式 (手机和微信至少添一项)</view>
<view class="ss">称呼*<text class="nn">请输入称呼</text></view>
<view class="ss">手机号<text class="aa">请输入手机号</text></view>
<view class="ss">微信号<text class="aa">请输入微信号</text></view>
<view class="gg">拼车信息</view>
<view class="ss">出发地点*<text class="dd">限7个字</text></view>
<view class="ss">目的地*<text class="aa">限7个字</text></view>
<view class="ss">空座数*<text class="aa">请输入空座数</text></view>
在index.less中输入代码:
.jj{
width: 100%;
height: 34px;
font-size: 20px;
background-color: black;
text-indent: 1em;
}
.gg{
width: 100%;
height: 25px;
text-indent: 1em;
display: flex;
color: rgb(109, 109, 107);
background-color: silver;
}
.ss{
display: flex;
font-size: 20px;
text-indent: 1em;
margin-top: 10px;
}
.aa{
display: flex;
font-size: 15px;
margin-left: 40px;
margin-top: 10px;
}
.dd{
display: flex;
font-size: 15px;
margin-left: 16px;
margin-top: 10px;
}
.nn{
display: flex;
font-size: 15px;
margin-left: 50px;
margin-top: 10px;
}
执行效果:
二. 编程题
在index.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) {}
}
});
在index.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>
在index.wxss中输入代码:
.note {
margin: 40rpx 0 10rpx;
color: #666;
font-size: 120%;
font-weight: 200;
}
.past {
margin-bottom: 30rpx;
font-size: 160%;
font-weight: 300;
}
.settings {
flex-direction: row;
}
.main,.settings {
display: flex;
}
.main {
position: relative;
flex: 2;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
}
.motto {
display: block;
min-height: 84rpx;
line-height: 1.5;
font-size: 26rpx;
}
.zoomout .btn-del,.zoomout .btn-setting,.zoomout .motto,.zoomout .note {
color: #333;
}
.ad-index-float {
position: fixed;
right: 0;
bottom: 0;
width: 80rpx;
height: 80rpx;
z-index: 31;
}
.custom-ad.ad-index-float {
bottom: 94rpx;
}
.custom-ad.custom-ad-iphonex {
bottom: 124rpx!important;
}
.custom-ad-iphonex {
bottom: 0!important;
}
.ad-index-float image {
width: 80rpx;
height: 80rpx;
}
在app.js中输入代码:
var a = require("4E683285C190288C280E5A82494C27D6.js");
wx.cloud.init({
env: "weapp-900m-hawy7"
}), App({
onLaunch: function() {
this.handleTabBar(), this.handleNavigation();
},
onShow: function() {
this.handleTabBar(), this.handleNavigation();
},
handleTabBar: function() {
if (this.globalData.canHideTabBar) var a = setInterval(function() {
wx.hideTabBar({
success: function() {
clearInterval(a);
}
});
}, 16);
},
handleNavigation: function() {
var i = this.globalData.res.version, n = this.globalData.res.SDKVersion, e = a.compareVersion(i, "6.6.0") >= 0, t = a.compareVersion(n, "1.7.0") >= 0;
e && t && (this.globalData.canHideNavigation = !0);
},
globalData: {
res: wx.getSystemInfoSync(),
canHideTabBar: wx.canIUse("hideTabBar"),
canHideNavigation: !1,
isiPhoneX: wx.getSystemInfoSync().model.toLowerCase().match(/iphone x|iphone 11|iphone 12/gim),
statusBarHeight: wx.getSystemInfoSync().statusBarHeight || 0
}
});
在app.json中输入代码:
{
"pages": [
"pages/index/index",
"pages/countdown/countdown",
"pages/meditation/meditation",
"pages/about/about"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#393a3e",
"navigationBarTitleText": "人生进度",
"navigationBarTextStyle": "white",
"navigationStyle": "custom"
},
"tabBar": {
"color": "#999",
"selectedColor": "#999",
"list": [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "images/tab_home.png",
"selectedIconPath": "images/tab_home_selected.png"
},
{
"pagePath": "pages/countdown/countdown",
"text": "年月日",
"iconPath": "images/tab_countdown.png",
"selectedIconPath": "images/tab_countdown_selected.png"
},
{
"pagePath": "pages/meditation/meditation",
"text": "静思",
"iconPath": "images/tab_meditation.png",
"selectedIconPath": "images/tab_meditation_selected.png"
},
{
"pagePath": "pages/about/about",
"text": "关于",
"iconPath": "images/tab_about.png",
"selectedIconPath": "images/tab_about_selected.png"
}
]
},
"navigateToMiniProgramAppIdList": []
}
执行效果: