Преглед изворни кода

注册,登录,修改密码

chen пре 5 година
родитељ
комит
9215e2ec0a
8 измењених фајлова са 211 додато и 27 уклоњено
  1. 2 0
      app.js
  2. 39 16
      pages/home/index.js
  3. 62 0
      pages/login/index.js
  4. 12 1
      pages/my/index.js
  5. 41 0
      pages/register/index.js
  6. 7 4
      pages/register/index.wxml
  7. 44 2
      pages/updatePassword/index.js
  8. 4 4
      pages/updatePassword/index.wxml

+ 2 - 0
app.js

@@ -21,6 +21,8 @@ App({
   globalData: {
   globalData: {
     share: false,  // 分享默认为false
     share: false,  // 分享默认为false
     height: 0,
     height: 0,
+    publicUrl: 'http://127.0.0.1:7004/',
+    imageUrl:'http://124.235.209.122:88',
   }
   }
   
   
 })
 })

+ 39 - 16
pages/home/index.js

@@ -30,14 +30,15 @@ Page({
       myActive:'/pages/images/people_fill.png'
       myActive:'/pages/images/people_fill.png'
     },
     },
     // 热门产品
     // 热门产品
-    productList: [{
-        "pic": '/pages/images/cooperation01.png',
-        title: '热门产品'
-      },
-      {
-        "pic": '/pages/images/cooperation01.png',
-        title: '热门产品'
-      }
+    productList: [
+      // {
+      //   "pic": '/pages/images/cooperation01.png',
+      //   title: '热门产品'
+      // },
+      // {
+      //   "pic": '/pages/images/cooperation01.png',
+      //   title: '热门产品'
+      // }
     ],
     ],
     // 政策解读
     // 政策解读
     policyList: [],
     policyList: [],
