Compare commits

...

2 Commits

Author SHA1 Message Date
刘嘉炜 e2bca46922 add author 4 years ago
刘嘉炜 9cbee1e4e4 add account modal 4 years ago
  1. 184
      src/components/author_modal/author_modal.vue
  2. 9
      src/pages.json
  3. 426
      src/pages/index/index.vue
  4. 117
      src/pages/login_and_bind/login_and_bind.vue

184
src/components/author_modal/author_modal.vue

@ -0,0 +1,184 @@
<template>
<view class="ox-dark-mask">
<view class="ic-author-modal">
<view class="iam-title">微信授权</view>
<view class="iam-tip">您的信息和数据将受到保护</view>
<image class="iam-pic" mode="aspectFit" src="/static/images/icon/author_modal.png"></image>
<view class="iam-btns">
<button plain hover-class="hover-active" @click="cancelAuthor">取消</button>
<button
v-if="isProfile"
plain
hover-class="hover-active"
@click="profileConfirm"
>授权并登录</button>
<button
v-else
plain
hover-class="hover-active"
open-type="getUserInfo"
lang="zh_CN"
@getuserinfo="confirmAuthor"
>授权并登录</button>
</view>
</view>
</view>
</template>
<script>
import { API } from '../../js/api';
import { servers } from '../../js/server';
import util from '../../utils/util'
const uniLogin = util.promisify(uni.login);
const APPID = uni.getAccountInfoSync().miniProgram.appId;
const app = getApp();
export default {
computed: {
isProfile: _=>util.isProfile(),
},
methods: {
//
profileConfirm(){
uni.getUserProfile({
lang: 'zh_CN', desc: '授权登陆',
success: res => {
this.confirmAuthor({detail: {...res}});
},
fail: function(err) {
util.showNone('获取用户信息失败!请重试');
console.warn('getUserProfile Err', err)
}
})
},
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();
return util.showNone('获取用户信息失败!请稍后重试');
}
let loginRes = await uniLogin();
if(!loginRes.code){
// this.closeAuthor();
return util.showNone('获取登陆凭证失败!稍后重试');
}
servers.post({
url: API.wechatMiniAppLoginAndSync,
data: this.getLoginQuery({
userInfo: userRes.detail,
loginRes
}),
isDefaultGet: false,
})
.then(res=>{
util.hideLoad();
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.data);
setTimeout(_=>{
this.$emit('success', _data);
// this.getIndexInfo();
// this.closeAuthor();
// this.loginStatus = app.isLogin();
}, 1200);
}else{
util.showNone(_data.message || '后台登陆失败!');
setTimeout(_=>{
this.$emit('fail', _data);
}, 1200)
// setTimeout(_=>this.closeAuthor(), 1200);
}
}).catch(err=>{
util.hideLoad();
setTimeout(_=>{
this.$emit('fail', err);
}, 1200)
})
},
cancelAuthor(){
this.$emit('cancel')
}
}
}
</script>
<style lang="scss">
@import "~style/public.scss";
.ic-author-modal{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
padding-top: 60upx;
width: 662upx;
height: 884upx;
border-radius: 10upx;
background-color: #fff;
.iam-title{
margin-bottom: 22upx;
text-align: center;
line-height: 60upx;
font-size: 44upx;
font-weight: 500;
color: #1a1a1a;
}
.iam-tip{
margin-bottom: 52upx;
line-height: 40upx;
text-align: center;
font-size: 28upx;
color: #9c9c9f;
}
.iam-pic{
margin: 0 auto 62upx;
display: block;
width: 488upx;
height: 416upx;
}
.iam-btns{
@include centerFlex(center);
>button{
margin: 0 20upx;
width: 240upx;
height: 92upx;
line-height: 88upx;
text-align: center;
border-radius: 46upx;
border: 2upx solid $themeColor;
font-size: 32upx;
color: $themeColor;
&+button{
background-color: $themeColor;
color: #fff;
}
}
}
}
</style>

9
src/pages.json

