123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- <template>
- <div id="app">
- <div class="main-content" v-show="preFlag">
- <img src="../assets/tmd_logo.png" class="logo animated fadeIn" @load="loadImage" />
- <!-- 选择身份 -->
- <div class="centerCol" v-if="isSelectRole">
- <span class="title">{{$t('index.chooseRole')}}</span>
- <div class="select-role-wrap center">
- <div class="role-item centerCol" v-for="item in roleList" @click="handleRole(item)">
- <Icon type="ios-ribbon" size="60" /><span class="role-name">{{item.label}}</span>
- </div>
- </div>
- </div>
- <!-- 选择模块 -->
- <div class="auth-wrap centerCol" v-else>
- <Button type="primary" size="large" class="btn-login animated fadeIn" @click="handleLogin('login')" v-show="!isLogin">{{$t('index.login')}}</Button>
- <Button type="primary" size="large" class="btn-login animated fadeIn" @click="handleLogin('regist')" v-show="!isLogin">{{$t('index.register')}}</Button>
- <Button type="primary" size="large" class="btn-login animated fadeIn" @click="handleAuth()" v-show="!hasAuthSchool">去授权</Button>
- <p v-show="isLogin" class="suc-text">{{$t('index.authSchool')}}: {{schoolInfo.schoolName}}</p>
- <div v-show="isLogin" class="suc-text select-role">
- <span>{{$t('index.currentRole')}}:</span>
- <Select v-model="currentRole" style="width:200px" @on-change="handleRoleChange">
- <Option v-for="item in roleList" :value="item.value" :key="item.value">{{ item.label }}</Option>
- </Select>
- </div>
- <div v-show="isLogin" class="overlay-wrap center animated fadeIn">
- <SelectModule :moduleList="moduleList"></SelectModule>
- </div>
- </div>
- </div>
- <!-- 用户信息 -->
- <div class="user-wrap" v-show="isLogin">
- <div>
- <span class="ivu-avatar ivu-avatar-circle ivu-avatar-default ivu-avatar-icon"><i class="ivu-icon ivu-icon-ios-person"></i></span>
- <span>{{username}}</span>
- <span class="btn-exit" @click="handleExit">{{$t('index.exit')}}</span>
- </div>
- </div>
- </div>
- </template>
- <script>
- import animate from 'animate.css'
- import SelectModule from '@/common/SelectModule.vue'
- export default {
- components: {
- SelectModule
- },
- data() {
- return {
- isLogin: false,
- isSelectRole: false,
- username: "",
- hasAuthSchool: true,
- schoolInfo: {},
- preFlag: false,
- currentRole: "",
- roleList: [],
- moduleList: [{
- name: "学情分析",
- link: "/saindex"
- }, {
- name: "课纲系统",
- link: "/sak"
- }, {
- name: "课纲管理",
- link: "/sak"
- }]
- }
- },
- methods: {
- //前往授权
- handleAuth() {
- this.$router.replace('/authorization')
- },
- //获取登录人员角色列表
- changeLoginRoles(enRoles) {
- let arr = [];
- this.$api.getLoginRoles({}).then(res => {
- let cnRoles = res.result.data;
- for (let i in cnRoles) {
- for (let j in enRoles) {
- if (enRoles[j] == cnRoles[i].rowKey) {
- arr.push({
- value: enRoles[j],
- label: cnRoles[i].name
- });
- }
- }
- }
- this.roleList = arr;
- })
- },
- //图片加载完成后再展示
- loadImage() {
- this.preFlag = true;
- },
- //访问TW登录并回调
- handleLogin(types) {
- let that = this;
- that.$api.getLoginLink({ date: "151615156", type: types }).then(res => {
- let loginUrl = res.result.data;
- let callback = window.location.href;
- window.location.href = loginUrl + callback;
- })
- },
- //获取URL地址的指定参数
- getParamAsCH(paramName) {
- var paramValue = "";
- var isFound = false;
- if (window.location.search.indexOf("?") == 0 && window.location.search.indexOf("=") > 1) {
- var arrSource = decodeURI(window.location.search).substring(1, window.location.search.length).split("&");
- var i = 0;
- while (i < arrSource.length && !isFound) {
- if (arrSource[i].indexOf("=") > 0) {
- if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase()) {
- paramValue = arrSource[i].split("=")[1];
- isFound = true;
- }
- }
- i++;
- }
- }
- paramValue = unescape(paramValue)
- return paramValue;
- },
- //登录回调函数获取参数
- loginCallback() {
- let that = this;
- let bcrypt = require('bcryptjs');
- let name = this.getParamAsCH("name") ? this.getParamAsCH("name") : localStorage.getItem('username');
- let teamModelId = this.getParamAsCH("id");
- let ticket = this.getParamAsCH("ticket");
- let token = localStorage.getItem('token') ? localStorage.getItem('token') : "";
- that.$Spin.show();
- that.$api.checkLogin({ //登录验证
- name: name,
- teamModelId: teamModelId,
- ticket: ticket,
- token: token,
- sign: bcrypt.hashSync(ticket + teamModelId)
- }).then(res => {
- let token = res.result.data.jwtToken.access_token;
- if (token) {
- if (!localStorage.getItem('token')) {
- that.$Message.success(this.$t('index.loginSuc'));
- }
- let decode = that.$jwtDecode(res.result.data.jwtToken.access_token);//解析返回的token
- that.roleList = Array.isArray(decode.role) ? decode.role : decode.role.split(' ');
- that.changeLoginRoles(Array.isArray(decode.role) ? decode.role : decode.role.split(' '));//身份替换
- localStorage.setItem('token', token);
- localStorage.setItem('username', decode.name);
- localStorage.setItem('decodeData', JSON.stringify(decode));
- that.username = decode.name;
- that.isLogin = true;
- that.isSelectRole = true;
- that.$Spin.hide();
- } else {
- that.$Message.warning("服务器错误!未返回token");
- }
- }).catch(res => {
- //that.$Message.warning("当前未登录");
- that.$Spin.hide();
- })
- },
- //判断当前登录用户是否有授权学校
- getAuthSchool(roleCode) {
- this.$api.getAuthSchool({ RoleCode: roleCode }).then(res => {
- this.schoolInfo = res.result.data;
- this.hasAuthSchool = true;
- localStorage.setItem('schoolInfo', JSON.stringify(res.result.data));
- })
- },
- //退出操作清除存储数据
- handleExit() {
- localStorage.clear();
- window.location.href = window.location.origin;
- },
- //选择身份跳转到模块选择
- handleRole(role) {
- this.isSelectRole = false;
- this.currentRole = role.value;
- this.getAuthSchool(role.value);
- },
- //身份变化
- handleRoleChange(val) {
- this.getAuthSchool(val);
- }
- },
- mounted() {
- this.loginCallback();
- }
- }
- </script>
- <style scoped>
- html, body, #app {
- height: 100% !important;
- /*-moz-user-select: none; /*火狐 firefox*/
- /*-webkit-user-select: none;/ /*webkit浏览器*/
- /*-ms-user-select: none;*/ /*IE10+*/
- /*user-select: none;*/
- }
- .main-content {
- position: relative;
- width: 100%;
- min-width: 1200px;
- min-height: 768px;
- background: url("http://chq.dygl.pujiaoyun.cn/static/img/banner.jpg") center 100% no-repeat;
- height: 100%;
- display: flex;
- flex-direction: column;
- align-items: center;
- padding-top: 50px;
- }
- .center {
- display: flex;
- flex-direction: row;
- justify-content: center;
- align-items: center;
- }
- .centerCol {
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- }
- .overlay-wrap {
- padding: 20px 10px;
- background-color: rgba(218, 218, 218, 0.08);
- margin-top: 50px;
- }
- .logo {
- width: 200px;
- height: 200px;
- margin-bottom: 50px;
- }
- .btn-login {
- width: 150px;
- margin-top: 15px;
- background-color: #a0a1a275 !important;
- border-color: #87888a !important;
- }
- .suc-text {
- color: #fff;
- font-size: 14px;
- font-weight: 200;
- }
- .user-wrap {
- position: absolute;
- right: 50px;
- top: 50px;
- color: white;
- font-size: 14px;
- font-weight: 200;
- }
- .ivu-avatar {
- background-color: #30a6e1 !important;
- margin-right: 10px;
- }
- .btn-exit {
- font-size: 12px;
- cursor: pointer;
- margin-left: 15px;
- }
- .select-role {
- margin-top: 15px;
- }
- .select-role /deep/ .ivu-select {
- color: #000 !important;
- width: 150px !important;
- }
- .select-role .ivu-select-selection {
- background-color: rgba(255,255,255,.18) !important;
- border-color: #373737 !important;
- }
- .select-role-wrap {
- background-color: rgba(218, 218, 218, 0.08);
- padding: 5px;
- justify-content: normal;
- flex-wrap: wrap;
- max-width: 930px;
- }
- .role-item {
- width: 210px;
- height: 210px;
- background-color: rgba(179,179,179,.15);
- margin: 10px;
- color: #c5c5c5;
- font-size: 14px;
- font-weight: 200;
- cursor: pointer;
- }
- .role-item:hover {
- background: rgba(179,179,179,.42);
- color: #fff;
- }
- .title {
- font-size: 26px;
- font-weight: 200;
- color: #fff;
- margin-bottom: 20px;
- }
- .role-name {
- margin-top: 10px;
- }
- </style>
|