Browse Source

build: :zap: 代码优化

chaooo 2 years ago
parent
commit
f3c0374b04

+ 1 - 1
.prettierrc.cjs

@@ -4,7 +4,7 @@ module.exports = {
   // 开始标签的右尖括号是否跟随在最后一行属性末尾,默认false
   bracketSameLine: true,
   // 对象字面量的括号之间打印空格 (true - Example: { foo: bar } ; false - Example: {foo:bar})
-  bracketSpacing: true,
+  bracketSpacing: false,
   // 是否格式化一些文件中被嵌入的代码片段的风格(auto|off;默认auto)
   embeddedLanguageFormatting: "auto",
   // 指定 HTML 文件的空格敏感度 (css|strict|ignore;默认css)

+ 3 - 3
src/App.vue

@@ -1,11 +1,11 @@
 <script setup lang="ts">
-import { ElConfigProvider } from "element-plus";
-import { useAppStore } from "@/store/modules/app";
+import {ElConfigProvider} from "element-plus";
+import {useAppStore} from "@/store/modules/app";
 const appStore = useAppStore();
 </script>
 
 <template>
-  <el-config-provider :locale="appStore.locale" :size="appStore.size">
+  <el-config-provider :locale="appStore.locale">
     <router-view />
   </el-config-provider>
 </template>

+ 8 - 7
src/api/areaboard/index.ts

@@ -1,16 +1,17 @@
 import request from "@/utils/request";
-import { AxiosPromise } from "axios";
-import { AddressId, Area, AreaCard, AreaLineData, AreaParams } from "@/api/areaboard/types";
-import { DashboardData } from "@/api/dashboard/types";
+import {AxiosPromise} from "axios";
+import {AddressId, Area, AreaCard, AreaLineData, AreaParams} from "@/api/areaboard/types";
+import {DashboardData} from "@/api/dashboard/types";
+import {SchoolList} from "@/api/school/types";
 
 /**
  * 获取区域
  */
-export function getAreaAddress(id: number): AxiosPromise<Area> {
+export function getAreaAddress(id: number): AxiosPromise<Area[]> {
   return request({
     url: "/board/v1/area",
     method: "get",
-    params: { parent_id: id },
+    params: {parent_id: id},
   });
 }
 
@@ -18,11 +19,11 @@ export function getAreaAddress(id: number): AxiosPromise<Area> {
  * 获取学校
  * /board/v1/get-school?province_id=&city_id=
  */
-export function getAreaSchool(province_id: number, city_id: number): AxiosPromise<Area> {
+export function getAreaSchool(province_id: number, city_id: number): AxiosPromise<SchoolList[]> {
   return request({
     url: "/board/v1/get-school",
     method: "get",
-    params: { province_id: province_id, city_id: city_id },
+    params: {province_id: province_id, city_id: city_id},
   });
 }
 

+ 8 - 8
src/api/teacher/index.ts

@@ -1,7 +1,7 @@
 import request from "@/utils/request";
-import { AxiosPromise } from "axios";
-import { GradeList } from "@/api/grade/types";
-import { TeacherEquipment, TeacherList, TeacherManage } from "@/api/teacher/types";
+import {AxiosPromise} from "axios";
+import {GradeList} from "@/api/grade/types";
+import {TeacherEquipment, TeacherList, TeacherManage} from "@/api/teacher/types";
 /**
  * 获取教师管理列表
  */
@@ -9,17 +9,17 @@ export function getTeacherManage(id: number, keyword: string): AxiosPromise<Teac
   return request({
     url: "/board/v1/teacher",
     method: "get",
-    params: { school_id: id, search: keyword },
+    params: {school_id: id, search: keyword},
   });
 }
 /**
  * 获取教师下拉框列表
  */
-export function getTeacherList(id: number): AxiosPromise<TeacherList[]> {
+export function getTeacherList(id: number): AxiosPromise<TeacherManage> {
   return request({
     url: "/board/v1/teacher",
     method: "get",
-    params: { school_id: id },
+    params: {school_id: id},
   });
 }
 
@@ -30,7 +30,7 @@ export function getTeacherEquipment(id: number): AxiosPromise<TeacherEquipment>
   return request({
     url: "/board/v1/teacher-equipment",
     method: "get",
-    params: { teacher_id: id },
+    params: {teacher_id: id},
   });
 }
 
@@ -41,6 +41,6 @@ export function getTeacherGrade(id: number): AxiosPromise<GradeList[]> {
   return request({
     url: "/board/v1/teacher-class",
     method: "get",
-    params: { teacher_id: id },
+    params: {teacher_id: id},
   });
 }

+ 2 - 2
src/components/Charts/CurveLineChart.vue

@@ -1,6 +1,6 @@
 <!-- 圆饼图 -->
 <template>
-  <div :id="id" :class="className" :style="{ height, width }" />
+  <div :id="id" :class="className" :style="{height, width}" />
 </template>
 
 <script setup lang="ts">
@@ -47,7 +47,7 @@ const options = {
   xAxis: {
     type: "category",
     axisLabel: {
-      formatter: function (value, index) {
+      formatter: function (value: number, index: number) {
         return Math.ceil(index / 60) + "分钟";
       },
       interval: (index: number, value: string) => {

+ 2 - 2
src/components/Charts/LineChart.vue

@@ -1,6 +1,6 @@
 <!-- 圆饼图 -->
 <template>
-  <div :id="id" :class="className" :style="{ height, width }" />
+  <div :id="id" :class="className" :style="{height, width}" />
 </template>
 
 <script setup lang="ts">
@@ -50,7 +50,7 @@ const options = {
     boundaryGap: true,
     axisLabel: {
       color: "#09132e",
-      interval: (value, index) => {
+      interval: (value: number, index: number) => {
         return index % 4 == 0;
       },
     },

+ 6 - 6
src/layout/components/Sidebar/SidebarItem.vue

@@ -1,10 +1,10 @@
 <script setup lang="ts">
-import { useRouter } from "vue-router";
+import {useRouter} from "vue-router";
 import path from "path-browserify";
-import { isExternal } from "@/utils";
+import {isExternal} from "@/utils";
 import AppLink from "./Link.vue";
 import SvgIcon from "@/components/SvgIcon/index.vue";
-import { SidebarRoutes } from "@/layout/components/Sidebar/types";
+import {SidebarRoutes} from "@/layout/components/Sidebar/types";
 
 const router = useRouter();
 const props = defineProps({
@@ -23,7 +23,7 @@ const props = defineProps({
     required: true,
   },
 });
-const itemRoute: SidebarRoutes = reactive(props.item);
+const itemRoute: SidebarRoutes = reactive<SidebarRoutes>(props.item);
 const onlyOneChild = ref(); // 临时变量,唯一子路由
 /**
  * 判断当前路由是否只有一个子路由
@@ -46,7 +46,7 @@ function hasOneShowingChild(children: any = [], parent: any) {
   });
   // 1:如果无显示的子路由, 复制当前路由信息作为其子路由,满足只拥有一个子路由的条件,所以返回 true
   if (showingChildren.length === 0) {
-    onlyOneChild.value = { ...parent, path: "", noShowingChildren: true };
+    onlyOneChild.value = {...parent, path: "", noShowingChildren: true};
     return true;
   }
   // 2:如果只有一个显示的子路由, 判断子路由children
@@ -85,7 +85,7 @@ function resolvePath(routePath: string): string {
 function addActiveClass(routePath: string) {
   const currentBase: string = routePath.split("/")[1];
   document.querySelectorAll(".el-menu-item").forEach((item) => {
-    const pathBase: string = item.attributes.getNamedItem("mark").value.split("/")[1];
+    const pathBase: string = item.attributes.getNamedItem("mark")?.value.split("/")[1];
     if (currentBase == pathBase) {
       const active = document.querySelectorAll(".el-menu-item.is-active");
       if (active && active.length) {

+ 7 - 9
src/store/modules/user.ts

@@ -1,11 +1,9 @@
-import { defineStore } from "pinia";
-import { loginApi, logoutApi } from "@/api/auth";
-import { resetRouter } from "@/router";
-import { store } from "@/store";
-import { useStorage } from "@vueuse/core";
-import { LoginData, LoginResult } from "@/api/auth/types";
-import { useRouter } from "vue-router";
-const router = useRouter();
+import {defineStore} from "pinia";
+import {loginApi, logoutApi} from "@/api/auth";
+import {resetRouter} from "@/router";
+import {store} from "@/store";
+import {useStorage} from "@vueuse/core";
+import {LoginData, LoginResult} from "@/api/auth/types";
 
 export const useUserStore = defineStore("user", () => {
   // state
@@ -23,7 +21,7 @@ export const useUserStore = defineStore("user", () => {
   function login(loginData: LoginData) {
     return new Promise<void>((resolve, reject) => {
       loginApi(loginData)
-        .then(({ data }) => {
+        .then(({data}) => {
           userInfo.value = JSON.stringify(data);
           setUserData(data);
           resolve();

+ 25 - 29
src/views/areaboard/index.vue

@@ -1,16 +1,16 @@
 <script setup lang="ts">
-import { DashboardData } from "@/api/dashboard/types";
-import { AddressId, Area, AreaCard, AreaLineData, AreaParams } from "@/api/areaboard/types";
+import {DashboardData} from "@/api/dashboard/types";
+import {Area, AreaCard, AreaLineData, AreaParams} from "@/api/areaboard/types";
 import AreaDataCard from "@/views/areaboard/components/AreaDataCard.vue";
 import LiquidChart from "@/components/Charts/LiquidChart.vue";
 import PercentBarChart from "@/components/Charts/PercentBarChart.vue";
 import CircleChart from "@/components/Charts/CircleChart.vue";
 import LineChart from "@/components/Charts/LineChart.vue";
 import AverageBarChart from "@/components/Charts/AverageBarChart.vue";
-import { GradeList } from "@/api/grade/types";
-import { getGradeSelect } from "@/api/grade";
-import { getAreaAddress, getAreaBoardLines, getAreaBoardPies, getAreaCard, getAreaSchool } from "@/api/areaboard";
-import { SchoolList } from "@/api/school/types";
+import {GradeList} from "@/api/grade/types";
+import {getGradeSelect} from "@/api/grade";
+import {getAreaAddress, getAreaBoardLines, getAreaBoardPies, getAreaCard, getAreaSchool} from "@/api/areaboard";
+import {SchoolList} from "@/api/school/types";
 
 defineOptions({
   name: "DashboardArea",
@@ -19,10 +19,6 @@ defineOptions({
 /**
  * 筛选条件
  */
-const address: AddressId = reactive({
-  province_id: 0,
-  city_id: 0,
-});
 const dataParams: AreaParams = reactive({
   province_id: 0,
   city_id: 0,
@@ -36,13 +32,13 @@ const provinceData = ref<Area[]>();
 const cityData = ref<Area[]>();
 async function getAddressData(id: number) {
   getAreaAddress(id)
-    .then(({ data }) => {
+    .then(({data}) => {
       if (id == 0) {
         provinceData.value = data;
-        provinceData.value?.unshift({ area_id: 0, area_name: "全部省" });
+        provinceData.value?.unshift({area_id: 0, area_name: "全部省"});
       } else {
         cityData.value = data;
-        cityData.value?.unshift({ area_id: 0, area_name: "全部市" });
+        cityData.value?.unshift({area_id: 0, area_name: "全部市"});
       }
       // 重新获取学校
       getSchoolData(dataParams);
@@ -50,9 +46,9 @@ async function getAddressData(id: number) {
     .catch((error) => {
       console.log(error);
       if (id == 0) {
-        provinceData.value = [{ area_id: 0, area_name: "全部省" }];
+        provinceData.value = [{area_id: 0, area_name: "全部省"}];
       } else {
-        cityData.value = [{ area_id: 0, area_name: "全部市" }];
+        cityData.value = [{area_id: 0, area_name: "全部市"}];
       }
     });
 }
@@ -63,13 +59,13 @@ async function getAddressData(id: number) {
 const schoolData = ref<SchoolList[]>();
 async function getSchoolData(params: AreaParams) {
   getAreaSchool(params.province_id, params.city_id)
-    .then(({ data }) => {
+    .then(({data}) => {
       schoolData.value = data;
-      schoolData.value?.unshift({ num: "", school_id: 0, name: "全部学校" });
+      schoolData.value?.unshift({num: "", school_id: 0, name: "全部学校"});
     })
     .catch((error) => {
       schoolData.value = [];
-      schoolData.value?.unshift({ num: "", school_id: 0, name: "全部学校" });
+      schoolData.value?.unshift({num: "", school_id: 0, name: "全部学校"});
       console.log(error);
     });
 }
@@ -79,13 +75,13 @@ async function getSchoolData(params: AreaParams) {
 const gradeData = ref<GradeList[]>();
 async function getGradeData(schoolId: number) {
   getGradeSelect(schoolId)
-    .then(({ data }) => {
+    .then(({data}) => {
       gradeData.value = data;
-      gradeData.value?.unshift({ id: 0, name: "全部班级" });
+      gradeData.value?.unshift({id: 0, name: "全部班级"});
     })
     .catch((error) => {
       gradeData.value = [];
-      gradeData.value?.unshift({ id: 0, name: "全部班级" });
+      gradeData.value?.unshift({id: 0, name: "全部班级"});
       console.log(error);
     });
 }
@@ -101,7 +97,7 @@ const cardStatus = ref(false);
 const cards = ref<AreaCard>();
 async function getDataCard(params: AreaParams) {
   getAreaCard(params)
-    .then(({ data }) => {
+    .then(({data}) => {
       cards.value = data;
       cardStatus.value = true;
     })
@@ -118,7 +114,7 @@ const pieChartData = ref<DashboardData>();
 async function getPieChartData(params: AreaParams) {
   pieStatus.value = false;
   getAreaBoardPies(params)
-    .then(({ data }) => {
+    .then(({data}) => {
       pieChartData.value = data;
       pieStatus.value = true;
     })
@@ -138,7 +134,7 @@ const averageData = ref<number[][]>();
 async function getLineChartData(params: AreaParams) {
   lineStatus.value = false;
   getAreaBoardLines(params)
-    .then(({ data }) => {
+    .then(({data}) => {
       lineChartData.value = data;
       // 柱状图
       averageData.value = [];
@@ -166,10 +162,10 @@ function getPageData() {
 onMounted(() => {
   // 获取省份
   getAddressData(0);
-  cityData.value = [{ area_id: 0, area_name: "全部市" }];
+  cityData.value = [{area_id: 0, area_name: "全部市"}];
   // 获取学校
   getSchoolData(dataParams);
-  gradeData.value = [{ id: 0, name: "全部班级" }];
+  gradeData.value = [{id: 0, name: "全部班级"}];
   // 获取页面数据
   getPageData();
 });
@@ -206,7 +202,7 @@ onMounted(() => {
         <!-- 数据卡片 -->
         <template v-if="cardStatus">
           <AreaDataCard
-            :key="cards.toString()"
+            :key="cards?.toString()"
             :schools="cards?.school || 0"
             :games="cards?.game || 0"
             :students="cards?.student || 0" />
@@ -331,8 +327,8 @@ onMounted(() => {
             <template v-if="lineStatus">
               <AverageBarChart
                 id="averageBarChart1"
-                :key="averageData.toString()"
-                :data-sets="averageData"
+                :key="averageData?.toString()"
+                :data-sets="averageData || [[], []]"
                 width="520px"
                 height="520px"
                 class="chart" />

+ 12 - 20
src/views/dashboard/index.vue

@@ -3,13 +3,13 @@ import DataCard from "@/views/dashboard/components/DataCard.vue";
 import LiquidChart from "@/components/Charts/LiquidChart.vue";
 import CircleChart from "@/components/Charts/CircleChart.vue";
 import PercentBarChart from "@/components/Charts/PercentBarChart.vue";
-import { watch } from "vue";
-import { useUserStore } from "@/store/modules/user";
+import {watch} from "vue";
+import {useUserStore} from "@/store/modules/user";
 
-import { getDashboardData, getDashboardTop } from "@/api/dashboard";
-import { DashboardCard, DashboardData } from "@/api/dashboard/types";
-import { getGradeSelect } from "@/api/grade";
-import { GradeList } from "@/api/grade/types";
+import {getDashboardData, getDashboardTop} from "@/api/dashboard";
+import {DashboardCard, DashboardData} from "@/api/dashboard/types";
+import {getGradeSelect} from "@/api/grade";
+import {GradeList} from "@/api/grade/types";
 
 const userStore = useUserStore();
 defineOptions({
@@ -23,7 +23,7 @@ const cardStatus = ref(false);
 const cards = ref<DashboardCard>();
 async function getDataCard(schoolId: number) {
   getDashboardTop(schoolId)
-    .then(({ data }) => {
+    .then(({data}) => {
       cards.value = data;
       cardStatus.value = true;
     })
@@ -39,13 +39,13 @@ const gradeData = ref<GradeList[]>();
 let gradeId = ref(0);
 async function getGradeData(schoolId: number) {
   getGradeSelect(schoolId)
-    .then(({ data }) => {
+    .then(({data}) => {
       gradeData.value = data;
-      gradeData.value?.unshift({ id: 0, name: "全部班级" });
+      gradeData.value?.unshift({id: 0, name: "全部班级"});
     })
     .catch((error) => {
       gradeData.value = [];
-      gradeData.value?.unshift({ id: 0, name: "全部班级" });
+      gradeData.value?.unshift({id: 0, name: "全部班级"});
       console.log(error);
     });
 }
@@ -55,18 +55,10 @@ async function getGradeData(schoolId: number) {
 const chartStatus = ref(false);
 const chartMessage = ref("加载中...");
 const chartData = ref<DashboardData>();
-// let chartData: DashboardData = reactive({
-//   frontAverage: 0, // 初期专注力估值
-//   afterAverage: 0, // 近期专注力估值
-//   front: 0, // 初期50分以上的占比
-//   after: 0, // 近期50分以上的占比
-//   frontProportion: { num: [], percentage: [] }, // 初期分期占比分析
-//   afterProportion: { num: [], percentage: [] }, // 近期分期占比分析
-// });
 async function getChartData(schoolId: number, gradeId: number) {
   chartStatus.value = false;
   getDashboardData(schoolId, gradeId)
-    .then(({ data }) => {
+    .then(({data}) => {
       chartData.value = data;
       chartStatus.value = true;
     })
@@ -109,7 +101,7 @@ watch(
     <!-- 数据卡片 -->
     <template v-if="cardStatus">
       <DataCard
-        :key="cards.toString()"
+        :key="cards?.toString()"
         :classes="cards?.grade || 0"
         :teachers="cards?.teacher || 0"
         :students="cards?.student || 0"

+ 40 - 36
src/views/equipment/index.vue

@@ -1,10 +1,10 @@
 <script setup lang="ts">
-import { watch } from "vue";
-import { useUserStore } from "@/store/modules/user";
-import { TeacherList, TeacherManage } from "@/api/teacher/types";
-import { getTeacherList } from "@/api/teacher";
-import { EquipmentManage, EquipmentParams } from "@/api/equipment/types";
-import { getEquipmentLists } from "@/api/equipment";
+import {watch} from "vue";
+import {useUserStore} from "@/store/modules/user";
+import {TeacherList, TeacherManage} from "@/api/teacher/types";
+import {getTeacherList} from "@/api/teacher";
+import {EquipmentManage, EquipmentParams} from "@/api/equipment/types";
+import {getEquipmentLists} from "@/api/equipment";
 const userStore = useUserStore();
 defineOptions({
   name: "EquipmentIndex",
@@ -15,10 +15,10 @@ defineOptions({
 const teacherSelect = ref<TeacherList[]>();
 async function getTeacherData(schoolId: number) {
   getTeacherList(schoolId)
-    .then(({ data }) => {
+    .then(({data}) => {
       const temp: TeacherManage = data;
       teacherSelect.value = temp.lists;
-      teacherSelect.value?.unshift({ id: 0, name: "全部教师" });
+      teacherSelect.value?.unshift({id: 0, name: "全部教师"});
     })
     .catch((error) => {
       console.log(error);
@@ -26,8 +26,12 @@ async function getTeacherData(schoolId: number) {
 }
 
 // 获取设备
-const pageParams: EquipmentParams = reactive({});
-let equipmentData: EquipmentManage = reactive({});
+const pageParams: EquipmentParams = reactive({
+  school_id: userStore.schoolId,
+  teacher_id: 0,
+  sn: "",
+});
+const equipmentData = ref<EquipmentManage>();
 const equipmentStatus = ref(false);
 const dataStatus = reactive({
   AI: false,
@@ -44,16 +48,16 @@ const dataMessage = ref("加载中...");
 async function getEquipmentData(schoolId: number) {
   pageParams.school_id = schoolId;
   getEquipmentLists(pageParams)
-    .then(({ data }) => {
-      equipmentData = <EquipmentManage>{ ...data };
-      dataStatus.AI = equipmentData?.AI.length > 0 || false;
-      dataStatus.SW = equipmentData?.SW.length > 0 || false;
-      dataStatus.KL = equipmentData?.KL.length > 0 || false;
-      dataStatus.PP = equipmentData?.PP.length > 0 || false;
-      dataStatus.SU = equipmentData?.SU.length > 0 || false;
-      dataStatus.SC = equipmentData?.SC.length > 0 || false;
-      dataStatus.UF = equipmentData?.UF.length > 0 || false;
-      dataStatus.JM = equipmentData?.JM.length > 0 || false;
+    .then(({data}) => {
+      equipmentData.value = data;
+      dataStatus.AI = equipmentData.value?.AI.length > 0 || false;
+      dataStatus.SW = equipmentData.value?.SW.length > 0 || false;
+      dataStatus.KL = equipmentData.value?.KL.length > 0 || false;
+      dataStatus.PP = equipmentData.value?.PP.length > 0 || false;
+      dataStatus.SU = equipmentData.value?.SU.length > 0 || false;
+      dataStatus.SC = equipmentData.value?.SC.length > 0 || false;
+      dataStatus.UF = equipmentData.value?.UF.length > 0 || false;
+      dataStatus.JM = equipmentData.value?.JM.length > 0 || false;
       equipmentStatus.value =
         dataStatus.AI ||
         dataStatus.SW ||
@@ -107,11 +111,11 @@ watch(
     <template v-if="equipmentStatus">
       <div v-if="dataStatus.AI" class="equipment-box">
         <div class="title">
-          <span>水母星球脑机</span><b>{{ equipmentData.AI.length }}</b
+          <span>水母星球脑机</span><b>{{ equipmentData?.AI.length }}</b
           >台
         </div>
         <el-row :gutter="15">
-          <template v-for="item in equipmentData.AI" :key="item.sn">
+          <template v-for="item in equipmentData?.AI" :key="item.sn">
             <el-col :xs="12" :span="6">
               <div class="box-card">
                 <el-row>
@@ -136,11 +140,11 @@ watch(
       </div>
       <div v-if="dataStatus.SW" class="equipment-box">
         <div class="title">
-          <span>智脑水舞</span><b>{{ equipmentData.SW.length }}</b
+          <span>智脑水舞</span><b>{{ equipmentData?.SW.length }}</b
           >台
         </div>
         <el-row :gutter="15">
-          <template v-for="item in equipmentData.SW" :key="item.sn">
+          <template v-for="item in equipmentData?.SW" :key="item.sn">
             <el-col :xs="12" :span="6">
               <div class="box-card">
                 <el-row>
@@ -165,11 +169,11 @@ watch(
       </div>
       <div v-if="dataStatus.KL" class="equipment-box">
         <div class="title">
-          <span>智脑恐龙</span><b>{{ equipmentData.KL.length }}</b
+          <span>智脑恐龙</span><b>{{ equipmentData?.KL.length }}</b
           >台
         </div>
         <el-row :gutter="15">
-          <template v-for="item in equipmentData.KL" :key="item.sn">
+          <template v-for="item in equipmentData?.KL" :key="item.sn">
             <el-col :xs="12" :span="6">
               <div class="box-card">
                 <el-row>
@@ -194,11 +198,11 @@ watch(
       </div>
       <div v-if="dataStatus.PP" class="equipment-box">
         <div class="title">
-          <span>智脑碰碰车</span><b>{{ equipmentData.PP.length }}</b
+          <span>智脑碰碰车</span><b>{{ equipmentData?.PP.length }}</b
           >台
         </div>
         <el-row :gutter="15">
-          <template v-for="item in equipmentData.PP" :key="item.sn">
+          <template v-for="item in equipmentData?.PP" :key="item.sn">
             <el-col :xs="12" :span="6">
               <div class="box-card">
                 <el-row>
@@ -223,11 +227,11 @@ watch(
       </div>
       <div v-if="dataStatus.SU" class="equipment-box">
         <div class="title">
-          <span>智脑SUV</span><b>{{ equipmentData.SU.length }}</b
+          <span>智脑SUV</span><b>{{ equipmentData?.SU.length }}</b
           >台
         </div>
         <el-row :gutter="15">
-          <template v-for="item in equipmentData.SU" :key="item.sn">
+          <template v-for="item in equipmentData?.SU" :key="item.sn">
             <el-col :xs="12" :span="6">
               <div class="box-card">
                 <el-row>
@@ -252,11 +256,11 @@ watch(
       </div>
       <div v-if="dataStatus.SC" class="equipment-box">
         <div class="title">
-          <span>智脑赛车</span><b>{{ equipmentData.SC.length }}</b
+          <span>智脑赛车</span><b>{{ equipmentData?.SC.length }}</b
           >台
         </div>
         <el-row :gutter="15">
-          <template v-for="item in equipmentData.SC" :key="item.sn">
+          <template v-for="item in equipmentData?.SC" :key="item.sn">
             <el-col :xs="12" :span="6">
               <div class="box-card">
                 <el-row>
@@ -281,11 +285,11 @@ watch(
       </div>
       <div v-if="dataStatus.UF" class="equipment-box">
         <div class="title">
-          <span>智脑UFO</span><b>{{ equipmentData.UF.length }}</b
+          <span>智脑UFO</span><b>{{ equipmentData?.UF.length }}</b
           >台
         </div>
         <el-row :gutter="15">
-          <template v-for="item in equipmentData.UF" :key="item.sn">
+          <template v-for="item in equipmentData?.UF" :key="item.sn">
             <el-col :xs="12" :span="6">
               <div class="box-card">
                 <el-row>
@@ -310,11 +314,11 @@ watch(
       </div>
       <div v-if="dataStatus.JM" class="equipment-box">
         <div class="title">
-          <span>智脑积木</span><b>{{ equipmentData.JM.length }}</b
+          <span>智脑积木</span><b>{{ equipmentData?.JM.length }}</b
           >台
         </div>
         <el-row :gutter="15">
-          <template v-for="item in equipmentData.JM" :key="item.sn">
+          <template v-for="item in equipmentData?.JM" :key="item.sn">
             <el-col :xs="12" :span="6">
               <div class="box-card">
                 <el-row>

+ 8 - 8
src/views/login/index.vue

@@ -40,11 +40,11 @@ import router from "@/router";
 import SvgIcon from "@/components/SvgIcon/index.vue";
 
 // 状态管理依赖
-import { useUserStore } from "@/store/modules/user";
+import {useUserStore} from "@/store/modules/user";
 
 // API依赖
-import { LocationQuery, LocationQueryValue, useRoute } from "vue-router";
-import { LoginData } from "@/api/auth/types";
+import {LocationQuery, LocationQueryValue, useRoute} from "vue-router";
+import {LoginData} from "@/api/auth/types";
 
 const userStore = useUserStore();
 const route = useRoute();
@@ -65,13 +65,13 @@ const autoLogin = ref(true);
 const loginData = ref<LoginData>({
   // phone: "18770033942",
   // password: "123456",
-  phone: localStorage.getItem("autoName") ? atob(localStorage.getItem("autoName")) : "",
-  password: localStorage.getItem("autoPass") ? atob(localStorage.getItem("autoPass")) : "",
+  phone: atob(localStorage.getItem("autoName") || ""),
+  password: atob(localStorage.getItem("autoPass") || ""),
 });
 
 const loginRules = {
-  phone: [{ required: true, trigger: "blur", validator: usernameValidator }],
-  password: [{ required: true, trigger: "blur", validator: passwordValidator }],
+  phone: [{required: true, trigger: "blur", validator: usernameValidator}],
+  password: [{required: true, trigger: "blur", validator: passwordValidator}],
 };
 
 /**
@@ -119,7 +119,7 @@ function handleLogin() {
             }
             return acc;
           }, {});
-          router.push({ path: redirect, query: otherQueryParams });
+          router.push({path: redirect, query: otherQueryParams});
         })
         .catch((error) => {
           console.log("登录", error);

+ 9 - 9
src/views/student/download.vue

@@ -4,15 +4,15 @@ import RadarChart from "@/components/Charts/RadarChart.vue";
 import CircleChart from "@/components/Charts/CircleChart.vue";
 import DoubleChart from "@/components/Charts/DoubleChart.vue";
 import SvgIcon from "@/components/SvgIcon/index.vue";
-import { getUrlParam } from "@/utils";
+import {getUrlParam} from "@/utils";
 /**
  * pnpm install html2canvas --save
  * 导出页面内容为图片
  */
-import { ref } from "vue";
-import { useUserStore } from "@/store/modules/user";
-import { getStudentBoard } from "@/api/student";
-import { StudentBoard } from "@/api/student/types";
+import {ref} from "vue";
+import {useUserStore} from "@/store/modules/user";
+import {getStudentBoard} from "@/api/student";
+import {StudentBoard} from "@/api/student/types";
 import html2canvas from "html2canvas";
 
 const userStore = useUserStore();
@@ -30,8 +30,8 @@ async function getChartData(schoolId: number) {
   // 从url获取学生Id
   const studentId = Number(getUrlParam("id")) || 0;
   getStudentBoard(studentId, schoolId)
-    .then(({ data }) => {
-      chartData = <StudentBoard>{ ...data };
+    .then(({data}) => {
+      chartData = <StudentBoard>{...data};
       dataStatus.value = true;
       radarData = [chartData.after, chartData.front];
       setTimeout(() => {
@@ -83,8 +83,8 @@ const downloadHandle = (name: string) => {
   html2canvas(exportPage.value, {
     backgroundColor: "#f3f6fd", //海报的背景颜色
     useCORS: true, //允许跨域
-    width: document.querySelector(".result-container").offsetWidth, //生成海报的width,默认px
-    height: document.querySelector(".result-container").offsetHeight, //生成海报的height
+    width: document.querySelector(".result-container")?.offsetWidth, //生成海报的width,默认px
+    height: document.querySelector(".result-container")?.offsetHeight, //生成海报的height
   })
     .then((canvas) => {
       // canvas 其实就是返回报文,我们所讲的response的意思

+ 12 - 12
src/views/student/index.vue

@@ -1,10 +1,10 @@
 <script setup lang="ts">
-import { GradeList } from "@/api/grade/types";
-import { watch } from "vue";
-import { useUserStore } from "@/store/modules/user";
-import { getGradeSelect } from "@/api/grade";
-import { getStudentLists } from "@/api/student";
-import { StudentItem, StudentList, StudentParams } from "@/api/student/types";
+import {GradeList} from "@/api/grade/types";
+import {watch} from "vue";
+import {useUserStore} from "@/store/modules/user";
+import {getGradeSelect} from "@/api/grade";
+import {getStudentLists} from "@/api/student";
+import {StudentItem, StudentList, StudentParams} from "@/api/student/types";
 const userStore = useUserStore();
 defineOptions({
   name: "StudentIndex",
@@ -18,13 +18,13 @@ const gradeData = ref<GradeList[]>();
 let gradeId = ref(0);
 async function getGradeData(schoolId: number) {
   getGradeSelect(schoolId)
-    .then(({ data }) => {
+    .then(({data}) => {
       gradeData.value = data;
-      gradeData.value?.unshift({ id: 0, name: "全部班级" });
+      gradeData.value?.unshift({id: 0, name: "全部班级"});
     })
     .catch((error) => {
       gradeData.value = [];
-      gradeData.value?.unshift({ id: 0, name: "全部班级" });
+      gradeData.value?.unshift({id: 0, name: "全部班级"});
       console.log(error);
     });
 }
@@ -42,11 +42,11 @@ const studentSearch: StudentParams = reactive({
 const dataStatus = ref(0);
 const studentCount = ref(0);
 const studentData = ref<StudentItem[]>();
-async function getStudentData(schoolId) {
+async function getStudentData(schoolId: number) {
   studentSearch.school_id = schoolId;
   getStudentLists(studentSearch)
-    .then(({ data }) => {
-      const { count, lists } = data;
+    .then(({data}) => {
+      const {count, lists} = data;
       studentCount.value = count;
       studentData.value = lists;
       dataStatus.value = 1;

+ 26 - 26
src/views/student/result.vue

@@ -4,11 +4,11 @@ import RadarChart from "@/components/Charts/RadarChart.vue";
 import CircleChart from "@/components/Charts/CircleChart.vue";
 import DoubleChart from "@/components/Charts/DoubleChart.vue";
 import SvgIcon from "@/components/SvgIcon/index.vue";
-import { getUrlParam } from "@/utils";
-import { watch } from "vue";
-import { useUserStore } from "@/store/modules/user";
-import { getStudentBoard } from "@/api/student";
-import { StudentBoard } from "@/api/student/types";
+import {getUrlParam} from "@/utils";
+import {watch} from "vue";
+import {useUserStore} from "@/store/modules/user";
+import {getStudentBoard} from "@/api/student";
+import {StudentBoard} from "@/api/student/types";
 
 const userStore = useUserStore();
 defineOptions({
@@ -18,17 +18,17 @@ defineOptions({
 // 数据状态
 const dataStatus = ref(false);
 const dataMessage = ref("加载中...");
-let chartData: StudentBoard = reactive({});
+const chartData = ref<StudentBoard>();
 // 五维雷达图
 let radarData: number[][] = reactive([]);
 async function getChartData(schoolId: number) {
   // 从url获取学生Id
   const studentId = Number(getUrlParam("id")) || 0;
   getStudentBoard(studentId, schoolId)
-    .then(({ data }) => {
-      chartData = <StudentBoard>{ ...data };
+    .then(({data}) => {
+      chartData.value = data;
       dataStatus.value = true;
-      radarData = [chartData.after, chartData.front];
+      radarData = [chartData.value?.after || [], chartData.value?.front || []];
     })
     .catch((error) => {
       dataStatus.value = false;
@@ -41,11 +41,11 @@ function starElement(index: number, compare: number) {
   let value = 0;
   let tag = "";
   if (compare == 0) {
-    star = chartData.eeg[index].front[1];
-    value = chartData.eeg[index].front[0];
+    star = chartData.value?.eeg[index].front[1] || 1;
+    value = chartData.value?.eeg[index].front[0] || 0;
   } else {
-    star = chartData.eeg[index].after[1];
-    value = chartData.eeg[index].after[0];
+    star = chartData.value?.eeg[index].after[1] || 1;
+    value = chartData.value?.eeg[index].after[0] || 0;
   }
   if (star == 1) {
     tag = "重度不足";
@@ -85,27 +85,27 @@ watch(
       <el-row class="box-card">
         <el-col :xs="10" :span="5">
           <div class="l1">
-            <span>{{ chartData.name }}</span>
+            <span>{{ chartData?.name }}</span>
           </div>
-          <div class="l2">{{ chartData.phone }}</div>
+          <div class="l2">{{ chartData?.phone }}</div>
         </el-col>
         <el-col :xs="14" :span="5">
           <div class="l1">
-            <span>{{ chartData.count }}</span>
+            <span>{{ chartData?.count }}</span>
           </div>
           <div class="l2">训练次数累计</div>
         </el-col>
         <el-col :xs="10" :span="6">
           <div class="l1">
-            <span>{{ chartData.minute }}</span
-            >分<span>{{ chartData.second }}</span
+            <span>{{ chartData?.minute }}</span
+            >分<span>{{ chartData?.second }}</span
             >秒
           </div>
           <div class="l2">训练时长累计</div>
         </el-col>
         <el-col :xs="14" :span="8">
           <div class="l1">
-            前<span>{{ chartData.sort }}%</span>
+            前<span>{{ chartData?.sort }}%</span>
           </div>
           <div class="l2">在所有通过训练的学员中你的位置是</div>
         </el-col>
@@ -136,8 +136,8 @@ watch(
               <div class="charts">
                 <CircleChart
                   id="resultChart1"
-                  :key="chartData.height"
-                  :data="chartData.height"
+                  :key="chartData?.height"
+                  :data="chartData?.height || 0"
                   height="220px"
                   width="220px"
                   color="#4284f2"
@@ -153,8 +153,8 @@ watch(
               <div class="charts">
                 <DoubleChart
                   id="doubleChart1"
-                  :key="chartData.height_num"
-                  :data="chartData.height_num"
+                  :key="chartData?.height_num"
+                  :data="chartData?.height_num || 0"
                   height="220px"
                   width="220px"
                   color="#4e68b0"
@@ -164,11 +164,11 @@ watch(
             </el-col>
             <el-col :xs="24" :span="10">
               <div class="charts last">
-                <template v-if="chartData.percentage?.length > 0">
+                <template v-if="chartData?.percentage?.length > 0">
                   <PieChart
                     id="pieChart"
-                    :key="chartData.percentage.toString()"
-                    :data="chartData.percentage"
+                    :key="chartData?.percentage.toString()"
+                    :data="chartData?.percentage || []"
                     width="400px"
                     height="350px"
                     class="chart"