login_account_number.vue 26 KB

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