张延森 3 年 前
コミット
0598ca6574
共有7 個のファイルを変更した153 個の追加147 個の削除を含む
  1. 1
    1
      babel.config.js
  2. 78
    0
      src/components/FieldPicker/index.vue
  3. 0
    3
      src/store/index.js
  4. 10
    3
      src/util/initial.js
  5. 8
    8
      src/views/UserCenter.vue
  6. 46
    132
      src/views/userPages/SetUser.vue
  7. 10
    0
      vue.config.js

+ 1
- 1
babel.config.js ファイルの表示

@@ -7,7 +7,7 @@ module.exports = {
7 7
     ['import', {
8 8
       libraryName: 'vant',
9 9
       libraryDirectory: 'es',
10
-      style: true
10
+      style: (name) => `${name}/style/less`,
11 11
     }, 'vant']
12 12
   ]
13 13
 }

+ 78
- 0
src/components/FieldPicker/index.vue ファイルの表示

@@ -0,0 +1,78 @@
1
+<template>
2
+  <van-field
3
+    readonly
4
+    clickable
5
+    :name="name"
6
+    :value="valueText"
7
+    :label="label"
8
+    :placeholder="placeholder"
9
+    @click="show = true"
10
+  >
11
+    <template slot="extra">
12
+      <van-popup v-model="show" :position="position">
13
+        <van-picker
14
+          show-toolbar
15
+          :columns="columns"
16
+          :value-key="valueKey"
17
+          @click.native.stop="() => {}"
18
+          @confirm="handleConfirm"
19
+          @cancel="show = false"
20
+        />
21
+      </van-popup>
22
+    </template>
23
+  </van-field>
24
+</template>
25
+
26
+<script>
27
+// 暂时只支持单列
28
+
29
+export default {
30
+  name: 'FieldPicker',
31
+  props: {
32
+    name: String,
33
+    value: null,
34
+    label: String,
35
+    placeholder: {
36
+      type: String,
37
+      default: '请选择'
38
+    },
39
+    position: {
40
+      type: String,
41
+      default: 'bottom',
42
+    },
43
+    columns: {
44
+      type: Array,
45
+      default: () => [],
46
+    },
47
+    valueKey: {
48
+      type: String,
49
+      required: true,
50
+    },
51
+    valueId: {
52
+      type: String,
53
+      required: true,
54
+    },
55
+  },
56
+  computed: {
57
+    valueText() {
58
+      if (this.value === undefined || this.value === null) return undefined;
59
+      if (!this.columns) return undefined;
60
+
61
+      const item = this.columns.filter(x => x[this.valueId] === this.value)[0] || {}
62
+      return item[this.valueKey]
63
+    }
64
+  },
65
+  data() {
66
+    return {
67
+      show: false,
68
+    }
69
+  },
70
+  methods: {
71
+    handleConfirm(_, inx) {
72
+      this.show = false
73
+      const item = this.columns[inx]
74
+      this.$emit('input', item[this.valueId])
75
+    }
76
+  }
77
+}
78
+</script>

+ 0
- 3
src/store/index.js ファイルの表示

@@ -16,11 +16,8 @@ const store = new Vuex.Store({
16 16
       phone: '',
17 17
       personId: '',
18 18
       classId: '',
19
-      sexNumber: null,
20
-      Semester: '',
21 19
       sex: '',
22 20
       termId: '',
23
-      Classs: '',
24 21
       LOADING: false,
25 22
     }
26 23
   },

+ 10
- 3
src/util/initial.js ファイルの表示

@@ -70,10 +70,17 @@ export function Login () {
70 70
     console.log(e);
71 71
     let userInfo = {
72 72
       token: e.token,
73
-      name: e.person.name,
74
-      phone: e.person.phone,
75
-      personId: e.person.personId,
73
+      ...e.person,
76 74
     }
75
+
76
+    if (e.student && e.student.classId) {
77
+      userInfo = {
78
+        ...userInfo,
79
+        termId: e.student.termId,
80
+        classId: e.student.classId,
81
+      }
82
+    }
83
+
77 84
     store.commit('SET_USER_INFO', userInfo)
78 85
     hideLoading()
79 86
 

+ 8
- 8
src/views/UserCenter.vue ファイルの表示

@@ -14,7 +14,9 @@
14 14
         </div>
15 15
       </div>
16 16
 
17
-      <div v-else class="userInfo-button-zhuce" @click="seeUserInfo()">注册</div>
17
+      <div v-else class="userInfo-button-zhuce" @click="seeUserInfo()">
18
+        <van-button round type="info" size="small">&nbsp;&nbsp;注&nbsp;&nbsp;&nbsp;&nbsp;册&nbsp;&nbsp;</van-button>
19
+      </div>
18 20
     </div>
19 21
 
20 22
     <div class="menu-list flex-1">
@@ -135,14 +137,12 @@ export default {
135 137
 
136 138
     }
137 139
     .userInfo-button-zhuce {
138
-      width: 80px;
139
-      letter-spacing: 4px;
140
-      color: #fff;
141
-      border-radius: 20px;
142
-      line-height: 30px;
143
-      background-color: #2cb798;
144 140
       margin: 0 auto;
145
-      text-align: center;
141
+
142
+      .van-button {
143
+        // text-align: right;
144
+        // letter-spacing: 10px;
145
+      }
146 146
     }
147 147
   }
