Bladeren bron

no message

seamwang 1 jaar geleden
bovenliggende
commit
f92ae6281c
2 gewijzigde bestanden met toevoegingen van 94 en 92 verwijderingen
  1. 48 48
      src/common/utils/fetch.js
  2. 46 44
      src/pages/myStudents/myStudents.vue

+ 48 - 48
src/common/utils/fetch.js

@@ -2,52 +2,52 @@ import store from '@/store/index'
2 2
 
3 3
 // 统一请求方法
4 4
 export default function fetch (url, params = {}, method = 'POST', showFail = true) {
5
-	let showLoading = true
6
-	if (params && params.notShowLoading) {
7
-		showLoading = false
8
-	}
9
-	if (showLoading) {
10
-		uni.showLoading({
11
-			mask: true,
12
-			title: '加载中...'
13
-		})
14
-	}
15
-	url = process.env.VUE_APP_BASE_URL + url
16
-	params.token = store.getters.token
17
-	params.student_id = params.student_id || store.getters.kid
18
-	return new Promise((resolve, reject) => {
19
-		uni.request({
20
-			url,
21
-			data: params,
22
-			method,
23
-			header: {},
24
-			success: (res) => {
25
-				uni.hideLoading()
26
-				// 0:错误; 1:正确; 10000:没有token -2: 需要绑定手机
27
-				const rs = res.data
28
-				if (rs && rs.code === 1) {
29
-					resolve(rs)
30
-				} else if (rs.code === 10000) {
31
-					// // 跳转至登录页
32
-					uni.showModal({
33
-						title: '请先登录',
34
-						content: '您还没有登录,请先去登录',
35
-						success: res => {
36
-							if (res.confirm) {
37
-								uni.navigateTo({ url: '/pages/login/index' })
38
-							}
39
-						}
40
-					})
41
-				} else {
42
-					if (showFail) uni.showToast({ title: rs.msg, icon: 'none', duration: 2000 })// 直接提示错误
43
-					resolve(rs)
44
-				}
45
-			},
46
-			fail: (err) => {
47
-				uni.hideLoading()
48
-				uni.showToast({ title: err, icon: 'none', duration: 2000 })
49
-				reject(err)
50
-			}
51
-		})
52
-	})
5
+  let showLoading = true
6
+  if (params && params.notShowLoading) {
7
+    showLoading = false
8
+  }
9
+  if (showLoading) {
10
+    uni.showLoading({
11
+      mask: true,
12
+      title: '加载中...'
13
+    })
14
+  }
15
+  url = process.env.VUE_APP_BASE_URL + url
16
+  params.token = store.getters.token
17
+  params.student_id = params.student_id || store.getters.kid
18
+  return new Promise((resolve, reject) => {
19
+    uni.request({
20
+      url,
21
+      data: params,
22
+      method,
23
+      header: {},
24
+      success: (res) => {
25
+        uni.hideLoading()
26
+        // 0:错误; 1:正确; 10000:没有token -2: 需要绑定手机
27
+        const rs = res.data
28
+        if (rs && rs.code === 1) {
29
+          resolve(rs)
30
+        } else if (rs.code === 10000) {
31
+          // // 跳转至登录页
32
+          uni.showModal({
33
+            title: '请先登录',
34
+            content: '您还没有登录,请先去登录',
35
+            success: res => {
36
+              if (res.confirm) {
37
+                uni.navigateTo({ url: '/pages/login/index' })
38
+              }
39
+            }
40
+          })
41
+        } else {
42
+          if (showFail) uni.showToast({ title: rs.msg, icon: 'none', duration: 2000 })// 直接提示错误
43
+          resolve(rs)
44
+        }
45
+      },
46
+      fail: (err) => {
47
+        uni.hideLoading()
48
+        uni.showToast({ title: err, icon: 'none', duration: 2000 })
49
+        reject(err)
50
+      }
51
+    })
52
+  })
53 53
 }

+ 46 - 44
src/pages/myStudents/myStudents.vue

@@ -18,27 +18,33 @@
18 18
             <view class="text-lg">学生列表</view>
19 19
             <view class="text-xs text-grey">
20 20
               <text class="text-red">点击选择,左滑删除,右侧添加</text>
21
-              <text class="cuIcon-roundaddfill text-cyan margin-left-xl add-icon" @tap="showModal"
22
-                data-target="ChooseModal"></text>
21
+              <text class="cuIcon-roundaddfill text-cyan margin-left-xl add-icon" @tap="showModal" data-target="ChooseModal"></text>
23 22
             </view>
24 23
           </view>
25 24
           <view class="padding-lr text-right" v-if="!phone">
26 25
             <text class="text-red text-xs">右侧点击绑定手机号,直接获取绑定学生列表</text>
