register.vue 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  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;' class="flex">
  7. <view class="NumberMedium" style='width:15%;border-right:1px solid #E8E9ED;'>+86</view>
  8. <view style='width:85%;'><input maxlength="11" v-model='phone' @input='phoneinput' style='padding-left:10px;' placeholder="请输入手机号码" type="number" class="Regular"></view>
  9. <image v-if='phone!=""' @click='phone=""' class='close' src='../../static/img/login/guanbi@2x.png'></image>
  10. </view>
  11. <view style='width:100%;border-bottom:1px solid #E8E9ED;position:relative;padding:10px;' class="flex">
  12. <view style='width:70%;position:relative;'>
  13. <input v-model='verifyCode' class="Regular" placeholder="请输入验证码" type="number">
  14. <image v-if='verifyCode!=""' @click='verifyCode=""' class='close1' src='../../static/img/login/guanbi@2x.png'></image>
  15. </view>
  16. <button :class='codestatus&&!sendDisabled?"active":""' @click='getcode' class='getcode Regular'>{{sendText}}</button>
  17. </view>
  18. <view style='border-bottom:1px solid #E8E9ED;padding:10px;position:relative;'>
  19. <u-input maxlength='16' class='Regular input-style' style='height:30px;' v-model='password' placeholder="请输入密码,6-16位字符" :type="type"/>
  20. <!-- <input maxlength='16' class='password Regular input-style' style='height:30px;' v-model='password' placeholder="请输入密码,6-16位字符" :type="type"> -->
  21. <!-- <image v-if='password!=""' @click='password=""' class='close2' src='../../static/img/login/guanbi@2x.png'></image> -->
  22. <!-- <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> -->
  23. </view>
  24. <button :class='phone!=""&&verifyCode!=""&&password!=""?"active":""' @click='register' class='verificationCode'>注册</button>
  25. <view style='color:#6A6A6A;margin-top:10px;text-align:center;'>
  26. <image @click='consent' style='width:14px;height:14px;position:relative;top:2px;margin-right:5px;' :src="consentStatus==true?'../../static/img/login/select@2x.png':'../../static/img/login/selected2.png'" alt=""></image>
  27. 已阅读并同意
  28. <navigator url="/pages/sale/webview?can_share=false&url=https://liangxin.zthymaoyi.com/userAgreement.html" class="path" hover-class="navigator-hover">《服务协议》</navigator>和<navigator url="/pages/sale/webview?can_share=false&url=https://liangxin.zthymaoyi.com/screctAgreement.html"
  29. class="path" hover-class="navigator-hover">《隐私政策》</navigator>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. mapMutations
  37. } from 'vuex';
  38. import { openFSqlite, createFSQL, selectFSQL, addFSQL } from '../../util/f.js'
  39. import helper from '@/common/helper.js';
  40. import { queryData, upData, initData } from '../../util/dbUtil.js'
  41. export default {
  42. data() {
  43. return {
  44. inputContent: null,
  45. loginType: "wechat",
  46. phone: '',
  47. password: '',
  48. logining: false,
  49. isPhone: false,
  50. isApple: true,
  51. accessToken:'',
  52. params:{
  53. encryptedData:'',
  54. session_key:'',
  55. iv:'',
  56. },
  57. userInfo:{
  58. nickName:'',
  59. avatarUrl:'',
  60. gender:'',
  61. phone:''
  62. },
  63. consentStatus:false,
  64. codestatus:false,
  65. type:'password',
  66. inputStatus:'none',
  67. verifyCode:null,
  68. sendText:'获取验证码',
  69. sendDisabled: false,
  70. system:'',
  71. platform:'',
  72. userData:undefined,
  73. canIUseProfile:false
  74. }
  75. },
  76. onShow() {
  77. // this.loginType = "wechat"
  78. // this.$api.logout()
  79. },
  80. onLoad(options) {
  81. if( wx.getUserProfile ){
  82. console.log('--check getUserProfile--OK');
  83. this.canIUseProfile = true;
  84. }
  85. console.log("login on load")
  86. var that = this
  87. that.$api.request('user', 'sendIsApple', {
  88. }).then(res => {
  89. that.isApple = res.data
  90. })
  91. uni.getSystemInfo({
  92. success:(res) => {
  93. // console.log(res)
  94. this.system = res.system // ios
  95. this.platform = res.platform // 14.3
  96. }
  97. })
  98. },
  99. methods: {
  100. // 随机数
  101. randomAccess(min,max){
  102. return Math.floor(Math.random() * (min - max) + max)
  103. },
  104. // 解码
  105. decodeUnicode(str) {
  106. //Unicode显示方式是\u4e00
  107. str = "\\u"+str
  108. str = str.replace(/\\/g, "%");
  109. //转换中文
  110. str = unescape(str);
  111. //将其他受影响的转换回原来
  112. str = str.replace(/%/g, "\\");
  113. return str;
  114. },
  115. /*
  116. *@param Number NameLength 要获取的名字长度
  117. */
  118. getRandomName(NameLength){
  119. let name = ""
  120. for(let i = 0;i<NameLength;i++){
  121. let unicodeNum = ""
  122. unicodeNum = this.randomAccess(0x4e00,0x9fa5).toString(16)
  123. name += this.decodeUnicode(unicodeNum)
  124. }
  125. return name
  126. },
  127. phoneinput(e){
  128. if(e.detail.value.length==11){
  129. this.codestatus=true
  130. }
  131. },
  132. getcode(){
  133. var that = this
  134. if(/^0?1[3|4|5|6|7|8][0-9]\d{8}$/.test(this.phone)){
  135. this.$api.doRequest('get','/commonUser/sendVerifyCode',{phone:this.phone}).then(res => {
  136. if(res.data.code==200){
  137. that.sendDisabled = true
  138. let sec = 60
  139. let interval = setInterval(() => {
  140. sec--;
  141. that.sendText = sec + 's后重发'
  142. if (sec <= 0) {
  143. that.sendDisabled = false
  144. that.sendText = "获取验证码"
  145. clearInterval(interval)
  146. }
  147. }, 1000)
  148. }else{
  149. uni.showToast({
  150. title: res.data.message,
  151. icon:'none',
  152. duration: 2000
  153. })
  154. }
  155. })
  156. .catch(res => {
  157. uni.showToast({
  158. title: res.data.message,
  159. icon:'none',
  160. duration: 2000
  161. })
  162. });
  163. }else{
  164. uni.showToast({
  165. title: '请输入正确的手机号',
  166. icon:'none',
  167. duration: 2000
  168. })
  169. }
  170. },
  171. register(){
  172. var that = this
  173. if(!this.consentStatus){
  174. uni.showToast({
  175. title: '请勾选协议',
  176. icon:'none',
  177. duration: 2000
  178. })
  179. return
  180. }
  181. if(this.verifyCode.length>6){
  182. uni.showToast({
  183. title: '验证码错误',
  184. icon:'none',
  185. duration: 2000
  186. })
  187. return
  188. }
  189. if(this.password.length<6){
  190. uni.showToast({
  191. title: '请输入正确的密码格式',
  192. icon:'none',
  193. duration: 2000
  194. })
  195. return
  196. }
  197. var username=this.getRandomName(3)
  198. this.$api.doRequest('post','/commonUser/register',{phone:this.phone,password:this.password,verifyCode:this.verifyCode,userName:username}).then(res => {
  199. if(res.data.code=='11002'){
  200. uni.showToast({
  201. title: '验证码错误或过期,请重新获取',
  202. icon:'none',
  203. duration: 2000
  204. })
  205. return
  206. }else if(res.data.code=='11004'){
  207. uni.showToast({
  208. title: '该手机号已注册,可直接登录',
  209. icon:'none',
  210. duration: 2000
  211. })
  212. return
  213. }
  214. else{
  215. uni.showLoading({
  216. title: '登录中',
  217. mask:true
  218. })
  219. this.$api.doRequest('get','/commonUser/login',{phone:this.phone,password:this.password,cid:this.clientId}).then(res => {
  220. if(res.data.code==200){
  221. // pc登录
  222. this.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: this.phone,
  223. veriCode: "123456",}).then(res1 => {
  224. if(res1.data.code==200){
  225. uni.setStorageSync('pcUserInfo', res1.data.data)
  226. helper.getListByUserId()
  227. }
  228. else{
  229. that.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: '13333333333',
  230. veriCode: "123456",}).then(res2 => {
  231. uni.setStorageSync('pcUserInfo', res2.data.data)
  232. helper.getListByUserId()
  233. })
  234. }
  235. })
  236. uni.setStorageSync('userInfo', res.data)
  237. that.$store.commit('login', res.data)
  238. // that.liangxinLogin()
  239. uni.switchTab({
  240. url: '/pages/sale/information'
  241. });
  242. }else{
  243. uni.showToast({
  244. title: res.data.message,
  245. icon:'none',
  246. duration: 2000
  247. })
  248. }
  249. uni.hideLoading()
  250. })
  251. .catch(res => {
  252. console.log(res);
  253. });
  254. }
  255. })
  256. .catch(res => {
  257. console.log(res);
  258. });
  259. },
  260. consent(){
  261. this.consentStatus=!this.consentStatus
  262. uni.setStorage({
  263. key: 'policyStorageKey',
  264. data: this.consentStatus
  265. });
  266. },
  267. switchover(){
  268. if(this.type=='password'){
  269. this.type='text'
  270. }else{
  271. this.type='password'
  272. }
  273. },
  274. gocode(){
  275. uni.navigateTo({
  276. url:'/pages/public/login'
  277. })
  278. },
  279. forgetpass(){
  280. uni.navigateTo({
  281. url:'/pages/public/reset'
  282. })
  283. },
  284. phonelogin(){
  285. var that=this
  286. uni.showLoading({
  287. title: '登录中',
  288. mask:true
  289. })
  290. console.log("clientid",that.clientId)
  291. this.$api.request('user', 'login',{
  292. password:that.password,
  293. phone:that.phone,
  294. cid:that.clientId
  295. }, failres => {
  296. that.$api.msg(failres.errmsg)
  297. uni.hideLoading()
  298. }).then(res => {
  299. console.log(res)
  300. uni.setStorageSync('userInfo', res.data)
  301. that.$store.commit('login', res.data)
  302. // that.liangxinLogin()
  303. uni.switchTab({
  304. url: '/pages/sale/information'
  305. });
  306. uni.hideLoading()
  307. })
  308. },
  309. appleLogin(){
  310. var that=this
  311. uni.getProvider({
  312. service: 'oauth',
  313. success: function (res) {
  314. // console.log(res.provider)
  315. if(~res.provider.indexOf('apple')) {
  316. uni.login({
  317. provider: 'apple',
  318. success: loginRes => {
  319. uni.getUserInfo({
  320. provider: 'apple',
  321. success: userInfoRes => {
  322. that.$api.request('user', 'thirdPartLogin', {
  323. loginType: 4/* */,
  324. raw: JSON.stringify(userInfoRes.userInfo)
  325. }, failres => {
  326. that.$api.msg(failres.errmsg)
  327. uni.hideLoading()
  328. }).then(res => {
  329. console.log("thirdPartLogin:"+res.data.phone)
  330. that.accessToken = res.data.accessToken
  331. that.logining = false
  332. uni.getUserInfo({
  333. lang: 'zh_CN',
  334. success: (e) => {
  335. uni.setStorageSync('userInfo', res.data)
  336. that.$store.commit('login', res.data)
  337. e.userInfo.nickname = e.userInfo.nickName
  338. e.userInfo.cid = uni.getStorageSync("clientId")
  339. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  340. //同步过后
  341. res.data.nickname = e.userInfo.nickName
  342. res.data.avatarUrl = e.userInfo.avatarUrl
  343. res.data.gender = e.userInfo.gender
  344. if(!res.data.phone){
  345. res.data.phone = e.userInfo.phone
  346. }
  347. uni.setStorageSync('userInfo', res.data)
  348. that.$store.commit('login', res.data)
  349. })
  350. },
  351. complete: (e) => {
  352. uni.hideLoading()
  353. if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
  354. that.isPhone = true//显示自定义的获取手机权限提示框
  355. that.inputStatus = 'inline'
  356. that.inputContent = ''
  357. }
  358. else{
  359. uni.switchTab({
  360. url: '/pages/sale/sale'
  361. });
  362. console.log("complete")
  363. }
  364. }
  365. })
  366. })
  367. console.log('获取用户信息成功'+JSON.stringify(userInfoRes))
  368. }
  369. })
  370. },
  371. fail: err => {
  372. console.log('apple登录失败' + JSON.stringify(err))
  373. uni.showToast({
  374. title:'登录失败',
  375. icon:'none'
  376. })
  377. }
  378. })
  379. }
  380. },
  381. fail: err => {
  382. uni.showToast({
  383. title:'登录失败',
  384. icon:'none'
  385. })
  386. }
  387. })
  388. },
  389. doGetVerify() {
  390. const that = this
  391. var phone = this.inputContent;
  392. if (!phone || phone.length != 11) {
  393. uni.showToast({
  394. title:'请输入正确手机号!',
  395. icon:'none'
  396. })
  397. return
  398. }
  399. that.$api.request('user', 'sendVerifyCode', {
  400. phone: phone,
  401. }).then(res => {
  402. that.sendDisabled = true
  403. let sec = 60
  404. let interval = setInterval(() => {
  405. sec--;
  406. that.sendText = sec + 's后重发'
  407. if (sec <= 0) {
  408. that.sendDisabled = false
  409. that.sendText = "获取验证码"
  410. clearInterval(interval)
  411. }
  412. }, 1000)
  413. })
  414. },
  415. verifyCodeInput(e){
  416. this.verifyCode = e.detail.value
  417. },
  418. cancel() {
  419. this.inputShow = false
  420. this.inputStatus = 'none'
  421. this.isPhone = false
  422. },
  423. confirm() {
  424. var that = this
  425. if (!this.inputContent || this.inputContent.length != 11) {
  426. uni.showToast({
  427. title:'请输入正确手机号!',
  428. icon:'none'
  429. })
  430. return
  431. }
  432. if (!this.verifyCode) {
  433. uni.showToast({
  434. title:'请输入验证码!',
  435. icon:'none'
  436. })
  437. return
  438. }
  439. this.$api.request('user', 'mergeUser', {
  440. phone: that.inputContent,
  441. verifyCode:that.verifyCode
  442. },failres => {
  443. that.$api.msg(failres.errmsg)
  444. uni.hideLoading()
  445. }).then(res => {
  446. that.accessToken = res.data.accessToken
  447. that.$api.setUserInfo(res.data)
  448. that.logining = false
  449. uni.getUserInfo({
  450. lang: 'zh_CN',
  451. success: (e) => {
  452. uni.setStorageSync('userInfo', res.data)
  453. that.$store.commit('login', res.data)
  454. e.userInfo.nickname = e.userInfo.nickName
  455. e.userInfo.cid = uni.getStorageSync("clientId")
  456. console.log(e.userInfo)
  457. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  458. //同步过后
  459. res.data.nickname = e.userInfo.nickName
  460. res.data.avatarUrl = e.userInfo.avatarUrl
  461. res.data.gender = e.userInfo.gender
  462. res.data.phone = e.userInfo.phone
  463. uni.setStorageSync('userInfo', res.data)
  464. that.$store.commit('login', res.data)
  465. // that.liangxinLogin()
  466. })
  467. },
  468. complete: (e) => {
  469. uni.switchTab({
  470. url: '/pages/sale/information'
  471. });
  472. uni.hideLoading()
  473. that.isPhone=false
  474. uni.navigateBack()
  475. }
  476. })
  477. })
  478. },
  479. ...mapMutations(['login']),
  480. inputChange(e) {
  481. const key = e.currentTarget.dataset.key;
  482. this[key] = e.detail.value;
  483. },
  484. chooseLoginType(type) {
  485. this.loginType = type
  486. },
  487. navBack() {
  488. uni.navigateBack();
  489. },
  490. toRegist() {
  491. uni.redirectTo({
  492. url: '/pages/public/register'
  493. })
  494. },
  495. ///发起消息订阅
  496. requestSubscribe(){
  497. const that = this
  498. wx.requestSubscribeMessage({
  499. tmplIds: ['xL_uZEqJz4QP1FbnlzQWAiO2zVBn3Qeu8JwLVOU3hU0','8cVkckXi_8zfHeScXRHhjN6cgZFYYCWIMPDTiPWagXY','IE7WxBsv-fDvPWSrng-97lGWtvZf9rHuECBlhRLlWxI'],//
  500. success :(res)=>{
  501. console.log("订阅消息 成功 "+res);
  502. },
  503. fail :(errMsg) =>{
  504. console.log("订阅消息 失败 "+errMsg.errMsg);
  505. },
  506. complete:(errMsg)=>{
  507. console.log("订阅消息 完成 "+errMsg);
  508. }
  509. });
  510. },
  511. getPhoneNumber(e) {
  512. console.log(e)
  513. if (e.mp.detail.errMsg==="getPhoneNumber:ok") {
  514. this.isPhone = false
  515. this.params.iv = e.mp.detail.iv
  516. this.params.encryptedData = e.mp.detail.encryptedData
  517. this.params.session_key = this.accessToken
  518. console.log(this.params)
  519. this.getTokenAsync(this.params)
  520. }
  521. },
  522. // 请求后获取token
  523. async getTokenAsync(params) {
  524. let that = this
  525. this.$api.request('user', 'getPhoneNumber', params).then(res => {
  526. if(res.data.phoneNumber){
  527. that.userInfo.phone = res.data.phoneNumber
  528. }
  529. if(res.data.unionId){
  530. that.userInfo.unionId = res.data.unionId
  531. }
  532. that.userInfo.cid = uni.getStorageSync("clientId")
  533. console.log(that.userInfo)
  534. that.$api.request('user', 'syncUserInfo', that.userInfo).then(syncRes => {
  535. uni.setStorageSync('userInfo', that.userInfo)
  536. that.$store.commit('login', that.userInfo)
  537. that.$api.setUserInfo(that.userInfo)
  538. uni.hideLoading()
  539. // that.liangxinLogin()
  540. })
  541. if(res.data.phoneNumber){
  542. uni.switchTab({
  543. url: '/pages/sale/information'
  544. });
  545. }
  546. })
  547. },
  548. async toLogin() {
  549. this.verifyCode = ''
  550. const that = this
  551. if (that.phone.length !== 11) {
  552. that.$api.msg('请输入11位中国手机号')
  553. } else if (that.password.length < 8) {
  554. that.$api.msg('密码至少8位')
  555. } else {
  556. that.logining = true;
  557. //#ifdef MP-WEIXIN
  558. //若是小程序平台,则获取到openId。整个过程是静默完成的
  559. uni.login({
  560. provider: 'weixin',
  561. success: (wxres => {
  562. that.$api.request('user', 'login', {
  563. phone: that.phone,
  564. password: that.password,
  565. loginType: 1,
  566. raw: JSON.stringify(wxres)
  567. }, failres => {
  568. that.logining = false
  569. uni.showToast({
  570. title: failres.errmsg,
  571. icon: "none"
  572. });
  573. }).then(res => {
  574. that.logining = false
  575. that.$store.commit('login', res.data)
  576. uni.setStorageSync('userInfo', res.data)
  577. if (that.$api.prePage().lodaData) {
  578. that.$api.prePage().loadData()
  579. }
  580. uni.navigateBack()
  581. })
  582. })
  583. })
  584. //#endif
  585. //#ifdef APP-PLUS || H5
  586. //若是App登录,则不需要保存OpenId。可直接登录
  587. that.$api.request('user', 'login', {
  588. phone: that.phone,
  589. password: that.password,
  590. }, failres => {
  591. that.logining = false
  592. uni.showToast({
  593. title: failres.errmsg,
  594. icon: "none"
  595. });
  596. }).then(res => {
  597. that.logining = false
  598. that.$store.commit('login', res.data)
  599. uni.setStorageSync('userInfo', res.data)
  600. if (that.$api.prePage().lodaData) {
  601. that.$api.prePage().loadData()
  602. }
  603. uni.navigateBack()
  604. })
  605. //#endif
  606. }
  607. },
  608. miniWechatLogin(e) {
  609. const that = this
  610. //旧版本方式
  611. if( this.canIUseProfile == false ){
  612. console.log("旧版本方式")
  613. //获取授权信息
  614. if(e.detail.userInfo){
  615. console.log('用户允许了授权')
  616. console.log( e.detail.userInfo ); //1.拿到基本的微信信息!!
  617. uni.showLoading({
  618. title: '加载中',
  619. mask:true
  620. })
  621. that.logining = true
  622. let loginType = 1
  623. let userInfo = e.detail.userInfo
  624. uni.login({
  625. provider: 'weixin',
  626. success: (wxres => {
  627. that.logining = false
  628. that.$api.request('user', 'thirdPartLogin', {
  629. loginType: loginType,
  630. raw: JSON.stringify(wxres)
  631. }, failres => {
  632. that.$api.msg(failres.errmsg)
  633. uni.hideLoading()
  634. }).then(res => {
  635. that.accessToken = res.data.accessToken
  636. that.$api.setUserInfo(res.data)
  637. that.userInfo = res.data
  638. uni.getUserInfo({
  639. lang: 'zh_CN',
  640. provider: 'weixin',
  641. withCredentials:true,
  642. success: (e) => {
  643. that.params.iv = e.iv
  644. that.params.encryptedData = e.encryptedData
  645. that.params.session_key = that.accessToken
  646. console.log(this.params)
  647. that.getTokenAsync(this.params)
  648. uni.setStorageSync('userInfo', res.data)
  649. that.$store.commit('login', res.data)
  650. e.userInfo.nickname = e.userInfo.nickName
  651. if(e.userInfo.phone == undefined){
  652. e.userInfo.phone = ''
  653. }
  654. e.userInfo.cid = uni.getStorageSync("clientId")
  655. console.log(e.userInfo)
  656. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  657. //同步过后
  658. res.data.nickname = userInfo.nickName
  659. res.data.avatarUrl = userInfo.avatarUrl
  660. res.data.gender = userInfo.gender
  661. if(userInfo.phone){
  662. res.data.phone = userInfo.phone
  663. // that.liangxinLogin()
  664. }
  665. uni.setStorageSync('userInfo', res.data)
  666. that.$store.commit('login', res.data)
  667. that.$api.setUserInfo(res.data)
  668. uni.hideLoading()
  669. // uni.navigateBack()
  670. })
  671. },
  672. complete: (e) => {
  673. uni.hideLoading()
  674. if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
  675. that.isPhone = true//显示自定义的获取手机权限提示框
  676. that.inputStatus = 'inline'
  677. that.inputContent = ''
  678. }
  679. else{
  680. uni.setStorageSync('PageCur', "sale");
  681. // uni.switchTab({
  682. // url: '/pages/sale/sale'
  683. // });
  684. uni.switchTab({
  685. url: '/pages/sale/information'
  686. });
  687. console.log("complete")
  688. }
  689. }
  690. })
  691. })
  692. }),
  693. })
  694. }
  695. //新版本方式
  696. }else{
  697. console.log("新版本方式")
  698. uni.showLoading({
  699. title: '加载中',
  700. mask:true
  701. })
  702. that.logining = true
  703. let loginType = 1
  704. wx.getUserProfile({
  705. desc : '用于完善用户资料',
  706. lang : 'zh_CN',
  707. success : function( proRes ){
  708. console.log('proRes.userInfo',proRes.userInfo)
  709. uni.login({
  710. provider: 'weixin',
  711. success: (wxres => {
  712. that.logining = false
  713. that.$api.request('user', 'thirdPartLogin', {
  714. loginType: loginType,
  715. raw: JSON.stringify(wxres)
  716. }, failres => {
  717. that.$api.msg(failres.errmsg)
  718. uni.hideLoading()
  719. }).then(res => {
  720. console.log('res+++++',res)
  721. that.accessToken = res.data.accessToken
  722. that.$api.setUserInfo(res.data)
  723. that.userInfo = res.data
  724. // that.params.iv = proRes.iv
  725. // that.params.encryptedData = proRes.encryptedData
  726. // that.params.session_key = that.accessToken
  727. // console.log(that.params)
  728. // that.getTokenAsync(that.params)
  729. uni.setStorageSync('userInfo', res.data)
  730. that.$store.commit('login', res.data)
  731. if(proRes.userInfo.phone == undefined){
  732. proRes.userInfo.phone = ''
  733. }
  734. res.data.cid = uni.getStorageSync("clientId")
  735. that.$api.request('user', 'syncUserInfo', res.data).then(syncRes => {
  736. //同步过后
  737. res.data.nickname = proRes.userInfo.nickName
  738. res.data.avatarUrl = proRes.userInfo.avatarUrl
  739. res.data.gender = proRes.userInfo.gender
  740. if(proRes.userInfo.phone){
  741. res.data.phone = proRes.userInfo.phone
  742. }
  743. uni.setStorageSync('userInfo', res.data)
  744. that.$store.commit('login', res.data)
  745. that.$api.setUserInfo(res.data)
  746. uni.hideLoading()
  747. if(!that.userInfo.phone||that.userInfo.phone==""||that.userInfo.phone ==undefined){
  748. that.isPhone = true//显示自定义的获取手机权限提示框
  749. that.inputStatus = 'inline'
  750. that.inputContent = ''
  751. }
  752. else{
  753. uni.setStorageSync('PageCur', "sale");
  754. // uni.switchTab({
  755. // url: '/pages/sale/sale'
  756. // });
  757. uni.reLaunch({
  758. url: '/pages/sale/information'
  759. });
  760. console.log("complete")
  761. // that.liangxinLogin()
  762. }
  763. })
  764. console.log( 'wx.getUserProfile=>用户允许了授权' );
  765. })
  766. })
  767. })
  768. },
  769. fail : function( res ){
  770. console.log('wx.getUserProfile=>用户拒绝了授权');
  771. console.log( res );
  772. }
  773. });
  774. }
  775. // 获取用户的当前设置,判断是否点击了“总是保持以上,不在询问”
  776. // wx.getSetting({
  777. // withSubscriptions: true,//是否获取用户订阅消息的订阅状态,默认false不返回
  778. // success(res){
  779. //
  780. // if(res.subscriptionsSetting.mainSwitch){
  781. // }else{
  782. // }
  783. // }
  784. // })
  785. // uni.showModal({
  786. // title: '温馨提示',
  787. // content: '为更好的与您沟通,小程序需要向您发送通知消息',
  788. // confirmText:"同意",
  789. // cancelText:"拒绝",
  790. // showCancel: false,
  791. // success: function (res) {
  792. // if (res.confirm) {
  793. // //调用订阅消息
  794. // that.requestSubscribe();
  795. // } else if (res.cancel) {
  796. // ///显示第二个弹说明一下
  797. // wx.showModal({
  798. // title: '温馨提示',
  799. // content: '拒绝后您将无法获取实时的交易、物流消息',
  800. // confirmText:"知道了",
  801. // showCancel:false,
  802. // success: function (res) {
  803. // uni.openSetting({ // 打开设置页
  804. // success(res) {
  805. // console.log(res.authSetting)
  806. // }
  807. // });
  808. // }
  809. // });
  810. // }
  811. // }
  812. // });
  813. },
  814. wechatLogin() {
  815. const that = this
  816. that.logining = true
  817. let loginType = 2
  818. uni.showLoading({
  819. title: '正在同步消息',
  820. mask:true
  821. })
  822. uni.login({
  823. provider: 'weixin',
  824. success: (wxres => {
  825. that.$api.request('user', 'thirdPartLogin', {
  826. loginType: loginType,
  827. raw: JSON.stringify(wxres)
  828. }, failres => {
  829. that.$api.msg(failres.errmsg)
  830. uni.hideLoading()
  831. }).then(res => {
  832. console.log("thirdPartLogin:"+res.data.phone)
  833. that.accessToken = res.data.accessToken
  834. that.logining = false
  835. uni.getUserInfo({
  836. lang: 'zh_CN',
  837. success: (e) => {
  838. uni.setStorageSync('userInfo', res.data)
  839. that.$store.commit('login', res.data)
  840. e.userInfo.nickname = e.userInfo.nickName
  841. e.userInfo.cid = uni.getStorageSync("clientId")
  842. console.log(e.userInfo)
  843. that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
  844. //同步过后
  845. res.data.nickname = e.userInfo.nickName
  846. res.data.avatarUrl = e.userInfo.avatarUrl
  847. res.data.gender = e.userInfo.gender
  848. if(res.data.phone){
  849. res.data.phone = e.userInfo.phone
  850. // that.liangxinLogin()
  851. }
  852. uni.setStorageSync('userInfo', res.data)
  853. that.$store.commit('login', res.data)
  854. })
  855. },
  856. complete: (e) => {
  857. uni.hideLoading()
  858. if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
  859. that.isPhone = true//显示自定义的获取手机权限提示框
  860. that.inputStatus = 'inline'
  861. that.inputContent = ''
  862. }
  863. else{
  864. // uni.switchTab({
  865. // url: '/pages/sale/sale'
  866. // });
  867. uni.switchTab({
  868. url: '/pages/sale/information'
  869. });
  870. console.log("complete")
  871. }
  872. }
  873. })
  874. })
  875. })
  876. })
  877. },
  878. wechatH5Login() {
  879. const that = this
  880. let href = window.location.origin
  881. let page = that.$api.prePage()
  882. let prePath = '/pages/index/index'
  883. if (page) {
  884. prePath = page.__page__.path
  885. }
  886. window.location = 'https://open.weixin.qq.com/connect/oauth2/authorize?'
  887. + 'appid=' + that.$api.defConfig().h5Appid + '&redirect_uri=' + escape(href) + '&response_type=code&scope=snsapi_userinfo&state=' + escape(prePath) + '#wechat_redirect'
  888. },
  889. liangxinLogin(){
  890. const that = this
  891. var userInfoTmp = uni.getStorageSync("userInfo")
  892. console.log('userInfoTmp',userInfoTmp)
  893. that.$socket.login(userInfoTmp.phone, "123456", null, res=>{
  894. console.log('粮信登录',res)
  895. if (res.success) {
  896. that.$socket.showLoginDialog = false
  897. // 缓存用户
  898. that.userData = res.response.data
  899. console.log('userData',that.userData)
  900. that.$u.vuex("userData", that.userData);
  901. // 缓存通讯录
  902. that.$socket.listGuests(that.userData.user.operId, res => {
  903. // #ifdef APP-PLUS
  904. createFSQL(that.userData.user.operId).then();
  905. let contact = res.response.data;
  906. contact.forEach(c=>{
  907. c.members.forEach(m=>{
  908. m.name = c.name;
  909. addFSQL(m, that.userData.user.operId).then();
  910. })
  911. })
  912. // #endif
  913. that.$u.vuex('firendItem', res.response.data)
  914. });
  915. // 缓存消息列表
  916. that.$socket.queryOnlineMessage(that.userData.user.operId,q =>{
  917. let data = q.response.data;
  918. for(var i in data){
  919. initData(data[i].groupMsg.list, data[i].groupInfo.chatId);
  920. }
  921. })
  922. // 缓存链接
  923. that.$socket.getLinks(that.userData.user.operId, res=>{
  924. that.$u.vuex('linkItem',res.response.data)
  925. });
  926. // // 跳转到消息列表
  927. // that.$u.route({
  928. // url: 'pages/home/home',
  929. // type: 'switchTab'
  930. // });
  931. } else {
  932. uni.showModal({
  933. title:res.reason + ",请稍后再试",
  934. showCancel:false
  935. })
  936. }
  937. });
  938. }
  939. },
  940. }
  941. </script>
  942. <style lang='scss' scoped>
  943. .password{
  944. border:none;
  945. outline: none;
  946. }
  947. .apple{
  948. background: #000;
  949. width: 35px;
  950. height: 35px;
  951. padding: 8px;
  952. border-radius: 50%;
  953. vertical-align: middle;
  954. }
  955. page {
  956. background: #fff;
  957. }
  958. .cuIcon-weixin{
  959. background: #39b54a;
  960. color: #fff;
  961. font-size: 18px;
  962. padding: 9px;
  963. border-radius: 50%;
  964. vertical-align: middle;
  965. margin-right:5px;
  966. }
  967. .container {
  968. padding-top: 85px;
  969. position: relative;
  970. width: 100vw;
  971. height: 100vh;
  972. overflow: hidden;
  973. background: url('~@/static/img/login/bg.png');
  974. background-size:100%;
  975. }
  976. .close{
  977. width:20px;height:20px;position:absolute;
  978. right:0px;
  979. }
  980. .close1{
  981. width:20px;height:20px;position:absolute;
  982. right:10px;
  983. top:0;
  984. }
  985. .close2{
  986. width: 15px;
  987. height: 15px;
  988. position: absolute;
  989. right: 19px;
  990. top: 50%;
  991. transform: translateY(-45%);
  992. }
  993. .wrapper {
  994. position: relative;
  995. z-index: 90;
  996. padding-bottom: 40upx;
  997. height:100%;
  998. padding:0 30px;
  999. }
  1000. .back-btn {
  1001. position: absolute;
  1002. left: 40upx;
  1003. z-index: 9999;
  1004. padding-top: var(--status-bar-height);
  1005. top: 40upx;
  1006. font-size: 40upx;
  1007. color: $font-color-dark;
  1008. }
  1009. .verificationCode{
  1010. margin-top:20px;
  1011. background:#F5F6F9;
  1012. color:#AFB3BF;
  1013. }
  1014. .verificationCode:after{
  1015. border:none;
  1016. }
  1017. .register{
  1018. position:absolute;
  1019. bottom:20px;
  1020. left:50%;
  1021. transform: translateX(-50%);
  1022. color:#333333;
  1023. height:50px;
  1024. line-height:50px;
  1025. border-radius:30px;border: 1px solid #444444;
  1026. }
  1027. .register:after{
  1028. border:none;
  1029. }
  1030. .verificationCode.active{
  1031. background:#22C572;
  1032. color:#fff;
  1033. }
  1034. .getcode{
  1035. font-size:14px;
  1036. position:absolute;
  1037. right:0;
  1038. top:50%;
  1039. transform: translateY(-50%);
  1040. color:#AFB3BF;
  1041. background:#F5F6F9;
  1042. height:30px;
  1043. line-height:30px;
  1044. }
  1045. .getcode:after{
  1046. border:none;
  1047. }
  1048. uni-navigator{
  1049. display:inline-block;
  1050. color:#22C572;
  1051. }
  1052. .getcode.active{
  1053. background:#22C572;
  1054. color:#fff;
  1055. }
  1056. </style>