首頁  >  文章  >  微信小程式  >  小程式開發廁所雷達實例分享

小程式開發廁所雷達實例分享

高洛峰
高洛峰原創
2017-03-22 17:11:001733瀏覽

緊急情況~ 找不到廁所? 晴天霹靂 褲衩一聲? 完嘍~~快來用廁所雷達~~~。身為一個優秀的樓主,我不只寫了程式碼,連廣告次都想好了,哇咔咔咔~~~~  「廁所找的快,排的才痛快」。
練習區裡看到一個“廁所雷達”就來做了下,主要還是為了練習小程序“控件的基本用法”和“頁間的交互”,CSS依舊讓我感到頭疼,不過比上次的demo「石頭剪刀布」好了很多了HOHO。 (PS:頁面有好幾個,就先貼上首頁的程式碼吧,想看的小夥伴就下載一下然後咱們互相交流哦,註釋都寫好了的說。哦對了,新的分享功能也加進去了,當然廣告詞已經寫在分享裡了。

小程式開發廁所雷達實例分享#js:

//index.js
var app = getApp()
var winHeight = 0
var winWidth = 0
Page({
  data: {
      //背景图片,现在没有
      img:'/pages/image/123.png',
      //确定左边距距离,上边距距离,厕所title,头像
      dataArr:[{'left':200,'top':100,'title':'我家厕所最好','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':'雪姐专用坑','img':'/pages/image/4.png'}]
  },
  //进页面后获取数据
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
              console.log(userInfo)
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
    //获取数据
    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()
    // 调用 wx.drawCanvas,通过 canvasId 指定在哪张画布上绘制,通过 actions 指定绘制行为
    wx.drawCanvas({
      canvasId: 'radar',
      actions: context.getActions() // 获取绘图动作数组
    })
  },
  onShareAppMessage: function() {
    // 用户点击右上角分享
    return {
      title: '厕所雷达', // 分享标题
      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;
}

小程式開發廁所雷達實例分享

#

以上是小程式開發廁所雷達實例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn