切换组织机构
parent
e3feb1b7e5
commit
aab535bf28
@ -0,0 +1,86 @@
|
||||
<!--
|
||||
* @Desc:
|
||||
* @Author: lijj
|
||||
* @Date: 2024-10-18 11:20:04
|
||||
-->
|
||||
<template>
|
||||
<BasicModal
|
||||
v-bind="$attrs"
|
||||
title="选择机构"
|
||||
width="400px"
|
||||
@register="registerModal"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<a-form class="ds-org-toggle-model" layout="vertical">
|
||||
<a-form-item label="机构名称">
|
||||
<a-radio-group v-model:value="orgId">
|
||||
<a-radio v-for="item in options" :key="item.orgId" :value="item.orgId">{{ item.orgName }}</a-radio>
|
||||
</a-radio-group>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</BasicModal>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { ref, defineExpose } from 'vue'
|
||||
import { BasicModal, useModalInner } from '/@/components/Modal'
|
||||
import { useMessage } from '/@/hooks/web/useMessage'
|
||||
import { ChangeOrg, getUserInfo } from '/@/api/common/index'
|
||||
import { useMultipleTabStore } from '/@/store/modules/multipleTab'
|
||||
import { router } from '/@/router'
|
||||
// 声明Emits
|
||||
const $message = useMessage()
|
||||
import { useTabs } from '/@/hooks/web/useTabs'
|
||||
import { useUserStore } from '/@/store/modules/user'
|
||||
const { refreshPage } = useTabs(router)
|
||||
const tabStore = useMultipleTabStore()
|
||||
const options = ref([])
|
||||
const orgId = ref(null)
|
||||
//表单赋值
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner()
|
||||
|
||||
//表单提交事件
|
||||
async function handleSubmit() {
|
||||
setModalProps({ confirmLoading: true })
|
||||
const userStore = useUserStore()
|
||||
ChangeOrg({ id: orgId.value }).then(res => {
|
||||
userStore.setToken(res.data.accessToken)
|
||||
userStore.setUserInfo({ refreshToken: res.data.refreshToken })
|
||||
getUserInfo().then(data => {
|
||||
setModalProps({ confirmLoading: false })
|
||||
const userInfo = data.data
|
||||
userStore.setUserInfo(userInfo)
|
||||
tabStore.closeAllTab(router)
|
||||
$message.createMessage.success('切换成功!')
|
||||
closeModal()
|
||||
}).catch(() => {
|
||||
setModalProps({ confirmLoading: false })
|
||||
})
|
||||
refreshPage()
|
||||
}).catch(() => {
|
||||
setModalProps({ confirmLoading: false })
|
||||
})
|
||||
}
|
||||
|
||||
async function init(info) {
|
||||
if (!info) {
|
||||
$message.createMessage.warning('当前系统无登录用户!')
|
||||
return
|
||||
} else {
|
||||
await setModalProps({ visible: true })
|
||||
options.value = info.userOrgs
|
||||
orgId.value = info.orgId
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
init,
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.ds-org-toggle-model {
|
||||
.ant-radio-group .ant-radio-wrapper {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue