ソースを参照

style: 代码格式化4

chaooo 2 年 前
コミット
1cb338dc59

+ 1 - 1
.env.production

@@ -2,4 +2,4 @@
 
 VITE_APP_TITLE = 'shuimuai-dashboard-h5'
 VITE_APP_PORT = 3000
-VITE_APP_BASE_API = '/prod-api'
+VITE_APP_BASE_API = 'http://devapi.shuimuai.com/'

+ 2 - 2
src/api/school/types.ts

@@ -15,8 +15,8 @@ export interface SchoolList {
 export interface GradeList {
   /** 班级id */
   id: number;
-  /** 学校id */
-  school_id: number;
+  // /** 学校id */
+  // school_id: number;
   /** 学校名称 */
   name: string;
 }

+ 1 - 1
src/layout/components/Navbar.vue

@@ -71,7 +71,7 @@ onMounted(() => {
 watch(
   () => schoolId.value,
   (newValue, oldValue) => {
-    let num;
+    let num: string = "";
     schoolData.value?.some((school) => {
       if (newValue == school.school_id) {
         num = school.num;

+ 26 - 20
src/layout/components/Sidebar/SidebarItem.vue

@@ -1,9 +1,10 @@
 <script setup lang="ts">
-import { useRouter } from "vue-router";
+import { RouteRecordRaw, useRouter } from "vue-router";
 import path from "path-browserify";
 import { isExternal } from "@/utils/index";
 import AppLink from "./Link.vue";
 import SvgIcon from "@/components/SvgIcon/index.vue";
+import { SidebarRoutes } from "@/layout/components/Sidebar/types";
 
 const router = useRouter();
 const props = defineProps({
@@ -22,7 +23,8 @@ const props = defineProps({
     required: true,
   },
 });
-
+//const {item} = props;
+const itemRoute: SidebarRoutes = reactive(props.item);
 const onlyOneChild = ref(); // 临时变量,唯一子路由
 /**
  * 判断当前路由是否只有一个子路由
@@ -33,9 +35,9 @@ const onlyOneChild = ref(); // 临时变量,唯一子路由
  * @param children 子路由数组
  * @param parent 当前路由
  */
-function hasOneShowingChild(children = [], parent: any) {
+function hasOneShowingChild(children: any = [], parent: any) {
   // 需要显示的子路由数组
-  const showingChildren = children.filter((item: any) => {
+  const showingChildren: any = children.filter((item: any) => {
     if (item.meta?.hidden) {
       return false; // 过滤不显示的子路由
     } else {
@@ -66,25 +68,27 @@ function hasOneShowingChild(children = [], parent: any) {
  *
  * @param routePath 路由路径
  */
-function resolvePath(routePath: string) {
+function resolvePath(routePath: string): string {
   if (isExternal(routePath)) {
     return routePath;
   }
-  if (isExternal(props.basePath)) {
-    return props.basePath;
+  if (isExternal(props.basePath || "")) {
+    return props.basePath || "";
   }
   // 完整路径 = 父级路径(/level/level_3) + 路由路径
-  const fullPath = path.resolve(props.basePath, routePath); // 相对路径 → 绝对路径
-  return fullPath;
+  // return fullPath 相对路径 → 绝对路径
+  return path.resolve(props.basePath || "", routePath);
 }
 
 /**
  * 处理子页面时父级菜单高亮
  */
-function addActiveClass(routePath) {
-  const currentBase = routePath.split("/")[1];
+function addActiveClass(routePath: string) {
+  const currentBase: string = routePath.split("/")[1];
   document.querySelectorAll(".el-menu-item").forEach((item) => {
-    const pathBase = item.attributes["mack"].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) {
@@ -115,10 +119,10 @@ if (onMounted) {
 }
 </script>
 <template>
-  <div v-if="!item.meta || !item.meta.hidden">
+  <div v-if="!itemRoute.meta || !itemRoute.meta.hidden">
     <template
       v-if="
-        hasOneShowingChild(item.children, item) &&
+        hasOneShowingChild(itemRoute.children, itemRoute) &&
         (!onlyOneChild.children || onlyOneChild.noShowingChildren)
       "
     >
@@ -126,7 +130,7 @@ if (onMounted) {
       <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)">
         <el-menu-item
           :index="resolvePath(onlyOneChild.path)"
-          :mack="resolvePath(onlyOneChild.path)"
+          :mark="resolvePath(onlyOneChild.path)"
         >
           <svg-icon
             v-if="onlyOneChild.meta && onlyOneChild.meta.icon"
@@ -138,17 +142,19 @@ if (onMounted) {
         </el-menu-item>
       </app-link>
     </template>
-    <el-sub-menu v-else :index="resolvePath(item.path)" teleported>
+    <el-sub-menu v-else :index="resolvePath(itemRoute.path)" teleported>
       <!-- 包含多个子路由 $route.path  -->
       <template #title>
         <svg-icon
-          v-if="item.meta && item.meta.icon"
-          :icon-class="item.meta.icon"
+          v-if="itemRoute.meta && itemRoute.meta.icon"
+          :icon-class="itemRoute.meta.icon"
         />
-        <span v-if="item.meta && item.meta.title">{{ item.meta.title }}</span>
+        <span v-if="itemRoute.meta && itemRoute.meta.title">{{
+          itemRoute.meta.title
+        }}</span>
       </template>
       <sidebar-item
-        v-for="child in item.children"
+        v-for="child in itemRoute.children"
         :key="child.path"
         :item="child"
         :base-path="resolvePath(child.path)"

+ 9 - 0
src/layout/components/Sidebar/types.ts

@@ -0,0 +1,9 @@
+export interface SidebarRoutes {
+  meta: {
+    icon: string;
+    title: string;
+    hidden: boolean;
+  };
+  path: string;
+  children: SidebarRoutes[];
+}

+ 2 - 2
src/views/charts-components/CircleChart.vue

@@ -37,8 +37,8 @@ const props = defineProps({
     default: "#2f539b",
   },
   fontSize: {
-    type: Number,
-    default: 18,
+    type: String,
+    default: "18px",
   },
   fontWeight: {
     type: String,

+ 4 - 3
src/views/charts-components/FocusBarChart.vue

@@ -35,10 +35,11 @@ const props = defineProps({
     default: [] as Array<number>,
   },
 });
-const labelFormatter = ({ value, dataIndex }) => {
-  const star = props.star?.[dataIndex] * 1;
+const labelFormatter = (params: any) => {
+  //{ value, dataIndex } = params;
+  const star = (props.star as number[])?.[params.dataIndex] * 1 || 0;
   const label = [];
-  label.push(value);
+  label.push(params.value);
   if (star === 1) {
     label.push("重度不足");
   }

+ 2 - 2
src/views/charts-components/PercentBarChart.vue

@@ -40,7 +40,7 @@ const props = defineProps({
   },
 });
 
-const labelFormatter = (params) => {
+const labelFormatter = (params: any) => {
   // 显示人数 加 百分比
   if (params.value > 0) {
     return props.data?.[params.dataIndex] + "人 (" + params.value + "%)";
@@ -48,7 +48,7 @@ const labelFormatter = (params) => {
     return "";
   }
 };
-const colorFormatter = function (params) {
+const colorFormatter = (params: any) => {
   // 每个柱子的颜色即为colorList数组里的每一项,如果柱子数目多于colorList的长度,则柱子颜色循环使用该数组
   const colorList = ["#68cfff", "#688fff", "#b890ef", "#ee7a66", "#f6c04c"];
   return colorList[params.dataIndex];

+ 9 - 9
src/views/charts-components/RadarChart.vue

@@ -57,7 +57,7 @@ const globalColor = {
 /**
  * 指示器 及 状态tag 自定义rich
  */
-const tagBaseRich = (bgColor) => {
+const tagBaseRich = (bgColor: string) => {
   return {
     color: globalColor.white,
     padding: [4, 10, 4, 10],
@@ -77,7 +77,7 @@ const indicatorRich = {
   green: tagBaseRich(globalColor.green),
   blue: tagBaseRich(globalColor.blue),
 };
-const indicatorFormatter = (name, indicator) => {
+const indicatorFormatter = (name: string, indicator: any) => {
   if (!props.tag) {
     return `{tit|${name}}`;
   }
@@ -105,8 +105,8 @@ const indicatorFormatter = (name, indicator) => {
 /**
  * 在图中定位每个数据的位置
  */
-const positionLabelData = (data, idx) => {
-  const labelValue = [0, 0, 0, 0, 0];
+const positionLabelData = (data: number[], idx: number) => {
+  const labelValue: any = [0, 0, 0, 0, 0];
   labelValue[idx] = data[idx];
   // idx = 0,1,2,3,4 对应 top,left,left,right,right
   let pos = "bottom";
@@ -125,16 +125,16 @@ const positionLabelData = (data, idx) => {
       show: true,
       fontSize: 12,
       position: pos,
-      formatter: (params) => {
+      formatter: (params: any) => {
         return params.value > 0 ? params.value : "";
       },
     },
   };
 };
-const positionFormatter = (data) => {
-  const result = [];
+const positionFormatter = (data: any) => {
+  const result: any = [];
   for (let idx in data) {
-    result.push(positionLabelData(data, idx * 1));
+    result.push(positionLabelData(data, Number(idx)));
   }
   return result;
 };
@@ -226,7 +226,7 @@ const getOptions = () => {
         show: true,
         color: globalColor.before,
         fontSize: 16,
-        //distance: 5
+        distance: 0,
       },
       lineStyle: { width: 0 },
       data: positionFormatter(props.dataSets?.[1]),

+ 6 - 6
src/views/dashboard/components/DataCard.vue

@@ -30,7 +30,7 @@ const props = defineProps({
   },
 });
 // 卡片数字动效
-function countNumber(number) {
+function countNumber(number: any) {
   return useTransition(number, {
     duration: 2000,
     transition: TransitionPresets.easeOutExpo,
@@ -64,31 +64,31 @@ watchEffect(() => {
   <el-row :gutter="40" class="data-card">
     <el-col :xs="24" :sm="12" :md="8" :lg="5">
       <div class="card c1">
-        <span class="n">{{ Math.round(classCountOutput) }}</span
+        <span class="n">{{ Math.round(Number(classCountOutput)) }}</span
         ><span>全部班级</span>
       </div>
     </el-col>
     <el-col :xs="24" :sm="12" :md="8" :lg="5">
       <div class="card c2">
-        <span class="n">{{ Math.round(teacherCountOutput) }}</span
+        <span class="n">{{ Math.round(Number(teacherCountOutput)) }}</span
         ><span>全部教师</span>
       </div>
     </el-col>
     <el-col :xs="24" :sm="12" :md="8" :lg="5">
       <div class="card c3">
-        <span class="n">{{ Math.round(studentCountOutput) }}</span
+        <span class="n">{{ Math.round(Number(studentCountOutput)) }}</span
         ><span>全部学生</span>
       </div>
     </el-col>
     <el-col :xs="24" :sm="12" :md="8" :lg="5">
       <div class="card c4">
-        <span class="n">{{ Math.round(equipmentCountOutput) }}</span
+        <span class="n">{{ Math.round(Number(equipmentCountOutput)) }}</span
         ><span>设备套数</span>
       </div>
     </el-col>
     <el-col :xs="24" :sm="12" :md="8" :lg="5">
       <div class="card c5">
-        <span class="n">{{ Math.round(trainingCountOutput) }}</span
+        <span class="n">{{ Math.round(Number(trainingCountOutput)) }}</span
         ><span>累计训练次数</span>
       </div>
     </el-col>

+ 26 - 13
src/views/dashboard/index.vue

@@ -18,8 +18,14 @@ defineOptions({
 /**
  * 数据卡片
  */
-const cards: DashboardCard = reactive({});
-async function getDataCard(schoolId) {
+const cards: DashboardCard = reactive({
+  grade: 0,
+  teacher: 0,
+  student: 0,
+  equipment: 0,
+  game: 0,
+});
+async function getDataCard(schoolId: number) {
   getDashboardTop(schoolId)
     .then(({ data }) => {
       // 全部班级
@@ -43,7 +49,7 @@ async function getDataCard(schoolId) {
 const gradeData = ref<GradeList[]>();
 // 班级编号
 let gradeId = ref(0);
-async function getGradeData(schoolId) {
+async function getGradeData(schoolId: number) {
   getGradeList(schoolId)
     .then(({ data }) => {
       data.unshift({ id: 0, name: "全部班级" });
@@ -58,8 +64,15 @@ async function getGradeData(schoolId) {
  * 图表数据
  */
 const chartStatus = ref(false);
-const chartData: DashboardData = reactive({});
-async function getChartData(gradeId) {
+const chartData: DashboardData = reactive({
+  frontAverage: 0,
+  afterAverage: 0,
+  front: 0,
+  after: 0,
+  frontProportion: { num: [], percentage: [] },
+  afterProportion: { num: [], percentage: [] },
+});
+async function getChartData(gradeId: number) {
   getDashboardData(gradeId)
     .then(({ data }) => {
       // 初期专注力估值
@@ -116,7 +129,7 @@ function changeGrade() {
   <div class="dashboard-container">
     <!-- 数据卡片 -->
     <DataCard
-      :key="cards"
+      :key="cards.toString()"
       :classes="cards.grade"
       :teachers="cards.teacher"
       :students="cards.student"
@@ -194,8 +207,8 @@ function changeGrade() {
                   color="#3a7fc2"
                   bg-color="#e4e7f4"
                   font-color="#3a7fc2"
-                  font-size="30"
-                  round-cap="true"
+                  font-size="30px"
+                  :round-cap="Boolean(true)"
                 />
                 <p>初期训练</p>
                 <p>专注力50以上人数比例</p>
@@ -205,15 +218,15 @@ function changeGrade() {
               <div v-if="chartStatus" class="item">
                 <CircleChart
                   id="circleChart2"
-                  :key="chartData.after"
+                  :key="chartData.after.toString()"
                   :data="chartData.after ? chartData.after : 0"
                   height="200px"
                   width="200px"
                   color="#5563ac"
                   bg-color="#e4e7f4"
                   font-color="#5563ac"
-                  font-size="30"
-                  round-cap="true"
+                  font-size="30px"
+                  :round-cap="Boolean(true)"
                 />
                 <p>近期训练</p>
                 <p>专注力50以上人数比例</p>
@@ -231,7 +244,7 @@ function changeGrade() {
               <div v-if="chartStatus" class="bar">
                 <PercentBarChart
                   id="barChart1"
-                  :key="chartData.frontProportion"
+                  :key="chartData.frontProportion.toString()"
                   width="400px"
                   height="500px"
                   title="全体学员初期训练专注力评分占比"
@@ -245,7 +258,7 @@ function changeGrade() {
               <div v-if="chartStatus" class="bar">
                 <PercentBarChart
                   id="barChart2"
-                  :key="chartData.afterProportion"
+                  :key="chartData.afterProportion.toString()"
                   width="400px"
                   height="500px"
                   title="全体学员训练近期专注力评分平均占比"

+ 0 - 1
src/views/equipment/index.vue

@@ -20,7 +20,6 @@ let teacherNumber = ref(0);
 const teacherData = ref<GradeList[]>([
   {
     id: 0,
-    school_id: 0,
     name: "全部",
   },
 ]);

+ 4 - 4
src/views/evaluation/components/EvaluateCard.vue

@@ -20,7 +20,7 @@ const props = defineProps({
   },
 });
 // 卡片数字动效
-function countNumber(number) {
+function countNumber(number: any) {
   return useTransition(number, {
     duration: 5000,
     transition: TransitionPresets.easeOutExpo,
@@ -44,15 +44,15 @@ onMounted(() => {
 <template>
   <div class="clear">
     <div class="data-card c1">
-      <span class="n">{{ Math.round(studentCountOutput) }}</span
+      <span class="n">{{ Math.round(Number(studentCountOutput)) }}</span
       ><span>参与测评学生总计</span>
     </div>
     <div class="data-card c2">
-      <span class="n">{{ Math.round(focusCountOutput) }}</span
+      <span class="n">{{ Math.round(Number(focusCountOutput)) }}</span
       ><span>脑电专注力测评次数</span>
     </div>
     <div class="data-card c3">
-      <span class="n">{{ Math.round(trainingCountOutput) }}</span
+      <span class="n">{{ Math.round(Number(trainingCountOutput)) }}</span
       ><span>脑电检测次数</span>
     </div>
   </div>

+ 1 - 1
src/views/grade/index.vue

@@ -23,7 +23,7 @@ watch(
 const gradeData = ref<GradeList[]>();
 // 班级编号
 let gradeId = ref(0);
-async function getGradeData(schoolId) {
+async function getGradeData(schoolId: number) {
   getGradeList(schoolId)
     .then(({ data }) => {
       gradeData.value = data;

+ 2 - 6
src/views/login/index.vue

@@ -88,12 +88,8 @@ 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: localStorage.getItem("autoName") || "",
+  password: localStorage.getItem("autoPass") || "",
 });
 
 const loginRules = {

+ 0 - 1
src/views/student/index.vue

@@ -21,7 +21,6 @@ let classNumber = ref(0);
 const gradeData = ref<GradeList[]>([
   {
     id: 0,
-    school_id: 0,
     name: "全部班级",
   },
 ]);

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

@@ -77,8 +77,8 @@ const pieData = ref([12, 18, 20, 28, 22]);
                   bg-color="#dadff0"
                   font-color="#09132e"
                   font-weight="normal"
-                  font-size="18"
-                  line-width="30"
+                  font-size="18px"
+                  :line-width="Number(30)"
                 />
                 <p>高专注力状态数据占比</p>
               </div>

+ 0 - 1
src/views/training/index.vue

@@ -22,7 +22,6 @@ let trainingType = ref("");
 const gradeData = ref<GradeList[]>([
   {
     id: 0,
-    school_id: 0,
     name: "全部班级",
   },
 ]);