Commit 4b0dd2ff by 梁建民

js

parent 0e6e9130
......@@ -57,7 +57,6 @@ App({
}
},
onLaunch() {
console.log('初始化');
let me = this;
wx.setStorage({
key: "myUsername",
......
{
"pages": [
"pages/person/auth/index",
"pages/person/getphone/index",
"pages/person/login/index",
"pages/person/agreement/index",
"pages/person/successfully/index",
......
// pages/login/index.js
var http = require('../../../utils/util.js');
var service = require('../../../utils/api.js');
Page({
/**
* 页面的初始数据
*/
data: {
userinfo: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.switchTab({
url: '/pages/tab/home/home'
})
onLoad: function(options) {
// 查看是否授权
wx.getSetting({
success(res) {
console.log(res)
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({
withCredentials:true,
success: function (res) {
console.log(res.userInfo)
}
})
// 已经授权
}
}
})
......@@ -37,52 +30,100 @@ Page({
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
onShareAppMessage: function() {
},
/**
* 授权用户信息
*/
bindGetUserInfo(e) {
console.log(e.detail.userInfo)
let self = this;
this.setData({
userinfo: e.detail.userInfo
});
wx.login({
success(res) {
wx.showLoading();
if (res.code) {
//发起网络请求
http.getData(service.apis.getOpenId, {
code: res.code,
'userinfo[avatarUrl]': self.data.userinfo.avatarUrl,
'userinfo[nickName]': self.data.userinfo.nickName
}, function(res) {
if (res.err_code === 0) {
wx.setStorage({
key: "openid",
data: res.data.openid
});
wx.setStorage({
key: "session_key",
data: res.data.session_key
});
//授权成功跳转一键获取手机号
wx.navigateTo({
url: '/pages/person/getphone/index'
})
}
});
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
/**
* 暂不注册
*/
toUrl: function() {
wx.switchTab({
url: '/pages/tab/home/home'
})
}
})
\ No newline at end of file
......@@ -2,8 +2,8 @@
"usingComponents": {
},
"navigationBarTitleText": "IC登录",
"navigationBarBackgroundColor": "#0D84D1",
"navigationBarTextStyle": "white",
"backgroundColor": "#0d84d1"
"navigationBarTitleText": "",
"navigationBarBackgroundColor": "white",
"navigationBarTextStyle": "black",
"backgroundColor": "white"
}
\ No newline at end of file
......@@ -9,14 +9,14 @@
</view>
<!-- 授权 -->
<view class="auth">
<view class="auth">
<view>
<button class="btn-com btn-com-b" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">一键授权(微信用户资料)</button>
<view class="btn-com btn-com-c">暂不注册,先看看</view>
<view class="btn-com btn-com-c" bindtap="toUrl">暂不注册,先看看</view>
</view>
<view class="text-wrap row">
<view class="btn-text mr">验证码登录</view>
<view class="btn-text">密码登录</view>
<navigator url="/pages/person/verifycode/index" class="btn-text mr">验证码登录</navigator>
<navigator url="/pages/person/login/index" class="btn-text">密码登录</navigator>
</view>
</view>
......
var http = require('../../../utils/util.js');
var service = require('../../../utils/api.js');
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
},
/**
* 一键获取手机号
*/
getPhoneNumber(e) {
http.getData(service.apis.getwxUserInfo, {
openid: wx.getStorageSync('openid'),
session_key: wx.getStorageSync('session_key'),
encryptedData: e.detail.encryptedData,
iv: e.detail.iv
}, function(res) {
if (res.err_code === 0) {
}
});
}
})
\ No newline at end of file
{
"usingComponents": {},
"navigationBarTitleText": "",
"navigationBarBackgroundColor": "white",
"navigationBarTextStyle": "black",
"backgroundColor": "white"
}
\ No newline at end of file
<view class='person'>
<view class='head column verCenter'>
<view class="head-logo column">
<view class='logo'>
<cover-image src="/res/images/imgs/iclogo.png" class="img"></cover-image>
</view>
<text class="t1">IC业务助手</text>
<text class='t2'>让询报价更轻松、便捷</text>
</view>
<!-- 授权 -->
<view class="auth">
<view>
<button class="btn-com btn-com-b" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">一键获取手机号</button>
</view>
<view class="text-wrap row">
<navigator url="/pages/person/verifycode/index" class="btn-text mr">验证码登录</navigator>
<navigator url="/pages/person/login/index" class="btn-text">密码登录</navigator>
</view>
</view>
</view>
</view>
\ No newline at end of file
/* pages/login/index.wxss */
.person {
padding: 108rpx 0 0 0;
}
.person .logo .img {
width: 225rpx;
height: 201rpx;
}
.person .t1 {
margin-top: 50rpx;
margin-bottom: 10rpx;
font-size: 46rpx;
color: #3f3a3a;
font-weight: 600;
}
.person .t2 {
font-size: 26rpx;
color: #9f9fa0;
}
.person .btn-com {
display: block;
}
.person .auth {
width: 100%;
}
.person .auth .btn-com-b {
margin-top: 80rpx;
}
.person .auth .btn-com-c {
border: 2rpx solid rgba(216, 223, 230, 1);
font-size: 32rpx;
color: #adb6bf;
background: none;
margin-top: 40rpx;
}
.text-wrap {
text-align: center;
align-content: center;
justify-content: center;
padding-top: 260rpx;
}
.btn-text {
color: #8a9299;
font-size: 25rpx;
}
.text-wrap .mr {
margin-right: 60rpx;
}
......@@ -7,8 +7,16 @@ const inquiry_url = 'http://inquiryapi.icsales.cc';
const index_url = 'http://www.icsales.cc';
const apis = {
/**
* 用户注册
*/
* 授权接口
*/
getOpenId: auth_url + '/v1/getOpenId',
/**
* 获取微信用户信息
*/
getwxUserInfo: auth_url + '/v1/getwxUserInfo',
/**
* 用户注册
*/
authRegister: auth_url + '/auth/register',
/**
* 账号密码登录
......@@ -79,8 +87,8 @@ const apis = {
*/
goodsSave: goods_url + '/goods/save',
/***
* 商品上下架
*/
* 商品上下架
*/
goodsStatus: goods_url + "/goods/status",
/****
* 询价搜索 不需要token
......@@ -164,4 +172,7 @@ const apis = {
*/
userMarkmsg: user_url + '/user/markmsg'
}
export default apis
\ No newline at end of file
module.exports = {
apis: apis
}
\ No newline at end of file
//数据请求(get)
const getData = (url, callBack) => {
const getData = (url, params, callBack) => {
wx.showNavigationBarLoading(); //顶部显示loading效果
wx.request({
url: getApp().globalUrl.baseUrl + url,
url: url,
data: params,
header: {
"Content-Type": "applciation/json"
},
success: (res) => {
callBack(true, res.data)
typeof callBack == "function" && callBack(res.data, "");
wx.hideNavigationBarLoading();
},
fail: (err) => {
callBack(false, err)
typeof callBack == "function" && callBack(null, err.errMsg);
console.log(err)
wx.hideNavigationBarLoading();
}
})
};
......@@ -48,7 +52,10 @@ const uploadFile = (paths, callBack) => {
success: (res) => {
var data = JSON.parse(res.data);
if (data.suc == 'y') {
callBack({ imgSrc: data.data.file.url, image_id: data.data.file.image_id })
callBack({
imgSrc: data.data.file.url,
image_id: data.data.file.image_id
})
} else {
showModal(data.msg);
}
......@@ -81,4 +88,4 @@ module.exports = {
getData: getData,
postData: postData,
chooseImg: chooseImg
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment