Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
user
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
hooloo
mp
user
Commits
8b4559e6
Commit
8b4559e6
authored
Jun 10, 2022
by
weijiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改首页获取位置逻辑
parent
aae89676
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
83 deletions
+106
-83
pages/menu/menu.vue
+76
-48
pages/mine/mine.vue
+2
-4
request/user/index.js
+28
-31
No files found.
pages/menu/menu.vue
View file @
8b4559e6
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<image
src=
"../../static/imgs/banner.png"
></image>
<image
src=
"../../static/imgs/banner.png"
></image>
<view
class=
"shop-info"
:style=
"'top:120rpx'"
>
<view
class=
"shop-info"
:style=
"'top:120rpx'"
>
<view
class=
"shop-box"
>
<view
class=
"shop-box"
>
<text
@
click=
"
openShow
"
class=
"shop-name"
>
{{
shopInfo
.
name
}}
</text>
<text
@
click=
"
showArea
"
class=
"shop-name"
>
{{
shopInfo
.
name
}}
</text>
<u-icon
name=
"arrow-right"
class=
"arrow-right-select"
color=
"#FFFFFF"
></u-icon>
<u-icon
name=
"arrow-right"
class=
"arrow-right-select"
color=
"#FFFFFF"
></u-icon>
</view>
</view>
<view
v-if=
"shopInfo.distance"
class=
"distance"
>
距您
{{
shopInfo
.
distance
}}
</view>
<view
v-if=
"shopInfo.distance"
class=
"distance"
>
距您
{{
shopInfo
.
distance
}}
</view>
...
@@ -82,14 +82,23 @@ export default {
...
@@ -82,14 +82,23 @@ export default {
},
},
},
},
created
()
{
created
()
{
this
.
getLocation
()
},
},
onLoad
:
async
function
()
{
onLoad
:
async
function
()
{
User
.
getAddress
()
uni
.
getSetting
({
$EventBus
.
$off
(
'getMenuList'
)
success
:
(
res
)
=>
{
$EventBus
.
$on
(
'getMenuList'
,
(
data
)
=>
{
// 已经授权位置不获取默认店铺
this
.
shopInfo
=
data
;
if
(
res
.
authSetting
[
'scope.userLocation'
]){
this
.
getMenuList
(
data
.
id
)
User
.
getLocation
((
state
,
params
)
=>
{
if
(
state
!=
1
)
{
return
;
}
this
.
getShopMenus
(
params
);
});
}
else
{
this
.
getShopMenus
();
this
.
authLocation
();
}
}
})
})
if
(
!
this
.
userms
){
if
(
!
this
.
userms
){
User
.
wxLoginAndGetOpenid
(
true
).
then
(
loginInfo
=>
{
User
.
wxLoginAndGetOpenid
(
true
).
then
(
loginInfo
=>
{
...
@@ -114,6 +123,14 @@ export default {
...
@@ -114,6 +123,14 @@ export default {
}
}
},
},
methods
:
{
methods
:
{
getShopMenus
(
params
)
{
$EventBus
.
$off
(
'getMenuList'
);
$EventBus
.
$on
(
'getMenuList'
,
(
data
)
=>
{
this
.
shopInfo
=
data
;
this
.
getMenuList
(
data
.
id
);
});
User
.
getShopInfo
(
params
);
},
openQrcode
()
{
openQrcode
()
{
// 不生成二维码
// 不生成二维码
if
([
'2'
,
'3'
].
indexOf
(
this
.
orderInfo
.
state
)
!=
-
1
){
if
([
'2'
,
'3'
].
indexOf
(
this
.
orderInfo
.
state
)
!=
-
1
){
...
@@ -131,26 +148,29 @@ export default {
...
@@ -131,26 +148,29 @@ export default {
}
}
})
})
},
},
openShow
()
{
showArea
()
{
const
postion
=
uni
.
getStorageSync
(
'location'
);
uni
.
getSetting
({
if
(
postion
)
{
success
:
(
res
)
=>
{
Order
.
getShop
(
postion
).
then
(
res
=>
{
// 已经授权位置不获取默认店铺
const
data
=
res
.
data
.
data
if
(
res
.
authSetting
[
'scope.userLocation'
])
{
const
two
=
data
[
0
].
children
User
.
getLocation
((
state
,
params
)
=>
{
const
three
=
two
[
0
].
children
console
.
log
(
"showArea, state:"
+
state
+
", params:"
+
JSON
.
stringify
(
params
));
this
.
columns
=
[[...
data
],
[...
two
],
[...
three
]]
this
.
showAreaDialog
(
params
);
this
.
show
=
true
});
})
}
else
{
return
console
.
log
(
"showArea no location"
);
}
this
.
showAreaDialog
();
this
.
getLocation
((
data
)
=>
{
}
Order
.
getShop
(
data
).
then
(
res
=>
{
}
const
data
=
res
.
data
.
data
})
const
two
=
data
[
0
].
children
},
const
three
=
two
[
0
].
children
showAreaDialog
(
params
)
{
this
.
columns
=
[[...
data
],
[...
two
],
[...
three
]]
Order
.
getShop
(
params
).
then
(
res
=>
{
this
.
show
=
true
const
data
=
res
.
data
.
data
;
})
const
two
=
data
[
0
].
children
;
const
three
=
two
[
0
].
children
;
this
.
columns
=
[[...
data
],
[...
two
],
[...
three
]];
this
.
show
=
true
;
})
})
},
},
changeHandler
()
{
},
changeHandler
()
{
},
...
@@ -172,29 +192,37 @@ export default {
...
@@ -172,29 +192,37 @@ export default {
}
}
},
},
// 获取定位授权
// 获取定位授权
get
Location
(
callback
)
{
auth
Location
(
callback
)
{
uni
.
getSetting
({
uni
.
getSetting
({
success
:
(
res
)
=>
{
success
:
(
res
)
=>
{
// console.log(res.authSetting['scope.userLocation']);
uni
.
authorize
({
if
(
!
res
.
authSetting
[
'scope.userLocation'
])
{
scope
:
'scope.userLocation'
,
uni
.
authorize
({
success
:
()
=>
{
//1.1 允许授权
scope
:
'scope.userLocation'
,
// console.log("允许授权位置");
success
:
()
=>
{
//1.1 允许授权
User
.
getLocation
((
state
,
params
)
=>
{
User
.
getLocation
(
data
=>
{
if
(
state
!=
1
){
callback
?
callback
(
data
)
:
User
.
getAddress
()
return
;
});
}
},
callback
?
callback
(
params
)
:
this
.
getShopMenus
(
params
);
fail
:
(
err
)
=>
{
//1.2 拒绝授权
});
wx
.
exitMiniProgram
({
success
:
(
res
)
=>
{
}
})
},
// console.log("获取位置失败")
fail
:
(
err
)
=>
{
//1.2 拒绝授权
uni
.
showToast
({
"title"
:
"获取位置失败,请打开位置授权"
,
icon
:
'error'
})
wx
.
exitMiniProgram
({
success
:
(
res
)
=>
{
}
})
}
// console.log("获取位置失败")
})
uni
.
showToast
({
"title"
:
"获取位置失败,请打开位置授权"
,
icon
:
'error'
})
}
else
{
}
User
.
getLocation
(
data
=>
{
})
callback
&&
callback
(
data
)
// if (res.authSetting['scope.userLocation']) {
});
// console.log("以前允许授权位置");
}
// User.getLocation((state, params) => {
// if(state != 1){
// return;
// }
// callback && callback(params);
// });
// } else {
// }
}
}
})
})
},
},
...
...
pages/mine/mine.vue
View file @
8b4559e6
...
@@ -20,8 +20,7 @@
...
@@ -20,8 +20,7 @@
<view
class=
"order1"
>
我的订单
</view>
<view
class=
"order1"
>
我的订单
</view>
<view
class=
"order2"
>
点击查看订单
</view>
<view
class=
"order2"
>
点击查看订单
</view>
<view>
<view>
<image
class=
"orderImg"
src=
"../../static/imgs/myOrder.png"
>
<image
class=
"orderImg"
src=
"../../static/imgs/myOrder.png"
></image>
</image>
</view>
</view>
</view>
</view>
<view
class=
"right_box"
>
<view
class=
"right_box"
>
...
@@ -51,8 +50,7 @@
...
@@ -51,8 +50,7 @@
<h3>
常用功能
</h3>
<h3>
常用功能
</h3>
<view
class=
"function_item"
>
<view
class=
"function_item"
>
<u-icon
name=
"server-fill"
color=
"#000000"
size=
"16"
></u-icon>
<u-icon
name=
"server-fill"
color=
"#000000"
size=
"16"
></u-icon>
<button
class=
"function_item_text"
open-type=
"contact"
bindcontact=
"handleContact"
<button
class=
"function_item_text"
open-type=
"contact"
bindcontact=
"handleContact"
session-from=
"sessionFrom"
>
联系客服
</button>
session-from=
"sessionFrom"
>
联系客服
</button>
<u-icon
name=
"arrow-right"
class=
"function_item_icon"
color=
"#000000"
size=
"12"
></u-icon>
<u-icon
name=
"arrow-right"
class=
"function_item_icon"
color=
"#000000"
size=
"12"
></u-icon>
</view>
</view>
</view>
</view>
...
...
request/user/index.js
View file @
8b4559e6
...
@@ -9,43 +9,40 @@ export default {
...
@@ -9,43 +9,40 @@ export default {
type
:
'gcj02'
,
//返回可以用于uni.openLocation的经纬度
type
:
'gcj02'
,
//返回可以用于uni.openLocation的经纬度
success
:
function
(
res
)
{
success
:
function
(
res
)
{
var
params
=
{
var
params
=
{
lat
:
res
.
latitude
,
lat
:
res
.
latitude
,
lng
:
res
.
longitude
,
lng
:
res
.
longitude
,
};
};
Store
.
commit
(
'saveLocation'
,
params
);
if
(
params
.
lat
&&
params
.
lng
)
{
uni
.
setStorage
({
key
:
'location'
,
data
:
params
});
Store
.
commit
(
'saveLocation'
,
params
);
callback
&&
callback
(
params
);
uni
.
setStorage
({
key
:
'location'
,
data
:
params
});
// return params;
}
else
{
params
=
uni
.
getStorageSync
(
'location'
);
}
callback
&&
callback
(
1
,
params
);
},
},
fail
:
function
(
res
)
{
fail
:
function
(
res
)
{
uni
.
showToast
({
const
params
=
uni
.
getStorageSync
(
'location'
);
title
:
'获取地址失败,将导致部分功能不可用'
,
callback
&&
callback
(
0
,
params
);
icon
:
'none'
,
});
},
},
});
});
},
},
// 获取默认店铺
// 获取店铺信息
getAddress
(
params
)
{
getShopInfo
(
params
)
{
return
uni
.
$u
.
http
return
uni
.
$u
.
http
.
get
(
'/weixin/getShop'
,
{
params
})
.
get
(
'/weixin/getShop'
,
{
.
then
((
res
)
=>
{
params
,
console
.
log
(
"get shop:"
+
JSON
.
stringify
(
res
.
data
.
data
));
})
if
(
res
.
data
.
code
==
200
)
{
.
then
((
res
)
=>
{
Store
.
commit
(
'saveShopInfo'
,
res
.
data
.
data
);
if
(
res
.
data
.
code
==
200
)
{
uni
.
setStorage
({
key
:
'shopData'
,
data
:
res
.
data
.
data
});
Store
.
commit
(
'saveShopInfo'
,
res
.
data
.
data
);
if
(
res
.
data
.
data
)
{
uni
.
setStorage
({
key
:
'shopData'
,
data
:
res
.
data
.
data
});
$EventBus
.
$emit
(
'getMenuList'
,
res
.
data
.
data
);
if
(
res
.
data
.
data
)
{
}
}
$EventBus
.
$emit
(
'getMenuList'
,
res
.
data
.
data
);
return
res
;
}
}).
catch
((
err
)
=>
{
}
console
.
log
(
"get shop error"
);
return
res
;
return
err
;
})
});
.
catch
((
err
)
=>
{
return
err
;
});
},
},
uniLogin
(
res
,
callback
)
{
uniLogin
(
res
,
callback
)
{
uni
.
login
({
uni
.
login
({
...
...
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