Code Monkey home page Code Monkey logo

vr_wechat's Introduction

BLUES VR for WeChat

全景图片浏览微信小程序,支持 VR 模式。

依赖

基于 WeUIkrpano 实现。

关键代码

获取全景图列表

<!--pages/index/index.wxml-->

<block wx:for="{{pano_type}}" wx:key="{{item.id}}">
  <view>{{item.type}}</view>
  <view>
    <navigator url="url?v={{item.id}}" wx:for="{{item.list}}" wx:key="{{item.id}}">
      <view>{{item.title}}</view>
      <view wx:if="{{item.isNew}}">New</view>
      ...
    </navigator>
  </view>
</block>
// pages/index/index.js

data: {
  pano_type: []
},

onLoad: function (options) {
  var that = this;
  wx.request({
    url: "url",
    success: function (res) {
      console.log("[res.data]: %o", res.data);
      that.setData({
        pano_type: res.data.pano
      })
    }
  });
}

加入/移除收藏

<!--pages/index/index.wxml-->

<navigator bindlongpress="joinFavorite" data-id="{{item.id}}" data-title="{{item.title}}">
  ...
</navigator>
// pages/index/index.js

joinFavorite: function (e) {
  var id = e.currentTarget.dataset.id, favorites = wx.getStorageSync("favorites") || [], i = favorites.indexOf(id);
  wx.showModal({
    title: i < 0 ? "加入收藏" : "移出收藏",
    content: "将“" + e.currentTarget.dataset.title + "”" + (i < 0 ? "加入" : "移出") + "个人收藏?",
    confirmText: i < 0 ? "加入" : "移出",
    cancelText: "取消",
    success: function (res) {
      if (res.confirm) {
        i < 0 ? favorites.unshift(id) : favorites.splice(i, 1);
        wx.setStorageSync("favorites", favorites);
        console.log("[favorites]: %o", favorites);
      }
    }
  });
}

获取收藏列表

<!--pages/index/my_favorites.wxml-->

<block wx:for="{{favorites_list}}" wx:for-index="i" wx:key="{{favorites_list[i][0]}}">
  <navigator url="url?v={{favorites_list[i][0]}}">
    <view>{{favorites_list[i][1]}}</view>
    ...
  </navigator>
</block>
// pages/my_favorites/my_favorites.js

data: {
  favorites_list: []
},

onLoad: function (options) {
  var that = this;
  wx.request({
    url: "url",
    success: function (res) {
      var favorites_list = [], favorites = wx.getStorageSync("favorites") || [];
      for (var i = 0; i < res.data.pano.length; i++) {
        for (var j = 0; j < res.data.pano[i].list.length; j++) {
          favorites.indexOf(res.data.pano[i].list[j].id) >= 0 && favorites_list.push([res.data.pano[i].list[j].id, res.data.pano[i].list[j].title]);
        };
      };
      console.log("[favorites_list]: %o", favorites_list);
      that.setData({
        favorites_list: favorites_list
      })
    }
  });
}

嵌入 H5

详见 https://github.com/iflycn/vr

vr_wechat's People

Contributors

iflycn avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.