login.vue 25 KB

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