login.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <view>
  3. <u-navbar title="" back-icon-size="24"></u-navbar>
  4. <view class="title">
  5. 手机号注册/登录
  6. </view>
  7. <view class="welcome">
  8. 欢迎来到青少年宫启航教培管家
  9. </view>
  10. <!-- 登录框-->
  11. <view class="login-box">
  12. <view class="tel">
  13. <view class="icon">
  14. <img src="../../../assets/img/riFill-cellphone-fill@1x.png" alt="">
  15. </view>
  16. <u-line color="red" direction="col" length="40rpx" margin="auto 0" />
  17. <view class="tips">
  18. <u-input v-model="form.telephone" type="number" placeholder="请填写手机号码" />
  19. </view>
  20. </view>
  21. <view class="hint">
  22. 未注册的手机号验证后将自动注册
  23. </view>
  24. <view class="pwd">
  25. <view class="icon">
  26. <img src="../../../assets/img/riFill-lock-password-fill@1x.png" alt="">
  27. </view>
  28. <u-line color="red" direction="col" length="40rpx" margin="auto 0" />
  29. <view class="tips">
  30. <view class="input">
  31. <u-input type="number" v-model="form.verifyCode" placeholder="请输入验证码" />
  32. </view>
  33. <view class="verification-code" :style="isCodeTipsColor ? 'color: #999999;' : ''" @click="getCode">{{codeTips}}</view>
  34. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" change-text="已发送(Xs)">
  35. </u-verification-code>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- <view class="tip">
  40. 短信升级可能无法收到验证码,恢复可能需要3-5天!
  41. </view> -->
  42. <view class="agreement">
  43. <label class="radio">
  44. <radio value="" @click="radioClick" /><text class="text">我已阅读并同意
  45. <text style="color: rgba(13, 186, 199, 1);">《起航教培管家用户协议》</text></text>
  46. </label>
  47. </view>
  48. <!-- 按钮 -->
  49. <button class="login-btn" @click="signIn">登  录</button>
  50. </view>
  51. </template>
  52. <script>
  53. import * as loginApi from '@/apis/login.js'
  54. import {
  55. checkPhone
  56. } from '@/apis/utils'
  57. export default {
  58. data() {
  59. return {
  60. form: {
  61. telephone: '',
  62. openId: '',
  63. verifyCode: '',
  64. userType: 1
  65. },
  66. isSendMsgIng: false,
  67. isCodeTipsColor: false,
  68. sendMsgSecond: 60,
  69. codeTips: '',
  70. agreementValue: false,
  71. personInfo: null
  72. }
  73. },
  74. onLoad() {
  75. this.findByOpenId();
  76. },
  77. methods: {
  78. findByOpenId() {
  79. var openId = this.carhelp.getOpenId()
  80. if (openId == "") {
  81. //("--------findByOpenId----------")
  82. setTimeout(() => {
  83. this.findByOpenId()
  84. }, 1000)
  85. return
  86. }
  87. uni.request({
  88. method: 'get',
  89. url: process.car.BASE_URL + "/mobile/regUser/findByOpenId",
  90. data: {
  91. openId: openId,
  92. userType: '1'
  93. },
  94. header: {
  95. 'Content-Type': 'application/x-www-form-urlencoded',
  96. 'X-Requested-With': 'XMLHttpRequest',
  97. }
  98. }).then((response) => {
  99. let [error, res] = response;
  100. if (res.data.code == 200 && res.data.result) {
  101. var token = res ? res.data.data.token : '';
  102. this.carhelp.setPersonInfo(res.data.data.regUser);
  103. this.carhelp.setToken(token);
  104. this.carhelp.setPersonInfoPlus(res.data.data);
  105. uni.redirectTo({
  106. url: '/pages/parents/homePage/homePage'
  107. })
  108. } else {
  109. this.carhelp.logoff()
  110. }
  111. }).catch(error => {
  112. })
  113. },
  114. codeChange(text) {
  115. this.codeTips = text;
  116. },
  117. start() {
  118. if (!this.isSendMsgIng) {
  119. uni.showLoading({
  120. title: "加载中",
  121. mask: true,
  122. })
  123. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  124. uni.hideLoading();
  125. this.carhelp.set("getvcodetime", new Date().getTime());
  126. if (!"") {
  127. //倒计时
  128. uni.showToast({
  129. title: "发送成功"
  130. })
  131. } else {
  132. uni.showToast({
  133. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  134. })
  135. }
  136. }).catch(error => {
  137. uni.showToast({
  138. title: error,
  139. icon: "none"
  140. })
  141. })
  142. }
  143. },
  144. //倒计时
  145. end() {
  146. this.sendMsgSecond = 60;
  147. this.isSendMsgIng = false;
  148. this.isCodeTipsColor = false;
  149. },
  150. // 获取验证码
  151. getCode() {
  152. if (this.$refs.uCode.canGetCode) {} else {
  153. uni.showToast({
  154. title: '倒计时结束后再发送',
  155. icon: "none"
  156. })
  157. return
  158. }
  159. var checkPhoneResult = checkPhone(this.form.telephone);
  160. if (checkPhoneResult !== true) {
  161. uni.showToast({
  162. title: checkPhoneResult,
  163. })
  164. return;
  165. }
  166. this.$refs.uCode.start();
  167. this.isCodeTipsColor = true;
  168. },
  169. radioClick() {
  170. this.agreementValue = true;
  171. },
  172. signIn() {
  173. var checkPhoneResult = checkPhone(this.form.telephone);
  174. if(!this.form.telephone) {
  175. uni.showToast({
  176. title: checkPhoneResult,
  177. icon: "none"
  178. })
  179. return;
  180. }
  181. if(!this.form.verifyCode) {
  182. uni.showToast({
  183. title: "请输入验证码",
  184. icon: "none"
  185. })
  186. return
  187. }
  188. if(!this.agreementValue) {
  189. uni.showToast({
  190. title: "请勾选协议",
  191. icon: "none"
  192. })
  193. return
  194. }
  195. uni.showLoading({
  196. title: "加载中",
  197. mask: true,
  198. })
  199. this.form.openId= this.carhelp.getOpenId();
  200. loginApi.validateCode(this.form).then((response) => {
  201. uni.hideLoading();
  202. var token = response ? response.data.token : '';
  203. this.carhelp.setToken(token);
  204. this.carhelp.setPersonInfo(response.data.regUser);
  205. uni.redirectTo({
  206. url: '/pages/parents/homePage/homePage'
  207. })
  208. }).catch(error => {
  209. uni.showToast({
  210. title: error,
  211. icon: "none"
  212. })
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. page {
  220. background-color: #fff;
  221. }
  222. .title {
  223. margin-top: 24px;
  224. color: rgba(16, 16, 16, 1);
  225. font-size: 24px;
  226. text-align: center;
  227. }
  228. .welcome {
  229. margin-top: 8rpx;
  230. color: rgba(119, 119, 119, 1);
  231. text-align: center;
  232. }
  233. // 登录框
  234. .login-box {
  235. margin-top: 84rpx;
  236. .tel,
  237. .pwd {
  238. display: flex;
  239. padding-left: 20rpx;
  240. width: 74.4%;
  241. height: 80rpx;
  242. line-height: 80rpx;
  243. color: rgba(183, 172, 172, 1);
  244. margin: auto;
  245. margin-bottom: 16rpx;
  246. border: 1px solid rgba(230, 230, 230, 1);
  247. border-radius: 50px;
  248. .icon {
  249. width: 14%;
  250. text-align: center;
  251. img {
  252. vertical-align: middle;
  253. }
  254. }
  255. .tips {
  256. text-indent: 16rpx;
  257. padding-right: 16rpx;
  258. // width: 85%;
  259. display: flex;
  260. justify-content: space-between;
  261. ::v-deepuni-input {
  262. height: 40px !important;
  263. line-height: 40px !important;
  264. }
  265. .input {
  266. width: 60%;
  267. }
  268. }
  269. // 验证码
  270. .verification-code {
  271. color: rgba(13, 186, 199, 1);
  272. line-height: 40px;
  273. }
  274. }
  275. .hint {
  276. text-align: center;
  277. color: rgba(153, 153, 153, 1);
  278. font-size: 12px;
  279. margin-bottom: 42px;
  280. }
  281. }
  282. .agreement {
  283. margin-top: 84rpx;
  284. text-align: center;
  285. ::v-deep.uni-radio-input {
  286. width: 32rpx;
  287. height: 32rpx;
  288. }
  289. .text {
  290. line-height: 20px;
  291. color: #999999;
  292. }
  293. }
  294. .login-btn {
  295. width: 74.4%;
  296. background-color: rgba(13, 186, 199, 1);
  297. color: rgba(255, 255, 255, 1);
  298. font-size: 16px;
  299. border-radius: 50px;
  300. margin-top: 26rpx;
  301. }
  302. .tip{
  303. color: red;
  304. text-align: center;
  305. }
  306. </style>