login_account_number.vue 26 KB

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