nav-tool-bar.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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">
  15. </el-option>
  16. </el-select>
  17. </span>
  18. <span title="搜索菜单" class="tool-fox" @click="closeSearch()" v-if="!isShowSearchInput">
  19. <i class="el-icon-search" style="font-weight: bold;"></i>
  20. </span>
  21. <span title="搜索菜单" class="tool-fox" @click="startSearch()" v-else>
  22. <i class="el-icon-search" style="font-weight: bold;"></i>
  23. </span>
  24. <span title="刷新" class="tool-fox" @click="$root.f5Tab($root.nativeTab)">
  25. <i class="el-icon-refresh-right" style="font-weight: bold;"></i>
  26. </span>
  27. <span title="当前时间" class="tool-fox">
  28. <span style="font-size: 0.90em;">{{ nowTime }}</span>
  29. </span>
  30. </div>
  31. <div class="tools-right">
  32. <span title="点击登录" class="tool-fox" onclick="location.href='login.html'" v-if="$root.user == null">
  33. <span style="font-size: 0.8em; font-weight: bold; position: relative; top: -2px;">未登录</span>
  34. </span>
  35. <span title="我的信息" class="tool-fox user-info" style="padding: 0;" v-if="$root.user != null">
  36. <el-dropdown @command="handleCommand" trigger="click" size="medium">
  37. <span class="el-dropdown-link user-name"
  38. style="height: 100%; padding: 0 1em; display: inline-block;">
  39. <img :src="$root.user.avatar" class="user-avatar">
  40. <span>{{ $root.user.username }}</span>
  41. <i class="el-icon-arrow-down el-icon--right"></i>
  42. </span>
  43. <el-dropdown-menu slot="dropdown">
  44. <el-dropdown-item v-for="drop in $root.dropList" :command="drop.name" :key="drop.name">
  45. {{ drop.name }}
  46. </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" @dragover="$event.preventDefault();"
  76. @drop="$event.preventDefault(); $event.stopPropagation(); $root.newWinTab($root.dragTab);">
  77. <span style="font-size: 16px;">新窗口打开</span>
  78. </div>
  79. </div>
  80. </template>
  81. <script>
  82. module.exports = {
  83. data() {
  84. return {
  85. msgTimmer: null,
  86. isSearch: false, // 当前是否处于搜索模式
  87. isShowSearchInput: true, // 是否显示打开搜索图标
  88. searchText: '', // 搜索框已经输入的字符
  89. searchList: [], // 搜索框 待选列表
  90. isFullScreen: false, // 是否处于全屏状态
  91. nowTime: '加载中...', // 当前时间
  92. currInterval: null, // 刷新当前时间的定时器
  93. themeList: [ // 主题数组
  94. {
  95. name: '蓝色',
  96. value: '1'
  97. },
  98. {
  99. name: '绿色',
  100. value: '2'
  101. },
  102. {
  103. name: '白色',
  104. value: '3'
  105. },
  106. {
  107. name: '灰色',
  108. value: '4'
  109. },
  110. {
  111. name: '红色',
  112. value: '5'
  113. },
  114. {
  115. name: '紫色',
  116. value: '9'
  117. },
  118. {
  119. name: 'pro钛合金',
  120. value: '6'
  121. },
  122. {
  123. name: '沉淀黑蓝',
  124. value: '7'
  125. },
  126. {
  127. name: '简约灰色',
  128. value: '8'
  129. },
  130. {
  131. name: '简约草绿',
  132. value: '10'
  133. },
  134. ],
  135. }
  136. },
  137. methods: {
  138. // ------------------------------ 搜索相关 ------------------------------
  139. // 开启搜索
  140. startSearch: function () {
  141. this.searchText = '';
  142. this.isSearch = true;
  143. this.f5SearchList();
  144. setTimeout(function () {
  145. this.isShowSearchInput = false;
  146. this.$refs['search'].focus(); //.$refs['nav-tool-bar'].
  147. }.bind(this), 200);
  148. },
  149. // 关闭搜索
  150. closeSearch: function () {
  151. this.searchText = '';
  152. this.isSearch = false;
  153. setTimeout(function () {
  154. try {
  155. this.isShowSearchInput = true;
  156. document.querySelector('body>.el-select-dropdown.el-popper').style.display =
  157. 'none';
  158. } catch (e) {
  159. throw e
  160. }
  161. }.bind(this), 200);
  162. },
  163. // 查找菜单
  164. findMenuBySearch: function (id) {
  165. this.$root.showMenuById(id);
  166. this.closeSearch();
  167. },
  168. // 刷新待选列表
  169. f5SearchList: function () {
  170. var searchList = [];
  171. let index = 1;
  172. function push(id, str) {
  173. searchList.push({
  174. id: id,
  175. text: (index++) + ". " + str
  176. });
  177. }
  178. // 遍历菜单
  179. let childList = this.$root.menuList;
  180. let showList = this.$root.showList;
  181. for (let menu1 of childList) {
  182. if (menu1.isShow === false || showList.indexOf(menu1.id + '') == -1) continue;
  183. if (menu1.childList) {
  184. for (let menu2 of menu1.childList) {
  185. if (menu2.isShow === false || showList.indexOf(menu2.id + '') == -1) continue;
  186. if (menu2.childList) {
  187. for (let menu3 of menu2.childList) {
  188. if (menu3.isShow === false || showList.indexOf(menu3.id + '') == -1) continue;
  189. if (menu3.childList) {
  190. for (let menu4 of menu3.childList) {
  191. if (menu4.isShow === false || showList.indexOf(menu4.id + '') == -1)
  192. continue;
  193. push(menu4.id, menu1.name + ' > ' + menu2.name + ' > ' + menu3.name +
  194. ' > ' + menu4.name);
  195. }
  196. } else {
  197. push(menu3.id, menu1.name + ' > ' + menu2.name + ' > ' + menu3.name);
  198. }
  199. }
  200. } else {
  201. push(menu2.id, menu1.name + ' > ' + menu2.name);
  202. }
  203. }
  204. } else {
  205. push(menu1.id, menu1.name);
  206. }
  207. }
  208. this.searchList = searchList;
  209. },
  210. // ------------------------------ 主题 ------------------------------
  211. // 切换主题
  212. toggleTheme: function (command) {
  213. // 开始切换
  214. this.$root.themeV = command + "";
  215. localStorage.setItem('themeV', command);
  216. for (var i = 0; i < this.themeList.length; i++) {
  217. if (this.themeList[i].value + '' == command + '') {
  218. this.$message('切换成功,' + this.themeList[i].name);
  219. }
  220. }
  221. },
  222. // ------------------------------ 全屏 ------------------------------
  223. // 进入全屏
  224. fullScreen: function () {
  225. this.isFullScreen = true;
  226. if (document.documentElement.RequestFullScreen) {
  227. document.documentElement.RequestFullScreen();
  228. }
  229. //兼容火狐
  230. if (document.documentElement.mozRequestFullScreen) {
  231. document.documentElement.mozRequestFullScreen();
  232. }
  233. //兼容谷歌等可以webkitRequestFullScreen也可以webkitRequestFullscreen
  234. if (document.documentElement.webkitRequestFullScreen) {
  235. document.documentElement.webkitRequestFullScreen();
  236. }
  237. //兼容IE,只能写msRequestFullscreen
  238. if (document.documentElement.msRequestFullscreen) {
  239. document.documentElement.msRequestFullscreen();
  240. }
  241. },
  242. // 退出全屏
  243. outFullScreen: function () {
  244. this.isFullScreen = false;
  245. if (document.exitFullScreen) {
  246. document.exitFullscreen()
  247. }
  248. //兼容火狐
  249. if (document.mozCancelFullScreen) {
  250. document.mozCancelFullScreen()
  251. }
  252. //兼容谷歌等
  253. if (document.webkitExitFullscreen) {
  254. document.webkitExitFullscreen()
  255. }
  256. //兼容IE
  257. if (document.msExitFullscreen) {
  258. document.msExitFullscreen()
  259. }
  260. },
  261. // ------------------------------ 其它 ------------------------------
  262. // 处理userinfo的下拉点击
  263. handleCommand: function (command) {
  264. this.$root.dropList.forEach(function (drop) {
  265. if (drop.name == command) {
  266. drop.click();
  267. }
  268. })
  269. },
  270. // 打开便签
  271. openNote: function () {
  272. var w = (document.body.clientWidth * 0.4) + 'px';
  273. var h = (document.body.clientHeight * 0.6) + 'px';
  274. var default_content = '一个简单的小便签, 关闭浏览器后再次打开仍然可以加载到上一次的记录, 你可以用它来记录一些临时资料';
  275. var value = localStorage.getItem('sa_admin_note') || default_content;
  276. var index = layer.prompt({
  277. title: '一个小便签',
  278. value: value,
  279. formType: 2,
  280. area: [w, h],
  281. btn: ['保存'],
  282. maxlength: 99999999,
  283. skin: 'layer-note-class'
  284. }, function (pass, index) {
  285. layer.close(index)
  286. });
  287. var se = '#layui-layer' + index + ' .layui-layer-input';
  288. var d = document.querySelector(se);
  289. d.oninput = function () {
  290. localStorage.setItem('sa_admin_note', this.value);
  291. }
  292. },
  293. // 刷新时间
  294. initInterval: function () {
  295. if (this.currInterval) {
  296. clearInterval(this.currInterval);
  297. }
  298. // 一直更新时间
  299. this.currInterval = setInterval(function () {
  300. var da = new Date();
  301. var Y = da.getFullYear(); //年
  302. var M = da.getMonth() + 1; //月
  303. var D = da.getDate(); //日
  304. var h = da.getHours(); //小时
  305. var sx = "凌晨";
  306. if (h >= 6) {
  307. sx = "上午"
  308. }
  309. if (h >= 12) {
  310. sx = "下午";
  311. if (h >= 18) {
  312. sx = "晚上";
  313. }
  314. h -= 12;
  315. }
  316. var m = da.getMinutes(); //分
  317. var s = da.getSeconds(); //秒
  318. var z = ['日', '一', '二', '三', '四', '五', '六'][da.getDay()]; //周几
  319. // z = z == 0 ? '日' : z;
  320. var zong = "";
  321. zong += Y + "-" + M + "-" + D + " " + sx + " " + h + ":" + m + ":" + s + " 周" + z;
  322. this.nowTime = zong;
  323. }.bind(this), 1000);
  324. },
  325. getBusinessMsg() {
  326. sa.ajaxNoLoading('/TbBusiness/getMsg', function (resp) {
  327. let msgList = resp.data;
  328. for (let i in msgList) {
  329. setTimeout(() => {
  330. this.popMsg(msgList[i])
  331. }, 1000)
  332. }
  333. }.bind(this))
  334. },
  335. popMsg(content) {
  336. this.$notify({
  337. title: '消息提醒',
  338. message: content,
  339. duration: 0
  340. });
  341. }
  342. },
  343. created() {
  344. this.getBusinessMsg();
  345. this.initInterval();
  346. },
  347. beforeDestroy() {
  348. if (this.msgTimmer != null) {
  349. clearInterval(this.msgTimmer);
  350. }
  351. }
  352. }
  353. </script>
  354. <style scoped>
  355. .tools-left {
  356. border: 0px #000 solid;
  357. float: left;
  358. }
  359. .tools-right {
  360. float: right;
  361. }
  362. .tool-fox {
  363. padding: 0 1em;
  364. display: inline-block;
  365. cursor: pointer;
  366. }
  367. .tool-fox,
  368. .tool-fox i {
  369. transition: all 0.2s;
  370. }
  371. .user-info {
  372. position: relative;
  373. top: -2px;
  374. }
  375. .user-avatar {
  376. width: 30px;
  377. height: 30px;
  378. border-radius: 50%;
  379. vertical-align: middle;
  380. }
  381. .user-info .user-name {
  382. font-size: 0.9em;
  383. }
  384. /* 搜素框 */
  385. .search-fox {
  386. display: inline-block;
  387. vertical-align: middle;
  388. overflow: hidden;
  389. max-width: 0px;
  390. padding: 0em 0em;
  391. margin-left: -5px;
  392. transition: all 0.2s;
  393. }
  394. .search-fox-show {
  395. display: inline-block;
  396. max-width: 500px;
  397. margin-left: 0px;
  398. padding: 0 1em;
  399. }
  400. .search-fox:hover {
  401. background-color: rgba(0, 0, 0, 0) !important;
  402. }
  403. .search-fox .el-input__inner {
  404. border-radius: 0px;
  405. border-width: 0px;
  406. border-bottom-width: 1px;
  407. background-color: rgba(0, 0, 0, 0);
  408. }
  409. .search-fox .el-input__icon {
  410. display: none;
  411. }
  412. /*800之下*/
  413. @media (max-width: 800px) {
  414. .tools-right {
  415. display: none;
  416. }
  417. }
  418. </style>