login.vue 29 KB

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