Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
施宇
/
icsalesProgram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f4f243b0
authored
Jul 23, 2019
by
梁建民
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
登录
parent
4b0dd2ff
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
280 additions
and
135 deletions
app.js
app.json
pages/person/auth/index.js
pages/person/auth/index.wxml
pages/person/getphone/index.js
pages/person/login/index.js
pages/person/login/index.json
pages/person/login/index.wxml
utils/api.js
utils/util.js
app.js
View file @
f4f243b0
...
...
@@ -58,16 +58,34 @@ App({
},
onLaunch
()
{
let
me
=
this
;
// 查看是否授权
wx
.
getSetting
({
success
(
res
)
{
console
.
log
(
res
)
if
(
res
.
authSetting
[
'scope.userInfo'
])
{
// 已经授权
wx
.
switchTab
({
url
:
'/pages/tab/home/home'
})
}
}
})
wx
.
setStorage
({
key
:
"myUsername"
,
data
:
'18271408717'
});
this
.
conn
.
open
({
apiUrl
:
WebIM
.
config
.
apiURL
,
user
:
'18271408717'
,
pwd
:
'123456'
,
appKey
:
WebIM
.
config
.
appkey
});
WebIM
.
conn
.
listen
({
onOpened
(
message
)
{
...
...
app.json
View file @
f4f243b0
{
"pages"
:
[
"pages/person/login/index"
,
"pages/person/auth/index"
,
"pages/person/getphone/index"
,
"pages/person/login/index"
,
"pages/person/agreement/index"
,
"pages/person/successfully/index"
,
"pages/person/register/index"
,
...
...
pages/person/auth/index.js
View file @
f4f243b0
var
http
=
require
(
'../../../utils/util.js'
);
var
service
=
require
(
'../../../utils/api.js'
)
;
const
http
=
require
(
'../../../utils/util.js'
);
import
{
apis
}
from
'../../../utils/api.js'
;
Page
({
...
...
@@ -7,6 +7,7 @@ Page({
* 页面的初始数据
*/
data
:
{
canIUse
:
wx
.
canIUse
(
'button.open-type.getUserInfo'
),
userinfo
:
[]
},
...
...
@@ -15,16 +16,7 @@ Page({
*/
onLoad
:
function
(
options
)
{
// 查看是否授权
wx
.
getSetting
({
success
(
res
)
{
console
.
log
(
res
)
if
(
res
.
authSetting
[
'scope.userInfo'
])
{
// 已经授权
}
}
})
},
/**
...
...
@@ -81,42 +73,63 @@ Page({
bindGetUserInfo
(
e
)
{
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
)
if
(
e
.
detail
.
errMsg
==
'getUserInfo:ok'
){
wx
.
login
({
success
(
res
)
{
if
(
res
.
code
)
{
//存储用户资料
self
.
setData
({
userinfo
:
e
.
detail
.
userInfo
});
//获取openId
http
.
getData
(
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'
});
}
},
true
);
}
else
{
console
.
log
(
'登录失败!'
+
res
.
errMsg
);
}
},
fail
(
res
)
{
wx
.
showLoading
({
title
:
'网络不通,请重试'
})
}
}
})
})
}
else
{
//用户拒绝获取资料
wx
.
navigateTo
({
url
:
'/pages/person/login/index'
});
}
},
/**
* 暂不注册
...
...
pages/person/auth/index.wxml
View file @
f4f243b0
...
...
@@ -11,7 +11,8 @@
<!-- 授权 -->
<view class="auth">
<view>
<button class="btn-com btn-com-b" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">一键授权(微信用户资料)</button>
<button wx:if="{{canIUse}}" class="btn-com btn-com-b" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">一键授权</button>
<view wx:else>请升级微信版本</view>
<view class="btn-com btn-com-c" bindtap="toUrl">暂不注册,先看看</view>
</view>
<view class="text-wrap row">
...
...
pages/person/getphone/index.js
View file @
f4f243b0
var
http
=
require
(
'../../../utils/util.js'
);
var
service
=
require
(
'../../../utils/api.js'
)
;
const
http
=
require
(
'../../../utils/util.js'
);
import
{
apis
}
from
'../../../utils/api.js'
;
Page
({
...
...
@@ -69,21 +69,38 @@ Page({
* 一键获取手机号
*/
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
)
{
if
(
e
.
detail
.
errMsg
==
'getPhoneNumber:ok'
){
http
.
getData
(
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
)
{
//注入token
wx
.
setStorage
({
key
:
"token"
,
data
:
res
.
data
.
access_token
});
wx
.
switchTab
({
url
:
'/pages/tab/home/home'
});
}
},
true
);
}
else
{
//用户拒绝获取手机
wx
.
navigateTo
({
url
:
'/pages/person/login/index'
});
}
}
})
\ No newline at end of file
pages/person/login/index.js
View file @
f4f243b0
// pages/person/login/index.js
const
http
=
require
(
'../../../utils/util.js'
);
import
{
apis
}
from
'../../../utils/api.js'
;
Page
({
/**
* 页面的初始数据
*/
data
:
{
error
:
false
,
visible_pwd
:
false
,
passwordType
:
true
},
/**
...
...
@@ -20,17 +25,7 @@ Page({
*/
onReady
:
function
()
{
wx
.
login
({
success
(
res
)
{
console
.
log
(
res
)
if
(
res
.
code
)
{
//发起网络请求
}
else
{
console
.
log
(
'登录失败!'
+
res
.
errMsg
)
}
}
})
},
/**
...
...
@@ -74,9 +69,54 @@ Page({
onShareAppMessage
:
function
()
{
},
getPhoneNumber
(
e
)
{
console
.
log
(
e
.
detail
.
errMsg
)
console
.
log
(
e
.
detail
.
iv
)
console
.
log
(
e
.
detail
.
encryptedData
)
/**
* 登录
*/
formSubmit
:
function
(
e
)
{
http
.
postData
(
apis
.
authlogin
,
e
.
detail
.
value
,
function
(
res
){
if
(
res
.
err_code
===
0
){
//注入token
wx
.
setStorage
({
key
:
"access_token"
,
data
:
res
.
data
.
access_token
});
wx
.
switchTab
({
url
:
'/pages/tab/home/home'
})
}
else
{
wx
.
showToast
({
title
:
res
.
err_msg
,
icon
:
'none'
,
duration
:
2000
});
}
},
true
);
},
/**
* 密码是否可见
*/
toggleFn
:
function
(
e
){
if
(
this
.
data
[
'visible_pwd'
])
{
this
.
setData
({
visible_pwd
:
false
,
passwordType
:
true
});
}
else
{
this
.
setData
({
visible_pwd
:
true
,
passwordType
:
false
});
}
}
})
\ No newline at end of file
pages/person/login/index.json
View file @
f4f243b0
{
"usingComponents"
:
{}
"usingComponents"
:
{},
"navigationBarTitleText"
:
""
,
"navigationBarBackgroundColor"
:
"white"
,
"navigationBarTextStyle"
:
"black"
,
"backgroundColor"
:
"white"
}
\ No newline at end of file
pages/person/login/index.wxml
View file @
f4f243b0
<!-- 密码登录 -->
<view class="person">
<view class="column tit">
<text class="t1">Hi,上午好</text>
<text class="t1">欢迎使用IC业务助手!</text>
</view>
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">212</button>
<view class="inp-wrap row verCenter">
<text class="icon iconfont iconiconxiantiaoshouji21"></text>
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入手机号" placeholder-class="placeholderClass"></input>
<view class="areacode" bindtap="switchPrice">
<text class="tel-value">中国 + 86</text>
<text class="icon iconfont iconbianzu1"></text>
</view>
</view>
</view>
<view class="inp-wrap row verCenter">
<text class="icon iconfont iconiconxiantiaoshouji2"></text>
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入密码" placeholder-class="placeholderClass" class="pwd"></input>
<text class="icon iconfont iconiconxiantiaoshouji4 pwd-ico"></text>
</view>
</view>
<view class="error-wrap row bothSide verCenter">
<view class="error">
<text class="icon iconfont iconiconxiantiaoshouji1"></text>
<text class="txt">密码错误,请重新输入</text>
</view>
<navigator class="forget" url="pages/person/verifycode/index">忘记密码?</navigator>
</view>
<button class="login-button">登录</button>
<view class="bottom row bothSide">
<navigator class="txt" url="/pages/person/verifycode/index">验证码登录</navigator>
<navigator class="txt" url="/pages/person/verifycode/index">注册账户</navigator>
</view>
</view>
<view class="column tit">
<text class="t1">Hi,上午好</text>
<text class="t1">欢迎使用IC业务助手!</text>
</view>
<form bindsubmit="formSubmit">
<view class="inp-wrap row verCenter">
<text class="icon iconfont iconiconxiantiaoshouji21"></text>
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入手机号" placeholder-class="placeholderClass" name="mobile" type="number"></input>
<view class="areacode" bindtap="switchPrice">
<text class="tel-value">中国 + 86</text>
<text class="icon iconfont iconbianzu1"></text>
</view>
</view>
</view>
<view class="inp-wrap row verCenter">
<text class="icon iconfont iconiconxiantiaoshouji2"></text>
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入密码" placeholder-class="placeholderClass" class="pwd" name="password" password='{{passwordType}}'></input>
<block wx:if="{{visible_pwd}}">
<text class="icon iconfont iconiconxiantiaoshouji3 pwd-ico" bindtap="toggleFn"></text>
</block>
<block wx:else>
<text class="icon iconfont iconiconxiantiaoshouji4 pwd-ico" bindtap="toggleFn"></text>
</block>
</view>
</view>
<view class="error-wrap row bothSide verCenter">
<view class="error">
<block wx:if="{{error}}">
<text class="icon iconfont iconiconxiantiaoshouji1"></text>
<text class="txt">密码错误,请重新输入</text>
</block>
</view>
<navigator class="forget" url="pages/person/verifycode/index">忘记密码?</navigator>
</view>
<button class="login-button" form-type="submit">登录</button>
</form>
<view class="bottom row bothSide">
<navigator class="txt" url="/pages/person/verifycode/index">验证码登录</navigator>
<navigator class="txt" url="/pages/person/verifycode/index">注册账户</navigator>
</view>
</view>
\ No newline at end of file
utils/api.js
View file @
f4f243b0
...
...
@@ -5,7 +5,8 @@ const user_url = 'http://userapi.icsales.cc';
const
goods_url
=
'http://goodsapi.icsales.cc'
;
const
inquiry_url
=
'http://inquiryapi.icsales.cc'
;
const
index_url
=
'http://www.icsales.cc'
;
const
apis
=
{
const
apis
=
{
/**
* 授权接口
*/
...
...
@@ -173,6 +174,7 @@ const apis = {
userMarkmsg
:
user_url
+
'/user/markmsg'
}
module
.
exports
=
{
apis
:
apis
}
\ No newline at end of file
}
utils/util.js
View file @
f4f243b0
//数据请求(get)
const
getData
=
(
url
,
params
,
callBack
)
=>
{
wx
.
showNavigationBarLoading
();
//顶部显示loading效果
const
getData
=
(
url
,
params
,
callBack
,
loading
)
=>
{
wx
.
showNavigationBarLoading
();
if
(
loading
){
wx
.
showLoading
();
}
wx
.
request
({
url
:
url
,
data
:
params
,
...
...
@@ -8,38 +13,66 @@ const getData = (url, params, callBack) => {
"Content-Type"
:
"applciation/json"
},
success
:
(
res
)
=>
{
typeof
callBack
==
"function"
&&
callBack
(
res
.
data
,
""
);
wx
.
hideNavigationBarLoading
();
wx
.
hideLoading
();
},
fail
:
(
err
)
=>
{
typeof
callBack
==
"function"
&&
callBack
(
null
,
err
.
errMsg
);
console
.
log
(
err
)
console
.
log
(
err
);
wx
.
hideNavigationBarLoading
();
wx
.
hideLoading
();
}
})
};
//数据请求(post)
const
postData
=
(
url
,
data
,
callBack
)
=>
{
showLoading
(
"加载中"
,
true
)
var
Url
=
getApp
().
globalUrl
.
baseUrl
+
url
;
const
postData
=
(
url
,
params
,
callBack
,
loading
)
=>
{
wx
.
showNavigationBarLoading
();
if
(
loading
)
{
wx
.
showLoading
();
}
wx
.
request
({
url
:
U
rl
,
data
:
data
,
url
:
u
rl
,
data
:
params
,
header
:
{
"Content-Type"
:
"applciation/json"
},
method
:
"POST"
,
success
:
(
res
)
=>
{
wx
.
hideLoading
()
callBack
(
true
,
res
.
data
)
typeof
callBack
==
"function"
&&
callBack
(
res
.
data
,
""
);
wx
.
hideNavigationBarLoading
();
wx
.
hideLoading
();
},
fail
:
(
err
)
=>
{
wx
.
hideLoading
()
callBack
(
false
,
err
)
typeof
callBack
==
"function"
&&
callBack
(
null
,
err
.
errMsg
);
console
.
log
(
err
);
wx
.
hideNavigationBarLoading
();
wx
.
hideLoading
();
}
})
};
//上传文件
const
uploadFile
=
(
paths
,
callBack
)
=>
{
let
gUrl
=
getApp
().
globalUrl
;
...
...
@@ -84,6 +117,8 @@ const chooseImg = (num, callback) => {
}
})
};
module
.
exports
=
{
getData
:
getData
,
postData
:
postData
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment