login.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="loginPage" >
  3. <image src="https:\/\/t38.9026.com\/uploads\/golf\/images\/2022-05-31\/20220531915411.png" mode="" class="image"></image>
  4. <view class="" style="text-align: center;margin: 100rpx;">日月峡康养旅行</view>
  5. <view class="logo">
  6. <image src="../static/login/LOGO@2x.png" mode="widthFix"></image>
  7. </view>
  8. <!-- 选择登陆方式 -->
  9. <view class="btn">
  10. <button class="phoneNumber" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" withCredentials="true">手机号一键登录</button>
  11. <!-- <view @click="gologin">
  12. 手机号一键登录
  13. </view> -->
  14. <view class="otherNumber" @click="gootherNuber">
  15. <view class="icon">
  16. <image src="../static/login/iconS@2x.png" mode="widthFix"></image>
  17. </view>
  18. <view class="" >
  19. 其他手机号登陆
  20. </view>
  21. </view>
  22. </view>
  23. <view class="aggre">
  24. 登录即代表您同意我们的
  25. <text class="underline" @click="terms">用户协议</text>和
  26. <text class="underline" @click="Policy">隐私政策</text>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import WXBizDataCrypt from "@/static/js/WXBizDataCrypt.js"
  32. export default{
  33. data(){
  34. return{
  35. tips:"获取验证码",
  36. value: '',
  37. // 输入的验证码
  38. code:'',
  39. // 获取微信登录的code
  40. wxCode:'',
  41. // 解密密钥
  42. session_key:'',
  43. // 手机号
  44. phone:'',
  45. encryptedData:"",
  46. iv:'',
  47. openid:"",
  48. unionid:'',
  49. nickName:''
  50. }
  51. },
  52. onLoad() {
  53. this.initLogin()
  54. },
  55. methods:{
  56. // 获取微信登录的code以及发送请求
  57. initLogin() {
  58. uni.login({
  59. success: (res) => {
  60. // console.log(res)
  61. if (res.code) { //微信登录成功 已拿到code
  62. this.wxCode = res.code //保存获取到的code
  63. console.log(res.code,"WXcode");
  64. } else {
  65. console.log('登录失败!' + res.errMsg)
  66. }
  67. }
  68. })
  69. },
  70. getPhoneNumber (e) {
  71.   if(e.detail.errMsg=="getPhoneNumber:ok"){
  72. /*uni.login({
  73. success: (res) => {
  74. // console.log(res)
  75. if (res.code) { //微信登录成功 已拿到code
  76. this.wxCode = res.code //保存获取到的code */
  77. uni.$u.http.post('/api/login/phone',{
  78. code:this.wxCode,
  79. iv:e.detail.iv,
  80. enc:e.detail.encryptedData
  81. }).then(res=>{
  82. console.log(res)
  83. uni.setStorageSync('token', res.token)
  84. uni.setStorageSync('phone', res.user.phone)
  85. this.$store.commit('setToken', res.token)
  86. this.$store.commit('loginState', res.token)
  87. this.$store.commit('getUserInfo',{
  88. //code:this.wxCode,
  89. phone:res.user.phone,
  90. })
  91. uni.showToast({
  92. title: '登录成功',
  93. icon:"success",
  94. duration: 1000
  95. })
  96. uni.reLaunch({
  97. url:"/pages/index/index"
  98. })
  99. }).catch(err=>{
  100. console.log(err)
  101. uni.showToast({
  102. icon:"error",
  103. title:err.message,
  104. })
  105. })
  106. }else{
  107. console.log('用户点击了拒绝') ;
  108. }
  109. },
  110. // getUserInfo(e){
  111. // uni.getUserInfo({
  112. // success:(res)=>{
  113. // console.log(res)
  114. // // var userInfo = res.userInfo;
  115. // }
  116. // })
  117. // },
  118. // 其他电话号码登录
  119. gootherNuber(){
  120. uni.navigateTo({
  121. url:"otherNumlogin"
  122. })
  123. },
  124. // 政策
  125. Policy(){
  126. uni.navigateTo({
  127. url:"/pages/userCenter/Policy"
  128. })
  129. },
  130. // 政策
  131. terms(){
  132. uni.navigateTo({
  133. url:"/pages/userCenter/Terms"
  134. })
  135. },
  136. }
  137. }
  138. </script>
  139. <style lang="less">
  140. page{
  141. color: #ffffff;
  142. }
  143. .image{
  144. position: fixed;
  145. width: 100%;
  146. height: 100%;
  147. top: 0;
  148. left: 0;
  149. z-index: -1;
  150. }
  151. .logo{
  152. text-align: center;
  153. margin-top: 197rpx;
  154. image{
  155. width: 114rpx;
  156. }
  157. }
  158. .btn{
  159. text-align: center;
  160. margin-top: 117rpx;
  161. .phoneNumber{
  162. margin: 0 auto;
  163. width: 654rpx;
  164. height: 92rpx;
  165. line-height: 92rpx;
  166. background: #1E9F6A;
  167. color: #FFFFFF;
  168. border-radius: 8rpx 32rpx 8rpx 32rpx;
  169. }
  170. .otherNumber{
  171. display: flex;
  172. justify-content: center;
  173. align-items: center;
  174. margin: 32rpx auto 0;
  175. width: 654rpx;
  176. height: 92rpx;
  177. line-height: 92rpx;
  178. background: rgba(255, 255, 255, 0.16);
  179. border-radius: 8rpx 32rpx 8rpx 32rpx;
  180. border: 1px solid #E2E2E3;
  181. .icon{
  182. image{
  183. width: 38rpx;
  184. margin: 40rpx 30rpx 0 0;
  185. }
  186. }
  187. }
  188. }
  189. .aggre{
  190. margin-top: 400rpx;
  191. text-align: center;
  192. font-family: PingFang-SC-Medium, PingFang-SC;
  193. font-weight: 500;
  194. color: #E2E2E2;
  195. font-size: 26rpx;
  196. .underline{
  197. text-decoration:underline;
  198. padding: 0 6rpx;
  199. }
  200. }
  201. </style>