HomePage.vue 8.1 KB

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