register.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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&&!sendDisabled?"active":""' @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. }else{
  157. this.codestatus = false
  158. }
  159. },
  160. getcode() {
  161. var that = this
  162. if (/^0?1[3|4|5|6|7|8][0-9]\d{8}$/.test(this.phone)) {
  163. that.$request.baseRequest('get', '/commonUser/sendVerifyCode', {
  164. phone: this.phone
  165. }).then(res => {
  166. console.log(2222222)
  167. if (res.code == 200) {
  168. console.log(1121212)
  169. that.sendDisabled = true
  170. let sec = 60
  171. let interval = setInterval(() => {
  172. sec--;
  173. that.sendText = sec + 's后重发'
  174. if (sec <= 0) {
  175. that.sendDisabled = false
  176. that.sendText = "获取验证码"
  177. clearInterval(interval)
  178. }
  179. }, 1000)
  180. } else {
  181. uni.showToast({
  182. title: res.message,
  183. icon: 'none',
  184. duration: 2000
  185. })
  186. }
  187. })
  188. .catch(res => {
  189. uni.showToast({
  190. title: res.data.message,
  191. icon: 'none',
  192. duration: 2000
  193. })
  194. });
  195. } else {
  196. uni.showToast({
  197. title: '请输入正确的手机号',
  198. icon: 'none',
  199. duration: 2000
  200. })
  201. }
  202. },
  203. register() {
  204. var that = this
  205. if (!this.consentStatus) {
  206. uni.showToast({
  207. title: '请勾选协议',
  208. icon: 'none',
  209. duration: 2000
  210. })
  211. return
  212. }
  213. if (this.verifyCode.length > 6) {
  214. uni.showToast({
  215. title: '验证码错误',
  216. icon: 'none',
  217. duration: 2000
  218. })
  219. return
  220. }
  221. if (this.password.length < 6) {
  222. uni.showToast({
  223. title: '密码请输入6-16字符格式',
  224. icon: 'none',
  225. duration: 2000
  226. })
  227. return
  228. }
  229. var username = this.getRandomName(3)
  230. that.$request.baseRequest('post', '/commonUser/register', {
  231. phone: this.phone,
  232. password: this.password,
  233. verifyCode: this.verifyCode,
  234. userName: username,
  235. identification:1,//司机标识
  236. avatarUrl:"https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/1656724567954127.png"//司机默认头像
  237. }).then(res => {
  238. if (res.code == '11002') {
  239. uni.showToast({
  240. title: '验证码错误或过期,请重新获取',
  241. icon: 'none',
  242. duration: 2000
  243. })
  244. return
  245. } else if (res.code == '11004') {
  246. uni.showToast({
  247. title: '该手机号已注册,可直接登录',
  248. icon: 'none',
  249. duration: 2000
  250. })
  251. return
  252. } else {
  253. uni.showLoading({
  254. title: '登录中',
  255. mask: true
  256. })
  257. that.$request.baseRequest('get', '/commonUser/login', {
  258. phone: this.phone,
  259. password: this.password,
  260. loginFlag: 2,
  261. identification:1 //司机标识
  262. }).then(res => {
  263. if (res.code == 200) {
  264. // // pc登录
  265. // that.$request.baseRequest('post', '/commonUser/api/loginQuickly', {
  266. // mobilePhone: this.phone,
  267. // veriCode: "123456",
  268. // }).then(res1 => {
  269. // if (res1.code == 200) {
  270. // uni.setStorageSync('pcUserInfo', res1.data)
  271. // helper.getListByUserId()
  272. // } else {
  273. // that.$api.doRequest('post',
  274. // '/commonUser/api/loginQuickly', {
  275. // mobilePhone: '14444444444',
  276. // veriCode: "123456",
  277. // }).then(res2 => {
  278. // uni.setStorageSync('pcUserInfo', res2
  279. // .data)
  280. // helper.getListByUserId()
  281. // })
  282. // }
  283. // })
  284. uni.setStorageSync('userInfo', res.data)
  285. that.$store.commit('login', res.data)
  286. uni.switchTab({
  287. url: '/pages/goodSource/index'
  288. });
  289. } else {
  290. uni.showToast({
  291. title: res.message,
  292. icon: 'none',
  293. duration: 2000
  294. })
  295. }
  296. uni.hideLoading()
  297. })
  298. .catch(res => {
  299. console.log(res);
  300. });
  301. }
  302. })
  303. .catch(res => {
  304. console.log(res);
  305. });
  306. },
  307. consent() {
  308. this.consentStatus = !this.consentStatus
  309. uni.setStorage({
  310. key: 'policyStorageKey',
  311. data: this.consentStatus
  312. });
  313. },
  314. switchover() {
  315. if (this.type == 'password') {
  316. this.type = 'text'
  317. } else {
  318. this.type = 'password'
  319. }
  320. },
  321. ...mapMutations(['login']),
  322. navBack() {
  323. uni.navigateBack();
  324. },
  325. },
  326. }
  327. </script>
  328. <style lang='scss' scoped>
  329. uni-navigator {
  330. display: inline-block;
  331. color: #2772FB;
  332. }
  333. .password {
  334. border: none;
  335. outline: none;
  336. }
  337. .apple {
  338. background: #000;
  339. width: 35px;
  340. height: 35px;
  341. padding: 8px;
  342. border-radius: 50%;
  343. vertical-align: middle;
  344. }
  345. page {
  346. background: #fff;
  347. }
  348. .cuIcon-weixin {
  349. background: #2772FB;
  350. color: #fff;
  351. font-size: 18px;
  352. padding: 9px;
  353. border-radius: 50%;
  354. vertical-align: middle;
  355. margin-right: 5px;
  356. }
  357. .container {
  358. padding-top: 85px;
  359. position: relative;
  360. width: 100vw;
  361. height: calc(100vh - 85px);
  362. overflow: hidden;
  363. background: url('~@/static/images/mine/bg@2x.png');
  364. background-size: 100%;
  365. }
  366. .close {
  367. width: 20px;
  368. height: 20px;
  369. position: absolute;
  370. right: 0px;
  371. }
  372. .close1 {
  373. width: 20px;
  374. height: 20px;
  375. position: absolute;
  376. right: 10px;
  377. top: 0;
  378. }
  379. .close2 {
  380. width: 15px;
  381. height: 15px;
  382. position: absolute;
  383. right: 19px;
  384. top: 50%;
  385. transform: translateY(-45%);
  386. }
  387. .wrapper {
  388. position: relative;
  389. z-index: 90;
  390. padding-bottom: 40upx;
  391. height: 100%;
  392. padding: 0 30px;
  393. }
  394. .back-btn {
  395. position: absolute;
  396. left: 40upx;
  397. z-index: 9999;
  398. padding-top: var(--status-bar-height);
  399. top: 40upx;
  400. font-size: 40upx;
  401. color: black;
  402. }
  403. .verificationCode {
  404. margin-top: 20px;
  405. background: #F5F6F9;
  406. color: #AFB3BF;
  407. }
  408. .verificationCode:after {
  409. border: none;
  410. }
  411. .register {
  412. position: absolute;
  413. bottom: 20px;
  414. left: 50%;
  415. transform: translateX(-50%);
  416. color: #333333;
  417. height: 50px;
  418. line-height: 50px;
  419. border-radius: 30px;
  420. border: 1px solid #444444;
  421. }
  422. .register:after {
  423. border: none;
  424. }
  425. .verificationCode.active {
  426. background: #2772FB;
  427. color: #fff;
  428. }
  429. .getcode {
  430. font-size: 14px;
  431. position: absolute;
  432. right: 0;
  433. top: 50%;
  434. transform: translateY(-50%);
  435. color: #AFB3BF;
  436. background: #F5F6F9;
  437. height: 30px;
  438. line-height: 30px;
  439. }
  440. .getcode:after {
  441. border: none;
  442. }
  443. uni-navigator {
  444. display: inline-block;
  445. color: #2772FB;
  446. }
  447. .getcode.active {
  448. background: #2772FB;
  449. color: #fff;
  450. }
  451. .NumberMedium {
  452. display: flex;
  453. align-items: center;
  454. }
  455. .flex {
  456. align-items: center;
  457. }
  458. </style>