login.vue 25 KB

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