From 5839959f0a256cf2c73026f43652affa528bf291 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Sat, 2 Apr 2016 07:32:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9openid=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/wechat/activities.html | 53 +------------------------ public/javascripts/wechat/auth.js | 3 ++ public/javascripts/wechat/wechat_dev.js | 49 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 52 deletions(-) diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index ea730d4f7..2fb2fa81d 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -219,58 +219,7 @@ - - + \ No newline at end of file diff --git a/public/javascripts/wechat/auth.js b/public/javascripts/wechat/auth.js index 1d9682720..79f5f96a1 100644 --- a/public/javascripts/wechat/auth.js +++ b/public/javascripts/wechat/auth.js @@ -15,16 +15,19 @@ $(function(){ } window.getOpenId = function(cb){ + alert(g_openid); if (g_openid.length>0){ cb(g_openid); } var code = getUrlParam("code"); + alert(code); $.ajax({ url: '/wechat/get_open_id?code='+code, type: 'get', dataType: 'json', success: function(data){ g_openid = data.openid; + alert(g_openid); cb(g_openid); }, error: function(xhr,err){ diff --git a/public/javascripts/wechat/wechat_dev.js b/public/javascripts/wechat/wechat_dev.js index c921ed64d..18fe67e1f 100644 --- a/public/javascripts/wechat/wechat_dev.js +++ b/public/javascripts/wechat/wechat_dev.js @@ -2,5 +2,54 @@ * Created by root on 3/25/16. */ $(document).ready(function(){ + + var bt=baidu.template; + bt.LEFT_DELIMITER=''; + + var apiUrl = '/api/v1/'; + var loadDataFromServer = function(id, page){ + getOpenId(function(openid){ + $.ajax({ + url: apiUrl + 'activities/' + openid +"?page=" + parseInt(page), + dataType: 'json', + success: function(data){ + setTemplate(data.data, data.all_count, data.count, data.page); + }, + error: function(xhr,status,err){ + console.log(err); + } + }); + }) + + }; + var setTemplate = function(data, all_count, count, page){ + console.log(data); + var html=bt('t:result-list',{activities: data, all_count: all_count, count: count, page: page}); + if (page == 0) { + $('#container').prepend(html); + } else { + $("#more_activities").remove(); + $('#container').append(html); + } + descToggle(); + }; + //内容全部显示与部分隐藏 + var descToggle = function(){ + $(".post-all-content").each(function(){ + var postHeight = $(this).height(); + if (postHeight > 90){ + $(this).parent().next().css("display","block"); + $(this).parent().next().toggle(function(){ + $(this).text("点击隐藏"); + $(this).prev().css("height",postHeight); + },function(){ + $(this).text("点击展开"); + $(this).prev().css("height",90); + }); + } + }); + } + loadDataFromServer(8686, 0); });