nav-tool-bar.vue 12 KB

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