Browse Source

add api getUserProfile

voice
刘嘉炜 4 years ago
parent
commit
6b4e8f9a40
  1. 29
      src/pages/admin_bind/admin_bind.vue
  2. 25
      src/pages/employee/perfect_info/perfect_info.vue
  3. 90
      src/pages/index/index.vue
  4. 23
      src/pages/login/login.vue
  5. 9
      src/utils/util.js

29
src/pages/admin_bind/admin_bind.vue

@ -6,11 +6,19 @@
<view>请点击确认绑定按钮成为超级管理员</view> <view>请点击确认绑定按钮成为超级管理员</view>
<view>绑定后您将可以添加员工并查看品牌订单数据</view> <view>绑定后您将可以添加员工并查看品牌订单数据</view>
<button <button
v-if="isProfile"
plain
hover-class="hover-active"
@click="getUserInfoProfile"
>确认绑定</button>
<button
v-else
plain plain
hover-class="hover-active" hover-class="hover-active"
open-type="getUserInfo" open-type="getUserInfo"
lang="zh_CN" lang="zh_CN"
@getuserinfo="getuserinfo">确认绑定</button>
@getuserinfo="getuserinfo"
>确认绑定</button>
</view> </view>
</template> </template>
@ -20,12 +28,15 @@ import { servers } from '../../js/server';
import util from '../../utils/util'; import util from '../../utils/util';
const uniLogin = util.promisify(uni.login); const uniLogin = util.promisify(uni.login);
export default { export default {
computed: {
isProfile: _=> util.isProfile(),
},
data(){ data(){
return { return {
brandInfo: {}, brandInfo: {},
sceneQuery: { sceneQuery: {
b:'37',
r:'1'
b:'',
r:''
}, },
} }
}, },
@ -44,6 +55,18 @@ export default {
}, },
methods: { methods: {
getUserInfoProfile(){
uni.getUserProfile({
lang: 'zh_CN', desc: '用户绑定',
success: res => {
this.getuserinfo({detail: {...res}});
},
fail: function(err) {
util.showNone('获取用户信息失败!请重试');
console.warn('getUserProfile Err', err)
}
})
},
async getuserinfo(userRes){ async getuserinfo(userRes){
if(!userRes.detail.userInfo){ if(!userRes.detail.userInfo){
return util.showNone('获取用户信息失败!请稍后重试'); return util.showNone('获取用户信息失败!请稍后重试');

25
src/pages/employee/perfect_info/perfect_info.vue

@ -19,7 +19,15 @@
<view><input v-model="userPhone" type="number" maxlength="11" /></view> <view><input v-model="userPhone" type="number" maxlength="11" /></view>
</view> </view>
</view> </view>
<button
v-if="isProfile"
class="pi-btn"
hover-class="hover-active"
@click="profileBtn"
>接受邀请</button>
<button <button
v-else
open-type="getUserInfo" open-type="getUserInfo"
lang="zh_CN" lang="zh_CN"
class="pi-btn" class="pi-btn"
@ -37,6 +45,9 @@ import { servers } from '../../../js/server';
import util from '../../../utils/util'; import util from '../../../utils/util';
const uniLogin = util.promisify(uni.login); const uniLogin = util.promisify(uni.login);
export default { export default {
computed: {
isProfile: _=> util.isProfile(),
},
data(){ data(){
return { return {
userName: '', userName: '',
@ -61,6 +72,18 @@ export default {
}, },
methods: { methods: {
profileBtn(){
uni.getUserProfile({
lang: 'zh_CN', desc: '用户绑定',
success: res => {
this.getuserinfo({detail: {...res}});
},
fail: function(err) {
util.showNone('获取用户信息失败!请重试');
console.warn('getUserProfile Err', err)
}
})
},
async getuserinfo(userRes){ async getuserinfo(userRes){
let { userName, userPhone, brand_id } = this; let { userName, userPhone, brand_id } = this;
@ -75,7 +98,7 @@ export default {
return util.showNone('获取登陆凭证失败!稍后重试'); return util.showNone('获取登陆凭证失败!稍后重试');
} }
const APPID = uni.getAccountInfoSync().miniProgram.appId; const APPID = uni.getAccountInfoSync().miniProgram.appId;
console.log(userRes)
let { sceneQuery } = this; let { sceneQuery } = this;
util.showLoad(); util.showLoad();
// //

90
src/pages/index/index.vue

@ -50,7 +50,15 @@
<image class="iam-pic" mode="aspectFit" src="/static/images/icon/author_modal.png"></image> <image class="iam-pic" mode="aspectFit" src="/static/images/icon/author_modal.png"></image>
<view class="iam-btns"> <view class="iam-btns">
<button plain hover-class="hover-active" @click="cancelAuthor">取消</button> <button plain hover-class="hover-active" @click="cancelAuthor">取消</button>
<button <button
v-if="isProfile"
plain
hover-class="hover-active"
@click="profileConfirm"
>授权并登录</button>
<button
v-else
plain plain
hover-class="hover-active" hover-class="hover-active"
open-type="getUserInfo" open-type="getUserInfo"
@ -131,6 +139,7 @@
//#endif //#endif
export default { export default {
computed: { computed: {
isProfile: _=>util.isProfile(),
// loginStatus(){ // loginStatus(){
// return app.isLogin(); // return app.isLogin();
// } // }
@ -140,7 +149,7 @@
tabList, tabList,
isShowAuthorModal: false, isShowAuthorModal: false,
indexData: {}, indexData: {},
loginStatus: app.isLogin()
loginStatus: false,
} }
}, },
async onLoad() { async onLoad() {
@ -149,6 +158,7 @@
util.showLoad(); util.showLoad();
await this.checkUserAuthor(); await this.checkUserAuthor();
util.hideLoad(); util.hideLoad();
this.loginStatus = app.isLogin();
if(!!app.isLogin())this.getIndexInfo(); if(!!app.isLogin())this.getIndexInfo();
}catch(err){ }catch(err){
util.hideLoad(); util.hideLoad();
@ -195,42 +205,36 @@
// token // token
async checkUserAuthor(){ async checkUserAuthor(){
try{ try{
let setting;
try{setting = await uniGetSetting({})}catch(err){console.error(err)};
if(setting&&setting.authSetting&&setting.authSetting['scope.userInfo'] === true){
let [ loginRes, userRes ] = await Promise.all([uniLogin(), uniGetUserInfo({lang: 'zh_CN'})]);
return servers.post({
url: API.wechatMiniAppLoginAndSync,
data: this.getLoginQuery({
userInfo: userRes,
loginRes
}),
isDefaultGet: false,
})
.then(res=>{
util.hideLoad();
let _data = res.data;
if(_data.code == 0){
// let _data = res.data.data;
if(_data.data == ''){
uni.removeStorageSync('token');
this.loginStatus = app.isLogin();
return util.routeTo(`/pages/login/login`,'rL');
}
uni.setStorageSync('token',_data.data);
return _data;
}else{
util.showNone(_data.message || '校验身份失败!');
throw res.data || {};
let loginRes = await uniLogin();
return servers.post({
url: API.wechatMiniAppLoginAndSync,
data: {
code: loginRes.code,
appid: APPID,
},
isDefaultGet: false,
})
.then(res=>{
util.hideLoad();
let _data = res.data;
if(_data.code == 0){
// let _data = res.data.data;
if(_data.data == ''){
uni.removeStorageSync('token');
this.loginStatus = app.isLogin();
return util.routeTo(`/pages/login/login`,'rL');
} }
})
.catch(err=>{
throw err;
})
}else{
throw 'author err';
}
uni.setStorageSync('token',_data.data);
return _data;
}else{
util.showNone(_data.message || '校验身份失败!');
throw res.data || {};
}
})
.catch(err=>{
throw err;
})
}catch(err){ }catch(err){
throw err; throw err;
} }
@ -259,6 +263,20 @@
...userInfo.userInfo, ...userInfo.userInfo,
} }
}, },
//
profileConfirm(){
uni.getUserProfile({
lang: 'zh_CN', desc: '授权登陆',
success: res => {
this.confirmAuthor({detail: {...res}});
},
fail: function(err) {
util.showNone('获取用户信息失败!请重试');
console.warn('getUserProfile Err', err)
}
})
},
async confirmAuthor(userRes){ async confirmAuthor(userRes){
if(!userRes.detail.userInfo){ if(!userRes.detail.userInfo){
this.closeAuthor(); this.closeAuthor();

23
src/pages/login/login.vue

@ -11,12 +11,20 @@
</view> </view>
<button <button
v-if="isProfile"
class="lf-btn"
hover-class="hover-active"
@click="profileSubmit"
>登录</button>
<button
v-else
class="lf-btn" class="lf-btn"
hover-class="hover-active" hover-class="hover-active"
open-type="getUserInfo" open-type="getUserInfo"
lang="zh_CN" lang="zh_CN"
@getuserinfo="submitBtn" @getuserinfo="submitBtn"
>登录</button> >登录</button>
<view class="lf-tip">提示请联系管理员添加您为员工账号</view> <view class="lf-tip">提示请联系管理员添加您为员工账号</view>
<view class="lf-bot-btn" @click="toWebView">成为商家</view> <view class="lf-bot-btn" @click="toWebView">成为商家</view>
@ -31,6 +39,9 @@ const uniGetSetting = util.promisify(uni.getSetting);
const uniLogin = util.promisify(uni.login); const uniLogin = util.promisify(uni.login);
const APPID = uni.getAccountInfoSync().miniProgram.appId; const APPID = uni.getAccountInfoSync().miniProgram.appId;
export default { export default {
computed: {
isProfile: _=> util.isProfile(),
},
data(){ data(){
return { return {
formData: { formData: {
@ -41,6 +52,18 @@ export default {
} }
}, },
methods: { methods: {
profileSubmit(){
uni.getUserProfile({
lang: 'zh_CN', desc: '用户绑定',
success: res => {
this.submitBtn({detail: {...res}});
},
fail: function(err) {
util.showNone('获取用户信息失败!请重试');
console.warn('getUserProfile Err', err)
}
})
},
async submitBtn(userRes){ async submitBtn(userRes){
try{ try{
util.showLoad(); util.showLoad();

9
src/utils/util.js

@ -330,6 +330,12 @@ function formatScene(sceneStr = ''){
},{}) || {}; },{}) || {};
} }
// 是否支持新的授权方式
function isProfile(){
return !!uni.getUserProfile
}
function changeLowerCase(str){ function changeLowerCase(str){
return str.toString().toLocaleLowerCase(); return str.toString().toLocaleLowerCase();
} }
@ -361,5 +367,6 @@ export default {
requestPayment, requestPayment,
getQueryStr, getQueryStr,
formatScene, formatScene,
changeLowerCase
changeLowerCase,
isProfile
} }
Loading…
Cancel
Save