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