login.vue 30 KB

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