Commit b39cfc25 authored by Jenny's avatar Jenny

feat: 登录页面

parent b6f322b5
const install = (Vue, vm) => { const install = (Vue, vm) => {
/*************** 认证 API *****************/ /*************** 认证 API *****************/
// 登录 // 登录
let authLogin = params => vm.$u.post('/api/auth/login', params) let quickLogin = params => vm.$u.post('/report/user/quickLogin', params)
vm.$u.api = { vm.$u.api = {
authLogin quickLogin
} }
} }
......
const install = (Vue, vm) => { const install = (Vue, vm) => {
Vue.prototype.$u.http.setConfig({ Vue.prototype.$u.http.setConfig({
baseUrl: 'https://api.shop.eduwork.cn', // 请求的本域名 baseUrl: 'https://api.charleskeith.cn/api', // 请求的本域名
showLoading: true, // 是否显示请求中的loading showLoading: true, // 是否显示请求中的loading
loadingText: '努力加载中。。。', // 请求loading中的文字提示 loadingText: '努力加载中。。。', // 请求loading中的文字提示
loadingTime: 300, // 在此时间内,请求还没回来的话,就显示加载中动画,单位ms loadingTime: 300, // 在此时间内,请求还没回来的话,就显示加载中动画,单位ms
......
<template> <template>
<view> <view class="wrap">
登录 <view class="content">
<u-form
ref="uForm"
:model="params"
:error-type="['toast']"
:label-width="120"
>
<u-form-item label="用户名" prop="userName">
<u-input
v-model="params.userName"
type="text"
/>
</u-form-item>
<u-form-item label="密码" prop="password">
<u-input
v-model="params.password"
type="password"
:password-icon="true"
/>
</u-form-item>
</u-form>
<u-button
class="my-u-block u-m-t-80"
type="warning"
shape="square"
:ripple="true"
@click="submit"
:disabled="!submitDisabled"
>登入</u-button>
</view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
params: {
appId: wx.getAccountInfoSync().miniProgram.appId,
userName: '',
password: ''
},
rules: {
userName: [
{ required: true, message: '请输入用户名', trigger: 'blur' }
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' }
]
}
}
},
computed: {
submitDisabled() {
return this.params.userName && this.params.password
} }
}, },
methods: { methods: {
submit() {
this.$refs.uForm.validate(async valid => {
if (valid) {
let res = await this.$u.api.quickLogin(this.params)
this.$u.vuex('vuex_token', `${res.token_type} ${res.access_token}`)
this.$u.toast('登录成功')
// 登录成功后返回来源页面
let timer = setTimeout(() => {
const backUrl = uni.getStorageSync('back_url') || '/pages/index/index'
this.$u.route({
type: 'reLaunch',
url: backUrl
})
clearTimeout(timer)
}, 500)
} else {
console.log('验证失败');
} }
})
} }
},
onReady() {
this.$refs.uForm.setRules(this.rules)
}
};
</script> </script>
<style> <style lang="scss" scoped>
</style> </style>
\ No newline at end of file
...@@ -17,3 +17,7 @@ ...@@ -17,3 +17,7 @@
} }
} }
} }
.my-u-block {
display: block;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment