login_account_number.vue 27 KB

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