App.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <div id="app">
  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>
  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: 1000px;
  199. }
  200. .app_head {
  201. height: 67.5px;
  202. width: 100%;
  203. background-color: rgb(61, 103, 188);
  204. display: flex;
  205. align-items: center;
  206. min-width: 1000px;
  207. }
  208. .logo {
  209. height: 48px;
  210. width: 73px;
  211. background: url("./assets/logo.png");
  212. background-size: 100% 100%;
  213. margin-left: 20px;
  214. }
  215. .pb_body {
  216. margin: 20px;
  217. width: 98%;
  218. min-width: 745px;
  219. /* display: inline-block; */
  220. height: 95%;
  221. min-height: 750px;
  222. background: #fff;
  223. border-radius: 5px;
  224. /* position: absolute; */
  225. }
  226. .pb_head {
  227. font-size: 26px;
  228. /* font-weight: 600; */
  229. width: 95%;
  230. margin: 10px auto;
  231. padding: 10px 5px;
  232. border-bottom: 1px solid #eee;
  233. }
  234. .pb_content {
  235. /* height: 100%; */
  236. }
  237. .pb_content_body {
  238. width: 94%;
  239. margin: 10px auto;
  240. /* overflow: auto;
  241. height: calc(100% - 120px); */
  242. }
  243. .user_head {
  244. display: flex;
  245. align-items: center;
  246. margin-left: auto;
  247. margin-right: 20px;
  248. font-size: 18px;
  249. font-weight: 600;
  250. }
  251. .user_head .user_name {
  252. color: #fff;
  253. margin-right: 10px;
  254. }
  255. .user_head div {
  256. display: flex;
  257. align-items: center;
  258. cursor: pointer;
  259. }
  260. .user_head .exitI {
  261. background-image: url("./assets/exit.png");
  262. width: 25px;
  263. height: 25px;
  264. background-size: 100% 100%;
  265. margin-top: 1px;
  266. line-height: 25px;
  267. vertical-align: text-top;
  268. background-repeat: no-repeat;
  269. }
  270. .noticeBox {
  271. position: relative;
  272. margin-right: 10px;
  273. }
  274. .user_head .noticeI {
  275. background-image: url("./assets/icon/noticeA.png");
  276. width: 25px;
  277. height: 25px;
  278. background-size: 100% 100%;
  279. margin-top: 1px;
  280. line-height: 25px;
  281. vertical-align: text-top;
  282. background-repeat: no-repeat;
  283. cursor: pointer;
  284. }
  285. .noticeBox span {
  286. position: absolute;
  287. background: red;
  288. width: 15px;
  289. height: 15px;
  290. border-radius: 30px;
  291. color: #fff;
  292. text-align: center;
  293. font-size: 12px;
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. top: -3px;
  298. right: -3px;
  299. }
  300. .stuWidth {
  301. min-width: 1180px;
  302. }
  303. </style>