topWindow.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <view class="header">
  3. <!-- #ifdef H5 -->
  4. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  5. style="position: absolute; width: 0; height: 0">
  6. <symbol xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" id="icon-bug">
  7. <path
  8. d="M127.88 73.143c0 1.412-.506 2.635-1.518 3.669-1.011 1.033-2.209 1.55-3.592 1.55h-17.887c0 9.296-1.783 17.178-5.35 23.645l16.609 17.044c1.011 1.034 1.517 2.257 1.517 3.67 0 1.412-.506 2.635-1.517 3.668-.958 1.033-2.155 1.55-3.593 1.55-1.438 0-2.635-.517-3.593-1.55l-15.811-16.063a15.49 15.49 0 0 1-1.196 1.06c-.532.434-1.65 1.208-3.353 2.322a50.104 50.104 0 0 1-5.192 2.974c-1.758.87-3.94 1.658-6.546 2.364-2.607.706-5.189 1.06-7.748 1.06V47.044H58.89v73.062c-2.716 0-5.417-.367-8.106-1.102-2.688-.734-5.003-1.631-6.945-2.692a66.769 66.769 0 0 1-5.268-3.179c-1.571-1.057-2.73-1.94-3.476-2.65L33.9 109.34l-14.611 16.877c-1.066 1.14-2.344 1.711-3.833 1.711-1.277 0-2.422-.434-3.434-1.304-1.012-.978-1.557-2.187-1.635-3.627-.079-1.44.333-2.705 1.236-3.794l16.129-18.51c-3.087-6.197-4.63-13.644-4.63-22.342H5.235c-1.383 0-2.58-.517-3.592-1.55S.125 74.545.125 73.132c0-1.412.506-2.635 1.518-3.668 1.012-1.034 2.21-1.55 3.592-1.55h17.887V43.939L9.308 29.833c-1.012-1.033-1.517-2.256-1.517-3.669 0-1.412.505-2.635 1.517-3.668 1.012-1.034 2.21-1.55 3.593-1.55s2.58.516 3.593 1.55l13.813 14.106h67.396l13.814-14.106c1.012-1.034 2.21-1.55 3.592-1.55 1.384 0 2.581.516 3.593 1.55 1.012 1.033 1.518 2.256 1.518 3.668 0 1.413-.506 2.636-1.518 3.67l-13.814 14.105v23.975h17.887c1.383 0 2.58.516 3.593 1.55 1.011 1.033 1.517 2.256 1.517 3.668l-.005.01zM89.552 26.175H38.448c0-7.23 2.489-13.386 7.466-18.469C50.892 2.623 56.92.082 64 .082c7.08 0 13.108 2.541 18.086 7.624 4.977 5.083 7.466 11.24 7.466 18.469z">
  9. </path>
  10. </symbol>
  11. </svg>
  12. <!-- #endif -->
  13. <view class="navbar" :class="{'navbar-mini':!matchLeftWindow,'popup-menu':popupMenuOpened}">
  14. <view class="navbar-left">
  15. <view class="logo pointer" @click="linkTo">
  16. <image :src="logo" mode="heightFix"></image>
  17. <text>{{appName}}</text>
  18. </view>
  19. <uni-icons @click="toggleSidebar" type="bars" class="menu-icon" size="30" color="#999"></uni-icons>
  20. </view>
  21. <view class="navbar-middle">
  22. <text class="title-text">{{navigationBarTitleText}}</text>
  23. </view>
  24. <view class="navbar-right pointer">
  25. <!-- #ifdef H5 -->
  26. <view v-if="logs.length" @click="showErrorLogs" class="menu-item debug pointer">
  27. <svg class="svg-icon">
  28. <use xlink:href="#icon-bug"></use>
  29. </svg>
  30. <uni-badge class="debug-badge" :text="logs.length" type="error"></uni-badge>
  31. </view>
  32. <!-- #endif -->
  33. <picker mode="selector" :range="langs" range-key="text" @change="changeLanguage">
  34. <view class="admin-icons-lang flex lang-icon" />
  35. </picker>
  36. <view class="" style="position: relative;">
  37. <view v-show="userInfo.nickname || userInfo.username || userInfo.mobile || userInfo.email" class="navbar-user" @click="togglePopupMenu">
  38. <view class="admin-icons-user user-icon" />
  39. <view class="username ml-s"><text>{{userInfo.nickname || userInfo.username || userInfo.mobile || userInfo.email}}</text></view>
  40. <uni-icons class="arrowdown" type="arrowdown" color="#666" size="13"></uni-icons>
  41. </view>
  42. <view class="uni-mask" @click="togglePopupMenu" />
  43. <view class="navbar-menu">
  44. <template v-if="userInfo.nickname || userInfo.username || userInfo.mobile || userInfo.email">
  45. <view class="menu-item hover-highlight" @click="changePassword">
  46. <text>{{ $t("topwindow.text.changePwd") }}</text>
  47. </view>
  48. <view class="menu-item hover-highlight">
  49. <text class="logout pointer" @click="logout">{{ $t("topwindow.text.signOut") }}</text>
  50. </view>
  51. </template>
  52. <view class="popup-menu__arrow"></view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <uni-popup ref="errorLogsPopup" type="center">
  58. <view class="modal">
  59. <scroll-view class="modal-content" scroll-y="true">
  60. <error-log class="error-table" />
  61. </scroll-view>
  62. </view>
  63. </uni-popup>
  64. <!-- 沉余代码,临时处理 uni-datetime-picker 国际化不生效的问题 -->
  65. <!-- #ifdef H5 -->
  66. <uni-datetime-picker type="date" v-show="false"></uni-datetime-picker>
  67. <!-- #endif -->
  68. </view>
  69. </template>
  70. <script>
  71. import {
  72. mapState
  73. } from 'vuex'
  74. import uniIdPagesCommon from '@/uni_modules/uni-id-pages/common/common'
  75. import errorLog from '@/windows/components/error-log.vue'
  76. import config from '@/admin.config.js'
  77. export default {
  78. components: {
  79. errorLog
  80. },
  81. props: {
  82. navigationBarTitleText: {
  83. type: String
  84. },
  85. matchLeftWindow: {
  86. type: Boolean
  87. },
  88. showLeftWindow: {
  89. type: Boolean
  90. }
  91. },
  92. data() {
  93. return {
  94. ...config.navBar,
  95. popupMenuOpened: false,
  96. mpCapsule: 0
  97. }
  98. },
  99. computed: {
  100. ...mapState('app', ['appName']),
  101. ...mapState('app', ['routes']),
  102. ...mapState('user', ['userInfo']),
  103. ...mapState('error', ['logs'])
  104. },
  105. mounted() {
  106. // #ifdef MP
  107. let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  108. this.mpCapsule = menuButtonInfo.width
  109. // #endif
  110. // 沉余代码,临时处理 uni-datetime-picker 国际化不生效的问题
  111. // #ifdef H5
  112. uni.setLocale('en')
  113. this.$nextTick(() => {
  114. // 设置简体中文
  115. this.changeLanguage(0)
  116. })
  117. // #endif
  118. },
  119. methods: {
  120. showErrorLogs() {
  121. if (this.popupMenuOpened) {
  122. this.popupMenuOpened = false
  123. }
  124. this.$refs.errorLogsPopup.open()
  125. },
  126. showPasswordPopup() {
  127. if (this.popupMenuOpened) {
  128. this.popupMenuOpened = false
  129. }
  130. this.$refs.passwordPopup.open()
  131. },
  132. logout() {
  133. this.popupMenuOpened = false
  134. uniIdPagesCommon.logout()
  135. },
  136. toggleSidebar() {
  137. if (!this.showLeftWindow) {
  138. uni.showLeftWindow()
  139. } else {
  140. uni.hideLeftWindow()
  141. }
  142. },
  143. togglePopupMenu() {
  144. this.popupMenuOpened = !this.popupMenuOpened
  145. },
  146. changePassword() {
  147. uni.navigateTo({
  148. url: '/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd',
  149. complete: () => {
  150. this.popupMenuOpened = false
  151. }
  152. })
  153. },
  154. changeLanguage(e) {
  155. const index = typeof e === 'object' ? e.detail.value : e
  156. const lang = this.langs[index].lang || 'zh-Hans'
  157. const platform = uni.getSystemInfoSync().platform
  158. if (platform === 'android') {
  159. uni.showToast({
  160. icon: 'error',
  161. title: '暂不支持',
  162. duration: 2000
  163. })
  164. return
  165. }
  166. this.$i18n.locale = lang
  167. uni.setLocale(lang)
  168. },
  169. linkTo() {
  170. uni.reLaunch({
  171. url: '/'
  172. })
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="scss">
  178. .header {
  179. height: 60px;
  180. width: 100%;
  181. box-sizing: border-box;
  182. border-bottom: 1px solid darken($top-window-bg-color, 8%);
  183. background-color: $top-window-bg-color;
  184. color: $top-window-text-color;
  185. }
  186. .navbar {
  187. font-size: 14px;
  188. position: relative;
  189. height: 100%;
  190. padding: 0 20px;
  191. display: flex;
  192. justify-content: space-between;
  193. align-items: center;
  194. }
  195. .logo {
  196. min-width: 223px;
  197. display: flex;
  198. align-items: center;
  199. image {
  200. // logo宽高开发者可根据情况自行调节
  201. width: 30px;
  202. height: 30px;
  203. }
  204. text {
  205. margin-left: 8px;
  206. }
  207. }
  208. .menu-icon {
  209. width: 30px;
  210. height: 30px;
  211. line-height: 30px;
  212. }
  213. .navbar-middle,
  214. .navbar-right {
  215. flex: 1;
  216. /* #ifdef MP */
  217. margin-right: 97px;
  218. /* #endif */
  219. }
  220. .navbar-left {
  221. display: flex;
  222. }
  223. // 在平板以下,保持navbar-middle
  224. @media screen and (max-width: 767px) {
  225. .navbar-left {
  226. flex: 1;
  227. /* #ifdef MP */
  228. margin-right: 97px;
  229. /* #endif */
  230. }
  231. }
  232. .navbar-middle,
  233. .username {
  234. display: flex;
  235. align-items: center;
  236. overflow: hidden;
  237. text-overflow: ellipsis;
  238. white-space: nowrap;
  239. }
  240. .navbar-middle {
  241. text-align: center;
  242. }
  243. .username {
  244. max-width: 150px;
  245. }
  246. .title-text {
  247. font-size: 14px;
  248. line-height: 30px;
  249. }
  250. .navbar-menu {
  251. display: flex;
  252. }
  253. .menu-item {
  254. padding: 8px;
  255. font-size: 16px;
  256. color: #555;
  257. line-height: 1;
  258. }
  259. .debug {
  260. margin: 0 30px;
  261. display: inline-block;
  262. position: relative;
  263. }
  264. .debug-badge {
  265. position: absolute;
  266. top: 5px;
  267. right: 14px;
  268. transform: translateY(-50%) translateX(100%) scale(0.8);
  269. }
  270. .arrowdown {
  271. margin-top: 4px;
  272. margin-left: 3px;
  273. }
  274. .person {
  275. margin-top: 2px;
  276. margin-right: 2px;
  277. }
  278. .navbar-right {
  279. display: flex;
  280. justify-content: flex-end;
  281. align-items: center;
  282. }
  283. .navbar-right .uni-mask {
  284. position: fixed;
  285. top: 0;
  286. left: 0;
  287. width: 100%;
  288. height: 100%;
  289. background-color: rgba(255, 255, 255, 0);
  290. z-index: 999;
  291. }
  292. .popup-menu__arrow {
  293. position: absolute;
  294. top: -6px;
  295. right: 20px;
  296. border-width: 6px;
  297. margin-right: 3px;
  298. border-top-width: 0;
  299. border-bottom-color: #ebeef5;
  300. filter: drop-shadow(0 6px 12px rgba(0, 0, 0, .1));
  301. }
  302. .popup-menu__arrow::after {
  303. content: " ";
  304. position: absolute;
  305. display: block;
  306. width: 0;
  307. height: 0;
  308. border-color: transparent;
  309. border-style: solid;
  310. border-width: 10px;
  311. top: 1px;
  312. margin-left: -10px;
  313. border-top-width: 0;
  314. border-bottom-color: #fff;
  315. }
  316. /* 大屏时,隐藏的内容 */
  317. .menu-icon,
  318. .navbar-middle,
  319. // .navbar-user,
  320. .popup-menu__arrow,
  321. .navbar-right .uni-mask {
  322. display: none;
  323. }
  324. /* 小屏,显示的内容 */
  325. .navbar-mini .menu-icon {
  326. display: block;
  327. }
  328. .navbar-user {
  329. display: flex;
  330. justify-content: center;
  331. align-items: center;
  332. }
  333. /* 小屏时,隐藏的内容 */
  334. .navbar-mini .logo,
  335. .navbar-mini .debug,
  336. .navbar-menu,
  337. // .navbar-mini .navbar-menu .username
  338. {
  339. display: none;
  340. }
  341. .navbar-menu {
  342. width: 100px;
  343. flex-direction: column;
  344. align-items: center;
  345. justify-content: center;
  346. position: absolute;
  347. right: 0;
  348. /* #ifdef MP */
  349. // right: 97px;
  350. /* #endif */
  351. top: 27px;
  352. /* #ifndef H5 */
  353. // top: 85pxs: ;
  354. /* #endif */
  355. background-color: #fff;
  356. z-index: 999;
  357. padding: 10px 0;
  358. background-color: #fff;
  359. border: 1px solid #ebeef5;
  360. border-radius: 4px;
  361. box-shadow: 0 6px 12px 0 rgba(0, 0, 0, .5);
  362. }
  363. /* 小屏时,弹出下拉菜单 */
  364. .popup-menu .navbar-menu {
  365. display: flex;
  366. }
  367. .popup-menu .popup-menu__arrow,
  368. .popup-menu .navbar-right .uni-mask {
  369. display: block;
  370. }
  371. .hover-highlight:hover {
  372. color: $menu-text-color-actived;
  373. }
  374. .svg-icon {
  375. width: 1em;
  376. height: 1em;
  377. vertical-align: -.15em;
  378. fill: currentColor;
  379. overflow: hidden;
  380. }
  381. .password-popup {
  382. padding: 30px;
  383. }
  384. .language-item {
  385. font-stretch: 12px;
  386. vertical-align: baseline;
  387. text-decoration: underline;
  388. }
  389. .lang-icon {
  390. font-size: 18px;
  391. margin-top: 5px;
  392. margin-right: 30px;
  393. }
  394. .user-icon {
  395. font-size: 20px;
  396. }
  397. </style>