login.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <view class="login">
  3. <h3 style="margin-top: 100px;">学生评价位置调换系统</h3>
  4. <div id="self_defined_element" class="self-defined-classname ui-mt40"></div>
  5. <view class="intro">
  6. 请打开钉钉APP扫码登录
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. import Config from '@/common/js/config.js'
  12. import ddLogin from "@/static/js/ddLogin.js"
  13. export default {
  14. name:'',
  15. data(){
  16. return {
  17. redirectUrl : '',
  18. // redirectUrl : 'https://oy-desk.wucits.com',
  19. school_id : ''
  20. }
  21. },
  22. mounted(){
  23. this.school_id=this.getUrlParam("school_id")
  24. // this.school_id=1
  25. if(!this.school_id){
  26. this.school_id=uni.getStorageSync("school_id")
  27. }else{
  28. uni.setStorageSync("school_id",this.school_id)
  29. }
  30. this.redirectUrl=Config.schoolBaseData.redirectUrl+"?school_id="+this.school_id
  31. let token=uni.getStorageSync("token")
  32. if(!token){
  33. this.buildCode()
  34. }else{
  35. uni.navigateTo({
  36. url: "/pages/studentRanked/studentRanked"
  37. })
  38. }
  39. },
  40. methods:{
  41. doLogin(code){
  42. console.log("zhixinglema",this.school_id);
  43. this.$api.sendRequest({
  44. url: `/mobile/getUserInfoByScanCode`,
  45. method : 'post',
  46. data : {
  47. code,
  48. school_id : this.school_id
  49. },
  50. success: res => {
  51. console.log(res,code,"denglu");
  52. this.$store.commit("setTeacherInfo",res.data.teacher)
  53. uni.setStorageSync('token', res.data.teacher.token)
  54. uni.navigateTo({
  55. url:'/pages/studentRanked/studentRanked'
  56. })
  57. // window.location.href = this.redirectUrl;
  58. },
  59. error: res => {
  60. }
  61. })
  62. },
  63. getUrlParam(name) {
  64. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  65. var r = window.location.search.substr(1).match(reg);
  66. if (r != null) return unescape(r[2]);
  67. return null;
  68. },
  69. buildCode(){
  70. console.log(this.redirectUrl,"this.redirectUrl")
  71. window.DTFrameLogin(
  72. {
  73. id: 'self_defined_element',
  74. width: '300',
  75. height: '300',
  76. },
  77. {
  78. redirect_uri: encodeURIComponent(this.redirectUrl),
  79. client_id: Config.schoolBaseData.client_id,
  80. scope: 'openid',
  81. response_type: 'code',
  82. prompt: 'consent',
  83. },
  84. (loginResult) => {
  85. const {redirectUrl, authCode, state} = loginResult;
  86. console.log(authCode,"ininini?",redirectUrl);
  87. this.doLogin(authCode)
  88. // 这里可以直接进行重定向
  89. // 也可以在不跳转页面的情况下,使用code进行授权
  90. },
  91. (errorMsg) => {
  92. // 这里一般需要展示登录失败的具体原因
  93. console.log(`Login Error: ${errorMsg}`);
  94. },
  95. );
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped>
  101. .login{
  102. display: flex;
  103. justify-content: center;
  104. flex-direction: column;
  105. align-items: center;
  106. }
  107. .self-defined-classname {
  108. width: 300px;
  109. height: 300px;
  110. background-color: rebeccapurple;
  111. }
  112. .intro{
  113. color: #333;
  114. margin-top: 20px;
  115. }
  116. </style>