login_account_number.vue 27 KB

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