login.vue 5.6 KB

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