login_account_number.vue 26 KB

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