HomePage.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <el-container :class="getRole">
  3. <el-aside v-show="onshow">
  4. <div class="logo">
  5. <p v-if="userLoginDTO && userLoginDTO.type == '1'">
  6. <b>朗通后台管理系统</b>
  7. </p>
  8. <p v-if="userLoginDTO && userLoginDTO.type == '0'">
  9. <b>DiagbotCloud</b>
  10. </p>
  11. <p v-if="userLoginDTO && userLoginDTO.type == '0'">
  12. <b>后台管理系统</b>
  13. </p>
  14. </div>
  15. <lt-menu
  16. v-if="menuWrappers && menuWrappers.length"
  17. v-bind:role="getRole"
  18. v-bind:data="menuWrappers"
  19. ></lt-menu>
  20. <div class="version">
  21. <p>
  22. <span>版本信息:</span>
  23. <a href="javascript:void(0)" @click="showVersion">{{
  24. versionName
  25. }}</a>
  26. <i v-if="isNewV">
  27. <img src="../../images/new.png" alt />
  28. </i>
  29. </p>
  30. </div>
  31. </el-aside>
  32. <img
  33. src="../../images/icon-collect-right.png"
  34. v-show="!onshow"
  35. class="collect"
  36. @click="collect"
  37. />
  38. <img
  39. src="../../images/icon-collect-left.png"
  40. v-show="onshow"
  41. class="collect-left"
  42. @click="collect"
  43. />
  44. <el-container>
  45. <el-header class="clearfix">
  46. <div class="title fl">
  47. <h2>{{ organization && organization.name }}</h2>
  48. </div>
  49. <div class="userInfo fr">
  50. <span class="username" @click="goCenter">{{
  51. userLoginDTO && userLoginDTO.linkman
  52. }}</span>
  53. <lt-badge
  54. v-if="getRole == 'user'"
  55. class="green"
  56. :authStatus="authStatus"
  57. >{{ authStatusName }}</lt-badge
  58. >
  59. <el-button type="info" size="small" plain @click="logout"
  60. >退出</el-button
  61. >
  62. </div>
  63. </el-header>
  64. <el-main>
  65. <router-view v-if="ok" v-on:status-change="changeStatus"></router-view>
  66. </el-main>
  67. </el-container>
  68. <el-dialog
  69. title="版本信息"
  70. :visible.sync="versionVisible"
  71. width="50%"
  72. class="version-info"
  73. >
  74. <div v-html="versionInfo"></div>
  75. </el-dialog>
  76. </el-container>
  77. </template>
  78. <script>
  79. import LtMenu from "../common/Menu.vue";
  80. import LtBadge from "@base/LtBadge.vue";
  81. import api from "@api/index.js";
  82. import userApi from "@api/user.js";
  83. import Console from "@components/user/Console.vue";
  84. import newIcon from "../../images/new.png";
  85. export default {
  86. name: "homepage",
  87. components: {
  88. "lt-badge": LtBadge,
  89. "lt-menu": LtMenu,
  90. console: Console,
  91. },
  92. data: function() {
  93. return {
  94. menuWrappers: null,
  95. organization: null,
  96. userLoginDTO: null,
  97. authStatus: null,
  98. authStatusName: "",
  99. ok: false, //是否已获取到菜单
  100. versionName: "",
  101. versionVisible: false,
  102. versionInfo: "",
  103. isNewV: false,
  104. version: null, //版本信息接口返回的数据
  105. onshow: true,
  106. };
  107. },
  108. computed: {
  109. getRole: function() {
  110. return this.userLoginDTO && this.userLoginDTO.type == "0"
  111. ? "user"
  112. : "admin";
  113. },
  114. },
  115. created() {
  116. //获取菜单
  117. this.getMenuList();
  118. },
  119. watch: {
  120. $route: function(to, from) {
  121. if (from.name == "login") {
  122. this.getMenuList();
  123. }
  124. if (to.path == "/") {
  125. // 退出时清空菜单
  126. this.menuWrappers = [];
  127. this.isNewV = false;
  128. }
  129. },
  130. },
  131. mounted() {
  132. // let elSide = document.querySelector(".el-aside"),
  133. // tabWidth = document.querySelector(".collect-left");
  134. // tabWidth.style.left = elSide.offsetWidth - 36 + "px";
  135. // window.onresize = () => {
  136. // return (() => {
  137. // tabWidth.style.left = elSide.offsetWidth - 36 + "px";
  138. // })();
  139. // };
  140. },
  141. methods: {
  142. collect() {
  143. let tabWidth = document.querySelector(".collect-left");
  144. this.onshow = !this.onshow;
  145. tabWidth.style.left = this.onshow ? 300 - 36 + "px" : 300 + "px";
  146. },
  147. getMenuList() {
  148. api
  149. .getAccessdMenu()
  150. .then((res) => {
  151. if (res.data.code == "0") {
  152. const data = res.data.data;
  153. this.ok = true;
  154. const hasConcole = data.menuWrappers.find((it) => {
  155. return it.code.indexOf("-KZT") > -1;
  156. });
  157. //this.hasConcole = hasConcole!=-1;
  158. this.menuWrappers = data.menuWrappers;
  159. this.organization = data.organization;
  160. this.userLoginDTO = data.userLoginDTO;
  161. localStorage.setItem(
  162. "userLoginDTO",
  163. JSON.stringify(data.userLoginDTO)
  164. );
  165. this.getRole == "user" && this.getAuthStatus();
  166. if (hasConcole) {
  167. const url =
  168. this.getRole == "user" ? "/user/YH-KZT" : "/admin/LT-KZT";
  169. this.$router.push({ path: url });
  170. }
  171. this.getVersionInfo();
  172. }
  173. })
  174. .catch((error) => {
  175. console.log(error);
  176. });
  177. },
  178. isNewVersion() {
  179. //判断是否为新版
  180. },
  181. getVersionInfo() {
  182. const getInfo =
  183. this.getRole == "user" ? api.getVersionOuter : api.getVersionInner;
  184. getInfo().then((res) => {
  185. if (res.data.code == "0") {
  186. const data = res.data.data;
  187. this.fillVersionInfo(data);
  188. } else {
  189. this.$message(res.data.msg);
  190. }
  191. });
  192. },
  193. fillVersionInfo(data) {
  194. //进入时获取版本信息,如版本时间与localStorage中不一致或者一致但localStorage中未被点过,
  195. // 则要显示更新图标
  196. let htl = data.refreshTime
  197. ? "<h3>当前版本:" +
  198. data.name +
  199. "<span>" +
  200. data.refreshTime.substr(0, 10) +
  201. "</span></h3>"
  202. : "<h3>当前版本:" + data.name + "</h3>";
  203. let prags = data.detail || [];
  204. this.versionName = data.name;
  205. const versionTime = JSON.parse(
  206. localStorage.getItem("versionInfo-" + this.userLoginDTO.username)
  207. );
  208. if (
  209. !versionTime ||
  210. (data.refreshTime === versionTime.date && !versionTime.showed)
  211. ) {
  212. this.isNewV = true;
  213. } else {
  214. this.isNewV = false;
  215. }
  216. for (let i = 0; i < prags.length; i++) {
  217. htl +=
  218. "<p>" + prags[i].title + "</p><p>" + prags[i].description + "</p>";
  219. }
  220. this.versionInfo = htl;
  221. this.version = { date: data.refreshTime };
  222. },
  223. showVersion() {
  224. this.versionVisible = true;
  225. this.version.showed = true;
  226. this.isNewV = false;
  227. localStorage.setItem(
  228. "versionInfo-" + this.userLoginDTO.username,
  229. JSON.stringify(this.version)
  230. );
  231. },
  232. /*redirectPage(){
  233. const url = this.getRole=='user'?'/user':'/admin';
  234. this.$router.push({path:url});
  235. },*/
  236. changeStatus(text) {
  237. //账号信息中提交认证后修改状态
  238. this.authStatus = 2;
  239. this.authStatusName = text;
  240. },
  241. goCenter() {
  242. const url = this.getRole == "user" ? "" : "/admin/LT-GRZX";
  243. this.$router.push({ path: url });
  244. },
  245. getAuthStatus() {
  246. //获取用户认证状态
  247. userApi
  248. .getUserAuthStatus()
  249. .then((res) => {
  250. if (res.data.code == "0") {
  251. const data = res.data.data;
  252. // this.authStatus = data[0];
  253. this.authStatusName = data.authStatusName;
  254. this.authStatus = data.authStatus;
  255. }
  256. })
  257. .catch((error) => {
  258. console.log(error);
  259. });
  260. },
  261. logout() {
  262. //退出
  263. localStorage.removeItem("token");
  264. localStorage.removeItem("menuPath");
  265. this.$router.push({ path: "/" });
  266. },
  267. },
  268. };
  269. </script>
  270. <style lang="less">
  271. @import "../../less/common.less";
  272. .collect {
  273. width: 36px;
  274. height: 32px;
  275. position: fixed;
  276. left: 0;
  277. top: 70%;
  278. z-index: 20;
  279. }
  280. .collect-left {
  281. width: 36px;
  282. height: 32px;
  283. position: fixed;
  284. left: 264px;
  285. top: 65%;
  286. z-index: 20;
  287. }
  288. .user .el-menu-item.is-active {
  289. color: @userBase;
  290. }
  291. .admin .el-menu-item.is-active {
  292. color: @adminBase;
  293. }
  294. .admin .username {
  295. cursor: pointer;
  296. }
  297. .version-info h3 {
  298. font-size: 14px;
  299. margin-bottom: 20px;
  300. span {
  301. float: right;
  302. font-weight: normal;
  303. }
  304. }
  305. </style>
  306. <style lang="less" scoped>
  307. @import "../../less/common.less";
  308. .el-menu-vertical-demo.el-menu {
  309. height: calc(100% - 120px);
  310. overflow-y: auto;
  311. }
  312. .version {
  313. position: fixed;
  314. bottom: 0;
  315. width: 300px;
  316. min-width: 270px;
  317. font-size: 12px;
  318. /*text-indent: 50px;*/
  319. text-align: center;
  320. height: 54px;
  321. line-height: 54px;
  322. background: #fff;
  323. i {
  324. display: inline-block;
  325. width: 20px;
  326. height: 16px;
  327. img {
  328. vertical-align: text-top;
  329. }
  330. }
  331. }
  332. .user .version a {
  333. color: @userBase;
  334. }
  335. .admin .version a {
  336. color: @adminBase;
  337. }
  338. .user .logo {
  339. background: @userBase;
  340. p {
  341. font-size: 16px;
  342. line-height: normal;
  343. }
  344. }
  345. .admin .logo {
  346. background: @adminBase;
  347. p {
  348. font-size: 18px;
  349. line-height: 40px;
  350. }
  351. }
  352. .title {
  353. h2 {
  354. display: inline-block;
  355. line-height: 60px;
  356. font-size: 18px;
  357. }
  358. }
  359. .block {
  360. height: 40px;
  361. width: 100%;
  362. background: #fff;
  363. box-shadow: 0px 1px 2px #c9c9c9;
  364. }
  365. .el-main {
  366. padding: 0;
  367. }
  368. .el-button {
  369. margin-left: 15px;
  370. }
  371. </style>