Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
Compass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zong
Compass
Commits
6341be4a
Commit
6341be4a
authored
Mar 14, 2020
by
shijiuyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
7de55db2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
133 additions
and
122 deletions
+133
-122
app.js
src/wx/app.js
+59
-41
index.js
src/wx/pages/index/index.js
+71
-76
register.js
src/wx/pages/register/register.js
+3
-5
No files found.
src/wx/app.js
View file @
6341be4a
...
...
@@ -2,21 +2,50 @@
App
({
url
:
'https://www.koala-online.cn/compass/if/'
,
onLaunch
:
function
()
{
var
that
=
this
;
//调用wx用户登陆
wx
.
login
({
success
:
res
=>
{
// 发送 res.code 到后台换取 openId, sessionKey, unionId
this
.
checkUser
(
res
.
code
,
null
);
wx
.
request
({
url
:
that
.
url
+
'ajax_check_user_registed.php'
,
data
:
{
code
:
res
.
code
},
success
(
resp
)
{
//保存返回的openId和unionId
console
.
log
(
resp
)
let
config
=
{
openId
:
resp
.
data
.
result
.
openId
,
unionId
:
resp
.
data
.
result
.
unionId
,
registed
:
resp
.
data
.
result
.
registed
};
// wx.showToast({
// title: "unionId=" + res.data.result.unionId,
// icon: 'success',
// duration: 2000
// });
wx
.
setStorageSync
(
"config"
,
config
);
},
fail
(
resp
)
{
wx
.
showToast
({
title
:
'resp'
,
icon
:
'success'
,
duration
:
2000
});
},
complete
(
resp
)
{
},
})
}
})
var
config
=
wx
.
getStorageSync
(
'config'
);
var
that
=
this
;
//获取并保存用户的经纬度信息
wx
.
getLocation
({
type
:
'wgs84'
,
success
:
function
(
res
)
{
let
location
=
{
let
location
=
{
latitude
:
res
.
latitude
,
longitude
:
res
.
longitude
};
...
...
@@ -26,48 +55,36 @@ App({
})
}
})
// 获取用户信息
wx
.
getSetting
({
success
:
res
=>
{
if
(
res
.
authSetting
[
'scope.userInfo'
])
{
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx
.
getUserInfo
({
success
:
res
=>
{
// 可以将 res 发送给后台解码出 unionId
this
.
globalData
.
userInfo
=
res
.
userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if
(
this
.
userInfoReadyCallback
)
{
this
.
userInfoReadyCallback
(
res
)
}
}
})
}
}
})
},
//判断用户是否已经注册
checkUser
:
function
(
code
,
openid
){
wx
.
request
({
url
:
this
.
url
+
'ajax_check_user_registed.php'
,
data
:
{
openId
:
openid
,
code
:
code
},
header
:
{
'content-type'
:
'application/json'
// 默认值
},
success
(
res
)
{
//保存返回的openId和unionId
let
config
=
{
openId
:
res
.
data
.
result
.
openId
,
unionId
:
res
.
data
.
result
.
unionId
,
registed
:
res
.
data
.
result
.
registed
};
wx
.
showToast
({
title
:
"unionId="
+
res
.
data
.
result
.
unionId
,
icon
:
'success'
,
duration
:
2000
});
wx
.
setStorage
({
key
:
'config'
,
data
:
config
,
});
},
fail
:
function
(
res
)
{
wx
.
showToast
({
title
:
"失败"
,
icon
:
'success'
,
duration
:
2000
});
},
complete
:
function
(
res
)
{
},
})
},
globalData
:
{
userInfo
:
null
userInfo
:
null
,
config
:
null
},
})
\ No newline at end of file
src/wx/pages/index/index.js
View file @
6341be4a
...
...
@@ -29,85 +29,80 @@ Page({
var
that
=
this
;
//获取用户当前的经纬度信息并调用接口判断用户身份
var
config
=
wx
.
getStorageSync
(
'config'
);
setTimeout
(
function
(){
wx
.
getStorage
({
key
:
'location'
,
success
:
function
(
resp
)
{
var
location
=
resp
.
data
;
var
latitude
=
resp
.
data
.
latitude
;
var
longitude
=
resp
.
data
.
longitude
;
wx
.
showToast
({
title
:
config
.
unionId
,
var
location
=
wx
.
getStorageSync
(
'location'
);
var
latitude
=
location
.
latitude
;
var
longitude
=
location
.
longitude
;
wx
.
showToast
({
title
:
location
,
})
wx
.
request
({
url
:
app
.
url
+
'ajax_get_user_role.php'
,
data
:
{
unionId
:
config
.
unionId
,
latitude
:
latitude
,
longitude
:
longitude
},
header
:
{
'content-type'
:
'application/json'
},
method
:
'GET'
,
dataType
:
'json'
,
success
:
function
(
res
)
{
console
.
log
(
res
)
if
(
res
.
statusCode
==
200
){
//保存用户当前的省市区县信息
location
.
province
=
res
.
data
.
result
.
province
location
.
city
=
res
.
data
.
result
.
city
location
.
district
=
res
.
data
.
result
.
district
wx
.
setStorage
({
key
:
'location'
,
data
:
location
,
})
//保存用户名称信息
config
.
name
=
res
.
data
.
result
.
name
wx
.
setStorage
({
key
:
'config'
,
data
:
config
,
})
wx
.
request
({
url
:
app
.
url
+
'ajax_get_user_role.php'
,
data
:
{
unionId
:
config
.
unionId
,
latitude
:
latitude
,
longitude
:
longitude
},
header
:
{
'content-type'
:
'application/json'
},
method
:
'GET'
,
dataType
:
'json'
,
success
:
function
(
res
)
{
console
.
log
(
res
)
if
(
res
.
statusCode
==
200
)
{
//保存用户当前的省市区县信息
location
.
province
=
res
.
data
.
result
.
province
location
.
city
=
res
.
data
.
result
.
city
location
.
district
=
res
.
data
.
result
.
district
wx
.
setStorage
({
key
:
'location'
,
data
:
location
,
})
//保存用户名称信息
config
.
name
=
res
.
data
.
result
.
name
wx
.
setStorage
({
key
:
'config'
,
data
:
config
,
})
//未注册用户的话。跳转到社会人士注册页面
if
(
res
.
data
.
status
==
"REGIST"
)
{
//页面跳转
wx
.
redirectTo
({
url
:
'../socialUserRegister/socialUserRegister'
,
});
}
that
.
setData
({
roleTitle
:
res
.
data
.
result
.
name
,
role
:
res
.
data
.
result
.
role
,
childAge
:
res
.
data
.
result
.
childAge
})
//菜单控制[亲子活动]
if
(
res
.
data
.
result
.
role
==
1
||
res
.
data
.
result
.
childAge
==
1
)
{
that
.
setData
({
showFamily
:
true
})
}
//菜单控制[社会实践]
if
(
res
.
data
.
result
.
role
==
2
||
res
.
data
.
result
.
childAge
==
2
)
{
that
.
setData
({
showSocial
:
true
})
}
//菜单控制[消息]
if
(
res
.
data
.
result
.
role
==
4
)
{
that
.
setData
({
showNews
:
false
})
}
that
.
getIndexData
();
}
},
fail
:
function
(
res
)
{
},
complete
:
function
(
res
)
{
},
//未注册用户的话。跳转到社会人士注册页面
if
(
res
.
data
.
status
==
"REGIST"
)
{
//页面跳转
wx
.
redirectTo
({
url
:
'../socialUserRegister/socialUserRegister'
,
});
}
that
.
setData
({
roleTitle
:
res
.
data
.
result
.
name
,
role
:
res
.
data
.
result
.
role
,
childAge
:
res
.
data
.
result
.
childAge
})
},
})
},
1000
);
//菜单控制[亲子活动]
if
(
res
.
data
.
result
.
role
==
1
||
res
.
data
.
result
.
childAge
==
1
)
{
that
.
setData
({
showFamily
:
true
})
}
//菜单控制[社会实践]
if
(
res
.
data
.
result
.
role
==
2
||
res
.
data
.
result
.
childAge
==
2
)
{
that
.
setData
({
showSocial
:
true
})
}
//菜单控制[消息]
if
(
res
.
data
.
result
.
role
==
4
)
{
that
.
setData
({
showNews
:
false
})
}
that
.
getIndexData
();
}
},
fail
:
function
(
res
)
{
wx
.
showToast
({
title
:
'数据获取异常'
,
})
},
complete
:
function
(
res
)
{
},
})
},
/**
...
...
src/wx/pages/register/register.js
View file @
6341be4a
...
...
@@ -55,7 +55,8 @@ Page({
//家校/家园用户注册
regist
(
e
){
//获取本地存储的openId和unionId
var
config
=
wx
.
getStorageSync
(
'config'
);
var
that
=
this
;
// 获取用户信息
wx
.
getUserInfo
({
...
...
@@ -67,10 +68,7 @@ Page({
if
(
this
.
userInfoReadyCallback
)
{
this
.
userInfoReadyCallback
(
res
)
}
//获取本地存储的openId和unionId
var
config
=
wx
.
getStorageSync
(
'config'
);
wx
.
request
({
url
:
app
.
url
+
'ajax_user_register.php'
,
data
:
{
...
...
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