|
@@ -1,20 +1,17 @@
|
|
|
<template>
|
|
|
<mobile-frame>
|
|
|
<view class="main">
|
|
|
- <view class="one">
|
|
|
- <image class="image" :src="logoUrl">
|
|
|
- </image>
|
|
|
- </view>
|
|
|
<view class="two">
|
|
|
<uni-forms ref="form" :rules="rules" :model="form" label-width="auto">
|
|
|
- <uni-forms-item label="登录账号" name="code_phone">
|
|
|
- <uni-easyinput type="text" v-model="form.code_phone" placeholder="请输入登录账号" />
|
|
|
+ <uni-forms-item label="账号" name="phone">
|
|
|
+ <uni-easyinput type="text" v-model="form.phone" placeholder="请输入账号" />
|
|
|
</uni-forms-item>
|
|
|
- <uni-forms-item label="登录密码" name="password">
|
|
|
- <uni-easyinput type="password" v-model="form.password" placeholder="请输入登录密码" />
|
|
|
+ <uni-forms-item label="密码" name="password">
|
|
|
+ <uni-easyinput type="password" v-model="form.password" placeholder="请输入密码" />
|
|
|
</uni-forms-item>
|
|
|
<view class="btn">
|
|
|
- <button type="default" size="mini" @click="toSubmit('form')">提交登录</button>
|
|
|
+ <button type="default" size="mini" @click="toSubmit('form')">登录</button>
|
|
|
+ <button type="default" size="mini" @click="wxLogin()">微信信任登录</button>
|
|
|
</view>
|
|
|
</uni-forms>
|
|
|
</view>
|
|
@@ -29,21 +26,23 @@
|
|
|
logoUrl: this.$config.logoUrl,
|
|
|
form: {},
|
|
|
rules: {
|
|
|
- code_phone: {
|
|
|
+ phone: {
|
|
|
rules: [{
|
|
|
required: true,
|
|
|
- errorMessage: '请输入登录账号',
|
|
|
+ errorMessage: '请输入账号',
|
|
|
},
|
|
|
-
|
|
|
+ {
|
|
|
+ minLength: 11,
|
|
|
+ maxLength: 11,
|
|
|
+ errorMessage: '账号长度在{maxLength}个字符',
|
|
|
+ }
|
|
|
]
|
|
|
},
|
|
|
password: {
|
|
|
rules: [{
|
|
|
- required: true,
|
|
|
- errorMessage: '请输入登录密码',
|
|
|
- },
|
|
|
-
|
|
|
- ]
|
|
|
+ required: true,
|
|
|
+ errorMessage: '请输入密码',
|
|
|
+ }, ]
|
|
|
},
|
|
|
}
|
|
|
};
|
|
@@ -61,28 +60,142 @@
|
|
|
toSubmit(ref) {
|
|
|
const that = this;
|
|
|
that.$refs[ref].validate().then(async params => {
|
|
|
- const res = await that.$api(`/admin/login`, 'POST', {
|
|
|
+ const res = await that.$api(`/user/login`, 'POST', {
|
|
|
...params
|
|
|
})
|
|
|
if (res.errcode == '0') {
|
|
|
+ uni.showToast({
|
|
|
+ title: '登录成功',
|
|
|
+ icon: 'success'
|
|
|
+ });
|
|
|
uni.setStorage({
|
|
|
key: 'token',
|
|
|
data: res.data,
|
|
|
success: function() {
|
|
|
- uni.redirectTo({
|
|
|
- url: `/pagesA/adminHome/index`
|
|
|
+ uni.navigateBack({
|
|
|
+ delta: 1
|
|
|
})
|
|
|
}
|
|
|
});
|
|
|
+ } else {
|
|
|
+ if (res.errcode == '-5') {
|
|
|
+ // 账号无,注册账号
|
|
|
+ that.createUser(params);
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ console.log('表单错误信息:', err);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 注册账号,去登录
|
|
|
+ async createUser(params) {
|
|
|
+ const that = this;
|
|
|
+ const res = await that.$api(`/user`, 'POST', {
|
|
|
+ ...params
|
|
|
+ })
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ that.userLogin(params, '1')
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 注册微信账号,去登录
|
|
|
+ async createwxUser(params) {
|
|
|
+ const that = this;
|
|
|
+ const res = await that.$api(`/user`, 'POST', {
|
|
|
+ ...params
|
|
|
+ })
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ that.userLogin(params, '2')
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 账号,微信登录
|
|
|
+ async userLogin(params, type) {
|
|
|
+ const that = this;
|
|
|
+ let res;
|
|
|
+ if (type == '1') {
|
|
|
+ res = await that.$api(`/user/login`, 'POST', {
|
|
|
+ ...params
|
|
|
+ })
|
|
|
+ } else if (type == '2') {
|
|
|
+ res = await that.$api(`/user/wxLogin`, 'POST', {
|
|
|
+ openid: params.openid
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ uni.showToast({
|
|
|
+ title: '登录成功',
|
|
|
+ icon: 'success'
|
|
|
+ });
|
|
|
+ uni.setStorage({
|
|
|
+ key: 'token',
|
|
|
+ data: res.data,
|
|
|
+ success: function() {
|
|
|
+ uni.navigateBack({
|
|
|
+ delta: 1
|
|
|
+ })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ if (res.errcode == '-5') {
|
|
|
+ // 账号无,注册账号
|
|
|
+ that.createwxUser(params);
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
title: res.errmsg,
|
|
|
- icon: 'error',
|
|
|
- duration: 2000
|
|
|
+ icon: 'none'
|
|
|
});
|
|
|
}
|
|
|
- }).catch(err => {
|
|
|
- console.log('表单错误信息:', err);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 微信登录
|
|
|
+ wxLogin() {
|
|
|
+ const that = this;
|
|
|
+ uni.login({
|
|
|
+ provider: 'weixin',
|
|
|
+ success: function(res) {
|
|
|
+ // 获取平台信息
|
|
|
+ uni.getSystemInfo({
|
|
|
+ success: async function(arr) {
|
|
|
+ let platForm = arr.uniPlatform;
|
|
|
+ if (platForm == 'app') { //app平台
|
|
|
+ uni.showToast({
|
|
|
+ title: 'app端暂未开通微信登录',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ } else if (platForm == 'mp-weixin') { //微信平台
|
|
|
+ const aee = await that.$api(`/wechat/api/login/app`, 'GET', {
|
|
|
+ js_code: res.code,
|
|
|
+ config: 'pointApp'
|
|
|
+ })
|
|
|
+ if (aee.errcode == '0') {
|
|
|
+ // 微信登录
|
|
|
+ that.userLogin({
|
|
|
+ openid: aee.data.openid
|
|
|
+ }, '2');
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: function(err) {
|
|
|
+ console.log(err);
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
}
|
|
@@ -91,22 +204,10 @@
|
|
|
|
|
|
<style lang="scss">
|
|
|
.main {
|
|
|
- .one {
|
|
|
- text-align: center;
|
|
|
- padding: 8vw 0;
|
|
|
- margin: 0 0 2vw 0;
|
|
|
- background-image: linear-gradient(#35BD7B, #75E4B1);
|
|
|
|
|
|
- .image {
|
|
|
- width: 25vw;
|
|
|
- height: 25vw;
|
|
|
- border-radius: 50%;
|
|
|
- box-shadow: 0 0 5px var(--f9Color);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
.two {
|
|
|
- padding: 0 2vw;
|
|
|
+ padding: 2vw;
|
|
|
|
|
|
.btn {
|
|
|
text-align: center;
|