App.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div id="app" :class="{appNoWidth:$route.path == '/data' || $route.path == '/note'}">
  3. <!-- <div class="app_head" :class="{stuWidth:$route.path == '/student'}"> -->
  4. <!-- <div class="logo" @click="goTo('/course')"></div>
  5. <span style="margin-left: 10px; color: #fff; font-weight: 600" @click="goTo('/course')"
  6. >PBL项目管理平台</span
  7. >
  8. <div class="user_head" v-if="this.$store.state.isLogin">
  9. <div class="noticeBox">
  10. <i class="noticeI" @click="goTo('/works')"></i>
  11. <span v-if="this.$store.state.nCount != 0">{{
  12. this.$store.state.nCount > 99 ? "99+" : this.$store.state.nCount
  13. }}</span>
  14. </div>
  15. <span class="user_name">{{
  16. this.$store.state.userInfo ? this.$store.state.userInfo.name : "用户"
  17. }}</span>
  18. <div @click="exit">
  19. <i class="exitI"></i>
  20. <el-button type="text" style="color: white"
  21. >退出</el-button
  22. >
  23. </div>
  24. </div> -->
  25. <!-- </div> -->
  26. <div :class="{gHeight: $route.path == '/Grid'}" style="width:100%;height:100%">
  27. <!-- main 内容 -->
  28. <keep-alive v-if="$route.meta.keepAlive">
  29. <!-- 这里是会被缓存的视图组件 -->
  30. <router-view
  31. v-if="$route.meta.keepAlive"
  32. :class="{ pb_body: isShowNav }"
  33. />
  34. </keep-alive>
  35. <!-- 这里是不被缓存的视图组件 -->
  36. <router-view
  37. v-if="!$route.meta.keepAlive"
  38. :class="{ pb_body: isShowNav }"
  39. />
  40. <!-- 底部导航 -->
  41. <!-- <footer-nav
  42. v-if="isShowNav"
  43. :luyou="this.$store.state.luyou"
  44. ></footer-nav> -->
  45. </div>
  46. </div>
  47. </template>
  48. <script>
  49. // import leftBar from "./components/tools/leftBar";
  50. import { Message } from "element-ui";
  51. export default {
  52. name: "App",
  53. data() {
  54. return {
  55. isShowNav: true, // 是否显示导航 Tab
  56. navTabs: [
  57. "/class",
  58. "/course",
  59. "/data",
  60. "/notice",
  61. "/student",
  62. "/works",
  63. "/worksDetail",
  64. "/course/courseDetail",
  65. "/library",
  66. // "/course/addCourse",
  67. // "/ask",
  68. // "/ask/askList",
  69. ], // 导航
  70. };
  71. },
  72. // components: {
  73. // "footer-nav": leftBar,
  74. // },
  75. created: function () {
  76. this.routerP();
  77. // this.getnCount();
  78. setInterval(() => {
  79. // this.getnCount();
  80. }, 60000);
  81. },
  82. methods: {
  83. isLogin() {
  84. const loading = this.$loading.service({
  85. background: "rgba(255, 255, 255)",
  86. target: document.querySelector("body"),
  87. });
  88. var _isLogin = this.$cookies.get("tlogin");
  89. var userInfo = this.$cookies.get("teacherInfo");
  90. // if (_isLogin == "1" && userInfo) {
  91. loading.close();
  92. this.$store.commit("update", ["isLogin", true]);
  93. // var info = JSON.parse(window.sessionStorage.getItem("userInfo"));
  94. this.$store.commit("update", ["userInfo", userInfo]);
  95. let router_path = this.$route.path;
  96. if (router_path == "/") {
  97. this.$router.push("/course");
  98. }
  99. // } else {
  100. // this.$store.commit("update", ["isLogin", false]);
  101. // Message({
  102. // message: "未登录,请登录",
  103. // type: "warning",
  104. // });
  105. // setTimeout(() => {
  106. // loading.close();
  107. // this.$router.push("/login");
  108. // }, 2000);
  109. // }
  110. },
  111. getnCount() {
  112. let params = {
  113. bid: this.$store.state.userInfo.userid,
  114. };
  115. this.ajax
  116. .get(this.$store.state.api + "getNcount", params)
  117. .then((res) => {
  118. console.log(res);
  119. if (res.data[0].length > 0) {
  120. this.$store.commit("update", ["nCount", res.data[0][0].num]);
  121. } else {
  122. this.$store.commit("update", ["nCount", 0]);
  123. }
  124. })
  125. .catch((err) => {
  126. console.error(err);
  127. });
  128. },
  129. routerP() {
  130. const { navTabs } = this.$data;
  131. let router_path = this.$route.path;
  132. console.log(router_path);
  133. if (router_path != "/login") {
  134. this.isLogin();
  135. }
  136. var a = 0;
  137. for (var i = 0; i < navTabs.length; i++) {
  138. if (router_path == navTabs[i]) {
  139. this.isShowNav = true;
  140. a = 1;
  141. break;
  142. }
  143. }
  144. if (a == 0) {
  145. this.isShowNav = false;
  146. }
  147. },
  148. exit() {
  149. sessionStorage.clear();
  150. this.$cookies.remove("tlogin");
  151. this.$cookies.remove("teacherInfo");
  152. this.$store.commit("update", ["isLogin", false]);
  153. this.$store.commit("update", ["userInfo", {}]);
  154. Message({
  155. message: "退出成功",
  156. type: "success",
  157. });
  158. this.$router.push("/login");
  159. },
  160. goTo(path) {
  161. this.$router.push(path);
  162. },
  163. },
  164. watch: {
  165. $route(to, from) {
  166. const { navTabs } = this.$data;
  167. const toPath = to.path;
  168. const fromName = from.name;
  169. var a = 0;
  170. for (var i = 0; i < navTabs.length; i++) {
  171. if (toPath == navTabs[i]) {
  172. this.isShowNav = true;
  173. a = 1;
  174. break;
  175. }
  176. }
  177. if (a == 0) {
  178. this.isShowNav = false;
  179. }
  180. },
  181. },
  182. };
  183. </script>
  184. <style>
  185. * {
  186. margin: 0;
  187. padding: 0;
  188. }
  189. body {
  190. font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
  191. "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  192. }
  193. #app {
  194. height: 100%;
  195. width: 100%;
  196. background: #e6eaf0;
  197. /* min-width: 1380px; */
  198. min-width: 1250px;
  199. }
  200. .appNoWidth{
  201. min-width: unset !important;
  202. display: inline-block !important;
  203. min-width: 550px;
  204. }
  205. .app_head {
  206. height: 67.5px;
  207. width: 100%;
  208. background-color: rgb(61, 103, 188);
  209. display: flex;
  210. align-items: center;
  211. min-width: 1000px;
  212. }
  213. .logo {
  214. height: 48px;
  215. width: 73px;
  216. background: url("./assets/logo.png");
  217. background-size: 100% 100%;
  218. margin-left: 20px;
  219. }
  220. .pb_body {
  221. margin: 20px;
  222. width: 98%;
  223. min-width: 745px;
  224. /* display: inline-block; */
  225. height: 95%;
  226. min-height: 750px;
  227. background: #fff;
  228. border-radius: 5px;
  229. /* position: absolute; */
  230. }
  231. .pb_head {
  232. font-size: 26px;
  233. /* font-weight: 600; */
  234. width: 95%;
  235. margin: 10px auto;
  236. padding: 10px 5px;
  237. border-bottom: 1px solid #eee;
  238. }
  239. .pb_content {
  240. /* height: 100%; */
  241. }
  242. .pb_content_body {
  243. width: 94%;
  244. margin: 10px auto;
  245. /* overflow: auto;
  246. height: calc(100% - 120px); */
  247. }
  248. .user_head {
  249. display: flex;
  250. align-items: center;
  251. margin-left: auto;
  252. margin-right: 20px;
  253. font-size: 18px;
  254. font-weight: 600;
  255. }
  256. .user_head .user_name {
  257. color: #fff;
  258. margin-right: 10px;
  259. }
  260. .user_head div {
  261. display: flex;
  262. align-items: center;
  263. cursor: pointer;
  264. }
  265. .user_head .exitI {
  266. background-image: url("./assets/exit.png");
  267. width: 25px;
  268. height: 25px;
  269. background-size: 100% 100%;
  270. margin-top: 1px;
  271. line-height: 25px;
  272. vertical-align: text-top;
  273. background-repeat: no-repeat;
  274. }
  275. .noticeBox {
  276. position: relative;
  277. margin-right: 10px;
  278. }
  279. .user_head .noticeI {
  280. background-image: url("./assets/icon/noticeA.png");
  281. width: 25px;
  282. height: 25px;
  283. background-size: 100% 100%;
  284. margin-top: 1px;
  285. line-height: 25px;
  286. vertical-align: text-top;
  287. background-repeat: no-repeat;
  288. cursor: pointer;
  289. }
  290. .noticeBox span {
  291. position: absolute;
  292. background: red;
  293. width: 15px;
  294. height: 15px;
  295. border-radius: 30px;
  296. color: #fff;
  297. text-align: center;
  298. font-size: 12px;
  299. display: flex;
  300. align-items: center;
  301. justify-content: center;
  302. top: -3px;
  303. right: -3px;
  304. }
  305. .stuWidth {
  306. min-width: 1180px;
  307. }
  308. .gHeight{
  309. height: 100%;
  310. }
  311. </style>