login.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="content">
  3. <view class="force-login-wrap">
  4. <view class="force-login__content y-f">
  5. <view class="logo">
  6. <view class="logo-img">
  7. <image :src="headerImg"></image>
  8. </view>
  9. </view>
  10. <view class="login-notice">允许微信授权后,可体验更多功能</view>
  11. <view class="btns" v-if="appid">
  12. <view class="author-btn" @click="loginByMp()">微信授权登录</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="footer-tips">重庆云联融智提供技术支持</view>
  17. </view>
  18. </template>
  19. <script>
  20. const isWechat = () => {
  21. return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
  22. }
  23. import { getRealLink } from '@/api/course.js'
  24. export default {
  25. data() {
  26. return {
  27. sortLink: '',
  28. appid: "",
  29. code:null,
  30. realLink: '',
  31. headerImg:''
  32. }
  33. },
  34. onLoad(option) {
  35. this.sortLink = option.sortLink || ''
  36. this.code = option.code || ''
  37. this.getRealLink()
  38. },
  39. methods: {
  40. getRealLink() {
  41. getRealLink({sortLink:this.sortLink}).then(res=>{
  42. this.headerImg = res.headerImg||''
  43. if(res.code == 200 && res.realLink) {
  44. this.realLink = res.realLink
  45. this.appid = res.config.mpAppId
  46. if(this.code) {
  47. this.loginByMp()
  48. }
  49. } else {
  50. uni.showToast({
  51. title: '课程已过期或链接无效',
  52. icon: 'none'
  53. });
  54. }
  55. }).catch(err=>{
  56. if(err.code ==='ECONNABORTED'){
  57. uni.showToast({
  58. title: '请求超时,请检查网络后重试',
  59. icon: 'none'
  60. });
  61. } else {
  62. uni.showToast({
  63. title: '发生错误,请稍后再试',
  64. icon: 'none'
  65. });
  66. }
  67. })
  68. },
  69. loginByMp(){
  70. if(this.code==null || !this.code){
  71. this.getWechatCode()
  72. return;
  73. }
  74. const url = this.realLink + '&code=' + this.code
  75. window.location.replace(url)
  76. },
  77. getWechatCode() {
  78. if (isWechat) {
  79. let appid = this.appid; //微信APPid
  80. let code = this.getUrlCode().code; //是否存在code
  81. let local = window.location.href;
  82. if (code == null || code === "") {
  83. // 不存在就打开上面的地址进行授权
  84. window.location.href =
  85. "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
  86. appid +
  87. "&redirect_uri=" +
  88. encodeURIComponent(local) +
  89. "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
  90. } else {
  91. this.code = code;
  92. }
  93. }
  94. },
  95. // 截取url中的code方法
  96. getUrlCode(){
  97. var url = location.search;
  98. var theRequest = new Object();
  99. if (url.indexOf("?") != -1) {
  100. var str = url.substr(1);
  101. var strs = str.split("&");
  102. for (var i = 0; i < strs.length; i++) {
  103. theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  104. }
  105. }
  106. return theRequest;
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss">
  112. .container {
  113. flex: 1;
  114. display: flex;
  115. flex-direction: column;
  116. justify-content: flex-start;
  117. position: relative;
  118. }
  119. .footer-tips {
  120. width: 100%;
  121. position: absolute;
  122. bottom: 14rpx;
  123. left: 0;
  124. text-align: center;
  125. font-family: PingFang SC,PingFang SC;
  126. font-weight: 500;
  127. font-size: 12px;
  128. color: #bbb;
  129. }
  130. .force-login-wrap {
  131. width: 100%;
  132. height: 100%;
  133. overflow: hidden;
  134. z-index: 11111;
  135. top: 0;
  136. .force-login__content {
  137. width: 100%;
  138. position: absolute;
  139. left: 50%;
  140. top: 40%;
  141. transform: translate(-50%, -50%);
  142. .logo{
  143. display: flex;
  144. flex-direction: column;
  145. justify-content: center;
  146. align-items: center;
  147. .logo-img{
  148. border: 4upx solid #FFFFFF;
  149. box-shadow: 0px 5px 15px 2px rgba(0,0,0,0.1);
  150. border-radius: 50%;
  151. width: 80px;
  152. height: 80px;
  153. image{
  154. border-radius: 50%;
  155. width: 100%;
  156. height: 100%;
  157. overflow: hidden;
  158. }
  159. }
  160. .title{
  161. margin-top: 20rpx;
  162. font-size: 35rpx;
  163. font-family: PingFang SC;
  164. font-weight: bold;
  165. color: #000;
  166. margin-bottom: 30rpx;
  167. }
  168. }
  169. .login-notice {
  170. font-size: 28rpx;
  171. font-family: PingFang SC;
  172. font-weight: 400;
  173. color: #000;
  174. line-height: 44rpx;
  175. text-align: center;
  176. margin-top: 20rpx;
  177. margin-bottom: 80rpx;
  178. }
  179. .btns{
  180. position: relative;
  181. width: 630rpx;
  182. height: 80rpx;
  183. margin: 0 auto;
  184. .author-btn{
  185. display: flex;
  186. justify-content: center;
  187. align-items: center;
  188. z-index:100;
  189. position: absolute;
  190. width: 630rpx;
  191. height: 80rpx;
  192. background: linear-gradient(to right, #FF5C03 0%, #E2C99E 100%);
  193. background: -moz-linear-gradient(to right, #FF5C03 0%, #E2C99E 100%);
  194. // box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  195. border-radius: 40rpx;
  196. font-size: 30rpx;
  197. font-family: PingFang SC;
  198. font-weight: 500;
  199. color: rgba(255, 255, 255, 1);
  200. }
  201. }
  202. }
  203. }
  204. </style>