27 26
             <text class="cuIcon-mobile text-cyan add-icon margin-left-xl" @tap="globalNavigateTo('bindPhone')"></text>
28 27
           </view>
29
-          <scroll-view scroll-y :style="[{height:'calc(100vh - 230px - '+ topHeader+'px)'}]">
28
+          <scroll-view scroll-y :style="[{ height: 'calc(100vh - 230px - ' + topHeader + 'px)' }]">
30 29
             <view class="cu-list menu-avatar">
31
-              <view class="cu-item" :class="moveModel=='move-box-'+ index?'move-cur':''"
32
-                v-for="(item,index) in result.student_data" :key="index" @touchstart="ListTouchStart"
33
-                @touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + index"
34
-                @tap="chooseKid(item.id)">
30
+              <view
31
+                class="cu-item"
32
+                :class="moveModel == 'move-box-' + index ? 'move-cur' : ''"
33
+                v-for="(item, index) in result.student_data"
34
+                :key="index"
35
+                @touchstart="ListTouchStart"
36
+                @touchmove="ListTouchMove"
37
+                @touchend="ListTouchEnd"
38
+                :data-target="'move-box-' + index"
39
+                @tap="chooseKid(item.id)"
40
+              >
35 41
                 <image mode="scaleToFill" :src="defaultAvatar" class="avatar md left"></image>
36 42
                 <view class="content">
37
-                  <view>{{item.name}}</view>
38
-                  <view class="text-gray">{{item.school_name}}-{{item.grade_name}}-{{item.class_name}}</view>
43
+                  <view>{{ item.name }}</view>
44
+                  <view class="text-gray">{{ item.school_name }}-{{ item.grade_name }}-{{ item.class_name }}</view>
39 45
                 </view>
40 46
                 <view class="action">
41
-                  <text class="cuIcon-check text-student font-check" v-if="item.id===kid"></text>
47
+                  <text class="cuIcon-check text-student font-check" v-if="item.id === kid"></text>
42 48
                 </view>
43 49
                 <view class="move student-move">
44 50
                   <view class="bg-red" @tap.stop="unbind(item.id)">删除</view>
@@ -50,16 +56,16 @@
50 56
       </view>
51 57
     </view>
52 58
     <!-- 选择学生列表 -->
53
-    <view class="cu-modal" :class="modalName=='showStudents'?'show':''" @tap="hideModal">
54
-      <view class="cu-dialog bg-student" @tap.stop=''>
59
+    <view class="cu-modal" :class="modalName == 'showStudents' ? 'show' : ''" @tap="hideModal">
60
+      <view class="cu-dialog bg-student" @tap.stop="">
55 61
         <view class="padding text-left modal-body radius-student">
56 62
           <view class="cu-list menu-avatar">
57
-            <view class="cu-item" v-for="(item,index) in chooseList" :key="index" @tap="save(item.id)">
58
-              <view class="cu-inner" :class="{'checked':item.id===selectKid}">
63
+            <view class="cu-item" v-for="(item, index) in chooseList" :key="index" @tap="save(item.id)">
64
+              <view class="cu-inner" :class="{ checked: item.id === selectKid }">
59 65
                 <image mode="scaleToFill" :src="defaultAvatar" class="avatar md left"></image>
60 66
                 <view class="content">
61
-                  <view>{{item.name}}</view>
62
-                  <view class="text-gray">{{item.school_name}}-{{item.grade_name}}-{{item.class_name}}</view>
67
+                  <view>{{ item.name }}</view>
68
+                  <view class="text-gray">{{ item.school_name }}-{{ item.grade_name }}-{{ item.class_name }}</view>
63 69
                 </view>
64 70
               </view>
65 71
             </view>
@@ -68,19 +74,17 @@
68 74
       </view>
69 75
     </view>
70 76
     <!--添加学生-->
71
-    <view class="cu-modal" :class="modalName=='ChooseModal'?'show':''" @tap="hideModal">
72
-      <view class="cu-dialog bg-student" @tap.stop=''>
77
+    <view class="cu-modal" :class="modalName == 'ChooseModal' ? 'show' : ''" @tap="hideModal">
78
+      <view class="cu-dialog bg-student" @tap.stop="">
73 79
         <view class="cu-bar justify-around">
74 80
           <view class="content modal-title">添加学生</view>
75 81
         </view>
76 82
         <view class="padding-xl text-left modal-body">
77 83
           <view>
78
-            <input type="text" v-model.trim="student.student_name" placeholder="请输入学生名字"
79
-              class="student-input text-black text-lg">
84
+            <input type="text" v-model.trim="student.student_name" placeholder="请输入学生名字" class="student-input text-black text-lg" />
80 85
           </view>
