login.vue 25 KB

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