|
@@ -1,83 +1,95 @@
|
|
|
<template>
|
|
|
- <view class="u-page">
|
|
|
- <u--form ref="loginForm" :model="form" :rules="rules" errorType="toast">
|
|
|
- <u-row justify="center">
|
|
|
- <u-col span="9">
|
|
|
- <u-form-item prop="username">
|
|
|
- <u-input v-model="form.username" type="number" placeholder="请输入手机号" prefixIcon="account"
|
|
|
- :clearable="true" />
|
|
|
- </u-form-item>
|
|
|
- </u-col>
|
|
|
- </u-row>
|
|
|
+ <view class="u-page">
|
|
|
+ <u--form ref="loginForm" :model="form" :rules="rules" errorType="toast">
|
|
|
+ <u-row justify="center">
|
|
|
+ <u-col span="9">
|
|
|
+ <u-form-item prop="username">
|
|
|
+ <u-input v-model="form.username" type="number" placeholder="请输入手机号" prefixIcon="account"
|
|
|
+ :clearable="true" />
|
|
|
+ </u-form-item>
|
|
|
+ </u-col>
|
|
|
+ </u-row>
|
|
|
|
|
|
- <u-row justify="center">
|
|
|
- <u-col span="9">
|
|
|
- <u-form-item prop="password">
|
|
|
- <u-input v-model="form.password" type="password" placeholder="请输入密码" prefixIcon="lock" :clearable="true" />
|
|
|
- </u-form-item>
|
|
|
- </u-col>
|
|
|
- </u-row>
|
|
|
+ <u-row justify="center">
|
|
|
+ <u-col span="9">
|
|
|
+ <u-form-item prop="password">
|
|
|
+ <u-input v-model="form.password" type="password" placeholder="请输入密码" prefixIcon="lock" :clearable="true" />
|
|
|
+ </u-form-item>
|
|
|
+ </u-col>
|
|
|
+ </u-row>
|
|
|
|
|
|
- <u-row justify="center">
|
|
|
- <u-col span="9">
|
|
|
- <u-form-item>
|
|
|
- <u-button type="primary" text="登录并绑定微信" @click="submitForm"></u-button>
|
|
|
- <u-text type="info" align="center" text="微信一键登录" @click="quickLogin"></u-text>
|
|
|
- </u-form-item>
|
|
|
- </u-col>
|
|
|
- </u-row>
|
|
|
- </u--form>
|
|
|
+ <u-row justify="center">
|
|
|
+ <u-col span="9">
|
|
|
+ <u-form-item>
|
|
|
+ <u-button type="success" text="登录并绑定微信" @click="submitForm"></u-button>
|
|
|
+ <!-- <u-text type="info" align="center" text="微信一键登录" @click="quickLogin"></u-text> -->
|
|
|
+ </u-form-item>
|
|
|
+ </u-col>
|
|
|
+ </u-row>
|
|
|
+ </u--form>
|
|
|
|
|
|
- </view>
|
|
|
+ </view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import { setToken } from '@/common/auth.js'
|
|
|
- import { toast } from '@/common/common.js'
|
|
|
- import { login } from '@/api/login.js'
|
|
|
+ import { setToken } from '@/common/auth.js'
|
|
|
+ import { toast } from '@/common/common.js'
|
|
|
+ import { login } from '@/api/login.js'
|
|
|
|
|
|
- export default {
|
|
|
- data() {
|
|
|
- return {
|
|
|
- form: {
|
|
|
- username: '15143018065',
|
|
|
- password: 'sckj@2022',
|
|
|
- },
|
|
|
- rules: {
|
|
|
- username: [
|
|
|
- { required: true, message: '手机号不能为空', trigger: ['blur', 'change'] },
|
|
|
- { len: 11, message: '手机号应为11位数字', trigger: ['blur', 'change'] },
|
|
|
+ export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ form: {
|
|
|
+ username: '15143018065',
|
|
|
+ password: 'sckj@2022',
|
|
|
+ },
|
|
|
+ rules: {
|
|
|
+ username: [
|
|
|
+ { required: true, message: '手机号不能为空', trigger: ['blur', 'change'] },
|
|
|
+ { len: 11, message: '手机号应为11位数字', trigger: ['blur', 'change'] },
|
|
|
],
|
|
|
- password: [
|
|
|
- { required: true, message: '密码不能为空', trigger: ['blur', 'change'] },
|
|
|
- { min: 6, message: '密码长度应大于6位', trigger: ['blur', 'change'] },
|
|
|
+ password: [
|
|
|
+ { required: true, message: '密码不能为空', trigger: ['blur', 'change'] },
|
|
|
+ { min: 6, message: '密码长度应大于6位', trigger: ['blur', 'change'] },
|
|
|
]
|
|
|
- },
|
|
|
- }
|
|
|
- },
|
|
|
- onReady() {
|
|
|
- this.$refs.loginForm.setRules(this.rules)
|
|
|
- },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onReady() {
|
|
|
+ this.$refs.loginForm.setRules(this.rules)
|
|
|
+ },
|
|
|
|
|
|
- methods: {
|
|
|
- submitForm() {
|
|
|
- this.$refs.loginForm.validate().then(() => {
|
|
|
- login(this.form).then((res) => {
|
|
|
- if (res.code === 200) {
|
|
|
- const { data } = res
|
|
|
- setToken(data.access_token)
|
|
|
- uni.reLaunch({ url: '/pages/index/index' })
|
|
|
- } else {
|
|
|
- toast(res.msg)
|
|
|
- }
|
|
|
- })
|
|
|
- }).catch(() => {})
|
|
|
- },
|
|
|
- quickLogin() {
|
|
|
- console.log('quick login');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ methods: {
|
|
|
+ submitForm() {
|
|
|
+ this.$refs.loginForm.validate().then(() => {
|
|
|
+ uni.login({
|
|
|
+ provider: 'weixin',
|
|
|
+ success: (loginRes) => {
|
|
|
+ console.log(loginRes);
|
|
|
+ const params = {
|
|
|
+ ...this.form,
|
|
|
+ code: loginRes.code,
|
|
|
+ }
|
|
|
+ console.log(params);
|
|
|
+ login(params).then((res) => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ const { data } = res
|
|
|
+ setToken(data.access_token)
|
|
|
+ // uni.reLaunch({ url: '/pages/index/index' })
|
|
|
+ } else {
|
|
|
+ toast(res.msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }).catch(() => {})
|
|
|
+ },
|
|
|
+ quickLogin() {
|
|
|
+ console.log('quick login');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|