微信小程序入门

登录:

login.wxml

<button open-type="getUserInfo" bindgetuserinfo="user">登录</button>

login.js

 1 // pages/login/login.js
 2 Page({
 3 
 4   /**
 5    * 页面的初始数据
 6    */
 7   data: {
 8 
 9   },
10 
11   /**
12    * 生命周期函数--监听页面加载
13    */
14   onLoad: function (options) {
15 
16   },
17   
18   user:function(e){
19     console.log(e)
20     let nickName = e.detail.userInfo.nickName
21     if(e.detail.userInfo){
22       wx.login({
23         success (res) {
24           if (res.code) {
25             //发起网络请求
26             wx.request({
27               url: 'http://www.movie.1808a.com/admin/index/login',
28               data: {
29                 code: res.code,
30                 nickName:nickName
31               },
32               success(res){
33                   if(res.data.code==200){
34                     wx.setStorage({
35                       key:"userid",
36                       data:res.data.data
37                     }),
38                     wx.switchTab({
39                       url: '/pages/index/index',
40                     })
41                   }
42               }
43             })
44           } else {
45             console.log('登录失败!' + res.errMsg)
46           }
47         }
48       })
49     }else{
50       console.log('no')
51     }
52   }
53 })

 

 

 

展示页:

index.wxml

 1 <!--index.wxml-->
 2 <view class="header">
 3   <input type="text" placeholder="搜 索" class="input"/>
 4 </view>
 5 
 6 <!-- 影院热映 -->
 7 <view class="title">
 8   <text class="hot">影院热映</text>
 9   <text class="more">查看更多 > </text>
10 </view>
11 <scroll-view class="movie-hot" scroll-x="true" enable-flex="true">
12   <block wx:for="{{movie}}">
13     <navigator url="/pages/info/info?id={{item.id}}" hover-class="navigator-hover">
14     <view class="box">
15     <image src="{{item.image}}"></image>
16     <view class="name">{{item.title}}</view>
17     <view class="score">评分:{{item.score}}</view>
18   </view>
19 </navigator>
20   </block>
21 </scroll-view>
22 
23 <!-- 豆瓣热门 -->
24 <view class="title">
25   <text>豆瓣热门</text>
26   <text class="more">查看更多 > </text>
27 </view>
28 <view class="movie-hot">
29   <block wx:for="{{movie}}">
30     <view class="box">
31   <image src="{{item.image}}"></image>
32   <view class="name">{{item.title}}</view>
33   <view class="score">评分:{{item.score}}</view>
34   </view>
35   </block>
36 </view>

index.js

 1 //index.js
 2 //获取应用实例
 3 const app = getApp()
 4 
 5 Page({
 6   data: {
 7     
 8   },
 9   onLoad: function () {
10     wx.request({
11       url: 'http://www.movie.1808a.com/home/Movie/index',
12       data: {},
13       header: {'content-type':'application/json'},
14       method: 'GET',
15       dataType: 'json',
16       responseType: 'text',
17       success: (res)=>{
18         // console.log(res.data.data)
19         this.setData({
20           movie:res.data.data
21         })
22       },
23       fail: ()=>{},
24       complete: ()=>{}
25     });
26   }
27   
28 })

 

 

详情:

info.wxml

 1 <!--pages/info/info.wxml-->
 2 <view class="box">
 3   <view>{{info.id}}</view>
 4 <view class="title">{{info.title}}</view>
 5 <view class="image">
 6   <image src="{{info.image}}"></image>
 7 </view>
 8 <view class="score">
 9   评分:{{info.score}}
10 </view>
11 </view>
12 
13 <view>
14   <form catchsubmit="formSubmit" catchreset="formReset">
15     <view class="commont">
16       <text>评论</text>
17       <text>共有{{count}}条评论</text>
18     </view>
19     <input type="text" name="text" class="input"/>
20     <view class="butt">
21       <button style="margin: 30rpx 0" type="primary" formType="submit" data-id="{{info.id}}">提交评论</button>
22     <button style="margin: 30rpx 0"  type="primary" open-type="share">分享</button>
23     </view>
24   </form>
25 </view>
26 
27 
28 <block wx:for="{{comment}}" >
29   <view class="talk">
30     <view class="user">
31     用户{{item.uid}}:
32   </view>
33   <view>
34     {{item.comment}}
35   </view>
36   </view>
37 </block>

info.js

// pages/info/info.js
Page({
  data: {
    mid:0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options)
    wx.request({
      url: 'http://www.movie.1808a.com/home/Movie/info',
      data: {id:options.id},
      header: {'content-type':'application/json'},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (res)=>{
        //console.log(res.data.data)
        this.setData({
          info:res.data.data.data,
          comment:res.data.data.commont,
          count:res.data.data.count
        })
      },
      fail: ()=>{},
      complete: ()=>{}
    });
  },
  formSubmit(e) {
   // console.log(e)
    let mid = e.detail.target.dataset.id
    let text = e.detail.value.text
    let count = 0
    wx.request({
      url: 'http://www.movie.1808a.com/home/Movie/addData',
      data: {mid:mid,uid:1,comment:text},
      header: {'content-type':'application/json'},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (res)=>{
        console.log(res);
        this.setData({
          comment:res.data.data.commont,
          count:res.data.data.count
        })
      },
      fail: ()=>{},
      complete: ()=>{}
    });
  },
   /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

 

posted @ 2020-12-30 13:27  SlytherinGirl  阅读(130)  评论(0)    收藏  举报