UserMenu.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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://www.sdjintian.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. this.getUpdatePasswordLog()
  143. },
  144. computed: {
  145. ...mapState({
  146. // 后台菜单
  147. permissionMenuList: state => state.user.permissionList
  148. })
  149. },
  150. /* update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  151. watch: {
  152. // update-begin author:sunjianlei date:20200219 for: 菜单搜索改为动态组件,在手机端呈现出弹出框
  153. device: {
  154. immediate: true,
  155. handler() {
  156. this.searchMenuVisible = false
  157. this.searchMenuComp = this.isMobile() ? 'a-modal' : 'span'
  158. },
  159. },
  160. // update-end author:sunjianlei date:20200219 for: 菜单搜索改为动态组件,在手机端呈现出弹出框
  161. },
  162. methods: {
  163. getUpdatePasswordLog(){
  164. getAction("/qcsb.qyxx/qcQyxx/getPWDlog").then(res=>{
  165. if(res.code==200){
  166. debugger
  167. if(res.result=="未修改")
  168. this.updatePassword();
  169. }
  170. })
  171. },
  172. /* update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  173. showClick() {
  174. this.searchMenuVisible = true
  175. },
  176. hiddenClick(){
  177. this.shows = false
  178. },
  179. /* update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  180. ...mapActions(["Logout"]),
  181. ...mapGetters(["nickname", "avatar","userInfo"]),
  182. getAvatar(){
  183. return getFileAccessHttpUrl(this.avatar())
  184. },
  185. handleLogout() {
  186. const that = this
  187. this.$confirm({
  188. title: '提示',
  189. content: '真的要注销登录吗 ?',
  190. onOk() {
  191. return that.Logout({}).then(() => {
  192. // update-begin author:scott date:20211223 for:【JTC-198】退出登录体验不好
  193. //that.$router.push({ path: '/user/login' });
  194. // window.location.reload()
  195. // update-end author:scott date:20211223 for:【JTC-198】退出登录体验不好
  196. let sevice = 'http://' + window.location.host + '/'
  197. console.log("sevice=====" + sevice);
  198. // let serviceUrl = encodeURIComponent(sevice)
  199. window.location.href = sevice
  200. }).catch(err => {
  201. that.$message.error({
  202. title: '错误',
  203. description: err.message
  204. })
  205. })
  206. },
  207. onCancel() {
  208. },
  209. });
  210. },
  211. updatePassword(){
  212. let username = this.userInfo().username
  213. this.$refs.userPassword.show(username)
  214. },
  215. updateCurrentDepart(){
  216. this.$refs.departSelect.show()
  217. },
  218. systemSetting(){
  219. this.$refs.settingDrawer.showDrawer()
  220. },
  221. /* update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  222. searchMenus(arr,menus){
  223. for(let i of menus){
  224. if(!i.hidden && "layouts/RouteView"!==i.component){
  225. arr.push(i)
  226. }
  227. if(i.children&& i.children.length>0){
  228. this.searchMenus(arr,i.children)
  229. }
  230. }
  231. },
  232. filterOption(input, option) {
  233. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  234. },
  235. // update_begin author:sunjianlei date:20191230 for: 解决外部链接打开失败的问题
  236. searchMethods(value) {
  237. let route = this.searchMenuOptions.filter(item => item.id === value)[0]
  238. //update-begin-author:sunjianlei date:20220111 for: 【JTC-702】【菜单搜索】菜单搜索里点击跳转的菜单,无法将Token信息传递过去
  239. if(route.component.includes('layouts/IframePageView')){
  240. this.$router.push(route)
  241. }else{
  242. this.$router.push({ path: route.path })
  243. }
  244. //update-end-author:sunjianlei date:20220111 for: 【JTC-702】【菜单搜索】菜单搜索里点击跳转的菜单,无法将Token信息传递过去
  245. this.searchMenuVisible = false
  246. },
  247. // update_end author:sunjianlei date:20191230 for: 解决外部链接打开失败的问题
  248. /*update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  249. /*update_begin author:liushaoqian date:20200507 for: 刷新缓存*/
  250. clearCache(){
  251. getAction("sys/dict/refleshCache").then((res) => {
  252. if (res.success) {
  253. //重新加载缓存
  254. getAction("sys/dict/queryAllDictItems").then((res) => {
  255. if (res.success) {
  256. Vue.ls.remove(UI_CACHE_DB_DICT_DATA)
  257. Vue.ls.set(UI_CACHE_DB_DICT_DATA, res.result, 7 * 24 * 60 * 60 * 1000)
  258. }
  259. })
  260. this.$message.success("刷新缓存完成!");
  261. }
  262. }).catch(e=>{
  263. this.$message.warn("刷新缓存失败!");
  264. console.log("刷新失败",e)
  265. })
  266. }
  267. /*update_end author:liushaoqian date:20200507 for: 刷新缓存*/
  268. }
  269. }
  270. </script>
  271. <style lang="less" scoped>
  272. /* update_begin author:zhaoxin date:20191129 for: 让搜索框颜色能随主题颜色变换*/
  273. /* update-begin author:sunjianlei date:20191220 for: 解决全局样式冲突问题 */
  274. .user-wrapper .search-input {
  275. width: 180px;
  276. color: inherit;
  277. /deep/ .ant-select-selection {
  278. background-color: inherit;
  279. border: 0;
  280. border-bottom: 1px solid white;
  281. &__placeholder, &__field__placeholder {
  282. color: inherit;
  283. }
  284. }
  285. }
  286. /* update-end author:sunjianlei date:20191220 for: 解决全局样式冲突问题 */
  287. /* update_end author:zhaoxin date:20191129 for: 让搜索框颜色能随主题颜色变换*/
  288. </style>
  289. <style scoped>
  290. .logout_title {
  291. color: inherit;
  292. text-decoration: none;
  293. }
  294. </style>