fix(mobile): show real assignments on today page

This commit is contained in:
2026-07-09 13:24:19 +08:00
parent 03d9c93ea4
commit dd13936ca9
4 changed files with 62 additions and 16 deletions
+55 -13
View File
@@ -41,7 +41,7 @@
<button class="primary-button login-button" @click="goLogin">去登录</button>
</view>
<view class="section-card" v-else-if="home?.primary">
<view class="section-card" v-else-if="hasSchedule">
<view class="section-head">
<view class="section-title">
<text class="section-icon">日</text>
@@ -53,18 +53,18 @@
<view class="schedule-row">
<text class="step-dot blue">1</text>
<view class="schedule-copy">
<text class="schedule-title">每日小训:{{ home.primary.title.replace('三角色对练', '') }}</text>
<text class="schedule-desc">{{ home.primary.desc }}</text>
<text class="schedule-title">{{ primaryScheduleTitle }}</text>
<text class="schedule-desc">{{ primaryScheduleDesc }}</text>
</view>
<button class="schedule-action blue-action" @click="openTool(home.primary.cta)">开始</button>
<button class="schedule-action blue-action" @click="openPrimarySchedule">开始</button>
</view>
<view class="schedule-row" v-if="home.review">
<view class="schedule-row" v-if="home?.review">
<text class="step-dot orange">2</text>
<view class="schedule-copy">
<text class="schedule-title">今日复习:{{ home.review.title }}</text>
<text class="schedule-desc">{{ home.review.desc }}</text>
<text class="schedule-title">今日复习:{{ home?.review?.title }}</text>
<text class="schedule-desc">{{ home?.review?.desc }}</text>
</view>
<button class="schedule-action orange-action" @click="ask(home.review.title)">去复习</button>
<button class="schedule-action orange-action" @click="ask(home?.review?.title || '岗前SOP复习')">去复习</button>
</view>
</view>
</view>
@@ -106,11 +106,13 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import type { RoleHome } from '@/types/api';
import type { PracticeAssignment, RoleHome } from '@/types/api';
import { getMobileHome } from '@/services/home';
import { getPracticeAssignments } from '@/services/practice';
import { getAuth, isLoggedIn, rememberLoginRedirect } from '@/services/auth';
const home = ref<RoleHome | null>(null);
const assignments = ref<PracticeAssignment[]>([]);
const message = ref('');
const loggedIn = ref(false);
const quickQuestions = ['催费话术', '投诉应对', '收费标准'];
@@ -140,6 +142,26 @@ const mapTiles = computed(() => {
}));
});
const primaryAssignment = computed(() =>
assignments.value.find((item) => item.status === '待训练' && item.source !== 'daily')
|| assignments.value.find((item) => item.status === '待训练')
|| null
);
const hasSchedule = computed(() => Boolean(primaryAssignment.value || home.value?.primary || home.value?.review));
const primaryScheduleTitle = computed(() => {
const item = primaryAssignment.value;
if (item) {
return item.source === 'daily'
? `每日三题:${item.question || item.scenarioName}`
: `专项训练:${item.scenarioName || item.question}`;
}
return `每日小训:${home.value?.primary?.title.replace('三角色对练', '') || '场景练习'}`;
});
const primaryScheduleDesc = computed(() => {
const item = primaryAssignment.value;
if (item) return item.source === 'daily' ? '提交后显示反馈与参考答案' : (item.reason || '主管指派专项训练');
return home.value?.primary?.desc || '进入练习页查看今日任务';
});
const mentorName = computed(() => {
if (!loggedIn.value) return '同事';
const phone = getAuth().phone.trim();
@@ -153,15 +175,31 @@ const mentorBubbleText = computed(() =>
const loadHome = async () => {
loggedIn.value = isLoggedIn();
message.value = '';
assignments.value = [];
if (!loggedIn.value) {
home.value = null;
return;
}
try {
home.value = await getMobileHome('user');
} catch (error) {
const [homeResult, assignmentResult] = await Promise.allSettled([
getMobileHome('user'),
getPracticeAssignments(true)
]);
if (homeResult.status === 'fulfilled') {
home.value = homeResult.value;
} else {
home.value = null;
message.value = error instanceof Error ? error.message : '首页数据加载失败';
message.value = homeResult.reason instanceof Error ? homeResult.reason.message : '首页数据加载失败';
}
if (assignmentResult.status === 'fulfilled') {
assignments.value = assignmentResult.value;
} else {
loggedIn.value = isLoggedIn();
if (!loggedIn.value) {
home.value = null;
message.value = '登录已过期,请重新登录';
return;
}
message.value = assignmentResult.reason instanceof Error ? assignmentResult.reason.message : '今日任务加载失败';
}
};
@@ -179,6 +217,10 @@ const goLogin = () => {
uni.navigateTo({ url: '/pages/auth/login/index' });
};
const openPrimarySchedule = () => {
uni.switchTab({ url: '/pages/user/practice/index' });
};
const openTool = (title: string) => {
if (title.includes('问') || title.includes('SOP') || title.includes('sop')) {
goSop();
+3 -1
View File
@@ -4,6 +4,7 @@ import uniPlugin from '@dcloudio/vite-plugin-uni';
const uni = typeof uniPlugin === 'function' ? uniPlugin : uniPlugin.default;
const devPort = Number(process.env.PORT) || 5175;
const devHost = process.env.HOST || '0.0.0.0';
const proxyTarget = process.env.VITE_PROXY_TARGET || 'https://wygj-api.localhost';
export default defineConfig({
plugins: [uni()],
@@ -13,8 +14,9 @@ export default defineConfig({
strictPort: true,
proxy: {
'/dev-api': {
target: 'http://127.0.0.1:8080',
target: proxyTarget,
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/dev-api/, '')
}
}