调整课表

This commit is contained in:
ywyonui 2025-09-29 23:24:54 +08:00
parent 510d12282f
commit 153978b847
3 changed files with 344 additions and 86 deletions

View File

@ -1,21 +1,25 @@
<template>
<view class="schedule-page">
<view class="bj-picker">
<NjBjPicker @change="changeNjBj" icon-arrow="right" :customStyle="{ backgroundColor: '#fff', borderRadius: '0', padding: '12px 15px' }" />
<view class="bj-picker" @click="showClassTree">
<text :class="{ placeholder: !selectedClassText }">{{ selectedClassText || "请选择班级" }}</text>
<uni-icons type="right" size="16" color="#fff" v-if="canPickBj"></uni-icons>
</view>
<view class="week-selector" @click="openWeekPicker">
<text>{{ curZc.mc }}</text>
<uni-icons type="right" size="16" color="#fff"></uni-icons>
</view>
<view class="date-tabs">
<view class="date-tabs" v-if="rqList.length > 0">
<view v-for="(day, index) in rqList" :key="index" :class="['date-tab-item', { active: curRqIndex === index }]"
@click="selectDay(index)">
<text class="weekday">{{ day.zjmc }}</text>
<text class="date">{{ day.rqmc }}</text>
</view>
</view>
<view class="no-course-notice" v-else>
<text class="notice-text">本周处于节假日中无课程信息</text>
</view>
<view class="schedule-body">
<view class="schedule-body" v-if="rqList.length > 0 && sjList.length > 0">
<view v-for="(sj, index) in sjList" :key="index" class="schedule-row">
<view class="time-slot">
<text class="slot-name">{{ sj.mc }}</text>
@ -60,15 +64,31 @@
</view>
</view>
</uni-popup>
<!-- 班级选择树 -->
<BasicTree
ref="treeRef"
:range="treeData"
idKey="key"
rangeKey="title"
title="选择班级"
:multiple="false"
:selectParent="false"
@confirm="onTreeConfirm"
@cancel="onTreeCancel"
/>
</view>
</template>
<script lang="ts" setup>
import { ref, onMounted, nextTick } from "vue";
import { dqpkApi, drpkkbApi } from "@/api/base/server";
import NjBjPicker from "@/pages/components/NjBjPicker/index.vue";
import { ref, onMounted, computed, nextTick } from "vue";
import { drpkkbApi } from "@/api/base/server";
import BasicTree from '@/components/BasicTree/Tree.vue'
import { useUserStore } from "@/store/modules/user";
import { useCommonStore } from "@/store/modules/common";
import { findAllNjBjTree } from '@/api/base/server'
const { getJs } = useUserStore();
const { getDqPk } = useCommonStore();
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
import weekOfYear from "dayjs/plugin/weekOfYear";
@ -82,14 +102,118 @@ let dqZc = 0;
let xqId = '';
let bjId = '';
//
const changeNjBj = (nj: any, bj: any) => {
bjId = bj.key;
console.log("班级选择变更:", { nj, bj, bjId });
//
if (rqList.value.length > 0) {
selectDay(curRqIndex.value);
//
const treeData = ref<any[]>([]);
const treeRef = ref();
//
const curNj = ref<any>(null);
const curBj = ref<any>(null);
const canPickBj = computed(() => {
//
if (!treeData.value.length) {
return false;
}
if (treeData.value.length < 2) {
const children = treeData.value[0].children;
if (!children || !children.length || children.length < 2) {
return false;
}
}
return true;
});
//
const selectedClassText = computed(() => {
if (curBj.value && curNj.value) {
return `${curNj.value.title} ${curBj.value.title}`;
}
return '';
});
//
const showClassTree = () => {
if (!canPickBj.value) {
return;
}
if (treeRef.value) {
treeRef.value._show();
}
};
//
const onTreeConfirm = (selectedItems: any[]) => {
if (selectedItems.length > 0) {
const selectedItem = selectedItems[0]; //
// parents
if (selectedItem.parents && selectedItem.parents.length > 0) {
const parent = selectedItem.parents[0]; //
const nj = parent; //
const bj = selectedItem; //
curNj.value = nj;
curBj.value = bj;
bjId = bj.key;
//
if (rqList.value.length > 0) {
selectDay(curRqIndex.value);
}
} else {
//
curNj.value = selectedItem;
curBj.value = null;
bjId = '';
}
}
};
//
const onTreeCancel = () => {
//
};
//
const loadTreeData = async () => {
try {
const res = await findAllNjBjTree();
if (res.resultCode === 1 && res.result) {
// BasicTree
const convertTreeData = (items: any[]): any[] => {
return items.map((item: any) => ({
key: item.key,
title: item.title,
njmcId: item.njmcId,
children: item.children ? convertTreeData(item.children) : [],
}));
};
treeData.value = convertTreeData(res.result);
//
if (res.result.length > 0) {
const firstNj = res.result[0];
curNj.value = {
key: firstNj.key,
title: firstNj.title,
njmcId: firstNj.njmcId
};
//
if (firstNj.children && firstNj.children.length > 0) {
const firstBj = firstNj.children[0];
curBj.value = {
key: firstBj.key,
title: firstBj.title,
njmcId: firstBj.njmcId
};
bjId = firstBj.key;
}
}
}
} catch (error) {
uni.showToast({ title: "加载班级数据失败", icon: "error" });
}
};
@ -103,7 +227,14 @@ const curRqIndex = ref(0)
//
const zcList = ref<any>([])
//
const rqList = ref<any>([])
const rqList = computed(() => {
if (!curZc.value || !curZc.value.drList || !curZc.value.drList.length) {
return [];
}
return curZc.value.drList.filter((dr: any) => {
return (!dr.holiday && dr.zj <= 5) || (dr.holiday && dr.holiday.type != 2);
});
});
//
const sjList = ref<any>([])
@ -113,12 +244,15 @@ const isLoading = ref(false);
const showWeekPicker = ref(false);
const weekPopup = ref<any>(null);
const selectedWeekNumber = ref(0);
const targetScrollTop = ref(0); // scroll-top
//
const openWeekPicker = async () => {
// 2
if (!zcList.value || zcList.value.length < 2) {
return;
}
showWeekPicker.value = true;
//
await nextTick();
@ -152,7 +286,6 @@ const selectWeek = (zc: any) => {
}
//
Object.assign(curZc.value, zc);
Object.assign(rqList.value, curZc.value.drList);
//
closeWeekPicker();
@ -168,22 +301,24 @@ const selectDay = (index: number) => {
if (!rqList.value.length) {
return;
}
console.log("查询课表参数:", {
const params = {
jsId: "",
bjId: bjId || "",
xqId: xqId,
rq: rqList.value[index].rq,
zj: rqList.value[index].zj
});
drpkkbApi({
jsId: "", // getJs.id,
bjId: bjId || "", //
xqId: xqId,
rq: rqList.value[index].rq, //
zj: rqList.value[index].zj
}).then(res => {
zj: rqList.value[index].zj,
txDate: null
};
if (params.zj > 5) {
const holiday = rqList.value[index].holiday || {};
if (holiday && holiday.type === 3 && holiday.txDate) {
params.txDate = holiday.txDate;
}
}
console.log("查询课表参数:", params);
drpkkbApi(params).then(res => {
// result
if (res && res.resultCode === 1) {
sjList.value = res.result;
@ -212,12 +347,15 @@ const getCourseColorClass = (subject: string | undefined): string => {
onMounted(async () => {
try {
const res = await dqpkApi();
//
await loadTreeData();
const res = await getDqPk();
const result = res.result;
dqZc = res.result.dqZc;
xqId = res.result.dqXq.id;
dqZc = res.result.zc;
xqId = res.result.xq.id;
zcList.value = result.zcList;
sjList.value = result.sjList;
sjList.value = [];
// 1.
let zc = zcList.value.find((item:any) => item.djz === dqZc);
@ -227,7 +365,6 @@ onMounted(async () => {
//
Object.assign(curZc.value, zc);
Object.assign(rqList.value, curZc.value.drList);
// 2.
const currentDayOfWeek = dayjs().day(); // 0=, 1=, ..., 6=
@ -254,6 +391,7 @@ onMounted(async () => {
background-color: #f8f8f8;
}
.bj-picker,
.week-selector {
display: flex;
justify-content: space-between;
@ -275,12 +413,13 @@ onMounted(async () => {
flex-direction: column;
align-items: center;
justify-content: center;
padding: 8px 5px;
border-radius: 6px;
padding: 16rpx 10rpx;
border-radius: 12rpx;
background-color: rgba(255, 255, 255, 0.1);
color: #ffffff;
flex: 1;
min-width: 50px;
min-width: 100rpx;
max-width: 118rpx;
cursor: pointer;
transition: background-color 0.2s ease;
@ -484,30 +623,12 @@ onMounted(async () => {
}
}
/* 年级班级选择器样式 - 调整为单个选择器 */
.class-selector {
display: flex;
justify-content: center; //
align-items: center;
padding: 10px 15px;
background-color: #f8f8f8;
border-bottom: 1px solid #eee;
.picker-item {
display: flex;
align-items: center;
padding: 5px 15px; // padding
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
color: #333;
min-width: 150px; //
justify-content: space-between; //
text {
margin-right: 8px;
}
}
.no-course-notice {
margin: 15px;
background-color: #fff;
border-radius: 8px;
padding: 50px 15px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
text-align: center;
}
</style>
</style>

View File

@ -5,15 +5,18 @@
<uni-icons type="right" size="16" color="#fff"></uni-icons>
</view>
<view class="date-tabs">
<view class="date-tabs" v-if="rqList.length > 0">
<view v-for="(day, index) in rqList" :key="index" :class="['date-tab-item', { active: curRqIndex === index }]"
@click="selectDay(index)">
<text class="weekday">{{ day.zjmc }}</text>
<text class="date">{{ day.rqmc }}</text>
</view>
</view>
<view class="no-course-notice" v-else>
<text class="notice-text">本周处于节假日中无课程信息</text>
</view>
<view class="schedule-body">
<view class="schedule-body" v-if="rqList.length > 0 && sjList.length > 0">
<view v-for="(sj, index) in sjList" :key="index" class="schedule-row">
<view class="time-slot">
<text class="slot-name">{{ sj.mc }}</text>
@ -63,9 +66,11 @@
<script lang="ts" setup>
import { ref, onMounted, nextTick } from "vue";
import { dqpkApi, drpkkbApi } from "@/api/base/server";
import { drpkkbApi } from "@/api/base/server";
import { useUserStore } from "@/store/modules/user";
import { useCommonStore } from "@/store/modules/common";
const { getJs } = useUserStore();
const { getDqPk } = useCommonStore();
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
import weekOfYear from "dayjs/plugin/weekOfYear";
@ -88,7 +93,14 @@ const curRqIndex = ref(0)
//
const zcList = ref<any>([])
//
const rqList = ref<any>([])
const rqList = computed(() => {
if (!curZc.value || !curZc.value.drList || !curZc.value.drList.length) {
return [];
}
return curZc.value.drList.filter((dr: any) => {
return (!dr.holiday && dr.zj <= 5) || (dr.holiday && dr.holiday.type != 2);
});
});
//
const sjList = ref<any>([])
@ -104,6 +116,10 @@ const targetScrollTop = ref(0); // 新增:用于绑定 scroll-top
//
const openWeekPicker = async () => {
// 2
if (!zcList.value || zcList.value.length < 2) {
return;
}
showWeekPicker.value = true;
//
await nextTick();
@ -137,7 +153,6 @@ const selectWeek = (zc: any) => {
}
//
Object.assign(curZc.value, zc);
Object.assign(rqList.value, curZc.value.drList);
//
closeWeekPicker();
@ -152,13 +167,24 @@ const selectDay = (index: number) => {
if (!rqList.value.length) {
return;
}
drpkkbApi({
const params = {
jsId: getJs.id,
bjId: "",
xqId: xqId,
rq: rqList.value[index].rq, //
zj: rqList.value[index].zj
}).then(res => {
zj: rqList.value[index].zj,
txDate: null
};
if (params.zj > 5) {
const holiday = rqList.value[index].holiday || {};
if (holiday && holiday.type === 3 && holiday.txDate) {
params.txDate = holiday.txDate;
}
}
console.log("查询课表参数:", params);
drpkkbApi(params).then(res => {
// result
if (res && res.resultCode === 1) {
sjList.value = res.result;
@ -183,12 +209,12 @@ const getCourseColorClass = (subject: string | undefined): string => {
};
onMounted(async () => {
const res = await dqpkApi();
const res = await getDqPk();
const result = res.result;
dqZc = res.result.dqZc;
xqId = res.result.dqXq.id;
dqZc = res.result.zc;
xqId = res.result.xq.id;
zcList.value = result.zcList;
sjList.value = result.sjList;
sjList.value = [];
let zc = zcList.value.find((item:any) => item.djz === dqZc);
if (!zc) {
zc = zcList.value[0];
@ -226,12 +252,13 @@ onMounted(async () => {
flex-direction: column;
align-items: center;
justify-content: center;
padding: 8px 5px;
border-radius: 6px;
padding: 16rpx 10rpx;
border-radius: 12rpx;
background-color: rgba(255, 255, 255, 0.1);
color: #ffffff;
flex: 1;
min-width: 50px;
min-width: 100rpx;
max-width: 118rpx;
cursor: pointer;
transition: background-color 0.2s ease;
@ -460,4 +487,13 @@ onMounted(async () => {
}
}
}
.no-course-notice {
margin: 15px;
background-color: #fff;
border-radius: 8px;
padding: 50px 15px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
text-align: center;
}
</style>

View File

@ -10,6 +10,44 @@ import { jsdJsdkbApi, jsdKsccApi } from "@/api/base/server";
import { dqPkApi, gzlGetDqXqAndZcApi } from "@/api/base/gzlApi";
import { defineStore } from "pinia";
/**
*
* @param params
* @returns
*/
const getIdList = (params: any) => {
if (!params || !params.length) {
return [];
}
// 判断传入参数params是逗号分隔的字符串还是数组如果是字符串拆分成数组
if (typeof params == "string") {
return params.split(",");
} else if (Array.isArray(params)) {
return [...params];
}
}
/**
* ID列表
* @param idList ID列表
* @param data
* @returns
*/
const getCacheAndNewId = (idList: any[], data: any) => {
let cacheList: any = [];
let newIdList: any = [];
// 接下来判断bjPkkb里面有没有对应的排课科目数据如果有则记录如果没有则记录班级id
for (let i = 0; i < idList.length; i++) {
const bjId = idList[i];
if (data[bjId]) {
cacheList.push(...data[bjId]);
} else {
newIdList.push(bjId);
}
}
return { cacheList, newIdList };
}
interface CommonState {
data: any;
}
@ -29,6 +67,75 @@ export const useCommonStore = defineStore({
setData(data: any) {
this.data = data;
},
/**
*
* @param api api接口
* @param key
*/
async getCacheList (api: any, key: string) : Promise<any> {
if (!this.data[key]) {
this.data[key] = await api();
}
return Promise.resolve(this.data[key]);
},
/**
*
* @param api api接口
* @param params
* @param key
* @param subKey
*/
async getCacheSubList (api: any, params: any, key: string, subKey: string) : Promise<any> {
// 如果没有参数之间返回
if (!params || !params[subKey]) {
return Promise.resolve();
}
if (!this.data[key] || !this.data[key][subKey]) {
this.data[key] = this.data[key] || {};
this.data[key][subKey] = await api(params);
}
return Promise.resolve(this.data[key][subKey]);
},
/**
* ID列表
* @param api api接口
* @param params
* @param srcIdList ID列表
* @param key
* @param subKey
* @param paramKey idList对应的参数键
*/
async getCacheSubListByIdList (api: any, params: any, srcIdList: any, key: string, subKey: string, paramKey: string) : Promise<any> {
// 如果没有参数之间返回
let idList: any = getIdList(srcIdList);
if (!idList.length) {
return Promise.resolve([]);
}
let dataKey: any = this.data[key] || {};
const { cacheList, newIdList } = getCacheAndNewId(idList, dataKey);
let retList = [...cacheList];
// 判断如果有新的班级id则请求接口获取排课科目数据
if (newIdList.length) {
// 把newIdList转换成逗号分隔的字符串
const newIdStr = newIdList.join(',');
params[paramKey] = newIdStr;
const res = await api(params);
let newList:any = [];
if (res.resultCode == 1) {
newList = res.result || [];
} else if (Array.isArray(res)) {
newList = res || [];
}
// 缓存数据
newList.map((item:any) => {
dataKey[item[subKey]] = dataKey[item[subKey]] || [];
dataKey[item[subKey]].push(item);
retList.push(item);
});
this.data[key] = dataKey;
}
return Promise.resolve(retList);
},
// 所有年级
async getAllNj(): Promise<any> {
if (!this.data.allNj) {
@ -100,13 +207,7 @@ export const useCommonStore = defineStore({
return Promise.resolve(this.data.kscc[params.bjId]);
},
async getDqPk(): Promise<any> {
if (!this.data.dqpk) {
const res = await dqPkApi();
if (res && res.resultCode === 1) {
this.data.dqpk = res.result;
}
}
return Promise.resolve(this.data.dqpk);
return this.getCacheList(dqPkApi, "dqpk");
},
async getDqPkZcList(): Promise<any> {
const dqpk = await this.getDqPk();