register.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <view class="page">
  3. <view class="content">
  4. <view class="pageTop x-c">
  5. <view class="loginBox">
  6. <view class="login-item">
  7. <view class="input-account">
  8. <input v-model="userName" placeholder="手机号" type="number" maxlength="11" />
  9. </view>
  10. <view class="line"></view>
  11. </view>
  12. <view class="login-item">
  13. <view class="input-pwd">
  14. <input v-model="password" placeholder="密码(6-15个字符)" type="password" />
  15. </view>
  16. <view class="line"></view>
  17. </view>
  18. <view class="login-item">
  19. <view class="input-pwd">
  20. <input v-model="password1" placeholder="确认密码" type="password" />
  21. </view>
  22. <view class="line"></view>
  23. </view>
  24. <view class="login-item" v-if="isSms">
  25. <view class="input-yzcode x-bc">
  26. <input v-model="code" placeholder="验证码" type="number"></input>
  27. <view style="color:#666;flex-shrink: 0;" @click="sendSms">
  28. {{coolDown==0 ? '获取验证码': `${coolDown}秒后重试`}}
  29. </view>
  30. </view>
  31. <view class="line"></view>
  32. </view>
  33. <view class="btns">
  34. <view class="login-btn" @click="doRegister">注册</view>
  35. </view>
  36. </view>
  37. <view class="checkbox">
  38. <view class="checkbox-icon" @tap="handleAgree">
  39. <image src="../../static/image/login/radio_default.png" v-show="!agree"></image>
  40. <image src="../../static/image/login/radio_choose.png" v-show="agree"></image>
  41. </view>
  42. <view>我已阅读并同意<text @tap="goToWeb(0)">《用户协议》</text><text @tap="goToWeb(1)">《隐私政策》</text> 并使用本机号码登录
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import {
  51. register,
  52. login,
  53. registerByPhone,
  54. registerSendCode,
  55. isSmsVerification
  56. } from '@/api/user'
  57. import {
  58. goPage,
  59. quickWechatLogin
  60. } from "@/utils/login.js"
  61. import {
  62. vipPop
  63. } from '@/utils/vipPop.js'
  64. export default {
  65. data() {
  66. return {
  67. //userName:"CEadmin01",
  68. //password:"ADMIN01",
  69. userName: "",
  70. password: "",
  71. password1: "",
  72. registrationID: "",
  73. code: "",
  74. aback: true,
  75. agree: false,
  76. source: '',
  77. coolDown: 0,
  78. timer: null,
  79. isSms: false,
  80. }
  81. },
  82. onLoad(option) {
  83. let that = this;
  84. // #ifdef APP-PLUS
  85. this.source = plus.os.name == "iOS" ? "iOS" : plus.runtime.channel || 'app';
  86. // #endif
  87. uni.$on('getRegistrationID', function(data) {
  88. that.registrationID = data;
  89. });
  90. },
  91. onShow() {
  92. this.$getRegistrationID();
  93. this.isSmsVerificationFun()
  94. },
  95. onUnload() {
  96. uni.$off('getRegistrationID');
  97. },
  98. mounted() {
  99. },
  100. methods: {
  101. async isSmsVerificationFun() {
  102. const res = await isSmsVerification()
  103. if (res.code == 200) {
  104. this.isSms = res.isSmsVerification == 1 ? true : false
  105. } else {
  106. if (!res.msg) return
  107. uni.showToast({
  108. icon: 'none',
  109. title: res.msg
  110. })
  111. }
  112. },
  113. sendSms() {
  114. if (this.coolDown > 0) {
  115. return
  116. }
  117. if (!uni.$u.test.mobile(this.userName)) {
  118. uni.showToast({
  119. title: "请输入正确的手机号",
  120. icon: 'none',
  121. });
  122. return
  123. }
  124. this.coolDown = 60;
  125. registerSendCode({
  126. phone: this.userName
  127. }).then(res => {
  128. if (res.code == 200) {
  129. uni.showToast({
  130. title: '验证码已发送',
  131. icon: 'none',
  132. });
  133. this.coolDown = 60;
  134. this.timer = setInterval(() => {
  135. this.coolDown--;
  136. if (this.coolDown === 0) {
  137. clearInterval(this.timer);
  138. this.timer = null;
  139. }
  140. }, 1000);
  141. } else {
  142. this.timer && clearInterval(this.timer);
  143. this.coolDown = 0
  144. uni.showToast({
  145. title: res.msg,
  146. icon: 'none',
  147. });
  148. }
  149. },
  150. rej => {
  151. this.timer && clearInterval(this.timer);
  152. this.coolDown = 0;
  153. }).catch(() => {
  154. this.timer && clearInterval(this.timer);
  155. this.coolDown = 0;
  156. })
  157. },
  158. doRegister() {
  159. if (!uni.$u.test.mobile(this.userName)) {
  160. uni.showToast({
  161. title: "请输入正确的手机号",
  162. icon: 'none',
  163. });
  164. return
  165. }
  166. if (this.$isEmpty(this.password)) {
  167. uni.showToast({
  168. title: "请输入密码",
  169. icon: 'none',
  170. });
  171. return
  172. }
  173. if (this.password.length < 6 || this.password.length > 15) {
  174. uni.showToast({
  175. title: "密码长度应该在6到15个字符",
  176. icon: 'none',
  177. });
  178. return
  179. }
  180. if (this.password != this.password1) {
  181. uni.showToast({
  182. title: "两次输入密码不一致",
  183. icon: 'none'
  184. });
  185. }
  186. if (this.$isEmpty(this.code) && this.isSms) {
  187. uni.showToast({
  188. title: "请输入验证码",
  189. icon: 'none',
  190. });
  191. return
  192. }
  193. if (!this.agree) {
  194. uni.showToast({
  195. title: "请同意相关协议",
  196. icon: 'none'
  197. });
  198. return
  199. }
  200. var data = {
  201. phone: this.userName,
  202. password: this.password,
  203. jpushId: this.registrationID || uni.getStorageSync("registrationID"),
  204. source: this.source,
  205. code: this.code
  206. };
  207. var that = this;
  208. uni.showLoading({
  209. title: "注册中..."
  210. });
  211. if (this.isSms) {
  212. registerByPhone(data).then(res => {
  213. if (res.code == 200) {
  214. this.doLogin();
  215. } else {
  216. uni.hideLoading()
  217. uni.showToast({
  218. title: res.msg,
  219. icon: 'none'
  220. });
  221. }
  222. },
  223. rej => {}
  224. );
  225. return
  226. }
  227. data['loginType'] = 1
  228. register(data).then(res => {
  229. if (res.code == 200) {
  230. this.doLogin();
  231. } else {
  232. uni.hideLoading()
  233. uni.showToast({
  234. title: res.msg,
  235. icon: 'none'
  236. });
  237. }
  238. })
  239. },
  240. doLogin() {
  241. let data = {
  242. phone: this.userName,
  243. password: this.password,
  244. jpushId: this.registrationID || uni.getStorageSync("registrationID"),
  245. loginType: 1
  246. };
  247. let that = this;
  248. login(data).then(res => {
  249. uni.hideLoading()
  250. if (res.code == 200 && res.users && Object.prototype.toString.call(res.users) ==
  251. '[object Array]') {
  252. uni.setStorageSync('requestParam', data)
  253. uni.setStorageSync('wechatList', res.users)
  254. goPage();
  255. return
  256. }
  257. if (res.code == 200) {
  258. // #ifdef APP-PLUS
  259. if (res.isNew) {
  260. quickWechatLogin(true, res.phone);
  261. return;
  262. }
  263. // #endif
  264. if (res.alert) {
  265. vipPop({
  266. alert: res.alert,
  267. alert1: res.alert1
  268. }, e => {
  269. uni.switchTab({
  270. url: '/pages_im/pages/conversation/conversationList/index',
  271. // url: '/pages/course/index'
  272. });
  273. })
  274. }
  275. uni.setStorageSync('AppToken', res.token);
  276. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  277. uni.$emit('refreshIM');
  278. uni.$emit('showHealthButler');
  279. uni.reLaunch({
  280. url: '/pages_im/pages/conversation/conversationList/index',
  281. // url: '../index/index',
  282. animationType: 'pop-in',
  283. animationDuration: 100
  284. })
  285. } else {
  286. uni.showToast({
  287. title: res.msg,
  288. icon: 'none'
  289. });
  290. }
  291. },
  292. rej => {}
  293. );
  294. },
  295. getRegistrationID() {
  296. // #ifdef APP-PLUS
  297. // #endif
  298. },
  299. handleAgree() { // 同意
  300. this.agree = !this.agree
  301. },
  302. goToWeb(index) {
  303. uni.setStorageSync('url', index == 0 ? "https://userapp.zkhj6.com/web/userAgreement" :
  304. "https://userapp.zkhj6.com/web/privacyPolicy");
  305. uni.navigateTo({
  306. url: "/pages/index/h5"
  307. })
  308. },
  309. },
  310. beforeDestroy() { // 组件卸载时清掉定时器,防止内存泄漏
  311. this.timer && clearInterval(this.timer);
  312. }
  313. }
  314. </script>
  315. <style lang="scss">
  316. page {
  317. background-color: #ffffff;
  318. }
  319. .content {
  320. display: flex;
  321. flex-direction: column;
  322. align-items: center;
  323. height: calc(100vh);
  324. width: 100%;
  325. justify-content: space-between;
  326. //padding-top: calc(100% - 32vh);
  327. }
  328. .pageTop {
  329. display: flex;
  330. flex-direction: column;
  331. width: 100%;
  332. }
  333. .content .head {
  334. text-align: center;
  335. width: 100%;
  336. height: 100rpx;
  337. background-size: cover;
  338. box-sizing: border-box;
  339. font-size: 36rpx;
  340. font-weight: bold;
  341. color: #666;
  342. }
  343. .content .head image {
  344. width: 150rpx;
  345. height: 150rpx;
  346. border-radius: 10rpx;
  347. box-shadow: 0px 0px 20rpx rgba(0, 0, 0, 0.2);
  348. }
  349. .title {
  350. color: #141414;
  351. margin: 50upx 0upx 30upx 0rpx;
  352. font-size: 38rpx;
  353. font-weight: 500;
  354. }
  355. .desc {
  356. color: #686866;
  357. padding: 0 0 30rpx 0rpx;
  358. font-size: 28rpx;
  359. }
  360. .loginBox {
  361. padding: 10px 10px 30rpx;
  362. width: calc(100% - 20px);
  363. margin-top: 0rpx;
  364. background: #FDFDFD;
  365. //box-shadow: 0rpx 4rpx 27rpx 0rpx rgba(155,155,155,0.25);
  366. border-radius: 7rpx;
  367. }
  368. .login-item p {
  369. text-align: left;
  370. }
  371. .line {
  372. height: 0.5rpx;
  373. background-color: #efefef;
  374. margin-top: 10rpx;
  375. }
  376. .input-account {
  377. margin-top: 20rpx;
  378. margin-bottom: 0rpx;
  379. border-radius: 40rpx;
  380. border: solid 0rpx #efefef;
  381. height: 80rpx;
  382. width: 100%;
  383. background: url(/static/account.png) no-repeat 0 center;
  384. background-size: 30rpx 30rpx;
  385. background-position: 30rpx;
  386. }
  387. .input-yzcode {
  388. margin-top: 20rpx;
  389. margin-bottom: 0rpx;
  390. border-radius: 40rpx;
  391. border: solid 0rpx #efefef;
  392. height: 80rpx;
  393. width: 100%;
  394. background: url(/static/image/login/cz_icon.png) no-repeat 0 center;
  395. background-size: 30rpx 30rpx;
  396. background-position: 30rpx;
  397. }
  398. .input-pwd {
  399. margin-top: 40rpx;
  400. margin-bottom: 20rpx;
  401. border-radius: 40rpx;
  402. border: solid 0rpx #efefef;
  403. height: 80rpx;
  404. width: 100%;
  405. background: url(/static/password.png) no-repeat 0 center;
  406. background-size: 30rpx 30rpx;
  407. background-position: 30rpx;
  408. }
  409. input {
  410. margin-left: 80rpx;
  411. height: 80rpx;
  412. line-height: 80rpx
  413. }
  414. .footer {
  415. color: #686866;
  416. width: 100%;
  417. position: fixed;
  418. text-align: center;
  419. bottom: 60upx;
  420. font-size: 28rpx;
  421. }
  422. .btns {
  423. margin: 50rpx 0rpx;
  424. margin-bottom: 0rpx;
  425. }
  426. .login-btn {
  427. display: flex;
  428. align-items: center;
  429. justify-content: center;
  430. width: 100%;
  431. height: 80rpx;
  432. background: linear-gradient(to right, #FF5C03 0%, #FF5C03 100%);
  433. background: -moz-linear-gradient(to right, #FF5C03 0%, #FF5C03 100%);
  434. box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
  435. border-radius: 40rpx;
  436. font-size: 30rpx;
  437. font-family: PingFang SC;
  438. font-weight: 500;
  439. color: rgba(255, 255, 255, 1);
  440. }
  441. .reg-box {
  442. padding-bottom: 20rpx;
  443. margin: 0 10px;
  444. .reg-btn {
  445. font-size: 16px;
  446. color: #FF5C03;
  447. }
  448. }
  449. .pageBottom {
  450. height: 260rpx;
  451. width: 75%;
  452. display: flex;
  453. flex-direction: column;
  454. }
  455. .tips {
  456. color: #999;
  457. font-size: 36rpx;
  458. }
  459. .menu {
  460. margin-top: 30rpx;
  461. image {
  462. width: 78rpx;
  463. height: 78rpx;
  464. }
  465. }
  466. .checkbox {
  467. margin: 20rpx;
  468. margin-top: 16rpx;
  469. display: flex;
  470. flex-direction: row;
  471. align-items: flex-start;
  472. justify-content: flex-start;
  473. font-family: PingFang SC, PingFang SC;
  474. font-weight: 400;
  475. font-size: 26rpx;
  476. color: #999999;
  477. line-height: 38rpx;
  478. text-align: left;
  479. text {
  480. color: #FF5C03;
  481. }
  482. &-icon {
  483. flex-shrink: 0;
  484. margin-right: 12rpx;
  485. image {
  486. height: 24rpx;
  487. width: 24rpx;
  488. }
  489. }
  490. }
  491. </style>