Yansen 2 年前
父节点
当前提交
fcbc64e923

+ 1
- 0
config/index.js 查看文件

@@ -23,6 +23,7 @@ const config = {
23 23
   alias: {
24 24
     '@/layout': path.resolve(__dirname, '..', 'src/layout'),
25 25
     '@/components': path.resolve(__dirname, '..', 'src/components'),
26
+    '@/native': path.resolve(__dirname, '..', 'src/native'),
26 27
     '@/assets': path.resolve(__dirname, '..', 'src/assets'),
27 28
     '@/service': path.resolve(__dirname, '..', 'src/service'),
28 29
     '@/utils': path.resolve(__dirname, '..', 'src/utils'),

+ 1
- 0
src/app.config.js 查看文件

@@ -1,6 +1,7 @@
1 1
 export default defineAppConfig({
2 2
   pages: [
3 3
     'pages/index/index',
4
+    'pages/avatar/index',
4 5
     'pages/rank/index'
5 6
   ],
6 7
   window: {

二进制
src/assets/images/circle.png 查看文件


二进制
src/assets/images/star.png 查看文件


src/pages/index/components/avatar-change.vue → src/pages/avatar/components/avatar-change.vue 查看文件

@@ -25,7 +25,7 @@ import { useModel } from '@zjxpcyc/vue-tiny-store';
25 25
 import defaultAvatar from '@/assets/images/avatar.png';
26 26
 import { updatePerson } from '@/service/person';
27 27
 import avatarSlider from './avatar-slider.vue';
28
-import useCanvas from '../useCanvas';
28
+import useCanvas from '../../avatar/useCanvas';
29 29
 
30 30
 export default {
31 31
   components: {

src/pages/index/components/avatar-slider.vue → src/pages/avatar/components/avatar-slider.vue 查看文件


src/pages/index/components/banner.vue → src/pages/avatar/components/banner.vue 查看文件


+ 4
- 0
src/pages/avatar/index.config.js 查看文件

@@ -0,0 +1,4 @@
1
+export default definePageConfig({
2
+  navigationBarTitleText: '换头像,为祖国母亲庆生',
3
+  enableShareAppMessage: true
4
+})

+ 42
- 0
src/pages/avatar/index.vue 查看文件

@@ -0,0 +1,42 @@
1
+<template>
2
+  <a-layout>
3
+    <view class="v-flex container avatar-contariner">
4
+      <banner class="flex-0" />
5
+      <avatar-change class="flex-1" />
6
+    </view>
7
+  </a-layout>
8
+</template>
9
+
10
+<script>
11
+import { ref } from 'vue';
12
+import Taro, { useReady } from '@tarojs/taro';
13
+import { useModel } from '@zjxpcyc/vue-tiny-store';
14
+import { onShareAppMessage, onShareTimeline } from '@/utils/share'
15
+import banner from './components/banner.vue';
16
+import avatarChange from './components/avatar-change.vue';
17
+
18
+export default {
19
+  components: {
20
+    'avatar-change': avatarChange,
21
+    banner,
22
+  },
23
+  onShareAppMessage,
24
+  onShareTimeline,
25
+  setup () {
26
+    const { user } = useModel('user');
27
+
28
+    return {
29
+      user,
30
+    }
31
+  },
32
+}
33
+</script>
34
+
35
+<style lang="less">
36
+  .avatar-contariner {
37
+    background-repeat: no-repeat;
38
+    background-image: url(http://yz-h5.oss-cn-shanghai.aliyuncs.com/assets/guoqing-miniapp/back.jpg);
39
+    background-position: center bottom;
40
+    background-size: 100% auto;
41
+  }
42
+</style>

src/pages/index/useCanvas.js → src/pages/avatar/useCanvas.js 查看文件


+ 3
- 3
src/pages/index/index.config.js 查看文件

@@ -1,4 +1,4 @@
1 1
 export default definePageConfig({
2
-  navigationBarTitleText: '庆国庆,换头像',
3
-  enableShareAppMessage: true
4
-})
2
+  navigationBarTitleText: '换头像,为祖国母亲庆生',
3
+  enableShareAppMessage: true,
4
+})

+ 143
- 41
src/pages/index/index.vue 查看文件

@@ -1,52 +1,154 @@
1 1
 <template>
2
-  <a-layout>
3
-    <view class="v-flex container index-contariner">
4
-      <banner class="flex-0" />
5
-      <avatar-change class="flex-1" />
2
+  <view class="page index-page">
3
+    <map
4
+      class="index-map"
5
+      longitude="104.142597"
6
+      latitude="35.068215"
7
+      scale="3"
8
+      subkey="E4UBZ-2H265-WEMI5-QUMH5-VCCVZ-XPBHO"
9
+      layer-style="1"
10
+      :enable-zoom="false"
11
+      :enable-scroll="false"
12
+      :enable-poi="false"
13
+    ></map>
14
+
15
+    <view class="index-ad">
16
+      <banner-ad></banner-ad>
17
+    </view>
18
+
19
+    <view class="index-head">
20
+      <view class="index-title">全国庆生接力图</view>
21
+      <view class="index-tab flex">
22
+        <view class="index-tab-item flex-0" @tap="toNav('/pages/avatar/index')">换头像</view>
23
+        <view class="index-tab-item flex-0" @tap="toNav('/pages/rank/index')">排行榜</view>
24
+      </view>
6 25
     </view>
7
-  </a-layout>
26
+  </view>
8 27
 </template>
9 28
 
10 29
 <script>
11
-import { ref } from 'vue';
12
-import Taro, { useReady } from '@tarojs/taro';
13
-import { useModel } from '@zjxpcyc/vue-tiny-store';
14
-import banner from './components/banner.vue';
15
-import avatarChange from './components/avatar-change.vue';
16
-
17
-export default {
18
-  components: {
19
-    'avatar-change': avatarChange,
20
-    banner,
21
-  },
22
-  onShareAppMessage() {
23
-    return {
24
-      title: '庆国庆, 邀请好友一起换头像吧~',
25
-      path: `/pages/index/index?recommender=${this.user.personId}`,
26
-      imageUrl: 'https://yz-h5.oss-cn-shanghai.aliyuncs.com/assets/guoqing-miniapp/avatar_share.jpg',
27
-    }
28
-  },
29
-  onShareTimeline() {
30
-    return {
31
-      title: '庆国庆, 邀请好友一起换头像吧~',
32
-      query: `recommender=${this.user.personId}`
33
-    }
34
-  },
35
-  setup () {
36
-    const { user } = useModel('user');
30
+  import { ref } from 'vue';
31
+  import Taro, { useReady } from '@tarojs/taro';
32
+  import { useModel } from '@zjxpcyc/vue-tiny-store';
33
+  import { onShareAppMessage, onShareTimeline } from '@/utils/share';
34
+  import circleImg from '@/assets/images/star.png';
35
+
36
+  export default {
37
+    onShareAppMessage,
38
+    onShareTimeline,
39
+
40
+    setup () {
41
+      let markerAdded = false;
42
+      let drawing = false;
43
+      const mapCtx = ref();
44
+      const { list, getList } = useModel('rank');
37 45
 
38
-    return {
39
-      user,
46
+      const addMarkers = () => {
47
+        if (!list.value.length) return;
48
+        if (!mapCtx.value) return;
49
+        if (markerAdded) return;
50
+        if (drawing) return;
51
+
52
+        drawing = true;
53
+        const markers = list.value.map((it, inx) => ({
54
+          id: inx + 1,
55
+          longitude: it.location[0],
56
+          latitude: it.location[1],
57
+          iconPath: circleImg,
58
+          width: 12,
59
+          height: 12,
60
+          label: {
61
+            content: it.shorName,
62
+          }
63
+        }));
64
+
65
+        mapCtx.value.addMarkers({
66
+          markers,
67
+          clear: true,
68
+          success: () => {
69
+            markerAdded = true;
70
+          },
71
+          fail: (err) => {
72
+            console.error(err);
73
+          },
74
+          complete: () => {
75
+            drawing = false;
76
+          }
77
+        })
78
+      }
79
+
80
+      useReady(() => {
81
+        if (!list.value.length) {
82
+          getList().then(() => {
83
+            addMarkers();
84
+          });
85
+        }
86
+        
87
+        wx.createSelectorQuery().select('.index-map').context(res => {
88
+          mapCtx.value = res.context;
89
+          addMarkers();
90
+        }).exec()
91
+      });
92
+
93
+      const toNav = (url) => {
94
+        Taro.navigateTo({ url })
95
+      };
96
+
97
+      return {
98
+        toNav,
99
+      }
40 100
     }
41
-  },
42
-}
101
+    
102
+  }
103
+
43 104
 </script>
44 105
 
106
+
45 107
 <style lang="less">
46
-  .index-contariner {
47
-    background-repeat: no-repeat;
48
-    background-image: url(http://yz-h5.oss-cn-shanghai.aliyuncs.com/assets/guoqing-miniapp/back.jpg);
49
-    background-position: center bottom;
50
-    background-size: 100% auto;
108
+.index-page {
109
+  position: relative;
110
+
111
+  map {
112
+    width: 100%;
113
+    height: 100%;
51 114
   }
52
-</style>
115
+
116
+  .index-head {
117
+    position: absolute;
118
+    width: 100vw;
119
+    top: 0;
120
+    left: 0;
121
+    z-index: 10;
122
+
123
+    .index-title {
124
+      text-align: center;
125
+      margin-top: 50rpx;
126
+      font-size: 1.4em;
127
+    }
128
+
129
+    .index-tab {
130
+      width: 80vw;
131
+      margin: auto;
132
+      margin-top: 50rpx;
133
+      justify-content: space-around;
134
+
135
+      .index-tab-item {
136
+        text-align: center;
137
+        width: 200rpx;
138
+        border: 2px solid #fffd00;
139
+        box-sizing: border-box;
140
+        border-radius: 16rpx;
141
+        line-height: 2em;
142
+        color: #fffd00;
143
+      }
144
+    }
145
+  }
146
+
147
+  .index-ad {
148
+    position: absolute;
149
+    bottom: 0;
150
+    left: 0;
151
+    width: 100vw;
152
+  }
153
+}
154
+</style>

+ 1
- 1
src/pages/rank/components/list.vue 查看文件

@@ -47,7 +47,7 @@
47 47
         loading.value = true;
48 48
 
49 49
         const pageNum = pg ? pg : pageNumber.value + 1;
50
-        getRank({ pageNum, pageSize: 10, type: props.stType }).then(res => {
50
+        getRank({ pageNum, pageSize: 20, type: props.stType }).then(res => {
51 51
           const { records, current, pages } = res;
52 52
           list.value = list.value.concat(records || []);
53 53
           pageNumber.value = current;

+ 1
- 1
src/pages/rank/index.config.js 查看文件

@@ -1,5 +1,5 @@
1 1
 export default definePageConfig({
2
-  navigationBarTitleText: '庆国庆,换头像',
2
+  navigationBarTitleText: '换头像,为祖国母亲庆生',
3 3
   enableShareAppMessage: true,
4 4
   // disableScroll: true,
5 5
 })

+ 2
- 7
src/pages/rank/index.vue 查看文件

@@ -26,6 +26,7 @@ import Taro, { useReady } from '@tarojs/taro';
26 26
 import { useModel } from '@zjxpcyc/vue-tiny-store';
27 27
 import BannerBox from '@/components/banner/index.vue'
28 28
 import { getMyRank } from '@/service/rank';
29
+import { onShareAppMessage } from '@/utils/share'
29 30
 import ListVue from './components/list.vue';
30 31
 
31 32
 export default {
@@ -33,13 +34,7 @@ export default {
33 34
     // 'banner-box': BannerBox,
34 35
     'rank-list': ListVue,
35 36
   },
36
-  onShareAppMessage() {
37
-    return {
38
-      title: '庆国庆, 邀请好友一起换头像吧~',
39
-      path: `/pages/index/index?recommender=${this.user.personId}`,
40
-      imageUrl: 'https://yz-h5.oss-cn-shanghai.aliyuncs.com/assets/guoqing-miniapp/avatar_share.jpg',
41
-    }
42
-  },
37
+  onShareAppMessage,
43 38
   setup () {
44 39
     const { user } = useModel('user');
45 40
     const current = ref(0);

+ 20
- 2
src/store/index.js 查看文件

@@ -1,5 +1,7 @@
1 1
 import createStore from '@zjxpcyc/vue-tiny-store';
2
-import { ref } from 'vue'
2
+import { ref } from 'vue';
3
+import { getRank } from '@/service/rank';
4
+import { transform } from '@/utils/coordinate';
3 5
 
4 6
 function useUser() {
5 7
   const user = ref()
@@ -12,5 +14,21 @@ function useUser() {
12 14
   }
13 15
 }
14 16
 
15
-const store = createStore({ user: useUser })
17
+function useRank() {
18
+  const list = ref([])
19
+
20
+  const getList = () => {
21
+    return getRank({ pageNum: 1, pageSize: 500, type: 'area' }).then(res => {
22
+      const { records = [] } = res;
23
+      list.value = records.map(x => ({ ...x, location: transform(x.location) }));
24
+    })
25
+  }
26
+
27
+  return {
28
+    list,
29
+    getList,
30
+  }
31
+}
32
+
33
+const store = createStore({ user: useUser, rank: useRank })
16 34
 export default store

+ 54
- 0
src/utils/coordinate.js 查看文件

@@ -0,0 +1,54 @@
1
+
2
+/**  
3
+ * 单点坐标纠偏
4
+ */
5
+const pi = 3.14159265358979324;
6
+const a = 6378245.0;
7
+const ee = 0.00669342162296594323;
8
+const x_pi = 3.14159265358979324 * 3000.0 / 180.0;
9
+
10
+function outOfChina(lat, lon) {
11
+  if(lon < 72.004 || lon > 137.8347)
12
+      return true;
13
+  if(lat < 0.8293 || lat > 55.8271)
14
+      return true;
15
+  return false;
16
+};
17
+
18
+function transformLat(x, y) {
19
+  let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
20
+  ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
21
+  ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
22
+  ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
23
+  return ret;
24
+};
25
+
26
+function transformLon(x, y) {
27
+  let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
28
+  ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
29
+  ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
30
+  ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;
31
+  return ret;
32
+};
33
+
34
+// wgs84 转 gcj02
35
+export function transform (location) {
36
+  const [wgLon, wgLat] = location.split(',').map(x => x - 0);
37
+  const latlng = [];
38
+  if(outOfChina(wgLat, wgLon)) {
39
+    latlng[0] = wgLon;
40
+    latlng[1] = wgLat;
41
+    return latlng;
42
+  }
43
+  let dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
44
+  let dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
45
+  const radLat = wgLat / 180.0 * pi;
46
+  let magic = Math.sin(radLat);
47
+  magic = 1 - ee * magic * magic;
48
+  const sqrtMagic = Math.sqrt(magic);
49
+  dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
50
+  dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
51
+  latlng[0] = wgLon + dLon;
52
+  latlng[1] = wgLat + dLat;
53
+  return latlng;
54
+};

+ 16
- 0
src/utils/share.js 查看文件

@@ -0,0 +1,16 @@
1
+
2
+export function onShareAppMessage() {
3
+  return {
4
+    title: '换头像, 接力为祖国母亲庆生吧~',
5
+    path: `/pages/index/index?recommender=${this.user.personId}`,
6
+    imageUrl: 'https://yz-h5.oss-cn-shanghai.aliyuncs.com/assets/guoqing-miniapp/avatar_share.jpg',
7
+  }
8
+}
9
+
10
+
11
+export function onShareTimeline() {
12
+  return {
13
+    title: '换头像, 接力为祖国母亲庆生吧~',
14
+    query: `recommender=${this.user.personId}`
15
+  }
16
+}