12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091 |
- <template>
- <view class="container">
- <view class="left-bottom-sign"></view>
- <view class="back-btn yticon icon-zuojiantou-up" @click="navBack"></view>
- <view class="right-top-sign"></view>
- <!-- 设置白色背景防止软键盘把下部绝对定位元素顶上来盖住输入框等 -->
- <view class="wrapper">
- <view class="left-top-sign">LOGIN</view>
- <view class="welcome">
- 欢迎回来!
- </view>
- <!-- <button v-if="!loginType" class="confirm-btn" @click="chooseLoginType('wechat')" :disabled="logining">微信快速登录(推荐)</button>
- <button v-if="!loginType" class="confirm-btn" @click="chooseLoginType('phone')" :disabled="logining">手机注册登录</button> -->
- <!-- #ifdef MP-WEIXIN -->
- <!-- 旧版本方式 -->
- <block v-if="canIUseProfile==false" >
- <button v-if="loginType === 'wechat'" class="confirm-btn" open-type="getUserInfo" @getuserinfo="miniWechatLogin"
- :disabled="logining">微信授权登录</button>
- </block>
- <!-- 新版本方式 -->
- <block v-else>
- <button v-if="loginType === 'wechat'" class="confirm-btn" @tap="miniWechatLogin"
- :disabled="logining" >微信授权登录</button>
- </block>
- <!-- #endif -->
- <!-- #ifdef APP-PLUS -->
- <block v-if="isApple">
- <button v-if="loginType === 'wechat'" class="confirm-btn" @click="wechatLogin" :disabled="logining">微信授权登录</button>
- <button v-if="loginType === 'wechat' && isApple && platform == 'ios' && system >= '13'" class="confirm-btn" @click="appleLogin" :disabled="logining">通过Apple登录</button>
- </block>
- <block v-else>
- <view class="input-content">
- <view class="cu-form-group">
- <view class="title"><text class="cuIcon-my"></text></view>
- <input placeholder="请输入用户名" v-model="phone" name="input" ></input>
- </view>
- <view class="cu-form-group">
- <view class="title"><text class="cuIcon-lock"></text></view>
- <input placeholder="请输入登录密码" password v-model="password" name="input" ></input>
- </view>
- <view style='padding:0;' class="cu-form-group">
- <view></view>
- <view @click='forgetpass'>忘记登录密码?</view>
- </view>
- <button style='width:100%;' @click='phonelogin' class="cu-btn bg-gradual-green">登录</button>
- </view>
- <!-- <view style=' position: fixed;bottom: 9px;width: 100%;text-align-last: center;'>
- <text @click="wechatLogin" class="cuIcon-weixin"></text>
- <image class='apple' src="https://taohaoliang.oss-cn-beijing.aliyuncs.com/tmp/apple.png" @click="appleLogin" alt=""></image>
- </view> -->
- </block>
- <!-- #endif -->
- <!-- #ifdef H5 -->
- <button v-if="loginType === 'wechat'" class="confirm-btn" @click="wechatH5Login" :disabled="logining">微信授权登录</button>
- <button v-if="loginType === 'wechat' && isApple && platform == 'ios' && system >= '13'" class="confirm-btn" @click="appleLogin" :disabled="logining">通过Apple登录</button>
- <!-- #endif -->
- <button v-if="loginType === 'phone'" class="confirm-btn" @click="toLogin" :disabled="logining">登录</button>
- <view v-if="loginType === 'phone'" class="forget-section">
- 忘记密码?
- </view>
- <!-- #ifdef MP-WEIXIN -->
- <div v-if="isPhone" class="alert" >
- <div class="auth">
- <div class="apply">
- <span class="">需要获取您的手机权限</span>
- <p>(请开启手机权限)</p>
- </div>
- <button class="confirm" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">确认</button>
- </div>
- </div>
- <!-- #endif -->
- <!-- #ifdef APP-PLUS -->
- <neil-modal
- :show="isPhone"
- @close="cancel"
- :style="{display:inputStatus}"
- title="绑定手机号"
- showConfirm="true"
- showCancel="true"
- @confirm="confirm"
- >
- <view class="cu-form-group">
- <input v-model="inputContent" style="margin:20upx;" type="mobile" placeholder="请输入手机号" />
- </view>
- <view class="cu-form-group">
- <view class="title">验证码</view>
- <input type="mobile" value="" placeholder="6位验证码" maxlength="6"
- data-key="verifyCode" @input="verifyCodeInput" style="width: 60%;"></input>
- <button class='cu-btn bg-green shadow':disabled="sendDisabled" @click="doGetVerify">{{sendText}}</button>
- </view>
- </neil-modal>
- <!-- #endif -->
- </view>
- <view v-if="loginType === 'phone'" class="register-section">
- 还没有账号?
- <text @click="toRegist">马上注册</text>
- </view>
- </view>
- </template>
- <script>
- import {
- mapMutations
- } from 'vuex';
- import { openFSqlite, createFSQL, selectFSQL, addFSQL } from '../../util/f.js'
- import { queryData, upData, initData } from '../../util/dbUtil.js'
- export default {
- data() {
- return {
- inputContent: null,
- loginType: "wechat",
- phone: '',
- password: '',
- logining: false,
- isPhone: false,
- isApple: true,
- accessToken:'',
- params:{
- encryptedData:'',
- session_key:'',
- iv:'',
- },
- userInfo:{
- nickName:'',
- avatarUrl:'',
- gender:'',
- phone:''
- },
- inputStatus:'none',
- verifyCode:null,
- sendText:'获取验证码',
- sendDisabled: false,
- system:'',
- platform:'',
- userData:undefined,
- canIUseProfile:false
- }
- },
- onShow() {
- // this.loginType = "wechat"
- this.$api.logout()
- },
- onLoad(options) {
-
- if( wx.getUserProfile ){
- console.log('--check getUserProfile--OK');
- this.canIUseProfile = true;
- }
- console.log("login on load")
- var that = this
- that.$api.request('user', 'sendIsApple', {
- }).then(res => {
- that.isApple = res.data
- })
- uni.getSystemInfo({
- success:(res) => {
- // console.log(res)
- this.system = res.system // ios
- this.platform = res.platform // 14.3
- }
- })
- },
- methods: {
- forgetpass(){
- uni.navigateTo({
- url:'/pages/public/reset'
- })
- },
- phonelogin(){
- var that=this
- uni.showLoading({
- title: '登录中'
- })
- console.log("clientid",clientId)
- this.$api.request('user', 'login',{
- password:that.password,
- phone:that.phone,
- cid:clientId
- }, failres => {
- that.$api.msg(failres.errmsg)
- uni.hideLoading()
- }).then(res => {
- console.log(res)
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- that.liangxinLogin()
- uni.switchTab({
- url: '/pages/sale/information'
- });
- uni.hideLoading()
- })
- },
- appleLogin(){
- var that=this
- uni.getProvider({
- service: 'oauth',
- success: function (res) {
- // console.log(res.provider)
- if(~res.provider.indexOf('apple')) {
- uni.login({
- provider: 'apple',
- success: loginRes => {
- uni.getUserInfo({
- provider: 'apple',
- success: userInfoRes => {
-
- that.$api.request('user', 'thirdPartLogin', {
- loginType: 4/* */,
- raw: JSON.stringify(userInfoRes.userInfo)
- }, failres => {
- that.$api.msg(failres.errmsg)
- uni.hideLoading()
- }).then(res => {
- console.log("thirdPartLogin:"+res.data.phone)
- that.accessToken = res.data.accessToken
- that.logining = false
- uni.getUserInfo({
- lang: 'zh_CN',
- success: (e) => {
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- e.userInfo.nickname = e.userInfo.nickName
- e.userInfo.cid = uni.getStorageSync("clientId")
- that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
- //同步过后
- res.data.nickname = e.userInfo.nickName
- res.data.avatarUrl = e.userInfo.avatarUrl
- res.data.gender = e.userInfo.gender
-
- if(!res.data.phone){
- res.data.phone = e.userInfo.phone
- }
-
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- })
- },
- complete: (e) => {
- uni.hideLoading()
-
- if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
- that.isPhone = true//显示自定义的获取手机权限提示框
- that.inputStatus = 'inline'
- that.inputContent = ''
- }
- else{
- uni.switchTab({
- url: '/pages/sale/sale'
- });
- console.log("complete")
- }
- }
- })
-
- })
- console.log('获取用户信息成功'+JSON.stringify(userInfoRes))
- }
- })
- },
- fail: err => {
- console.log('apple登录失败' + JSON.stringify(err))
- uni.showToast({
- title:'登录失败',
- icon:'none'
- })
- }
- })
- }
- },
- fail: err => {
- uni.showToast({
- title:'登录失败',
- icon:'none'
- })
- }
- })
- },
- doGetVerify() {
- const that = this
- var phone = this.inputContent;
- if (!phone || phone.length != 11) {
- uni.showToast({
- title:'请输入正确手机号!',
- icon:'none'
- })
- return
- }
-
- that.$api.request('user', 'sendVerifyCode', {
- phone: phone,
- }).then(res => {
- that.sendDisabled = true
- let sec = 60
- let interval = setInterval(() => {
- sec--;
- that.sendText = sec + 's后重发'
- if (sec <= 0) {
- that.sendDisabled = false
- that.sendText = "获取验证码"
- clearInterval(interval)
- }
- }, 1000)
- })
-
- },
- verifyCodeInput(e){
- this.verifyCode = e.detail.value
- },
- cancel() {
- this.inputShow = false
- this.inputStatus = 'none'
- this.isPhone = false
- },
- confirm() {
- var that = this
- if (!this.inputContent || this.inputContent.length != 11) {
- uni.showToast({
- title:'请输入正确手机号!',
- icon:'none'
- })
- return
- }
- if (!this.verifyCode) {
- uni.showToast({
- title:'请输入验证码!',
- icon:'none'
- })
- return
- }
- this.$api.request('user', 'mergeUser', {
- phone: that.inputContent,
- verifyCode:that.verifyCode
- },failres => {
- that.$api.msg(failres.errmsg)
- uni.hideLoading()
- }).then(res => {
- that.accessToken = res.data.accessToken
- that.$api.setUserInfo(res.data)
- that.logining = false
- uni.getUserInfo({
- lang: 'zh_CN',
- success: (e) => {
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- e.userInfo.nickname = e.userInfo.nickName
- e.userInfo.cid = uni.getStorageSync("clientId")
- console.log(e.userInfo)
- that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
- //同步过后
- res.data.nickname = e.userInfo.nickName
- res.data.avatarUrl = e.userInfo.avatarUrl
- res.data.gender = e.userInfo.gender
- res.data.phone = e.userInfo.phone
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- that.liangxinLogin()
- })
- },
- complete: (e) => {
- uni.switchTab({
- url: '/pages/sale/information'
- });
- uni.hideLoading()
- that.isPhone=false
-
- uni.navigateBack()
- }
- })
- })
-
- },
- ...mapMutations(['login']),
- inputChange(e) {
- const key = e.currentTarget.dataset.key;
- this[key] = e.detail.value;
- },
- chooseLoginType(type) {
- this.loginType = type
- },
- navBack() {
- uni.navigateBack();
- },
- toRegist() {
- uni.redirectTo({
- url: '/pages/public/register'
- })
- },
- ///发起消息订阅
- requestSubscribe(){
- const that = this
- wx.requestSubscribeMessage({
- tmplIds: ['xL_uZEqJz4QP1FbnlzQWAiO2zVBn3Qeu8JwLVOU3hU0','8cVkckXi_8zfHeScXRHhjN6cgZFYYCWIMPDTiPWagXY','IE7WxBsv-fDvPWSrng-97lGWtvZf9rHuECBlhRLlWxI'],//
- success :(res)=>{
- console.log("订阅消息 成功 "+res);
- },
- fail :(errMsg) =>{
- console.log("订阅消息 失败 "+errMsg.errMsg);
- },
- complete:(errMsg)=>{
- console.log("订阅消息 完成 "+errMsg);
-
- }
-
- });
- },
- getPhoneNumber(e) {
-
- console.log(e)
- if (e.mp.detail.errMsg==="getPhoneNumber:ok") {
- this.isPhone = false
- this.params.iv = e.mp.detail.iv
- this.params.encryptedData = e.mp.detail.encryptedData
- this.params.session_key = this.accessToken
- console.log(this.params)
- this.getTokenAsync(this.params)
- }
-
- },
- // 请求后获取token
- async getTokenAsync(params) {
- let that = this
- this.$api.request('user', 'getPhoneNumber', params).then(res => {
- if(res.data.phoneNumber){
- that.userInfo.phone = res.data.phoneNumber
- }
- if(res.data.unionId){
- that.userInfo.unionId = res.data.unionId
- }
-
- that.userInfo.cid = uni.getStorageSync("clientId")
- console.log(that.userInfo)
- that.$api.request('user', 'syncUserInfo', that.userInfo).then(syncRes => {
- uni.setStorageSync('userInfo', that.userInfo)
- that.$store.commit('login', that.userInfo)
- that.$api.setUserInfo(that.userInfo)
- uni.hideLoading()
- that.liangxinLogin()
- })
- if(res.data.phoneNumber){
- uni.switchTab({
- url: '/pages/sale/information'
- });
- }
-
- })
- },
- async toLogin() {
- this.verifyCode = ''
- const that = this
- if (that.phone.length !== 11) {
- that.$api.msg('请输入11位中国手机号')
- } else if (that.password.length < 8) {
- that.$api.msg('密码至少8位')
- } else {
- that.logining = true;
- //#ifdef MP-WEIXIN
- //若是小程序平台,则获取到openId。整个过程是静默完成的
- uni.login({
- provider: 'weixin',
- success: (wxres => {
- that.$api.request('user', 'login', {
- phone: that.phone,
- password: that.password,
- loginType: 1,
- raw: JSON.stringify(wxres)
- }, failres => {
- that.logining = false
- uni.showToast({
- title: failres.errmsg,
- icon: "none"
- });
- }).then(res => {
- that.logining = false
- that.$store.commit('login', res.data)
- uni.setStorageSync('userInfo', res.data)
- if (that.$api.prePage().lodaData) {
- that.$api.prePage().loadData()
- }
- uni.navigateBack()
- })
- })
- })
- //#endif
- //#ifdef APP-PLUS || H5
- //若是App登录,则不需要保存OpenId。可直接登录
- that.$api.request('user', 'login', {
- phone: that.phone,
- password: that.password,
- }, failres => {
- that.logining = false
- uni.showToast({
- title: failres.errmsg,
- icon: "none"
- });
- }).then(res => {
- that.logining = false
- that.$store.commit('login', res.data)
- uni.setStorageSync('userInfo', res.data)
- if (that.$api.prePage().lodaData) {
- that.$api.prePage().loadData()
- }
- uni.navigateBack()
- })
- //#endif
- }
- },
-
- miniWechatLogin(e) {
- const that = this
- //旧版本方式
- if( this.canIUseProfile == false ){
- console.log("旧版本方式")
- //获取授权信息
- if(e.detail.userInfo){
-
- console.log('用户允许了授权')
- console.log( e.detail.userInfo ); //1.拿到基本的微信信息!!
-
- uni.showLoading({
- title: '加载中'
- })
- that.logining = true
- let loginType = 1
- let userInfo = e.detail.userInfo
- uni.login({
- provider: 'weixin',
- success: (wxres => {
- that.logining = false
- that.$api.request('user', 'thirdPartLogin', {
- loginType: loginType,
- raw: JSON.stringify(wxres)
- }, failres => {
- that.$api.msg(failres.errmsg)
- uni.hideLoading()
- }).then(res => {
- that.accessToken = res.data.accessToken
- that.$api.setUserInfo(res.data)
- that.userInfo = res.data
- uni.getUserInfo({
- lang: 'zh_CN',
- provider: 'weixin',
- withCredentials:true,
- success: (e) => {
- that.params.iv = e.iv
- that.params.encryptedData = e.encryptedData
- that.params.session_key = that.accessToken
- console.log(this.params)
- that.getTokenAsync(this.params)
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- e.userInfo.nickname = e.userInfo.nickName
- if(e.userInfo.phone == undefined){
- e.userInfo.phone = ''
- }
- e.userInfo.cid = uni.getStorageSync("clientId")
- console.log(e.userInfo)
- that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
- //同步过后
- res.data.nickname = userInfo.nickName
- res.data.avatarUrl = userInfo.avatarUrl
- res.data.gender = userInfo.gender
- if(userInfo.phone){
- res.data.phone = userInfo.phone
- that.liangxinLogin()
- }
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- that.$api.setUserInfo(res.data)
-
- uni.hideLoading()
- // uni.navigateBack()
- })
- },
- complete: (e) => {
- uni.hideLoading()
-
- if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
- that.isPhone = true//显示自定义的获取手机权限提示框
- that.inputStatus = 'inline'
- that.inputContent = ''
- }
- else{
- uni.setStorageSync('PageCur', "sale");
- // uni.switchTab({
- // url: '/pages/sale/sale'
- // });
- uni.switchTab({
- url: '/pages/sale/information'
- });
- console.log("complete")
- }
- }
- })
- })
- }),
-
- })
-
- }
-
- //新版本方式
- }else{
- console.log("新版本方式")
- uni.showLoading({
- title: '加载中'
- })
- that.logining = true
- let loginType = 1
- wx.getUserProfile({
- desc : '用于完善用户资料',
- lang : 'zh_CN',
- success : function( proRes ){
- console.log('proRes.userInfo',proRes.userInfo)
- uni.login({
- provider: 'weixin',
- success: (wxres => {
- that.logining = false
- that.$api.request('user', 'thirdPartLogin', {
- loginType: loginType,
- raw: JSON.stringify(wxres)
- }, failres => {
- that.$api.msg(failres.errmsg)
- uni.hideLoading()
- }).then(res => {
- console.log('res+++++',res)
- that.accessToken = res.data.accessToken
- that.$api.setUserInfo(res.data)
- that.userInfo = res.data
- // that.params.iv = proRes.iv
- // that.params.encryptedData = proRes.encryptedData
- // that.params.session_key = that.accessToken
- // console.log(that.params)
- // that.getTokenAsync(that.params)
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- if(proRes.userInfo.phone == undefined){
- proRes.userInfo.phone = ''
- }
- res.data.cid = uni.getStorageSync("clientId")
- that.$api.request('user', 'syncUserInfo', res.data).then(syncRes => {
- //同步过后
- res.data.nickname = proRes.userInfo.nickName
- res.data.avatarUrl = proRes.userInfo.avatarUrl
- res.data.gender = proRes.userInfo.gender
- if(proRes.userInfo.phone){
- res.data.phone = proRes.userInfo.phone
- }
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- that.$api.setUserInfo(res.data)
- uni.hideLoading()
- if(!that.userInfo.phone||that.userInfo.phone==""||that.userInfo.phone ==undefined){
- that.isPhone = true//显示自定义的获取手机权限提示框
- that.inputStatus = 'inline'
- that.inputContent = ''
- }
- else{
- uni.setStorageSync('PageCur', "sale");
- // uni.switchTab({
- // url: '/pages/sale/sale'
- // });
- uni.reLaunch({
- url: '/pages/sale/information'
- });
- console.log("complete")
- that.liangxinLogin()
- }
- })
- console.log( 'wx.getUserProfile=>用户允许了授权' );
- })
- })
- })
-
- },
- fail : function( res ){
- console.log('wx.getUserProfile=>用户拒绝了授权');
- console.log( res );
-
- }
- });
-
- }
-
- // 获取用户的当前设置,判断是否点击了“总是保持以上,不在询问”
- // wx.getSetting({
- // withSubscriptions: true,//是否获取用户订阅消息的订阅状态,默认false不返回
- // success(res){
- // debugger
- // if(res.subscriptionsSetting.mainSwitch){
-
- // }else{
-
- // }
- // }
- // })
- // uni.showModal({
- // title: '温馨提示',
- // content: '为更好的与您沟通,小程序需要向您发送通知消息',
- // confirmText:"同意",
- // cancelText:"拒绝",
- // showCancel: false,
- // success: function (res) {
- // if (res.confirm) {
- // //调用订阅消息
- // that.requestSubscribe();
- // } else if (res.cancel) {
- // ///显示第二个弹说明一下
- // wx.showModal({
- // title: '温馨提示',
- // content: '拒绝后您将无法获取实时的交易、物流消息',
- // confirmText:"知道了",
- // showCancel:false,
- // success: function (res) {
- // uni.openSetting({ // 打开设置页
- // success(res) {
- // console.log(res.authSetting)
- // }
- // });
- // }
- // });
- // }
- // }
- // });
-
-
- },
- wechatLogin() {
- const that = this
- that.logining = true
- let loginType = 2
- uni.showLoading({
- title: '正在同步消息'
- })
- uni.login({
- provider: 'weixin',
- success: (wxres => {
- that.$api.request('user', 'thirdPartLogin', {
- loginType: loginType,
- raw: JSON.stringify(wxres)
- }, failres => {
- that.$api.msg(failres.errmsg)
- uni.hideLoading()
- }).then(res => {
- console.log("thirdPartLogin:"+res.data.phone)
- that.accessToken = res.data.accessToken
- that.logining = false
- uni.getUserInfo({
- lang: 'zh_CN',
- success: (e) => {
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- e.userInfo.nickname = e.userInfo.nickName
- e.userInfo.cid = uni.getStorageSync("clientId")
- console.log(e.userInfo)
- that.$api.request('user', 'syncUserInfo', e.userInfo).then(syncRes => {
- //同步过后
- res.data.nickname = e.userInfo.nickName
- res.data.avatarUrl = e.userInfo.avatarUrl
- res.data.gender = e.userInfo.gender
- if(res.data.phone){
- res.data.phone = e.userInfo.phone
- that.liangxinLogin()
- }
-
- uni.setStorageSync('userInfo', res.data)
- that.$store.commit('login', res.data)
- })
- },
- complete: (e) => {
- uni.hideLoading()
-
- if(!res.data.phone||res.data.phone==""||res.data.phone ==undefined){
- that.isPhone = true//显示自定义的获取手机权限提示框
- that.inputStatus = 'inline'
- that.inputContent = ''
- }
- else{
- // uni.switchTab({
- // url: '/pages/sale/sale'
- // });
- uni.switchTab({
- url: '/pages/sale/information'
- });
- console.log("complete")
-
- }
-
- }
- })
-
- })
- })
- })
- },
- wechatH5Login() {
- const that = this
- let href = window.location.origin
- let page = that.$api.prePage()
- let prePath = '/pages/index/index'
- if (page) {
- prePath = page.__page__.path
- }
- window.location = 'https://open.weixin.qq.com/connect/oauth2/authorize?'
- + 'appid=' + that.$api.defConfig().h5Appid + '&redirect_uri=' + escape(href) + '&response_type=code&scope=snsapi_userinfo&state=' + escape(prePath) + '#wechat_redirect'
- },
- liangxinLogin(){
- const that = this
- var userInfoTmp = uni.getStorageSync("userInfo")
- console.log('userInfoTmp',userInfoTmp)
- that.$socket.login(userInfoTmp.phone, "123456", null, res=>{
- console.log('粮信登录',res)
- if (res.success) {
- that.$socket.showLoginDialog = false
- // 缓存用户
- that.userData = res.response.data
- console.log('userData',that.userData)
- that.$u.vuex("userData", that.userData);
- // 缓存通讯录
- that.$socket.listGuests(that.userData.user.operId, res => {
- // #ifdef APP-PLUS
- createFSQL(that.userData.user.operId).then();
- let contact = res.response.data;
- contact.forEach(c=>{
- c.members.forEach(m=>{
- m.name = c.name;
- addFSQL(m, that.userData.user.operId).then();
- })
- })
- // #endif
- that.$u.vuex('firendItem', res.response.data)
- });
-
- // 缓存消息列表
- that.$socket.queryOnlineMessage(that.userData.user.operId,q =>{
- let data = q.response.data;
- for(var i in data){
- initData(data[i].groupMsg.list, data[i].groupInfo.chatId);
- }
- })
-
- // 缓存链接
- that.$socket.getLinks(that.userData.user.operId, res=>{
- that.$u.vuex('linkItem',res.response.data)
- });
-
-
- // // 跳转到消息列表
- // that.$u.route({
- // url: 'pages/home/home',
- // type: 'switchTab'
- // });
- } else {
- uni.showModal({
- title:res.reason + ",请稍后再试",
- showCancel:false
- })
- }
- });
- }
- },
- }
- </script>
- <style lang='scss' scoped>
- .apple{
- background: #000;
- width: 35px;
- height: 35px;
- padding: 8px;
- border-radius: 50%;
- vertical-align: middle;
- }
- page {
- background: #fff;
- }
- .cuIcon-weixin{
- background: #39b54a;
- color: #fff;
- font-size: 18px;
- padding: 9px;
- border-radius: 50%;
- vertical-align: middle;
- margin-right:5px;
- }
- .alert{
- position: fixed;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- overflow: hidden;
- outline: 0;
- -webkit-overflow-scrolling: touch;
- background-color: rgb(0, 0, 0);
- filter: alpha(opacity=60);
- background-color: rgba(0, 0, 0, 0.6);
- z-index: 9999;
- .auth{
- position: absolute;
- top: 50%;
- left: 50%;
- width: 80%;
- height: 340rpx;
- border-radius: 20rpx;
- transform:translate(-50%,-50%);
- background: #fff;
- display: flex;
- flex-direction: column;
- .apply{
- margin: 0rpx auto;
- padding: 60rpx 40rpx;
- flex:1;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: space-between;
- font-size: 34rpx;
- color:rgb(34,34,34);
- p{
- font-size:30rpx
- }
- }
- .confirm{
- border-top: 1rpx solid rgb(221,221,221);
- text-align: center;
- height: 100rpx;
- width: 100%;
- line-height: 100rpx;
- font-size: 34rpx;
- color:rgb(255,145,37);
- }
- }
- }
- .container {
- padding-top: 115px;
- position: relative;
- width: 100vw;
- height: 100vh;
- overflow: hidden;
- background: #fff;
- }
- .wrapper {
- position: relative;
- z-index: 90;
- background: #fff;
- padding-bottom: 40upx;
- height:100%;
- }
- .back-btn {
- position: absolute;
- left: 40upx;
- z-index: 9999;
- padding-top: var(--status-bar-height);
- top: 40upx;
- font-size: 40upx;
- color: $font-color-dark;
- }
- .left-top-sign {
- font-size: 120upx;
- color: $page-color-base;
- position: relative;
- left: -16upx;
- }
- .right-top-sign {
- position: absolute;
- top: 80upx;
- right: -30upx;
- z-index: 95;
- &:before,
- &:after {
- display: block;
- content: "";
- width: 400upx;
- height: 80upx;
- background: #b4f3e2;
- }
- &:before {
- transform: rotate(50deg);
- border-radius: 0 50px 0 0;
- }
- &:after {
- position: absolute;
- right: -198upx;
- top: 0;
- transform: rotate(-50deg);
- border-radius: 50px 0 0 0;
- /* background: pink; */
- }
- }
- .left-bottom-sign {
- position: absolute;
- left: -270upx;
- bottom: -320upx;
- border: 100upx solid #d0d1fd;
- border-radius: 50%;
- padding: 180upx;
- }
- .welcome {
- position: relative;
- left: 50upx;
- top: -90upx;
- font-size: 46upx;
- color: #555;
- text-shadow: 1px 0px 1px rgba(0, 0, 0, .3);
- }
- .input-content {
- padding: 0 60upx;
- }
- .input-item {
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- justify-content: center;
- padding: 0 30upx;
- background: $page-color-light;
- height: 120upx;
- border-radius: 4px;
- margin-bottom: 50upx;
- &:last-child {
- margin-bottom: 0;
- }
- .tit {
- height: 50upx;
- line-height: 56upx;
- font-size: $font-sm+2upx;
- color: $font-color-base;
- }
- input {
- height: 60upx;
- font-size: $font-base + 2upx;
- color: $font-color-dark;
- width: 100%;
- }
- }
- .confirm-btn {
- width: 630upx;
- height: 76upx;
- line-height: 76upx;
- border-radius: 50px;
- margin-top: 70upx;
- background: $uni-color-primary;
- color: #fff;
- font-size: $font-lg;
- &:after {
- border-radius: 100px;
- }
- }
- .forget-section {
- font-size: $font-sm+2upx;
- color: $font-color-spec;
- text-align: center;
- margin-top: 40upx;
- }
- .register-section {
- position: absolute;
- left: 0;
- bottom: 50upx;
- width: 100%;
- font-size: $font-sm+2upx;
- color: $font-color-base;
- text-align: center;
- text {
- color: $font-color-spec;
- margin-left: 10upx;
- }
- }
- </style>
|