login.vue 7.0 KB

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