login.vue 2.8 KB

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