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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
56 deletions
+79
-56
pages/menu/menu.vue
+64
-36
pages/mine/mine.vue
+2
-4
request/user/index.js
+13
-16
No files found.
pages/menu/menu.vue
View file @
8b4559e6
...
...
@@ -4,7 +4,7 @@
<image
src=
"../../static/imgs/banner.png"
></image>
<view
class=
"shop-info"
:style=
"'top:120rpx'"
>
<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>
</view>
<view
v-if=
"shopInfo.distance"
class=
"distance"
>
距您
{{
shopInfo
.
distance
}}
</view>
...
...
@@ -82,14 +82,23 @@ export default {
},
},
created
()
{
this
.
getLocation
()
},
onLoad
:
async
function
()
{
User
.
getAddress
()
$EventBus
.
$off
(
'getMenuList'
)
$EventBus
.
$on
(
'getMenuList'
,
(
data
)
=>
{
this
.
shopInfo
=
data
;
this
.
getMenuList
(
data
.
id
)
uni
.
getSetting
({
success
:
(
res
)
=>
{
// 已经授权位置不获取默认店铺
if
(
res
.
authSetting
[
'scope.userLocation'
]){
User
.
getLocation
((
state
,
params
)
=>
{
if
(
state
!=
1
)
{
return
;
}
this
.
getShopMenus
(
params
);
});
}
else
{
this
.
getShopMenus
();
this
.
authLocation
();
}
}
})
if
(
!
this
.
userms
){
User
.
wxLoginAndGetOpenid
(
true
).
then
(
loginInfo
=>
{
...
...
@@ -114,6 +123,14 @@ export default {
}
},
methods
:
{
getShopMenus
(
params
)
{
$EventBus
.
$off
(
'getMenuList'
);
$EventBus
.
$on
(
'getMenuList'
,
(
data
)
=>
{
this
.
shopInfo
=
data
;
this
.
getMenuList
(
data
.
id
);
});
User
.
getShopInfo
(
params
);
},
openQrcode
()
{
// 不生成二维码
if
([
'2'
,
'3'
].
indexOf
(
this
.
orderInfo
.
state
)
!=
-
1
){
...
...
@@ -131,26 +148,29 @@ export default {
}
})
},
openShow
()
{
const
postion
=
uni
.
getStorageSync
(
'location'
);
if
(
postion
)
{
Order
.
getShop
(
postion
).
then
(
res
=>
{
const
data
=
res
.
data
.
data
const
two
=
data
[
0
].
children
const
three
=
two
[
0
].
children
this
.
columns
=
[[...
data
],
[...
two
],
[...
three
]]
this
.
show
=
true
})
return
}
this
.
getLocation
((
data
)
=>
{
Order
.
getShop
(
data
).
then
(
res
=>
{
const
data
=
res
.
data
.
data
const
two
=
data
[
0
].
children
const
three
=
two
[
0
].
children
this
.
columns
=
[[...
data
],
[...
two
],
[...
three
]]
this
.
show
=
true
showArea
()
{
uni
.
getSetting
({
success
:
(
res
)
=>
{
// 已经授权位置不获取默认店铺
if
(
res
.
authSetting
[
'scope.userLocation'
])
{
User
.
getLocation
((
state
,
params
)
=>
{
console
.
log
(
"showArea, state:"
+
state
+
", params:"
+
JSON
.
stringify
(
params
));
this
.
showAreaDialog
(
params
);
});
}
else
{
console
.
log
(
"showArea no location"
);
this
.
showAreaDialog
();
}
}
})
},
showAreaDialog
(
params
)
{
Order
.
getShop
(
params
).
then
(
res
=>
{
const
data
=
res
.
data
.
data
;
const
two
=
data
[
0
].
children
;
const
three
=
two
[
0
].
children
;
this
.
columns
=
[[...
data
],
[...
two
],
[...
three
]];
this
.
show
=
true
;
})
},
changeHandler
()
{
},
...
...
@@ -172,16 +192,18 @@ export default {
}
},
// 获取定位授权
get
Location
(
callback
)
{
auth
Location
(
callback
)
{
uni
.
getSetting
({
success
:
(
res
)
=>
{
// console.log(res.authSetting['scope.userLocation']);
if
(
!
res
.
authSetting
[
'scope.userLocation'
])
{
uni
.
authorize
({
scope
:
'scope.userLocation'
,
success
:
()
=>
{
//1.1 允许授权
User
.
getLocation
(
data
=>
{
callback
?
callback
(
data
)
:
User
.
getAddress
()
// console.log("允许授权位置");
User
.
getLocation
((
state
,
params
)
=>
{
if
(
state
!=
1
){
return
;
}
callback
?
callback
(
params
)
:
this
.
getShopMenus
(
params
);
});
},
fail
:
(
err
)
=>
{
//1.2 拒绝授权
...
...
@@ -190,11 +212,17 @@ export default {
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 @@
<view
class=
"order1"
>
我的订单
</view>
<view
class=
"order2"
>
点击查看订单
</view>
<view>
<image
class=
"orderImg"
src=
"../../static/imgs/myOrder.png"
>
</image>
<image
class=
"orderImg"
src=
"../../static/imgs/myOrder.png"
></image>
</view>
</view>
<view
class=
"right_box"
>
...
...
@@ -51,8 +50,7 @@
<h3>
常用功能
</h3>
<view
class=
"function_item"
>
<u-icon
name=
"server-fill"
color=
"#000000"
size=
"16"
></u-icon>
<button
class=
"function_item_text"
open-type=
"contact"
bindcontact=
"handleContact"
session-from=
"sessionFrom"
>
联系客服
</button>
<button
class=
"function_item_text"
open-type=
"contact"
bindcontact=
"handleContact"
session-from=
"sessionFrom"
>
联系客服
</button>
<u-icon
name=
"arrow-right"
class=
"function_item_icon"
color=
"#000000"
size=
"12"
></u-icon>
</view>
</view>
...
...
request/user/index.js
View file @
8b4559e6
...
...
@@ -12,38 +12,35 @@ export default {
lat
:
res
.
latitude
,
lng
:
res
.
longitude
,
};
if
(
params
.
lat
&&
params
.
lng
)
{
Store
.
commit
(
'saveLocation'
,
params
);
uni
.
setStorage
({
key
:
'location'
,
data
:
params
});
callback
&&
callback
(
params
);
// return params;
}
else
{
params
=
uni
.
getStorageSync
(
'location'
);
}
callback
&&
callback
(
1
,
params
);
},
fail
:
function
(
res
)
{
uni
.
showToast
({
title
:
'获取地址失败,将导致部分功能不可用'
,
icon
:
'none'
,
});
const
params
=
uni
.
getStorageSync
(
'location'
);
callback
&&
callback
(
0
,
params
);
},
});
},
// 获取默认店铺
getAddress
(
params
)
{
return
uni
.
$u
.
http
.
get
(
'/weixin/getShop'
,
{
params
,
})
// 获取店铺信息
getShopInfo
(
params
)
{
return
uni
.
$u
.
http
.
get
(
'/weixin/getShop'
,
{
params
})
.
then
((
res
)
=>
{
console
.
log
(
"get shop:"
+
JSON
.
stringify
(
res
.
data
.
data
));
if
(
res
.
data
.
code
==
200
)
{
Store
.
commit
(
'saveShopInfo'
,
res
.
data
.
data
);
uni
.
setStorage
({
key
:
'shopData'
,
data
:
res
.
data
.
data
});
if
(
res
.
data
.
data
)
{
$EventBus
.
$emit
(
'getMenuList'
,
res
.
data
.
data
);
}
}
return
res
;
})
.
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
log
(
"get shop error"
);
return
err
;
});
},
...
...
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