Browse Source

no message

seamwang 1 year ago
parent
commit
f92ae6281c
2 changed files with 94 additions and 92 deletions
  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
 export default function fetch (url, params = {}, method = 'POST', showFail = true) {
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
             <view class="text-lg">学生列表</view>
18
             <view class="text-lg">学生列表</view>
19
             <view class="text-xs text-grey">
19
             <view class="text-xs text-grey">
20
               <text class="text-red">点击选择,左滑删除,右侧添加</text>
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
             </view>
22
             </view>
24
           </view>
23
           </view>
25
           <view class="padding-lr text-right" v-if="!phone">
24
           <view class="padding-lr text-right" v-if="!phone">
26
             <text class="text-red text-xs">右侧点击绑定手机号,直接获取绑定学生列表</text>
25
             <text class="text-red text-xs">右侧点击绑定手机号,直接获取绑定学生列表</text>
27
             <text class="cuIcon-mobile text-cyan add-icon margin-left-xl" @tap="globalNavigateTo('bindPhone')"></text>
26
             <text class="cuIcon-mobile text-cyan add-icon margin-left-xl" @tap="globalNavigateTo('bindPhone')"></text>
28
           </view>
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
             <view class="cu-list menu-avatar">
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
                 <image mode="scaleToFill" :src="defaultAvatar" class="avatar md left"></image>
41
                 <image mode="scaleToFill" :src="defaultAvatar" class="avatar md left"></image>
36
                 <view class="content">
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
                 </view>
45
                 </view>
40
                 <view class="action">
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
                 </view>
48
                 </view>
43
                 <view class="move student-move">
49
                 <view class="move student-move">
44
                   <view class="bg-red" @tap.stop="unbind(item.id)">删除</view>
50
                   <view class="bg-red" @tap.stop="unbind(item.id)">删除</view>
@@ -50,16 +56,16 @@
50
       </view>
56
       </view>
51
     </view>
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
         <view class="padding text-left modal-body radius-student">
61
         <view class="padding text-left modal-body radius-student">
56
           <view class="cu-list menu-avatar">
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
                 <image mode="scaleToFill" :src="defaultAvatar" class="avatar md left"></image>
65
                 <image mode="scaleToFill" :src="defaultAvatar" class="avatar md left"></image>
60
                 <view class="content">
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
                 </view>
69
                 </view>
64
               </view>
70
               </view>
65
             </view>
71
             </view>
@@ -68,19 +74,17 @@
68
       </view>
74
       </view>
69
     </view>
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
         <view class="cu-bar justify-around">
79
         <view class="cu-bar justify-around">
74
           <view class="content modal-title">添加学生</view>
80
           <view class="content modal-title">添加学生</view>
75
         </view>
81
         </view>
76
         <view class="padding-xl text-left modal-body">
82
         <view class="padding-xl text-left modal-body">
77
           <view>
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
           </view>
85
           </view>
81
           <view class="margin-top" v-if="student.student_name">
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
           </view>
88
           </view>
85
           <view class="margin-top">
89
           <view class="margin-top">
86
             <button class="student-input text-student text-left" @tap="get_students">获取学生</button>
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
 import { _shopList } from '@/api/course'
103
 import { _shopList } from '@/api/course'
100
 import { mapGetters } from 'vuex'
104
 import { mapGetters } from 'vuex'
101
 export default {
105
 export default {
102
-  data () {
106
+  data() {
103
     return {
107
     return {
104
       showAdd: false,
108
       showAdd: false,
105
       topHeader: this.globalCustomBarHeight,
109
       topHeader: this.globalCustomBarHeight,
@@ -118,13 +122,10 @@ export default {
118
     }
122
     }
119
   },
123
   },
120
   computed: {
124
   computed: {
121
-    ...mapGetters([
122
-      'kid', 'phone'
123
-    ])
125
+    ...mapGetters(['kid', 'phone'])
124
   },
126
   },
125
-  onLoad () {
126
-  },
127
-  onShow () {
127
+  onLoad() {},
128
+  onShow() {
128
     this.get_list()
129
     this.get_list()
129
     const kid = this.kid
130
     const kid = this.kid
130
     if (kid) {
131
     if (kid) {
@@ -134,25 +135,23 @@ export default {
134
         title: '请选择学生',
135
         title: '请选择学生',
135
         content: '请先选择一个学生',
136
         content: '请先选择一个学生',
136
         showCancel: false,
137
         showCancel: false,
137
-        success: res => {
138
-
139
-        }
138
+        success: res => {}
140
       })
139
       })
141
     }
140
     }
142
   },
141
   },
143
   methods: {
142
   methods: {
144
-    showModal (e) {
143
+    showModal(e) {
145
       this.modalName = e.currentTarget.dataset.target
144
       this.modalName = e.currentTarget.dataset.target
146
     },
145
     },
147
-    hideModal (e) {
146
+    hideModal(e) {
148
       this.modalName = null
147
       this.modalName = null
149
     },
148
     },
150
-    get_list () {
149
+    get_list() {
151
       _getStudents().then(res => {
150
       _getStudents().then(res => {
152
         this.result = res.data
151
         this.result = res.data
153
       })
152
       })
154
     },
153
     },
155
-    get_students () {
154
+    get_students() {
156
       if (!this.student.student_name) return uni.showToast({ title: '请输入学生姓名', icon: 'none' })
155
       if (!this.student.student_name) return uni.showToast({ title: '请输入学生姓名', icon: 'none' })
157
       if (!this.student.school_name) return uni.showToast({ title: '请输入学校名称', icon: 'none' })
156
       if (!this.student.school_name) return uni.showToast({ title: '请输入学校名称', icon: 'none' })
158
       _getStudents(this.student).then(res => {
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
       this.selectKid = id
168
       this.selectKid = id
170
       uni.showModal({
169
       uni.showModal({
171
         title: '确定绑定?',
170
         title: '确定绑定?',
@@ -182,7 +181,7 @@ export default {
182
         }
181
         }
183
       })
182
       })
184
     },
183
     },
185
-    unbind (id) {
184
+    unbind(id) {
186
       const _self = this
185
       const _self = this
187
       uni.showModal({
186
       uni.showModal({
188
         title: '确定解绑?',
187
         title: '确定解绑?',
@@ -192,7 +191,9 @@ export default {
192
             _unbindStudent({ student: id }).then(res => {
191
             _unbindStudent({ student: id }).then(res => {
193
               if (res.code === 1) {
192
               if (res.code === 1) {
194
                 uni.showToast({ title: '解绑成功!' })
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
                 this.get_list()
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
       uni.showModal({
205
       uni.showModal({
205
         title: '确定选择学生',
206
         title: '确定选择学生',
206
         message: '确定选择该学生?',
207
         message: '确定选择该学生?',
@@ -214,19 +215,20 @@ export default {
214
         }
215
         }
215
       })
216
       })
216
     },
217
     },
217
-    setCarts () { // 刷新购物车
218
+    setCarts() {
219
+      // 刷新购物车
218
       _shopList().then(res => {
220
       _shopList().then(res => {
219
         const carts = res.data.map(item => item.class_attend_id)
221
         const carts = res.data.map(item => item.class_attend_id)
220
         this.$store.dispatch('setCarts', carts)
222
         this.$store.dispatch('setCarts', carts)
221
       })
223
       })
222
     },
224
     },
223
-    ListTouchStart (e) {
225
+    ListTouchStart(e) {
224
       this.listTouchStart = e.touches[0].pageX
226
       this.listTouchStart = e.touches[0].pageX
225
     },
227
     },
226
-    ListTouchMove (e) {
228
+    ListTouchMove(e) {
227
       this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
229
       this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
228
     },
230
     },
229
-    ListTouchEnd (e) {
231
+    ListTouchEnd(e) {
230
       if (this.listTouchDirection === 'left') {
232
       if (this.listTouchDirection === 'left') {
231
         this.moveModel = e.currentTarget.dataset.target
233
         this.moveModel = e.currentTarget.dataset.target
232
       } else {
234
       } else {