微信小程序“豆瓣电影”

				版权声明:本文为博主原创文章,未经博主允许不得转载。					https://blog.csdn.net/CNZSWYMP/article/details/78676642				</div>
							            <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-f57960eb32.css">
					<div class="htmledit_views" id="content_views">
            <p>开发环境为微信web开发者工具,实现的功能是可以在首页查看豆瓣电影评分前250名并且可以点击跳转到详情页,在搜索页输入关键字搜索相关电影。效果图如下</p>

代码


 
 
  1. app.json
  2. {
  3. "pages":[
  4. "pages/index/index",
  5. "pages/movie/movie",
  6. "pages/search/search",
  7. "pages/profile/profile"
  8. ],
  9. "window":{
  10. "navigationBarBackgroundColor": "#35495e",
  11. "navigationBarTextStyle": "white",
  12. "navigationBarTitleText": "豆瓣电影",
  13. "backgroundColor": "#fff",
  14. "backgroundTextStyle": "dark",
  15. "enablePullDownRefresh": true
  16. },
  17. "tabBar":{
  18. "list":[
  19. {
  20. "text": "推荐电影",
  21. "iconPath": "images/board.png",
  22. "selectedIconPath": "images/board-actived.png",
  23. "pagePath": "pages/index/index"
  24. },
  25. {
  26. "text": "发现电影",
  27. "iconPath": "images/search.png",
  28. "selectedIconPath": "images/search_black.png",
  29. "pagePath": "pages/search/search"
  30. },
  31. {
  32. "text": "我的电影",
  33. "iconPath": "images/profile.png",
  34. "selectedIconPath": "images/profile-actived.png",
  35. "pagePath": "pages/profile/profile"
  36. }
  37. ]
  38. }
  39. }
  40. app.wxss
  41. page{
  42. font-family: "Microsoft YaHei";
  43. background-color: #fff;
  44. display: flex;
  45. /*纵向排列*/
  46. flex-direction: column;
  47. }
  48. .page-header{
  49. display: flex;
  50. /*横向居中对齐*/
  51. justify-content: center;
  52. border-bottom: 2rpx solid #ccc;
  53. margin-bottom: 10rpx;
  54. }
  55. .page-header-text{
  56. padding: 20rpx 40rpx;
  57. color: #999;
  58. font-size: 40rpx;
  59. text-align: center;
  60. }
  61. .page-body{
  62. display: flex;
  63. flex: 1;
  64. flex-direction: column;
  65. }
  66. .item{
  67. display: flex;
  68. padding: 20rpx 40rpx;
  69. border-bottom: 2rpx solid #eee;
  70. }
  71. .poster{
  72. width: 130rpx;
  73. height: 160rpx;
  74. margin-right: 20rpx;
  75. }
  76. .meta{
  77. flex: 1;
  78. }
  79. .item.title,.item.sub-title{
  80. display: block;
  81. margin-bottom: 14rpx;
  82. }
  83. .title{
  84. font-size: 35rpx;
  85. }
  86. .sub-title{
  87. font-size: 25rpx;
  88. color: #c0c0c0;
  89. }
  90. .artists{
  91. font-size: 26rpx;
  92. color: #999;
  93. }
  94. .rating{
  95. font-size: 28rpx;
  96. font-weight: bold;
  97. color: red;
  98. }

 
 
  1. index.wxml
  2. <view class= "page-header">
  3. <text class= "page-header-text">{{title}}</text>
  4. </view>
  5. <scroll-view class= "page-body" scorll-y= "true">
  6. <navigator url= "../movie/movie?id={{item.id}}" wx: for= "{{movies}}">
  7. <view class= "item">
  8. <image class= "poster"src= "{{item.images.small}}"></image>
  9. <view class= "meta">
  10. <text class= "title">{{item.title}}</text>
  11. <text class= "sub-title">
  12. {{item.original_title}} ({{item.year}})</text>
  13. <text class= "artists">
  14. <text wx: for= "{{item.directors}}">
  15. {{item.name}}
  16. </text>
  17. </text>
  18. </view>
  19. <view class= "rating">
  20. <text>{{item.rating.average}}</text>
  21. </view>
  22. </view>
  23. </navigator>
  24. </scroll-view>
  25. index.wxss
  26. /**index.wxss**/
  27. .userinfo {
  28. display: flex;
  29. flex-direction: column;
  30. align-items: center;
  31. }
  32. .userinfo-avatar {
  33. width: 128rpx;
  34. height: 128rpx;
  35. margin: 20rpx;
  36. border-radius: 50%;
  37. }
  38. .userinfo-nickname {
  39. color: #aaa;
  40. }
  41. .usermotto {
  42. margin-top: 200px;
  43. }
  44. index.js
  45. var API_URL = 'https://api.douban.com/v2/movie/top250'
  46. Page({
  47. data: {
  48. title: "加载中...",
  49. movies:[]
  50. } ,
  51. onLoad:function(){
  52. var that = this;
  53. wx.showToast({
  54. title: "加载中...",
  55. icon: "loading",
  56. duration: 10000
  57. });
  58. //发出的请求必须是HTTPS的
  59. wx.request({
  60. url: API_URL,
  61. data:{},
  62. header:{
  63. //进行网络数据请求出现400 是因为请求header的Content-type变了
  64. 'content-type': 'json'
  65. },
  66. success:function(res){
  67. //隐藏消息提示框
  68. wx.hideToast();
  69. var data = res.data;
  70. console.log(data);
  71. that.setData({
  72. title:data.title,
  73. movies:data.subjects
  74. });
  75. }
  76. });
  77. }
  78. })

 


 
 
  1. movie.wxml
  2. <scroll-view scroll-y= "true">
  3. <view class= "meta">
  4. <image class= "poster" src= "{{movie.images.large}}" background-size= "cover"></image>
  5. <text class= "title">{{movie.title}}({{movie.year}})</text>
  6. <text class= "info">评分:{{movie.rating.average}}</text>
  7. <text class= "info">导演:<block wx: for= "{{movie.directors}}">{{item.name}}</block></text>
  8. <text class= "info">主演:<block wx: for= "{{movie.casts}}">{{item.name}}</block></text>
  9. </view>
  10. <view class= "summary">
  11. <text class= "label">摘要:</text>
  12. <text class= "content">{{movie.summary}}</text>
  13. </view>
  14. </scroll-view>
  15. movie.wxss
  16. .meta{
  17. display: flex;
  18. flex-direction: column;
  19. align-items: center;
  20. height: 1000rpx;
  21. padding: 50rpx 40rpx;
  22. }
  23. .poster{
  24. width: 80%;
  25. height: 80%;
  26. margin: 20rpx;
  27. }
  28. .title{
  29. font-style: 42prx;
  30. color: #444;
  31. }
  32. .info{
  33. font-size: 18rpx;
  34. color: #888;
  35. margin-top: 20rpx;
  36. width: 80%;
  37. }
  38. .summary{
  39. width: 80%;
  40. margin: 30rpx auto;
  41. }
  42. .label{
  43. display: block;
  44. }
  45. .content{
  46. color: #666;
  47. font-size: 20rpx;
  48. padding: 10rpx;
  49. }
  50. movie.js
  51. var API_URL = 'https://api.douban.com/v2/movie/subject/'
  52. Page({
  53. data: {
  54. movie:{}
  55. },
  56. onLoad: function ( params) {
  57. // console.log(params);
  58. var that = this;
  59. wx.request({
  60. url: API_URL+ params.id,
  61. data: {},
  62. header: {
  63. 'content-type': 'json' // 默认值
  64. },
  65. success: function (res) {
  66. // console.log(res.data)
  67. that.setData({
  68. movie:res.data
  69. });
  70. }
  71. })
  72. },
  73. })

 


 
 
  1. profile.wxml
  2. <view class= "container">
  3. <view bindtap= "bindViewTap" class= "userinfo">
  4. <image class= "userinfo-avatar" src= "{{userInfo.avatarUrl}}" background-size= "cover"></image>
  5. </view>
  6. <view class= "infohead">电影</view>
  7. <view class= "infolist" wx: for= "{{infoList}}">
  8. <view class= "infoitem">{{item.text}}</view>
  9. </view>
  10. <view class= "infohead">其他</view>
  11. <view bindtap= "bindViewTap" class= "infolist" wx: for= "{{other}}">
  12. <view class= "infoitem">{{item.text}}</view>
  13. </view>
  14. </view>
  15. profile.wxss
  16. .container {
  17. height: 100%;
  18. display: flex;
  19. flex-direction: column;
  20. box-sizing: border-box;
  21. padding: 10px;
  22. }
  23. .userinfo {
  24. display: flex;
  25. flex-direction: column;
  26. align-items: center;
  27. }
  28. .userinfo-avatar {
  29. width: 128rpx;
  30. height: 128rpx;
  31. border-radius: 50%;
  32. }
  33. .userinfo-nickname {
  34. color: #aaa;
  35. font-size: 6px;
  36. }
  37. .infohead{
  38. font-size: 16px;
  39. border-bottom: 1px solid #dadada;
  40. padding-top: 30px;
  41. padding-bottom: 15px;
  42. }
  43. .infoitem{
  44. position: relative;
  45. padding: 15px;
  46. -webkit-box-align: center;
  47. -ms-flex-align: center;
  48. align-items: center;
  49. border-bottom: 1px solid #dadada;
  50. }
  51. profile.js
  52. var app =getApp()
  53. Page({
  54. data: {
  55. text: "Page profiles",
  56. infoList:[
  57. {
  58. text: "我的电影票"
  59. },
  60. {
  61. text: "我的兑奖券"
  62. },
  63. {
  64. text: "我的优惠券"
  65. },
  66. {
  67. text: "想看、看过的电影"
  68. }
  69. ],
  70. other:[
  71. {
  72. text: "点这里寻找你喜欢的电影哦"
  73. },
  74. {
  75. text: "猜你喜欢的电影"
  76. }
  77. ],
  78. userInfo:{}
  79. },
  80. onLoad: function (options) {
  81. var that = this;
  82. app.getUserInfo(function(userInfo){
  83. that.setData({
  84. userInfo:userInfo
  85. })
  86. });
  87. console.log(that.data.userInfo)
  88. },
  89. bindViewTap:function(e){
  90. var film =e.currentTarget;
  91. wx.navigateTo({
  92. url: '../../search/search'
  93. })
  94. }
  95. })

 


 
 
  1. search.wxml
  2. <view class= "page-header">
  3. <input class= "page-header-text" placeholder= "输入搜索关键词" auto-focus
  4. bindchange= "search"/>
  5. </view>
  6. <scroll-view class= "page-body" scorll-y= "true">
  7. <navigator url= "../movie/movie?id={{item.id}}" wx: for= "{{movies}}">
  8. <view class= "item">
  9. <image class= "poster"src= "{{item.images.small}}"></image>
  10. <view class= "meta">
  11. <text class= "title">{{item.title}}</text>
  12. <text class= "sub-title">
  13. {{item.original_title}} ({{item.year}})</text>
  14. <text class= "artists">
  15. <text wx: for= "{{item.directors}}">
  16. {{item.name}}
  17. </text>
  18. </text>
  19. </view>
  20. <view class= "rating">
  21. <text>{{item.rating.average}}</text>
  22. </view>
  23. </view>
  24. </navigator>
  25. </scroll-view>
  26. search.js
  27. var API_URL = 'https://api.douban.com/v2/movie/search';
  28. Page({
  29. data: {
  30. movies:[]
  31. },
  32. //编译时此处有错 注意e!
  33. search:function(e){
  34. if(!e.detail. value){
  35. return;
  36. }
  37. wx.showToast({
  38. title: "加载中...",
  39. icon: "loading",
  40. duration: 10000
  41. });
  42. var that = this;
  43. wx.request({
  44. url: API_URL+ "?q="+e.detail. value,
  45. data:{},
  46. header: {
  47. 'content-type': 'json' // 默认值
  48. },
  49. success:function(res){
  50. // console.log(res.data);
  51. wx.hideToast();
  52. that.setData({
  53. movies:res.data.subjects
  54. });
  55. }
  56. });
  57. }
  58. })

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值