login.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="content">
  3. <view>
  4. <view class="logo-cont">
  5. <u-image src="/static/logo.png" width="160" height="160" class="logo"></u-image>
  6. <!-- <u-image src="/static/login_slogan.png" mode="aspectFit" width="286" height="36" class="logo_text"></u-image> -->
  7. </view>
  8. <view class="login-btns">
  9. <u-button shape="circle" :custom-style="wxButton" class="login-btn" type="success" :hair-line="false" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  10. 微信授权登录
  11. </u-button>
  12. <u-gap height="30"></u-gap>
  13. <u-button shape="circle" :custom-style="phoneButton" class="login-btn phoneBtn" @click="phoneLogin" :hoverClass='none'>
  14. 账号密码登录
  15. </u-button>
  16. </view>
  17. </view>
  18. <!-- 客服电话 -->
  19. <view class="phone flex justify_center align_center">
  20. <u-icon name="phone" color="#191919" font-size="32"></u-icon>
  21. <text>客服电话:4008826012</text>
  22. </view>
  23. <view class="nologin">
  24. <u-button shape="circle" size="mini" plain lass="login-btn" @click="cansel" type="info">
  25. 暂不登录
  26. </u-button>
  27. </view>
  28. <view class="authUserYs">
  29. <view class="xieyi">
  30. 登录即代表同意
  31. <text @click="toYsPage()">
  32. 《乐色超人(骑手端)用户协议》
  33. </text>
  34. 及 <text @click="toYsPage()">
  35. 《隐私政策》
  36. </text>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. login
  44. } from "@/api/login"
  45. export default {
  46. components: {},
  47. data() {
  48. return {
  49. path: '/pages/index/index',
  50. lanuch: false,
  51. code: '',
  52. wxButton: {
  53. background: '#0DC55F'
  54. },
  55. phoneButton: {
  56. background: '#fff',
  57. color:'#000',
  58. }
  59. }
  60. },
  61. onLoad(option) {
  62. // 开启分享
  63. uni.showShareMenu({
  64. withShareTicket: true,
  65. menus: ['shareAppMessage', 'shareTimeline']
  66. })
  67. // 为解决首次登录异常问题 进入页面先调微信登录获取code
  68. this.wxLogin()
  69. const {
  70. path,
  71. lanuch
  72. } = option;
  73. this.lanuch = (lanuch + '') === 'true';
  74. if (path) {
  75. this.path = decodeURIComponent(path);
  76. }
  77. },
  78. methods: {
  79. cansel(){
  80. this.$store.state.vuex_noLogin = true
  81. uni.reLaunch({
  82. url: '/pages/index/index'
  83. })
  84. },
  85. toYsPage(){
  86. uni.navigateTo({
  87. url: '/pages/agreement/agreement'
  88. })
  89. },
  90. getPhoneNumber(e) {
  91. let _this = this
  92. uni.showLoading({
  93. mask: true,
  94. title: '加载中'
  95. });
  96. if (!this.code) {
  97. this.wxLogin()
  98. }
  99. console.log(this.code, e)
  100. if (e.target.errMsg === 'getPhoneNumber:ok') {
  101. setTimeout(()=>{
  102. const params={
  103. code: _this.code,
  104. encryptedData: e.target.encryptedData,
  105. iv: e.target.iv,
  106. }
  107. login(params).then(res => {
  108. uni.hideLoading();
  109. _this.code = ''
  110. console.log(res,_this.path, 'login data')
  111. if (res.status == '200') {
  112. getApp().globalData.token = res.data
  113. _this.$u.vuex('vuex_token',res.data)
  114. uni.$emit("getUserInfo")
  115. if (_this.path === '/pages/index/index' || _this.lanuch) {
  116. uni.reLaunch({
  117. url: _this.path
  118. });
  119. } else {
  120. uni.redirectTo({
  121. url: _this.path
  122. });
  123. }
  124. } else {
  125. uni.showToast({
  126. title: res.message,
  127. icon: 'none',
  128. duration: 2500
  129. });
  130. }
  131. });
  132. },300)
  133. } else {
  134. uni.showToast({
  135. title: '授权失败',
  136. icon: 'none',
  137. duration: 2500
  138. });
  139. }
  140. },
  141. // 调微信登录 获取code
  142. wxLogin () {
  143. let _this = this
  144. uni.login({
  145. provider: 'weixin',
  146. success(res) {
  147. console.log(res.code)
  148. _this.code = res.code
  149. }
  150. })
  151. },
  152. // 手机号登录
  153. phoneLogin () {
  154. if(this.url){
  155. wx.navigateTo({
  156. url: '/pages/login/phoneLogin?path='+this.path+'&lanuch='+this.lanuch+'&encode='+this.url
  157. })
  158. }else{
  159. wx.navigateTo({
  160. url: '/pages/login/phoneLogin?path='+this.path+'&lanuch='+this.lanuch
  161. })
  162. }
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss">
  168. .content{
  169. width: 100%;
  170. height: 100vh;
  171. padding:0 120upx;
  172. margin: 0 auto;
  173. background-color: #fff;
  174. .logo-cont{
  175. display: flex;
  176. flex-direction: column;
  177. align-items: center;
  178. }
  179. .logo{
  180. display: inline-block;
  181. margin:250upx 256upx 120upx;
  182. }
  183. .logo_text{
  184. display: inline-block;
  185. margin-bottom: 200upx;
  186. }
  187. .login-btn{
  188. display: block;
  189. height: 80upx;
  190. }
  191. .phoneBtn:active{
  192. background: #fff ;
  193. outline: none;
  194. }
  195. .nologin{
  196. text-align: center;
  197. margin: 100upx 0 50upx 0;
  198. }
  199. .phone{
  200. font-weight: 400;
  201. margin-top:40upx;
  202. text{
  203. display: inline-block;
  204. margin-left:10upx ;
  205. }
  206. }
  207. .authUserYs{
  208. text-align: center;
  209. position: absolute;
  210. bottom: 5%;
  211. font-size: 24upx;
  212. color: #191919;
  213. .xieyi{
  214. width: 80%;
  215. }
  216. text{
  217. color: #4F88F7;
  218. }
  219. }
  220. }
  221. </style>