公众号项目
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.

200 lines
5.0 KiB

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