huangyouyou пре 10 месеци
родитељ
комит
75ccfa1059
6 измењених фајлова са 209 додато и 70 уклоњено
  1. 20 0
      api/student.js
  2. 0 1
      pages.json
  3. 92 47
      pages/classes/select.vue
  4. 45 6
      pages/index/init.vue
  5. 24 12
      pages/test/bmi.vue
  6. 28 4
      store/useUserStore.js

+ 20 - 0
api/student.js

@@ -3,3 +3,23 @@ import request from "@/utils/request";
 export function cradToStudentInfo(data) {
   return request.post('machine/student/cardToInfo', data)
 }
+
+export function login(data) {
+  return request.post('equipment/common/login', data)
+}
+
+export function getTaskClassList(data) {
+  return request.post('equipment/work/getTaskClassList', data)
+}
+
+export function getTaskStudentList(data) {
+  return request.post('equipment/work/getTaskStudentList', data)
+}
+
+export function addStudentTaskData(data) {
+  return request.post('equipment/work/addStudentTaskData', data)
+}
+
+export function getStudentTaskDetail(data) {
+  return request.post('equipment/work/getStudentTaskDetail', data)
+}

+ 0 - 1
pages.json

@@ -8,7 +8,6 @@
   },
   "pages": [
     //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
-
        {
          "path": "pages/index/init",
          "style": {

+ 92 - 47
pages/classes/select.vue

@@ -16,11 +16,11 @@
       </view>
       <view class="select-info" v-else-if="activeTab == 'class'">
         <view v-for="(item, index) in classList" class="info-item" @click="changeClass(item)"
-          :class="item.active == true ? `info-active-item1` : `info-item1`">{{ item.name }}</view>
+          :class="item.active == true ? `info-active-item1` : `info-item1`">{{ item.class_name }}</view>
       </view>
       <view class="select-info" v-else-if="activeTab == 'student'">
         <view v-for="(item, index) in studentList" class="info-item" @click="changeStudent(item)"
-          :class="item.active == true ? `info-active-item2` : `info-item2`">{{ item.name }}</view>
+          :class="item.active == true ? `info-active-item2` : `info-item2`">{{ item.jname }}</view>
       </view>
     </view>
     <view class="selected-box">
@@ -37,16 +37,18 @@
 </template>
 
 <script setup>
-import { onActivated, onMounted, reactive, ref, computed } from "vue";
-import { onLoad } from '@dcloudio/uni-app';
+import { onActivated, onUnmounted, watch, ref, computed } from "vue";
+import { onLoad, onUnload, onHide } from '@dcloudio/uni-app';
 import { navTo, showToast } from "@/utils/app";
+import { getTaskClassList, getTaskStudentList } from "@/api/student";
 
 const title = ref('学生未激活')
 const select = ref(0)
 const selectMax = ref(1)
 const totalList = ref([])
 const activeTab = ref('grade')
-const countdown = ref(60)
+const countdown = ref(5)
+const interval = ref()
 const queryForm = ref({
   student_id: 0,
 })
@@ -61,6 +63,23 @@ const selectedArr = ref([
   { name: '11', id: 3 },
 ])
 
+const setCountdown = ()=>{
+  interval.value = setInterval(()=>{
+    countdown.value -=1
+  } , 1000);
+  if(countdown.value == 0){
+    clearInterval(interval)
+    goBcak()
+  }
+}
+
+watch(countdown, (newVal, oldVal)=>{
+  if(newVal <= 0){
+    clearInterval(interval.value)
+    goBcak()
+  }
+})
+
 const classList = computed(() => {
   let activeGrade = totalList.value.find(item => item.active == true)
   return activeGrade ? activeGrade.class : null
@@ -83,46 +102,63 @@ const curSelected = computed(() => {
     let activeClass = classList.value.find(item => item.active == true)
     if (activeClass) {
       arr.push(activeClass)
-      let activeStudent = studentList.value.find(item => item.active == true)
-      if (activeStudent) arr.push(activeStudent)
+      if(studentList.value && studentList.value.length > 0){
+        let activeStudent = studentList.value.find(item => item.active == true)
+        if (activeStudent) arr.push(activeStudent)
+      }
     }
   }
   return arr
 })
 
-const getGradeList = () => {
-  totalList.value = [
-    { name: '一年级', id: 1 },
-    { name: '二年级', id: 2 },
-    { name: '二年级', id: 3 },
-    { name: '二年级', id: 4 },
-    { name: '二年级', id: 5 },
-    { name: '二年级', id: 6 },
-    { name: '二年级', id: 7 },
-  ]
-}
-
-const getClassList = () => {
-  totalList.value.find(item => item.active == true).class = [
-    { name: '一班', id: 1 },
-    { name: '二班', id: 3 },
-    { name: '三班', id: 4 },
-    { name: '四班', id: 5 },
-    { name: '五班', id: 6 },
-    { name: '六班', id: 7 },
-  ]
-}
-
-const getStudent = () => {
-  totalList.value.find(item => item.active == true).class
-    .find(item => item.active == true).student = [
-      { name: '11', id: 1 },
-      { name: '22', id: 3 },
-      { name: '33', id: 4 },
-      { name: '44', id: 5 },
-      { name: '55', id: 6 },
-      { name: '66', id: 7 },
-    ]
+const getGradeList = async () => {
+  const res = await getTaskClassList()
+  const list = []
+  if(res.code == 1){
+    res.data.grades.forEach(el => {
+      if (!list.some(e => e.id == el.id)) {
+        list.push(el);
+      }
+    });
+  }
+  totalList.value = list
+
+  const classList = []
+  for(let item of res.data.list){
+    for(let task of item.task){
+      classList.push({
+        ...item,
+        ...task,
+        name: item.class_name
+      })
+    }
+  }
+
+  for(let gradeItem of totalList.value){
+
+    let arr = []
+    for(let classItem of classList){
+      if(gradeItem.id == classItem.grade){
+        arr.push(classItem)
+      }
+    }
+    if(arr.length > 0)gradeItem.class = arr
+  }
+}
+
+const getStudent = async (item) => {
+  const res = await getTaskStudentList({
+    task_id: item.task_id
+  })
+  if(res.code == 1){
+    let list = res.data.list.map(i=>{
+      return {...i,name: i.jname}
+    })
+    totalList.value.find(item => item.active == true).class
+    .find(item => item.active == true).student = list
+  }
+
+  
 }
 
 const changeTab = (item) => {
@@ -133,7 +169,9 @@ const changeGrade = (item) => {
   activeTab.value = 'class'
   for (let i of totalList.value) { i.active = false }
   item.active = true
-  getClassList()
+  let classList = totalList.value.find(i => i.active == true).class
+  for (let i of classList) { i.active = false }
+  // getClassList()
 }
 
 const changeClass = (item) => {
@@ -141,7 +179,7 @@ const changeClass = (item) => {
   let classList = totalList.value.find(i => i.active == true).class
   for (let i of classList) { i.active = false }
   item.active = true
-  getStudent()
+  getStudent(item)
 }
 
 const changeStudent = (item) => {
@@ -160,7 +198,8 @@ const goBcak = () => {
 const navToTest = () => {
   if (curSelected.value.length == 3) {
     navTo('pages/test/bmi', {
-
+      student_id: curSelected.value[2].id,
+      task_id: curSelected.value[1].task_id,
     })
   }
 }
@@ -168,10 +207,14 @@ const navToTest = () => {
 
 onLoad(() => {
   getGradeList()
+  setCountdown()
 })
 
-// 挂载完成之后
-onMounted(() => {
+onHide(()=>{
+  clearInterval(interval.value)
+})
+onUnload(()=>{
+  clearInterval(interval.value)
 })
 </script>
 
@@ -280,7 +323,7 @@ onMounted(() => {
   display: flex;
   justify-content: center;
   text-align: center;
-  height: 110upx;
+  height: 10vh;
   line-height: 110upx;
   font-weight: bold;
   font-size: 28rpx;
@@ -319,9 +362,11 @@ onMounted(() => {
 }
 
 .select-info {
-  padding: 20upx;
+  padding: 20upx 10upx 20upx 20upx;
   display: flex;
   flex-wrap: wrap;
+  height: 40vh;
+  overflow: auto;
 }
 
 .info-item {

+ 45 - 6
pages/index/init.vue

@@ -20,7 +20,7 @@
         <view v-if="curStep == 1" class="flow-step-item flow-step-item1">1</view>
         <image v-else :src="`${imgUrl}/start_icon_done_blue.png`" />
         <view class="flow-step-point" :class="curStep > 1 ? 'flow-step-point-active1' : ''">········</view>
-        <view v-if="curStep == 1" class="flow-step-item">2</view>
+        <view v-if="curStep <= 1" class="flow-step-item">2</view>
         <view v-else-if="curStep == 2" class="flow-step-item flow-step-item2">2</view>
         <image v-else :src="`${imgUrl}/start_icon_done_green.png`" />
         <view class="flow-step-point" :class="curStep > 2 ? 'flow-step-point-active2' : ''">········</view>
@@ -34,7 +34,7 @@
         <image :src="`${imgUrl}/start_img_default.png`" />
         <view class="tips-box">
           <view class="tips">暂无网络连接,请重试</view>
-          <view class="btn btn-primary" @click="toSelect">重新检测</view>
+          <view class="btn btn-primary" @click="initNetwork">重新检测</view>
         </view>
       </view>
       <view v-else-if="curStep == 2" class="step2-box">
@@ -43,7 +43,7 @@
         <uv-input placeholder="请输入密码" border="surround" fontSize="28upx" v-model="loginForm.pwd" password="true"
           class="step2-input"></uv-input>
         <view style="display: flex;">
-          <view class="btn btn-green" @click="toSelect">登录</view>
+          <view class="btn btn-green" @click="handleLogin">登录</view>
         </view>
       </view>
       <view v-else class="step3-box">
@@ -59,16 +59,23 @@
 <script setup>
 import { onActivated, onMounted, reactive, ref } from "vue";
 import { navTo, showToast } from "@/utils/app";
+import {useUserStore} from "@/store/useUserStore";
+import {logs, sleep} from "@/utils/util";
+import { onLoad } from '@dcloudio/uni-app';
+
+const userStore = useUserStore()
 
 const imgUrl = ref('/static/image/bmi-init')
-const curStep = ref(1)
+const curStep = ref(0)
 const loginForm = ref({
   mac: '',
   pwd: ''
 })
+const networkType = ref({})
 
 const changeStep = () => {
   curStep.value += 1
+  
   if(curStep.value == 5){
     navTo('pages/index/index', {
 
@@ -76,8 +83,40 @@ const changeStep = () => {
   }
 }
 
-// 挂载完成之后
-onMounted(() => {
+const initNetwork = () =>{
+  uni.getNetworkType({
+    success: async (res) => {
+      networkType.value = res.networkType
+      if (res.networkType == 'none') {
+        showToast('无网络连接')
+        curStep.value = 1
+      } else {
+        await sleep(1100)
+        curStep.value = 2
+      }
+    }
+  })
+}
+
+const handleLogin = async () =>{
+  if(loginForm.value.mac == ''){
+    return showToast('请输入设备码')
+  }
+  if(loginForm.value.pwd == ''){
+    return showToast('请输入密码')
+  }
+  userStore.login(loginForm.value).then(async (data)=>{
+    curStep.value += 1
+    await sleep(1000)
+    curStep.value += 1
+    await sleep(1000)
+    navTo('pages/index/index', {})
+  }).catch(()=>{
+  })
+}
+
+onLoad(() => {
+  initNetwork()
 })
 </script>
 

+ 24 - 12
pages/test/bmi.vue

@@ -5,31 +5,31 @@
             <view class="student-card">
                 <view class="student-box1">
                     <image class="head-img"
-                        :src="student_info.sex == 1 ? '/static/image/bmi/test_img_head_boy.png' : '/static/image/bmi/test_img_head_gril.png'">
+                        :src="student_info.gender == 1 ? '/static/image/bmi/test_img_head_boy.png' : '/static/image/bmi/test_img_head_gril.png'">
                     </image>
                     <view class="student-info1">
                         <view class="student-info11">
                             <view class="student-info111">
-                                <view>{{ student_info.name }}</view>
+                                <view>{{ student_info.student_name }}</view>
                                 <image class="sex-img"
-                                    :src="student_info.sex == 1 ? '/static/image/bmi/test_icon_boy.png' : '/static/image/bmi/test_icon_gril.png'">
+                                    :src="student_info.gender == 1 ? '/static/image/bmi/test_icon_boy.png' : '/static/image/bmi/test_icon_gril.png'">
                                 </image>
                             </view>
-                            <view class="student-num">编号:{{ student_info.number }}</view>
+                            <!-- <view class="student-num">编号:{{ student_info.number }}</view> -->
                         </view>
-                        <view class="student-info12">{{ student_info.class }}</view>
+                        <view class="student-info12">{{ student_info.class_name }}</view>
                     </view>
                 </view>
                 <view class="student-info2">
                     <view>
                         <image src="/static/image/bmi/test_icon_id.png">
                         </image>
-                        <text>11122221</text>
+                        <text>{{ machine_num ? machine_num : '手动选择' }}</text>
                     </view>
                     <view>
                         <image src="/static/image/bmi/test_icon_school.png">
                         </image>
-                        <text>石岐小学</text>
+                        <text>{{student_info.school_name}}</text>
                     </view>
                 </view>
             </view>
@@ -76,13 +76,17 @@
 <script setup>
 import { onActivated, onMounted, reactive, ref } from "vue";
 import { navTo, showToast } from "@/utils/app";
+import { addStudentTaskData, getStudentTaskDetail } from "@/api/student";
+import { onLoad } from '@dcloudio/uni-app';
 
 const isFinish = ref(false)
+const machine_num = ref('')
 const student_info = ref({
-    name: '张珊珊',
-    sex: 2,
+    student_name: '张珊珊',
+    gender: 2,
     number: 123456,
-    class: '一年三班'
+    class_name: '一年三班',
+    school_name: '开睿学校'
 })
 
 const goBcak = () => {
@@ -91,8 +95,16 @@ const goBcak = () => {
     })
 }
 
-// 挂载完成之后
-onMounted(() => {
+const getDetail = async( query)=>{
+     const res = await getStudentTaskDetail(query)
+     if(res.code == 1){
+        student_info.value = res.data.detail
+     }
+}
+
+onLoad((query) => {
+    console.log(query)
+  getDetail(query)
 })
 </script>
 

+ 28 - 4
store/useUserStore.js

@@ -1,12 +1,14 @@
 import {defineStore} from "pinia";
 import storage from "@/utils/storage";
 import {useConfigStore} from "@/store/useConfigStore";
-
+import {login} from "@/api/student";
+import { showToast } from "@/utils/app";
 
 export const useUserStore = defineStore({
   id: 'user',
   state: () => ({
     token: null,
+    userInfo: {}
   }),
   getters: {},
   actions: {
@@ -19,14 +21,36 @@ export const useUserStore = defineStore({
         this.token = token
       }
     },
-    login() {
+    async login(loginForm) {
       const configStore = useConfigStore()
-      let mac = configStore.getMac()
-      console.log('login mac', mac)
+      // let mac = configStore.getMac()
+      return new Promise(async (resolve, reject) => {
+        const res = await login({
+          username: loginForm.mac,
+          password: loginForm.pwd,
+        })
+        if(res.code == 1 && res.data.token){
+          this.setToken(res.data)
+          resolve(res.data)
+        }
+        else{
+          showToast(res.msg)
+          reject(res.msg)
+        }
+      })
     },
     logout() {
       this.token = null
+      this.userInfo = {}
+      storage.remove("LOGIN_TEACHER_TOKEN")
+      storage.remove("userInfo")
     },
+    setToken(data){
+      this.token = data.token
+      this.userInfo = data.info
+      storage.setKey('LOGIN_TEACHER_TOKEN', data.token)
+      storage.setKey('userInfo', data.info)
+    }
     // getMachineInfo() {
     //   this.mac = '123'
     // },