@ -4,6 +4,15 @@
{
"path": "pages/index/index",
"style": {
"mp-weixin": {
"navigationStyle": "custom"
}
}
},
{
"path": "pages/login_and_bind/login_and_bind",
"style": {
"navigationBarTitleText": "登录"
}
},
{

426
src/pages/index/index.vue

@ -1,6 +1,8 @@
<template>
<view class="index-container">
<view class="ic-custom-bar" :style="customBarStyle">
</view>
<view class="ic-content">
<view class="ic-header">
<view class="ih-address" v-if="loginStatus" @click="toStoreList">
@ -43,28 +45,33 @@
</view>
</view>
<view class="ox-dark-mask" v-if="isShowAuthorModal">
<view class="ic-author-modal">
<view class="iam-title">微信授权</view>
<view class="iam-tip">您的信息和数据将受到保护</view>
<image class="iam-pic" mode="aspectFit" src="/static/images/icon/author_modal.png"></image>
<view class="iam-btns">
<button plain hover-class="hover-active" @click="cancelAuthor">取消</button>
<author-modal
v-if="isShowAuthorModal"
@cancel="authorCancel"
@fail='authorFail'
@success='authorSuccess'
<button
v-if="isProfile"
plain
hover-class="hover-active"
@click="profileConfirm"
>授权并登录</button>
<button
v-else
plain
hover-class="hover-active"
open-type="getUserInfo"
lang="zh_CN"
@getuserinfo="confirmAuthor"
>授权并登录</button>
></author-modal>
<view class="ox-dark-mask" v-if="false">
<view class="ic-account-change">
<view class="iac-tit">轻触头像切换账号</view>
<view class="iac-account-ls">
<view class="ial-item">
<view class="ii-icon">
<image></image>
</view>
<view class="ii-info">
<view class="ii-name">欧轩智能场馆</view>
<view class="ii-tag">当前使用</view>
</view>
</view>
<view class="ial-item ial-add">
<view class="ii-icon">
</view>
<view class="ii-info">
<view class="ii-name">欧轩智能场馆</view>
</view>
</view>
</view>
</view>
</view>
@ -76,87 +83,29 @@
import util from '../../utils/util';
import { servers } from '../../js/server';
import { API } from '../../js/api';
const tabList = [
{
id: 0,
name: '营业额',
path: '/pages/turnover/turnover',
serverKey: 1001 //
},
{
id: 1,
name: '收款记录',
path: '/pages/collection/record/record',
serverKey: 1002 //
},
{
id: 2,
name: '订单管理',
path: '/subpackage/order/pages/order_manage/order_manage',
serverKey: 1012 //
},
{
id: 3,
name: '员工管理',
path: '/pages/employee/manage/manage',
serverKey: 1007 //
},
{
id: 4,
name: '核销查询',
path: '/pages/write_off/search_result/search_result',
serverKey: 1008 //
},
{
id: 5,
name: '场地看板',
// path: '/pages/site/order_list/order_list', // 20210804
path: '/pages/site/manage/manage',
serverKey: 1009 //
},
{
id: 6,
name: '设备管理',
path: '/subpackage/device/pages/index/index',
serverKey: 1010 //
},
{
id: 7,
name: '商品零售',
path: '/subpackage/retail/pages/index/index',
serverKey: 1011 //
},
{
id: 8,
name: '课程管理',
path: '/subpackage/course/pages/index/index',
serverKey: 1013 // 1013
}
];
import author_modal from '../../components/author_modal/author_modal.vue'
const app = getApp();
//#ifndef H5
const uniGetSetting = util.promisify(uni.getSetting);
const uniLogin = util.promisify(uni.login);
const uniGetUserInfo= util.promisify(uni.getUserInfo);
const APPID = uni.getAccountInfoSync().miniProgram.appId;
//#endif
export default {
components: {
'author-modal': author_modal
},
computed: {
isProfile: _=>util.isProfile(),
// loginStatus(){
// return app.isLogin();
// }
customBarStyle(){
let { customBarInfo } = this;
return `height: ${customBarInfo.height}px;`
}
},
data() {
return {
tabList,
tabList: tabList(),
isShowAuthorModal: false,
indexData: {},
loginStatus: false,
customBarInfo: {},
}
},
async onLoad() {
@ -177,12 +126,44 @@
// #endif
},
onShow(){
this.initCustomBarInfo();
// #ifndef H5
let { indexData } = this;
if(JSON.stringify(indexData)!='{}'&&!!app.isLogin())this.getIndexInfo();
// #endif
},
methods: {
//
initCustomBarInfo(){
let _timer = null; // api
const sysInfo = uni.getSystemInfoSync();
const capsuleInfo = uni.getMenuButtonBoundingClientRect();
// const capsuleInfo = null;
let _data = {
statusBarHeight: sysInfo.statusBarHeight,
capsuleInfo,
}
clearTimeout(_timer);
_timer = null;
if(capsuleInfo&&capsuleInfo.top&&capsuleInfo.bottom){
_data[ 'height' ] = capsuleInfo.bottom + capsuleInfo.top - sysInfo.statusBarHeight + 4;
}else{
_timer = setTimeout(_=>this.initCustomBarInfo(),700); // api
_data[ 'height' ] = sysInfo.statusBarHeight + 50;
}
this.customBarInfo = _data;
},
authorCancel(){
this.closeAuthor();
},
authorFail(){
this.closeAuthor();
},
authorSuccess(){
this.getIndexInfo();
this.closeAuthor();
this.loginStatus = app.isLogin();
},
toNoticeList(){
if(!app.isLogin())return this.showAuthor();
util.routeTo(`/pages/message/list/list`,'nT');
@ -196,7 +177,6 @@
if(!_permission[tabInfo.serverKey])return util.showNone('暂无权限,请联系管理员开启!')
util.routeTo(tabInfo.path,'nT');
},
getIndexInfo(){
servers.get({
url: API.calc,
@ -226,12 +206,13 @@
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);
uni.setStorageSync('token', _data.data);
return _data;
}else{
util.showNone(_data.message || '校验身份失败!');
@ -252,81 +233,6 @@
closeAuthor(){
this.isShowAuthorModal = false
},
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,
}
},
//
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){
if(!userRes.detail.userInfo){
this.closeAuthor();
return util.showNone('获取用户信息失败!请稍后重试');
}
let loginRes = await uniLogin();
if(!loginRes.code){
this.closeAuthor();
return util.showNone('获取登陆凭证失败!稍后重试');
}
servers.post({
url: API.wechatMiniAppLoginAndSync,
data: this.getLoginQuery({
userInfo: userRes.detail,
loginRes
}),
isDefaultGet: false,
})
.then(res=>{
util.hideLoad();
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.data);
setTimeout(_=>{
this.getIndexInfo();
this.closeAuthor();
this.loginStatus = app.isLogin();
}, 1200);
}else{
util.showNone(_data.message || '后台登陆失败!');
setTimeout(_=>this.closeAuthor(), 1200);
}
}).catch(util.hideLoad)
},
toStoreList(){
if(!app.isLogin())return this.showAuthor();
@ -335,10 +241,75 @@
},
}
}
function tabList(){
return [
{
id: 0,
name: '营业额',
path: '/pages/turnover/turnover',
serverKey: 1001 //
},
{
id: 1,
name: '收款记录',
path: '/pages/collection/record/record',
serverKey: 1002 //
},
{
id: 2,
name: '订单管理',
path: '/subpackage/order/pages/order_manage/order_manage',
serverKey: 1012 //
},
{
id: 3,
name: '员工管理',
path: '/pages/employee/manage/manage',
serverKey: 1007 //
},
{
id: 4,
name: '核销查询',
path: '/pages/write_off/search_result/search_result',
serverKey: 1008 //
},
{
id: 5,
name: '场地看板',
// path: '/pages/site/order_list/order_list', // 20210804
path: '/pages/site/manage/manage',
serverKey: 1009 //
},
{
id: 6,
name: '设备管理',
path: '/subpackage/device/pages/index/index',
serverKey: 1010 //
},
{
id: 7,
name: '商品零售',
path: '/subpackage/retail/pages/index/index',
serverKey: 1011 //
},
{
id: 8,
name: '课程管理',
path: '/subpackage/course/pages/index/index',
serverKey: 1013 // 1013
}
];
}
</script>
<style lang="scss" scoped>
@import "~style/public.scss";
.ic-custom-bar{
background-color: $themeColor;
margin-bottom: 24upx;
}
.index-container{
position: relative;
}
@ -510,55 +481,90 @@
}
}
.ic-author-modal{
.ic-account-change{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
padding-top: 60upx;
width: 662upx;
height: 884upx;
border-radius: 10upx;
background-color: #fff;
.iam-title{
margin-bottom: 22upx;
text-align: center;
line-height: 60upx;
left: 0;
top: 0;
bottom: 0;
width: 500upx;
background-color: #f2f2f7;
padding-top: 312upx;
.iac-tit{
font-size: 44upx;
font-weight: 500;
color: #1a1a1a;
}
.iam-tip{
margin-bottom: 52upx;
line-height: 40upx;
line-height: 60upx;
text-align: center;
font-size: 28upx;
color: #9c9c9f;
}
.iam-pic{
margin: 0 auto 62upx;
display: block;
width: 488upx;
height: 416upx;
color: #1A1A1A;
}
.iam-btns{
@include centerFlex(center);
>button{
margin: 0 20upx;
width: 240upx;
height: 92upx;
line-height: 88upx;
text-align: center;
border-radius: 46upx;
border: 2upx solid $themeColor;
font-size: 32upx;
color: $themeColor;
&+button{
background-color: $themeColor;
color: #fff;
.iac-account-ls{
padding: 78upx 20upx 24upx;
.ial-item{
padding: 0 18upx;
margin-bottom: 24upx;
height: 144upx;
border-radius: 10upx;
background-color: #fff;
@include centerFlex(space-between);
.ii-icon{
flex-shrink: 0;
margin-right: 20upx;
width: 88upx;
height: 88upx;
>image{
width: 100%;
height: 100%;
background-color: skyblue;
border-radius: 6upx;
}
}
.ii-info{
flex-grow: 1;
.ii-name{
margin-bottom: 4upx;
font-size: 32upx;
line-height: 44upx;
color: #1a1a1a;
@include textHide(1);
}
.ii-tag{
padding: 0 10upx;
display: inline-block;
line-height: 40upx;
font-size: 28upx;
color: $themeColor;
border-radius: 6upx;
background-color: rgba($color: #36C990, $alpha: .13);
}
}
}
.ial-add{
.ii-icon{
position: relative;
border: 2upx solid #979797;
border-radius: 6upx;
&::before,&::after{
content: '';
display: block;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 40upx;
height: 4upx;
border-radius: 2upx;
background-color: #9A9A9D;
}
&::after{
height: 40upx;
width: 4upx;
}
}
>.ii-info >.ii-name{
color: #9A9A9D;
}
}
}
}
}
</style>

117
src/pages/login_and_bind/login_and_bind.vue

@ -0,0 +1,117 @@
<template>
<view class="login-and-bind">
<view class="lab-header">
<view class="lh-txt"><text>您好\n\r欢迎使用商家助手</text></view>
</view>
<view class="lab-main">
<view class="lm-bar"></view>
<view class="lm-logo"></view>
<view class="lm-ipt-ls">
<view class="lil-item">
<input placeholder="请输入密码" />
<view class="li-tip">您输入的账号信息有误请检查重新输入</view>
</view>
<view class="lil-item"><input placeholder="请输入密码" /></view>
<view class="lil-item"><input placeholder="请输入密码" /></view>
</view>
<view class="lm-btn">登录</view>
<view class="lm-tip">账号登录成功后即被激活且绑定微信号</view>
<view class="lm-help-link">使用帮助</view>
</view>
</view>
</template>
<script>
export default {
}
</script>
<style lang="scss">
@import '~style/public.scss';
page{
background-color: #fff;
}
.login-and-bind{
padding-bottom: 0upx;
padding-bottom: calc( 0upx + constant(safe-area-inset-bottom)); /* 兼容 iOS < 11.2 */
padding-bottom: calc( 0upx + env(safe-area-inset-bottom)); /* 兼容 iOS >= 11.2 */
}
.lab-header{
padding: 88upx 40upx 0;
height: 300upx;
background-color: #17a181;
.lh-txt{
font-size: 56upx;
line-height: 66upx;
font-weight: 500;
color: #fff;
}
}
.lab-main{
position: relative;
.lm-bar{
height: 160upx;
background-color: skyblue;
}
.lm-logo{
margin: -146upx auto 68upx;
width: 176upx;
height: 176upx;
border-radius: 50%;
background-color: $themeColor;
}
.lm-ipt-ls{
padding: 68upx 74upx 10upx;
.lil-item{
position: relative;
margin-bottom: 50upx;
padding: 0 40upx;
height: 108upx;
border-radius: 54upx;
border: 2upx solid #D8D8D8;
@include centerFlex(center);
>input{
flex-grow: 1;
height: 100%;
font-size: 32upx;
color: #1a1a1a;
}
.li-tip{
position: absolute;
right: 0;
bottom: -42upx;
padding: 0 40upx;
font-size: 28upx;
line-height: 40upx;
color: #EA5061;
}
}
}
.lm-btn{
margin: 0 auto 20upx;
width: 610upx;
line-height: 108upx;
border-radius: 54upx;
text-align: center;
font-size: 32upx;
color: #fff;
background-color: $themeColor;
}
.lm-tip{
margin-bottom: 122upx;
text-align: center;
line-height: 40upx;
font-size: 28upx;
color: #B2B2B2;
}
.lm-help-link{
text-align: center;
font-size: 28upx;
line-height: 40upx;
color: $themeColor;
}
}
</style>
Loading…
Cancel
Save