register.vue 31 KB

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