UserMenu.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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:wangshuai date:20200601 for: 退出登录跳转登录页面
  183. var type=Vue.ls.get('TYPE');
  184. if(type==2||type=="2"){
  185. that.$router.push({ path: '/user/login' });
  186. }else{
  187. window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww7c43b4b5f33945ad&redirect_uri=http://hr3.gksports.net.cn:8081&response_type=code&scope=snsapi_userinfo&agentid=1000009&state=STATE#wechat_redirect"
  188. }
  189. //that.$router.push({ path: '/user/login' });
  190. // update-end author:wangshuai date:20200601 for: 退出登录跳转登录页面
  191. //window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww7c43b4b5f33945ad&redirect_uri=http://hr.gksports.net.cn&response_type=code&scope=snsapi_userinfo&agentid=1000009&state=STATE#wechat_redirect"
  192. //window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wwd372e7740b9b586f&redirect_uri=geke.g.dr1997.com&response_type=code&scope=snsapi_userinfo&agentid=1000004&state=STATE#wechat_redirect";
  193. }).catch(err => {
  194. that.$message.error({
  195. title: '错误',
  196. description: err.message
  197. })
  198. })
  199. },
  200. onCancel() {
  201. },
  202. });
  203. },
  204. updatePassword(){
  205. let username = this.userInfo().username
  206. this.$refs.userPassword.show(username)
  207. },
  208. updateCurrentDepart(){
  209. this.$refs.departSelect.show()
  210. },
  211. systemSetting(){
  212. this.$refs.settingDrawer.showDrawer()
  213. },
  214. /* update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  215. searchMenus(arr,menus){
  216. for(let i of menus){
  217. if(!i.hidden && "layouts/RouteView"!==i.component){
  218. arr.push(i)
  219. }
  220. if(i.children&& i.children.length>0){
  221. this.searchMenus(arr,i.children)
  222. }
  223. }
  224. },
  225. filterOption(input, option) {
  226. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  227. },
  228. // update_begin author:sunjianlei date:20191230 for: 解决外部链接打开失败的问题
  229. searchMethods(value) {
  230. let route = this.searchMenuOptions.filter(item => item.id === value)[0]
  231. if (route.meta.internalOrExternal === true || route.component.includes('layouts/IframePageView')) {
  232. window.open(route.meta.url, '_blank')
  233. } else {
  234. this.$router.push({ path: route.path })
  235. }
  236. this.searchMenuVisible = false
  237. },
  238. // update_end author:sunjianlei date:20191230 for: 解决外部链接打开失败的问题
  239. /*update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  240. /*update_begin author:liushaoqian date:20200507 for: 刷新缓存*/
  241. clearCache(){
  242. getAction("sys/dict/refleshCache").then((res) => {
  243. if (res.success) {
  244. //重新加载缓存
  245. getAction("sys/dict/queryAllDictItems").then((res) => {
  246. if (res.success) {
  247. Vue.ls.remove(UI_CACHE_DB_DICT_DATA)
  248. Vue.ls.set(UI_CACHE_DB_DICT_DATA, res.result, 7 * 24 * 60 * 60 * 1000)
  249. }
  250. })
  251. this.$message.success("刷新缓存完成!");
  252. }
  253. }).catch(e=>{
  254. this.$message.warn("刷新缓存失败!");
  255. console.log("刷新失败",e)
  256. })
  257. }
  258. /*update_end author:liushaoqian date:20200507 for: 刷新缓存*/
  259. }
  260. }
  261. </script>
  262. <style lang="less" scoped>
  263. /* update_begin author:zhaoxin date:20191129 for: 让搜索框颜色能随主题颜色变换*/
  264. /* update-begin author:sunjianlei date:20191220 for: 解决全局样式冲突问题 */
  265. .user-wrapper .search-input {
  266. width: 180px;
  267. color: inherit;
  268. /deep/ .ant-select-selection {
  269. background-color: inherit;
  270. border: 0;
  271. border-bottom: 1px solid white;
  272. &__placeholder, &__field__placeholder {
  273. color: inherit;
  274. }
  275. }
  276. }
  277. /* update-end author:sunjianlei date:20191220 for: 解决全局样式冲突问题 */
  278. /* update_end author:zhaoxin date:20191129 for: 让搜索框颜色能随主题颜色变换*/
  279. </style>
  280. <style scoped>
  281. .logout_title {
  282. color: inherit;
  283. text-decoration: none;
  284. }
  285. </style>