Răsfoiți Sursa

feat: 更换企业刷新页面

gatsby 1 lună în urmă
părinte
comite
81d419af82

+ 5 - 1
backend/tests/test_id.py

@@ -4,7 +4,7 @@
 
 import unittest
 
-from app.utils.snowflake import extract_tenant_id_from_id_str, get_snowflake_id_str
+from app.utils.snowflake import extract_tenant_id_from_id_str, get_snowflake_id_str, _get_snowflake_id
 
 
 class TestID(unittest.TestCase):
@@ -14,6 +14,10 @@ class TestID(unittest.TestCase):
         print(len(id))
         print(extract_tenant_id_from_id_str(id))
 
+    def test_id(self):
+        id = _get_snowflake_id()
+        print(id)
+
 
 if __name__ == "__main__":
     unittest.main()

+ 24 - 1
frontend/src/layouts/components/NavBar/components/EnterpriseSwitcher.vue

@@ -34,12 +34,16 @@ import { computed } from "vue";
 import { useEnterpriseStore } from "@/store/modules/enterprise.store";
 import { OfficeBuilding, ArrowDown, Check } from "@element-plus/icons-vue";
 
+const router = useRouter(); 
+const route = useRoute();
+
 const enterpriseStore = useEnterpriseStore();
 
 const currentEnterprise = computed(() => enterpriseStore.getCurrentEnterprise);
 const hasEnterprise = computed(() => enterpriseStore.hasEnterprise);
 const enterpriseList = computed(() => enterpriseStore.getEnterpriseList);
 
+
 // 在组件挂载或依赖变化时处理
 onMounted(() => {
   if (!currentEnterprise.value && hasEnterprise.value && enterpriseList.value.length > 0) {
@@ -55,7 +59,26 @@ onMounted(() => {
 // }, { immediate: true });
 
 function handleSwitch(enterpriseId: string) {
-  enterpriseStore.setCurrentEnterprise(enterpriseId);
+  const enterprise = enterpriseStore.findEnterpriseById(enterpriseId);
+  if (!enterprise) {
+    ElMessage.error('企业不存在~');
+    return;
+  }
+  
+  ElMessageBox.confirm(
+    `切换企业 【${enterprise.name}】,是否继续?`,
+    '确认切换',
+    {
+      confirmButtonText: '确定',
+      cancelButtonText: '取消',
+      type: 'warning'
+    }
+  ).then(() => {
+    enterpriseStore.setCurrentEnterprise(enterpriseId);
+    router.go(0);
+  }).catch(() => {
+    // 用户取消切换
+  });
 }
 </script>
 

+ 5 - 0
frontend/src/store/modules/enterprise.store.ts

@@ -21,6 +21,11 @@ export const useEnterpriseStore = defineStore("enterprise", {
   }),
 
   getters: {
+    findEnterpriseById(state) {
+      return (enterpriseId: string) => {
+        return state.enterpriseList.find((item) => item.enterprise_id === enterpriseId);
+      };
+    },
     getEnterpriseList(state) {
       // if (state.enterpriseList.length > 0) {
       //   return state.enterpriseList;

+ 15 - 1
frontend/src/views/module_payment/account/components/AccountOverview.vue

@@ -128,7 +128,7 @@
     </el-card>
 
     <el-row :gutter="16" class="mt-4">
-      <el-col :span="6">
+      <!-- <el-col :span="6">
         <el-card shadow="hover">
           <div class="stat-item">
             <div class="stat-label">签约状态</div>
@@ -139,6 +139,17 @@
             </div>
           </div>
         </el-card>
+      </el-col> -->
+
+      <el-col :span="6">
+        <el-card shadow="hover">
+          <div class="stat-item">
+            <div class="stat-label">当前企业</div>
+            <div class="stat-value text-truncate">
+              {{ currentEnterprise?.name || "-" }}
+            </div>
+          </div>
+        </el-card>
       </el-col>
 
       <el-col :span="6">
@@ -224,6 +235,7 @@ import { useEnterpriseStore } from "@/store/modules/enterprise.store";
 import AccountAPI from "@/api/module_payment/account";
 import { Refresh, Document, Coin, Wallet, Money } from "@element-plus/icons-vue";
 import { ref, computed, onMounted } from "vue";
+import en from "@/lang/package/en";
 
 const props = defineProps<{
   enterpriseId?: string;
@@ -249,6 +261,8 @@ const currentEnterpriseId = computed(
   () => props.enterpriseId || enterpriseStore.getCurrentEnterprise?.enterprise_id
 );
 
+const currentEnterprise = computed(() => enterpriseStore.getCurrentEnterprise);
+
 const authorizeStatus = computed(() =>
   accountData.value.account_book_id ? "AUTHORIZED" : "PENDING"
 );