Browse Source

add account login

voice
刘嘉炜 4 years ago
parent
commit
1bf8f91157
  1. 3
      src/js/api.js
  2. 5
      src/pages.json
  3. 95
      src/pages/index/index.vue
  4. 205
      src/pages/login/login.vue
  5. 33
      src/subpackage/device/pages/login/login.vue

3
src/js/api.js

@ -2,7 +2,8 @@ export const ORIGIN = `http://testmanager.ouxuanzhineng.cn`; // 测试
// export const ORIGIN = `https://minimanage.ouxuanzhineng.cn`; // 正式
export const API = {
wechatMiniAppLoginAndSync: `${ORIGIN}/user/wechatMiniAppLoginAndSync`, // 小程序授权
wechatMiniAppLoginAndSync: `${ORIGIN}/assistant/WechatMiniAppGetToken`, // 小程序授权获取token,为空就登录
WechatMiniApplogin: `${ORIGIN}/assistant/WechatMiniApplogin`, // 小程序登录获取token
brandInfo: `${ORIGIN}/stadium/brand/get`, // 品牌信息
assistantAuth: `${ORIGIN}/assistant/auth`, // 授权绑定 - 获取用户信息
calc: `${ORIGIN}/admin/assistant/calc`, // 首页 统计页面

5
src/pages.json

@ -6,6 +6,11 @@
}
},
{
"path": "pages/login/login",
"style": {
}
},
{
"path": "pages/site/order_list/order_list",
"style": {
"navigationBarTitleText": "我的预约订单列表"

95
src/pages/index/index.vue

@ -2,21 +2,21 @@
<view class="index-container">
<view class="ic-content">
<view class="ic-header">
<view class="ih-address" v-if="isLogin" @click="toStoreList">
<view class="ih-address" v-if="loginStatus" @click="toStoreList">
<view>{{indexData.brand_name || '-'}}({{indexData.stadium_num || '0'}})</view>
<image src="/static/images/icon/arrow_ff.png" mode="aspectFit"></image>
</view>
<view v-else class="ih-btn" hover-class="hover-active" @click="showAuthor">点击登陆</view>
<view class="ih-tip">今日总收入</view>
<view class="ih-price"><text>{{isLogin?'¥':''}}</text>{{isLogin?(indexData.amount || '0'):'***'}}</view>
<view class="ih-price"><text>{{loginStatus?'¥':''}}</text>{{loginStatus?(indexData.amount || '0'):'***'}}</view>
<view class="ih-amount">
<view>
<view>收款笔数</view>
<view>{{isLogin?(indexData.in_count || '0'):'**'}}</view>
<view>{{loginStatus?(indexData.in_count || '0'):'**'}}</view>
</view>
<view>
<view>退款笔数</view>
<view>{{isLogin?(indexData.out_count || '0'):'**'}}</view>
<view>{{loginStatus?(indexData.out_count || '0'):'**'}}</view>
</view>
</view>
<image class="ih-bg-icon" style="left: 0;" mode="aspectFit" src="/static/images/icon/index/header_bg_a.png"></image>
@ -140,14 +140,16 @@
//#endif
export default {
computed: {
// loginStatus(){
// return app.isLogin();
// }
},
data() {
return {
tabList,
isShowAuthorModal: false,
isLogin: false,
indexData: {},
loginStatus: app.isLogin()
}
},
async onLoad() {
@ -156,14 +158,13 @@
util.showLoad();
await this.checkUserAuthor();
util.hideLoad();
this.$nextTick(_=>this.isLogin = app.isLogin());
if(!!app.isLogin())this.getIndexInfo();
}catch(err){
util.hideLoad();
uni.removeStorageSync('token');
this.$nextTick(_=>this.isLogin = app.isLogin());
util.showNone(err.message || '身份校验失败!');
// util.showNone(err.message || '');
console.log('onLoad err',err);
this.loginStatus = app.isLogin();
}
// #endif
},
@ -209,33 +210,28 @@
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'})]);
console.log(userRes)
return servers.post({
url: API.wechatMiniAppLoginAndSync,
data: {
appid: APPID,
code: loginRes.code,
encryptedData: userRes.encryptedData,
// is_details: 1,
//
user_info: userRes.userInfo,
user_raw_data: userRes.rawData,
...userRes.userInfo,
},
data: this.getLoginQuery({
userInfo: userRes,
loginRes
}),
isDefaultGet: false,
})
.then(res=>{
util.hideLoad();
if(res.data.code == 0){
let _data = res.data.data;
if(_data.user.role == ''){
let _data = res.data;
if(_data.code == 0){
// let _data = res.data.data;
if(_data.data == ''){
uni.removeStorageSync('token');
return util.routeTo(`/pages/merchant_login/merchant_login`,'rL');
this.loginStatus = app.isLogin();
return util.routeTo(`/pages/login/login`,'rL');
}
uni.setStorageSync('token',_data.token);
uni.setStorageSync('token',_data.data);
return _data;
}else{
util.showNone(_data.message || '校验身份失败!');
throw res.data || {};
}
@ -259,6 +255,21 @@
cancelAuthor(){
this.closeAuthor();
},
getLoginQuery({
userInfo,
loginRes
}){
return {
appid: APPID,
code: loginRes.code,
encryptedData: userInfo.encryptedData,
// is_details: 1,
//
user_info: userInfo.userInfo,
user_raw_data: userInfo.rawData,
...userInfo.userInfo,
}
},
async confirmAuthor(userRes){
if(!userRes.detail.userInfo){
this.closeAuthor();
@ -273,35 +284,29 @@
servers.post({
url: API.wechatMiniAppLoginAndSync,
data: {
appid: APPID,
code: loginRes.code,
encryptedData: userRes.detail.encryptedData,
// is_details: 1,
//
user_info: userRes.detail.userInfo,
user_raw_data: userRes.detail.rawData,
...userRes.detail.userInfo,
// 'avatar_url': userRes.detail.userInfo.avatarUrl,
// ...userRes.detail.userInfo,
},
data: this.getLoginQuery({
userInfo: userRes,
loginRes
}),
isDefaultGet: false,
})
.then(res=>{
util.hideLoad();
if(res.data.code == 0){
let _data = res.data.data;
if(_data.user.role == '')return util.routeTo(`/pages/merchant_login/merchant_login`,'rL');
util.showNone(res.data.message || '登陆成功!');
let _data = res.data || {};
if(_data.code == 0){
if(_data.data == '')return util.routeTo(`/pages/login/login`,'rL');
util.showNone(_data.message || '登陆成功!');
// let _data = res.data.data;
// if(_data.user.role == '')return util.routeTo(`/pages/merchant_login/merchant_login`,'rL');
uni.setStorageSync('token',_data.token);
uni.setStorageSync('token',_data.data);
setTimeout(_=>{
this.isLogin = app.isLogin();
this.getIndexInfo();
this.closeAuthor();
this.loginStatus = app.isLogin();
}, 1200);
}else{
util.showNone(res.data.message || '后台登陆失败!');
util.showNone(_data.message || '后台登陆失败!');
setTimeout(_=>this.closeAuthor(), 1200);
}

205
src/pages/login/login.vue

@ -0,0 +1,205 @@
<template>
<view class="login-container">
<view class="lc-header">
<view class="lh-logo"></view>
<view class="lh-name">欧轩智能场馆</view>
</view>
<view class="lc-form">
<view class="lf-frame"><input placeholder="请输入品牌ID" v-model="formData.brand_id" /></view>
<view class="lf-frame"><input placeholder="请输入账号" v-model="formData.account" /></view>
<view class="lf-frame"><input placeholder="请输入密码" v-model="formData.password" password /></view>
</view>
<button
class="lf-btn"
hover-class="hover-active"
open-type="getUserInfo"
lang="zh_CN"
@getuserinfo="submitBtn"
>登录</button>
<view class="lf-tip">提示请联系管理员添加您为员工账号</view>
<view class="lf-bot-btn" @click="toWebView">成为商家</view>
</view>
</template>
<script>
import { API } from '../../js/api';
import { servers } from '../../js/server';
import util from '../../utils/util';
const uniGetSetting = util.promisify(uni.getSetting);
const uniLogin = util.promisify(uni.login);
const APPID = uni.getAccountInfoSync().miniProgram.appId;
export default {
data(){
return {
formData: {
brand_id: '',
account: '',
password: '',
}
}
},
methods: {
async submitBtn(userRes){
try{
util.showLoad();
if(!userRes.detail.userInfo){
util.hideLoad();
return util.showNone('获取用户信息失败!请稍后重试');
}
let loginRes = await uniLogin();
if(!loginRes.code){
util.hideLoad();
return util.showNone('获取登陆凭证失败!稍后重试');
}
let userInfo = userRes.detail || {};
console.log(userRes)
let { formData } = this;
servers.post({
url: API.WechatMiniApplogin,
data: {
appid: APPID,
code: loginRes.code,
encryptedData: userInfo.encryptedData,
// is_details: 1,
//
user_info: userInfo.userInfo,
user_raw_data: userInfo.rawData,
...userInfo.userInfo,
username: formData.account,
password: formData.password,
brand_id: formData.brand_id,
},
isDefaultGet: false,
})
.then(res=>{
util.hideLoad();
let _data = res.data || {};
if(_data.code == 0){
util.showNone(_data.message || '操作成功!');
uni.setStorageSync('token',_data.data);
setTimeout(_=>{
util.routeTo(`/pages/index/index`, rL);
}, 1200);
}else{
util.showNone(_data.message || '操作失败!');
}
})
.catch(util.hideLoad)
}catch(err){
util.hideLoad();
console.warn('login err', err);
}
},
toWebView(){
util.routeTo(`/pages/web_view/web_view`,'rL');
}
},
}
</script>
<style lang="scss">
@import '~style/public.scss';
page{
background-color: #fff;
}
.login-container{
padding-bottom: 0;
padding-bottom: calc( 0 + constant(safe-area-inset-bottom)); /* 兼容 iOS < 11.2 */
padding-bottom: calc( 0 + env(safe-area-inset-bottom)); /* 兼容 iOS >= 11.2 */
.lc-header{
position: relative;
padding-top: 130upx;
margin-bottom: 86upx;
height: 470upx;
width: 100%;
overflow: hidden;
&::before{
content: '';
display: block;
position: absolute;
left: 50%;
bottom: 0upx;
z-index: -1;
transform: translateX(-50%);
background-color: $themeColor;
width: 3000upx;
height: 3000upx;
border-radius: 50%;
}
.lh-logo{
margin: 0 auto 24upx;
width: 190upx;
height: 190upx;
border-radius: 50%;
background-color: #fff;
overflow: hidden;
>image{
width: 100%;
height: 100%;
}
}
.lh-name{
padding: 0 24upx;
text-align: center;
line-height: 50upx;
font-weight: 500;
font-size: 36upx;
color: #fff;
}
}
.lc-form{
margin-bottom: 84upx;
.lf-frame{
margin: 0 auto 28upx;
padding: 0 20upx;
width: 610upx;
height: 108upx;
border: 2upx solid #dddddd;
border-radius: 54upx;
>input{
width: 100%;
height: 100%;
text-align: center;
font-size: 32upx;
color: #333;
}
&:last-child{
margin-bottom: 0;
}
}
}
.lf-btn{
margin-bottom: 16upx;
width: 610upx;
height: 108upx;
border-radius: 54upx;
border: none;
background-color: $themeColor;
font-size: 36upx;
line-height: 108upx;
color: #fff;
}
.lf-tip{
margin-bottom: 118upx;
text-align: center;
line-height: 40upx;
text-align: center;
font-size: 28upx;
color: #9A9A9D;
}
.lf-bot-btn{
margin-bottom: 20upx;
line-height: 40upx;
text-align: center;
font-size: 28upx;
color: $themeColor;
text-decoration: underline;
}
}
</style>

33
src/subpackage/device/pages/login/login.vue

@ -1,33 +0,0 @@
<template>
<view class="login-container">
<view class="lc-header">
<view class="lh-logo"></view>
<view class="lh-name"></view>
</view>
</view>
</template>
<script>
export default {
}
</script>
<style lang="scss">
@import '~style/public.scss';
.login-container{
.lc-header{
padding-bottom: 136upx;
height: 236upx;
background-color: $themeColor;
.lh-log{
margin: 0 auto 24upx;
width: 190upx;
height: 190upx;
}
.lh-name{
font-size: 18upx;
}
}
}
</style>
Loading…
Cancel
Save