兼兼街公众号代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 lines
4.9 KiB

2 years ago
  1. <template>
  2. <view>
  3. <WxBLogin v-if="code === ''"/>
  4. <view v-else class="login">
  5. <!-- <view class="login"> -->
  6. <view class="login-img flex align-center justify-center">
  7. <image src="@/static/img/logon-icon.png" mode=""></image>
  8. </view>
  9. <view class="login-title">兼职尽在兼兼街</view>
  10. <view class="btn-box">
  11. <u-button v-if="code !== ''" text="微信授权登录" :round="true" openType="getUserInfo" @click="logionClick" :customStyle="baomingStyle" :hairline="false" color="#00CCCC"></u-button>
  12. <u-button v-else="code === ''" text="获取登录权限" :round="true" openType="getUserInfo" @click="logionClick" :customStyle="baomingStyle" :hairline="false" color="#00CCCC"></u-button>
  13. </view>
  14. <view class="tips flex align-center justify-between" @click="xieyiChoose = !xieyiChoose">
  15. <view>
  16. 注册/登录即代表同意
  17. <text class="xieyi" @click.stop="seeXieyi">用户协议与隐私政策</text>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import WxBLogin from '@/components/run-component/wx-b-login.vue'
  25. export default{
  26. components: {
  27. WxBLogin
  28. },
  29. data(){
  30. return{
  31. xieyiChoose:true,
  32. code: '',
  33. did: '',
  34. vid:'',
  35. baomingStyle: {
  36. fontSize:"30rpx",
  37. fontWeight:"700",
  38. height: "100rpx",
  39. width: "480rpx"
  40. },
  41. baomingStyleQuxiao:{
  42. fontSize:"30rpx",
  43. fontWeight:"700",
  44. height: "100rpx",
  45. width: "480rpx",
  46. marginTop : "40rpx"
  47. }
  48. }
  49. },
  50. onLoad(err){
  51. if (err.vid) {
  52. this.$store.commit('set_ivcode', err.vid);
  53. }
  54. if (err.did) {
  55. uni.setStorageSync("did", err.did);
  56. }
  57. this.code = this.GetQueryString('code');
  58. if(!this.code){
  59. this.getwx_authorize();
  60. }
  61. },
  62. // 隐藏微信h5的标题栏
  63. onReady() {
  64. this.$com.displayNav();
  65. },
  66. methods:{
  67. seeXieyi(){
  68. uni.navigateTo({
  69. url:'/pages/my/xieyi'
  70. })
  71. },
  72. logionClick(){
  73. let actoken ="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2OTAxNzI3NjAsInVzZXJuYW1lIjoib2ROdHc2dEJVNmMxenlnU1lmb2d4ZWdTX2xxbyJ9.btUCZf5Jhx6XZIDLqI8TVTa00edZ989sxzNXe0V0eiw";
  74. this.$store.commit('set_userToken', actoken);
  75. uni.switchTab({
  76. url:'/pages/my/index'
  77. })
  78. let did = uni.getStorageSync("did");
  79. if (did) {
  80. uni.navigateTo({
  81. url:'/pages/home/course-detial?id=' + did
  82. })
  83. } else {
  84. uni.switchTab({
  85. url:'/pages/my/index'
  86. })
  87. }
  88. // if(this.code){
  89. // //直接去登录发起请求
  90. // this.toWxLogin()
  91. // } else {
  92. // //获取code 静默授权
  93. // this.getwx_authorize();
  94. // }
  95. },
  96. toWxLogin(code){
  97. this.vid= uni.getStorageSync("ivcode");
  98. this.$api('wxLogin',{code:this.code, vid: this.vid})
  99. .then(res=>{
  100. if(res.code == 200){
  101. this.$store.commit('set_userToken',res.result.token);
  102. this.$store.commit('set_userInfo',res.result.userInfo);
  103. let did = uni.getStorageSync("did");
  104. if (did) {
  105. uni.setStorageSync("did", null);
  106. uni.navigateTo({
  107. url:'/pages/home/course-detial?id=' + did
  108. })
  109. } else {
  110. uni.navigateTo({
  111. url:'/pages/my/my-xiansuo-now'
  112. })
  113. }
  114. }else{
  115. this.$Toast(res.message)
  116. }
  117. }).catch(error=>{
  118. uni.showModal({
  119. content:JSON.stringify(error)
  120. })
  121. })
  122. },
  123. getwx_authorize(){
  124. console.log("进入了这")
  125. this.logionClick()
  126. // let vid = uni.getStorageSync("ivcode");
  127. // //授权的回调地址
  128. // let redirect_uri = encodeURIComponent('https://job.java996.icu/pages/my/login-kehu');
  129. // //这是我们公众号的appid
  130. // let appid = 'wx6fb4a17b28186d58';
  131. // //修改授权参数
  132. // window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appid+'&redirect_uri='+redirect_uri+'&response_type=code&scope=snsapi_userinfo&state='+vid+'&connect_redirect=1#wechat_redirect';
  133. },
  134. //获取url中参数的方法
  135. GetQueryString(name) {
  136. var url = window.location.href;
  137. try {
  138. var cs = url.split('?')[1]; //获取?之后的参数字符串
  139. var cs_arr = cs.split('&'); //参数字符串分割为数组
  140. for (var i = 0; i < cs_arr.length; i++) { //遍历数组,拿到json对象
  141. if (cs_arr[i].split('=')[0] == name) {
  142. return cs_arr[i].split('=')[1];
  143. }
  144. }
  145. return "";
  146. } catch {
  147. return "";
  148. }
  149. },
  150. }
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. .login {
  155. background-size: 100% 100%;
  156. height: 70vh;
  157. padding-top: 154rpx;
  158. .login-title {
  159. margin-top: 40rpx;
  160. font-size: 34rpx;
  161. font-weight: 700;
  162. text-align: center;
  163. padding-bottom: 30rpx;
  164. }
  165. .login-img {
  166. image {
  167. border-radius: 50%;
  168. width:248rpx;
  169. height: 248rpx;
  170. }
  171. }
  172. .btn-box {
  173. margin-top: 136rpx;
  174. }
  175. .tips {
  176. width: 500rpx;
  177. position: fixed;
  178. bottom: 52rpx;
  179. left: 51%;
  180. transform: translate(-50%,0);
  181. font-size: 24rpx;
  182. color: #707070;
  183. .xieyi {
  184. color: #00CCFF;
  185. }
  186. }
  187. }
  188. </style>