81 86
           <view class="margin-top" v-if="student.student_name">
82
-            <input type="text" v-model.trim="student.school_name" placeholder="请输入学校名称"
83
-              class="student-input text-black text-lg">
87
+            <input type="text" v-model.trim="student.school_name" placeholder="请输入学校名称" class="student-input text-black text-lg" />
84 88
           </view>
85 89
           <view class="margin-top">
86 90
             <button class="student-input text-student text-left" @tap="get_students">获取学生</button>
@@ -99,7 +103,7 @@ import { _getStudents, _bindStudent, _unbindStudent } from '@/api/auth'
99 103
 import { _shopList } from '@/api/course'
100 104
 import { mapGetters } from 'vuex'
101 105
 export default {
102
-  data () {
106
+  data() {
103 107
     return {
104 108
       showAdd: false,
105 109
       topHeader: this.globalCustomBarHeight,
@@ -118,13 +122,10 @@ export default {
118 122
     }
119 123
   },
120 124
   computed: {
121
-    ...mapGetters([
122
-      'kid', 'phone'
123
-    ])
125
+    ...mapGetters(['kid', 'phone'])
124 126
   },
125
-  onLoad () {
126
-  },
127
-  onShow () {
127
+  onLoad() {},
128
+  onShow() {
128 129
     this.get_list()
129 130
     const kid = this.kid
130 131
     if (kid) {
@@ -134,25 +135,23 @@ export default {
134 135
         title: '请选择学生',
135 136
         content: '请先选择一个学生',
136 137
         showCancel: false,
137
-        success: res => {
138
-
139
-        }
138
+        success: res => {}
140 139
       })
141 140
     }
142 141
   },
143 142
   methods: {
144
-    showModal (e) {
143
+    showModal(e) {
145 144
       this.modalName = e.currentTarget.dataset.target
146 145
     },
147
-    hideModal (e) {
146
+    hideModal(e) {
148 147
       this.modalName = null
149 148
     },
150
-    get_list () {
149
+    get_list() {
151 150
       _getStudents().then(res => {
152 151
         this.result = res.data
153 152
       })
154 153
     },
155
-    get_students () {
154
+    get_students() {
156 155
       if (!this.student.student_name) return uni.showToast({ title: '请输入学生姓名', icon: 'none' })
157 156
       if (!this.student.school_name) return uni.showToast({ title: '请输入学校名称', icon: 'none' })
158 157
       _getStudents(this.student).then(res => {
@@ -165,7 +164,7 @@ export default {
165 164
         }
166 165
       })
167 166
     },
168
-    save (id) {
167
+    save(id) {
169 168
       this.selectKid = id
170 169
       uni.showModal({
171 170
         title: '确定绑定?',
@@ -182,7 +181,7 @@ export default {
182 181
         }
183 182
       })
184 183
     },
185
-    unbind (id) {
184
+    unbind(id) {
186 185
       const _self = this
187 186
       uni.showModal({
188 187
         title: '确定解绑?',
@@ -192,7 +191,9 @@ export default {
192 191
             _unbindStudent({ student: id }).then(res => {
193 192
               if (res.code === 1) {
194 193
                 uni.showToast({ title: '解绑成功!' })
195
-                if (_self.kid === id) { _self.$store.dispatch('setKid', 0) }// 解绑选中学生
194
+                if (_self.kid === id) {
195
+                  _self.$store.dispatch('setKid', 0)
196
+                } // 解绑选中学生
196 197
                 this.get_list()
197 198
               }
198 199
             })
@@ -200,7 +201,7 @@ export default {
200 201
         }
201 202
       })
202 203
     },
203
-    chooseKid (id) {
204
+    chooseKid(id) {
204 205
       uni.showModal({
205 206
         title: '确定选择学生',
206 207
         message: '确定选择该学生?',
@@ -214,19 +215,20 @@ export default {
214 215
         }
215 216
       })
216 217
     },
217
-    setCarts () { // 刷新购物车
218
+    setCarts() {
219
+      // 刷新购物车
218 220
       _shopList().then(res => {
219 221
         const carts = res.data.map(item => item.class_attend_id)
220 222
         this.$store.dispatch('setCarts', carts)
221 223
       })
222 224
     },
223
-    ListTouchStart (e) {
225
+    ListTouchStart(e) {
224 226
       this.listTouchStart = e.touches[0].pageX
225 227
     },
226
-    ListTouchMove (e) {
228
+    ListTouchMove(e) {
227 229
       this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
228 230
     },
229
-    ListTouchEnd (e) {
231
+    ListTouchEnd(e) {
230 232
       if (this.listTouchDirection === 'left') {
231 233
         this.moveModel = e.currentTarget.dataset.target
232 234
       } else {