123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <template>
- <view class="login-page">
- <uni-forms ref="loginForm" :model="form" :rules="rules">
- <uni-forms-item name="username">
- <uni-easyinput v-model="form.username" type="number" placeholder="请输入手机号" prefixIcon="account" :clearable="true" />
- </uni-forms-item>
- <uni-forms-item name="password">
- <uni-easyinput v-model="form.password" type="password" placeholder="请输入密码" prefixIcon="lock" :clearable="true" />
- </uni-forms-item>
- </uni-forms>
- <button type="primary" @click="submitForm">登录并绑定微信</button>
- </view>
- </template>
- <script>
- import { setToken } from '@/common/auth.js'
- import { login } from '@/api/login.js'
- import config from '@/config.js'
- export default {
- data() {
- return {
- form: {
- username: '15512341234', //15512341234
- password: 'sckj@2022', //sckj@2022
- },
- rules: {
- username: {
- rules: [
- { required: true, errorMessage: '手机号不能为空' },
- { format: 'number', errorMessage: '手机号应为数字' },
- ]
- },
- password: {
- rules: [
- { required: true, errorMessage: '密码不能为空' },
- ]
- }
- },
- }
- },
- methods: {
- submitForm() {
- this.$refs.loginForm.validate().then(() => {
- // #ifdef MP-WEIXIN
- uni.login({ // 获取用户登录凭证换取openid
- provider: 'weixin',
- success: (loginRes) => {
- const params = {
- ...this.form,
- code: loginRes.code,
- }
- login(params).then((res) => {
- const { code, data } = res
- if (code !== 200) return
- setToken(data.token.access_token)
- uni.setStorageSync('userInfo', data.sysUser)
- uni.reLaunch({ url: '/pages/index/index' })
- })
- }
- })
- // #endif
- }).catch(() => {})
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .login-page {
- width: 80%;
- margin: 35% auto;
- }
- </style>
|