feat: load all public packages without org_id for guest storefront
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -94,8 +94,11 @@ export default defineComponent({
|
|||||||
} else if (isLoggedIn()) {
|
} else if (isLoggedIn()) {
|
||||||
const ok = await queryOrgPackages();
|
const ok = await queryOrgPackages();
|
||||||
state.error = !ok;
|
state.error = !ok;
|
||||||
|
} else {
|
||||||
|
// Guest, no org_id: load all public packages across all orgs
|
||||||
|
const ok = await queryPublicPackages();
|
||||||
|
state.error = !ok;
|
||||||
}
|
}
|
||||||
// No orgId and unauth: show empty state, not error
|
|
||||||
state.loading = false;
|
state.loading = false;
|
||||||
state.loaded = true;
|
state.loaded = true;
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-7
@@ -18,8 +18,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<van-empty v-else description="账号未启用或未通过注册审核" />
|
<van-empty v-else description="账号未启用或未通过注册审核" />
|
||||||
</template>
|
</template>
|
||||||
<course-package-store v-if="!has_login && urlOrgId" />
|
<course-package-store v-if="!has_login" />
|
||||||
<van-empty v-if="!has_login && !urlOrgId" description="请返回微信小程序完成登录" />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -128,10 +127,6 @@ export default defineComponent({
|
|||||||
{ value: HtyBaseRoles.TEACHER, label: "老师" },
|
{ value: HtyBaseRoles.TEACHER, label: "老师" },
|
||||||
];
|
];
|
||||||
const has_login = computed(() => !!store.current.hty_id);
|
const has_login = computed(() => !!store.current.hty_id);
|
||||||
const urlOrgId = computed(() => {
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
|
||||||
return params.get('org_id') || '';
|
|
||||||
});
|
|
||||||
const is_registered = computed(() => store.current.is_registered);
|
const is_registered = computed(() => store.current.is_registered);
|
||||||
const is_enabled = computed(() => store.current.enabled);
|
const is_enabled = computed(() => store.current.enabled);
|
||||||
const authorized = computed(() => userStatus === UserStates.Authorized);
|
const authorized = computed(() => userStatus === UserStates.Authorized);
|
||||||
@@ -194,7 +189,7 @@ export default defineComponent({
|
|||||||
return {
|
return {
|
||||||
is_registered, is_enabled, is_student, has_teacher,
|
is_registered, is_enabled, is_student, has_teacher,
|
||||||
has_login, authorized, activeRoles, chooseRole, setRole, store,
|
has_login, authorized, activeRoles, chooseRole, setRole, store,
|
||||||
initial_roles, scene, urlOrgId
|
initial_roles, scene
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,9 +37,10 @@ export default function useCoursePackage() {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function queryPublicPackages(orgId: string, keyword?: string, page = 1, pageSize = 20): Promise<boolean> {
|
async function queryPublicPackages(orgId?: string, keyword?: string, page = 1, pageSize = 20): Promise<boolean> {
|
||||||
load_start();
|
load_start();
|
||||||
const params = new URLSearchParams({org_id: orgId, page: String(page), page_size: String(pageSize)});
|
const params = new URLSearchParams({page: String(page), page_size: String(pageSize)});
|
||||||
|
if (orgId) params.set('org_id', orgId);
|
||||||
if (keyword) params.set('keyword', keyword);
|
if (keyword) params.set('keyword', keyword);
|
||||||
const {r, d, e} = await request({url: `/api/v1/clazz/course-package/public-packages?${params}`});
|
const {r, d, e} = await request({url: `/api/v1/clazz/course-package/public-packages?${params}`});
|
||||||
load_done();
|
load_done();
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"status": "failed",
|
||||||
|
"failedTests": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import { expect, test } from './fixtures';
|
||||||
|
|
||||||
|
const moicenUnionid = process.env.MOICEN_E2E_UNIONID?.trim();
|
||||||
|
|
||||||
|
test('debug role switcher visibility', async ({ page }) => {
|
||||||
|
test.setTimeout(120_000);
|
||||||
|
|
||||||
|
const q = new URLSearchParams({ unionid: moicenUnionid!, status: '2' });
|
||||||
|
await page.goto(`/?${q.toString()}`, {
|
||||||
|
waitUntil: 'domcontentloaded',
|
||||||
|
timeout: 60_000,
|
||||||
|
});
|
||||||
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
||||||
|
await page.waitForTimeout(5000);
|
||||||
|
|
||||||
|
const roleSelect = page.getByText('请选择您的登录身份');
|
||||||
|
if (await roleSelect.isVisible().catch(() => false)) {
|
||||||
|
const studentRole = page.locator('.van-grid-item').filter({ hasText: '学生' });
|
||||||
|
if (await studentRole.isVisible().catch(() => false)) {
|
||||||
|
await studentRole.click();
|
||||||
|
await page.waitForTimeout(5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page.url().includes('/org/select')) {
|
||||||
|
const orgCells = page.locator('#app .van-cell-group .van-cell');
|
||||||
|
const n = await orgCells.count();
|
||||||
|
console.log(`org cells count: ${n}`);
|
||||||
|
expect(n).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
// Check token before org select
|
||||||
|
const tokenBefore = await page.evaluate(() => window.localStorage.getItem('Authorization'));
|
||||||
|
console.log(`token before org select: ${tokenBefore ? 'EXISTS' : 'NONE'}`);
|
||||||
|
|
||||||
|
await orgCells.first().click();
|
||||||
|
await page.waitForTimeout(5000);
|
||||||
|
|
||||||
|
// Check URL and token after org select
|
||||||
|
console.log(`URL after org select click + wait: ${page.url()}`);
|
||||||
|
const tokenAfter = await page.evaluate(() => window.localStorage.getItem('Authorization'));
|
||||||
|
console.log(`token after org select: ${tokenAfter ? 'EXISTS' : 'NONE'}`);
|
||||||
|
const currentRole = await page.evaluate(() => window.localStorage.getItem('CurrentUserRole'));
|
||||||
|
console.log(`CurrentUserRole: ${currentRole}`);
|
||||||
|
const teacherId = await page.evaluate(() => window.localStorage.getItem('CurrentTeacherId'));
|
||||||
|
console.log(`CurrentTeacherId: ${teacherId}`);
|
||||||
|
|
||||||
|
await page.goto('/student/profile', {
|
||||||
|
waitUntil: 'domcontentloaded',
|
||||||
|
timeout: 60_000,
|
||||||
|
});
|
||||||
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
||||||
|
|
||||||
|
// Immediately check URL after navigation
|
||||||
|
console.log(`URL right after navigating to /student/profile: ${page.url()}`);
|
||||||
|
const tokenNav = await page.evaluate(() => window.localStorage.getItem('Authorization'));
|
||||||
|
console.log(`token after navigate: ${tokenNav ? 'EXISTS' : 'NONE'}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
console.log(`URL after 2s: ${page.url()}`);
|
||||||
|
|
||||||
|
// Check full state
|
||||||
|
const state = await page.evaluate(() => {
|
||||||
|
const keys = Object.keys(window.localStorage);
|
||||||
|
const store: Record<string, string | null> = {};
|
||||||
|
for (const k of keys) store[k] = window.localStorage.getItem(k);
|
||||||
|
return store;
|
||||||
|
});
|
||||||
|
console.log(`localStorage keys: ${JSON.stringify(Object.keys(state))}`);
|
||||||
|
console.log(`Authorization: ${state['Authorization'] ? 'EXISTS' : 'NONE'}`);
|
||||||
|
|
||||||
|
const els = await page.evaluate(() => {
|
||||||
|
const result: string[] = [];
|
||||||
|
document.querySelectorAll('.van-icon').forEach(el => {
|
||||||
|
result.push(el.className);
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
console.log(`icons: ${JSON.stringify(els)}`);
|
||||||
|
|
||||||
|
const profileInfo = await page.locator('.info').isVisible().catch(() => false);
|
||||||
|
console.log(`profile .info visible: ${profileInfo}`);
|
||||||
|
|
||||||
|
const roleSwitcher = await page.locator('.van-icon-exchange').isVisible().catch(() => false);
|
||||||
|
console.log(`role switcher visible: ${roleSwitcher}`);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user