register.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. <template>
  2. <view class="container">
  3. <view class="back-btn cuIcon-back" @click="navBack"></view>
  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 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 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 maxlength='16' class='Regular input-style' style='height:30px;' v-model='password'
  25. 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;text-align:center;'>
  33. <image @click='consent' style='width:14px;height:14px;position:relative;top:2px;margin-right:5px;'
  34. :src="consentStatus==true?'../../static/img/login/select@2x.png':'../../static/img/login/selected2.png'"
  35. alt=""></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|9][0-9]\d{8}$/.test(this.phone)) {
  154. this.$api.doRequest('get', '/commonUser/sendVerifyCode', {
  155. phone: this.phone
  156. }).then(res => {
  157. if (res.data.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.data.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. this.$api.doRequest('post', '/commonUser/register', {
  220. phone: this.phone,
  221. password: this.password,
  222. verifyCode: this.verifyCode,
  223. userName: username
  224. }).then(res => {
  225. if (res.data.code == '11002') {
  226. uni.showToast({
  227. title: '验证码错误或过期,请重新获取',
  228. icon: 'none',
  229. duration: 2000
  230. })
  231. return
  232. } else if (res.data.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. this.$api.doRequest('get', '/commonUser/login', {
  245. phone: this.phone,
  246. password: this.password,
  247. cid: this.clientId
  248. }).then(res => {
  249. if (res.data.code == 200) {
  250. // pc登录
  251. this.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: this.phone,
  252. veriCode: "123456",}).then(res1 => {
  253. if(res1.data.code==200){
  254. uni.setStorageSync('pcUserInfo', res1.data.data)
  255. helper.getListByUserId()
  256. }
  257. else{
  258. that.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: '14444444444',
  259. veriCode: "123456",}).then(res2 => {
  260. uni.setStorageSync('pcUserInfo', res2.data.data)
  261. helper.getListByUserId()
  262. })
  263. }
  264. })
  265. uni.setStorageSync('userInfo', res.data.data)
  266. that.$store.commit('login', res.data.data)
  267. // that.liangxinLogin()
  268. uni.switchTab({
  269. url: '/pages/sale/information'
  270. });
  271. } else {
  272. uni.showToast({
  273. title: res.data.message,
  274. icon: 'none',
  275. duration: 2000
  276. })
  277. }
  278. uni.hideLoading()
  279. })
  280. .catch(res => {
  281. console.log(res);
  282. });
  283. }
  284. })
  285. .catch(res => {
  286. console.log(res);
  287. });
  288. },
  289. consent() {
  290. this.consentStatus = !this.consentStatus
  291. uni.setStorage({
  292. key: 'policyStorageKey',
  293. data: this.consentStatus
  294. });
  295. },
  296. switchover() {
  297. if (this.type == 'password') {
  298. this.type = 'text'
  299. } else {
  300. this.type = 'password'
  301. }
  302. },
  303. gocode() {
  304. uni.navigateTo({
  305. url: '/pages/public/login'
  306. })
  307. },
  308. forgetpass() {
  309. uni.navigateTo({
  310. url: '/pages/public/reset'
  311. })
  312. },
  313. phonelogin() {
  314. var that = this
  315. uni.showLoading({
  316. title: '登录中',
  317. mask: true
  318. })
  319. console.log("clientid", that.clientId)
  320. this.$api.request('user', 'login', {
  321. password: that.password,
  322. phone: that.phone,
  323. cid: that.clientId
  324. }, failres => {
  325. that.$api.msg(failres.errmsg)
  326. uni.hideLoading()
  327. }).then(res => {
  328. console.log(res)
  329. uni.setStorageSync('userInfo', res.data)
  330. that.$store.commit('login', res.data)
  331. // that.liangxinLogin()
  332. uni.switchTab({
  333. url: '/pages/sale/information'
  334. });
  335. uni.hideLoading()
  336. })
  337. },
  338. appleLogin() {
  339. var that = this
  340. uni.getProvider({
  341. service: 'oauth',
  342. success: function(res) {
  343. // console.log(res.provider)
  344. if (~res.provider.indexOf('apple')) {
  345. uni.login({
  346. provider: 'apple',
  347. success: loginRes => {
  348. uni.getUserInfo({
  349. provider: 'apple',
  350. success: userInfoRes => {
  351. that.$api.request('user',
  352. 'thirdPartLogin', {
  353. loginType: 4 /* */ ,
  354. raw: JSON.stringify(userInfoRes
  355. .userInfo)
  356. }, failres => {
  357. that.$api.msg(failres.errmsg)
  358. uni.hideLoading()
  359. }).then(res => {
  360. console.log("thirdPartLogin:" +
  361. res.data.phone)
  362. that.accessToken = res.data
  363. .accessToken
  364. that.logining = false
  365. uni.getUserInfo({
  366. lang: 'zh_CN',
  367. success: (e) => {
  368. uni.setStorageSync(
  369. 'userInfo',
  370. res
  371. .data
  372. )
  373. that.$store
  374. .commit(
  375. 'login',
  376. res
  377. .data
  378. )
  379. e.userInfo
  380. .nickname =
  381. e
  382. .userInfo
  383. .nickName
  384. e.userInfo
  385. .cid =
  386. uni
  387. .getStorageSync(
  388. "clientId"
  389. )
  390. that.$api
  391. .request(
  392. 'user',
  393. 'syncUserInfo',
  394. e
  395. .userInfo
  396. )
  397. .then(
  398. syncRes => {
  399. //同步过后
  400. res.data
  401. .nickname =
  402. e
  403. .userInfo
  404. .nickName
  405. res.data
  406. .avatarUrl =
  407. e
  408. .userInfo
  409. .avatarUrl
  410. res.data
  411. .gender =
  412. e
  413. .userInfo
  414. .gender
  415. if (!
  416. res
  417. .data
  418. .phone
  419. ) {
  420. res.data
  421. .phone =
  422. e
  423. .userInfo
  424. .phone
  425. }
  426. uni.setStorageSync(
  427. 'userInfo',
  428. res
  429. .data
  430. )
  431. that.$store
  432. .commit(
  433. 'login',
  434. res
  435. .data
  436. )
  437. })
  438. },
  439. complete: (e) => {
  440. uni.hideLoading()
  441. if (!res
  442. .data
  443. .phone ||
  444. res
  445. .data
  446. .phone ==
  447. "" ||
  448. res
  449. .data
  450. .phone ==
  451. undefined
  452. ) {
  453. that.isPhone =
  454. true //显示自定义的获取手机权限提示框
  455. that.inputStatus =
  456. 'inline'
  457. that.inputContent =
  458. ''
  459. } else {
  460. uni.switchTab({
  461. url: '/pages/sale/sale'
  462. });
  463. console
  464. .log(
  465. "complete"
  466. )
  467. }
  468. }
  469. })
  470. })
  471. console.log('获取用户信息成功' + JSON.stringify(
  472. userInfoRes))
  473. }
  474. })
  475. },
  476. fail: err => {
  477. console.log('apple登录失败' + JSON.stringify(err))
  478. uni.showToast({
  479. title: '登录失败',
  480. icon: 'none'
  481. })
  482. }
  483. })
  484. }
  485. },
  486. fail: err => {
  487. uni.showToast({
  488. title: '登录失败',
  489. icon: 'none'
  490. })
  491. }
  492. })
  493. },
  494. doGetVerify() {
  495. const that = this
  496. var phone = this.inputContent;
  497. if (!phone || phone.length != 11) {
  498. uni.showToast({
  499. title: '请输入正确手机号!',
  500. icon: 'none'
  501. })
  502. return
  503. }
  504. that.$api.request('user', 'sendVerifyCode', {
  505. phone: phone,
  506. }).then(res => {
  507. that.sendDisabled = true
  508. let sec = 60
  509. let interval = setInterval(() => {
  510. sec--;
  511. that.sendText = sec + 's后重发'
  512. if (sec <= 0) {
  513. that.sendDisabled = false
  514. that.sendText = "获取验证码"
  515. clearInterval(interval)
  516. }
  517. }, 1000)
  518. })
  519. },
  520. verifyCodeInput(e) {
  521. this.verifyCode = e.detail.value
  522. },
  523. cancel() {
  524. this.inputShow = false
  525. this.inputStatus = 'none'
  526. this.isPhone = false
  527. },
  528. confirm() {
  529. var that = this
  530. if (!this.inputContent || this.inputContent.length != 11) {
  531. uni.showToast({
  532. title: '请输入正确手机号!',
  533. icon: 'none'
  534. })
  535. return
  536. }
  537. if (!this.verifyCode) {
  538. uni.showToast({
  539. title: '请输入验证码!',
  540. icon: 'none'
  541. })
  542. return
  543. }
  544. this.$api.request('user', 'mergeUser', {
  545. phone: that.inputContent,
  546. verifyCode: that.verifyCode
  547. }, failres => {
  548. that.$api.msg(failres.errmsg)
  549. uni.hideLoading()
  550. }).then(res => {
  551. that.accessToken = res.data.accessToken
  552. that.$api.setUserInfo(res.data)
  553. that.logining = false
  554. uni.getUserInfo({
  555. lang: 'zh_CN',
  556. success: (e) => {
  557. uni.setStorageSync('userInfo', res.data)
  558. that.$store.commit('login', res.data)
  559. e.userInfo.nickname = e.userInfo.nickName
  560. e.userInfo.cid = uni.getStorageSync("clientId")
  561. console.log(e.userInfo)
  562. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  563. //同步过后
  564. res.data.nickname = e.userInfo.nickName
  565. res.data.avatarUrl = e.userInfo.avatarUrl
  566. res.data.gender = e.userInfo.gender
  567. res.data.phone = e.userInfo.phone
  568. uni.setStorageSync('userInfo', res.data)
  569. that.$store.commit('login', res.data)
  570. // that.liangxinLogin()
  571. })
  572. },
  573. complete: (e) => {
  574. uni.switchTab({
  575. url: '/pages/sale/information'
  576. });
  577. uni.hideLoading()
  578. that.isPhone = false
  579. uni.navigateBack()
  580. }
  581. })
  582. })
  583. },
  584. ...mapMutations(['login']),
  585. inputChange(e) {
  586. const key = e.currentTarget.dataset.key;
  587. this[key] = e.detail.value;
  588. },
  589. chooseLoginType(type) {
  590. this.loginType = type
  591. },
  592. navBack() {
  593. uni.navigateBack();
  594. },
  595. toRegist() {
  596. uni.redirectTo({
  597. url: '/pages/public/register'
  598. })
  599. },
  600. ///发起消息订阅
  601. requestSubscribe() {
  602. const that = this
  603. wx.requestSubscribeMessage({
  604. tmplIds: ['xL_uZEqJz4QP1FbnlzQWAiO2zVBn3Qeu8JwLVOU3hU0',
  605. '8cVkckXi_8zfHeScXRHhjN6cgZFYYCWIMPDTiPWagXY',
  606. 'IE7WxBsv-fDvPWSrng-97lGWtvZf9rHuECBlhRLlWxI'
  607. ], //
  608. success: (res) => {
  609. console.log("订阅消息 成功 " + res);
  610. },
  611. fail: (errMsg) => {
  612. console.log("订阅消息 失败 " + errMsg.errMsg);
  613. },
  614. complete: (errMsg) => {
  615. console.log("订阅消息 完成 " + errMsg);
  616. }
  617. });
  618. },
  619. getPhoneNumber(e) {
  620. console.log(e)
  621. if (e.mp.detail.errMsg === "getPhoneNumber:ok") {
  622. this.isPhone = false
  623. this.params.iv = e.mp.detail.iv
  624. this.params.encryptedData = e.mp.detail.encryptedData
  625. this.params.session_key = this.accessToken
  626. console.log(this.params)
  627. this.getTokenAsync(this.params)
  628. }
  629. },
  630. // 请求后获取token
  631. async getTokenAsync(params) {
  632. let that = this
  633. this.$api.request('user', 'getPhoneNumber', params).then(res => {
  634. if (res.data.phoneNumber) {
  635. that.userInfo.phone = res.data.phoneNumber
  636. }
  637. if (res.data.unionId) {
  638. that.userInfo.unionId = res.data.unionId
  639. }
  640. that.userInfo.cid = uni.getStorageSync("clientId")
  641. console.log(that.userInfo)
  642. that.$api.request('user', 'syncUserInfo', that.userInfo).then(syncRes => {
  643. uni.setStorageSync('userInfo', that.userInfo)
  644. that.$store.commit('login', that.userInfo)
  645. that.$api.setUserInfo(that.userInfo)
  646. uni.hideLoading()
  647. // that.liangxinLogin()
  648. })
  649. if (res.data.phoneNumber) {
  650. uni.switchTab({
  651. url: '/pages/sale/information'
  652. });
  653. }
  654. })
  655. },
  656. async toLogin() {
  657. this.verifyCode = ''
  658. const that = this
  659. if (that.phone.length !== 11) {
  660. that.$api.msg('请输入11位中国手机号')
  661. } else if (that.password.length < 8) {
  662. that.$api.msg('密码至少8位')
  663. } else {
  664. that.logining = true;
  665. //#ifdef MP-WEIXIN
  666. //若是小程序平台,则获取到openId。整个过程是静默完成的
  667. uni.login({
  668. provider: 'weixin',
  669. success: (wxres => {
  670. that.$api.request('user', 'login', {
  671. phone: that.phone,
  672. password: that.password,
  673. loginType: 1,
  674. raw: JSON.stringify(wxres)
  675. }, failres => {
  676. that.logining = false
  677. uni.showToast({
  678. title: failres.errmsg,
  679. icon: "none"
  680. });
  681. }).then(res => {
  682. that.logining = false
  683. that.$store.commit('login', res.data)
  684. uni.setStorageSync('userInfo', res.data)
  685. if (that.$api.prePage().lodaData) {
  686. that.$api.prePage().loadData()
  687. }
  688. uni.navigateBack()
  689. })
  690. })
  691. })
  692. //#endif
  693. //#ifdef APP-PLUS || H5
  694. //若是App登录,则不需要保存OpenId。可直接登录
  695. that.$api.request('user', 'login', {
  696. phone: that.phone,
  697. password: that.password,
  698. }, failres => {
  699. that.logining = false
  700. uni.showToast({
  701. title: failres.errmsg,
  702. icon: "none"
  703. });
  704. }).then(res => {
  705. that.logining = false
  706. that.$store.commit('login', res.data)
  707. uni.setStorageSync('userInfo', res.data)
  708. if (that.$api.prePage().lodaData) {
  709. that.$api.prePage().loadData()
  710. }
  711. uni.navigateBack()
  712. })
  713. //#endif
  714. }
  715. },
  716. miniWechatLogin(e) {
  717. const that = this
  718. //旧版本方式
  719. if (this.canIUseProfile == false) {
  720. console.log("旧版本方式")
  721. //获取授权信息
  722. if (e.detail.userInfo) {
  723. console.log('用户允许了授权')
  724. console.log(e.detail.userInfo); //1.拿到基本的微信信息!!
  725. uni.showLoading({
  726. title: '加载中',
  727. mask: true
  728. })
  729. that.logining = true
  730. let loginType = 1
  731. let userInfo = e.detail.userInfo
  732. uni.login({
  733. provider: 'weixin',
  734. success: (wxres => {
  735. that.logining = false
  736. that.$api.request('user', 'thirdPartLogin', {
  737. loginType: loginType,
  738. raw: JSON.stringify(wxres)
  739. }, failres => {
  740. that.$api.msg(failres.errmsg)
  741. uni.hideLoading()
  742. }).then(res => {
  743. that.accessToken = res.data.accessToken
  744. that.$api.setUserInfo(res.data)
  745. that.userInfo = res.data
  746. uni.getUserInfo({
  747. lang: 'zh_CN',
  748. provider: 'weixin',
  749. withCredentials: true,
  750. success: (e) => {
  751. that.params.iv = e.iv
  752. that.params.encryptedData = e.encryptedData
  753. that.params.session_key = that.accessToken
  754. console.log(this.params)
  755. that.getTokenAsync(this.params)
  756. uni.setStorageSync('userInfo', res.data)
  757. that.$store.commit('login', res.data)
  758. e.userInfo.nickname = e.userInfo.nickName
  759. if (e.userInfo.phone == undefined) {
  760. e.userInfo.phone = ''
  761. }
  762. e.userInfo.cid = uni.getStorageSync(
  763. "clientId")
  764. console.log(e.userInfo)
  765. that.$api.request('user', 'syncUserInfo', e
  766. .userInfo).then(syncRes => {
  767. //同步过后
  768. res.data.nickname = userInfo
  769. .nickName
  770. res.data.avatarUrl = userInfo
  771. .avatarUrl
  772. res.data.gender = userInfo
  773. .gender
  774. if (userInfo.phone) {
  775. res.data.phone = userInfo
  776. .phone
  777. // that.liangxinLogin()
  778. }
  779. uni.setStorageSync('userInfo',
  780. res.data)
  781. that.$store.commit('login', res
  782. .data)
  783. that.$api.setUserInfo(res.data)
  784. uni.hideLoading()
  785. // uni.navigateBack()
  786. })
  787. },
  788. complete: (e) => {
  789. uni.hideLoading()
  790. if (!res.data.phone || res.data.phone ==
  791. "" || res.data.phone == undefined) {
  792. that.isPhone = true //显示自定义的获取手机权限提示框
  793. that.inputStatus = 'inline'
  794. that.inputContent = ''
  795. } else {
  796. uni.setStorageSync('PageCur', "sale");
  797. // uni.switchTab({
  798. // url: '/pages/sale/sale'
  799. // });
  800. uni.switchTab({
  801. url: '/pages/sale/information'
  802. });
  803. console.log("complete")
  804. }
  805. }
  806. })
  807. })
  808. }),
  809. })
  810. }
  811. //新版本方式
  812. } else {
  813. console.log("新版本方式")
  814. uni.showLoading({
  815. title: '加载中',
  816. mask: true
  817. })
  818. that.logining = true
  819. let loginType = 1
  820. wx.getUserProfile({
  821. desc: '用于完善用户资料',
  822. lang: 'zh_CN',
  823. success: function(proRes) {
  824. console.log('proRes.userInfo', proRes.userInfo)
  825. uni.login({
  826. provider: 'weixin',
  827. success: (wxres => {
  828. that.logining = false
  829. that.$api.request('user', 'thirdPartLogin', {
  830. loginType: loginType,
  831. raw: JSON.stringify(wxres)
  832. }, failres => {
  833. that.$api.msg(failres.errmsg)
  834. uni.hideLoading()
  835. }).then(res => {
  836. console.log('res+++++', res)
  837. that.accessToken = res.data.accessToken
  838. that.$api.setUserInfo(res.data)
  839. that.userInfo = res.data
  840. // that.params.iv = proRes.iv
  841. // that.params.encryptedData = proRes.encryptedData
  842. // that.params.session_key = that.accessToken
  843. // console.log(that.params)
  844. // that.getTokenAsync(that.params)
  845. uni.setStorageSync('userInfo', res.data)
  846. that.$store.commit('login', res.data)
  847. if (proRes.userInfo.phone == undefined) {
  848. proRes.userInfo.phone = ''
  849. }
  850. res.data.cid = uni.getStorageSync("clientId")
  851. that.$api.request('user', 'syncUserInfo', res
  852. .data).then(syncRes => {
  853. //同步过后
  854. res.data.nickname = proRes.userInfo
  855. .nickName
  856. res.data.avatarUrl = proRes
  857. .userInfo.avatarUrl
  858. res.data.gender = proRes.userInfo
  859. .gender
  860. if (proRes.userInfo.phone) {
  861. res.data.phone = proRes
  862. .userInfo.phone
  863. }
  864. uni.setStorageSync('userInfo', res
  865. .data)
  866. that.$store.commit('login', res
  867. .data)
  868. that.$api.setUserInfo(res.data)
  869. uni.hideLoading()
  870. if (!that.userInfo.phone || that
  871. .userInfo.phone == "" || that
  872. .userInfo.phone == undefined) {
  873. that.isPhone =
  874. true //显示自定义的获取手机权限提示框
  875. that.inputStatus = 'inline'
  876. that.inputContent = ''
  877. } else {
  878. uni.setStorageSync('PageCur',
  879. "sale");
  880. // uni.switchTab({
  881. // url: '/pages/sale/sale'
  882. // });
  883. uni.reLaunch({
  884. url: '/pages/sale/information'
  885. });
  886. console.log("complete")
  887. // that.liangxinLogin()
  888. }
  889. })
  890. console.log('wx.getUserProfile=>用户允许了授权');
  891. })
  892. })
  893. })
  894. },
  895. fail: function(res) {
  896. console.log('wx.getUserProfile=>用户拒绝了授权');
  897. console.log(res);
  898. }
  899. });
  900. }
  901. // 获取用户的当前设置,判断是否点击了“总是保持以上,不在询问”
  902. // wx.getSetting({
  903. // withSubscriptions: true,//是否获取用户订阅消息的订阅状态,默认false不返回
  904. // success(res){
  905. //
  906. // if(res.subscriptionsSetting.mainSwitch){
  907. // }else{
  908. // }
  909. // }
  910. // })
  911. // uni.showModal({
  912. // title: '温馨提示',
  913. // content: '为更好的与您沟通,小程序需要向您发送通知消息',
  914. // confirmText:"同意",
  915. // cancelText:"拒绝",
  916. // showCancel: false,
  917. // success: function (res) {
  918. // if (res.confirm) {
  919. // //调用订阅消息
  920. // that.requestSubscribe();
  921. // } else if (res.cancel) {
  922. // ///显示第二个弹说明一下
  923. // wx.showModal({
  924. // title: '温馨提示',
  925. // content: '拒绝后您将无法获取实时的交易、物流消息',
  926. // confirmText:"知道了",
  927. // showCancel:false,
  928. // success: function (res) {
  929. // uni.openSetting({ // 打开设置页
  930. // success(res) {
  931. // console.log(res.authSetting)
  932. // }
  933. // });
  934. // }
  935. // });
  936. // }
  937. // }
  938. // });
  939. },
  940. wechatLogin() {
  941. const that = this
  942. that.logining = true
  943. let loginType = 2
  944. uni.showLoading({
  945. title: '正在同步消息',
  946. mask: true
  947. })
  948. uni.login({
  949. provider: 'weixin',
  950. success: (wxres => {
  951. that.$api.request('user', 'thirdPartLogin', {
  952. loginType: loginType,
  953. raw: JSON.stringify(wxres)
  954. }, failres => {
  955. that.$api.msg(failres.errmsg)
  956. uni.hideLoading()
  957. }).then(res => {
  958. console.log("thirdPartLogin:" + res.data.phone)
  959. that.accessToken = res.data.accessToken
  960. that.logining = false
  961. uni.getUserInfo({
  962. lang: 'zh_CN',
  963. success: (e) => {
  964. uni.setStorageSync('userInfo', res.data)
  965. that.$store.commit('login', res.data)
  966. e.userInfo.nickname = e.userInfo.nickName
  967. e.userInfo.cid = uni.getStorageSync("clientId")
  968. console.log(e.userInfo)
  969. that.$api.request('user', 'syncUserInfo', e
  970. .userInfo).then(syncRes => {
  971. //同步过后
  972. res.data.nickname = e.userInfo.nickName
  973. res.data.avatarUrl = e.userInfo
  974. .avatarUrl
  975. res.data.gender = e.userInfo.gender
  976. if (res.data.phone) {
  977. res.data.phone = e.userInfo.phone
  978. // that.liangxinLogin()
  979. }
  980. uni.setStorageSync('userInfo', res
  981. .data)
  982. that.$store.commit('login', res.data)
  983. })
  984. },
  985. complete: (e) => {
  986. uni.hideLoading()
  987. if (!res.data.phone || res.data.phone == "" || res
  988. .data.phone == undefined) {
  989. that.isPhone = true //显示自定义的获取手机权限提示框
  990. that.inputStatus = 'inline'
  991. that.inputContent = ''
  992. } else {
  993. // uni.switchTab({
  994. // url: '/pages/sale/sale'
  995. // });
  996. uni.switchTab({
  997. url: '/pages/sale/information'
  998. });
  999. console.log("complete")
  1000. }
  1001. }
  1002. })
  1003. })
  1004. })
  1005. })
  1006. },
  1007. wechatH5Login() {
  1008. const that = this
  1009. let href = window.location.origin
  1010. let page = that.$api.prePage()
  1011. let prePath = '/pages/index/index'
  1012. if (page) {
  1013. prePath = page.__page__.path
  1014. }
  1015. window.location = 'https://open.weixin.qq.com/connect/oauth2/authorize?' +
  1016. 'appid=' + that.$api.defConfig().h5Appid + '&redirect_uri=' + escape(href) +
  1017. '&response_type=code&scope=snsapi_userinfo&state=' + escape(prePath) + '#wechat_redirect'
  1018. },
  1019. liangxinLogin() {
  1020. const that = this
  1021. var userInfoTmp = uni.getStorageSync("userInfo")
  1022. console.log('userInfoTmp', userInfoTmp)
  1023. that.$socket.login(userInfoTmp.phone, "123456", null, res => {
  1024. console.log('粮信登录', res)
  1025. if (res.success) {
  1026. that.$socket.showLoginDialog = false
  1027. // 缓存用户
  1028. that.userData = res.response.data
  1029. console.log('userData', that.userData)
  1030. that.$u.vuex("userData", that.userData);
  1031. // 缓存通讯录
  1032. that.$socket.listGuests(that.userData.user.operId, res => {
  1033. // #ifdef APP-PLUS
  1034. createFSQL(that.userData.user.operId).then();
  1035. let contact = res.response.data;
  1036. contact.forEach(c => {
  1037. c.members.forEach(m => {
  1038. m.name = c.name;
  1039. addFSQL(m, that.userData.user.operId).then();
  1040. })
  1041. })
  1042. // #endif
  1043. that.$u.vuex('firendItem', res.response.data)
  1044. });
  1045. // 缓存消息列表
  1046. that.$socket.queryOnlineMessage(that.userData.user.operId, q => {
  1047. let data = q.response.data;
  1048. for (var i in data) {
  1049. initData(data[i].groupMsg.list, data[i].groupInfo.chatId);
  1050. }
  1051. })
  1052. // 缓存链接
  1053. that.$socket.getLinks(that.userData.user.operId, res => {
  1054. that.$u.vuex('linkItem', res.response.data)
  1055. });
  1056. // // 跳转到消息列表
  1057. // that.$u.route({
  1058. // url: 'pages/home/home',
  1059. // type: 'switchTab'
  1060. // });
  1061. } else {
  1062. uni.showModal({
  1063. title: res.reason + ",请稍后再试",
  1064. showCancel: false
  1065. })
  1066. }
  1067. });
  1068. }
  1069. },
  1070. }
  1071. </script>
  1072. <style lang='scss' scoped>
  1073. .password {
  1074. border: none;
  1075. outline: none;
  1076. }
  1077. .apple {
  1078. background: #000;
  1079. width: 35px;
  1080. height: 35px;
  1081. padding: 8px;
  1082. border-radius: 50%;
  1083. vertical-align: middle;
  1084. }
  1085. page {
  1086. background: #fff;
  1087. }
  1088. .cuIcon-weixin {
  1089. background: #39b54a;
  1090. color: #fff;
  1091. font-size: 18px;
  1092. padding: 9px;
  1093. border-radius: 50%;
  1094. vertical-align: middle;
  1095. margin-right: 5px;
  1096. }
  1097. .container {
  1098. padding-top: 85px;
  1099. position: relative;
  1100. width: 100vw;
  1101. height: 100vh;
  1102. overflow: hidden;
  1103. background: url('~@/static/img/login/bg.png');
  1104. background-size: 100%;
  1105. }
  1106. .close {
  1107. width: 20px;
  1108. height: 20px;
  1109. position: absolute;
  1110. right: 0px;
  1111. }
  1112. .close1 {
  1113. width: 20px;
  1114. height: 20px;
  1115. position: absolute;
  1116. right: 10px;
  1117. top: 0;
  1118. }
  1119. .close2 {
  1120. width: 15px;
  1121. height: 15px;
  1122. position: absolute;
  1123. right: 19px;
  1124. top: 50%;
  1125. transform: translateY(-45%);
  1126. }
  1127. .wrapper {
  1128. position: relative;
  1129. z-index: 90;
  1130. padding-bottom: 40upx;
  1131. height: 100%;
  1132. padding: 0 30px;
  1133. }
  1134. .back-btn {
  1135. position: absolute;
  1136. left: 40upx;
  1137. z-index: 9999;
  1138. padding-top: var(--status-bar-height);
  1139. top: 40upx;
  1140. font-size: 40upx;
  1141. color: $font-color-dark;
  1142. }
  1143. .verificationCode {
  1144. margin-top: 20px;
  1145. background: #F5F6F9;
  1146. color: #AFB3BF;
  1147. }
  1148. .verificationCode:after {
  1149. border: none;
  1150. }
  1151. .register {
  1152. position: absolute;
  1153. bottom: 20px;
  1154. left: 50%;
  1155. transform: translateX(-50%);
  1156. color: #333333;
  1157. height: 50px;
  1158. line-height: 50px;
  1159. border-radius: 30px;
  1160. border: 1px solid #444444;
  1161. }
  1162. .register:after {
  1163. border: none;
  1164. }
  1165. .verificationCode.active {
  1166. background: #22C572;
  1167. color: #fff;
  1168. }
  1169. .getcode {
  1170. font-size: 14px;
  1171. position: absolute;
  1172. right: 0;
  1173. top: 50%;
  1174. transform: translateY(-50%);
  1175. color: #AFB3BF;
  1176. background: #F5F6F9;
  1177. height: 30px;
  1178. line-height: 30px;
  1179. }
  1180. .getcode:after {
  1181. border: none;
  1182. }
  1183. uni-navigator {
  1184. display: inline-block;
  1185. color: #22C572;
  1186. }
  1187. .getcode.active {
  1188. background: #22C572;
  1189. color: #fff;
  1190. }
  1191. .NumberMedium {
  1192. display: flex;
  1193. align-items: center;
  1194. }
  1195. .flex {
  1196. align-items: center;
  1197. }
  1198. </style>