main.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <div :style="auiWrapper" v-loading.fullscreen.lock="loading" :element-loading-text="$t('loading')" class="aui-wrapper all-main-wraper">
  3. <template v-if="!loading">
  4. <!-- <div @click="menuChangeCeshi">路径切换导航</div> -->
  5. <div class="smp_main-t">
  6. <main-navbar ref="mainNavbar" v-if="navbarFlag"/>
  7. </div>
  8. <div class="smp_main-b" v-if="isNormalSidebar">
  9. <div class="smp_main-l" v-show="isMainMenuHaveChild">
  10. <main-sidebar v-if="sidebarFlag" ref="sidebar"/>
  11. </div>
  12. <div class="smp_main-r" :class="{'onClose':$store.state.sidebarFold,'main-no-left':!isMainMenuHaveChild}">
  13. <content-crumb v-if="isMainMenuHaveChild"></content-crumb>
  14. <main-content />
  15. </div>
  16. </div>
  17. <div class="smp_main-b" v-else>
  18. <div class="smp_main-r" :class="{'onClose':$store.state.sidebarFold,'main-no-left':true}">
  19. <basicCom :isSidebar="true"></basicCom>
  20. </div>
  21. </div>
  22. </template>
  23. <noticePop ref="noticePop"></noticePop>
  24. <taskPop ref="taskPop"></taskPop>
  25. <!-- 北信源即时通讯应用入口 -->
  26. <openPcexeBtn ref="openPcexeBtn"></openPcexeBtn>
  27. </div>
  28. </template>
  29. <script>
  30. import Cookies from 'js-cookie'
  31. import MainNavbar from './main-navbar'
  32. import MainSidebar from './main-sidebar'
  33. import MainContent from './main-content'
  34. import debounce from 'lodash/debounce'
  35. import ContentCrumb from './main-content-crumb'
  36. import noticePop from './notice-pop'
  37. import taskPop from './task-pop'
  38. import openPcexeBtn from './openPcexeBtn'
  39. import basicCom from '@/views/modules/demo/basicComponent/basic-com'
  40. import { clearLoginInfo } from '@/utils'
  41. import shuiyin from '@/utils/shuiyin'
  42. let allComponent = {
  43. index: ''
  44. }
  45. export default {
  46. provide () {
  47. allComponent.index = this
  48. return {
  49. allComponent: allComponent,
  50. // 刷新
  51. refresh () {
  52. this.$store.state.contentIsNeedRefresh = true
  53. this.$nextTick(() => {
  54. this.$store.state.contentIsNeedRefresh = false
  55. })
  56. }
  57. }
  58. },
  59. data () {
  60. return {
  61. loading: true,
  62. isNormalSidebar: true,
  63. navbarFlag: false,
  64. sidebarFlag: false,
  65. mainContent: 'aui-content__wrapper',
  66. auiWrapper: '',
  67. isMainMenuHaveChild: true,
  68. menuDataAll: [],
  69. areaCode: ''
  70. }
  71. },
  72. components: {
  73. MainNavbar,
  74. MainSidebar,
  75. MainContent,
  76. ContentCrumb,
  77. basicCom,
  78. noticePop,
  79. taskPop,
  80. openPcexeBtn
  81. },
  82. watch: {
  83. $route: 'routeHandle'
  84. },
  85. created () {
  86. // this.windowResizeHandle()
  87. // this.routeHandle(this.$route)
  88. Promise.all([
  89. this.getUserInfo(),
  90. this.getPermissions()
  91. ]).then(() => {
  92. this.getTitleLogo()
  93. this.loading = false
  94. })
  95. this.loading = false
  96. this.navbarFlag = window.SITE_CONFIG['isNavbar']
  97. this.sidebarFlag = window.SITE_CONFIG['isSidebar']
  98. if (!this.sidebarFlag) {
  99. this.mainContent = ''
  100. }
  101. if (!this.navbarFlag) {
  102. this.auiWrapper = 'padding-top:0px;'
  103. }
  104. if (this.$route.name === 'JCZJ') {
  105. this.gotoWaterfallSidebar()
  106. }
  107. },
  108. mounted () {
  109. this.getMenuList()
  110. this.monitorChild()
  111. this.setWaterMarker()
  112. if (Cookies.get('loginMsg')) {
  113. this.$alert('本系统所有操作均有日志记录,非因工作原因,不得使用系统查询获取信息,不得随意泄漏、传播或出售通过系统查询获取的信息。', '温馨提示', {
  114. confirmButtonText: '确定',
  115. showClose: false,
  116. callback: action => {
  117. Cookies.remove('loginMsg')
  118. },
  119. customClass: 'login-msg'
  120. });
  121. }
  122. window.addEventListener('message', (e) => {
  123. console.log('收到消息', e)
  124. if (e.data.code === 401 || e.data.code === 402 || e.data.code === 403 || e.data.code === 10001) {
  125. if(localStorage.getItem('pathCopy')) {
  126. localStorage.setItem('pathCopyshow',true)
  127. }
  128. this.$alert(e.data.msg, '提示',{
  129. showClose: false,
  130. showCancelButton: false,
  131. callback: () => {
  132. this.tokenInvalid()
  133. }
  134. })
  135. }
  136. })
  137. },
  138. methods: {
  139. setWaterMarker () {
  140. // /api-idaas
  141. this.$http.get('/idaas/sso/user/watermark/info').then(({ data: res }) => {
  142. if (res.code !== 0) {
  143. return this.$message.error(res.msg)
  144. }
  145. shuiyin([res.data.ip, res.data.username, res.data.currentTime])
  146. }).catch(() => {})
  147. },
  148. // 窗口改变大小
  149. // windowResizeHandle () {
  150. // this.$store.state.sidebarFold = document.documentElement['clientWidth'] <= 992 || false
  151. // window.addEventListener('resize', debounce(() => {
  152. // this.$store.state.sidebarFold = document.documentElement['clientWidth'] <= 992 || false
  153. // }, 150))
  154. // },
  155. getMenuList () {
  156. this.menuDataAll = window.SITE_CONFIG['menuList']
  157. },
  158. checkMenu (origin) {
  159. let arr = this.menuDataAll.filter((e) => {
  160. if (e.url) {
  161. return e.url.indexOf(origin) > -1
  162. } else {
  163. return false
  164. }
  165. })
  166. return arr.length
  167. },
  168. tokenInvalid (config) {
  169. console.log(config)
  170. clearLoginInfo()
  171. this.$router.push({ name: 'login' })
  172. },
  173. menuChangeCeshi () {
  174. let config = {
  175. path: 'https://www.baidu.com'
  176. }
  177. this.menuChange(config)
  178. },
  179. menuChange (config) {
  180. console.log(config)
  181. let path = config.path
  182. let menuObj = {}
  183. let parent = ''
  184. let item = this.menuDataAll.filter((e) => {
  185. return e.url === path
  186. })[0]
  187. if (item) {
  188. this.menuDataAll.forEach((e) => {
  189. menuObj[e.UUID] = e
  190. })
  191. parent = this.findParent(menuObj, item)
  192. console.log(menuObj, parent, item)
  193. this.$refs.mainNavbar.$refs.navbarmenu.gotoPageByUUID(parent.UUID)
  194. this.$router.push({ path: item.UUID })
  195. }
  196. // clearLoginInfo()
  197. // this.$router.push({ name: 'login' })
  198. },
  199. findParent (obj, item) {
  200. // console.log(item.id)
  201. let parent = obj[item.parentUUID]
  202. if (parent) {
  203. return this.findParent(obj, parent)
  204. } else {
  205. return item
  206. }
  207. },
  208. isMyEvent (name, obj) {
  209. let isHas = false
  210. Object.keys(obj).forEach((e) => {
  211. if (e === name) {
  212. isHas = true
  213. }
  214. })
  215. return isHas
  216. },
  217. // 跨域监听
  218. monitorChild () {
  219. let _this = this
  220. let eventObj = {
  221. tokenInvalid: _this.tokenInvalid.bind(this),
  222. menuChange: _this.menuChange.bind(this)
  223. }
  224. window.addEventListener('message', function (e) {
  225. if (!e.data.event || !_this.isMyEvent(e.data.event, eventObj)) {
  226. console.log('事件错误')
  227. return
  228. }
  229. if (_this.checkMenu(e.origin)) {
  230. eventObj[e.data.event] && eventObj[e.data.event](e.data.config)
  231. } else {
  232. console.log('源头错误')
  233. }
  234. console.log(e, window.location.origin)
  235. // e.data.cbk()
  236. })
  237. },
  238. // 显示通知弹窗
  239. showNotice () {
  240. this.$refs.noticePop.showPop()
  241. },
  242. // 显示通知弹窗
  243. showTask () {
  244. this.$refs.taskPop.showPop()
  245. },
  246. // 切换导航
  247. gotoNormalSidebar () {
  248. this.isNormalSidebar = true
  249. this.$nextTick(() => {
  250. this.$refs.sidebar.remedyMenuNoChange()
  251. })
  252. },
  253. gotoWaterfallSidebar () {
  254. this.isNormalSidebar = false
  255. },
  256. // 路由, 监听
  257. routeHandle (route) {
  258. if (route.name === 'JCZJ') {
  259. this.isNormalSidebar = true
  260. this.$nextTick(() => {
  261. this.gotoWaterfallSidebar()
  262. })
  263. } else {
  264. !this.isNormalSidebar && this.gotoNormalSidebar()
  265. }
  266. // !this.isNormalSidebar && this.gotoNormalSidebar()
  267. if (!route.meta.isTab) {
  268. return false
  269. }
  270. var tab = this.$store.state.contentTabs.filter(item => item.name === route.name)[0]
  271. if (!tab) {
  272. tab = {
  273. ...window.SITE_CONFIG['contentTabDefault'],
  274. ...route.meta,
  275. 'name': route.name,
  276. 'params': { ...route.params },
  277. 'query': { ...route.query }
  278. }
  279. this.$store.state.contentTabs = this.$store.state.contentTabs.concat(tab)
  280. }
  281. this.$store.state.sidebarMenuActiveName = tab.menuId
  282. this.$store.state.contentTabsActiveName = tab.name
  283. },
  284. // 获取当前管理员信息
  285. getUserInfo () {
  286. return this.$http.get('/idaas/sso/user/info').then(({ data: res }) => {
  287. if (res.code !== 0) {
  288. return this.$message.error(res.msg)
  289. }
  290. // console.log(res)
  291. this.$store.state.user.name = res.userInfo.displayName
  292. this.$store.state.user.organizations = res.userInfo.organizations[0].organizationName
  293. if (res.userInfo.extendField && res.userInfo.extendField.regionCode) {
  294. this.areaCode = res.userInfo.extendField.regionCode
  295. }
  296. }).catch(() => {})
  297. },
  298. // 获取权限
  299. getPermissions () {
  300. return this.$http.get('/idaas/ps/user/buttonList').then(({ data: res }) => {
  301. if (res.code !== 0) {
  302. return this.$message.error(res.msg)
  303. }
  304. this.$store.dispatch('permission', res.buttonList)
  305. window.SITE_CONFIG['permissions'] = res.buttonList
  306. }).catch(() => {})
  307. },
  308. getTitleLogo () {
  309. if (!this.areaCode) {
  310. return
  311. }
  312. // 生产环境
  313. this.$http.get('http://10.110.34.19:30600/sysbase/area/admin/getCityAreaByCode?areaCode=' + this.areaCode).then(({ data: res }) => {
  314. // 测试环境
  315. // this.$http.get('http://10.110.37.15:30600/sysbase/area/admin/getCityAreaByCode?areaCode=' + this.areaCode).then(({ data: res }) => {
  316. if (res.code !== '0') {
  317. return this.$message.error(res.msg)
  318. }
  319. res.result.areaTitle && (document.title = res.result.areaTitle)
  320. if (res.result.areaLogo) {
  321. // window.$('link[rel="shortcut icon"]').attr('href', res.result.areaLogo)
  322. window.$('.navbar-logo img').attr('src', res.result.areaLogo)
  323. }
  324. }).catch(() => {})
  325. }
  326. }
  327. }
  328. </script>