|
@@ -1,4 +1,5 @@
|
|
|
import { ref } from 'vue';
|
|
import { ref } from 'vue';
|
|
|
|
|
+import { useUserInfo } from '/@/stores/userInfo';
|
|
|
import { loadOrgList, type OrgOption } from '../api/s0SalesApi';
|
|
import { loadOrgList, type OrgOption } from '../api/s0SalesApi';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -59,12 +60,37 @@ function isEmptyScopeValue(v: unknown): boolean {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 从已加载组织列表按 code 求默认归属;取不到默认组织时返回空对象(不脑补 id/domainCode)。
|
|
|
|
|
- * domainCode 口径沿用页面既有约定:新记录取工厂 code。
|
|
|
|
|
|
|
+ * 兜底归属:当前登录租户自身的组织 Id(sysAuth/userInfo 的 orgId)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 适用于未铺设 S0-C001 / S0-F001 种子组织的租户(如 UAT 系列):这类租户的
|
|
|
|
|
+ * SysOrg 只有一个未标 Type 的根节点,公司(201)/工厂(501) 下拉均为空,
|
|
|
|
|
+ * 新增时取不到默认归属,会被后端 [Range(1, long.MaxValue)] 必填校验拦下。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 取 orgId 而非 tenantId:这些租户既有 S0 数据的 company_ref_id / factory_ref_id
|
|
|
|
|
+ * 存的就是本值(SysTenant.OrgId),沿用可与既有数据保持同一口径,不引入新值。
|
|
|
|
|
+ */
|
|
|
|
|
+function getCurrentTenantOrgId(): string | undefined {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const orgId = useUserInfo().userInfos?.orgId;
|
|
|
|
|
+ if (orgId == null || orgId === '' || orgId === '0') return undefined;
|
|
|
|
|
+ return String(orgId);
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ // store 未就绪(例如单测直接调用本函数)时不阻断,退回无默认归属。
|
|
|
|
|
+ return undefined;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 从已加载组织列表按 code 求默认归属;取不到种子组织时回落到当前租户自身组织。
|
|
|
|
|
+ * 两者都取不到才返回空对象(不脑补 id/domainCode)。
|
|
|
|
|
+ * domainCode 口径沿用页面既有约定:新记录取工厂 code;兜底路径下不臆造,留空。
|
|
|
*/
|
|
*/
|
|
|
export function getDefaultS0OrgScope(companyOptions: OrgOption[], factoryOptions: OrgOption[]): S0OrgScope {
|
|
export function getDefaultS0OrgScope(companyOptions: OrgOption[], factoryOptions: OrgOption[]): S0OrgScope {
|
|
|
const company = companyOptions.find((item) => item.code === S0_DEFAULT_COMPANY_CODE);
|
|
const company = companyOptions.find((item) => item.code === S0_DEFAULT_COMPANY_CODE);
|
|
|
- if (!company) return {};
|
|
|
|
|
|
|
+ if (!company) {
|
|
|
|
|
+ const tenantOrgId = getCurrentTenantOrgId();
|
|
|
|
|
+ return tenantOrgId ? { companyRefId: tenantOrgId, factoryRefId: tenantOrgId } : {};
|
|
|
|
|
+ }
|
|
|
const factory = factoryOptions.find((item) => item.code === S0_DEFAULT_FACTORY_CODE && item.pid === company.id);
|
|
const factory = factoryOptions.find((item) => item.code === S0_DEFAULT_FACTORY_CODE && item.pid === company.id);
|
|
|
return {
|
|
return {
|
|
|
companyRefId: company.id,
|
|
companyRefId: company.id,
|