Browse Source

调用api.home api.view 接口
商品详情分享功能

wangxin 6 years ago
parent
commit
fecfda5cec

+ 1 - 1
app.json

@@ -1,9 +1,9 @@
 {
   "pages": [
+    "template/home/index",
     "template/carts/index",
     "template/poster/index",
     "template/view/index",
-    "template/home/index",
     "template/pay/index",
     "template/login/index"
   ],

+ 1 - 29
app.wxss

@@ -1,39 +1,11 @@
 @import 'static/weiui/weui.wxss';
+@import 'dever/package/wxParse/wxParse.wxss';
 
 page{
     background-color: #FFFFFF;
     font-size: 16px;
     font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
 }
-/*
-.page__hd {
-    padding: 40px;
-}
-.page__bd {
-    padding-bottom: 40px;
-}
-.page__bd_spacing {
-    padding-left: 15px;
-    padding-right: 15px;
-}
-
-.page__ft{
-    padding-bottom: 10px;
-    text-align: center;
-}
-
-.page__title {
-    text-align: left;
-    font-size: 20px;
-    font-weight: 400;
-}
-
-.page__desc {
-    margin-top: 5px;
-    color: #888888;
-    text-align: left;
-    font-size: 14px;
-}*/
 .nxh__button {
   background: #539804;
   color: #fff;

+ 3 - 1
dever/config.js

@@ -4,7 +4,9 @@ var config =
     host : 
     {
         // 主域名
-        'main': 'http://192.168.33.10/leek/product/?l='
+        'main': 'http://192.168.33.10/leek/product/?l=',
+        'product': 'https://api.nongchanghezi.com/product/?l=',
+        'passport':'https://api.nongchanghezi.com/passport/?l='
     },
 
     // 项目id

+ 3 - 2
dever/core.js

@@ -81,9 +81,10 @@ var dever =
     }
 
     //html解析
-    ,html : function()
+    , html: function (bindName, data, target)
     {
-        var wxParse = this.package('wxParse');
+        var wxParse = this.package('wxParse/wxParse');
+        wxParse.wxParse(bindName, 'html', data, target, 0);
     }
 
     //获取请求

+ 17 - 62
template/home/index.js

@@ -3,35 +3,24 @@ Page({
   data: {
       test : 1
   },
-
-  /**
-   * 生命周期函数--监听页面加载
-   */
   onLoad: function (options) {
-    /*var self = this;
     // 初始化购物车
-    self.dever.carts(self, 'carts.save', 'carts/index');
-    var success = function(data, res)
-    {
-        self.dever.setList(self, data.product);
-    };
-    self.dever.request('main.api.home', {}, {success: success});*/
-
-    //test - begin
-    var list = new Array();
-    for(var i=1; i<4; i++){
-      var item = new Object();
-      item.id = i;
-      item.pic = '/static/img/item-'+(1+Math.round(Math.random()*1))+'.png';
-      item.name = i+'盒有机韭菜';
-      item.price = i*20;
-      list.push(item);
+    //self.dever.carts(self, 'carts.save', 'carts/index');
+    var that = this;
+    var callback = {
+      success: function(data, res){
+        that.dever.setList(that, data.product);
+        that.dever.stopPullDown();
+      }
     }
-    this.dever.setList(this, list);
-    this.dever.stopPullDown();
-    //test - end
+    that.dever.request('product.api.home', {
+      signature:''
+    },callback);
   },
 
+  /**
+   * 查看商品详情
+   */
   view: function (event) {
     if (typeof (event) == 'object') {
       var id = event.currentTarget.dataset.id
@@ -41,6 +30,9 @@ Page({
     this.dever.location('view/index?id=' + id);
   },
 
+  /**
+   * 添加购物车
+   */
   addCarts: function (event){
     if (typeof (event) == 'object') {
       var id = event.currentTarget.dataset.id
@@ -50,45 +42,8 @@ Page({
     this.dever.location('carts/index?id=' + id);
   },
 
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady: function () {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow: function () {
-    
-  },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide: function () {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload: function () {
-
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
   onPullDownRefresh: function () {
     this.dever.startPullDown(this);
-  },
+  }
 
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage: function () {
-
-  },
 })

+ 2 - 2
template/home/index.wxss

@@ -3,11 +3,11 @@
 }
 .page__hd
 {
-  margin-top:28rpx;
   border-radius: 5px;
   box-shadow: 0rpx 3rpx 5rpx #DBDBDB;
-  margin: 28rpx 30rpx 0 30rpx;
+  margin: 30rpx 30rpx 0 30rpx;
   padding: 0rpx;
+  overflow: hidden;
 }
 .pic
 {

+ 0 - 1
template/pay/index.wxml

@@ -1,5 +1,4 @@
 <image class='pay-ok' src='/static/img/ok.png'></image>
 <view class='pay-result-h1'>下单成功</view>
 <view class='pay-result-h2'>您的订单已经支付成功,马上为您发货!</view>
-<button class='look-order-detail nxh__button'>查看订单详情</button>
 <button class='share-friends nxh__button'>分享给朋友</button>

+ 0 - 6
template/pay/index.wxss

@@ -16,10 +16,4 @@ page {
 .pay-result-h2 {
   font-size: 30rpx;
   color: #666;
-}
-.look-order-detail {
-  margin: 70rpx 0 30rpx;
-  background: #fff;
-  border:1rpx solid #539804;
-  color: #539804;
 }

+ 32 - 49
template/view/index.js

@@ -1,65 +1,48 @@
 Page({
-
-  /**
-   * 页面的初始数据
-   */
+  dever: getApp().dever,
+  product: null,
   data: {
-    
+    content: ""
   },
 
-  /**
-   * 生命周期函数--监听页面加载
-   */
   onLoad: function (options) {
-  
+    var that = this;
+    var callback = {
+      success: function (data, res) {
+        that.product = data.product;
+        var temp = that.dever.html('content', data.product.content, that);
+        that.setData({
+          content: temp
+        })
+      }
+    }
+    that.dever.request('product.api.view',{
+      signature: '',
+      id: options.id
+    }, callback);
   },
 
   /**
-   * 生命周期函数--监听页面初次渲染完成
+   * 分享
    */
-  onReady: function () {
-  
+  onShareAppMessage: function (options){
+    wx.showShareMenu({
+      withShareTicket: true,
+      success: function(res){
+        //TODO 
+      },
+      fail: function(res){
+        //TODO 
+      }
+    })  
+    //options.from可以用来判断是从自定义button打开的转发页面,还是从右上角的打开的转发页面。
   },
 
   /**
-   * 生命周期函数--监听页面显示
+   * 立即购买
    */
-  onShow: function () {
-  
-  },
+  doBuy: function(){
 
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide: function () {
-  
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload: function () {
-  
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh: function () {
-  
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom: function () {
-  
-  },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage: function () {
-  
   }
+
 })

+ 7 - 3
template/view/index.wxml

@@ -1,7 +1,11 @@
+<!-- 引入模板 -->
+<import src="../../dever/package/wxParse/wxParse.wxml"/>
+
 <view class='content'>
-  <image mode='widthFix' src='/static/img/item-1.png'></image>
+  <!-- 这一块是富文本 显示的内容区 -->
+  <template is="wxParse" data="{{wxParseData:content.nodes}}"/>
 </view>
 <view class='bottom'>
-  <button class='nxh__button'>分享给好友</button>
-  <button class='nxh__button'>立即购买</button>
+  <button class='nxh__button' open-type='share'>分享给好友</button>
+  <button class='nxh__button' bindtap='doBuy'>立即购买</button>
 </view>

+ 3 - 0
template/view/index.wxss

@@ -1,3 +1,6 @@
+.content {
+  padding: 30rpx 30rpx 150rpx 30rpx;
+}
 .content image {
   width: 750rpx;
 }