register.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <template>
  2. <view class="container">
  3. <u-icon class="back-btn" name="arrow-left" color="black" size="20" @click="navBack"></u-icon>
  4. <view class="wrapper">
  5. <h2 class="Semibold">手机号注册</h2>
  6. <view style='width:100%;margin-top:50px;border-bottom:1px solid #E8E9ED;padding:10px;position:relative;'
  7. class="flex">
  8. <view class="NumberMedium" style='width:15%;border-right:1px solid #E8E9ED;'>+86</view>
  9. <view style='width:85%;'>
  10. <!-- <u-input border="none" maxlength="11" v-model='phone' @input='phoneinput' style='padding-left:10px;'
  11. placeholder="请输入手机号码" type="number" class="Regular" /> -->
  12. <input placeholder-style="color:#AFB3BF" border="none" maxlength="11" v-model='phone'
  13. @input='phoneinput' style='padding-left:10px;' placeholder="请输入手机号码" type="number"
  14. class="Regular" />
  15. </view>
  16. <!-- <image v-if='phone!=""' @click='phone=""' class='close' src='../../static/img/login/guanbi@2x.png'></image> -->
  17. </view>
  18. <view style='width:100%;border-bottom:1px solid #E8E9ED;position:relative;padding:10px 0;' class="flex">
  19. <view style='width:70%;position:relative;'>
  20. <!-- <u-input border="none" v-model='verifyCode' class="Regular" placeholder="请输入验证码" type="number" maxlength="6" />
  21. -->
  22. <input placeholder-style="color:#AFB3BF" border="none" maxlength="6" v-model='verifyCode' style=''
  23. placeholder="请输入验证码" type="number" class="Regular" />
  24. </view>
  25. <!-- -->
  26. <button :class='codestatus?"activeCode":""' @click='getcode'
  27. class='getcode Regular'>{{sendText}}</button>
  28. </view>
  29. <view style='border-bottom:1px solid #E8E9ED;padding:10px 0;position:relative;display: flex;'>
  30. <!-- <u-input border="none" maxlength='16' class='Regular input-style' style='height:30px;'
  31. v-model='password' placeholder="请输入密码,6-16位字符" :type="type" /> -->
  32. <!-- <u-input placeholder-style="color:#AFB3BF" border="none" maxlength="16" v-model='password' style=''
  33. placeholder="请输入密码,6-16位字符" :type="isShowPassword" class="Regular input-style" /> -->
  34. <input placeholder-style="color:#AFB3BF" v-model='password' v-if="isShowPassword=='password'"
  35. placeholder="请输入密码" type="password">
  36. <input maxlength='16' placeholder-style="color:#AFB3BF" class='password Regular' v-model='password'
  37. v-else type="text" placeholder="请输入密码">
  38. <view style="width: 50%;text-align: right;">
  39. <image class='yanjingicon' style='width:22px;height:22px;margin-right: 20rpx;'
  40. @click="passWordStatus(1)" v-if="isShowPassword=='password'" src="../../static/yioncang.png"
  41. mode=""></image>
  42. <image class='yanjingicon' style='width:22px;height:22px;margin-right: 20rpx;'
  43. @click="passWordStatus(2)" v-else src="../../static/xianshi.png" mode=""></image>
  44. </view>
  45. <!-- <input maxlength='16' class='password Regular input-style' style='height:30px;' v-model='password' placeholder="请输入密码,6-16位字符" :type="type"> -->
  46. <!-- <image v-if='password!=""' @click='password=""' class='close2' src='../../static/img/login/guanbi@2x.png'></image> -->
  47. <!-- <view @click='switchover' style='position:absolute;right:0;top:38%;z-index:10;cursor:pointer;' class="iconfont " :class='type=="password"?"icon-yanjing-biyan":"icon-yanjing-zhengyan"'></view> -->
  48. </view>
  49. <button :class='phone!=""&&verifyCode!=""&&password!=""?"active":""' @click='$u.throttle(register(), 1000)'
  50. class='verificationCode'>注册</button>
  51. <view
  52. style='color:#6A6A6A;margin-top:10px;font-size:30rpx;display:flex;justify-content:center;align-items: center;'>
  53. <u--image style='margin-right:3px;position:relative;top:1rpx;' @click='consent'
  54. :src="consentStatus==true?'../../static/images/mine/duihao@2x.png':'../../static/images/mine/wxz.png'"
  55. width="17px" height="17px"></u--image>
  56. 已阅读并同意
  57. <navigator
  58. url="/pages/public/serviceAgreement/serviceAgreement?url=http://liangxin.zthymaoyi.com/cytUserAgreement.html"
  59. class="path" hover-class="navigator-hover">《服务协议》</navigator>和<navigator
  60. url="/pages/public/cytScrectAgreement/cytScrectAgreement?url=http://liangxin.zthymaoyi.com/cytScrectAgreement.html"
  61. class="path" hover-class="navigator-hover">《隐私政策》</navigator>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import {
  68. mapMutations
  69. } from 'vuex';
  70. import {
  71. openFSqlite,
  72. createFSQL,
  73. selectFSQL,
  74. addFSQL
  75. } from '../../util/f.js'
  76. import helper from '@/common/helper.js';
  77. import {
  78. queryData,
  79. upData,
  80. initData
  81. } from '../../util/dbUtil.js'
  82. export default {
  83. data() {
  84. return {
  85. inputContent: null,
  86. loginType: "wechat",
  87. phone: '',
  88. password: '',
  89. logining: false,
  90. isPhone: false,
  91. isApple: true,
  92. accessToken: '',
  93. params: {
  94. encryptedData: '',
  95. session_key: '',
  96. iv: '',
  97. },
  98. userInfo: {
  99. nickName: '',
  100. avatarUrl: '',
  101. gender: '',
  102. phone: ''
  103. },
  104. consentStatus: false,
  105. codestatus: false,
  106. type: 'password',
  107. inputStatus: 'none',
  108. verifyCode: null,
  109. sendText: '获取验证码',
  110. sendDisabled: false,
  111. system: '',
  112. platform: '',
  113. canIUseProfile: false,
  114. isShowPassword: 'password'
  115. }
  116. },
  117. onShow() {
  118. // this.loginType = "wechat"
  119. // this.$api.logout()
  120. },
  121. onLoad(options) {
  122. if (wx.getUserProfile) {
  123. console.log('--check getUserProfile--OK');
  124. this.canIUseProfile = true;
  125. }
  126. console.log("login on load")
  127. var that = this
  128. // that.$api.request('user', 'sendIsApple', {}).then(res => {
  129. // that.isApple = res.data
  130. // })
  131. // uni.getSystemInfo({
  132. // success: (res) => {
  133. // // console.log(res)
  134. // this.system = res.system // ios
  135. // this.platform = res.platform // 14.3
  136. // }
  137. // })
  138. },
  139. methods: {
  140. passWordStatus(type) {
  141. if (type == 1) {
  142. this.isShowPassword = 'text'
  143. } else {
  144. this.isShowPassword = 'password'
  145. }
  146. },
  147. // 随机数
  148. randomAccess(min, max) {
  149. return Math.floor(Math.random() * (min - max) + max)
  150. },
  151. // 解码
  152. decodeUnicode(str) {
  153. //Unicode显示方式是\u4e00
  154. str = "\\u" + str
  155. str = str.replace(/\\/g, "%");
  156. //转换中文
  157. str = unescape(str);
  158. //将其他受影响的转换回原来
  159. str = str.replace(/%/g, "\\");
  160. return str;
  161. },
  162. /*
  163. *@param Number NameLength 要获取的名字长度
  164. */
  165. getRandomName(NameLength) {
  166. let name = ""
  167. for (let i = 0; i < NameLength; i++) {
  168. let unicodeNum = ""
  169. unicodeNum = this.randomAccess(0x4e00, 0x9fa5).toString(16)
  170. name += this.decodeUnicode(unicodeNum)
  171. }
  172. return name
  173. },
  174. phoneinput(e) {
  175. if (e.detail.value.length == 11) {
  176. this.codestatus = true
  177. } else {
  178. this.codestatus = false
  179. }
  180. },
  181. getcode() {
  182. var that = this
  183. if (this.sendText != "获取验证码") {
  184. return
  185. }
  186. if (/^0?1[3|4|5|6|7|8][0-9]\d{8}$/.test(this.phone)) {
  187. that.$request.baseRequest('get', '/commonUser/sendVerifyCode', {
  188. phone: this.phone,
  189. flag: 3
  190. }).then(res => {
  191. if (res.code == 200) {
  192. that.codestatus = false
  193. let sec = 60
  194. let interval = setInterval(() => {
  195. sec--;
  196. that.sendText = sec + 's后重发'
  197. if (sec <= 0) {
  198. that.sendDisabled = true
  199. that.sendText = "获取验证码"
  200. that.codestatus = true
  201. clearInterval(interval)
  202. }
  203. }, 1000)
  204. } else {
  205. uni.showToast({
  206. title: res.message,
  207. icon: 'none',
  208. duration: 2000
  209. })
  210. }
  211. })
  212. .catch(res => {
  213. uni.showToast({
  214. title: res.data.message,
  215. icon: 'none',
  216. duration: 2000
  217. })
  218. });
  219. } else {
  220. uni.showToast({
  221. title: '请输入正确的手机号',
  222. icon: 'none',
  223. duration: 2000
  224. })
  225. }
  226. },
  227. register() {
  228. var that = this
  229. if (!this.consentStatus) {
  230. uni.showToast({
  231. title: '请勾选协议',
  232. icon: 'none',
  233. duration: 2000
  234. })
  235. return
  236. }
  237. if (!this.phone) {
  238. uni.showToast({
  239. title: '手机号不能为空',
  240. icon: 'none',
  241. duration: 2000
  242. })
  243. return
  244. }
  245. if (!this.verifyCode) {
  246. uni.showToast({
  247. title: '验证码不能为空',
  248. icon: 'none',
  249. duration: 2000
  250. })
  251. return
  252. }
  253. if (!this.password) {
  254. uni.showToast({
  255. title: '密码不能为空',
  256. icon: 'none',
  257. duration: 2000
  258. })
  259. return
  260. }
  261. if (this.verifyCode.length > 6) {
  262. uni.showToast({
  263. title: '验证码错误',
  264. icon: 'none',
  265. duration: 2000
  266. })
  267. return
  268. }
  269. if (this.password.length < 6) {
  270. uni.showToast({
  271. title: '密码输入错误',
  272. icon: 'none',
  273. duration: 2000
  274. })
  275. return
  276. }
  277. var username = this.getRandomName(3)
  278. that.$request.baseRequest('post', '/commonUser/register', {
  279. phone: this.phone,
  280. password: this.password,
  281. verifyCode: this.verifyCode,
  282. userName: username,
  283. identification: 2,
  284. avatarUrl: "https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/165672849620975.png" //司机默认头像
  285. }).then(res => {
  286. if (res.code == '11003') {
  287. uni.showToast({
  288. title: res.message,
  289. icon: 'none',
  290. duration: 2000
  291. })
  292. return
  293. } else if (res.code == '11004') {
  294. uni.showToast({
  295. title: '该手机号已注册,可直接登录',
  296. icon: 'none',
  297. duration: 2000
  298. })
  299. return
  300. } else {
  301. uni.showLoading({
  302. title: '登录中',
  303. mask: true
  304. })
  305. that.$request.baseRequest('get', '/commonUser/login', {
  306. phone: this.phone,
  307. password: this.password,
  308. loginFlag: 1,
  309. identification: 2
  310. }).then(res => {
  311. if (res.code == 200) {
  312. console.log("userInfo", res.data)
  313. uni.setStorageSync('userInfo', res.data)
  314. that.$request.baseRequest('get', '/newsInfo/unreadMessage', {
  315. reCommonId: this.userInfo.id,
  316. }).then(res3 => {
  317. if (res3.data || res3.data == 0) {
  318. let name = 'myTip';
  319. let value = res3.data
  320. if (value == 0) {
  321. uni.removeTabBarBadge({
  322. index: 2
  323. })
  324. }
  325. that.$store.commit('$uStore', {
  326. name,
  327. value
  328. });
  329. if (value != 0 && value) {
  330. uni.setTabBarBadge({
  331. index: 2,
  332. text: value + ""
  333. })
  334. }
  335. }
  336. })
  337. uni.hideLoading()
  338. that.$store.commit('login', res.data)
  339. var name = 'userInfo';
  340. var value = res.data;
  341. that.$store.commit('$uStore', {
  342. name,
  343. value
  344. });
  345. uni.switchTab({
  346. url: '/pages/mine/index'
  347. });
  348. } else {
  349. uni.hideLoading()
  350. uni.showToast({
  351. title: res.message,
  352. icon: 'none',
  353. duration: 2000
  354. })
  355. }
  356. uni.hideLoading()
  357. })
  358. .catch(res => {
  359. uni.hideLoading()
  360. console.log(res);
  361. });
  362. }
  363. })
  364. .catch(res => {
  365. uni.hideLoading()
  366. console.log(res);
  367. });
  368. },
  369. consent() {
  370. this.consentStatus = !this.consentStatus
  371. uni.setStorage({
  372. key: 'policyStorageKey',
  373. data: this.consentStatus
  374. });
  375. },
  376. switchover() {
  377. if (this.type == 'password') {
  378. this.type = 'text'
  379. } else {
  380. this.type = 'password'
  381. }
  382. },
  383. ...mapMutations(['login']),
  384. navBack() {
  385. uni.navigateBack();
  386. },
  387. },
  388. }
  389. </script>
  390. <style lang='scss' scoped>
  391. uni-navigator {
  392. display: inline-block;
  393. color: #F5BA3C;
  394. }
  395. .password {
  396. border: none;
  397. outline: none;
  398. }
  399. .apple {
  400. background: #000;
  401. width: 35px;
  402. height: 35px;
  403. padding: 8px;
  404. border-radius: 50%;
  405. vertical-align: middle;
  406. }
  407. page {
  408. background: #fff;
  409. }
  410. .cuIcon-weixin {
  411. background: #F5BA3C;
  412. color: #fff;
  413. font-size: 18px;
  414. padding: 9px;
  415. border-radius: 50%;
  416. vertical-align: middle;
  417. margin-right: 5px;
  418. }
  419. .container {
  420. padding-top: 85px;
  421. position: relative;
  422. width: 100vw;
  423. height: calc(100vh - 13vh);
  424. overflow: hidden;
  425. background: url('~@/static/images/mine/bg@2x.png');
  426. /* background-size: 100%; */
  427. }
  428. .close {
  429. width: 20px;
  430. height: 20px;
  431. position: absolute;
  432. right: 0px;
  433. }
  434. .close1 {
  435. width: 20px;
  436. height: 20px;
  437. position: absolute;
  438. right: 10px;
  439. top: 0;
  440. }
  441. .close2 {
  442. width: 15px;
  443. height: 15px;
  444. position: absolute;
  445. right: 19px;
  446. top: 50%;
  447. transform: translateY(-45%);
  448. }
  449. .wrapper {
  450. position: relative;
  451. z-index: 90;
  452. padding-bottom: 40upx;
  453. height: 100%;
  454. padding: 0 30px;
  455. }
  456. .back-btn {
  457. position: absolute;
  458. left: 40upx;
  459. z-index: 9999;
  460. padding-top: var(--status-bar-height);
  461. top: 40upx;
  462. font-size: 40upx;
  463. color: black;
  464. }
  465. .verificationCode {
  466. margin-top: 20px;
  467. background: #F5F6F9;
  468. color: #AFB3BF;
  469. }
  470. .verificationCode:after {
  471. border: none;
  472. }
  473. .register {
  474. position: absolute;
  475. bottom: 20px;
  476. left: 50%;
  477. transform: translateX(-50%);
  478. color: #333333;
  479. height: 50px;
  480. line-height: 50px;
  481. border-radius: 30px;
  482. border: 1px solid #444444;
  483. }
  484. .register:after {
  485. border: none;
  486. }
  487. .verificationCode.active {
  488. background: #F5BA3C;
  489. color: #fff;
  490. }
  491. .getcode {
  492. font-size: 14px;
  493. position: absolute;
  494. right: 0;
  495. top: 50%;
  496. transform: translateY(-50%);
  497. color: #AFB3BF;
  498. background: #F5F6F9;
  499. height: 30px;
  500. line-height: 30px;
  501. }
  502. .getcode:after {
  503. border: none;
  504. }
  505. uni-navigator {
  506. display: inline-block;
  507. color: #F5BA3C;
  508. }
  509. .activeCode {
  510. background: #F5BA3C;
  511. color: #fff;
  512. }
  513. .NumberMedium {
  514. display: flex;
  515. align-items: center;
  516. }
  517. .flex {
  518. align-items: center;
  519. }
  520. </style>