register.vue 31 KB

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