register.vue 30 KB

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