项目内切换角色
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-12-24 16:21:23 +08:00
parent 177510643d
commit a95a129dde
14 changed files with 331 additions and 130 deletions
+51 -29
View File
@@ -244,9 +244,10 @@
</el-dialog>
<browserTip ref="browserTip" />
<toggleRole
:visible="toggleRoleVisible"
:visible.sync="toggleRoleVisible"
:loading="toggleRoleLoading"
@save="loginByRole"
@cancel="cancel"
/>
</div>
</template>
@@ -424,6 +425,13 @@ export default {
// this.$alert(this.$t('login:message:login4'), this.$t('common:title:warning'))
this.$message.warning(this.$t('login:message:login4'))
}
if (
Array.isArray(this.$store.state.user.roles) &&
this.$store.state.user.roles.length === 1
) {
this.loginByRole(this.$store.state.user.roles[0].Id)
return
}
return (this.toggleRoleVisible = true)
})
.catch(() => {
@@ -438,36 +446,44 @@ export default {
.then((res) => {
this.toggleRoleLoading = false
if (res) {
this.$store.dispatch('permission/generateRoutes').then((res) => {
this.loading = false
if (res && res.length > 0) {
this.$store.dispatch('global/getNoticeList')
this.$router.addRoutes(res)
if (this.loginType === 'DevOps') {
this.$router.replace({ path: res[0].path })
return
}
if (this.hasPermi(['role:radmin'])) {
this.$router.replace({ path: res[0].path })
return
}
if (
this.hasPermi([
'role:air',
'role:rpm',
'role:rcrc',
'role:rir',
])
) {
this.$router.replace({ path: '/trials/trials-list' })
this.$store
.dispatch('permission/generateRoutes')
.then((res) => {
this.loading = false
if (res && res.length > 0) {
this.$store.dispatch('global/getNoticeList')
this.$router.addRoutes(res)
if (this.loginType === 'DevOps') {
this.$router.replace({ path: res[0].path })
return
}
if (this.hasPermi(['role:radmin'])) {
this.$router.replace({ path: res[0].path })
return
}
if (
this.hasPermi([
'role:air',
'role:rpm',
'role:rcrc',
'role:rir',
])
) {
this.$router.replace({ path: '/trials/trials-list' })
} else {
this.$router.replace({ path: '/trials' })
}
} else {
this.$router.replace({ path: '/trials' })
this.toggleRoleLoading = false
// 此账户暂未配置菜单权限,请联系管理员处理后再登录。
this.$message.warning(this.$t('login:message:login2'))
}
} else {
// 此账户暂未配置菜单权限,请联系管理员处理后再登录。
this.$message.warning(this.$t('login:message:login2'))
}
})
})
.catch((err) => {
this.toggleRoleLoading = false
})
} else {
this.toggleRoleLoading = false
}
})
.catch(() => {
@@ -476,6 +492,12 @@ export default {
this.toggleRoleLoading = false
})
},
cancel() {
this.showCode = true
this.loading = false
this.toggleRoleLoading = false
// this.toggleRoleVisible = false
},
onSuccess() {
this.isShow = false
this.loginIn()
@@ -44,7 +44,6 @@ export default {
this.$i18n.locale = lang
this.setLanguage(lang)
this.$updateDictionary()
console.log(Vue)
this.$upload()
window.location.reload()
}
@@ -11,7 +11,7 @@
<img v-else src="@/assets/zzlogo4.png" alt="" />
<span style="white-space: nowrap" v-if="NODE_ENV !== 'usa'">
<!-- 中心影像系统EICS -->
{{ $t("trials:trials:title:eics") }}
{{ $t('trials:trials:title:eics') }}
</span>
</div>
<div class="center-menu">
@@ -39,13 +39,17 @@
>
<i class="el-icon-odometer" />
<!-- 工作台 -->
<span slot="title">{{ $t("trials:menuTitle:workbench") }}</span>
<span slot="title">{{ $t('trials:menuTitle:workbench') }}</span>
</el-menu-item>
<el-menu-item v-if="!hasPermi(['role:zys','role:zyss','role:zybs'])" index="2" :disabled="TotalNeedSignSystemDocCount !== 0">
<el-menu-item
v-if="!hasPermi(['role:zys', 'role:zyss', 'role:zybs'])"
index="2"
:disabled="TotalNeedSignSystemDocCount !== 0"
>
<i class="el-icon-box" />
<!-- 我的项目 -->
<span slot="title">
{{ $t("trials:tab:trials") }}
{{ $t('trials:tab:trials') }}
</span>
</el-menu-item>
<el-menu-item
@@ -63,7 +67,7 @@
>
<i class="el-icon-chat-dot-square" />
<!-- 通知消息 -->
<span slot="title">{{ $t("trials:tab:notice") }}</span>
<span slot="title">{{ $t('trials:tab:notice') }}</span>
</el-menu-item>
<el-submenu index="4" class="my_info">
@@ -75,128 +79,214 @@
</span>
<!-- 账户信息 -->
<el-menu-item v-if="!hasPermi(['role:air'])" index="4-2">{{
$t("trials:trials-myinfo:title:accountInfo")
$t('trials:trials-myinfo:title:accountInfo')
}}</el-menu-item>
<!-- 管理后台 -->
<el-menu-item
v-if="hasPermi(['role:dev', 'role:oa', 'role:admin'])"
index="4-4"
>{{ $t("trials:trials-myinfo:title:system") }}</el-menu-item
>{{ $t('trials:trials-myinfo:title:system') }}</el-menu-item
>
<!-- 切换角色 -->
<el-menu-item index="4-5" v-if="hasRole">{{
$t('trials:trials-myinfo:title:toggleRole')
}}</el-menu-item>
<!-- 退出 -->
<el-menu-item index="4-3">{{
$t("trials:trials-myinfo:button:loginout")
$t('trials:trials-myinfo:button:loginout')
}}</el-menu-item>
</el-submenu>
</el-menu>
<TopLang v-if="VUE_APP_OSS_CONFIG_REGION !== 'oss-us-west-1'&& NODE_ENV !== 'usa'" />
<TopLang
v-if="
VUE_APP_OSS_CONFIG_REGION !== 'oss-us-west-1' && NODE_ENV !== 'usa'
"
/>
</div>
<toggleRole
:visible.sync="toggleRoleVisible"
:loading="toggleRoleLoading"
@save="loginByRole"
/>
</div>
</template>
<script>
import { mapGetters, mapMutations } from "vuex";
import TopLang from "./topLang";
import NoticeMarquee from "./noticeMarquee";
import { mapGetters, mapMutations } from 'vuex'
import TopLang from './topLang'
import NoticeMarquee from './noticeMarquee'
import toggleRole from '@/components/toggleRole'
export default {
components: { TopLang, NoticeMarquee },
components: { TopLang, NoticeMarquee, toggleRole },
data() {
return {
activeIndex: "2",
activeIndex: '2',
isReviewer: false,
userTypeShortName: zzSessionStorage.getItem("userTypeShortName"),
notice: "",
userTypeShortName: zzSessionStorage.getItem('userTypeShortName'),
notice: '',
VUE_APP_OSS_CONFIG_REGION: process.env.VUE_APP_OSS_CONFIG_REGION,
NODE_ENV: process.env.NODE_ENV,
};
toggleRoleVisible: false,
toggleRoleLoading: false,
}
},
computed: {
...mapGetters([
"sidebar",
"name",
"userName",
"device",
"TotalNeedSignSystemDocCount",
"language",
'sidebar',
'name',
'userName',
'device',
'TotalNeedSignSystemDocCount',
'language',
]),
roles() {
return this.$store.state.user.roles
},
hasRole() {
return this.roles && this.roles.length > 1
},
},
watch: {
$route(v) {
this.changeRoute(v);
this.changeRoute(v)
},
},
created() {
console.log(!this.hasPermi(["role:air"]));
this.isReviewer = JSON.parse(zzSessionStorage.getItem("IsReviewer"));
this.changeRoute(this.$route);
// this.isReviewer = JSON.parse(zzSessionStorage.getItem('IsReviewer'))
console.log(this.$route.path, 'this.$route.path')
this.changeRoute(this.$route)
},
methods: {
...mapMutations({ setLanguage: "lang/setLanguage" }),
...mapMutations({ setLanguage: 'lang/setLanguage' }),
changeRoute(v) {
if (v.path === "/trials/trials-workbench") {
this.activeIndex = "1";
if (v.path === '/trials/trials-workbench') {
this.activeIndex = '1'
}
if (
v.path === "/trials/trials-list" ||
~v.path.indexOf("/trials/trials-panel")
v.path === '/trials/trials-list' ||
~v.path.indexOf('/trials/trials-panel')
) {
this.activeIndex = "2";
this.activeIndex = '2'
}
if (v.path === "/trials/trials-notice") {
this.activeIndex = "3";
if (v.path === '/trials/trials-notice') {
this.activeIndex = '3'
}
if (v.path === "/trials/trials-myinfo") {
this.activeIndex = "4-2";
if (v.path === '/trials/trials-myinfo') {
this.activeIndex = '4-2'
}
},
handleSelect(key, keyPath) {
switch (key) {
case "4-2":
this.go("/trials/trials-myinfo");
break;
case "4-3":
this.logout();
break;
case "4-4":
this.go("/dashboard/list");
break;
case "1":
this.go("/trials/trials-workbench");
break;
case "2":
if (~this.$route.path.indexOf("/trials/trials-panel")) {
return;
case '4-2':
this.go('/trials/trials-myinfo')
break
case '4-3':
this.logout()
break
case '4-4':
this.go('/dashboard/list')
break
case '4-5':
// this.go('/dashboard/list')
// console.log('切换角色')
this.$store.dispatch('user/getUserInfo').then((res) => {
this.toggleRoleVisible = true
})
break
case '1':
this.go('/trials/trials-workbench')
break
case '2':
if (~this.$route.path.indexOf('/trials/trials-panel')) {
return
}
var lastWorkbench = zzSessionStorage.getItem("lastWorkbench");
var lastWorkbench = zzSessionStorage.getItem('lastWorkbench')
if (lastWorkbench) {
this.go(lastWorkbench);
this.go(lastWorkbench)
} else {
this.go("/trials/trials-list");
this.go('/trials/trials-list')
}
break;
case "3":
this.go("/trials/trials-notice");
break;
break
case '3':
this.go('/trials/trials-notice')
break
}
},
toggleSideBar() {
this.$store.dispatch("app/toggleSideBar");
this.$store.dispatch('app/toggleSideBar')
},
async logout() {
await this.$store.dispatch("user/logout");
this.$router.push(`/login`);
this.$i18n.locale = "zh";
this.setLanguage("zh");
this.$updateDictionary();
await this.$store.dispatch('user/logout')
this.$router.push(`/login`)
this.$i18n.locale = 'zh'
this.setLanguage('zh')
this.$updateDictionary()
},
go(value) {
this.$router.push({ path: value });
this.$router.push({ path: value })
},
account() {
this.$router.push({ name: "Account" });
this.$router.push({ name: 'Account' })
},
loginByRole(userRoleId) {
if (this.$store.state.user.userId === userRoleId) {
this.toggleRoleVisible = false
this.toggleRoleLoading = false
return false
}
this.toggleRoleLoading = true
this.$store
.dispatch('user/loginByRole', { userRoleId })
.then((res) => {
if (res) {
this.$store
.dispatch('permission/generateRoutes')
.then((res) => {
if (res && res.length > 0) {
this.$store.dispatch('global/getNoticeList')
this.$router.addRoutes(res)
this.toggleRoleLoading = false
if (this.loginType === 'DevOps') {
this.$router.replace({ path: res[0].path })
return
}
if (this.hasPermi(['role:radmin'])) {
this.$router.replace({ path: res[0].path })
return
}
if (
this.hasPermi([
'role:air',
'role:rpm',
'role:rcrc',
'role:rir',
])
) {
this.$router.replace({ path: '/trials/trials-list' })
} else {
this.$router.replace({ path: '/trials' })
}
window.location.reload()
} else {
// 此账户暂未配置菜单权限,请联系管理员处理后再登录。
this.toggleRoleLoading = false
this.$message.warning(this.$t('login:message:login2'))
}
})
.catch((err) => {
this.toggleRoleLoading = false
})
} else {
this.toggleRoleLoading = false
}
})
.catch(() => {
this.toggleRoleLoading = false
})
},
},
};
}
</script>
<style lang="scss" scoped>
@@ -108,6 +108,35 @@
{{ $t('trials:trials-myinfo:button:update') }}
</el-button>
</el-form-item>
<el-form-item
:label="$t('trials:trials-myinfo:form:toggleRole')"
style="position: relative"
prop="VerificationCode"
v-if="hasRole"
>
<el-radio-group v-model="userRoleId" class="roles" v-if="hasRole">
<el-radio
v-for="item in roles"
:key="item.Id"
:label="item.Id"
:disabled="item.isUserRoleDisabled"
style="margin-bottom: 10px"
>
{{ item.UserTypeShortName }}
</el-radio>
</el-radio-group>
<!-- 修改 -->
<el-button
:disabled="!userRoleId"
class="saveBtn"
:loading="toggleRoleLoading"
type="primary"
size="small"
@click="toggleRole"
>
{{ $t('trials:trials-myinfo:button:toggleRole') }}
</el-button>
</el-form-item>
</el-form>
</div>
<password />
@@ -142,6 +171,8 @@ export default {
data() {
return {
userForm: {},
userRoleId: null,
toggleRoleLoading: false,
sendDisabled: true,
sendTitle: this.$t('trials:trials-myinfo:button:getVCode'),
rule: {
@@ -174,7 +205,35 @@ export default {
},
}
},
created() {
this.userRoleId = zzSessionStorage.getItem('userId')
},
computed: {
roles() {
return this.$store.state.user.roles
},
hasRole() {
return this.roles && this.roles.length > 1
},
},
methods: {
// 切换角色
toggleRole() {
if (
this.userRoleId === zzSessionStorage.getItem('userId') ||
this.toggleRoleLoading
)
return false
this.toggleRoleLoading = true
this.$store
.dispatch('user/loginByRole', { userRoleId: this.userRoleId })
.then((res) => {
window.location.reload()
})
.catch(() => {
this.toggleRoleLoading = false
})
},
setNewEmail() {
setNewEmail(this.userForm.EMail, this.userForm.VerificationCode).then(
() => {
@@ -471,7 +471,6 @@ export default {
...mapState('user', ['isTestUser'])
},
mounted() {
console.log('isTestUser: ',this.isTestUser)
this.getUserTobeDoneRecord()
this.getNeedSignTrialDocTrialIdList()
this.getUserInfo()
@@ -507,7 +506,6 @@ export default {
},
getNeedSignTrialDocTrialIdList() {
getNeedSignTrialDocTrialIdList().then(res => {
console.log(res)
this.trialIdList = res.Result
this.$nextTick(() => {
var list = document.querySelectorAll('div[tab-data]')