bug
jiangping
2023-12-06 1f4e7d0f73a73e7350cf5a1df279d5f30904c5d5
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<template>
    <div class="wx">
        <img class="wx_bg" src="@/assets/background/login_bg@2x.png" alt="" />
        <div class="wx_login">
            <img class="wx_login_icon" src="@/assets/icon/logo@2x.png" alt="" />
            <span>DM云工厂</span>
            <div class="wx_login_list">
                <div class="wx_login_list_item">
                    <img src="@/assets/icon/login_ic_code@2x.png" alt="" />
                    <input type="text" v-model="from.companyId" placeholder="企业代码" />
                </div>
                <div class="wx_login_list_item">
                    <img src="@/assets/icon/login_ic_phone@2x.png" alt="" />
                    <input type="text" maxlength="11" v-model="from.username" placeholder="手机号" />
                </div>
                <div class="wx_login_list_item">
                    <img src="@/assets/icon/login_ic_password@2x.png" alt="" />
                    <input type="password" v-model="from.password" placeholder="密码" />
                </div>
            </div>
            <div class="wx_login_footer">
                <div class="wx_login_footer_btn" @click="login">立即登录</div>
            </div>
        </div>
    </div>
</template>
 
<script setup lang="ts">
import { onMounted, reactive } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useStore } from 'vuex';
import { wxLogin, wxAccountLogin, getUserInfo } from '@/apis/index';
import { Toast } from 'vant';
 
const route = useRoute()
const router = useRouter()
const store = useStore()
 
let from: any = reactive({
    openid: '',
    unionid: '',
    companyId: '',
    username: '',
    password: ''
})
 
const login = async () => {
    // if (!from.openid) return Toast('openid不能为空')
    // if (!from.unionid) return Toast('unionid不能为空')
    if (!from.companyId) return Toast('企业代码不能为空')
    if (!from.username) return Toast('手机号不能为空')
    if (!from.password) return Toast('密码不能为空')
    Toast.loading({
        message: '登录中...',
        forbidClick: true
    });
    let res = await wxAccountLogin(from)
    if (res.code === 200) {
        let info = await getUserInfo()
        if (info.code === 200) {
            await store.commit('setEntrance', 'WX')
            await store.commit('setUserInfo', info.data)
            await store.dispatch('getMenuList', 2)
            await router.replace('/workbench')
        }
    }
    Toast.clear();
}
 
onMounted(() => {
    wxLogin({ code: route.query.code })
        .then(async (res) => {
            if (res.code === 200) {
                // 免登录,直接跳首页
                if (res.data.loginStatus == 0) {
                    let info = await getUserInfo()
                    if (info.code === 200) {
                        await store.commit('setEntrance', 'WX')
                        await store.commit('setUserInfo', info.data)
                        await store.dispatch('getMenuList', 2)
                        await router.replace('/workbench')
                    }
                } else {
                    from.openid = res.data.openid
                    from.unionid = res.data.unionid
                }
            }
        })
})
</script>
 
<style lang="scss" scoped>
    .wx {
        width: 100vw;
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #FFFFFF linear-gradient(180deg, rgba(66,117,252,0.2) 0%, rgba(66,117,252,0) 100%);
        .wx_bg {
            width: 100vw;
            height: 812px;
            position: fixed;
            top: 0;
            left: 0;
        }
        .wx_login {
            width: 100vw;
            height: auto;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            .wx_login_icon {
                width: 180px;
                height: 180px;
            }
            span {
                font-size: 44px;
                font-family: PingFangSC-Semibold, PingFang SC;
                font-weight: 600;
                color: #333333;
                margin-top: 40px;
            }
            .wx_login_list {
                width: 100vw;
                padding: 0 60px;
                box-sizing: border-box;
                margin-top: 80px;
                position: relative;
                z-index: 9;
                .wx_login_list_item {
                    width: 100%;
                    height: 98px;
                    background: #FFFFFF;
                    border-radius: 8px;
                    padding: 0 40px;
                    box-sizing: border-box;
                    display: flex;
                    align-items: center;
                    margin-bottom: 40px;
                    &:last-child {
                        margin-bottom: 0 !important;
                    }
                    img {
                        width: 40px;
                        height: 40px;
                        flex-shrink: 0;
                        margin-right: 24px;
                    }
                    input::-webkit-input-placeholder {
                        font-size: 30px;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #B7BBC5;
                    }
                    input {
                        flex: 1;
                        height: 100%;
                        padding: 0 !important;
                        font-size: 30px;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #222222;
                        border: none;
                        outline: none;
                    }
                }
            }
            .wx_login_footer {
                width: 100vw;
                padding: 0 60px;
                box-sizing: border-box;
                margin-top: 80px;
                .wx_login_footer_btn {
                    width: 100%;
                    height: 98px;
                    line-height: 98px;
                    text-align: center;
                    background: #4275FC;
                    box-shadow: 0px 12px 24px 0px rgba(66,117,252,0.2);
                    border-radius: 8px;
                    font-size: 32px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #FFFFFF;
                }
            }
        }
    }
</style>