login.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view class="login">
  3. <h3 style="margin-top: 100px;" @click="login">学生评价位置调换系统</h3>
  4. <div id="self_defined_element" class="self-defined-classname ui-mt40"></div>
  5. <view class="intro">
  6. 请打开钉钉APP扫码登录
  7. </view>
  8. <uni-popup ref="popup" background-color="#fff" :mask-click="false">
  9. <view style="width: 350rpx;" class="popup-content pop">
  10. <view style="margin-bottom: 24rpx;" class="">
  11. 账号
  12. </view>
  13. <view style="margin-bottom: 24rpx;" class="">
  14. <uni-easyinput type="number" v-model="user.mobile" placeholder="请输入账号"
  15. :maxlength="100"></uni-easyinput>
  16. </view>
  17. <view style="margin-bottom: 24rpx;" class="">
  18. 密码
  19. </view>
  20. <view style="margin-bottom: 24rpx;" class="">
  21. <uni-easyinput type="password" v-model="user.password" placeholder="请输入账号"
  22. :maxlength="100"></uni-easyinput>
  23. </view>
  24. <u-button @click="submit" type="primary">登录</u-button>
  25. <u-button class="ui-mt20" @click="$refs.popup.close()">关闭</u-button>
  26. <!-- <u-button class="ui-mt20" @click="loadVconsole()">加载/关闭vconsole</u-button> -->
  27. </view>
  28. </uni-popup>
  29. </view>
  30. </template>
  31. <script>
  32. import Config from '@/common/js/config.js'
  33. import ddLogin from "@/static/js/ddLogin.js"
  34. export default {
  35. name:'',
  36. data(){
  37. return {
  38. redirectUrl : '',
  39. // redirectUrl : 'https://oy-desk.wucits.com',
  40. school_id : '',
  41. num : 0,
  42. user: {
  43. mobile: '15158580014',
  44. password: 'xlg123==='
  45. }
  46. }
  47. },
  48. mounted(){
  49. this.school_id=this.getUrlParam("school_id")
  50. // this.school_id=1
  51. if(!this.school_id){
  52. this.school_id=uni.getStorageSync("school_id")
  53. }else{
  54. uni.setStorageSync("school_id",this.school_id)
  55. }
  56. this.redirectUrl=Config.schoolBaseData.redirectUrl+"?school_id="+this.school_id
  57. let token=uni.getStorageSync("token")
  58. if(!token){
  59. this.buildCode()
  60. }else{
  61. uni.navigateTo({
  62. url: "/pages/studentRanked/studentRanked"
  63. })
  64. }
  65. },
  66. methods:{
  67. login() {
  68. this.num++
  69. if (this.num >= 10) {
  70. this.$refs.popup.open('center');
  71. this.num = 0
  72. }
  73. },
  74. submit() {
  75. this.$api.sendRequest({
  76. url: `/mobile/login/passLogin`,
  77. data: this.user,
  78. success: res => {
  79. this.loginCallBack(res.data)
  80. this.$refs.popup.close()
  81. },
  82. })
  83. },
  84. loginCallBack(teacher){
  85. console.log(teacher,"denglu");
  86. this.$store.commit("setTeacherInfo",teacher)
  87. uni.setStorageSync('token', teacher.token)
  88. uni.navigateTo({
  89. url:'/pages/studentRanked/studentRanked'
  90. })
  91. },
  92. doLogin(code){
  93. console.log("zhixinglema",this.school_id);
  94. this.$api.sendRequest({
  95. url: `/mobile/getUserInfoByScanCode`,
  96. method : 'post',
  97. data : {
  98. code,
  99. school_id : this.school_id
  100. },
  101. success: res => {
  102. this.loginCallBack(res.data)
  103. },
  104. error: res => {
  105. }
  106. })
  107. },
  108. getUrlParam(name) {
  109. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  110. var r = window.location.search.substr(1).match(reg);
  111. if (r != null) return unescape(r[2]);
  112. return null;
  113. },
  114. buildCode(){
  115. console.log(this.redirectUrl,"this.redirectUrl")
  116. window.DTFrameLogin(
  117. {
  118. id: 'self_defined_element',
  119. width: '300',
  120. height: '300',
  121. },
  122. {
  123. redirect_uri: encodeURIComponent(this.redirectUrl),
  124. client_id: Config.schoolBaseData.client_id,
  125. scope: 'openid',
  126. response_type: 'code',
  127. prompt: 'consent',
  128. },
  129. (loginResult) => {
  130. const {redirectUrl, authCode, state} = loginResult;
  131. console.log(authCode,"ininini?",redirectUrl);
  132. this.doLogin(authCode)
  133. // 这里可以直接进行重定向
  134. // 也可以在不跳转页面的情况下,使用code进行授权
  135. },
  136. (errorMsg) => {
  137. // 这里一般需要展示登录失败的具体原因
  138. console.log(`Login Error: ${errorMsg}`);
  139. },
  140. );
  141. }
  142. }
  143. }
  144. </script>
  145. <style scoped>
  146. .login{
  147. display: flex;
  148. justify-content: center;
  149. flex-direction: column;
  150. align-items: center;
  151. }
  152. .self-defined-classname {
  153. width: 300px;
  154. height: 300px;
  155. background-color: rebeccapurple;
  156. }
  157. .intro{
  158. color: #333;
  159. margin-top: 20px;
  160. }
  161. </style>