李志伟 3 anni fa
parent
commit
5cce81928a
4 ha cambiato i file con 49 aggiunte e 22 eliminazioni
  1. 15
    7
      src/components/AreaPicker/index.vue
  2. 6
    0
      src/main.js
  3. 19
    14
      src/pages/signup.vue
  4. 9
    1
      vue.config.js

+ 15
- 7
src/components/AreaPicker/index.vue Vedi File

@@ -1,6 +1,6 @@
1 1
 <template>
2
-  <van-popup v-model="show">
3
-    <van-area title="地区" v-model="value" :area-list="areaList" :loading="loading" @confirm="$emit('change')" />
2
+  <van-popup v-model="visible" position="bottom">
3
+    <van-area title="地区" v-model="value" :area-list="areaList" :loading="loading" @confirm="handleConfirm" />
4 4
   </van-popup>
5 5
 </template>
6 6
 
@@ -8,10 +8,7 @@
8 8
 export default {
9 9
   name: 'AreaPicker',
10 10
   props: {
11
-    value: {
12
-      type: Array,
13
-      default: () => []
14
-    },
11
+    value: [String, Array],
15 12
     show: Boolean
16 13
   },
17 14
   data() {
@@ -21,6 +18,14 @@ export default {
21 18
     }
22 19
   },
23 20
   computed: {
21
+    visible: {
22
+      get() {
23
+        return this.show
24
+      },
25
+      set(val) {
26
+        this.$emit('update:show', val)
27
+      }
28
+    },
24 29
     areaList() {
25 30
       return this.list.reduce((acc, x) => {
26 31
         const { province_list, city_list, county_list } = acc
@@ -46,6 +51,9 @@ export default {
46 51
     this.getAreaData()
47 52
   },
48 53
   methods: {
54
+    handleConfirm(v) {
55
+      this.$emit('change', v)
56
+    },
49 57
     getAreaData() {
50 58
       const list = localStorage.getItem('areas')
51 59
       if (list) {
@@ -56,7 +64,7 @@ export default {
56 64
       this.loading = true
57 65
 
58 66
       // 如果不存在
59
-      fetch('https://restapi.amap.com/v3/config/district?keywords=中国&subdistrict=3&key=194d2c8d01a9084e3b0bbb62d2d5fad0').then(res => res.JSON()).then(res => {
67
+      fetch('https://restapi.amap.com/v3/config/district?keywords=中国&subdistrict=3&key=194d2c8d01a9084e3b0bbb62d2d5fad0').then(res => res.json()).then(res => {
60 68
         this.list = res.districts[0].districts
61 69
         localStorage.setItem('area', this.list)
62 70
         this.loading = false

+ 6
- 0
src/main.js Vedi File

@@ -5,10 +5,16 @@ import App from './App'
5 5
 import 'regenerator-runtime/runtime'
6 6
 import 'swiper/swiper-bundle.css'
7 7
 
8
+
8 9
 import router from './router'
9 10
 import Swiper from './components/Swiper'
10 11
 import SwiperSlide from './components/SwiperSlide'
11 12
 
13
+import { Popup } from 'vant';
14
+import { Area } from 'vant';
15
+Vue.use(Popup);
16
+Vue.use(Area);
17
+
12 18
 Vue.config.productionTip = false
13 19
 Vue.component('swiper', Swiper)
14 20
 Vue.component('swiper-slide', SwiperSlide)

+ 19
- 14
src/pages/signup.vue Vedi File

@@ -36,18 +36,19 @@
36 36
       </div>
37 37
       <div class="formItem addressdiv" @click="showArea = true">
38 38
         <label>所在地区</label>
39
-        <input class="address" type="text" placeholder="请选择" v-model="formData.address" />
39
+        <input class="address" type="text" placeholder="请选择" v-model="address" />
40 40
       </div>
41 41
       <img @click="sumbit" class="submit" src="../../public/images/signup/submit.png" width="45%" />
42 42
     </div>
43
+    <area-picker :show.sync="showArea" @change="handleArea"></area-picker>
43 44
   </div>
44 45
 </template>
45 46
 <script>
46
-// import checked from '../../public/images/signup/checked.png'
47
-// import Unchecked from '../../public/images/signup/Unchecked.png'
47
+
48
+
48 49
 export default {
49 50
   components: {
50
-    // AreaPicker: () => import('@/components/AreaPicker.vue')
51
+    AreaPicker: () => import('@/components/AreaPicker')
51 52
   },
52 53
   data() {
53 54
     return {
@@ -86,7 +87,13 @@ export default {
86 87
           }
87 88
         ]
88 89
       ],
89
-      pickerVisibleProduct: false
90
+      pickerVisibleProduct: false,
91
+      address: undefined
92
+    }
93
+  },
94
+  watch: {
95
+    'this.formData.address'() {
96
+      this.address = formData.address[0].name+formData.address[1].name+formData.address[2].name
90 97
     }
91 98
   },
92 99
   methods: {
@@ -98,15 +105,10 @@ export default {
98 105
       this.ischecked = false
99 106
       this.formData.role = 'designer'
100 107
     },
101
-    // showProduct() {
102
-    //   this.pickerVisibleProduct = true
103
-    // },
104
-    // cancelProduct() {
105
-    //   this.pickerVisibleProduct = false
106
-    // },
107
-    // confirmProduct(res) {
108
-    //   this.formData.intendedProduct = res[0].label
109
-    // },
108
+    handleArea(val) {
109
+      this.showArea = false
110
+      this.formData.address = val
111
+    },
110 112
     verification() {
111 113
       if (!this.formData.userName) {
112 114
         alert('请输入您的姓名')
@@ -135,6 +137,9 @@ export default {
135 137
 }
136 138
 </script>
137 139
 <style scoped>
140
+body #app{
141
+  background: none !important;
142
+}
138 143
 * {
139 144
   margin: 0;
140 145
   padding: 0;

+ 9
- 1
vue.config.js Vedi File

@@ -1,3 +1,11 @@
1
+
2
+const path = require('path')
3
+
1 4
 module.exports = {
2
-  publicPath: './'
5
+  publicPath: './',
6
+  chainWebpack(config) {
7
+    config.resolve.alias
8
+      .set('@/components', path.resolve(__dirname, 'src/components/'))
9
+      .set('@/utils', path.resolve(__dirname, 'src/utils/'))
10
+  }
3 11
 }