e3421267df6e6736c55c77f990844c05ab19b901.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <div id="tabViewContainer">
  3. <div id="tabsItemBar" v-if="turnData=='0'">
  4. <div class="tabsContainer" ref="tabsContainer">
  5. <div class="tabsContent" :style="{marginLeft: marginLeft + 'px'}">
  6. <div class="tabsWidth" ref="tabsWidth">
  7. <div
  8. class="tags-view-item"
  9. :class="isActive(tag)?'tags-view-item-active':''"
  10. v-for="tag in openedTagViews"
  11. :key="tag.id"
  12. @click="changeCurrentView(tag,$event)">{{tag.menuName}} <span class='el-icon-close' @click.prevent.stop='removeView(tag)'></span>
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. <!-- <div class="operate-tags">-->
  18. <!-- &lt;!&ndash; <el-button type="text">暗色</el-button> &ndash;&gt;-->
  19. <!-- <i class="el-icon-arrow-left" @click="toPriv"></i>-->
  20. <!-- <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">-->
  21. <!-- <el-submenu index="1">-->
  22. <!-- <template slot="title">页签操作</template>-->
  23. <!-- <el-menu-item index="1-1">关闭当前</el-menu-item>-->
  24. <!-- &lt;!&ndash; <el-menu-item index="1-2">全部关闭</el-menu-item> &ndash;&gt;-->
  25. <!-- <el-menu-item index="1-3">除此之外全部关闭</el-menu-item>-->
  26. <!-- </el-submenu>-->
  27. <!-- </el-menu>-->
  28. <!-- <i class="el-icon-arrow-right" @click="toNext"></i>-->
  29. <!-- </div>-->
  30. </div>
  31. <div id="viewsItemBar" :style="{'height':viewHeight+'px'}">
  32. <!-- <div v-if="currentView.viewType=='component'" style="flex-basis:100%;height:100%;">
  33. <component :is="currentView.content"></component>
  34. </div>
  35. <div v-if="currentView.viewType=='html'" style="flex-basis:100%;height:100%;">
  36. {{currentView.content}}
  37. </div>
  38. <div v-if="currentView.viewType=='iframe'" style="flex-basis:100%;height:100%;">
  39. <iframe :src="currentView.content" frameborder="0" style="width:100%;height:100%;"></iframe>
  40. </div> -->
  41. <transition name="fade-transform" mode="out-in">
  42. <router-view :key="key" @turnHandle="turnHandle" v-if="show"></router-view>
  43. <keep-alive v-if="!show">
  44. <router-view :key="key" @turnHandle="turnHandle"></router-view>
  45. </keep-alive>
  46. </transition>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. /*
  52. @ 模块名称:tabsView视图
  53. @ 介绍:模仿vue-element-admin 制作的tabs视图架子
  54. @ author:wxcwater
  55. @ version:0.1.0
  56. @ to-do list:
  57. 1如果一个views都没开,要有一个默认的情况,不能展示大白板
  58. 2没考虑如果开的模块过多了 查航条怎么滚动的问题
  59. 3以下代码中增加的todo
  60. */
  61. import theme from '../../store/theme'
  62. export default {
  63. name: 'tabViewContainer',
  64. components:{
  65. },
  66. data () {
  67. return {
  68. turnData:"0",
  69. fullvalue:"",
  70. viewHeight:window.innerHeight - 86,
  71. editableTabsValue2: '2',
  72. openedTagViews: [],
  73. currentView: null,
  74. viewItemObj:{
  75. path:'/zhxxfw/zhjs',
  76. href:'/zhxxfw/zhjs',
  77. name:'综合监视',
  78. menuName:'综合监视',
  79. // redirect: 'firstpage',
  80. // component:mainPage,
  81. haveView:true,
  82. // children: [
  83. // {
  84. // path: 'firstpage',
  85. // component: () => import('../views/home/homeView.vue'),
  86. // name: 'firstpage',
  87. // meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
  88. // }
  89. // ]
  90. },
  91. activeIndex: '1',
  92. marginLeft: '0',
  93. themeName:'light'
  94. }
  95. },
  96. mounted:function(){
  97. this.viewItemObj.menuName = this.viewItemObj.name
  98. },
  99. computed:{
  100. key() {
  101. return this.$route.fullPath
  102. },
  103. msg(){
  104. return theme.state.testMsg
  105. },
  106. show(){
  107. if(this.$route.fullPath=="/yearSdPlanD" || this.$route.fullPath=="/detailYearSdPlanD" || this.$route.fullPath=="/planCheckSd" || this.$route.fullPath=="/home" || this.$route.fullPath=="/jchome"){
  108. return true;
  109. }else{
  110. return false;
  111. }
  112. }
  113. },
  114. methods:{
  115. turnHandle(code){
  116. if(code=="1"){
  117. this.turnData = "1";
  118. this.viewHeight = window.screen.height;
  119. this.$emit('turnHandle',"1");
  120. }else{
  121. this.turnData = "0";
  122. this.viewHeight = this.viewHeight-86;
  123. this.$emit('turnHandle',"0");
  124. }
  125. },
  126. handleSelect(key, keyPath) {
  127. if(key == '1-1'){
  128. this.removeView(this.currentView)
  129. }else if(key == '1-2'){
  130. this.openedTagViews = this.openedTagViews.filter(tab => tab.href == '/zhxxfw/zhjs');
  131. this.currentView = this.openedTagViews[0];
  132. this.$router.push(this.openedTagViews[0].href);
  133. }else if(key == '1-3'){
  134. this.openedTagViews = this.openedTagViews.filter(tab => tab.href == '/zhxxfw/zhjs' || tab.href == this.currentView.href);
  135. this.currentView = this.openedTagViews[0];
  136. this.$router.push(this.openedTagViews[0].href);
  137. }
  138. },
  139. isActive(tag) {
  140. if(tag.menuName == this.currentView.menuName){
  141. return true;
  142. }
  143. return false;
  144. },
  145. addView:function(viewItem){
  146. //newModuleParam包含模块名称,模块类型(component/iframe/html),content(viewsId/src);
  147. //to-do 如果传入的模块已经在打开队列中 应当激活而并非再添加一个一样的
  148. var newViewObject = {
  149. viewName: viewItem.menuName,
  150. };
  151. var _self = this;
  152. // console.log(viewItem.menuName);
  153. var isAdd = false;
  154. // console.log(this.openedTagViews)
  155. this.openedTagViews.forEach(item =>{
  156. // console.log(item)
  157. if(item.menuName == viewItem.menuName){
  158. _self.changeCurrentView(item);
  159. // console.log('have changed');
  160. isAdd = true;
  161. }
  162. });
  163. if(!isAdd && viewItem.href && viewItem.href.indexOf('http') == -1){
  164. this.openedTagViews.push(viewItem);
  165. this.currentView = viewItem;
  166. }
  167. if(viewItem.href == '/szygl/szygk/random'){
  168. this.$router.push('/szygl/szygk/'+Math.random());
  169. }else if(viewItem.href && viewItem.href.indexOf('http') > -1){
  170. window.open(viewItem.href)
  171. }else{
  172. if(viewItem.href){
  173. this.$router.push(viewItem.href);
  174. }
  175. this.$nextTick(() => { //使用nextTick为了保证dom元素都已经渲染完毕
  176. if(this.$refs.tabsWidth.offsetWidth > this.$refs.tabsContainer.offsetWidth){
  177. this.marginLeft = -( this.$refs.tabsWidth.offsetWidth - this.$refs.tabsContainer.offsetWidth )
  178. }
  179. });
  180. }
  181. },
  182. removeView:function(tagParam){
  183. // let tabs = this.openedTagViews;
  184. if(tagParam.href != '/zhxxfw/zhjs'){
  185. let deleteViewName = tagParam.menuName;
  186. this.openedTagViews = this.openedTagViews.filter(tab => tab.menuName !== deleteViewName);
  187. if(tagParam == this.currentView && this.openedTagViews.length>0){
  188. this.currentView = this.openedTagViews[0];
  189. this.$router.push(this.openedTagViews[0].href);
  190. }else if(this.openedTagViews.length==0){
  191. this.$router.push('/');
  192. }
  193. }
  194. },
  195. changeCurrentView:function(newView,event){
  196. // alert(newView.name);
  197. this.currentView = newView;
  198. this.$router.push(newView.href);
  199. // console.log(this.openedTagViews)
  200. // console.log(this.currentView)
  201. this.$emit('currentViewChange',{'newView':this.currentView});
  202. let e = event || window.event
  203. if(e.clientX < 100){
  204. this.toPriv()
  205. }
  206. if(e.clientX > 1100){
  207. this.toNext()
  208. }
  209. },
  210. toPriv(){
  211. this.marginLeft = '0'
  212. },
  213. toNext(){
  214. let clentTabsWidth = this.$refs.tabsWidth.offsetWidth + this.$refs.tabsWidth.offsetLeft
  215. if(this.$refs.tabsWidth.offsetWidth > this.$refs.tabsContainer.offsetWidth && clentTabsWidth > document.body.clientWidth - 200){
  216. this.marginLeft = this.marginLeft - 300
  217. }
  218. }
  219. },
  220. watch:{
  221. msg(n,o){
  222. if(n == 'dark'){
  223. this.themeName = 'dark';
  224. }else{
  225. this.themeName = 'light';
  226. }
  227. },
  228. currentOrgId(val){
  229. this.localRefresh = false // 通过v-if移除router-view节点
  230. this.$nextTick(() => {
  231. this.localRefresh = true // DOM更新后再通过v-if添加router-view节点
  232. })
  233. }
  234. }
  235. }
  236. </script>
  237. <style>
  238. #tabViewContainer{
  239. width: 100% ;
  240. min-height:100%;
  241. display: flex;
  242. flex-direction: column;
  243. /* justify-content: center; */
  244. align-items: stretch;
  245. }
  246. #tabsItemBar{
  247. background: var(--theme_head_bar);
  248. z-index: 9;
  249. width: 100%;
  250. position: relative;
  251. box-shadow: 0 1px 3px 0 rgba(0,0,0,.12), 0 0 3px 0 rgba(0,0,0,.04);
  252. }
  253. #tabViewContainer .light_back{
  254. background: linear-gradient(0deg,rgba(8,146,233,1),rgba(9,169,244,1),rgba(122,210,255,1));
  255. }
  256. #tabViewContainer .dark_back{
  257. background:linear-gradient(180deg,rgba(25,35,75,1),rgba(33,38,75,1));
  258. }
  259. .tabsContainer{
  260. width: 88%;
  261. overflow: hidden;
  262. }
  263. .tabsContent{
  264. width: 5000px;
  265. overflow: hidden;
  266. margin-left: 0;
  267. transition: all .8s;
  268. -moz-transition: all .8s;
  269. -webkit-transition: all .8s;
  270. -o-transition:all .8s;
  271. }
  272. .tabsContent .tabsWidth{
  273. float: left;
  274. /* flex-basis: 5%; */
  275. height: 30px;
  276. /* background-color: aqua; */
  277. display: flex;
  278. flex-direction: row;
  279. justify-content: flex-start;
  280. align-items: center;
  281. /* padding-left:5px; */
  282. }
  283. .operate-tags{
  284. position: absolute;
  285. top: 1px;
  286. right: 1px;
  287. padding: 0 10px;
  288. font-size: 14px;
  289. color: #fff;
  290. display: flex;
  291. align-items: center;
  292. height: 28px;
  293. line-height: 28px;
  294. /*background-color: #009cee;*/
  295. border-radius: 5px;
  296. }
  297. .operate-tags .el-menu{
  298. /*background-color: #009cee;*/
  299. }
  300. .operate-tags .el-submenu__title i{
  301. color: #fff;
  302. }
  303. .operate-tags .el-menu--horizontal>.el-submenu .el-submenu__title{
  304. height: 26px;
  305. line-height: 26px;
  306. color: #fff;
  307. }
  308. /*.operate-tags .el-menu--horizontal>.is-opened .el-submenu__title{*/
  309. /*background-color: #009aed;*/
  310. /*}*/
  311. /*.operate-tags .el-menu--horizontal>.el-submenu .el-submenu__title:hover{*/
  312. /*background-color: #009aed;*/
  313. /*}*/
  314. .operate-tags .el-menu--horizontal{
  315. border-bottom: none;
  316. }
  317. .operate-tags .el-submenu__title{
  318. padding: 0 10px;
  319. }
  320. .operate-tags .el-menu--horizontal>.el-submenu.is-active .el-submenu__title{
  321. border-bottom: none;
  322. }
  323. .operate-tags .el-menu--horizontal>.el-submenu.is-active .el-submenu__title{
  324. border-bottom: none;
  325. }
  326. .operate-tags .el-icon-arrow-left,.operate-tags .el-icon-arrow-right{
  327. color: #fff;
  328. font-size: 14px;
  329. font-weight: bold;
  330. cursor: pointer;
  331. padding: 2px;
  332. }
  333. .operate-tags .el-icon-arrow-left:hover{
  334. color: #003aed;
  335. }
  336. .operate-tags .el-icon-arrow-right:hover{
  337. color: #003aed;
  338. }
  339. #viewsItemBar{
  340. /* flex-basis: 95%; */
  341. flex-direction: row;
  342. justify-content: center;
  343. align-items: stretch;
  344. overflow: hidden;
  345. }
  346. .tags-view-item {
  347. display: inline-block;
  348. position: relative;
  349. height: 80%;
  350. /* line-height: 26px; */
  351. /* border: 1px solid #d8dce5; */
  352. color:rgba(255,255,255,1);
  353. /*background: #fff;*/
  354. padding: 0 4px;
  355. font-size: 12px;
  356. margin-left: 5px;
  357. /* margin-top: 4px; */
  358. display: flex;
  359. flex-direction: row;
  360. justify-content: space-around;
  361. align-items: center;
  362. transition: 0.5s all;
  363. cursor: pointer;
  364. }
  365. .tags-view-item:first-of-type{
  366. margin-left: 5px;
  367. }
  368. .tags-view-item-active{
  369. background:var(--theme_head_bar_active);
  370. color:rgba(255,255,255,1);
  371. border-color: #147DF4;
  372. border-radius: 3px;
  373. }
  374. .tags-view-item-active::before {
  375. content: '';
  376. background: #fff;
  377. display: inline-block;
  378. width: 7px;
  379. height: 7px;
  380. border-radius: 50%;
  381. position: relative;
  382. margin-right: 6px;
  383. }
  384. .tags-view-item .el-icon-close{
  385. margin-left: 4px;
  386. cursor: pointer;
  387. transform: rotate(0deg);
  388. transition: transform 0.1s linear;
  389. }
  390. .tags-view-item .el-icon-close:hover{
  391. transform: rotate(90deg)
  392. }
  393. .el-dropdown-menu__item--divided:before, .el-menu, .el-menu--horizontal>.el-menu-item:not(.is-disabled):focus, .el-menu--horizontal>.el-menu-item:not(.is-disabled):hover, .el-menu--horizontal>.el-submenu .el-submenu__title:hover {
  394. background: none !important;
  395. }
  396. .el-menu--horizontal {
  397. border-right: none;
  398. border-bottom: none !important;
  399. }
  400. </style>