148 148
   .menu-list {

+ 46
- 132
src/views/userPages/SetUser.vue ファイルの表示

@@ -4,76 +4,47 @@
4 4
       <van-nav-bar title="修改个人信息" left-text="返回" left-arrow @click-left="onClickLeft" />
5 5
       <van-form @submit="onSubmit">
6 6
         <van-field
7
-          v-model="name"
8
-          name="name"
7
+          v-model="personInfo.name"
9 8
           label="姓名"
10 9
           placeholder="姓名"
11 10
           :rules="[{ required: true, message: '请填写姓名' }]"
12 11
         />
13 12
         <van-field
14
-          v-model="phone"
13
+          v-model="personInfo.phone"
15 14
           type="number"
16
-          name="phone"
17 15
           maxlength="11"
18 16
           label="手机号"
19 17
           placeholder="手机号"
20 18
           :rules="[{ required: true, message: '请填写手机号码' }]"
21 19
         />
22
-        <van-field
23
-          readonly
24
-          clickable
25
-          name="sex"
26
-          :value="sex"
20
+
21
+        <field-picker
27 22
           label="性别"
28 23
           placeholder="点击选择性别"
29
-          @click="onClickPicker(1)"
24
+          v-model="personInfo.sex"
25
+          value-id="id"
26
+          value-key="label"
27
+          :columns="sexArry"
30 28
         />
31
-        <van-popup v-model="sexShowPicker" position="bottom">
32
-          <van-picker
33
-            show-toolbar
34
-            :columns="sexArry"
35
-            @confirm="onConfirmSex"
36
-            @cancel="sexShowPicker = false"
37
-          />
38
-        </van-popup>
39 29
 
40
-        <van-field
41
-          readonly
42
-          clickable
43
-          name="Semester"
44
-          :value="Semester"
30
+        <field-picker
31
+          v-model="personInfo.termId"
45 32
           label="学期"
46 33
           placeholder="点击选择学期"
47
-          @click="onClickPicker(2)"
34
+          value-id="termId"
35
+          value-key="name"
36
+          :columns="SemesterArry"
48 37
         />
49
-        <van-popup v-model="SemesterShowPicker" position="bottom">
50
-          <van-picker
51
-            show-toolbar
52
-            value-key="name"
53
-            :columns="SemesterArry"
54
-            @confirm="onConfirmSemester"
55
-            @cancel="SemesterShowPicker = false"
56
-          />
57
-        </van-popup>
58 38
 
59
-        <van-field
60
-          readonly
61
-          clickable
62
-          name="Classs"
63
-          :value="Classs"
39
+        <field-picker
40
+          v-model="personInfo.classId"
64 41
           label="班级"
65 42
           placeholder="点击选择班级"
66
-          @click="ClasssShowPicker = true"
43
+          value-id="classId"
44
+          value-key="name"
45
+          :columns="ClasssArry"
67 46
         />
68
-        <van-popup v-model="ClasssShowPicker" position="bottom">
69
-          <van-picker
70
-            show-toolbar
71
-            value-key="name"
72
-            :columns="ClasssArry"
73
-            @confirm="onConfirmClasss"
74
-            @cancel="onClickPicker(3)"
75
-          />
76
-        </van-popup>
47
+
77 48
         <div style="margin: 20px; margin-top:3em;">
78 49
           <van-button round block type="info" native-type="submit">提交</van-button>
79 50
         </div>
@@ -84,24 +55,25 @@
84 55
 
85 56
 <script>
86 57
 import { mapState } from 'vuex'
87
-import { SetUser, getSchoolterm, getSchoolClass } from '../../util/api'
58
+import { SetUser, getSchoolterm, getSchoolClass } from '@/util/api'
59
+
88 60
 export default {
61
+  components: {
62
+    FieldPicker: () => import('@/components/FieldPicker')
63
+  },
64
+
89 65
   data() {
90 66
     return {
91
-      name: '',
92
-      phone: '',
93
-      sexArry: ['男', '女'],
67
+      personInfo: {
68
+        name: null,
69
+        sex: null,
70
+        phone: null,
71
+        termId: null,
72
+        classId: null,
73
+      },
74
+      sexArry: [{id: 1, label: '男'}, {id: 2, label: '女'}],
94 75
       SemesterArry: [],
95 76
       ClasssArry: [],
96
-      sexShowPicker: false,
97
-      SemesterShowPicker: false,
98
-      ClasssShowPicker: false,
99
-      sex: '',
100
-      sexNumber: null,
101
-      Semester: '',
102
-      Classs: '',
103
-      termId: '',
104
-      classId: ''
105 77
     }
106 78
   },
107 79
   computed: {
@@ -113,11 +85,11 @@ export default {
113 85
     user: {
114 86
       handler(nw) {
115 87
         if (nw) {
116
-          this.name = nw.name
117
-          this.phone = nw.phone
118
-          this.Classs = nw.Classs
119
-          this.Semester = nw.Semester
120
-          this.sex = nw.sex
88
+          this.personInfo.name = nw.name
89
+          this.personInfo.phone = nw.phone
90
+          this.personInfo.classId = nw.classId
91
+          this.personInfo.termId = nw.termId
92
+          this.personInfo.sex = nw.sex
121 93
         }
122 94
       },
123 95
       immediate: true
@@ -125,9 +97,6 @@ export default {
125 97
   },
126 98
   mounted() {
127 99
     this.getSemester()
128
-    // if (this.ClasssShowPicker) {
129
-    //   this.getClass()
130
-    // }
131 100
   },
132 101
   methods: {
133 102
     // 获取学期班级 star
@@ -135,6 +104,12 @@ export default {
135 104
       getSchoolterm({ pageSize: 999 }).then((e) => {
136 105
         console.log('获取学期', e)
137 106
         this.SemesterArry = e.records
107
+
108
+        if ((!this.ClasssArry || this.ClasssArry.length < 1) && e.total > 0) {
109
+          const first = this.SemesterArry[0]
110
+
111
+          this.getClass(first.termId)
112
+        }
138 113
       })
139 114
     },
140 115
 
@@ -148,78 +123,17 @@ export default {
148 123
     onClickLeft() {
149 124
       this.$router.go(-1)
150 125
     },
151
-    onConfirmSex(e) {
152
-      if (e == '男') {
153
-        this.sexNumber = 1
154
-        this.sex = e
155
-      } else {
156
-        this.sexNumber = 2
157
-
158
-        this.sex = e
159
-      }
160
-
161
-      this.sexShowPicker = false
162
-    },
163 126
     //学期区------------------------
164 127
 
165
-    onConfirmSemester(e, x) {
166
-      const { name, termId } = e
167
-      this.Semester = name
168
-      this.getClass(termId)
169
-      this.termId = termId
170
-      console.log('🚀 ~值,下标 ', e, x)
171
-      this.SemesterShowPicker = false
172
-    },
173
-    //班级区------------------------
174
-    onConfirmClasss(e) {
175
-      const { name, classId } = e
176
-      this.Classs = name
177
-      this.classId = classId
178
-
179
-      this.ClasssShowPicker = false
180
-    },
181
-    // this.showPicker = false
182
-
183
-    onClickPicker(e) {
184
-      switch (e) {
185
-        case 1:
186
-          this.sexShowPicker = true
187
-
188
-          break
189
-        case 2:
190
-          this.SemesterShowPicker = true
191
-          this.Classs = ''
192
-
193
-          break
194
-        case 3:
195
-          this.ClasssShowPicker = true
196
-
197
-          break
198
-        default:
199
-          break
200
-      }
201
-    },
202 128
     onSubmit(values) {
203 129
       console.log('submit', values)
204 130
 
205 131
       this.$toast.success('修改成功!')
206 132
       SetUser(this.$store.state.user.personId, {
207
-        classId: this.classId,
208
-        name: this.name,
133
+        ...this.personInfo,
209 134
         personId: this.$store.state.user.personId,
210
-        phone: this.phone,
211
-        sex: this.sexNumber,
212
-        termId: this.termId
213 135
       }).then((e) => {
214
-        console.log(e)
215
-        this.$store.commit('SET_USER_INFO', { name: this.name })
216
-        this.$store.commit('SET_USER_INFO', { phone: values.phone })
217
-        this.$store.commit('SET_USER_INFO', { sexNumber: this.sexNumber })
218
-        this.$store.commit('SET_USER_INFO', { termId: this.termId })
219
-        this.$store.commit('SET_USER_INFO', { classId: this.classId })
220
-        this.$store.commit('SET_USER_INFO', { Classs: this.Classs })
221
-        this.$store.commit('SET_USER_INFO', { Semester: this.Semester })
222
-        this.$store.commit('SET_USER_INFO', { sex: this.sex })
136
+        this.$store.commit('SET_USER_INFO', this.personInfo)
223 137
         this.$router.go(-1)
224 138
       })
225 139
     }

+ 10
- 0
vue.config.js ファイルの表示

@@ -7,6 +7,16 @@ const resolve = dir => path.join(__dirname, dir)
7 7
 
8 8
 
9 9
 module.exports = {
10
+  css: {
11
+    loaderOptions: {
12
+      less: {
13
+        modifyVars: {
14
+          // 直接覆盖变量
15
+          'blue': '#2CB798',
16
+        },
17
+      },
18
+    },
19
+  },
10 20
 
11 21
   devServer: {
12 22
     proxy: {