register.vue 13 KB

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