register.vue 13 KB

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