nav.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. <template>
  18. <div class="nav-model">
  19. <router-link :to="{ path: '/home'}" tag="div" class="logo-box">
  20. <a href="javascript:"></a>
  21. </router-link>
  22. <div class="nav-box">
  23. <div class="clearfix list">
  24. <div class="nav-links">
  25. <router-link :to="{ path: '/home'}" tag="a" active-class="active">
  26. <span><em class="ansiconfont ans-icon-home-empty"></em>{{$t('Home')}}</span><strong></strong>
  27. </router-link>
  28. </div>
  29. </div>
  30. <div class="clearfix list">
  31. <div class="nav-links">
  32. <router-link :to="{ path: '/projects'}" tag="a" active-class="active">
  33. <span><em class="ansiconfont ans-icon-setting"></em>{{$t('Project Manage')}}</span><strong></strong>
  34. </router-link>
  35. </div>
  36. </div>
  37. <div class="clearfix list">
  38. <div class="nav-links">
  39. <router-link :to="{ path: '/resource'}" tag="a" active-class="active">
  40. <span><em class="ansiconfont ans-icon-folder-empty"></em>{{$t('Resources manage')}}</span><strong></strong>
  41. </router-link>
  42. </div>
  43. </div>
  44. <div class="clearfix list">
  45. <div class="nav-links">
  46. <router-link :to="{ path: '/datasource'}" tag="a" active-class="active">
  47. <span><em class="ansiconfont ans-icon-database"></em>{{$t('Datasource manage')}}</span><strong></strong>
  48. </router-link>
  49. </div>
  50. </div>
  51. <div class="clearfix list">
  52. <div class="nav-links">
  53. <router-link :to="{ path: '/monitor'}" tag="a" active-class="active">
  54. <span><em class="ansiconfont ans-icon-monitor"></em>{{$t('Monitor')}}</span><strong></strong>
  55. </router-link>
  56. </div>
  57. </div>
  58. <div class="clearfix list" >
  59. <div class="nav-links">
  60. <router-link :to="{ path: '/security'}" tag="a" active-class="active" v-ps="['ADMIN_USER']">
  61. <span><em class="ansiconfont ans-icon-shield"></em>{{$t('Security')}}</span><strong></strong>
  62. </router-link>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="right">
  67. <!--<span class="docs">
  68. <a :href="docLink">doc</a>
  69. </span>-->
  70. <span class="lang">
  71. <x-poptip
  72. style="width: 80px"
  73. trigger="click">
  74. <div class="lrns-list">
  75. <a href="javascript:" @click="_toggleLanguage(item.code)" v-for="(item,$index) in localeList" :key="$index"><span>{{item.name}}</span></a>
  76. </div>
  77. <div class="login-model" slot="reference">
  78. <span>{{activeLocale.name}}</span>
  79. <em class="ans-icon-arrow-down"></em>
  80. </div>
  81. </x-poptip>
  82. </span>
  83. <x-poptip
  84. ref="login"
  85. trigger="click"
  86. v-model="isLogin"
  87. placement="bottom-end">
  88. <div class="lrns-list">
  89. <a href="javascript:" @click="_goAccount">
  90. <em class="ans-icon-user-empty"></em>
  91. <span>{{$t('User Information')}}</span>
  92. </a>
  93. <a href="javascript:" @click="_signOut">
  94. <em class="ans-icon-off"></em>
  95. <span>{{$t('Logout')}}</span>
  96. </a>
  97. </div>
  98. <div class="login-model" slot="reference">
  99. <em class="ans-icon-user-solid"></em>
  100. <span>{{userInfo.userName}}</span>
  101. <em class="ans-icon-arrow-down"></em>
  102. </div>
  103. </x-poptip>
  104. </div>
  105. <div class="file-update-model" @click="_toggleArchive" v-if="isUpdate">
  106. <div class="icon-cloud">
  107. <em class="ans ans-icon-upload"></em>
  108. </div>
  109. <div class="progress-box">
  110. <m-progress-bar :value="progress" text-placement="bottom"></m-progress-bar>
  111. </div>
  112. </div>
  113. <div class="adaptive-m-nav">
  114. <div class="m-nav-box ">
  115. <a href="javascript:" @click="mIsNav = !mIsNav"><em class="ans-icon-database"></em></a>
  116. </div>
  117. <div class="m-title-box">
  118. <div class="logo-m"></div>
  119. </div>
  120. <div class="m-user-box">
  121. <a href="javascript:" @click="_goAccount"><em class="ans-icon-user-empty"></em></a>
  122. </div>
  123. <transition name="slide-fade">
  124. <div class="m-nav-list" v-if="mIsNav">
  125. <ul @click="mIsNav = false">
  126. <router-link :to="{ path: '/home'}" tag="li" active-class="active">
  127. <em class="ans-icon-home-empty"></em>
  128. <span>{{$t('Home')}}</span>
  129. </router-link>
  130. <router-link :to="{ path: '/projects'}" tag="li" active-class="active">
  131. <em class="ans-icon-setting"></em>
  132. <span>{{$t('Project manage')}}</span>
  133. </router-link>
  134. <router-link :to="{ path: '/resource'}" tag="li" active-class="active">
  135. <em class="ans-icon-folder-empty"></em>
  136. <span>{{$t('Resources manage')}}</span>
  137. </router-link>
  138. <router-link :to="{ path: '/datasource'}" tag="li" active-class="active">
  139. <em class="ans-icon-database"></em>
  140. <span>{{$t('Datasource manage')}}</span>
  141. </router-link>
  142. <router-link :to="{ path: '/security'}" tag="li" active-class="active" v-ps="['ADMIN_USER']">
  143. <em class="ans-icon-shield"></em>
  144. <span>{{$t('Security')}}</span>
  145. </router-link>
  146. </ul>
  147. </div>
  148. </transition>
  149. </div>
  150. </div>
  151. </template>
  152. <script>
  153. import _ from 'lodash'
  154. import cookies from 'js-cookie'
  155. import { mapState, mapActions } from 'vuex'
  156. import { findComponentDownward } from '@/module/util/'
  157. import mFileUpdate from '@/module/components/fileUpdate/fileUpdate'
  158. import mFileChildUpdate from '@/module/components/fileUpdate/fileChildUpdate'
  159. import mResourceChildUpdate from '@/module/components/fileUpdate/resourceChildUpdate'
  160. import mDefinitionUpdate from '@/module/components/fileUpdate/definitionUpdate'
  161. import mProgressBar from '@/module/components/progressBar/progressBar'
  162. import { findLocale, localeList } from '@/module/i18n/config'
  163. export default {
  164. name: 'roof-nav',
  165. data () {
  166. return {
  167. // Whether to drag
  168. isDrag: false,
  169. // Upload progress
  170. progress: 0,
  171. // Whether to upload
  172. isUpdate: false,
  173. // Whether to log in
  174. isLogin: false,
  175. // Mobile compatible navigation
  176. mIsNav: false,
  177. // Take the language list data to get rid of the language pack
  178. localeList: _.map(_.cloneDeep(localeList()), v => _.omit(v, ['locale'])),
  179. // Selected language
  180. activeLocale: '',
  181. // Environmental variable
  182. docLink: ''
  183. }
  184. },
  185. methods: {
  186. ...mapActions('user', ['signOut']),
  187. /**
  188. * User Info
  189. */
  190. _goAccount () {
  191. this.isLogin = false
  192. this.$router.push({ name: 'account' })
  193. },
  194. /**
  195. * Upload (for the time being)
  196. */
  197. _fileUpdate (type) {
  198. if (this.progress) {
  199. this._toggleArchive()
  200. return
  201. }
  202. let self = this
  203. let modal = this.$modal.dialog({
  204. closable: false,
  205. showMask: true,
  206. escClose: true,
  207. className: 'update-file-modal',
  208. transitionName: 'opacityp',
  209. render (h) {
  210. if(type === 'DEFINITION'){
  211. return h(mDefinitionUpdate, {
  212. on: {
  213. onProgress (val) {
  214. self.progress = val
  215. },
  216. onUpdate () {
  217. findComponentDownward(self.$root, `definition-list-index`)._updateList()
  218. self.isUpdate = false
  219. self.progress = 0
  220. modal.remove()
  221. },
  222. onArchive () {
  223. self.isUpdate = true
  224. },
  225. close () {
  226. self.progress = 0
  227. modal.remove()
  228. }
  229. },
  230. props: {
  231. type: type
  232. }
  233. })
  234. }else{
  235. return h(mFileUpdate, {
  236. on: {
  237. onProgress (val) {
  238. self.progress = val
  239. },
  240. onUpdate () {
  241. findComponentDownward(self.$root, `resource-list-index-${type}`)._updateList()
  242. self.isUpdate = false
  243. self.progress = 0
  244. modal.remove()
  245. },
  246. onArchive () {
  247. self.isUpdate = true
  248. },
  249. close () {
  250. self.progress = 0
  251. modal.remove()
  252. }
  253. },
  254. props: {
  255. type: type
  256. }
  257. })
  258. }
  259. }
  260. })
  261. },
  262. _fileChildUpdate (type,data) {
  263. if (this.progress) {
  264. this._toggleArchive()
  265. return
  266. }
  267. let self = this
  268. let modal = this.$modal.dialog({
  269. closable: false,
  270. showMask: true,
  271. escClose: true,
  272. className: 'update-file-modal',
  273. transitionName: 'opacityp',
  274. render (h) {
  275. return h(mFileChildUpdate, {
  276. on: {
  277. onProgress (val) {
  278. self.progress = val
  279. },
  280. onUpdate () {
  281. findComponentDownward(self.$root, `resource-list-index-${type}`)._updateList(data)
  282. self.isUpdate = false
  283. self.progress = 0
  284. modal.remove()
  285. },
  286. onArchive () {
  287. self.isUpdate = true
  288. },
  289. close () {
  290. self.progress = 0
  291. modal.remove()
  292. }
  293. },
  294. props: {
  295. type: type,
  296. id: data
  297. }
  298. })
  299. }
  300. })
  301. },
  302. _resourceChildUpdate (type,data) {
  303. if (this.progress) {
  304. this._toggleArchive()
  305. return
  306. }
  307. let self = this
  308. let modal = this.$modal.dialog({
  309. closable: false,
  310. showMask: true,
  311. escClose: true,
  312. className: 'update-file-modal',
  313. transitionName: 'opacityp',
  314. render (h) {
  315. return h(mResourceChildUpdate, {
  316. on: {
  317. onProgress (val) {
  318. self.progress = val
  319. },
  320. onUpdate () {
  321. findComponentDownward(self.$root, `resource-list-index-${type}`)._updateList(data)
  322. self.isUpdate = false
  323. self.progress = 0
  324. modal.remove()
  325. },
  326. onArchive () {
  327. self.isUpdate = true
  328. },
  329. close () {
  330. self.progress = 0
  331. modal.remove()
  332. }
  333. },
  334. props: {
  335. type: type,
  336. id: data
  337. }
  338. })
  339. }
  340. })
  341. },
  342. /**
  343. * Upload popup layer display
  344. */
  345. _toggleArchive () {
  346. $('.update-file-modal').show()
  347. },
  348. /**
  349. * sign out
  350. */
  351. _signOut () {
  352. this.signOut()
  353. },
  354. /**
  355. * Language switching
  356. */
  357. _toggleLanguage (language) {
  358. cookies.set('language', language, { path: '/' })
  359. setTimeout(() => {
  360. window.location.reload()
  361. }, 100)
  362. }
  363. },
  364. created () {
  365. let language = cookies.get('language')
  366. this.activeLocale = language ? findLocale(language) : '中文'
  367. this.docLink = process.env.NODE_ENV === 'true' ? 'docs' : `/view/docs/${this.activeLocale.code}/_book` // eslint-disable-line
  368. },
  369. computed: {
  370. ...mapState('user', ['userInfo'])
  371. },
  372. components: { mFileUpdate, mProgressBar, mDefinitionUpdate }
  373. }
  374. </script>
  375. <style lang="scss" rel="stylesheet/scss">
  376. .nav-model {
  377. height: 60px;
  378. background: #2D303A;
  379. box-shadow: 0 3px 5px rgba(0, 0, 0, 0.3);
  380. position: relative;
  381. .m-title-box {
  382. text-align: center;
  383. .logo-m {
  384. width: 36px;
  385. height: 36px;
  386. margin: 0 auto;
  387. position: relative;
  388. top: 12px;
  389. }
  390. }
  391. .logo-box {
  392. position: absolute;
  393. left: 10px;
  394. top: 8px;
  395. cursor: pointer;
  396. >a {
  397. width: 180px;
  398. height: 46px;
  399. display: block;
  400. background: url("./logo.svg") no-repeat;
  401. }
  402. }
  403. .nav-box {
  404. height: 60px;
  405. line-height: 60px;
  406. position: absolute;
  407. left: 220px;
  408. top: 0;
  409. .list {
  410. width: 106px;
  411. float: left;
  412. position: relative;
  413. cursor: pointer;
  414. margin-right: 14px;
  415. .nav-links {
  416. height: 60px;
  417. a {
  418. position: relative;
  419. text-decoration: none;
  420. font-size: 15px;
  421. color: #333;
  422. display: inline-block;
  423. float: left;
  424. text-align: center;
  425. span {
  426. display: block;
  427. width: 106px;
  428. color: #fff;
  429. .ansiconfont {
  430. vertical-align: -2px;
  431. font-size: 22px;
  432. margin-right: 4px;
  433. }
  434. }
  435. &:hover {
  436. span {
  437. color: #2d8cf0;
  438. }
  439. }
  440. &.active {
  441. span {
  442. color: #2D8BF0;
  443. i {
  444. color: #2d8cf0;
  445. }
  446. }
  447. b {
  448. height: 2px;
  449. background: #2d8cf0;
  450. display: block;
  451. margin-top: -2px;
  452. }
  453. }
  454. }
  455. }
  456. }
  457. }
  458. .right {
  459. position: absolute;
  460. right: 0;
  461. top: 0;
  462. .ans-poptip {
  463. min-width: 120px;
  464. }
  465. >.lang {
  466. .ans-poptip {
  467. min-width: 80px;
  468. }
  469. }
  470. >.docs {
  471. padding-right: 20px;
  472. a {
  473. color: #fff;
  474. font-size: 14px;
  475. vertical-align: middle;
  476. &:hover {
  477. color: #2d8bf0;
  478. }
  479. }
  480. }
  481. .current-project {
  482. height: 60px;
  483. line-height: 56px;
  484. display: inline-block;
  485. margin-right: 16px;
  486. cursor: pointer;
  487. i {
  488. font-size: 18px;
  489. vertical-align: middle;
  490. &:nth-child(1) {
  491. font-size: 20px;
  492. color:#2d8cf0;
  493. }
  494. }
  495. span {
  496. color: #333;
  497. vertical-align: middle;
  498. font-size: 14px;
  499. }
  500. &:hover {
  501. span {
  502. color: #2d8cf0;
  503. }
  504. }
  505. }
  506. .login-model {
  507. display: inline-block;
  508. margin-right: 20px;
  509. cursor: pointer;
  510. margin-top: 16px;
  511. em {
  512. font-size: 18px;
  513. vertical-align: middle;
  514. color: #fff;
  515. }
  516. span {
  517. color: #fff;
  518. vertical-align: middle;
  519. font-size: 14px;
  520. }
  521. &:hover {
  522. >i,>span {
  523. color: #2d8cf0;
  524. }
  525. }
  526. }
  527. .lrns-list {
  528. margin: -6px 0;
  529. a {
  530. display: block;
  531. height: 30px;
  532. line-height: 30px;
  533. font-size: 14px;
  534. &:hover {
  535. i,span {
  536. color: #2d8cf0;
  537. }
  538. }
  539. }
  540. }
  541. }
  542. .file-update-model {
  543. position: absolute;
  544. right: 160px;
  545. top: 18px;
  546. cursor: pointer;
  547. .progress-box {
  548. width: 240px;
  549. }
  550. .icon-cloud {
  551. position: absolute;
  552. left: -34px;
  553. top: 2px;
  554. > i {
  555. font-size: 22px;
  556. color: #2d8cf0;
  557. }
  558. }
  559. }
  560. }
  561. </style>