login_account_number.vue 27 KB

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