register.vue 11 KB

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