From b15a83329e33a954f41c9558b58aa1a64332c46b Mon Sep 17 00:00:00 2001
From: Mr.Shi <1878285526@qq.com>
Date: 星期五, 11 八月 2023 18:04:51 +0800
Subject: [PATCH] 标准版h5

---
 h5_standard/src/views/wxLogin.vue |   68 ++++++++++++++++++++++++++++++++--
 1 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/h5_standard/src/views/wxLogin.vue b/h5_standard/src/views/wxLogin.vue
index 44af9fb..87c9825 100644
--- a/h5_standard/src/views/wxLogin.vue
+++ b/h5_standard/src/views/wxLogin.vue
@@ -7,26 +7,86 @@
             <div class="wx_login_list">
                 <div class="wx_login_list_item">
                     <img src="@/assets/icon/login_ic_code@2x.png" alt="" />
-                    <input type="text" placeholder="浼佷笟浠g爜" />
+                    <input type="text" v-model="from.companyId" placeholder="浼佷笟浠g爜" />
                 </div>
                 <div class="wx_login_list_item">
                     <img src="@/assets/icon/login_ic_phone@2x.png" alt="" />
-                    <input type="text" placeholder="鎵嬫満鍙�" />
+                    <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="text" placeholder="瀵嗙爜" />
+                    <input type="password" v-model="from.password" placeholder="瀵嗙爜" />
                 </div>
             </div>
             <div class="wx_login_footer">
-                <div class="wx_login_footer_btn">绔嬪嵆鐧诲綍</div>
+                <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('浼佷笟浠g爜涓嶈兘涓虹┖')
+    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>

--
Gitblit v1.9.3