register.vue 11 KB

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