login_account_number.vue 25 KB

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