login_account_number.vue 26 KB

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