You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
11 KiB

1 year ago
  1. <template>
  2. <div class="user-wrapper" :class="theme">
  3. <!-- update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航 -->
  4. <!-- update-begin author:sunjianlei date:20191@20 for: 解决全局样式冲突的问题 -->
  5. <span class="action" @click="showClick">
  6. <a-icon type="search"></a-icon>
  7. </span>
  8. <!-- update-begin author:sunjianlei date:20200219 for: 菜单搜索改为动态组件在手机端呈现出弹出框 -->
  9. <component :is="searchMenuComp" v-show="searchMenuVisible || isMobile()" class="borders" :visible="searchMenuVisible" title="搜索菜单" :footer="null" @cancel="searchMenuVisible=false">
  10. <a-select
  11. class="search-input"
  12. showSearch
  13. :showArrow="false"
  14. placeholder="搜索菜单"
  15. optionFilterProp="children"
  16. :filterOption="filterOption"
  17. :open="isMobile()?true:null"
  18. :getPopupContainer="(node) => node.parentNode"
  19. :style="isMobile()?{width: '100%',marginBottom:'50px'}:{}"
  20. @change="searchMethods"
  21. @blur="hiddenClick"
  22. >
  23. <a-select-option v-for="(site,index) in searchMenuOptions" :key="index" :value="site.id">{{site.meta.title}}</a-select-option>
  24. </a-select>
  25. </component>
  26. <!-- update-end author:sunjianlei date:20200219 for: 菜单搜索改为动态组件在手机端呈现出弹出框 -->
  27. <!-- update-end author:sunjianlei date:20191220 for: 解决全局样式冲突的问题 -->
  28. <!-- update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航 -->
  29. <span class="action">
  30. <a class="logout_title" target="_blank" href="http://doc.jeecg.com">
  31. <a-icon type="question-circle-o"></a-icon>
  32. </a>
  33. </span>
  34. <header-notice class="action"/>
  35. <a-dropdown>
  36. <span class="action action-full ant-dropdown-link user-dropdown-menu">
  37. <a-avatar class="avatar" size="small" :src="getAvatar()"/>
  38. <span v-if="isDesktop()">欢迎您{{ nickname() }}</span>
  39. </span>
  40. <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
  41. <a-menu-item key="0">
  42. <router-link :to="{ name: 'account-center' }">
  43. <a-icon type="user"/>
  44. <span>个人中心</span>
  45. </router-link>
  46. </a-menu-item>
  47. <a-menu-item key="1">
  48. <router-link :to="{ name: 'account-settings-base' }">
  49. <a-icon type="setting"/>
  50. <span>账户设置</span>
  51. </router-link>
  52. </a-menu-item>
  53. <a-menu-item key="3" @click="systemSetting">
  54. <a-icon type="tool"/>
  55. <span>系统设置</span>
  56. </a-menu-item>
  57. <a-menu-item key="4" @click="updatePassword">
  58. <a-icon type="setting"/>
  59. <span>密码修改</span>
  60. </a-menu-item>
  61. <a-menu-item key="5" @click="updateCurrentDepart">
  62. <a-icon type="cluster"/>
  63. <span>切换部门</span>
  64. </a-menu-item>
  65. <a-menu-item key="6" @click="clearCache">
  66. <a-icon type="sync"/>
  67. <span>清理缓存</span>
  68. </a-menu-item>
  69. <!-- <a-menu-item key="2" disabled>
  70. <a-icon type="setting"/>
  71. <span>测试</span>
  72. </a-menu-item>
  73. <a-menu-divider/>
  74. <a-menu-item key="3">
  75. <a href="javascript:;" @click="handleLogout">
  76. <a-icon type="logout"/>
  77. <span>退出登录</span>
  78. </a>
  79. </a-menu-item>-->
  80. </a-menu>
  81. </a-dropdown>
  82. <span class="action">
  83. <a class="logout_title" href="javascript:;" @click="handleLogout">
  84. <a-icon type="logout"/>
  85. <span v-if="isDesktop()">&nbsp;退出登录</span>
  86. </a>
  87. </span>
  88. <user-password ref="userPassword"></user-password>
  89. <depart-select ref="departSelect" :closable="true" title="部门切换"></depart-select>
  90. <setting-drawer ref="settingDrawer" :closable="true" title="系统设置"></setting-drawer>
  91. </div>
  92. </template>
  93. <script>
  94. import HeaderNotice from './HeaderNotice'
  95. import UserPassword from './UserPassword'
  96. import SettingDrawer from "@/components/setting/SettingDrawer";
  97. import DepartSelect from './DepartSelect'
  98. import { mapActions, mapGetters,mapState } from 'vuex'
  99. import { mixinDevice } from '@/utils/mixin.js'
  100. import { getFileAccessHttpUrl,getAction } from "@/api/manage"
  101. import Vue from 'vue'
  102. import { UI_CACHE_DB_DICT_DATA } from "@/store/mutation-types"
  103. export default {
  104. name: "UserMenu",
  105. mixins: [mixinDevice],
  106. data(){
  107. return{
  108. // update-begin author:sunjianlei date:20200219 for: 头部菜单搜索规范命名 --------------
  109. searchMenuOptions:[],
  110. searchMenuComp: 'span',
  111. searchMenuVisible: false,
  112. // update-begin author:sunjianlei date:20200219 for: 头部菜单搜索规范命名 --------------
  113. }
  114. },
  115. components: {
  116. HeaderNotice,
  117. UserPassword,
  118. DepartSelect,
  119. SettingDrawer
  120. },
  121. props: {
  122. theme: {
  123. type: String,
  124. required: false,
  125. default: 'dark'
  126. }
  127. },
  128. /* update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  129. created() {
  130. let lists = []
  131. this.searchMenus(lists,this.permissionMenuList)
  132. this.searchMenuOptions=[...lists]
  133. },
  134. mounted() {
  135. //如果是单点登录模式
  136. if (process.env.VUE_APP_SSO == 'true') {
  137. let depart = this.userInfo().orgCode
  138. if (!depart) {
  139. this.updateCurrentDepart()
  140. }
  141. }
  142. },
  143. computed: {
  144. ...mapState({
  145. // 后台菜单
  146. permissionMenuList: state => state.user.permissionList
  147. })
  148. },
  149. /* update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  150. watch: {
  151. // update-begin author:sunjianlei date:20200219 for: 菜单搜索改为动态组件,在手机端呈现出弹出框
  152. device: {
  153. immediate: true,
  154. handler() {
  155. this.searchMenuVisible = false
  156. this.searchMenuComp = this.isMobile() ? 'a-modal' : 'span'
  157. },
  158. },
  159. // update-end author:sunjianlei date:20200219 for: 菜单搜索改为动态组件,在手机端呈现出弹出框
  160. },
  161. methods: {
  162. /* update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  163. showClick() {
  164. this.searchMenuVisible = true
  165. },
  166. hiddenClick(){
  167. this.shows = false
  168. },
  169. /* update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  170. ...mapActions(["Logout"]),
  171. ...mapGetters(["nickname", "avatar","userInfo"]),
  172. getAvatar(){
  173. return getFileAccessHttpUrl(this.avatar())
  174. },
  175. handleLogout() {
  176. const that = this
  177. this.$confirm({
  178. title: '提示',
  179. content: '真的要注销登录吗 ?',
  180. onOk() {
  181. return that.Logout({}).then(() => {
  182. // update-begin author:scott date:20211223 for:【JTC-198】退出登录体验不好
  183. //that.$router.push({ path: '/user/login' });
  184. window.location.reload()
  185. // update-end author:scott date:20211223 for:【JTC-198】退出登录体验不好
  186. }).catch(err => {
  187. that.$message.error({
  188. title: '错误',
  189. description: err.message
  190. })
  191. })
  192. },
  193. onCancel() {
  194. },
  195. });
  196. },
  197. updatePassword(){
  198. let username = this.userInfo().username
  199. this.$refs.userPassword.show(username)
  200. },
  201. updateCurrentDepart(){
  202. this.$refs.departSelect.show()
  203. },
  204. systemSetting(){
  205. this.$refs.settingDrawer.showDrawer()
  206. },
  207. /* update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  208. searchMenus(arr,menus){
  209. for(let i of menus){
  210. if(!i.hidden && "layouts/RouteView"!==i.component){
  211. arr.push(i)
  212. }
  213. if(i.children&& i.children.length>0){
  214. this.searchMenus(arr,i.children)
  215. }
  216. }
  217. },
  218. filterOption(input, option) {
  219. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  220. },
  221. // update_begin author:sunjianlei date:20191230 for: 解决外部链接打开失败的问题
  222. searchMethods(value) {
  223. let route = this.searchMenuOptions.filter(item => item.id === value)[0]
  224. //update-begin-author:sunjianlei date:20220111 for: 【JTC-702】【菜单搜索】菜单搜索里点击跳转的菜单,无法将Token信息传递过去
  225. if(route.component.includes('layouts/IframePageView')){
  226. this.$router.push(route)
  227. }else{
  228. this.$router.push({ path: route.path })
  229. }
  230. //update-end-author:sunjianlei date:20220111 for: 【JTC-702】【菜单搜索】菜单搜索里点击跳转的菜单,无法将Token信息传递过去
  231. this.searchMenuVisible = false
  232. },
  233. // update_end author:sunjianlei date:20191230 for: 解决外部链接打开失败的问题
  234. /*update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  235. /*update_begin author:liushaoqian date:20200507 for: 刷新缓存*/
  236. clearCache(){
  237. getAction("sys/dict/refleshCache").then((res) => {
  238. if (res.success) {
  239. //重新加载缓存
  240. getAction("sys/dict/queryAllDictItems").then((res) => {
  241. if (res.success) {
  242. Vue.ls.remove(UI_CACHE_DB_DICT_DATA)
  243. Vue.ls.set(UI_CACHE_DB_DICT_DATA, res.result, 7 * 24 * 60 * 60 * 1000)
  244. }
  245. })
  246. this.$message.success("刷新缓存完成!");
  247. }
  248. }).catch(e=>{
  249. this.$message.warn("刷新缓存失败!");
  250. console.log("刷新失败",e)
  251. })
  252. }
  253. /*update_end author:liushaoqian date:20200507 for: 刷新缓存*/
  254. }
  255. }
  256. </script>
  257. <style lang="less" scoped>
  258. /* update_begin author:zhaoxin date:20191129 for: 让搜索框颜色能随主题颜色变换*/
  259. /* update-begin author:sunjianlei date:20191220 for: 解决全局样式冲突问题 */
  260. .user-wrapper .search-input {
  261. width: 180px;
  262. color: inherit;
  263. /deep/ .ant-select-selection {
  264. background-color: inherit;
  265. border: 0;
  266. border-bottom: 1px solid white;
  267. &__placeholder, &__field__placeholder {
  268. color: inherit;
  269. }
  270. }
  271. }
  272. /* update-end author:sunjianlei date:20191220 for: 解决全局样式冲突问题 */
  273. /* update_end author:zhaoxin date:20191129 for: 让搜索框颜色能随主题颜色变换*/
  274. </style>
  275. <style scoped>
  276. .logout_title {
  277. color: inherit;
  278. text-decoration: none;
  279. }
  280. </style>