nav-tool-bar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <!-- 右边第一行,工具栏 -->
  2. <template>
  3. <div class="tools-panel">
  4. <div class="tools-left">
  5. <span title="折叠菜单" class="tool-fox" v-if="$root.isOpen == true" @click="$root.endOpen()">
  6. <i class="el-icon-s-fold"></i>
  7. </span>
  8. <span title="展开菜单" class="tool-fox" v-if="$root.isOpen == false" @click="$root.startOpen()">
  9. <i class="el-icon-s-unfold"></i>
  10. </span>
  11. <span title="搜索-input" class="tool-fox search-fox" :class=" isSearch ? 'search-fox-show' : '' ">
  12. <el-select v-model="searchText" size="mini" filterable placeholder="请输入菜单关键字" ref="search"
  13. @change="findMenuBySearch" @blur="closeSearch" @keyup.esc.native="closeSearch">
  14. <el-option v-for="item in searchList" :key="item.id" :label="item.text" :value="item.id"></el-option>
  15. </el-select>
  16. </span>
  17. <span title="搜索菜单" class="tool-fox" @click="closeSearch()" v-if="!isShowSearchInput">
  18. <i class="el-icon-search" style="font-weight: bold;"></i>
  19. </span>
  20. <span title="搜索菜单" class="tool-fox" @click="startSearch()" v-else>
  21. <i class="el-icon-search" style="font-weight: bold;"></i>
  22. </span>
  23. <span title="刷新" class="tool-fox" @click="$root.f5Tab($root.nativeTab)">
  24. <i class="el-icon-refresh-right" style="font-weight: bold;"></i>
  25. </span>
  26. <span title="当前时间" class="tool-fox">
  27. <span style="font-size: 0.90em;">{{nowTime}}</span>
  28. </span>
  29. </div>
  30. <div class="tools-right">
  31. <span title="点击登录" class="tool-fox" onclick="location.href='login.html'" v-if="$root.user == null">
  32. <span style="font-size: 0.8em; font-weight: bold; position: relative; top: -2px;">未登录</span>
  33. </span>
  34. <span title="我的信息" class="tool-fox user-info" style="padding: 0;" v-if="$root.user != null">
  35. <el-dropdown @command="handleCommand" trigger="click" size="medium">
  36. <span class="el-dropdown-link user-name" style="height: 100%; padding: 0 1em; display: inline-block;">
  37. <img :src="$root.user.avatar" class="user-avatar">
  38. <span>{{$root.user.username}}</span>
  39. <i class="el-icon-arrow-down el-icon--right"></i>
  40. </span>
  41. <el-dropdown-menu slot="dropdown">
  42. <el-dropdown-item v-for="drop in $root.dropList" :command="drop.name" :key="drop.name">{{drop.name}}</el-dropdown-item>
  43. </el-dropdown-menu>
  44. </el-dropdown>
  45. </span>
  46. <span title="主题" class="tool-fox" style="padding: 0;">
  47. <el-dropdown @command="toggleTheme" trigger="click" size="medium">
  48. <span class="el-dropdown-link" style="height: 100%; padding: 0 1em; display: inline-block;">
  49. <i class="el-icon-price-tag" style="font-weight: bold;"></i>
  50. <span style="font-size: 0.9em;">主题</span>
  51. </span>
  52. <el-dropdown-menu slot="dropdown">
  53. <el-dropdown-item :command="t.value" v-for="t in themeList" :key="t.name">
  54. <span :style=" $root.themeV == t.value ? 'color: #44f' : '' ">{{t.name}} </span>
  55. </el-dropdown-item>
  56. </el-dropdown-menu>
  57. </el-dropdown>
  58. </span>
  59. <span title="便签" class="tool-fox" @click="openNote()">
  60. <i class="el-icon-edit" style="font-weight: bold; font-size: 0.9em;"></i>
  61. <span style="font-size: 0.9em;">便签</span>
  62. </span>
  63. <span title="全屏" class="tool-fox" v-if="isFullScreen == false" @click="fullScreen()">
  64. <i class="el-icon-rank" style="font-weight: bold; transform: rotate(45deg)"></i>
  65. </span>
  66. <span title="退出全屏" class="tool-fox" v-if="isFullScreen == true" @click="outFullScreen()">
  67. <i class="el-icon-bottom-left" style="font-weight: bold; "></i>
  68. </span>
  69. </div>
  70. <!-- tab被拖拽时的遮罩(tab上拖拽:新窗口打开) -->
  71. <div class="shade-fox" v-if="$root.isDrag"
  72. @dragover="$event.preventDefault();"
  73. @drop="$event.preventDefault(); $event.stopPropagation(); $root.newWinTab($root.dragTab);">
  74. <span style="font-size: 16px;">新窗口打开</span>
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. module.exports = {
  80. data() {
  81. return {
  82. isSearch: false, // 当前是否处于搜索模式
  83. isShowSearchInput: true, // 是否显示打开搜索图标
  84. searchText: '', // 搜索框已经输入的字符
  85. searchList: [], // 搜索框 待选列表
  86. isFullScreen: false, // 是否处于全屏状态
  87. nowTime: '加载中...' , // 当前时间
  88. currInterval: null, // 刷新当前时间的定时器
  89. themeList: [ // 主题数组
  90. {name: '蓝色', value: '1'},
  91. {name: '绿色', value: '2'},
  92. {name: '白色', value: '3'},
  93. {name: '灰色', value: '4'},
  94. {name: '红色', value: '5'},
  95. {name: '紫色', value: '9'},
  96. {name: 'pro钛合金', value: '6'},
  97. {name: '沉淀黑蓝', value: '7'},
  98. {name: '简约灰色', value: '8'},
  99. {name: '简约草绿', value: '10'},
  100. ],
  101. }
  102. },
  103. methods: {
  104. // ------------------------------ 搜索相关 ------------------------------
  105. // 开启搜索
  106. startSearch: function() {
  107. this.searchText = '';
  108. this.isSearch = true;
  109. this.f5SearchList();
  110. setTimeout(function() {
  111. this.isShowSearchInput = false;
  112. this.$refs['search'].focus(); //.$refs['nav-tool-bar'].
  113. }.bind(this), 200);
  114. },
  115. // 关闭搜索
  116. closeSearch: function() {
  117. this.searchText = '';
  118. this.isSearch = false;
  119. setTimeout(function() {
  120. try{
  121. this.isShowSearchInput = true;
  122. document.querySelector('body>.el-select-dropdown.el-popper').style.display = 'none';
  123. }catch(e){throw e}
  124. }.bind(this), 200);
  125. },
  126. // 查找菜单
  127. findMenuBySearch: function(id) {
  128. this.$root.showMenuById(id);
  129. this.closeSearch();
  130. },
  131. // 刷新待选列表
  132. f5SearchList: function() {
  133. var searchList = [];
  134. let index = 1;
  135. function push(id, str) {
  136. searchList.push({id: id, text: (index++) + ". " + str});
  137. }
  138. // 遍历菜单
  139. let childList = this.$root.menuList;
  140. let showList = this.$root.showList;
  141. for (let menu1 of childList) {
  142. if(menu1.isShow === false || showList.indexOf(menu1.id + '') == -1) continue;
  143. if(menu1.childList) {
  144. for (let menu2 of menu1.childList) {
  145. if(menu2.isShow === false || showList.indexOf(menu2.id + '') == -1) continue;
  146. if(menu2.childList) {
  147. for (let menu3 of menu2.childList) {
  148. if(menu3.isShow === false || showList.indexOf(menu3.id + '') == -1) continue;
  149. if(menu3.childList) {
  150. for (let menu4 of menu3.childList) {
  151. if(menu4.isShow === false || showList.indexOf(menu4.id + '') == -1) continue;
  152. push(menu4.id, menu1.name + ' > ' + menu2.name + ' > ' + menu3.name + ' > ' + menu4.name);
  153. }
  154. } else {
  155. push(menu3.id, menu1.name + ' > ' + menu2.name + ' > ' + menu3.name);
  156. }
  157. }
  158. } else {
  159. push(menu2.id, menu1.name + ' > ' + menu2.name);
  160. }
  161. }
  162. } else {
  163. push(menu1.id, menu1.name);
  164. }
  165. }
  166. this.searchList = searchList;
  167. },
  168. // ------------------------------ 主题 ------------------------------
  169. // 切换主题
  170. toggleTheme: function(command) {
  171. // 开始切换
  172. this.$root.themeV = command + "";
  173. localStorage.setItem('themeV', command);
  174. for (var i = 0; i < this.themeList.length; i++) {
  175. if(this.themeList[i].value + '' == command + '') {
  176. this.$message('切换成功,' + this.themeList[i].name);
  177. }
  178. }
  179. },
  180. // ------------------------------ 全屏 ------------------------------
  181. // 进入全屏
  182. fullScreen: function() {
  183. this.isFullScreen = true;
  184. if(document.documentElement.RequestFullScreen){
  185. document.documentElement.RequestFullScreen();
  186. }
  187. //兼容火狐
  188. if(document.documentElement.mozRequestFullScreen){
  189. document.documentElement.mozRequestFullScreen();
  190. }
  191. //兼容谷歌等可以webkitRequestFullScreen也可以webkitRequestFullscreen
  192. if(document.documentElement.webkitRequestFullScreen){
  193. document.documentElement.webkitRequestFullScreen();
  194. }
  195. //兼容IE,只能写msRequestFullscreen
  196. if(document.documentElement.msRequestFullscreen){
  197. document.documentElement.msRequestFullscreen();
  198. }
  199. },
  200. // 退出全屏
  201. outFullScreen: function() {
  202. this.isFullScreen = false;
  203. if(document.exitFullScreen){
  204. document.exitFullscreen()
  205. }
  206. //兼容火狐
  207. if(document.mozCancelFullScreen){
  208. document.mozCancelFullScreen()
  209. }
  210. //兼容谷歌等
  211. if(document.webkitExitFullscreen){
  212. document.webkitExitFullscreen()
  213. }
  214. //兼容IE
  215. if(document.msExitFullscreen){
  216. document.msExitFullscreen()
  217. }
  218. },
  219. // ------------------------------ 其它 ------------------------------
  220. // 处理userinfo的下拉点击
  221. handleCommand: function(command) {
  222. this.$root.dropList.forEach(function(drop) {
  223. if(drop.name == command) {
  224. drop.click();
  225. }
  226. })
  227. },
  228. // 打开便签
  229. openNote: function() {
  230. var w = (document.body.clientWidth * 0.4) + 'px';
  231. var h = (document.body.clientHeight * 0.6) + 'px';
  232. var default_content = '一个简单的小便签, 关闭浏览器后再次打开仍然可以加载到上一次的记录, 你可以用它来记录一些临时资料';
  233. var value = localStorage.getItem('sa_admin_note') || default_content;
  234. var index = layer.prompt({
  235. title: '一个小便签',
  236. value: value,
  237. formType: 2,
  238. area: [w, h],
  239. btn: ['保存'],
  240. maxlength: 99999999,
  241. skin: 'layer-note-class'
  242. }, function(pass, index){
  243. layer.close(index)
  244. });
  245. var se = '#layui-layer' + index + ' .layui-layer-input';
  246. var d = document.querySelector(se);
  247. d.oninput = function() {
  248. localStorage.setItem('sa_admin_note', this.value);
  249. }
  250. },
  251. // 刷新时间
  252. initInterval: function() {
  253. if(this.currInterval) {
  254. clearInterval(this.currInterval);
  255. }
  256. // 一直更新时间
  257. this.currInterval = setInterval(function() {
  258. var da = new Date();
  259. var Y = da.getFullYear(); //年
  260. var M = da.getMonth() + 1; //月
  261. var D = da.getDate(); //日
  262. var h = da.getHours(); //小时
  263. var sx = "凌晨";
  264. if (h >= 6) {
  265. sx = "上午"
  266. }
  267. if (h >= 12) {
  268. sx = "下午";
  269. if (h >= 18) {
  270. sx = "晚上";
  271. }
  272. h -= 12;
  273. }
  274. var m = da.getMinutes(); //分
  275. var s = da.getSeconds(); //秒
  276. var z = ['日', '一', '二', '三', '四', '五', '六'][da.getDay()] ; //周几
  277. // z = z == 0 ? '日' : z;
  278. var zong = "";
  279. zong += Y + "-" + M + "-" + D + " " + sx + " " + h + ":" + m + ":" + s + " 周" + z;
  280. this.nowTime = zong;
  281. }.bind(this), 1000);
  282. }
  283. },
  284. created() {
  285. this.initInterval();
  286. }
  287. }
  288. </script>
  289. <style scoped>
  290. .tools-left{border: 0px #000 solid; float: left;}
  291. .tools-right{float: right;}
  292. .tool-fox{padding: 0 1em; display: inline-block; cursor: pointer;}
  293. .tool-fox, .tool-fox i{transition: all 0.2s;}
  294. .user-info{position: relative; top: -2px;}
  295. .user-avatar{width: 30px; height: 30px; border-radius: 50%; vertical-align: middle;}
  296. .user-info .user-name{font-size: 0.9em;}
  297. /* 搜素框 */
  298. .search-fox{display: inline-block; vertical-align: middle; overflow: hidden; max-width: 0px; padding: 0em 0em; margin-left: -5px; transition: all 0.2s;}
  299. .search-fox-show{display: inline-block; max-width: 500px; margin-left: 0px; padding: 0 1em;}
  300. .search-fox:hover{background-color: rgba(0,0,0,0) !important;}
  301. .search-fox .el-input__inner{border-radius: 0px; border-width: 0px; border-bottom-width: 1px; background-color: rgba(0,0,0,0);}
  302. .search-fox .el-input__icon{display: none;}
  303. /*800之下*/
  304. @media(max-width: 800px) {
  305. .tools-right{display: none;}
  306. }
  307. </style>