index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. console.log(deptName,'deptNamedeptName')
  154. bm.forEach((b, index) => {
  155. data.push({
  156. label: b,
  157. key: b,
  158. pinyin: b
  159. })
  160. })
  161. return data
  162. }
  163. const pitchData = _ => {
  164. const data = []
  165. const getPitch = JSON.parse(localStorage.getItem('pitchDept'))
  166. const bm = getPitch && getPitch.data.length > 0 && getPitch.id === userId ? getPitch.data : mainPosition && Object.keys(mainPosition).length > 0 ? [mainPosition.name] : deptName
  167. bm.forEach((b, index) => {
  168. data.push(b)
  169. })
  170. return data
  171. }
  172. return {
  173. userList,
  174. locationName,
  175. deptName,
  176. roleName,
  177. userIds,
  178. mainPosition,
  179. tenants: this.$store.getters.tenants,
  180. tenantid: this.$store.getters.tenantid,
  181. dropdownVisible: false,
  182. changePasswordVisible: false,
  183. userInfoVisible: false,
  184. formType: 'part',
  185. bpmnVisible: false,
  186. pitchBM: [],
  187. data1: generateData(),
  188. value: pitchData(),
  189. filterMethod (query, item) {
  190. return item.pinyin.indexOf(query) > -1
  191. }
  192. }
  193. },
  194. computed: {
  195. ...mapState('ibps/user', [
  196. 'info',
  197. 'switchAccount'
  198. ]),
  199. userId () {
  200. return this.info && this.info.employee ? this.info.employee.id : (this.info && this.info.user && this.info.user.id ? this.info.user.id : '')
  201. },
  202. avatar () {
  203. const photo = this.info && this.info.employee ? this.info.employee.photo : null
  204. if (this.$utils.isEmpty(photo)) {
  205. return this.errorImage
  206. }
  207. return getFile(photo)
  208. },
  209. errorImage () {
  210. return this.$baseUrl + setting.userInfo.user.photo
  211. },
  212. userName () {
  213. return this.info && this.info.user ? this.info.user.fullname : ''
  214. },
  215. orgName () {
  216. return this.info && this.info.user ? this.info.user.orgName : ''
  217. },
  218. regOpen () {
  219. return this.$store.getters.regOpen
  220. }
  221. },
  222. watch: {
  223. value: {
  224. handler: function (val, oldVal) {
  225. const getPitch = JSON.parse(localStorage.getItem('pitchDept'))
  226. this.$store.dispatch('ibps/param/setpitchDept', val)
  227. const a = { id: this.userIds, data: val }
  228. if (getPitch && a.id !== getPitch.id) {
  229. localStorage.setItem('pitchDept', JSON.stringify(a))
  230. } else if (getPitch && a.id !== getPitch.id) {
  231. localStorage.setItem('pitchDept', JSON.stringify(getPitch))
  232. } else {
  233. localStorage.setItem('pitchDept', JSON.stringify(a))
  234. }
  235. },
  236. immediate: true
  237. }
  238. },
  239. created () {
  240. const getPitch = JSON.parse(localStorage.getItem('pitchDept'))
  241. if (getPitch && getPitch.data.length > 0 && getPitch.id !== this.userIds) {
  242. this.$store.dispatch('ibps/param/setpitchDept', getPitch)
  243. }
  244. },
  245. methods: {
  246. ...mapMutations({
  247. pageKeepAliveClean: 'ibps/page/keepAliveClean'
  248. }),
  249. ...mapActions({
  250. logout: 'ibps/account/logout',
  251. exitSwitchUser: 'ibps/user/exitSwitchUser',
  252. setTenantids: 'ibps/user/setTenantids'
  253. }),
  254. handleControlItemClick (command) {
  255. switch (command) {
  256. case 'dashboard':// 主页
  257. this.$router.push({ path: '/' })
  258. break
  259. case 'userInfo':// 个人信息
  260. this.userInfo()
  261. break
  262. case 'changePassword':// 修改密码
  263. this.changePassword()
  264. break
  265. case 'exitSwitchUser':// 切换用户
  266. this.handleExitSwitchUser()
  267. break
  268. case 'switchTenant':// 切换租户
  269. this.handleSwitchTenant()
  270. break
  271. case 'logout':// 登出
  272. this.logOff()
  273. break
  274. }
  275. },
  276. /**
  277. * @description 登出
  278. */
  279. logOff () {
  280. this.logout({
  281. vm: this,
  282. confirm: true
  283. })
  284. },
  285. changePassword () {
  286. this.changePasswordVisible = true
  287. },
  288. userInfo () {
  289. this.userInfoVisible = true
  290. },
  291. errorImageHandler () {
  292. return false
  293. },
  294. handleExitSwitchUser () {
  295. this.exitSwitchUser().then(() => {
  296. this.$message.closeAll()
  297. this.$message.success('退出用户成功!')
  298. // 由于已经加载过设置 需要清空缓存设置
  299. this.pageKeepAliveClean()
  300. // 由于已经加载过设置 需要刷新此页面
  301. this.$router.replace('/refresh')
  302. })
  303. },
  304. handleSwitchTenant () {
  305. // 清空当前租户ID
  306. this.setTenantids('')
  307. // 清除子系统
  308. this.$store.dispatch('ibps/system/set', null, { root: true })
  309. // 清除菜单
  310. this.$store.dispatch('ibps/menu/menusSet', null, { root: true })
  311. this.$router.replace('/tenantSelect')
  312. },
  313. leftcheckchange (value, direction, movedKeys) {
  314. if (value.length > 1) {
  315. value.splice(0, 1)
  316. }
  317. // let arrChild = this.$refs.xuanzexiang.$children[0].$children[2].$children
  318. // console.log(arrChild)
  319. // if(value.length>0){
  320. // let ind = arrChild.findIndex(i=>i.label==value[0])
  321. // console.log(ind)
  322. // arrChild.forEach((item,i)=>{
  323. // if(i!=ind){
  324. // item
  325. // }
  326. // })
  327. // }
  328. },
  329. handleChange (value, direction, movedKeys) {
  330. this.value.value = value
  331. if (this.value.value.length > 1) {
  332. this.value.value.shift()
  333. }
  334. // 监听右侧列表元素变化情况,一旦原有状态发生变化,就将提交按钮至于可用状态
  335. // 以此避免在没有配置任何职务信息及原有职务信息无变化的情况下提交表单
  336. // butDisabled.value = false;
  337. }
  338. }
  339. }
  340. </script>
  341. <style lang="scss" scoped>
  342. ::v-deep .el-dialog__body {
  343. display: flex;
  344. justify-content: center;
  345. padding: 20px 0 !important;
  346. }
  347. ::v-deep .el-dialog__footer {
  348. text-align: center;
  349. }
  350. ::v-deep .el-transfer-panel__filter .el-input__inner {
  351. width: 90%;
  352. }
  353. ::v-deep .el-transfer-panel__filter {
  354. margin: 10px 0;
  355. }
  356. ::v-deep .el-transfer-panel .el-checkbox__inner {
  357. border-radius: 100%;
  358. }
  359. // .ibps-layout-header-user {
  360. .dropdown512 {
  361. max-width: 150px;
  362. max-height: 300px;
  363. overflow-x: hidden;
  364. overflow-y: auto;
  365. line-height: 24px;
  366. padding: 0 5px 0 15px;
  367. &:hover {
  368. background-color: #fff !important;
  369. }
  370. .title512 {
  371. line-height: 20px;
  372. font-weight: 400;
  373. color: #606266;
  374. }
  375. .item512 {
  376. font-size: 12px;
  377. height: 20px;
  378. line-height: 18px;
  379. padding: 0px 4px;
  380. }
  381. }
  382. // }
  383. </style>