Mr.Zhang
2023-08-17 b32971b510810d697481bc677249d100de007059
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<template>
    <view class="content">
        <view class="p40 nav bbox">
            <view class="">合肥市智改数转诊断服务平台</view>
            <view class="">欢迎登录</view>
        </view>
        <view class="p40 mt30">
            <u--input
                placeholder="请输入账号"
                prefixIcon="account"
                clearable
                v-model="form.account"
                prefixIconStyle="font-size: 40rpx;color: #AAAAAA"
            ></u--input>
            <view class="p20"></view>
            <u--input
                placeholder="请输入密码"
                prefixIcon="lock"
                password
                clearable
                v-model="form.password"
                prefixIconStyle="font-size: 40rpx;color: #AAAAAA"
            ></u--input>
            <view class="ptb50"></view>
            <u-button
                :loading="logining"
                type="primary"
                color="#216EEE"
                text="登录"
                size="large"
                @click="loginAction"
            ></u-button>
        </view>
        
    </view>
</template>
 
<script>
    
    import { coustomLogin, wxEmpower } from '@/util/api/index'
    export default {
        data() {
            return {
                form: {
                    account: '',
                    password: '',
                },
                logining: false,
                openId: ''
            }
        },
        onLoad() {
            uni.login({
                success: data => {
                    this.wxLogin(data.code)
                },
                fail: err => {
                    uni.$u.toast(err)
                }
            })
        },
        methods: {
            loginAction() {
                if (!this.form.account || !this.form.password) {
                    uni.$u.toast('账号或者密码不能为空')
                }
                this.logining = true
                coustomLogin({...this.form, openid: this.openId})
                    .then(res => {
                        this.$store.commit('SETTOKEN', res.token)
                        this.$store.commit('SETUSERINFO', res)
                        uni.navigateTo({
                            url:'/pages/projectList/projectList'
                        })
                    })
                    .finally(() => {
                        this.logining = false
                    })
            },
            wxLogin(code) {
                wxEmpower({code})
                    .then(res => {
                        this.openId = res.openid
                        if (res.userInfo) {
                            this.$store.commit('SETTOKEN', res.userInfo.token)
                            this.$store.commit('SETUSERINFO', res.userInfo)
                            uni.navigateTo({
                                url:'/pages/projectList/projectList'
                            })
                        } 
                    })
                    .catch(err => {
                        uni.$u.toast(err)
                    })
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .content {
        // display: flex;
        // flex-direction: column;
        // align-items: center;
        // justify-content: center;
        height: 100vh;
        background-color: #FFFFFF;
        .nav {
            
            width: 750rpx;
            height: 520rpx;
            background: linear-gradient(180deg, #C7EBFF 0%, #FFFFFF 100%);
            display: flex;
            flex-direction: column-reverse;
            color: #293C5B;
            :first-child {
                height: 52rpx;
                font-size: 36rpx;
                line-height: 52rpx;
            }
            :last-child {
                height: 80rpx;
                font-size: 56rpx;
                font-weight: 500;
                line-height: 80rpx;
                margin-bottom: 16rpx;
            }
        }
    }
 
    .logo {
        height: 200rpx;
        width: 200rpx;
        margin-top: 200rpx;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 50rpx;
    }
 
    .text-area {
        display: flex;
        justify-content: center;
    }
 
    .title {
        font-size: 36rpx;
        color: #8f8f94;
    }
</style>