index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div class="ibps-layout-header-user">
  3. <el-dropdown
  4. size="small"
  5. @command="command => handleControlItemClick(command)"
  6. @visible-change="visible =>dropdownVisible=visible"
  7. >
  8. <div>
  9. <!-- <el-avatar
  10. :src="avatar"
  11. :text="userName"
  12. :alt="userName"
  13. style="background: none;"
  14. @error="errorImageHandler"
  15. /> -->
  16. <span class="user-name-span">
  17. <div class="user-name-title"> <i class="el-icon-user-solid" /> {{ userName }}</div>
  18. </span>
  19. <!-- <i
  20. class="user-dropdown"
  21. :class="{
  22. 'el-icon-arrow-down':!dropdownVisible,
  23. 'el-icon-arrow-up':dropdownVisible
  24. }"
  25. style="position: absolute;right: -15px;top: 15px;"
  26. /> -->
  27. </div>
  28. <el-dropdown-menu slot="dropdown" class="user-dropdown">
  29. <!-- <el-dropdown-item command="dashboard">
  30. <ibps-icon name="home" class="ibps-mr-10" />
  31. {{ $t('navbar.dashboard') }}
  32. </el-dropdown-item> -->
  33. <el-dropdown-item v-if="!regOpen && $store.getters.isTenantAdmin !== true" command="userInfo">
  34. <ibps-icon name="user" class="ibps-mr-10" />
  35. {{ $t('navbar.userInfo') }}
  36. </el-dropdown-item>
  37. <el-dropdown-item command="changePassword">
  38. <ibps-icon name="lock" class="ibps-mr-10" />
  39. {{ $t('navbar.changePassword') }}
  40. </el-dropdown-item>
  41. <el-dropdown-item v-if="$utils.isNotEmpty(switchAccount)" command="exitSwitchUser">
  42. <ibps-icon name="reply" class="ibps-mr-10" />
  43. {{ $t('navbar.exitSwitchUser') }}
  44. </el-dropdown-item>
  45. <el-dropdown-item v-if="tenants&& tenants.length > 0" command="switchTenant">
  46. <ibps-icon name="reply" class="ibps-mr-10" />
  47. {{ $t('navbar.switchTenant') }}
  48. </el-dropdown-item>
  49. <el-dropdown-item v-if="tenants&& tenants.length > 0">
  50. <ibps-icon name="my-request" class="ibps-mr-10" />
  51. {{ tenantid|optionsFilter(tenants,'name','id') }}
  52. </el-dropdown-item>
  53. <el-dropdown-item command="logout">
  54. <ibps-icon name="sign-out" class="ibps-mr-10" />
  55. {{ $t('navbar.logOut') }}
  56. </el-dropdown-item>
  57. <el-dropdown-item class="dropdown512" divided>
  58. <div class="title512">
  59. <i class="el-icon-location" />地点
  60. </div>
  61. <!-- <div class="item">{{ locationName }}</div> -->
  62. <el-tag class="item512" type="success">{{ locationName }}</el-tag>
  63. <template v-if="deptName.length">
  64. <div class="title512">
  65. <i class="el-icon-office-building" />部门
  66. <el-button type="text" icon="el-icon-edit" size="mini" circle @click="bpmnVisible = true" />
  67. </div>
  68. <el-tag
  69. v-for="(item, index) in value"
  70. :key="Date.now() + Math.random() + index"
  71. class="item512"
  72. type="info"
  73. size="small"
  74. >{{ item }}</el-tag>
  75. </template>
  76. <template v-if="roleName.length">
  77. <div class="title512">
  78. <i class="el-icon-postcard" />岗位
  79. </div>
  80. <el-tag
  81. v-for="(item, index) in roleName"
  82. :key="Date.now() + Math.random() + index"
  83. class="item512"
  84. type="warning"
  85. >{{ item }}</el-tag>
  86. </template>
  87. </el-dropdown-item>
  88. </el-dropdown-menu>
  89. </el-dropdown>
  90. <change-password
  91. :ids="userId"
  92. :reg-open="regOpen"
  93. :visible="changePasswordVisible"
  94. :title=" $t('navbar.changePassword') "
  95. @close="visible => changePasswordVisible = visible"
  96. />
  97. <user-info
  98. :id="userId"
  99. :form-type="formType"
  100. :visible="userInfoVisible"
  101. :title=" $t('navbar.userInfo') "
  102. readonly
  103. @close="visible => userInfoVisible = visible"
  104. />
  105. <el-dialog
  106. title="更换部门"
  107. :visible.sync="bpmnVisible"
  108. width="50%"
  109. >
  110. <el-transfer
  111. ref="xuanzexiang"
  112. v-model="value"
  113. filterable
  114. :filter-method="filterMethod"
  115. filter-placeholder="请输入关键字"
  116. :titles="['所在部门', '主部门']"
  117. :data="data1"
  118. @left-check-change="leftcheckchange"
  119. @change="handleChange"
  120. >
  121. <span slot="footer" class="dialog-footer">
  122. <!-- <el-button @click="bpmnVisible = false">取 消</el-button> -->
  123. <el-button type="primary" @click="bpmnVisible = false">关 闭</el-button>
  124. </span>
  125. </el-transfer>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script>
  130. import { mapState, mapActions, mapMutations } from 'vuex'
  131. import { getFile } from '@/utils/avatar'
  132. import setting from '@/setting.js'
  133. import ChangePassword from '@/views/platform/org/employee/change-password'
  134. import UserInfo from '@/views/platform/org/employee/edit'
  135. export default {
  136. components: {
  137. ChangePassword,
  138. UserInfo
  139. },
  140. data () {
  141. const { first = '', second = '' } = this.$store.getters.level
  142. const { userList = [], deptList = [], userId = '', pitchDept = [], mainPosition = {}} = this.$store.getters
  143. const t1 = deptList.find(i => i.positionId === first) || {}
  144. const t2 = deptList.find(i => i.positionId === second) || {}
  145. const locationName = second ? t1.positionName + t2.positionName : t1.positionName
  146. const t3 = userList.find(i => i.userId === userId) || {}
  147. const deptName = t3.positions ? deptList.filter(i => t3.positions.includes(i.positionName)).map(i => i.positionName) : []
  148. const roleName = t3.roles ? t3.roles.split(',') : []
  149. const userIds = userId
  150. const generateData = _ => {
  151. const data = []
  152. const bm = deptName
  153. bm.forEach((b, index) => {
  154. data.push({
  155. label: b,
  156. key: b,
  157. pinyin: b
  158. })
  159. })
  160. return data
  161. }
  162. const pitchData = _ => {
  163. const data = []
  164. const getPitch = JSON.parse(localStorage.getItem('pitchDept'))
  165. const bm = getPitch && getPitch.data.length > 0 && getPitch.id === userId ? getPitch.data : mainPosition && Object.keys(mainPosition).length > 0 ? [mainPosition.name] : deptName
  166. bm.forEach((b, index) => {
  167. data.push(b)
  168. })
  169. return data
  170. }
  171. return {
  172. userList,
  173. locationName,
  174. deptName,
  175. roleName,
  176. userIds,
  177. mainPosition,
  178. tenants: this.$store.getters.tenants,
  179. tenantid: this.$store.getters.tenantid,
  180. dropdownVisible: false,
  181. changePasswordVisible: false,
  182. userInfoVisible: false,
  183. formType: 'part',
  184. bpmnVisible: false,
  185. pitchBM: [],
  186. data1: generateData(),
  187. value: pitchData(),
  188. filterMethod (query, item) {
  189. return item.pinyin.indexOf(query) > -1
  190. }
  191. }
  192. },
  193. computed: {
  194. ...mapState('ibps/user', [
  195. 'info',
  196. 'switchAccount'
  197. ]),
  198. userId () {
  199. return this.info && this.info.employee ? this.info.employee.id : (this.info && this.info.user && this.info.user.id ? this.info.user.id : '')
  200. },
  201. avatar () {
  202. const photo = this.info && this.info.employee ? this.info.employee.photo : null
  203. if (this.$utils.isEmpty(photo)) {
  204. return this.errorImage
  205. }
  206. return getFile(photo)
  207. },
  208. errorImage () {
  209. return this.$baseUrl + setting.userInfo.user.photo
  210. },
  211. userName () {
  212. return this.info && this.info.user ? this.info.user.fullname : ''
  213. },
  214. orgName () {
  215. return this.info && this.info.user ? this.info.user.orgName : ''
  216. },
  217. regOpen () {
  218. return this.$store.getters.regOpen
  219. }
  220. },
  221. watch: {
  222. value: {
  223. handler: function (val, oldVal) {
  224. const getPitch = JSON.parse(localStorage.getItem('pitchDept'))
  225. this.$store.dispatch('ibps/param/setpitchDept', val)
  226. const a = { id: this.userIds, data: val }
  227. if (getPitch && a.id !== getPitch.id) {
  228. localStorage.setItem('pitchDept', JSON.stringify(a))
  229. } else if (getPitch && a.id !== getPitch.id) {
  230. localStorage.setItem('pitchDept', JSON.stringify(getPitch))
  231. } else {
  232. localStorage.setItem('pitchDept', JSON.stringify(a))
  233. }
  234. },
  235. immediate: true
  236. }
  237. },
  238. created () {
  239. const getPitch = JSON.parse(localStorage.getItem('pitchDept'))
  240. if (getPitch && getPitch.data.length > 0 && getPitch.id !== this.userIds) {
  241. this.$store.dispatch('ibps/param/setpitchDept', getPitch)
  242. }
  243. },
  244. methods: {
  245. ...mapMutations({
  246. pageKeepAliveClean: 'ibps/page/keepAliveClean'
  247. }),
  248. ...mapActions({
  249. logout: 'ibps/account/logout',
  250. exitSwitchUser: 'ibps/user/exitSwitchUser',
  251. setTenantids: 'ibps/user/setTenantids'
  252. }),
  253. handleControlItemClick (command) {
  254. switch (command) {
  255. case 'dashboard':// 主页
  256. this.$router.push({ path: '/' })
  257. break
  258. case 'userInfo':// 个人信息
  259. this.userInfo()
  260. break
  261. case 'changePassword':// 修改密码
  262. this.changePassword()
  263. break
  264. case 'exitSwitchUser':// 切换用户
  265. this.handleExitSwitchUser()
  266. break
  267. case 'switchTenant':// 切换租户
  268. this.handleSwitchTenant()
  269. break
  270. case 'logout':// 登出
  271. this.logOff()
  272. break
  273. }
  274. },
  275. /**
  276. * @description 登出
  277. */
  278. logOff () {
  279. this.logout({
  280. vm: this,
  281. confirm: true
  282. })
  283. },
  284. changePassword () {
  285. this.changePasswordVisible = true
  286. },
  287. userInfo () {
  288. this.userInfoVisible = true
  289. },
  290. errorImageHandler () {
  291. return false
  292. },
  293. handleExitSwitchUser () {
  294. this.exitSwitchUser().then(() => {
  295. this.$message.closeAll()
  296. this.$message.success('退出用户成功!')
  297. // 由于已经加载过设置 需要清空缓存设置
  298. this.pageKeepAliveClean()
  299. // 由于已经加载过设置 需要刷新此页面
  300. this.$router.replace('/refresh')
  301. })
  302. },
  303. handleSwitchTenant () {
  304. // 清空当前租户ID
  305. this.setTenantids('')
  306. // 清除子系统
  307. this.$store.dispatch('ibps/system/set', null, { root: true })
  308. // 清除菜单
  309. this.$store.dispatch('ibps/menu/menusSet', null, { root: true })
  310. this.$router.replace('/tenantSelect')
  311. },
  312. leftcheckchange (value, direction, movedKeys) {
  313. if (value.length > 1) {
  314. value.splice(0, 1)
  315. }
  316. // let arrChild = this.$refs.xuanzexiang.$children[0].$children[2].$children
  317. // console.log(arrChild)
  318. // if(value.length>0){
  319. // let ind = arrChild.findIndex(i=>i.label==value[0])
  320. // console.log(ind)
  321. // arrChild.forEach((item,i)=>{
  322. // if(i!=ind){
  323. // item
  324. // }
  325. // })
  326. // }
  327. },
  328. handleChange (value, direction, movedKeys) {
  329. this.value.value = value
  330. if (this.value.value.length > 1) {
  331. this.value.value.shift()
  332. }
  333. // 监听右侧列表元素变化情况,一旦原有状态发生变化,就将提交按钮至于可用状态
  334. // 以此避免在没有配置任何职务信息及原有职务信息无变化的情况下提交表单
  335. // butDisabled.value = false;
  336. }
  337. }
  338. }
  339. </script>
  340. <style lang="scss" scoped>
  341. .ibps-layout-header-user {
  342. ::v-deep {
  343. .el-dialog__body {
  344. display: flex;
  345. justify-content: center;
  346. padding: 20px 0 !important;
  347. }
  348. .el-dialog__footer {
  349. text-align: center;
  350. }
  351. .el-transfer-panel__filter .el-input__inner {
  352. width: 90%;
  353. }
  354. .el-transfer-panel__filter {
  355. margin: 10px 0;
  356. }
  357. .el-transfer-panel .el-checkbox__inner {
  358. border-radius: 100%;
  359. }
  360. }
  361. }
  362. .dropdown512 {
  363. max-width: 150px;
  364. max-height: 300px;
  365. overflow-x: hidden;
  366. overflow-y: auto;
  367. line-height: 24px;
  368. padding: 0 5px 0 15px;
  369. &:hover {
  370. background-color: #fff !important;
  371. }
  372. .title512 {
  373. line-height: 20px;
  374. font-weight: 400;
  375. color: #606266;
  376. }
  377. .item512 {
  378. font-size: 12px;
  379. height: 20px;
  380. line-height: 18px;
  381. padding: 0px 4px;
  382. }
  383. }
  384. </style>