index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div id="app">
  3. <div class="main-content" v-show="preFlag">
  4. <img src="../assets/tmd_logo.png" class="logo animated fadeIn" @load="loadImage" />
  5. <!-- 选择身份 -->
  6. <div class="centerCol" v-if="isSelectRole">
  7. <span class="title">{{$t('index.chooseRole')}}</span>
  8. <div class="select-role-wrap center">
  9. <div class="role-item centerCol" v-for="item in roleList" @click="handleRole(item)">
  10. <Icon type="ios-ribbon" size="60" /><span class="role-name">{{item.label}}</span>
  11. </div>
  12. </div>
  13. </div>
  14. <!-- 选择模块 -->
  15. <div class="auth-wrap centerCol" v-else>
  16. <Button type="primary" size="large" class="btn-login animated fadeIn" @click="handleLogin('login')" v-show="!isLogin">{{$t('index.login')}}</Button>
  17. <Button type="primary" size="large" class="btn-login animated fadeIn" @click="handleLogin('regist')" v-show="!isLogin">{{$t('index.register')}}</Button>
  18. <Button type="primary" size="large" class="btn-login animated fadeIn" @click="handleAuth()" v-show="!hasAuthSchool">去授权</Button>
  19. <p v-show="isLogin" class="suc-text">{{$t('index.authSchool')}}: {{schoolInfo.schoolName}}</p>
  20. <div v-show="isLogin" class="suc-text select-role">
  21. <span>{{$t('index.currentRole')}}:</span>
  22. <Select v-model="currentRole" style="width:200px" @on-change="handleRoleChange">
  23. <Option v-for="item in roleList" :value="item.value" :key="item.value">{{ item.label }}</Option>
  24. </Select>
  25. </div>
  26. <div v-show="isLogin" class="overlay-wrap center animated fadeIn">
  27. <SelectModule :moduleList="moduleList"></SelectModule>
  28. </div>
  29. </div>
  30. </div>
  31. <!-- 用户信息 -->
  32. <div class="user-wrap" v-show="isLogin">
  33. <div>
  34. <span class="ivu-avatar ivu-avatar-circle ivu-avatar-default ivu-avatar-icon"><i class="ivu-icon ivu-icon-ios-person"></i></span>
  35. <span>{{username}}</span>
  36. <span class="btn-exit" @click="handleExit">{{$t('index.exit')}}</span>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import animate from 'animate.css'
  43. import SelectModule from '@/common/SelectModule.vue'
  44. export default {
  45. components: {
  46. SelectModule
  47. },
  48. data() {
  49. return {
  50. isLogin: false,
  51. isSelectRole: false,
  52. username: "",
  53. hasAuthSchool: true,
  54. schoolInfo: {},
  55. preFlag: false,
  56. currentRole: "",
  57. roleList: [],
  58. moduleList: [{
  59. name: "学情分析",
  60. link: "/saindex"
  61. }, {
  62. name: "课纲系统",
  63. link: "/sak"
  64. }, {
  65. name: "课纲管理",
  66. link: "/sak"
  67. }]
  68. }
  69. },
  70. methods: {
  71. //前往授权
  72. handleAuth() {
  73. this.$router.replace('/authorization')
  74. },
  75. //获取登录人员角色列表
  76. changeLoginRoles(enRoles) {
  77. let arr = [];
  78. this.$api.getLoginRoles({}).then(res => {
  79. let cnRoles = res.result.data;
  80. for (let i in cnRoles) {
  81. for (let j in enRoles) {
  82. if (enRoles[j] == cnRoles[i].rowKey) {
  83. arr.push({
  84. value: enRoles[j],
  85. label: cnRoles[i].name
  86. });
  87. }
  88. }
  89. }
  90. this.roleList = arr;
  91. })
  92. },
  93. //图片加载完成后再展示
  94. loadImage() {
  95. this.preFlag = true;
  96. },
  97. //访问TW登录并回调
  98. handleLogin(types) {
  99. let that = this;
  100. that.$api.getLoginLink({ date: "151615156", type: types }).then(res => {
  101. let loginUrl = res.result.data;
  102. let callback = window.location.href;
  103. window.location.href = loginUrl + callback;
  104. })
  105. },
  106. //获取URL地址的指定参数
  107. getParamAsCH(paramName) {
  108. var paramValue = "";
  109. var isFound = false;
  110. if (window.location.search.indexOf("?") == 0 && window.location.search.indexOf("=") > 1) {
  111. var arrSource = decodeURI(window.location.search).substring(1, window.location.search.length).split("&");
  112. var i = 0;
  113. while (i < arrSource.length && !isFound) {
  114. if (arrSource[i].indexOf("=") > 0) {
  115. if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase()) {
  116. paramValue = arrSource[i].split("=")[1];
  117. isFound = true;
  118. }
  119. }
  120. i++;
  121. }
  122. }
  123. paramValue = unescape(paramValue)
  124. return paramValue;
  125. },
  126. //登录回调函数获取参数
  127. loginCallback() {
  128. let that = this;
  129. let bcrypt = require('bcryptjs');
  130. let name = this.getParamAsCH("name") ? this.getParamAsCH("name") : localStorage.getItem('username');
  131. let teamModelId = this.getParamAsCH("id");
  132. let ticket = this.getParamAsCH("ticket");
  133. let token = localStorage.getItem('token') ? localStorage.getItem('token') : "";
  134. that.$Spin.show();
  135. that.$api.checkLogin({ //登录验证
  136. name: name,
  137. teamModelId: teamModelId,
  138. ticket: ticket,
  139. token: token,
  140. sign: bcrypt.hashSync(ticket + teamModelId)
  141. }).then(res => {
  142. let token = res.result.data.jwtToken.access_token;
  143. if (token) {
  144. if (!localStorage.getItem('token')) {
  145. that.$Message.success(this.$t('index.loginSuc'));
  146. }
  147. let decode = that.$jwtDecode(res.result.data.jwtToken.access_token);//解析返回的token
  148. that.roleList = Array.isArray(decode.role) ? decode.role : decode.role.split(' ');
  149. that.changeLoginRoles(Array.isArray(decode.role) ? decode.role : decode.role.split(' '));//身份替换
  150. localStorage.setItem('token', token);
  151. localStorage.setItem('username', decode.name);
  152. localStorage.setItem('decodeData', JSON.stringify(decode));
  153. that.username = decode.name;
  154. that.isLogin = true;
  155. that.isSelectRole = true;
  156. that.$Spin.hide();
  157. } else {
  158. that.$Message.warning("服务器错误!未返回token");
  159. }
  160. }).catch(res => {
  161. //that.$Message.warning("当前未登录");
  162. that.$Spin.hide();
  163. })
  164. },
  165. //判断当前登录用户是否有授权学校
  166. getAuthSchool(roleCode) {
  167. this.$api.getAuthSchool({ RoleCode: roleCode }).then(res => {
  168. this.schoolInfo = res.result.data;
  169. this.hasAuthSchool = true;
  170. localStorage.setItem('schoolInfo', JSON.stringify(res.result.data));
  171. })
  172. },
  173. //退出操作清除存储数据
  174. handleExit() {
  175. localStorage.clear();
  176. window.location.href = window.location.origin;
  177. },
  178. //选择身份跳转到模块选择
  179. handleRole(role) {
  180. this.isSelectRole = false;
  181. this.currentRole = role.value;
  182. this.getAuthSchool(role.value);
  183. },
  184. //身份变化
  185. handleRoleChange(val) {
  186. this.getAuthSchool(val);
  187. }
  188. },
  189. mounted() {
  190. this.loginCallback();
  191. }
  192. }
  193. </script>
  194. <style scoped>
  195. html, body, #app {
  196. height: 100% !important;
  197. /*-moz-user-select: none; /*火狐 firefox*/
  198. /*-webkit-user-select: none;/ /*webkit浏览器*/
  199. /*-ms-user-select: none;*/ /*IE10+*/
  200. /*user-select: none;*/
  201. }
  202. .main-content {
  203. position: relative;
  204. width: 100%;
  205. min-width: 1200px;
  206. min-height: 768px;
  207. background: url("http://chq.dygl.pujiaoyun.cn/static/img/banner.jpg") center 100% no-repeat;
  208. height: 100%;
  209. display: flex;
  210. flex-direction: column;
  211. align-items: center;
  212. padding-top: 50px;
  213. }
  214. .center {
  215. display: flex;
  216. flex-direction: row;
  217. justify-content: center;
  218. align-items: center;
  219. }
  220. .centerCol {
  221. display: flex;
  222. flex-direction: column;
  223. justify-content: center;
  224. align-items: center;
  225. }
  226. .overlay-wrap {
  227. padding: 20px 10px;
  228. background-color: rgba(218, 218, 218, 0.08);
  229. margin-top: 50px;
  230. }
  231. .logo {
  232. width: 200px;
  233. height: 200px;
  234. margin-bottom: 50px;
  235. }
  236. .btn-login {
  237. width: 150px;
  238. margin-top: 15px;
  239. background-color: #a0a1a275 !important;
  240. border-color: #87888a !important;
  241. }
  242. .suc-text {
  243. color: #fff;
  244. font-size: 14px;
  245. font-weight: 200;
  246. }
  247. .user-wrap {
  248. position: absolute;
  249. right: 50px;
  250. top: 50px;
  251. color: white;
  252. font-size: 14px;
  253. font-weight: 200;
  254. }
  255. .ivu-avatar {
  256. background-color: #30a6e1 !important;
  257. margin-right: 10px;
  258. }
  259. .btn-exit {
  260. font-size: 12px;
  261. cursor: pointer;
  262. margin-left: 15px;
  263. }
  264. .select-role {
  265. margin-top: 15px;
  266. }
  267. .select-role /deep/ .ivu-select {
  268. color: #000 !important;
  269. width: 150px !important;
  270. }
  271. .select-role .ivu-select-selection {
  272. background-color: rgba(255,255,255,.18) !important;
  273. border-color: #373737 !important;
  274. }
  275. .select-role-wrap {
  276. background-color: rgba(218, 218, 218, 0.08);
  277. padding: 5px;
  278. justify-content: normal;
  279. flex-wrap: wrap;
  280. max-width: 930px;
  281. }
  282. .role-item {
  283. width: 210px;
  284. height: 210px;
  285. background-color: rgba(179,179,179,.15);
  286. margin: 10px;
  287. color: #c5c5c5;
  288. font-size: 14px;
  289. font-weight: 200;
  290. cursor: pointer;
  291. }
  292. .role-item:hover {
  293. background: rgba(179,179,179,.42);
  294. color: #fff;
  295. }
  296. .title {
  297. font-size: 26px;
  298. font-weight: 200;
  299. color: #fff;
  300. margin-bottom: 20px;
  301. }
  302. .role-name {
  303. margin-top: 10px;
  304. }
  305. </style>