cbvirtua 1.0.28 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/locaiton.js +64 -0
  2. package/package.json +1 -1
package/locaiton.js ADDED
@@ -0,0 +1,64 @@
1
+ const getWxLocation = () => {
2
+ wx.showLoading({
3
+ title: '定位中000...',
4
+ mask: true,
5
+ })
6
+ return new Promise((resolve, reject) => {
7
+ let _locationChangeFn = (res) => {
8
+ console.log('location change', res)
9
+ resolve(res)
10
+ wx.hideLoading()
11
+ wx.offLocationChange(_locationChangeFn)
12
+ }
13
+ wx.startLocationUpdate({
14
+ // type: 'gcj02',
15
+ type: 'wgs84',
16
+ success: (res) => {
17
+ wx.onLocationChange(_locationChangeFn)
18
+ },
19
+ fail: (err) => {
20
+ console.log('获取当前位置失败', err)
21
+ wx.hideLoading()
22
+ reject()
23
+ }
24
+ })
25
+ })
26
+ }
27
+
28
+ const toSetting = () => {
29
+ return new Promise((resolve, reject) => {
30
+ wx.openSetting({
31
+ async success(res) {
32
+ console.log(res)
33
+ if (res.authSetting["scope.userLocation"]) {
34
+ // res.authSetting["scope.userLocation"]为trueb表示用户已同意获得定位信息,此时调用getlocation可以拿到信息
35
+ let locationRes = await getWxLocation()
36
+ resolve(locationRes)
37
+ }
38
+ },
39
+ fail(err) {
40
+ reject()
41
+ }
42
+ })
43
+ })
44
+ }
45
+
46
+ const authorization = async () => {
47
+ try{
48
+ return await getWxLocation();
49
+ }catch{
50
+ wx.showModal({
51
+ title: '温馨提示',
52
+ content: '获取权限失败,需要获取您的地理位置才能为您提供更好的服务!是否授权获取地理位置?',
53
+ success: function (res) {
54
+ if (res.confirm) {
55
+ toSetting()
56
+ } else {
57
+ console.log('用户点击取消')
58
+ }
59
+ }
60
+ })
61
+ }
62
+ }
63
+
64
+ module.exports = {getWxLocation, toSetting, authorization}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cbvirtua",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {