jiangping
2023-08-17 8d7cb8876ac222eca1c82d5bab250f5551531edb
h5_standard/src/views/wxLogin.vue
@@ -7,86 +7,26 @@
            <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="企业代码" />
                    <input type="text" 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="手机号" />
                    <input type="text" 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="密码" />
                    <input type="text" placeholder="密码" />
                </div>
            </div>
            <div class="wx_login_footer">
                <div class="wx_login_footer_btn" @click="login">立即登录</div>
                <div class="wx_login_footer_btn">立即登录</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', 'DD')
            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', 'DD')
                        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>