Blame view

src/pages/like/index.vue 7.68 KB
ce4c83ff   wxy   初始提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
  <template>
  <div class="like">
  <!-- <div class='title'>2018年</div>
  <div class='eachmonth' v-for='(item, i) in months' :key='i'>
    <div class='month'>{{item}}</div>
    <div class='bar'>
      <div class='red' :style="like_percent[i]"></div>
      <div class='num'>{{like[i]}}</div>
      <div class='grey'></div>
    </div>
  </div> 
  <div class='total'>{{'总获赞数: '+total}}</div>-->
  <div class='Red' @tap='confirm(1)'>打卡</div>
  <div class='Blue' @tap='confirm(2)'>打卡</div>
  <div class='Green' @tap="confirm(3)">打卡</div>
  </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        months: [
          "1月",
          "2月",
          "3月",
          "4月",
          "5月",
          "6月",
          "7月",
          "8月",
          "9月",
          "10月",
          "11月",
          "12月"
        ],
        like: [],
        like_percent: [],
        total: -1,
        hasHandleAuth: false
      };
    },
    watch: {
      like(val) {
        let arr = [];
        let total = 0;
        val.forEach(function(item) {
          let style = "width:" + Math.round(item / 100).toFixed(0) + "%;";
          arr.push(style);
          total += item;
        });
        console.log(arr);
        this.like_percent = arr;
        this.total = total;
      }
    },
    methods: {
      load() {
        this.like = [
          1345,
          1058,
          2557,
          3058,
          4017,
          5550,
          8220,
          8575,
          7420,
          5402,
          4520,
          6327
        ];
      },
      confirm(sort=1){
        wx.showModal({
          title:'',
          content: '确定要定位吗?',
          success: res =>{
            if(res.confirm){
              if(sort==1){
                this.getLocation()
              }else if(sort==2){
                this.getLocation('wgs84')
              }else if(sort==3){
                this.getLocation1()
              }
            }
          }
        })
      },
      getLocation(type='gcj02') {
        wx.showLoading({ title: '正在定位' })
        let lat, lng
        wx.getLocation({
          type,
          success: res => {
            lat = res.latitude
            lng = res.longitude
            wx.request({
              url: 'https://api.map.baidu.com/geocoder/v2/',
              data: {
                ak: 'AnWpq9Kc3C8cq5CCGAzsq3NxpBkxRnl0',
                location: `${lat},${lng}`,
                coordtype: type + 'll',
                output: 'json'
              },
              success: res => {
                const formatted_address = res.data.result.formatted_address
                wx.hideLoading()
                wx.showModal({title: '定位成功',content:formatted_address,showCancel:false})
              }
            })
          },
          fail: err => {
            console.log(JSON.stringify(res))
            wx.hideLoading()
            let authSetting
            wx.getSetting({
              success: res => {
                authSetting = res.authSetting['scope.userLocation']
                console.log(authSetting)
              },
              complete: () => {
                if (authSetting) {
                  if (this.hasHandleAuth) {
                    this.getLocation(type)
                  } else{
                    this.service.UploadBug(this.rootUrl,'test/getLocation/',JSON.stringify(err))
                    wx.showModal({
                      title: '定位失败',
                      content: '微信未获得位置权限\n请在您手机的系统设置-权限管理中,打开微信的位置信息获取权限',
                      showCancel: false
                    })
                  }
                } else {
                  wx.showModal({
                    title: '授权请求',
                    content: '您已拒绝小程序获取地理位置,若要使用定位功能,请重新授权',
                    showCancel: false,
                    success: res => {
                      if (res.confirm) {
                        wx.openSetting({
                          success: res => {
                            if (res.authSetting['scope.userLocation']) {
                              this.hasHandleAuth = true
                              this.getLocation(type)
                            }
                          }
                        })
                      }
                    }
                  })
                }
              }
            })
          }
        })
      },
      getLocation1(type='gcj02') {
        wx.showLoading({ title: '正在定位' })
        let lat, lng
        wx.getLocation({
          type,
          success: res => {
            lat = res.latitude
            lng = res.longitude
            wx.request({
              url: 'https://api.map.baidu.com/geocoder/v2/',
              data: {
                ak: 'AnWpq9Kc3C8cq5CCGAzsq3NxpBkxRnl0',
                location: `${lat},${lng}`,
                coordtype: type + 'll',
                output: 'json'
              },
              success: res => {
                const formatted_address = res.data.result.formatted_address
                wx.hideLoading()
                wx.showModal({title: '定位成功',content:formatted_address,showCancel:false})
              }
            })
          },
          fail: res => {
            wx.hideLoading()
            let authSetting
            wx.getSetting({
              success: res => {
                authSetting = res.authSetting['scope.userLocation']
                console.log(authSetting)
              },
              complete: () => {
                if (authSetting) {
                  if (this.hasHandleAuth) {
                    this.getLocation1(type)
                  } else if(type=='gcj02'){
                    this.getLocation1('wgs84')
                  } else{
                    wx.showModal({
                      title: '定位失败',
                      content: '微信未获得位置权限\n请在您手机的系统设置-权限管理中,打开微信的位置信息获取权限',
                      showCancel: false
                    })
                  }
                } else {
                  wx.showModal({
                    title: '授权请求',
                    content: '您已拒绝小程序获取地理位置,若要使用定位功能,请重新授权',
                    showCancel: false,
                    success: res => {
                      if (res.confirm) {
                        wx.openSetting({
                          success: res => {
                            if (res.authSetting['scope.userLocation']) {
                              this.hasHandleAuth = true
                              this.getLocation1(type)
                            }
                          }
                        })
                      }
                    }
                  })
                }
              }
            })
          }
        })
      },
    },
    // onLoad() {
    //   this.load();
    //   let that = this;
    //   setTimeout(function() {
    //     that.$set(that.like, 6, 4444);
    //   }, 3000);
    // }
  };
  </script>
  <style lang="stylus" scoped>
  .like
    position fixed
    Height_Width(100%)
    top 0
    Background()
  .title
    Flex(flex, center, center)
    height 100rpx
    font 550 35rpx / 35rpx !specified
    color themeColor
  .eachmonth
    Flex(flex, , center)
    margin 0 40rpx 10rpx 40rpx
    .month
      flex none
      Font(26rpx, 35rpx)
      width 60rpx
    .bar
      display flex
      flex auto
      .red
        flex none
        height 35rpx
        background themeColor
      .num
        flex none
        padding-left 10rpx
        Font(24rpx, 35rpx)
        color themeColor
        background #EEE
      .grey
        flex auto
        height 35rpx
        background #EEE
  .total
    Font(26rpx, 45rpx)
    color grey
    text-align right
    padding-right 40rpx
  
  //以下是临时脚本
  
  .like
    Flex(flex, center, center, column)
    background black
    > div
      Height_Width(180rpx)
      Flex(flex, center, center)
      margin 40rpx 0
      border-radius 50%
      Font(40rpx, 40rpx, bold)
      color white
  
    .Red
      background red
    .Blue
      background blue
    .Green
      background green
  </style>