@@ -78,17 +79,19 @@ Page({
   // 热门产品跳转
   // 热门产品跳转
 
 
   productListDetail: function (e) {
   productListDetail: function (e) {
-    console.log(e.currentTarget.id)
+      console.log('productListDetail',e.currentTarget.id)
     wx.navigateTo({
     wx.navigateTo({
-      // url: '/pages/policyDetail/index?id=' + e.currentTarget.id // 希望跳转过去的页面
+        url: '/pages/productListDetail/index?id=' + e.currentTarget.id // 希望跳转过去的页面
     })
     })
   },
   },
   // 无id,模拟数据跳转
   // 无id,模拟数据跳转
-  productListDetail: function () {
-    wx.navigateTo({
-      // url: '/pages/policyDetail/index'
-    })
-  },
+  // productListDetail: function () {
+  //   wx.navigateTo({
+  //     // url: '/pages/policyDetail/index'
+  //   })
+  // },
+
+
   // 切换菜单
   // 切换菜单
   onChange(event) {
   onChange(event) {
     this.setData({
     this.setData({
@@ -116,6 +119,25 @@ Page({
       })
       })
     }
     }
   },
   },
+  topNews: function () {
+        wx.request({
+          method:"POST",
+          url: app.globalData.publicUrl + 'api/financial/financeclaims/top',
+          success:(e) => {
+            console.log('success',e);
+            if(e.data.errcode == 0){
+              let arr = [];
+              e.data.data.forEach((item) => {
+                // console.log('success',item.name.substring(0,5));
+                arr.push({_id:item._id,pic: app.globalData.imageUrl+item.innew.logo, title: item.name.substring(0,5)+'...'});
+              });
+              this.setData({
+                productList:arr
+              })
+            }
+          }
+        })
+      },
   loadPolicyList: function () {
   loadPolicyList: function () {
     request.query({
     request.query({
       url: 'api/financial/tPolicyInterpretation/select',
       url: 'api/financial/tPolicyInterpretation/select',
@@ -142,6 +164,7 @@ Page({
    * 生命周期函数--监听页面加载
    * 生命周期函数--监听页面加载
    */
    */
   onLoad: function (options) {
   onLoad: function (options) {
+    this.topNews();
     this.loadPolicyList();
     this.loadPolicyList();
 
 
   },
   },
@@ -150,7 +173,7 @@ Page({
    * 生命周期函数--监听页面初次渲染完成
    * 生命周期函数--监听页面初次渲染完成
    */
    */
   onReady: function () {
   onReady: function () {
-
+    console.log(JSON.stringify(wx.getStorageSync('user')))
   },
   },
 
 
   /**
   /**

+ 62 - 0
pages/login/index.js

@@ -13,10 +13,72 @@ Page({
       // 此页面 页面内容距最顶部的距离
       // 此页面 页面内容距最顶部的距离
       height: app.globalData.height * 2 + 20,
       height: app.globalData.height * 2 + 20,
     },
     },
+    user:{},
   },
   },
+//  findUser: function (e) {
+//     wx.request({
+//       method:"get",
+//       url: app.globalData.publicUrl + 'api/financial/companyuser',
+//       data:{
+//         phone: e.detail.value.phone
+//       },
+//       success:(e) => {
+//         if(e.data.errcode == 0){
+//           this.setData({
+//              user:e.data.data[0]
+//           })
+//         }
+//       }
+//     })
+//   },
   formSubmit: function (e) {
   formSubmit: function (e) {
     console.log('form发生了submit事件,携带数据为:', e.detail.value)
     console.log('form发生了submit事件,携带数据为:', e.detail.value)
+    let phone = e.detail.value.phone
+    let passwd = e.detail.value.password
+    wx.request({
+      method:"get",
+      url: app.globalData.publicUrl + 'api/financial/companyuser',
+      data:{
+        phone: e.detail.value.phone
+      },
+      success:(e) => {
+        if(e.data.errcode == 0){
+          this.setData({
+             user:e.data.data[0]
+          })
+          console.log('find---user',this.data.user);
+          wx.request({
+            method:"POST",
+            url: app.globalData.publicUrl + 'api/financial/companyuser/login',
+            data:{
+              phone:phone,
+              passwd:passwd
+            },
+            success:(e) => {
+              console.log('success',e);
+              if(e.data.errcode == 0){
+                wx.setStorage({
+                  key: 'user',
+                  data: this.data.user,
+                })
+                wx.navigateTo({
+                  url: '/pages/home/index'
+                })
+              } else {
+                wx.showToast({
+                  title: e.data.errmsg,
+                  icon: 'none',
+                  duration: 1500
+              })
+              }
+            }
+          })
+        }
+      }
+    })
   },
   },
+
+  
   // 忘记密码
   // 忘记密码
   unBtnPass: function () {
   unBtnPass: function () {
     wx.navigateTo({
     wx.navigateTo({

+ 12 - 1
pages/my/index.js

@@ -70,8 +70,19 @@ Page({
   // 退出登录
   // 退出登录
   onGoout: function () {
   onGoout: function () {
     console.log('退出登录')
     console.log('退出登录')
+    wx.removeStorage({
+      key: 'user',
+      success: function(res) {
+        console.log(res)
+        wx.showToast({
+          title: '退出成功',
+          icon: 'none',
+          duration: 1500
+      })
+      },
+    })
   },
   },
-
+  
   /**
   /**
    * 生命周期函数--监听页面加载
    * 生命周期函数--监听页面加载
    */
    */

+ 41 - 0
pages/register/index.js

@@ -17,7 +17,48 @@ Page({
   // 注册账号
   // 注册账号
   formSubmit: function (e) {
   formSubmit: function (e) {
     console.log('form发生了submit事件,携带数据为:', e.detail.value)
     console.log('form发生了submit事件,携带数据为:', e.detail.value)
+    wx.request({
+      method:"POST",
+      url: app.globalData.publicUrl + 'api/financial/companyuser',
+      data:{
+        phone: e.detail.value.phone,
+        passwd: e.detail.value.password,
+        company_name: e.detail.value.companyname
+      },
+      success:(e) => {
+        console.log('success',e);
+        if(e.data.errcode == 0){
+          wx.navigateTo({
+            url: '/pages/login/index'
+          })
+        } else {
+          if (e.data.details === "phone无效") {
+            wx.showToast({
+              title: '请重新输入手机号',
+              icon: 'none',
+              duration: 1500
+          })
+          
+          }
+          else if(e.data.errmsg === "数据已存在"){
+              wx.showToast({
+                title: '改手机号已被注册',
+                icon: 'none',
+                duration: 1500
+            })
+          }
+          else{
+              wx.showToast({
+                title: e.data.details?e.data.details:e.data.errmsg,
+                icon: 'none',
+                duration: 1500
+            })
+         }
+        }
+      }
+    })
   },
   },
+  
   /**
   /**
    * 生命周期函数--监听页面加载
    * 生命周期函数--监听页面加载
    */
    */

+ 7 - 4
pages/register/index.wxml

@@ -7,16 +7,19 @@
 		<view class="form">
 		<view class="form">
 			<form bindsubmit="formSubmit" bindreset="formReset">
 			<form bindsubmit="formSubmit" bindreset="formReset">
 				<view class='input-content'>
 				<view class='input-content'>
-					<view class='input-col'>
-						<input type='number' name="phone" placeholder='请输入您本人的手机号码' maxlength="11" placeholder-style="color:#888888;"></input>
+					<view class='input-col' style='border-bottom:none'>
+						<input type='text' name="companyname" placeholder='请输入企业名称' placeholder-style="color:#888888;"></input>
 					</view>
 					</view>
 					<view class='input-col'>
 					<view class='input-col'>
+						<input type='number' name="phone" placeholder='请输入您本人的手机号码' maxlength="11" placeholder-style="color:#888888;" ></input>
+					</view>
+					<!-- <view class='input-col'>
 						<input type='number' name="yanzhengma" placeholder='请输入验证码' placeholder-style="color:#888888;"></input>
 						<input type='number' name="yanzhengma" placeholder='请输入验证码' placeholder-style="color:#888888;"></input>
 						<view class="codeBtn"> 
 						<view class="codeBtn"> 
 						</view>
 						</view>
-					</view>
+					</view> -->
 					<view class='input-col' style='border-bottom:none'>
 					<view class='input-col' style='border-bottom:none'>
-						<input type='text' password name="password" placeholder='请输入8-20位字母数字组合的密码' placeholder-style="color:#888888;"></input>
+						<input type='text' password name="password" placeholder='请输入密码' placeholder-style="color:#888888;"></input>
 					</view>
 					</view>
 				</view>
 				</view>
 				<view class="save">
 				<view class="save">

+ 44 - 2
pages/updatePassword/index.js

@@ -15,7 +15,49 @@ Page({
     },
     },
   },
   },
   formSubmit: function (e) {
   formSubmit: function (e) {
-    console.log('form发生了submit事件,携带数据为:', e.detail.value)
+    console.log('form发生了submit事件,携带数据为:', e.detail.value);
+    // 获取当前登录用户信息
+    console.log(wx.getStorageSync('user'))
+    let user = wx.getStorageSync('user')
+    // console.log('user',user._id)
+   let password_new = e.detail.value.password_new
+   let password_again = e.detail.value.password_again
+    if (password_again != password_new) {
+      wx.showToast({
+        title: '密码不一致,请重新输入',
+        icon: 'none',
+        duration: 1500
+    })
+    }else{
+      wx.request({
+        method:"POST",
+        url: app.globalData.publicUrl + 'api/financial/companyuser/uppasswd',
+        data:{
+          uid: user._id,
+          newpasswd: e.detail.value.password_new,
+          oldpasswd: e.detail.value.password_old
+        },
+        success:(e) => {
+          console.log('success',e);
+          if(e.data.errcode == 0){
+            wx.showToast({
+              title: '密码修改成功',
+              icon: 'none',
+              duration: 1500
+          })
+            wx.navigateTo({
+              url: '/pages/home/index'
+            })
+          } else {
+            wx.showToast({
+              title: e.data.details?e.data.details:e.data.errmsg,
+              icon: 'none',
+              duration: 1500
+          })
+          }
+        }
+      })
+    }
   },
   },
 
 
   /**
   /**
@@ -29,7 +71,7 @@ Page({
    * 生命周期函数--监听页面初次渲染完成
    * 生命周期函数--监听页面初次渲染完成
    */
    */
   onReady: function () {
   onReady: function () {
-
+    // console.log(JSON.stringify(wx.getStorageSync('user')))
   },
   },
 
 
   /**
   /**

+ 4 - 4
pages/updatePassword/index.wxml

@@ -5,17 +5,17 @@
 			<form bindsubmit="formSubmit" bindreset="formReset">
 			<form bindsubmit="formSubmit" bindreset="formReset">
 				<view class='input-content'>
 				<view class='input-content'>
 					<view class='input-col' style='border-bottom:none'>
 					<view class='input-col' style='border-bottom:none'>
-						<input type='text' password name="password" placeholder='请输入您的密码' placeholder-style="color:#888888;"></input>
+						<input type='text' password name="password_old" placeholder='请输入您的密码' placeholder-style="color:#888888;"></input>
 					</view>
 					</view>
           		<view class='input-col' style='border-bottom:none'>
           		<view class='input-col' style='border-bottom:none'>
-						<input type='text' password name="password" placeholder='请输入新密码' placeholder-style="color:#888888;"></input>
+						<input type='text' password name="password_new" placeholder='请输入新密码' placeholder-style="color:#888888;"></input>
 					</view>
 					</view>
           		<view class='input-col' style='border-bottom:none'>
           		<view class='input-col' style='border-bottom:none'>
-						<input type='text' password name="password" placeholder='请再次输入密码' placeholder-style="color:#888888;"></input>
+						<input type='text' password name="password_again" placeholder='请再次输入密码' placeholder-style="color:#888888;"></input>
 					</view>
 					</view>
 				</view>
 				</view>
 				<view class="save">
 				<view class="save">
-					<button class='save-btn' form-type="submit">登录</button>
+					<button class='save-btn' form-type="submit">修改密码</button>
 				</view>
 				</view>
 			</form>
 			</form>
 		</view>
 		</view>