register.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. avatarUrl:"https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/1656724567954127.png"//司机默认头像
  227. }).then(res => {
  228. if (res.code == '11002') {
  229. uni.showToast({
  230. title: '验证码错误或过期,请重新获取',
  231. icon: 'none',
  232. duration: 2000
  233. })
  234. return
  235. } else if (res.code == '11004') {
  236. uni.showToast({
  237. title: '该手机号已注册,可直接登录',
  238. icon: 'none',
  239. duration: 2000
  240. })
  241. return
  242. } else {
  243. uni.showLoading({
  244. title: '登录中',
  245. mask: true
  246. })
  247. that.$request.baseRequest('get', '/commonUser/login', {
  248. phone: this.phone,
  249. password: this.password,
  250. loginFlag: 2,
  251. identification:1 //司机标识
  252. }).then(res => {
  253. if (res.code == 200) {
  254. // // pc登录
  255. // that.$request.baseRequest('post', '/commonUser/api/loginQuickly', {
  256. // mobilePhone: this.phone,
  257. // veriCode: "123456",
  258. // }).then(res1 => {
  259. // if (res1.code == 200) {
  260. // uni.setStorageSync('pcUserInfo', res1.data)
  261. // helper.getListByUserId()
  262. // } else {
  263. // that.$api.doRequest('post',
  264. // '/commonUser/api/loginQuickly', {
  265. // mobilePhone: '14444444444',
  266. // veriCode: "123456",
  267. // }).then(res2 => {
  268. // uni.setStorageSync('pcUserInfo', res2
  269. // .data)
  270. // helper.getListByUserId()
  271. // })
  272. // }
  273. // })
  274. uni.setStorageSync('userInfo', res.data)
  275. that.$store.commit('login', res.data)
  276. uni.switchTab({
  277. url: '/pages/goodSource/index'
  278. });
  279. } else {
  280. uni.showToast({
  281. title: res.message,
  282. icon: 'none',
  283. duration: 2000
  284. })
  285. }
  286. uni.hideLoading()
  287. })
  288. .catch(res => {
  289. console.log(res);
  290. });
  291. }
  292. })
  293. .catch(res => {
  294. console.log(res);
  295. });
  296. },
  297. consent() {
  298. this.consentStatus = !this.consentStatus
  299. uni.setStorage({
  300. key: 'policyStorageKey',
  301. data: this.consentStatus
  302. });
  303. },
  304. switchover() {
  305. if (this.type == 'password') {
  306. this.type = 'text'
  307. } else {
  308. this.type = 'password'
  309. }
  310. },
  311. ...mapMutations(['login']),
  312. navBack() {
  313. uni.navigateBack();
  314. },
  315. },
  316. }
  317. </script>
  318. <style lang='scss' scoped>
  319. uni-navigator {
  320. display: inline-block;
  321. color: #2772FB;
  322. }
  323. .password {
  324. border: none;
  325. outline: none;
  326. }
  327. .apple {
  328. background: #000;
  329. width: 35px;
  330. height: 35px;
  331. padding: 8px;
  332. border-radius: 50%;
  333. vertical-align: middle;
  334. }
  335. page {
  336. background: #fff;
  337. }
  338. .cuIcon-weixin {
  339. background: #2772FB;
  340. color: #fff;
  341. font-size: 18px;
  342. padding: 9px;
  343. border-radius: 50%;
  344. vertical-align: middle;
  345. margin-right: 5px;
  346. }
  347. .container {
  348. padding-top: 85px;
  349. position: relative;
  350. width: 100vw;
  351. height: calc(100vh - 85px);
  352. overflow: hidden;
  353. background: url('~@/static/images/mine/bg@2x.png');
  354. background-size: 100%;
  355. }
  356. .close {
  357. width: 20px;
  358. height: 20px;
  359. position: absolute;
  360. right: 0px;
  361. }
  362. .close1 {
  363. width: 20px;
  364. height: 20px;
  365. position: absolute;
  366. right: 10px;
  367. top: 0;
  368. }
  369. .close2 {
  370. width: 15px;
  371. height: 15px;
  372. position: absolute;
  373. right: 19px;
  374. top: 50%;
  375. transform: translateY(-45%);
  376. }
  377. .wrapper {
  378. position: relative;
  379. z-index: 90;
  380. padding-bottom: 40upx;
  381. height: 100%;
  382. padding: 0 30px;
  383. }
  384. .back-btn {
  385. position: absolute;
  386. left: 40upx;
  387. z-index: 9999;
  388. padding-top: var(--status-bar-height);
  389. top: 40upx;
  390. font-size: 40upx;
  391. color: black;
  392. }
  393. .verificationCode {
  394. margin-top: 20px;
  395. background: #F5F6F9;
  396. color: #AFB3BF;
  397. }
  398. .verificationCode:after {
  399. border: none;
  400. }
  401. .register {
  402. position: absolute;
  403. bottom: 20px;
  404. left: 50%;
  405. transform: translateX(-50%);
  406. color: #333333;
  407. height: 50px;
  408. line-height: 50px;
  409. border-radius: 30px;
  410. border: 1px solid #444444;
  411. }
  412. .register:after {
  413. border: none;
  414. }
  415. .verificationCode.active {
  416. background: #2772FB;
  417. color: #fff;
  418. }
  419. .getcode {
  420. font-size: 14px;
  421. position: absolute;
  422. right: 0;
  423. top: 50%;
  424. transform: translateY(-50%);
  425. color: #AFB3BF;
  426. background: #F5F6F9;
  427. height: 30px;
  428. line-height: 30px;
  429. }
  430. .getcode:after {
  431. border: none;
  432. }
  433. uni-navigator {
  434. display: inline-block;
  435. color: #2772FB;
  436. }
  437. .getcode.active {
  438. background: #2772FB;
  439. color: #fff;
  440. }
  441. .NumberMedium {
  442. display: flex;
  443. align-items: center;
  444. }
  445. .flex {
  446. align-items: center;
  447. }
  448. </style>