提交 837cbfed authored 作者: lidongxu's avatar lidongxu

信息提交页面搭建完毕

上级 ee74a7a3
import request from '@/utils/request'
// 登录方法
export function login(username, password, code, uuid) {
const data = {
username,
password,
code,
uuid
}
// 提交用户注册信息
export function submitUserInfo(data) {
return request({
'url': '/auth/login',
headers: {
isToken: false
},
'url': '/user/wechat/core/temporary/enroll',
'method': 'post',
'data': data
})
}
// 注册方法
export function register(data) {
return request({
url: '/auth/register',
headers: {
isToken: false
},
method: 'post',
data: data
})
}
// 获取用户详细信息
export function getInfo() {
return request({
'url': '/system/user/getInfo',
'method': 'get'
})
}
// 退出方法
export function logout() {
return request({
'url': '/auth/logout',
'method': 'DELETE'
})
}
// 获取验证码
export function getCodeImg() {
return request({
'url': '/auth/captchaImage',
headers: {
isToken: false
},
method: 'get',
timeout: 20000
})
}
}
\ No newline at end of file
......@@ -5,9 +5,9 @@ module.exports = {
mapKey: 'mryaav7xyp0Z3ItwUT3oMssYAmG8sTSU',
coordtype: 'gcj02', // 坐标类型(小程序获取和百度地图 API 使用类型要对应上)
// baseUrl: 'http://localhost:8080',
baseUrl: 'http://192.168.140.189:8080', // 局域网请求
// baseUrl: 'http://sfa.test.wxl66.cn:85/api', // 上线测试
// baseUrl: 'http://111.198.15.68:85/api',
baseUrl: 'http://promotion.wxl66.cn:8010', // 云 API 域名
wxAppId: 'wx5d89065bb4725557',
wxSecret: '7395e91baf6b49ca9b84b1301989f77e',
// 应用信息
appInfo: {
// 应用名称
......@@ -20,13 +20,13 @@ module.exports = {
site_url: "http://ruoyi.vip",
// 政策协议
agreements: [{
title: "隐私政策",
url: "https://ruoyi.vip/protocol.html"
},
{
title: "用户服务协议",
url: "https://ruoyi.vip/protocol.html"
}
title: "隐私政策",
url: "https://ruoyi.vip/protocol.html"
},
{
title: "用户服务协议",
url: "https://ruoyi.vip/protocol.html"
}
]
}
}
......@@ -4,14 +4,14 @@ import store from './store' // store
import plugins from './plugins' // plugins
import './permission' // permission
import * as auth from './utils/auth.js'
import config from './config.js'
Vue.use(plugins)
// 获取 access_token
const appid = 'wx5d89065bb4725557'
const secret = '7395e91baf6b49ca9b84b1301989f77e'
// 发起请求
uni.request({
url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appid}&secret=${secret}`,
url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${config.wxAppId}&secret=${config.wxSecret}`,
success: function (res) {
auth.setAccessToken(res.data.access_token)
},
......
{
"pages": [
{
"path": "pages/start",
"style": {
"navigationBarTitleText": "欢迎使用-小卤促销员平台"
}
},
{
"path": "pages/login",
"style": {
......@@ -7,9 +13,9 @@
}
},
{
"path": "pages/start",
"path": "pages/register",
"style": {
"navigationBarTitleText": "欢迎使用-小卤促销员平台"
"navigationBarTitleText": "促销员提交"
}
},
{
......@@ -30,12 +36,7 @@
"navigationBarTitleText": "工作台"
}
},
{
"path": "pages/register",
"style": {
"navigationBarTitleText": "注册"
}
},
{
"path": "pages/mine/index",
"style": {
......
......@@ -48,38 +48,55 @@ export default {
},
methods: {
// 手机号登录
getPhoneNumber(e) {
async getPhoneNumber(e) {
this.$modal.loading("登录中,请耐心等待...")
// 通过微信小程序 API 获取手机号
uni.request({
const [,phoneRes] = await uni.request({
url: `https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${getAccessToken()}`,
method: 'POST',
data: {
code: e.detail.code
},
success: (res) => {
console.log('后端解密手机号成功,手机号为:', res);
storage.set(constant.loginPhone, res.data.phone_info.phoneNumber)
this.$modal.closeLoading()
this.$tab.reLaunch('/pages/index')
},
fail: function () {
console.log('后端解密手机号失败');
}
})
// 调用微信登录接口,获取 code
const [,loginRes] = await uni.login({
provider: 'weixin'
})
// 通过 code 获取 openid
const [,openRes] = await uni.request({
url: `https://api.weixin.qq.com/sns/jscode2session?appid=${this.globalConfig.wxAppId}&secret=${this.globalConfig.wxSecret}&js_code=${loginRes.code}&grant_type=authorization_code`
});
// 获取用户信息-头像等
const [,userRes] = await uni.getUserInfo({
provider: 'weixin',
withCredentials: false
})
storage.set(constant.loginPhone, phoneRes.data.phone_info.phoneNumber)
storage.set(constant.loginOpenId, openRes.data.openid)
this.$store.commit('SET_USER', userRes.userInfo)
this.$modal.closeLoading()
this.$tab.reLaunch('/pages/register')
},
// // 登录成功后,处理函数
// async loginSuccess(result) {
// // 设置用户信息
// await this.$store.dispatch('GetInfo')
// await this.getAuth()
// this.$tab.reLaunch('/pages/index')
// },
// 登录成功后,开始获取各种权限
async getAuth() {
// 获取地址位置
return this.$store.dispatch('GetLocation')
fail: function () {
console.log('后端解密手机号失败');
}
},
// // 登录成功后,处理函数
// async loginSuccess(result) {
// // 设置用户信息
// await this.$store.dispatch('GetInfo')
// await this.getAuth()
// this.$tab.reLaunch('/pages/index')
// },
// 登录成功后,开始获取各种权限
async getAuth() {
// 获取地址位置
return this.$store.dispatch('GetLocation')
}
}
</script>
......
<template>
<view class="normal-login-container">
<view class="logo-content align-center justify-center flex">
<image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
</image>
<text class="title">若依移动端注册</text>
</view>
<view class="login-form-content">
<view class="input-item flex align-center">
<view class="iconfont icon-user icon"></view>
<input v-model="registerForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
</view>
<view class="input-item flex align-center">
<view class="iconfont icon-password icon"></view>
<input v-model="registerForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
</view>
<view class="input-item flex align-center">
<view class="iconfont icon-password icon"></view>
<input v-model="registerForm.confirmPassword" type="password" class="input" placeholder="请输入重复密码" maxlength="20" />
</view>
<view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
<view class="iconfont icon-code icon"></view>
<input v-model="registerForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
<view class="login-code">
<image :src="codeUrl" @click="getCode" class="login-code-img"></image>
<view class="normal-register-container">
<!-- 基础表单校验 -->
<uni-forms ref="valiForm"
:rules="rules"
:modelValue="formData">
<uni-forms-item label="头像"
required
name="avatar">
<button class="avatar"
open-type="chooseAvatar"
@chooseavatar="chooseavatarFn">
<img class="avatar_img"
:src="formData.avatarUrl" />
</button>
</uni-forms-item>
<uni-forms-item label="姓名"
required
name="name">
<uni-easyinput v-model="formData.name"
placeholder="请输入姓名" />
</uni-forms-item>
<uni-forms-item label="身份证">
<view class="id_card">
<uni-file-picker fileMediatype="image"
mode="grid"
limit="1"
return-type="object"
title="正面图片"
v-model="formData.idenFrontPhotoUrl"
@select="selectIdenPhotoFn"></uni-file-picker>
<uni-file-picker fileMediatype="image"
mode="grid"
limit="1"
return-type="object"
title="反面图片"
v-model="formData.idenReversePhotoUrl"
@select="selectIdenPhotoFn"></uni-file-picker>
</view>
</view>
<view class="action-btn">
<button @click="handleRegister()" class="register-btn cu-btn block bg-blue lg round">注册</button>
</view>
</view>
<view class="xieyi text-center">
<text @click="handleUserLogin" class="text-blue">使用已有账号登录</text>
</view>
</uni-forms-item>
<button type="primary"
@click="submit('valiForm')">提交信息</button>
</uni-forms>
</view>
</template>
<script>
import { getCodeImg, register } from '@/api/login'
export default {
data() {
return {
codeUrl: "",
captchaEnabled: true,
globalConfig: getApp().globalData.config,
registerForm: {
username: "",
password: "",
confirmPassword: "",
code: "",
uuid: ''
}
}
},
created() {
this.getCode()
},
methods: {
// 用户登录
handleUserLogin() {
this.$tab.navigateTo(`/pages/login`)
import { mapGetters } from 'vuex'
import { submitUserInfo } from '../api/login'
export default {
data() {
return {
// 校验表单数据
formData: {
avatarUrl: '',
name: '',
idenFrontPhotoUrl: [],
idenReversePhotoUrl: [],
},
// 获取图形验证码
getCode() {
getCodeImg().then(res => {
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
if (this.captchaEnabled) {
this.codeUrl = 'data:image/gif;base64,' + res.img
this.registerForm.uuid = res.uuid
}
})
},
// 注册方法
async handleRegister() {
if (this.registerForm.username === "") {
this.$modal.msgError("请输入您的账号")
} else if (this.registerForm.password === "") {
this.$modal.msgError("请输入您的密码")
} else if (this.registerForm.confirmPassword === "") {
this.$modal.msgError("请再次输入您的密码")
} else if (this.registerForm.password !== this.registerForm.confirmPassword) {
this.$modal.msgError("两次输入的密码不一致")
} else if (this.registerForm.code === "" && this.captchaEnabled) {
this.$modal.msgError("请输入验证码")
} else {
this.$modal.loading("注册中,请耐心等待...")
this.register()
// 校验规则
rules: {
avatarUrl: {
rules: [{
required: true,
errorMessage: '头像不能为空'
}]
},
name: {
rules: [{
required: true,
errorMessage: '名字不能为空'
}]
}
},
// 用户注册
async register() {
register(this.registerForm).then(res => {
this.$modal.closeLoading()
uni.showModal({
title: "系统提示",
content: "恭喜你,您的账号 " + this.registerForm.username + " 注册成功!",
success: function (res) {
if (res.confirm) {
uni.redirectTo({ url: `/pages/login` });
}
}
})
}).catch(() => {
if (this.captchaEnabled) {
this.getCode()
}
})
},
// 注册成功后,处理函数
registerSuccess(result) {
// 设置用户信息
this.$store.dispatch('GetInfo').then(res => {
this.$tab.reLaunch('/pages/index')
})
}
}
}
},
computed: {
...mapGetters(['user'])
},
methods: {
// 选择了头像
chooseavatarFn(obj) {
this.formData.avatarUrl = obj.detail.avatarUrl
},
// 选择了身份证
selectIdenPhotoFn(obj) {
// console.log(obj.tempFiles[0]) // 文件对象-需要自己上传 OSS
},
submit(ref) {
this.$refs[ref].validate().then(res => {
console.log('success', res);
uni.showToast({
title: `校验通过`
})
}).catch(err => {
console.log('err', err);
})
},
},
created() {
this.formData.avatarUrl = this.user.avatarUrl
this.formData.name = this.user.nickName
},
}
</script>
<style lang="scss">
page {
background-color: #ffffff;
page {
background-color: #ffffff;
}
.normal-register-container {
width: 100%;
padding: 40rpx;
// 头像
.avatar {
background: transparent;
float: left;
}
.normal-login-container {
width: 100%;
.avatar::after {
border: none;
}
.logo-content {
width: 100%;
font-size: 21px;
text-align: center;
padding-top: 15%;
.avatar_img {
width: 120rpx;
height: 120rpx;
}
image {
border-radius: 4px;
}
// 身份证
.id_card {
display: flex;
justify-content: space-between;
}
.title {
margin-left: 10px;
}
.uni-file-picker__header text:last-of-type {
display: none;
}
.uni-file-picker__container {
padding: 40rpx;
padding-top: 10rpx;
}
.file-picker__box {
height: 200rpx !important;
width: 100% !important;
background-color: #f1f1f1;
.icon-add {
background-color: #c9c9c9;
}
}
.login-form-content {
text-align: center;
margin: 20px auto;
margin-top: 15%;
width: 80%;
.input-item {
margin: 20px auto;
background-color: #f5f6f7;
height: 45px;
border-radius: 20px;
.icon {
font-size: 38rpx;
margin-left: 10px;
color: #999;
}
.logo-content {
width: 100%;
font-size: 21px;
text-align: center;
padding-top: 15%;
.input {
width: 100%;
font-size: 14px;
line-height: 20px;
text-align: left;
padding-left: 15px;
}
image {
border-radius: 4px;
}
}
.title {
margin-left: 10px;
}
}
.login-form-content {
text-align: center;
margin: 20px auto;
margin-top: 15%;
width: 80%;
.register-btn {
margin-top: 40px;
height: 45px;
.input-item {
margin: 20px auto;
background-color: #f5f6f7;
height: 45px;
border-radius: 20px;
.icon {
font-size: 38rpx;
margin-left: 10px;
color: #999;
}
.xieyi {
color: #333;
margin-top: 20px;
.input {
width: 100%;
font-size: 14px;
line-height: 20px;
text-align: left;
padding-left: 15px;
}
.login-code {
}
.register-btn {
margin-top: 40px;
height: 45px;
}
.xieyi {
color: #333;
margin-top: 20px;
}
.login-code {
height: 38px;
float: right;
.login-code-img {
height: 38px;
float: right;
.login-code-img {
height: 38px;
position: absolute;
margin-left: 10px;
width: 200rpx;
}
position: absolute;
margin-left: 10px;
width: 200rpx;
}
}
}
}
</style>
......@@ -10,9 +10,11 @@ export default {
setTimeout(() => {
// this.$tab.redirectTo('/page_subject/pages/login')
console.log(storage.get(constant.loginPhone))
// TODO:下面重写:有手机号,判断注册信息填过没有,有就去首页,没有就去注册页
if (storage.get(constant.loginPhone)) {
// 有存储过之前的登录手机号
this.$tab.switchTab('/pages/index')
// 有存储过之前的登录手机号+openId 也不对,需要注册成功,再去首页
// this.$tab.switchTab('/pages/index')
this.$tab.redirectTo('/pages/register')
} else {
this.$tab.redirectTo('/pages/login')
}
......
import store from '@/store'
const getters = {
token: state => state.user.token,
avatar: state => state.user.avatar,
......
......@@ -8,6 +8,7 @@ const constant = {
location: 'vuex_location',
// 登录使用手机号
loginPhone: 'vuex_login_phone',
loginOpenId: 'vuex_login_openid',
}
export default constant
......@@ -4,7 +4,7 @@ import constant from './constant'
let storageKey = 'storage_data'
// 存储节点变量名
let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions, constant.user, constant.location, constant.loginPhone]
let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions, constant.user, constant.location, constant.loginPhone, constant.loginOpenId]
const storage = {
set: function(key, value) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论