学期校历
This commit is contained in:
@@ -17,45 +17,19 @@
|
||||
<span class="week">{{ weekText }}</span>
|
||||
</div>
|
||||
|
||||
<span class="semester-bar__divider" />
|
||||
|
||||
<!-- 右:学期切换下拉框 -->
|
||||
<div class="semester-bar__item semester-bar__switch">
|
||||
<span class="label">切换学期</span>
|
||||
<div class="semester-select-wrap">
|
||||
<el-select
|
||||
:value="activeSemester ? activeSemester.nd : ''"
|
||||
placeholder="请选择学期"
|
||||
size="small"
|
||||
filterable
|
||||
class="semester-select"
|
||||
@change="handleSwitch"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in semesterList"
|
||||
:key="item.nd"
|
||||
:label="getSemesterName(item.nd)"
|
||||
:value="item.nd"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listSemester, updateSemester } from '@/api/teachBusiness/semester'
|
||||
import { listSemester } from '@/api/teachBusiness/semester'
|
||||
|
||||
export default {
|
||||
name: 'SemesterBar',
|
||||
data() {
|
||||
return {
|
||||
// 学期列表(接口数据)
|
||||
semesterList: [],
|
||||
// 当前选中的学期对象
|
||||
activeSemester: null,
|
||||
today: new Date(),
|
||||
loading: false
|
||||
today: new Date()
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -84,19 +58,15 @@ export default {
|
||||
this.getSemesterList()
|
||||
},
|
||||
methods: {
|
||||
/** 加载学期列表,默认选中当前学期(dqxq=true),无当前学期则选第一条 */
|
||||
/** 加载当前学期(dqxq=true),无当前学期则取第一条 */
|
||||
getSemesterList() {
|
||||
this.loading = true
|
||||
listSemester({ pageNum: 1, pageSize: 100 }).then(response => {
|
||||
const data = response.data || {}
|
||||
const list = data.records || []
|
||||
this.semesterList = list
|
||||
const current = list.find(i => i.dqxq)
|
||||
this.activeSemester = current || (list[0] ? list[0] : null)
|
||||
this.loading = false
|
||||
}).catch(() => {
|
||||
this.semesterList = []
|
||||
this.loading = false
|
||||
this.activeSemester = null
|
||||
})
|
||||
},
|
||||
/** 格式化后端 LocalDateTime(2026-02-23T00:00:00 -> 2026-02-23) */
|
||||
@@ -112,32 +82,6 @@ export default {
|
||||
const xq = s.slice(4)
|
||||
const map = { '01': '春季学期', '02': '夏季学期', '03': '秋季学期' }
|
||||
return xn + '年' + (map[xq] || '第' + xq + '学期')
|
||||
},
|
||||
/** 切换学期:将目标学期设为当前学期,原当前学期取消 */
|
||||
handleSwitch(nd) {
|
||||
const current = this.activeSemester
|
||||
if (!nd || (current && nd === current.nd)) return
|
||||
const target = this.semesterList.find(i => i.nd === nd)
|
||||
if (!target) return
|
||||
// 当前已是"当前学期"的其他记录(需取消)
|
||||
const others = this.semesterList.filter(i => i.dqxq && i.nd !== nd)
|
||||
|
||||
updateSemester({ ...target, dqxq: true }).then(() => {
|
||||
// 若存在原当前学期,一并取消
|
||||
if (others.length) {
|
||||
return Promise.all(others.map(o => updateSemester({ ...o, dqxq: false })))
|
||||
}
|
||||
return Promise.resolve()
|
||||
}).then(() => {
|
||||
this.activeSemester = target
|
||||
this.$message.success(`已切换至:${this.getSemesterName(nd)}`)
|
||||
// 重新拉取,同步最新 dqxq 状态
|
||||
this.getSemesterList()
|
||||
// 通知学期管理页面自动刷新
|
||||
this.$root.$emit('semester-current-changed')
|
||||
}).catch(() => {
|
||||
this.$message.error('切换学期失败,请稍后重试')
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,66 +165,5 @@ export default {
|
||||
&__divider {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&__switch {
|
||||
background: transparent;
|
||||
border: none;
|
||||
padding: 0;
|
||||
border-radius: 0;
|
||||
height: 36px;
|
||||
|
||||
/* 用一层定高 flex 容器包裹 select,彻底隔离其默认行高外溢 */
|
||||
.semester-select-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 36px;
|
||||
}
|
||||
|
||||
.semester-select {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
/* 关闭 select/input 外层默认行高,交给 flex 居中 */
|
||||
::v-deep .el-select,
|
||||
::v-deep .el-input {
|
||||
height: 36px;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="scss">
|
||||
/* 顶部学期选择器使用导航栏色系,避免被全局白色表单控件样式覆盖。 */
|
||||
#app .semester-bar__switch .semester-select {
|
||||
.el-input__inner {
|
||||
height: 36px;
|
||||
padding: 0 34px 0 13px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.22);
|
||||
border-radius: 7px;
|
||||
color: #ffffff;
|
||||
background: rgba(255, 255, 255, 0.10);
|
||||
box-shadow: none;
|
||||
|
||||
&::placeholder {
|
||||
color: rgba(255, 255, 255, 0.68);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(255, 255, 255, 0.38);
|
||||
background: rgba(255, 255, 255, 0.14);
|
||||
}
|
||||
|
||||
&:focus {
|
||||
border-color: rgba(255, 255, 255, 0.55);
|
||||
background: rgba(255, 255, 255, 0.14);
|
||||
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
}
|
||||
|
||||
.el-input__icon {
|
||||
color: rgba(255, 255, 255, 0.82);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -265,7 +265,14 @@ export default {
|
||||
},
|
||||
watch: {
|
||||
'form.kxrq': 'calculateWeeks',
|
||||
'form.jsrq': 'calculateWeeks'
|
||||
'form.jsrq': 'calculateWeeks',
|
||||
// 新增时选择学期类型后,自动带出开学/结束日期
|
||||
'form.xq'(val) {
|
||||
if (this.isAdd) this.autoFillDatesForXq()
|
||||
},
|
||||
'form.xn'(val) {
|
||||
if (this.isAdd) this.autoFillDatesForXq()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/** 顶栏切换当前学期后自动刷新 */
|
||||
@@ -286,6 +293,23 @@ export default {
|
||||
if (xn === undefined || xn === null || xn === '' || !xq) return ''
|
||||
return String(xn) + String(xq)
|
||||
},
|
||||
/** 根据学年+学期类型自动带出开学/结束日期(春季01:2-5月,夏季02:6-8月,秋季03:9-12月) */
|
||||
autoFillDatesForXq() {
|
||||
const xn = this.form.xn
|
||||
const xq = this.form.xq
|
||||
if (xn === undefined || xn === null || xn === '') return
|
||||
const year = Number(xn)
|
||||
const pad = m => `${year}-${String(m).padStart(2, '0')}`
|
||||
const rules = {
|
||||
'01': { start: pad(2) + '-01', end: pad(5) + '-31' },
|
||||
'02': { start: pad(6) + '-01', end: pad(8) + '-31' },
|
||||
'03': { start: pad(9) + '-01', end: pad(12) + '-31' }
|
||||
}
|
||||
const rule = rules[xq]
|
||||
if (!rule) return
|
||||
this.form.kxrq = rule.start
|
||||
this.form.jsrq = rule.end
|
||||
},
|
||||
/** 学期代号 -> 学期名称(如 202601 -> 2026年春季学期) */
|
||||
getSemesterName(nd) {
|
||||
if (!nd) return ''
|
||||
|
||||
Reference in New Issue
Block a user