register.vue 12 KB

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