iphoneLogin.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <view class="container">
  3. <view class="tis">登录后更精彩</view>
  4. <view class="cont">
  5. <input type="number" value="" v-model="phone" placeholder-style="color:#999999" placeholder="请输入手机号码" class="phoneInput" @input="input()" />
  6. <view class="yzmBox">
  7. <input type="number" value="" v-model="code" placeholder-style="color:#999999" placeholder="请输入验证码" class="yzmInput"
  8. @input="yzminput()" />
  9. <view @click="sendSms" class="yzmBtn" :class="{green:isgreen}">{{yzmTxt}}</view>
  10. </view>
  11. <view class="loginBtn" :class="{okBtn:show}" @click="gologin">验证并登录</view>
  12. <view class="privacy" @click="privacyClick">
  13. <image src="../../static/img/login_icon_checked.png" mode="" class="imgPrivacy" v-show="privacyCk">
  14. </image>
  15. <view class="nock" v-show="!privacyCk"></view>
  16. <span>同意</span> <span class="span1" @click.stop="goTreaty">《服务协议》</span>
  17. <span>与</span> <span class="span1" @click.stop="goIntimity">《隐私政策》 </span>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. privacyCk: true,
  27. phone: '',
  28. isYzm: true,
  29. yzmTxt: '获取验证码',
  30. isgreen: false,
  31. timer: null,
  32. show: false,
  33. cont: '',
  34. code: '',
  35. wxdata: '',
  36. wxCode: '',
  37. openID: '',
  38. wxOpendata: '',
  39. }
  40. },
  41. onLoad() {
  42. this.wxOpendata = uni.getStorageSync("wxOpendata");
  43. },
  44. methods: {
  45. goTreaty() {
  46. uni.navigateTo({
  47. url: '../me/treaty'
  48. })
  49. },
  50. goIntimity() {
  51. uni.navigateTo({
  52. url: '../me/intimity'
  53. })
  54. },
  55. getWxdata() {
  56. var that = this;
  57. uni.getUserProfile({
  58. lang: 'zh_CN',
  59. desc: '登录',
  60. success: (res) => {
  61. console.log(res);
  62. that.wxdata = res;
  63. uni.setStorage({
  64. key: 'wxdata',
  65. data: res,
  66. success: function() {
  67. that.ipLogin()
  68. }
  69. });
  70. },
  71. fail: (res) => {
  72. console.log(res)
  73. }
  74. });
  75. },
  76. gologin() {
  77. if (this.privacyCk == false) {
  78. uni.showToast({
  79. title: '您需要先同意相关服务协议与隐私政策',
  80. icon: 'none',
  81. duration: 3000
  82. });
  83. return
  84. }
  85. if (this.show) {
  86. if (this.wxOpendata) {
  87. this.openID = this.wxOpendata.openid;
  88. this.wxdata = uni.getStorageSync("wxdata")
  89. if (this.wxdata) {
  90. this.phoneLogin()
  91. } else {
  92. this.getWxdata()
  93. }
  94. } else {
  95. this.getWxdata()
  96. }
  97. }
  98. },
  99. ipLogin() {
  100. var that = this;
  101. uni.showLoading({});
  102. uni.login({
  103. provider: 'weixin',
  104. success: function(loginRes) {
  105. console.log(loginRes)
  106. that.wxCode = loginRes.code
  107. that.getWxOpenID()
  108. }
  109. });
  110. },
  111. getWxOpenID() {
  112. this.$http('worldKeepCar/sys/getWxOpenID', {
  113. code: this.wxCode,
  114. }, 'GET').then(res => {
  115. //console.log(res)
  116. this.openID = res.data.openid;
  117. // console.log(this.openID)
  118. this.phoneLogin()
  119. })
  120. },
  121. phoneLogin() {
  122. this.$http('worldKeepCar/sys/phoneLogin', {
  123. phone: this.phone,
  124. code: this.code,
  125. nickName: this.wxdata.userInfo.nickName,
  126. headUrl: this.wxdata.userInfo.avatarUrl,
  127. openID: this.openID,
  128. }, ).then(res => {
  129. uni.hideLoading();
  130. if (res.code == 0) {
  131. uni.setStorage({
  132. key: 'logodata',
  133. data: res.data,
  134. success: function() {
  135. that.ipLogin()
  136. }
  137. });
  138. uni.showToast({
  139. title: '登录成功',
  140. icon: 'none',
  141. duration: 3000
  142. });
  143. uni.switchTab({
  144. url: '../index/index'
  145. })
  146. } else {
  147. uni.showToast({
  148. title: res.msg,
  149. icon: 'none',
  150. duration: 3000
  151. });
  152. }
  153. })
  154. },
  155. input(phone) {
  156. console.log(this.phone);
  157. if (this.phone != '') {
  158. this.isgreen = true;
  159. }
  160. },
  161. yzminput() {
  162. if (this.code != '' && this.phone != '') {
  163. this.show = true;
  164. }
  165. },
  166. sendSms() {
  167. if (!this.isYzm) {
  168. return false;
  169. }
  170. this.isYzm = false;
  171. //this.clearIntervalDjs();
  172. //return false;
  173. if (this.phone === '') {
  174. this.isYzm = true
  175. uni.showToast({
  176. title: '手机号不可为空',
  177. icon: 'none',
  178. duration: 3000
  179. });
  180. } else {
  181. var reg = /^1[3456789]\d{9}$/;
  182. if (!reg.test(this.phone)) {
  183. uni.showToast({
  184. title: '手机号格式不正确',
  185. icon: 'none',
  186. duration: 3000
  187. });
  188. this.isYzm = true
  189. } else {
  190. this.$http('worldKeepCar/sys/sendSms', {
  191. phone: this.phone,
  192. }, 'GET').then(res => {
  193. this.isYzm = false;
  194. /* uni.showToast({
  195. title: '发送成功',
  196. icon:'none',
  197. duration: 3000
  198. }); */
  199. this.clearIntervalDjs()
  200. })
  201. }
  202. }
  203. },
  204. clearIntervalDjs() {
  205. const TIME_COUNT = 60;
  206. if (!this.timer) {
  207. this.cont = TIME_COUNT;
  208. this.isYzm = false;
  209. this.timer = setInterval(() => {
  210. if (this.cont > 0 && this.cont <= TIME_COUNT) {
  211. this.cont--;
  212. this.yzmTxt = this.cont + 'S'
  213. } else {
  214. this.isYzm = true;
  215. clearInterval(this.timer);
  216. this.timer = null;
  217. this.yzmTxt = "获取验证码"
  218. }
  219. }, 1000)
  220. }
  221. },
  222. privacyClick() {
  223. this.privacyCk = !this.privacyCk
  224. },
  225. blur1() {
  226. }
  227. }
  228. }
  229. </script>
  230. <style scoped>
  231. .tis {
  232. color: #333333;
  233. font-size: 44rpx;
  234. padding-top: 78rpx;
  235. padding-left: 58rpx;
  236. }
  237. .cont {
  238. padding: 58rpx;
  239. }
  240. .phoneInput {
  241. width: 604rpx;
  242. height: 88rpx;
  243. border-radius: 44rpx;
  244. border: 2rpx solid #EEEEEE;
  245. line-height: 88rpx;
  246. color: #333333;
  247. font-size: 30rpx;
  248. padding-left: 30rpx;
  249. }
  250. .yzmBox {
  251. width: 604rpx;
  252. height: 88rpx;
  253. border-radius: 44rpx;
  254. border: 2rpx solid #EEEEEE;
  255. line-height: 88rpx;
  256. color: #999999;
  257. font-size: 30rpx;
  258. padding-left: 30rpx;
  259. margin-top: 30rpx;
  260. display: flex;
  261. justify-content: space-between;
  262. }
  263. .yzmInput {
  264. line-height: 88rpx;
  265. color: #333333;
  266. font-size: 30rpx;
  267. height: 88rpx;
  268. }
  269. .yzmBtn {
  270. padding-right: 30rpx;
  271. border-left: 2rpx solid #EEEEEE;
  272. padding-left: 20rpx;
  273. height: 35rpx;
  274. line-height: 35rpx;
  275. margin-top: 26rpx;
  276. }
  277. .loginBtn {
  278. width: 634rpx;
  279. height: 88rpx;
  280. background: #F5F5F5;
  281. border-radius: 44rpx;
  282. line-height: 88rpx;
  283. text-align: center;
  284. margin-top: 30rpx;
  285. color: #999999;
  286. font-size: 30rpx;
  287. }
  288. .privacy {
  289. display: flex;
  290. /* justify-content: center; */
  291. font-size: 24rpx;
  292. color: #CCCCCC;
  293. padding-top: 34rpx;
  294. }
  295. .imgPrivacy {
  296. width: 28rpx;
  297. height: 28rpx;
  298. margin-top: 2rpx;
  299. margin-right: 10rpx;
  300. }
  301. .span1 {
  302. color: #FF4F00;
  303. }
  304. .nock {
  305. width: 22rpx;
  306. height: 22rpx;
  307. border-radius: 50%;
  308. border: 2px solid #AEAEAE;
  309. margin-top: 2rpx;
  310. margin-right: 10rpx;
  311. }
  312. .green {
  313. color: #FF4F00;
  314. }
  315. .okBtn {
  316. background: #FF4F00;
  317. color: #FFFFFF;
  318. }
  319. </style>