login_account_number.vue 26 KB

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