Browse Source

wx_login

用户登录
SZIIT2001010449 3 years ago
parent
commit
05430fad8d

+ 1 - 1
app.js

@@ -5,7 +5,7 @@ App({
             console.error()
             console.error()
         }else{
         }else{
             wx.cloud.init({
             wx.cloud.init({
-                env:'creator-xcq6k',
+                env:'weiyong-6gzb21u1bf15680a',
                 traceUser:true,
                 traceUser:true,
             })
             })
         }
         }

+ 2 - 1
app.json

@@ -1,6 +1,7 @@
 {
 {
     "pages": [
     "pages": [
-        "pages/index/index"
+        "pages/index/index",
+        "pages/insert/insert"
     ],
     ],
     "window": {
     "window": {
         "backgroundTextStyle": "light",
         "backgroundTextStyle": "light",

+ 111 - 1
pages/index/index.js

@@ -1,4 +1,5 @@
 // index.js
 // index.js
+const db=wx.cloud.database();
 Page({
 Page({
     /**
     /**
     * 页面的初始数据
     * 页面的初始数据
@@ -26,7 +27,51 @@ Page({
             }
             }
             ]
             ]
             },
             },
+            input_name:function(e){
+                this.setData({user_name:e.detail.value})
+            },
+            input_pwds:function(e){
+                
+                this.setData({user_pwds:e.detail.value})
+            },
+            login:function(){
+                console.log("登录获取的参数:"+this.data.user_name+","+this.data.user_pwds);
+                var that=this;
+              wx.request({
+                url: 'http://localhost:8084/login',
+               method:'POST',
+               header:{'content-type':'application/x-www-form-urlencoded'},
+               data:{
+                   'user_name':that.data.user_name,
+                   'user_pwds':that.data.user_pwds
+               },
+               success:function(res){
+                   var resData=res.data;
+                   console.log(":"+resData);
+                   if(resData==true){
+                       wx.showToast({
+                         title: '登录成功',
+                         icon:'success',
+                         duration:15000,
+                         success:function(){
+                             wx.navigateTo({
+                               url: '../insert/insert',
+                             })
+                         }
+                       })
+                   }else{
+                       wx.showToast({
+                         title: '登陆失败',
+                         icon:'none',
+                         duration:2000,
+                       })
+                   }
+               }
+              })
+
+            },
             toggleLogin: function(){
             toggleLogin: function(){
+                
             this.setData({
             this.setData({
             flag: !this.data.flag
             flag: !this.data.flag
             })
             })
@@ -34,7 +79,72 @@ Page({
             /**
             /**
             * 生命周期函数--监听页面加载
             * 生命周期函数--监听页面加载
             */
             */
-            onLoad: function (options) {
+           onLoad: function (options) {
+            //    增
+            // db.collection('product').add({
+            // data:{
+            // name:'小刘',
+            // age:20,
+            // gender:'男'
+            // },
+            // success(res){
+            // console.log('添加数据成功',res)
+            // },
+            // fail(res){
+            // console.log('添加数据失败',res)
+            // }
+            // })
+
+
+            // 删
+            // db.collection('product').doc('6d85a2b962a6a5ac0a4953f76ba21682').remove({
+            //     success(res){
+            //     console.log("数据删除成功",res)
+            //     },
+            //     fail(res){
+            //     console.log("数据删除失败",res)
+            //     }
+            //     })
+
+
+            // 改
+            // db.collection('product').doc('058dfefe62a6a83308856bcf1ec46e96').update({
+            //     data:{
+            //     name:'CreatorRay',
+            //     QQ:505417246
+            //     },
+            //     success(res){
+            //     console.log("数据修改成功")
+            //     },
+            //     fail(res){
+            //     console.log("数据修改失败")
+            //     }
+            //     })
+            
+
+            // 查 get
+            // db.collection('product').get({
+            //     success(res){
+            //     console.log("查询成功",res)
+            //     },
+            //     fail(res){
+            //     console.log("查询失败",res)
+            //     }
+            //     })
+               
+
+            // 查 where
+            // db.collection('product').where({
+            //     name:'CreatorRay'
+            //     }).get({
+            //     success(res){
+            //     console.log('name 为 Creator 的数据成功查到',res)
+            //     },
+            //     fail(res){
+            //     console.log('查询失败',res)
+            //     }
+            //     })
+               
             },
             },
             /**
             /**
             * 生命周期函数--监听页面初次渲染完成
             * 生命周期函数--监听页面初次渲染完成

+ 3 - 3
pages/index/index.wxml

@@ -4,13 +4,13 @@
  <view class="v1" wx:if="{{flag}}">
  <view class="v1" wx:if="{{flag}}">
  <view class="v2">
  <view class="v2">
  <!-- <image class="img1" src=""></image> -->
  <!-- <image class="img1" src=""></image> -->
- <input type="text" placeholder="请输入用户名/手机"/>
- <input type="password" placeholder="请输入密码"/>
+ <input type="text" bindinput="input_name" placeholder="请输入用户名/手机"/>
+ <input type="password"  bindinput="input_pwds" placeholder="请输入密码"/>
  <view class="v3">
  <view class="v3">
  <text>注册</text>
  <text>注册</text>
  <text class="text2">找回密码</text>
  <text class="text2">找回密码</text>
  </view>
  </view>
- <button class="button">登录</button>
+ <button class="button" bindtap="login">登录</button>
  <button class="button" bindtap="toggleLogin">二维码登录</button>
  <button class="button" bindtap="toggleLogin">二维码登录</button>
  </view>
  </view>
  </view>
  </view>

+ 79 - 0
pages/insert/insert.js

@@ -0,0 +1,79 @@
+// pages/insert.js
+const db=wx.cloud.database();
+Page({
+
+    /**
+     * 页面的初始数据
+     */
+    data: {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad: function (options) {
+        db.collection('product').add({
+        data:{
+        name:'小刘',
+        age:20,
+        gender:'男'
+        },
+        success(res){
+        console.log('添加数据成功',res)
+        },
+        fail(res){
+        console.log('添加数据失败',res)
+        }
+        })
+        },
+
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload: function () {
+
+    },
+
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh: function () {
+
+    },
+
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom: function () {
+
+    },
+
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage: function () {
+
+    }
+})

+ 3 - 0
pages/insert/insert.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 2 - 0
pages/insert/insert.wxml

@@ -0,0 +1,2 @@
+<!--pages/insert.wxml-->
+<text>pages/insert.wxml</text>

+ 1 - 0
pages/insert/insert.wxss

@@ -0,0 +1 @@
+/* pages/insert.wxss */

+ 4 - 4
project.config.json

@@ -4,7 +4,7 @@
         "ignore": []
         "ignore": []
     },
     },
     "setting": {
     "setting": {
-        "urlCheck": true,
+        "urlCheck": false,
         "es6": true,
         "es6": true,
         "enhance": true,
         "enhance": true,
         "postcss": true,
         "postcss": true,
@@ -20,7 +20,7 @@
         "checkInvalidKey": true,
         "checkInvalidKey": true,
         "checkSiteMap": true,
         "checkSiteMap": true,
         "uploadWithSourceMap": true,
         "uploadWithSourceMap": true,
-        "compileHotReLoad": true,
+        "compileHotReLoad": false,
         "lazyloadPlaceholderEnable": false,
         "lazyloadPlaceholderEnable": false,
         "useMultiFrameRuntime": true,
         "useMultiFrameRuntime": true,
         "useApiHook": true,
         "useApiHook": true,
@@ -30,7 +30,7 @@
             "disablePlugins": [],
             "disablePlugins": [],
             "outputPath": ""
             "outputPath": ""
         },
         },
-        "useIsolateContext": false,
+        "useIsolateContext": true,
         "userConfirmedBundleSwitch": false,
         "userConfirmedBundleSwitch": false,
         "packNpmManually": false,
         "packNpmManually": false,
         "packNpmRelationList": [],
         "packNpmRelationList": [],
@@ -43,7 +43,7 @@
     },
     },
     "compileType": "miniprogram",
     "compileType": "miniprogram",
     "libVersion": "2.21.3",
     "libVersion": "2.21.3",
-    "appid": "touristappid",
+    "appid": "wx47533c1dbade1725",
     "projectname": "weiyong",
     "projectname": "weiyong",
     "debugOptions": {
     "debugOptions": {
         "hidedInDevtools": []
         "hidedInDevtools": []