login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <el-container class="login-container">
  3. <el-header height="40px" style="background: #fff6e8;" class="p0">
  4. <top v-if="topLoadin" @userNavTo="userTo"></top>
  5. </el-header>
  6. <el-main class="p0">
  7. <login-top-menus :routers="visibleRouters"></login-top-menus>
  8. <login-form-banner ref="loginForm" :is-login="isLogin" :login-form="loginForm" :login-rules="loginRules"
  9. :loading="loading"></login-form-banner>
  10. <div class="fx-column fx-cen-cen">
  11. <index-card-subject-query class="mt20 index-block"/>
  12. <index-card-elective-test class="mt20 index-block"/>
  13. <index-card-career class="mt20 index-block"/>
  14. <index-preference-simulate class="mt20 index-block"/>
  15. <index-preference class="mt20 index-block"/>
  16. <index-news-top-wrapper class="mt20 index-block"/>
  17. </div>
  18. <bottom-p class="mt20"></bottom-p>
  19. <el-dialog v-if="dialogVisible" title :visible.sync="dialogVisible" width="850px">
  20. <complete-profile @completed="handleProfileCompleted"
  21. style="margin-left:250px; padding:0 30px"></complete-profile>
  22. </el-dialog>
  23. <el-dialog v-if="forgetDialogVisiable" :visible.sync="forgetDialogVisiable" title="忘记密码" width="650px"
  24. style="height:600px">
  25. <forget-password @resetPwdSuccess="forgetDialogVisiable=false"></forget-password>
  26. </el-dialog>
  27. </el-main>
  28. </el-container>
  29. </template>
  30. <script>
  31. import store from '@/store'
  32. import router from '@/router'
  33. import { mapActions, mapGetters } from 'vuex'
  34. import auth from '@/utils/auth'
  35. import { getFrontInitialRouters } from '@/api/system/user'
  36. import forgetPassword from '@/views/components/forget-pwd.vue'
  37. import CompleteProfile from '@/views/components/complete-profile.vue'
  38. import RouterHelpMixin from '@/router/router-help-mixin'
  39. import LoginTopInfo from '@/views/index/components/login-top-info'
  40. import LoginFormBanner from '@/views/index/components/login-form-banner'
  41. import LoginTopMenus from '@/views/index/components/login-top-menus'
  42. import loginCheckMixin from '@/views/components/blocks/index-login-check-mixin'
  43. import IndexCardElective from '@/views/index/components/index-card-elective'
  44. import IndexCardSubjectQuery from '@/views/index/components/index-card-subject-query'
  45. import IndexCardElectiveTest from '@/views/index/components/index-card-elective-test'
  46. import IndexPreferenceSimulate from '@/views/index/components/index-preference-simulate'
  47. import IndexPreference from '@/views/index/components/index-preference'
  48. import IndexCardCareer from '@/views/index/components/index-card-career'
  49. import IndexNewsTopWrapper from '@/views/index/components/index-news-top-wrapper'
  50. export default {
  51. mixins: [RouterHelpMixin, loginCheckMixin],
  52. components: {
  53. IndexNewsTopWrapper,
  54. IndexCardCareer,
  55. IndexPreference,
  56. IndexPreferenceSimulate,
  57. IndexCardElectiveTest,
  58. IndexCardSubjectQuery,
  59. IndexCardElective,
  60. LoginTopMenus,
  61. LoginFormBanner,
  62. LoginTopInfo,
  63. forgetPassword,
  64. CompleteProfile
  65. },
  66. provide() {
  67. return {
  68. to: this.to,
  69. userTo: this.userTo,
  70. handleLogin: this.handleLogin,
  71. logout: this.logout,
  72. handleForgetPwd: this.handleForgetPwd
  73. }
  74. },
  75. data() {
  76. return {
  77. forgetDialogVisiable: false,
  78. topLoadin: true,
  79. isLogin: auth.getToken(),
  80. loginObj: {},
  81. loading: false,
  82. gradeLoading: false,
  83. navList: [],
  84. loginForm: {
  85. username: '',
  86. password: '',
  87. // rememberMe: false,
  88. // code: "",
  89. // uuid: "",
  90. relation: 1,
  91. grade: 2,
  92. year: ''
  93. },
  94. loginRules: {
  95. relation: [
  96. {
  97. required: true,
  98. trigger: 'blur',
  99. message: '请选择学生端或者老师端'
  100. }
  101. ],
  102. grade: [
  103. {
  104. required: true,
  105. trigger: 'blur',
  106. message: '请选择学校类别'
  107. }
  108. ],
  109. username: [
  110. {
  111. required: true,
  112. trigger: 'blur',
  113. message: '用户名不能为空'
  114. }
  115. ],
  116. password: [
  117. {
  118. required: true,
  119. trigger: 'blur',
  120. message: '密码不能为空'
  121. }
  122. ],
  123. code: [
  124. {
  125. required: true,
  126. trigger: 'change',
  127. message: '验证码不能为空'
  128. }
  129. ]
  130. },
  131. options: {
  132. img: store.getters.avatar //裁剪图片的地址
  133. },
  134. submitLoading: false,
  135. schoolData: [],
  136. gradeData: [],
  137. classData: [],
  138. areaSchoolAndYears: {},
  139. isSecd: false,
  140. times: 120,
  141. form: {
  142. username: '',
  143. phoneNumber: '',
  144. code: '',
  145. schoolId: '',
  146. gradeId: [],
  147. clazzId: []
  148. },
  149. subjectData: [],
  150. dialogVisible: false,
  151. id: 0,
  152. props: {
  153. lazy: true,
  154. lazyLoad(node, resolve) {
  155. const { level } = node
  156. setTimeout(() => {
  157. const nodes = Array.from({
  158. length: level + 1
  159. }).map((item) => {
  160. let a = ''
  161. if (level == '0') {
  162. a = '省'
  163. } else if (level == '1') {
  164. a = '市'
  165. } else {
  166. a = '区'
  167. }
  168. return {
  169. value: 1212,
  170. label: `选项${a} `,
  171. leaf: level >= 2
  172. }
  173. })
  174. // 通过调用resolve将子节点数据返回,通知组件数据加载完成
  175. resolve(nodes)
  176. }, 1000)
  177. }
  178. }
  179. }
  180. },
  181. computed: {
  182. ...mapGetters([
  183. 'isFrontStudent',
  184. 'isFrontTeacher',
  185. 'isFrontMaster',
  186. 'currentUser'
  187. ]),
  188. visibleRouters() {
  189. return this.navList.filter((r) => r.meta?.title && !r.hidden)
  190. }
  191. },
  192. created() {
  193. let u = navigator.userAgent
  194. let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1
  195. if (isAndroid) {
  196. let url = this.$route.fullPath.split('?')[1]
  197. if (url && !this.isLogin) {
  198. let urlData = url.split('&')
  199. for (let i = 0; i < urlData.length; i++) {
  200. this.loginObj[urlData[i].split('=')[0]] =
  201. urlData[i].split('=')[1]
  202. }
  203. if (this.loginObj.username && this.loginObj.password) {
  204. // 直接发起登录
  205. this.loading = true
  206. this.Login(this.loginObj)
  207. .then(() => {
  208. this.isLogin = true
  209. this.loading = false
  210. this.getUser()
  211. this.getNav()
  212. // this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
  213. })
  214. .catch(() => {
  215. this.loading = false
  216. })
  217. }
  218. }
  219. } else {
  220. this.getUser()
  221. this.getNav()
  222. }
  223. },
  224. methods: {
  225. ...mapActions(['GenerateRoutes', 'Login', 'LogOut', 'GetInfo']),
  226. getNav() {
  227. console.log(
  228. 'getNav called',
  229. 'real menu=' + !!(this.islogin && this.currentUser.isBind),
  230. this.currentUser,
  231. this.isLogin
  232. )
  233. if (this.isLogin) {
  234. this.GenerateRoutes().then((accessRoutes) => {
  235. console.log('GenerateRoutes accessRoutes', accessRoutes)
  236. router.addRoutes(accessRoutes) // 动态添加可访问路由表
  237. this.navList = JSON.parse(
  238. JSON.stringify(
  239. this.$store.state.permission.topbarRouters
  240. )
  241. )
  242. })
  243. } else {
  244. getFrontInitialRouters().then((res) => {
  245. this.navList = res.data.map((r) => ({
  246. path: r.path,
  247. meta: r.meta
  248. }))
  249. })
  250. }
  251. },
  252. gouAction(data) {
  253. // 22.6.7 hht 作废此方法,只处理了有限级跳转
  254. if (data && data.length > 0) {
  255. if (data[0].children && data[0].children.length > 0) {
  256. if (
  257. data[0].children[0].children &&
  258. data[0].children[0].children.length > 0
  259. ) {
  260. return data[0].children[0].children.path
  261. } else {
  262. return data[0].path + '/' + data[0].children[0].path
  263. }
  264. } else {
  265. return data[0].path
  266. }
  267. } else {
  268. return ''
  269. }
  270. },
  271. handleClick(data) {
  272. let item = JSON.parse(JSON.stringify(data))
  273. let routes = undefined //三级菜单
  274. let second = [] //二级
  275. let routesTo = []
  276. if (item.children) {
  277. //有二级菜单
  278. item.children.forEach((item2) => {
  279. if (item2.children) {
  280. item2.children.forEach((item3) => {
  281. item3.path =
  282. item.path + '/' + item2.path + '/' + item3.path
  283. })
  284. if (!routes && item2.children.length) {
  285. //一级菜单下面第一个有3个菜单的二级菜单
  286. routes = item2.children
  287. routesTo = item2.children
  288. }
  289. } else {
  290. if (!routes) {
  291. routes = []
  292. }
  293. routesTo = item.children
  294. }
  295. item2.path = item.path + '/' + item2.path
  296. item2.level = 2
  297. second.push(item2)
  298. })
  299. auth.setActiveMenu(second[0].path)
  300. // let fal = false
  301. // second.forEach((item) => {
  302. // if (!fal && item.children && item.children.length > 0) {
  303. // auth.setActiveMenu(item.path)
  304. // fal = true
  305. // }
  306. // })
  307. auth.setMenuTab(second)
  308. this.three = true
  309. this.$store.commit('SET_SIDEBAR_ROUTERS', routes)
  310. } else {
  311. //没有二级菜单
  312. this.$store.commit('SET_SIDEBAR_ROUTERS', [])
  313. this.$router.push({
  314. path: item.path
  315. })
  316. }
  317. let path = this.findLeafDescendantPath(data)
  318. if (path) {
  319. this.$router.push({
  320. path: path
  321. })
  322. auth.setMenuListAction(path)
  323. } else {
  324. }
  325. auth.setMenuList(routes)
  326. },
  327. logout() {
  328. this.$confirm('确定注销并退出系统吗?', '提示', {
  329. confirmButtonText: '确定',
  330. cancelButtonText: '取消',
  331. type: 'warning'
  332. }).then(() => {
  333. this.LogOut().then(() => {
  334. this.isLogin = false
  335. this.getNav()
  336. this.topLoadin = false
  337. this.loginObj = {}
  338. setTimeout(() => {
  339. this.topLoadin = true
  340. this.$router.push({ path: '/login' })
  341. }, 10)
  342. })
  343. })
  344. },
  345. getUser() {
  346. if (!this.isLogin) return
  347. this.GetInfo().then((response) => {
  348. this.dialogVisible = !this.currentUser.isBind
  349. this.topLoadin = false
  350. setTimeout(() => {
  351. this.topLoadin = true
  352. }, 10)
  353. })
  354. },
  355. userTo() {
  356. //跳转至个人中心
  357. if (this.isLogin && !this.currentUser.isBind) {
  358. this.dialogVisible = true
  359. this.$message.error('请先完善信息!')
  360. return
  361. }
  362. const pcRouter = this.navList.find((r) => r.path == '/user')
  363. if (pcRouter) this.to(pcRouter)
  364. },
  365. to(url) {
  366. console.log('will go to', url)
  367. auth.removeMenuTab()
  368. auth.removeMenuList()
  369. if (this.isLogin && this.currentUser.isBind) {
  370. if (url == '/login') {
  371. window.location.reload()
  372. return
  373. }
  374. if (
  375. url ==
  376. '/index?type=http://8.134.76.179/index.php?m=login&token=94c750ea0f7f41d7753327792e937589'
  377. ) {
  378. window.open(
  379. 'http://8.134.76.179/index.php?m=login&token=' +
  380. this.currentUser.code
  381. )
  382. } else if (url == '/user/profile') {
  383. this.$router.push({
  384. path: url
  385. })
  386. } else {
  387. this.handleClick(url)
  388. }
  389. } else if (this.isLogin && this.currentUser.isBind) {
  390. this.dialogVisible = true
  391. this.$message.error('请先完善信息!')
  392. } else {
  393. this.$message.error('请先登陆!')
  394. }
  395. },
  396. handleForgetPwd() {
  397. this.forgetDialogVisiable = true
  398. },
  399. handleLogin() {
  400. this.$refs.loginForm.validate((valid) => {
  401. if (valid) {
  402. this.loading = true
  403. this.Login(this.loginForm)
  404. .then(() => {
  405. this.isLogin = true
  406. this.loading = false
  407. this.getUser()
  408. this.getNav()
  409. // this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
  410. })
  411. .catch(() => {
  412. this.loading = false
  413. })
  414. }
  415. })
  416. },
  417. handleProfileCompleted() {
  418. this.dialogVisible = !this.currentUser.isBind
  419. this.getNav() //重新获取菜单
  420. }
  421. }
  422. }
  423. </script>
  424. <style scoped>
  425. .login-container {
  426. background-color: #F2F2F2;
  427. }
  428. /deep/ .el-dialog {
  429. background: url("../../assets/images/img_bg1.png") no-repeat;
  430. /* background-size: 100% 100%;
  431. height: 580px; */
  432. max-height: 520px;
  433. width: 800px;
  434. }
  435. @media screen and (min-width: 1440px) {
  436. .index-block {
  437. width: 1350px;
  438. overflow: hidden;
  439. }
  440. }
  441. @media screen and (max-width: 1439px) {
  442. .index-block {
  443. width: calc(100vw - 80px);
  444. overflow: hidden;
  445. }
  446. }
  447. </style>