Files
UserclassFront/src/App.vue
T
2026-08-12 17:19:37 +08:00

256 lines
12 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div id="app" v-if="isLogin">
<layout-old v-if="isLayoutOld" :layoutData="layoutData"></layout-old>
<layout v-else :layoutData="layoutData"></layout>
<div :class="['base-wrap-main', layoutData.isAlone ? 'alone-page' : '']">
<transition v-if="!isNoAuthority" :name="!isBack ? 'fade' : 'back'" :mode="!isBack ? 'out-in' : 'in-out'">
<router-view v-if="isRouterAlive"></router-view>
</transition>
<div v-else class="no-authority-wrap">
<h3>暂无权限</h3>
<h6>如需查看,请联络管理员为您分配权限</h6>
</div>
</div>
<!-- <Modal v-model="isAlertModal" :closable="false" :mask-closable="false" title="更新提示" width="830">
<Alert show-icon>
因为铃铛等环境无法同一时间更新,为不影响正在运行的项目,所以新的标准样式名称改为base.layout.beta.css
</Alert>
<p>
<img width="100%" src="./assets/image/1636426109.jpg" alt="" />
</p>
</Modal> -->
</div>
</template>
<script>
import layout from "./frame/layout.vue";
import layoutOld from "./frame/layout_old.vue";
const appendLink = (baseHost, name, version) => {
var headHTML = `<link type="text/css" rel="stylesheet" href="${baseHost}/BschHome/front/css/${name}.css?v=${version}">`;
$("head:eq(0)").append(headHTML);
};
export default {
components: { layout, layoutOld },
name: "app",
data() {
return {
isRouterAlive: true,
isBack: false,
isLogin: false,
isNoAuthority: false,
layoutData: {},
isLayoutOld: conf.isLayoutOld,
isAlertModal: false,
};
},
provide() {
return {
reload: this.reload,
};
},
async created() {
try {
const baseHost = window.conf.baseHost,
ssoHost = window.conf.ssoHost;
var version = localStorage.getItem("themeVersion") || new Date().getTime();
appendLink(baseHost, "base.layout.beta", version);
var info = await this.getUserInfo();
var bschResult = await this.getBschHomeJsonp(baseHost, info.id);
this.setCurrentRole(bschResult, baseHost, info.id);
var mod = await this.getUserMod();
this.layoutInit(info, mod, bschResult.appList, baseHost, ssoHost);
this.isLogin = true;
} catch (error) {
console.error(error);
this.$Message.error("载入用户信息失败!");
}
// this.isAlertModal = true;
// if (localStorage.getItem("cook_is_alert") == null) {
// localStorage.setItem("cook_is_alert", true);
// this.isAlertModal = true;
// }
},
mounted() {
var isTrident = navigator.userAgent.indexOf("Trident") > -1; // 是否是IE内核
if (isTrident) {
$("html").css("overflow", "hidden");
}
},
methods: {
reload() {
this.isRouterAlive = false;
this.$nextTick(() => (this.isRouterAlive = true));
},
getUserInfo() {
const _this = this;
return new Promise((resolve, reject) => {
_this.$api.get(
APIConfig.Base.GetUserInfo,
null,
resp => {
resolve(resp.data);
},
error => reject(error)
);
});
},
getUserMod() {
const _this = this;
return new Promise((resolve, reject) => {
_this.$api.get(
APIConfig.Base.GetUserMod,
null,
resp => {
let resps={"code":0,"msg":"","data":
[
{"id":1493,"appId":551,"modId":1,"name":"学制选择","parentId":0,"path":null,"level":0,"page":"/","icon":null,"orderNumber":1493,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":2,"name":"时段设置","parentId":0,"path":null,"level":0,"page":"/itemSet","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":3,"name":"区域操作日志","parentId":0,"path":null,"level":0,"page":"/areaOperateDaily","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":4,"name":"学校设置","parentId":0,"path":null,"level":0,"page":"/schoolSetting","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":5,"name":"课程设置","parentId":0,"path":null,"level":0,"page":"/subjectManForZy","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":6,"name":"学科管理","parentId":0,"path":null,"level":0,"page":"/subjectSetzhi","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":7,"name":"班级管理","parentId":0,"path":null,"level":0,"page":"/classManage","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":8,"name":"选修班管理","parentId":0,"path":null,"level":0,"page":"/electiveClassManage","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":9,"name":"教师管理","parentId":0,"path":null,"level":0,"page":"/teacherManage","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":10,"name":"学生管理","parentId":0,"path":null,"level":0,"page":"/studentManage","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":11,"name":"历史查询","parentId":0,"path":null,"level":0,"page":"/historySearch","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":12,"name":"学生异动管理","parentId":0,"path":null,"level":0,"page":"/studentYDManage","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":13,"name":"教师转入管理","parentId":0,"path":null,"level":0,"page":"/zhuanruinfo","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":14,"name":"学生转入管理","parentId":0,"path":null,"level":0,"page":"/zhuanruinfostu","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
{"id":1494,"appId":551,"modId":15,"name":"日志管理","parentId":0,"path":null,"level":0,"page":"/dailySearch","icon":null,"orderNumber":1494,"usable":true,"children":[],"modules":[]},
],"timeNow":"2026-06-17 14:44:05"}
resolve(resps.data);
},
error => reject(error)
);
});
},
getBschHomeJsonp(baseHost, userId) {
var version = localStorage.getItem("themeVersion") || new Date().getTime();
return new Promise((resolve, reject) => {
var crossStorage,
crossUrl = `${baseHost}/BschHome/front/libs/cross`;
try {
var HEAD = document.getElementsByTagName("head")[0];
var node = document.createElement("script");
node.src = `${crossUrl}/client.js?v=${version}`;
node.onload = function () {
crossStorage = new Client(`${crossUrl}/middle.html?v=${version}`, () => {
crossStorage.getRoteData({ userId }, resp => {
resolve(resp);
});
//分页数据默认条数
const customPageCount = localStorage.getItem("customPageCount");
crossStorage.getItem("customPageCount", resp => {
if (resp == null) return false;
if (customPageCount == null) localStorage.setItem("customPageCount", resp);
else if (resp != customPageCount) {
crossStorage.setItem({
key: "customPageCount",
value: customPageCount,
});
}
});
});
};
HEAD.appendChild(node);
} catch (error) {
console.error(error);
console.error("获取身份信息失败!");
resolve(null);
}
});
},
layoutInit(info, mod, appList, baseHost, ssoHost) {
this.layoutData.appName = "班级管理";
this.layoutData.baseHost = baseHost;
this.layoutData.ssoHost = ssoHost;
const routes = this.$router.options.routes;
let arr = [];
mod.forEach(element => {
let iconIndex = routes.findIndex(
x =>
typeof x.meta !== "undefined" &&
typeof x.meta.modId !== "undefined" &&
typeof x.meta.icon !== "undefined" &&
x.meta.modId == element.modId
);
let icon = iconIndex > -1 ? "iconfont " + routes[iconIndex].meta.icon : ""; //icon不传则为默认
arr.push({
id: element.id,
name: element.name,
modId: element.modId,
page: element.page,
children: element.children || [],
icon,
});
});
// arr[0].icon = "iconfont icon-apps"; //icon样式示例,参见static/style/font 目录
this.layoutData.modList = arr.sort((a, b) => a.modId - b.modId);
this.layoutData.isAlone = arr.length == 1; //当只有一个选项卡时,隐藏menu和nav
let { id, name, profilePicture } = info;
this.layoutData.userInfo = { id, name, avatar: profilePicture };
this.layoutData.appList = appList || [];
//无权限
if (arr.length == 0) {
this.layoutData.isAlone = true;
this.isNoAuthority = true;
}
},
setCurrentRole(result, baseHost, userId) {
if (result) {
let { childId, roleId, schId } = result.checkRole;
localStorage.setItem("currentRole", encodeURI(JSON.stringify({ childId, roleId, schId, userId })));
localStorage.setItem("themeVersion", result.themeVersion);
appendLink(baseHost, result.themeName, result.themeVersion);
} else {
appendLink(baseHost, "default-theme", new Date().getTime());
}
},
},
};
</script>
<style lang="scss">
#loging-box,
.mop-load-div {
display: none;
}
/* 开始过渡阶段,动画出去阶段 */
.fade-enter-active,
.fade-leave-active {
transition: all 1ms cubic-bezier(0, 0.99, 1, 0.03);
}
/* 进入开始 */
.fade-enter {
// transform: translateY(10px);
opacity: 0;
}
/* 出去终点 */
.fade-leave-active {
// transform: translateY(-10px);
// opacity: 0;
}
.back-enter-active,
.back-leave-active {
transition: all 1ms cubic-bezier(0, 0.99, 1, 0.03);
}
/* 进入开始 */
.back-enter {
display: none;
}
/* 出去终点 */
.back-leave-active {
display: none;
}
#app {
height: 100%;
}
</style>