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
69c06183
Commit
69c06183
authored
Mar 08, 2020
by
biao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
794937f6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
141 additions
and
0 deletions
+141
-0
app.js
src/wx/app.js
+141
-0
No files found.
src/wx/app.js
0 → 100644
View file @
69c06183
//app.js
App
({
url
:
'https://www.koala-online.cn/compass/if/'
,
onLaunch
:
function
()
{
this
.
checkUser
();
var
config
=
wx
.
getStorageSync
(
'config'
);
var
that
=
this
;
wx
.
getLocation
({
type
:
'wgs84'
,
success
:
function
(
res
)
{
// console.log(res);
var
latitude
=
res
.
latitude
;
var
longitude
=
res
.
longitude
;
let
jingweidu
=
{
latitude
:
res
.
latitude
,
longitude
:
res
.
longitude
};
wx
.
setStorage
({
key
:
'jingweidu'
,
data
:
jingweidu
,
})
wx
:
wx
.
request
({
url
:
that
.
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
)
let
location
=
{
province
:
res
.
data
.
result
.
province
,
city
:
res
.
data
.
result
.
city
,
district
:
res
.
data
.
result
.
district
}
wx
.
setStorage
({
key
:
'location'
,
data
:
location
,
})
},
fail
:
function
(
res
)
{
},
complete
:
function
(
res
)
{
},
})
}
})
// 展示本地存储能力
var
logs
=
wx
.
getStorageSync
(
'logs'
)
||
[]
logs
.
unshift
(
Date
.
now
())
wx
.
setStorageSync
(
'logs'
,
logs
)
// var config = wx.getStorageSync('config');
// if(!config){
// wx.login({
// success: res => {
// // 发送 res.code 到后台换取 openId, sessionKey, unionId
// this.checkUser(res.code, null);
// console.log(res,11)
// }
// })
// }else{
// this.checkUser(null, res.openId);
// console.log(res.openId,22)
// }
// wx.getStorage({
// key: 'config',
// success: function(res) {
// console.log('res')
// if(!res){
// wx.login({
// success: res => {
// // 发送 res.code 到后台换取 openId, sessionKey, unionId
// this.checkUser(res.code,null);
// }
// })
// }else{
// this.checkUser(null,res.openId);
// }
// },
// })
// 登录
// 获取用户信息
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
)
{
console
.
log
(
res
,
'成功调用checkUser方法'
)
// if(res.data.result.message=="未注册")
if
(
res
.
data
.
status
==
'OK'
){
wx
.
showModal
({
title
:
'提示'
,
content
:
'成功调用checkUser方法'
,
})
let
config
=
{
openId
:
res
.
result
.
openId
,
unionId
:
res
.
result
.
unionId
,
zhuce
:
res
.
data
.
result
.
message
};
wx
.
setStorage
({
key
:
'config'
,
data
:
config
,
})
}
}
})
},
globalData
:
{
userInfo
:
null
},
})
\ No newline at end of file
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