HomePage.vue 8.3 KB

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