register.vue 11 KB

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