緊急情況~ 找不到廁所? 晴天霹靂 褲衩一聲? 完嘍~~快來(lái)用廁所雷達(dá)吧~~~。作為一個(gè)優(yōu)秀的樓主,胖子我不僅寫(xiě)了代碼,連廣告次都想好了,哇咔咔咔~~~~“廁所找的快,排的才痛快”。 練習(xí)區(qū)里看到一個(gè)“廁所雷達(dá)”就 ...




//index.js var app = getApp() var winHeight = 0 var winWidth = 0 Page({ data: { //背景圖片,現(xiàn)在沒(méi)有 img:'/pages/image/123.png', //確定左邊距距離,上邊距距離,廁所title,頭像 dataArr:[{'left':200,'top':100,'title':'我家?guī)詈?#39;,'img':'/pages/image/1.png'}, {'left':20,'top':400,'title':'amis的小屋','img':'/pages/image/2.png'}, {'left':540,'top':440,'title':'老丁的寶盆','img':'/pages/image/3.png'}, {'left':240,'top':800,'title':'雪姐專(zhuān)用坑','img':'/pages/image/4.png'}] }, //進(jìn)頁(yè)面后獲取數(shù)據(jù) onLoad: function () { console.log('onLoad') var that = this //調(diào)用應(yīng)用實(shí)例的方法獲取全局?jǐn)?shù)據(jù) app.getUserInfo(function(userInfo){ console.log(userInfo) //更新數(shù)據(jù) that.setData({ userInfo:userInfo }) }) //獲取數(shù)據(jù) wx.getSystemInfo({ success: function(res) { console.log(res) winHeight = res.windowHeight; winWidth = res.windowWidth; } }) // 使用 wx.createContext 獲取繪圖上下文 context var context = wx.createContext() context.arc(winWidth/2, winHeight/2, 50, 0, 2 * Math.PI, true) context.arc(winWidth/2, winHeight/2, 100, 0, 2 * Math.PI, true) context.arc(winWidth/2, winHeight/2, 150, 0, 2 * Math.PI, true) context.arc(winWidth/2, winHeight/2, 200, 0, 2 * Math.PI, true) context.arc(winWidth/2, winHeight/2, 250, 0, 2 * Math.PI, true) context.arc(winWidth/2, winHeight/2, 300, 0, 2 * Math.PI, true) context.setStrokeStyle('red') context.setLineWidth(1) context.stroke() // 調(diào)用 wx.drawCanvas,通過(guò) canvasId 指定在哪張畫(huà)布上繪制,通過(guò) actions 指定繪制行為 wx.drawCanvas({ canvasId: 'radar', actions: context.getActions() // 獲取繪圖動(dòng)作數(shù)組 }) }, onShareAppMessage: function() { // 用戶點(diǎn)擊右上角分享 return { title: '廁所雷達(dá)', // 分享標(biāo)題 desc: '廁所找的快,排的才痛快', // 分享描述 path: 'path' // 分享路徑 } } })
wxml:
<!--index.wxml-->
<canvas canvas-id="radar">
<image class="userinfo" src="{{userInfo.avatarUrl}}"></image>
<block wx:for="{{dataArr}}">
<navigator url="../logs/logs?title={{item.title}}&img={{item.img}}">
<view class="toiletView" style="left:{{item.left}}rpx;top:{{item.top}}rpx" bindtap="toiletDetails" id="{{index}}">
<image class="toiletView-image" src="{{item.img}}"></image>
<text class="toiletView-text">{{item.title}}</text>
</view>
</navigator>
</block>
</canvas>
wxss:
/**index.wxss**/ page{ background: black; height: 100%; } canvas{ width: 100%; height: 100%; } .userinfo { position:absolute; top: 561rpx; left:311rpx; width: 128rpx; height: 128rpx; border-radius: 50%; } .toiletView{ position:absolute; width: 180rpx; height: 180rpx; } .toiletView-image{ position:absolute; left: 13px; top: 0px; width: 128rpx; height: 128rpx; border-radius: 50%; } .toiletView-text{ position:absolute; bottom: 10rpx; font-size: 30rpx; color: orangered; width: 180rpx; text-align: center; }
小程序-廁所雷達(dá).zip