智能开屏:显示“姓名+早上/中午/下午/晚上问候”,支持春节、端午、中秋、国庆等节日文案,可点击跳过:[SmartLaunchScreen.vue](E:/jiaowu/web/src/components/SmartLaunchScreen.vue)
长按 App 图标:提供“我的课表、考试安排、课堂签到、消息中心”四个入口。签到会按学生/教师角色自动分流:[shortcuts.xml](E:/jiaowu/web/native/android/app/src/main/res/xml/shortcuts.xml) 桌面小组件:新增“今日课表”和“近期考试”,展示最近同步的数据,点击可进入对应页面:[WidgetRenderer.java](E:/jiaowu/web/native/android/app/src/main/java/edu/mingxu/jiaowu/WidgetRenderer.java) 安全处理:组件只缓存课程和考试摘要,不保存登录令牌;退出账号会清空组件,隔天未刷新时不会继续展示旧的“今日课表”。 原生模板已纳入版本管理,每次 npm run cap:sync 会自动恢复到被忽略的 Android 工程:[configure-capacitor.mjs](E:/jiaowu/web/scripts/configure-capacitor.mjs)
This commit is contained in:
@@ -93,6 +93,22 @@ SHA-256,下次启动时切换。新资源若未能成功启动,原生更新
|
||||
更新版本元数据和 ZIP 保存在数据库中,部署新服务端版本前必须先执行
|
||||
`--migrate-only`。
|
||||
|
||||
### Android 开屏、快捷入口与桌面组件
|
||||
|
||||
Android App 在系统静态启动页之后显示智能问候:优先使用当前登录姓名和春节、端午、
|
||||
中秋、国庆等节日文案,其次按早上、中午、下午和晚上展示问候;轻触可立即跳过,并
|
||||
遵守系统“减少动画”设置。
|
||||
|
||||
长按 App 图标提供“我的课表、考试安排、课堂签到、消息中心”四个快捷入口。“课堂
|
||||
签到”会按当前角色将学生带到扫码/定位签到,将教师带到发起签到。桌面组件提供“今日
|
||||
课表”和“近期考试”,展示 App 最近一次成功加载并安全写入 Android 本地缓存的数据;
|
||||
退出账号时会清空组件,跨日且尚未打开 App 刷新时不会继续展示过期的今日课表。
|
||||
|
||||
原生 Java、清单和组件资源模板保存在 `web/native/android`。每次运行
|
||||
`npm run cap:sync` 后,`configure-capacitor.mjs` 会把模板同步到被 Git 忽略的
|
||||
`web/android` 生成目录。上述能力涉及 Android 原生代码,首次加入或以后修改时必须
|
||||
重新构建 App,不能通过前端 OTA 单独下发。
|
||||
|
||||
## MySQL 8.4 生产部署
|
||||
|
||||
非 Development 环境只允许使用 MySQL。构建发布包与数据库配置相互独立:
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation|density"
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/title_activity_main"
|
||||
android:theme="@style/AppTheme.NoActionBarLaunch"
|
||||
android:launchMode="singleTask"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="mingxu" android:host="open" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcuts" />
|
||||
|
||||
</activity>
|
||||
|
||||
<receiver
|
||||
android:name=".ScheduleWidgetProvider"
|
||||
android:exported="false"
|
||||
android:label="@string/widget_schedule_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/schedule_widget_info" />
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".ExamWidgetProvider"
|
||||
android:exported="false"
|
||||
android:label="@string/widget_exam_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/exam_widget_info" />
|
||||
</receiver>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths"></meta-data>
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
<!-- Permissions -->
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
|
||||
</manifest>
|
||||
@@ -0,0 +1,16 @@
|
||||
package edu.mingxu.jiaowu;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.Context;
|
||||
|
||||
public class ExamWidgetProvider extends AppWidgetProvider {
|
||||
@Override
|
||||
public void onUpdate(
|
||||
Context context,
|
||||
AppWidgetManager appWidgetManager,
|
||||
int[] appWidgetIds
|
||||
) {
|
||||
WidgetRenderer.updateExams(context, appWidgetManager, appWidgetIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package edu.mingxu.jiaowu;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.getcapacitor.BridgeActivity;
|
||||
import com.getcapacitor.JSObject;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class MainActivity extends BridgeActivity {
|
||||
private static final Set<String> SHORTCUT_ROUTES =
|
||||
new HashSet<>(Arrays.asList(
|
||||
"timetable",
|
||||
"exams",
|
||||
"attendance",
|
||||
"notifications"));
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
registerPlugin(NativeHomePlugin.class);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
dispatchShortcut(intent);
|
||||
}
|
||||
|
||||
private void dispatchShortcut(Intent intent) {
|
||||
Uri data = intent == null ? null : intent.getData();
|
||||
if (data == null ||
|
||||
!"mingxu".equals(data.getScheme()) ||
|
||||
!"open".equals(data.getHost())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String route = data.getLastPathSegment();
|
||||
if (route == null || !SHORTCUT_ROUTES.contains(route)) {
|
||||
return;
|
||||
}
|
||||
|
||||
NativeHomePlugin.savePendingRoute(this, route);
|
||||
if (bridge != null) {
|
||||
JSObject detail = new JSObject();
|
||||
detail.put("route", route);
|
||||
bridge.triggerWindowJSEvent("mingxuShortcut", detail.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package edu.mingxu.jiaowu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.getcapacitor.JSObject;
|
||||
import com.getcapacitor.Plugin;
|
||||
import com.getcapacitor.PluginCall;
|
||||
import com.getcapacitor.PluginMethod;
|
||||
import com.getcapacitor.annotation.CapacitorPlugin;
|
||||
|
||||
@CapacitorPlugin(name = "NativeHome")
|
||||
public class NativeHomePlugin extends Plugin {
|
||||
static final String PREFERENCES = "mingxu_native_home";
|
||||
static final String WIDGET_PAYLOAD = "widget_payload";
|
||||
private static final String PENDING_ROUTE = "pending_route";
|
||||
|
||||
@PluginMethod
|
||||
public void updateWidgets(PluginCall call) {
|
||||
JSObject payload = call.getObject("payload");
|
||||
if (payload == null) {
|
||||
call.reject("缺少桌面组件数据。");
|
||||
return;
|
||||
}
|
||||
|
||||
preferences(getContext()).edit()
|
||||
.putString(WIDGET_PAYLOAD, payload.toString())
|
||||
.apply();
|
||||
WidgetRenderer.updateAll(getContext());
|
||||
call.resolve();
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void clearWidgets(PluginCall call) {
|
||||
preferences(getContext()).edit()
|
||||
.remove(WIDGET_PAYLOAD)
|
||||
.apply();
|
||||
WidgetRenderer.updateAll(getContext());
|
||||
call.resolve();
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
public void getLaunchRoute(PluginCall call) {
|
||||
SharedPreferences preferences = preferences(getContext());
|
||||
String route = preferences.getString(PENDING_ROUTE, null);
|
||||
preferences.edit().remove(PENDING_ROUTE).apply();
|
||||
JSObject result = new JSObject();
|
||||
if (route != null) {
|
||||
result.put("route", route);
|
||||
}
|
||||
call.resolve(result);
|
||||
}
|
||||
|
||||
static void savePendingRoute(Context context, String route) {
|
||||
preferences(context).edit().putString(PENDING_ROUTE, route).apply();
|
||||
}
|
||||
|
||||
static SharedPreferences preferences(Context context) {
|
||||
return context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package edu.mingxu.jiaowu;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.Context;
|
||||
|
||||
public class ScheduleWidgetProvider extends AppWidgetProvider {
|
||||
@Override
|
||||
public void onUpdate(
|
||||
Context context,
|
||||
AppWidgetManager appWidgetManager,
|
||||
int[] appWidgetIds
|
||||
) {
|
||||
WidgetRenderer.updateSchedule(context, appWidgetManager, appWidgetIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package edu.mingxu.jiaowu;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
final class WidgetRenderer {
|
||||
private static final int[] ROWS = {
|
||||
R.id.widget_row_one,
|
||||
R.id.widget_row_two,
|
||||
R.id.widget_row_three
|
||||
};
|
||||
private static final int[] TIMES = {
|
||||
R.id.widget_time_one,
|
||||
R.id.widget_time_two,
|
||||
R.id.widget_time_three
|
||||
};
|
||||
private static final int[] TITLES = {
|
||||
R.id.widget_item_title_one,
|
||||
R.id.widget_item_title_two,
|
||||
R.id.widget_item_title_three
|
||||
};
|
||||
private static final int[] SUBTITLES = {
|
||||
R.id.widget_item_subtitle_one,
|
||||
R.id.widget_item_subtitle_two,
|
||||
R.id.widget_item_subtitle_three
|
||||
};
|
||||
|
||||
private WidgetRenderer() {}
|
||||
|
||||
static void updateAll(Context context) {
|
||||
AppWidgetManager manager = AppWidgetManager.getInstance(context);
|
||||
int[] scheduleIds = manager.getAppWidgetIds(
|
||||
new ComponentName(context, ScheduleWidgetProvider.class));
|
||||
int[] examIds = manager.getAppWidgetIds(
|
||||
new ComponentName(context, ExamWidgetProvider.class));
|
||||
updateSchedule(context, manager, scheduleIds);
|
||||
updateExams(context, manager, examIds);
|
||||
}
|
||||
|
||||
static void updateSchedule(
|
||||
Context context,
|
||||
AppWidgetManager manager,
|
||||
int[] appWidgetIds
|
||||
) {
|
||||
JSONObject payload = payload(context);
|
||||
JSONArray items = payload.optJSONArray("schedule");
|
||||
boolean current = LocalDate.now().toString()
|
||||
.equals(payload.optString("scheduleDate"));
|
||||
render(
|
||||
context,
|
||||
manager,
|
||||
appWidgetIds,
|
||||
payload,
|
||||
current ? items : new JSONArray(),
|
||||
"今日课表",
|
||||
current ? "今天没有课程" : "打开 App 刷新今日课表",
|
||||
"timetable",
|
||||
1101);
|
||||
}
|
||||
|
||||
static void updateExams(
|
||||
Context context,
|
||||
AppWidgetManager manager,
|
||||
int[] appWidgetIds
|
||||
) {
|
||||
JSONObject payload = payload(context);
|
||||
render(
|
||||
context,
|
||||
manager,
|
||||
appWidgetIds,
|
||||
payload,
|
||||
payload.optJSONArray("exams"),
|
||||
"近期考试",
|
||||
"近期没有已发布考试",
|
||||
"exams",
|
||||
1201);
|
||||
}
|
||||
|
||||
private static void render(
|
||||
Context context,
|
||||
AppWidgetManager manager,
|
||||
int[] appWidgetIds,
|
||||
JSONObject payload,
|
||||
JSONArray items,
|
||||
String title,
|
||||
String emptyText,
|
||||
String route,
|
||||
int requestCode
|
||||
) {
|
||||
if (appWidgetIds == null || appWidgetIds.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int appWidgetId : appWidgetIds) {
|
||||
RemoteViews views = new RemoteViews(
|
||||
context.getPackageName(),
|
||||
R.layout.widget_academic);
|
||||
String displayName = payload.optString("displayName", "");
|
||||
views.setTextViewText(
|
||||
R.id.widget_title,
|
||||
displayName.trim().isEmpty() ? title : displayName + " · " + title);
|
||||
views.setTextViewText(
|
||||
R.id.widget_updated,
|
||||
updatedLabel(payload.optString("updatedAt")));
|
||||
|
||||
int count = items == null ? 0 : Math.min(items.length(), ROWS.length);
|
||||
views.setViewVisibility(
|
||||
R.id.widget_empty,
|
||||
count == 0 ? View.VISIBLE : View.GONE);
|
||||
views.setTextViewText(
|
||||
R.id.widget_empty,
|
||||
payload.length() == 0 ? "登录 App 后同步教务数据" : emptyText);
|
||||
|
||||
for (int index = 0; index < ROWS.length; index++) {
|
||||
if (index < count) {
|
||||
JSONObject item = items.optJSONObject(index);
|
||||
views.setViewVisibility(ROWS[index], View.VISIBLE);
|
||||
views.setTextViewText(
|
||||
TIMES[index],
|
||||
item == null ? "" : item.optString("time"));
|
||||
views.setTextViewText(
|
||||
TITLES[index],
|
||||
item == null ? "" : item.optString("title"));
|
||||
views.setTextViewText(
|
||||
SUBTITLES[index],
|
||||
item == null ? "" : item.optString("subtitle"));
|
||||
} else {
|
||||
views.setViewVisibility(ROWS[index], View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
views.setOnClickPendingIntent(
|
||||
R.id.widget_root,
|
||||
openIntent(context, route, requestCode + appWidgetId));
|
||||
manager.updateAppWidget(appWidgetId, views);
|
||||
}
|
||||
}
|
||||
|
||||
private static PendingIntent openIntent(
|
||||
Context context,
|
||||
String route,
|
||||
int requestCode
|
||||
) {
|
||||
Intent intent = new Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("mingxu://open/" + route),
|
||||
context,
|
||||
MainActivity.class);
|
||||
intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK |
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP |
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
return PendingIntent.getActivity(
|
||||
context,
|
||||
requestCode,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||
}
|
||||
|
||||
private static JSONObject payload(Context context) {
|
||||
String value = NativeHomePlugin.preferences(context)
|
||||
.getString(NativeHomePlugin.WIDGET_PAYLOAD, null);
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
return new JSONObject();
|
||||
}
|
||||
try {
|
||||
return new JSONObject(value);
|
||||
} catch (Exception ignored) {
|
||||
return new JSONObject();
|
||||
}
|
||||
}
|
||||
|
||||
private static String updatedLabel(String value) {
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
return "等待同步";
|
||||
}
|
||||
try {
|
||||
Instant instant = Instant.parse(value);
|
||||
return "更新于 " + DateTimeFormatter.ofPattern("HH:mm")
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.format(instant);
|
||||
} catch (Exception ignored) {
|
||||
return "最近已同步";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#173B72"
|
||||
android:pathData="M3,3h7v2H5v5H3zM14,3h7v7h-2V5h-5zM3,14h2v5h5v2H3zM19,14h2v7h-7v-2h5zM7,7h10v10H7zM9,9v6h6V9z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#173B72"
|
||||
android:pathData="M14,2H6c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V8zM13,9V3.5L18.5,9zM8,13h8v2H8zM8,17h8v2H8z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#173B72"
|
||||
android:pathData="M12,22c1.1,0 1.99,-0.9 1.99,-2h-4c0,1.1 0.9,2 2.01,2zM18,16v-5c0,-3.07 -1.63,-5.64 -4.5,-6.32V4c0,-0.83 -0.67,-1.5 -1.5,-1.5S10.5,3.17 10.5,4v0.68C7.64,5.36 6,7.92 6,11v5l-2,2v1h16v-1z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#173B72"
|
||||
android:pathData="M19,4h-1V2h-2v2H8V2H6v2H5c-1.11,0 -1.99,0.9 -1.99,2L3,20c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2zM19,20H5V9h14v11zM7,11h5v5H7z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="3dp" />
|
||||
<solid android:color="#2F8F89" />
|
||||
</shape>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="24dp" />
|
||||
<gradient
|
||||
android:angle="315"
|
||||
android:startColor="#F8FBFF"
|
||||
android:endColor="#EAF2FF" />
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="#DCE7F8" />
|
||||
</shape>
|
||||
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/widget_background"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<View
|
||||
android:layout_width="5dp"
|
||||
android:layout_height="22dp"
|
||||
android:layout_marginEnd="9dp"
|
||||
android:background="@drawable/widget_accent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="今日课表"
|
||||
android:textColor="#102652"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_updated"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="等待同步"
|
||||
android:textColor="#74839E"
|
||||
android:textSize="10sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="登录 App 后同步教务数据"
|
||||
android:textColor="#61718D"
|
||||
android:textSize="13sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_row_one"
|
||||
style="@style/WidgetAcademicRow">
|
||||
<TextView
|
||||
android:id="@+id/widget_time_one"
|
||||
style="@style/WidgetAcademicTime" />
|
||||
<LinearLayout style="@style/WidgetAcademicCopy">
|
||||
<TextView
|
||||
android:id="@+id/widget_item_title_one"
|
||||
style="@style/WidgetAcademicTitle" />
|
||||
<TextView
|
||||
android:id="@+id/widget_item_subtitle_one"
|
||||
style="@style/WidgetAcademicSubtitle" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_row_two"
|
||||
style="@style/WidgetAcademicRow">
|
||||
<TextView
|
||||
android:id="@+id/widget_time_two"
|
||||
style="@style/WidgetAcademicTime" />
|
||||
<LinearLayout style="@style/WidgetAcademicCopy">
|
||||
<TextView
|
||||
android:id="@+id/widget_item_title_two"
|
||||
style="@style/WidgetAcademicTitle" />
|
||||
<TextView
|
||||
android:id="@+id/widget_item_subtitle_two"
|
||||
style="@style/WidgetAcademicSubtitle" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_row_three"
|
||||
style="@style/WidgetAcademicRow">
|
||||
<TextView
|
||||
android:id="@+id/widget_time_three"
|
||||
style="@style/WidgetAcademicTime" />
|
||||
<LinearLayout style="@style/WidgetAcademicCopy">
|
||||
<TextView
|
||||
android:id="@+id/widget_item_title_three"
|
||||
style="@style/WidgetAcademicTitle" />
|
||||
<TextView
|
||||
android:id="@+id/widget_item_subtitle_three"
|
||||
style="@style/WidgetAcademicSubtitle" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<resources>
|
||||
<string name="app_name">明序教务</string>
|
||||
<string name="title_activity_main">明序教务</string>
|
||||
<string name="package_name">edu.mingxu.jiaowu</string>
|
||||
<string name="custom_url_scheme">edu.mingxu.jiaowu</string>
|
||||
<string name="shortcut_timetable_short">我的课表</string>
|
||||
<string name="shortcut_timetable_long">查看我的今日课表</string>
|
||||
<string name="shortcut_exams_short">考试安排</string>
|
||||
<string name="shortcut_exams_long">查看近期考试安排</string>
|
||||
<string name="shortcut_attendance_short">课堂签到</string>
|
||||
<string name="shortcut_attendance_long">扫码、定位或发起签到</string>
|
||||
<string name="shortcut_notifications_short">消息中心</string>
|
||||
<string name="shortcut_notifications_long">查看教务通知和待办</string>
|
||||
<string name="widget_schedule_name">明序今日课表</string>
|
||||
<string name="widget_exam_name">明序近期考试</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:background">@null</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
|
||||
<item name="android:background">@drawable/splash</item>
|
||||
</style>
|
||||
|
||||
<style name="WidgetAcademicRow">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">0dp</item>
|
||||
<item name="android:layout_weight">1</item>
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
<item name="android:minHeight">42dp</item>
|
||||
<item name="android:orientation">horizontal</item>
|
||||
</style>
|
||||
|
||||
<style name="WidgetAcademicTime">
|
||||
<item name="android:layout_width">76dp</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:ellipsize">end</item>
|
||||
<item name="android:maxLines">1</item>
|
||||
<item name="android:textColor">#2F8F89</item>
|
||||
<item name="android:textSize">11sp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
</style>
|
||||
|
||||
<style name="WidgetAcademicCopy">
|
||||
<item name="android:layout_width">0dp</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_weight">1</item>
|
||||
<item name="android:orientation">vertical</item>
|
||||
</style>
|
||||
|
||||
<style name="WidgetAcademicTitle">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:ellipsize">end</item>
|
||||
<item name="android:maxLines">1</item>
|
||||
<item name="android:textColor">#152848</item>
|
||||
<item name="android:textSize">13sp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
</style>
|
||||
|
||||
<style name="WidgetAcademicSubtitle">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:ellipsize">end</item>
|
||||
<item name="android:maxLines">1</item>
|
||||
<item name="android:textColor">#74839E</item>
|
||||
<item name="android:textSize">10sp</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/widget_exam_name"
|
||||
android:initialLayout="@layout/widget_academic"
|
||||
android:minWidth="250dp"
|
||||
android:minHeight="120dp"
|
||||
android:previewLayout="@layout/widget_academic"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="1800000"
|
||||
android:widgetCategory="home_screen" />
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/widget_schedule_name"
|
||||
android:initialLayout="@layout/widget_academic"
|
||||
android:minWidth="250dp"
|
||||
android:minHeight="120dp"
|
||||
android:previewLayout="@layout/widget_academic"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:updatePeriodMillis="1800000"
|
||||
android:widgetCategory="home_screen" />
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<shortcut
|
||||
android:shortcutId="timetable"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_shortcut_timetable"
|
||||
android:shortcutShortLabel="@string/shortcut_timetable_short"
|
||||
android:shortcutLongLabel="@string/shortcut_timetable_long">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:targetPackage="edu.mingxu.jiaowu"
|
||||
android:targetClass="edu.mingxu.jiaowu.MainActivity"
|
||||
android:data="mingxu://open/timetable" />
|
||||
</shortcut>
|
||||
<shortcut
|
||||
android:shortcutId="exams"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_shortcut_exam"
|
||||
android:shortcutShortLabel="@string/shortcut_exams_short"
|
||||
android:shortcutLongLabel="@string/shortcut_exams_long">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:targetPackage="edu.mingxu.jiaowu"
|
||||
android:targetClass="edu.mingxu.jiaowu.MainActivity"
|
||||
android:data="mingxu://open/exams" />
|
||||
</shortcut>
|
||||
<shortcut
|
||||
android:shortcutId="attendance"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_shortcut_attendance"
|
||||
android:shortcutShortLabel="@string/shortcut_attendance_short"
|
||||
android:shortcutLongLabel="@string/shortcut_attendance_long">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:targetPackage="edu.mingxu.jiaowu"
|
||||
android:targetClass="edu.mingxu.jiaowu.MainActivity"
|
||||
android:data="mingxu://open/attendance" />
|
||||
</shortcut>
|
||||
<shortcut
|
||||
android:shortcutId="notifications"
|
||||
android:enabled="true"
|
||||
android:icon="@drawable/ic_shortcut_notifications"
|
||||
android:shortcutShortLabel="@string/shortcut_notifications_short"
|
||||
android:shortcutLongLabel="@string/shortcut_notifications_long">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:targetPackage="edu.mingxu.jiaowu"
|
||||
android:targetClass="edu.mingxu.jiaowu.MainActivity"
|
||||
android:data="mingxu://open/notifications" />
|
||||
</shortcut>
|
||||
</shortcuts>
|
||||
@@ -1,4 +1,11 @@
|
||||
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import {
|
||||
copyFileSync,
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
readFileSync,
|
||||
readdirSync,
|
||||
writeFileSync,
|
||||
} from 'node:fs'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
@@ -12,17 +19,36 @@ function updateFile(path, update) {
|
||||
return true
|
||||
}
|
||||
|
||||
function copyTemplateTree(source, destination) {
|
||||
if (!existsSync(source)) {
|
||||
throw new Error(`缺少原生模板目录:${source}`)
|
||||
}
|
||||
mkdirSync(destination, { recursive: true })
|
||||
for (const entry of readdirSync(source, { withFileTypes: true })) {
|
||||
const sourcePath = resolve(source, entry.name)
|
||||
const destinationPath = resolve(destination, entry.name)
|
||||
if (entry.isDirectory()) copyTemplateTree(sourcePath, destinationPath)
|
||||
else copyFileSync(sourcePath, destinationPath)
|
||||
}
|
||||
}
|
||||
|
||||
function configureAndroid() {
|
||||
const androidRoot = resolve(webRoot, 'android')
|
||||
const variablesPath = resolve(webRoot, 'android', 'variables.gradle')
|
||||
const templateRoot = resolve(webRoot, 'native', 'android')
|
||||
const manifestPath = resolve(
|
||||
webRoot,
|
||||
'android',
|
||||
androidRoot,
|
||||
'app',
|
||||
'src',
|
||||
'main',
|
||||
'AndroidManifest.xml',
|
||||
)
|
||||
if (!existsSync(variablesPath) || !existsSync(manifestPath)) return false
|
||||
if (!existsSync(variablesPath)) return false
|
||||
|
||||
copyTemplateTree(templateRoot, androidRoot)
|
||||
if (!existsSync(manifestPath)) {
|
||||
throw new Error('Android 原生模板未生成 AndroidManifest.xml。')
|
||||
}
|
||||
|
||||
updateFile(variablesPath, content => {
|
||||
if (!/minSdkVersion\s*=\s*\d+/.test(content)) {
|
||||
@@ -78,4 +104,4 @@ if (!configuredPlatforms.length) {
|
||||
throw new Error('尚未生成 Capacitor 原生工程,请先运行 npx cap add android 或 ios。')
|
||||
}
|
||||
|
||||
console.log(`已配置 ${configuredPlatforms.join('、')} 的扫码和定位权限。`)
|
||||
console.log(`已配置 ${configuredPlatforms.join('、')} 的扫码、定位和原生桌面体验。`)
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import SmartLaunchScreen from './components/SmartLaunchScreen.vue'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<SmartLaunchScreen />
|
||||
<RouterView />
|
||||
</template>
|
||||
|
||||
Vendored
+1
@@ -55,6 +55,7 @@ declare module 'vue' {
|
||||
RichMessageContent: typeof import('./components/RichMessageContent.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
SmartLaunchScreen: typeof import('./components/SmartLaunchScreen.vue')['default']
|
||||
}
|
||||
export interface GlobalDirectives {
|
||||
vLoading: typeof import('element-plus/es')['ElLoadingDirective']
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { Capacitor } from '@capacitor/core'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
import { getSmartGreeting } from '../utils/smartGreeting'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const previewParams = import.meta.env.DEV
|
||||
? new URLSearchParams(window.location.search)
|
||||
: null
|
||||
const previewNative = previewParams?.has('previewLaunch') ?? false
|
||||
const previewName = previewParams?.get('previewName')
|
||||
const visible = ref(Capacitor.isNativePlatform() || previewNative)
|
||||
const leaving = ref(false)
|
||||
const greeting = computed(() =>
|
||||
getSmartGreeting(new Date(), previewName || auth.user?.displayName))
|
||||
let dismissTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let removeTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
function dismiss() {
|
||||
if (!visible.value || leaving.value) return
|
||||
leaving.value = true
|
||||
removeTimer = setTimeout(() => {
|
||||
visible.value = false
|
||||
}, 360)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (!visible.value) return
|
||||
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
||||
dismissTimer = setTimeout(dismiss, reducedMotion ? 650 : 1800)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (dismissTimer) clearTimeout(dismissTimer)
|
||||
if (removeTimer) clearTimeout(removeTimer)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="smart-launch">
|
||||
<section
|
||||
v-if="visible"
|
||||
class="smart-launch-screen"
|
||||
:class="{ leaving }"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
@click="dismiss"
|
||||
>
|
||||
<div class="smart-launch-orbit orbit-one" />
|
||||
<div class="smart-launch-orbit orbit-two" />
|
||||
<div class="smart-launch-content">
|
||||
<div class="smart-launch-mark" aria-hidden="true">
|
||||
<i v-for="index in 9" :key="index" />
|
||||
</div>
|
||||
<span class="smart-launch-brand">MINGXU ACADEMIC</span>
|
||||
<p>{{ greeting.label }}</p>
|
||||
<h1>{{ greeting.title }}</h1>
|
||||
<small>{{ greeting.subtitle }}</small>
|
||||
</div>
|
||||
<span class="smart-launch-skip">轻触跳过</span>
|
||||
</section>
|
||||
</Transition>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.smart-launch-screen {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 99999;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
overflow: hidden;
|
||||
color: #f8fbff;
|
||||
background:
|
||||
radial-gradient(circle at 15% 18%, rgb(74 198 193 / 22%), transparent 28rem),
|
||||
radial-gradient(circle at 88% 78%, rgb(94 132 255 / 24%), transparent 30rem),
|
||||
linear-gradient(145deg, #081733, #10275c 55%, #163b71);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.smart-launch-content {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
width: min(86vw, 32rem);
|
||||
text-align: center;
|
||||
animation: launch-rise 700ms cubic-bezier(.2, .8, .2, 1) both;
|
||||
}
|
||||
|
||||
.smart-launch-mark {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 0.72rem);
|
||||
gap: 0.3rem;
|
||||
width: fit-content;
|
||||
margin: 0 auto 1.6rem;
|
||||
padding: 1rem;
|
||||
border: 1px solid rgb(255 255 255 / 16%);
|
||||
border-radius: 1.25rem;
|
||||
background: rgb(255 255 255 / 8%);
|
||||
box-shadow: 0 1.3rem 4rem rgb(0 0 0 / 24%);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.smart-launch-mark i {
|
||||
width: 0.72rem;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 0.18rem;
|
||||
background: #6ee7d8;
|
||||
}
|
||||
|
||||
.smart-launch-mark i:nth-child(2n) { background: #9cb8ff; }
|
||||
.smart-launch-mark i:nth-child(5) { background: #fff; }
|
||||
|
||||
.smart-launch-brand {
|
||||
display: block;
|
||||
margin-bottom: 1.7rem;
|
||||
color: #8fe4dc;
|
||||
font-size: 0.68rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.28em;
|
||||
}
|
||||
|
||||
.smart-launch-content p {
|
||||
margin: 0 0 0.75rem;
|
||||
color: rgb(235 244 255 / 72%);
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
|
||||
.smart-launch-content h1 {
|
||||
margin: 0;
|
||||
font-family: "Noto Serif SC", "Songti SC", serif;
|
||||
font-size: clamp(1.7rem, 7vw, 2.45rem);
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.smart-launch-content small {
|
||||
display: block;
|
||||
max-width: 24rem;
|
||||
margin: 1rem auto 0;
|
||||
color: rgb(235 244 255 / 68%);
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.smart-launch-skip {
|
||||
position: absolute;
|
||||
bottom: max(2rem, env(safe-area-inset-bottom));
|
||||
z-index: 2;
|
||||
color: rgb(255 255 255 / 45%);
|
||||
font-size: 0.72rem;
|
||||
letter-spacing: 0.12em;
|
||||
}
|
||||
|
||||
.smart-launch-orbit {
|
||||
position: absolute;
|
||||
border: 1px solid rgb(255 255 255 / 8%);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.orbit-one {
|
||||
width: 24rem;
|
||||
height: 24rem;
|
||||
animation: launch-spin 18s linear infinite;
|
||||
}
|
||||
|
||||
.orbit-two {
|
||||
width: 38rem;
|
||||
height: 38rem;
|
||||
border-style: dashed;
|
||||
animation: launch-spin 28s linear infinite reverse;
|
||||
}
|
||||
|
||||
.smart-launch-leave-active { transition: opacity 360ms ease, transform 360ms ease; }
|
||||
.smart-launch-leave-to { opacity: 0; transform: scale(1.025); }
|
||||
|
||||
@keyframes launch-rise {
|
||||
from { opacity: 0; transform: translateY(1.2rem); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
|
||||
@keyframes launch-spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.smart-launch-content,
|
||||
.smart-launch-orbit {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -4,6 +4,7 @@ import './style.css'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import { initializeAppUpdates } from './services/appUpdates'
|
||||
import { initializeNativeHome } from './services/nativeHome'
|
||||
import { setRouter } from './utils/navigate'
|
||||
|
||||
const app = createApp(App)
|
||||
@@ -12,3 +13,4 @@ app.use(router)
|
||||
setRouter(router)
|
||||
app.mount('#app')
|
||||
void initializeAppUpdates()
|
||||
initializeNativeHome(router)
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
import { Capacitor, registerPlugin } from '@capacitor/core'
|
||||
import type { Router } from 'vue-router'
|
||||
import http from '../api/http'
|
||||
|
||||
interface WidgetItem {
|
||||
title: string
|
||||
subtitle: string
|
||||
time: string
|
||||
}
|
||||
|
||||
interface WidgetPayload {
|
||||
displayName: string
|
||||
scheduleDate: string
|
||||
schedule: WidgetItem[]
|
||||
exams: WidgetItem[]
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
interface NativeHomePlugin {
|
||||
updateWidgets(options: { payload: WidgetPayload }): Promise<void>
|
||||
clearWidgets(): Promise<void>
|
||||
getLaunchRoute(): Promise<{ route?: string }>
|
||||
}
|
||||
|
||||
interface StoredUser {
|
||||
displayName?: string
|
||||
roles?: string[]
|
||||
}
|
||||
|
||||
const NativeHome = registerPlugin<NativeHomePlugin>('NativeHome')
|
||||
const native = Capacitor.isNativePlatform()
|
||||
const syncInterval = 10 * 60 * 1000
|
||||
let lastSyncAt = 0
|
||||
let syncPromise: Promise<void> | null = null
|
||||
|
||||
function storedUser(): StoredUser | null {
|
||||
try {
|
||||
const value = localStorage.getItem('jiaowu_user')
|
||||
return value ? JSON.parse(value) as StoredUser : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function dateKey(date: Date) {
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
function parseDateOnly(value?: string) {
|
||||
if (!value) return null
|
||||
const [year, month, day] = value.slice(0, 10).split('-').map(Number)
|
||||
return year && month && day ? new Date(year, month - 1, day) : null
|
||||
}
|
||||
|
||||
function slotTime(slots: any[], period: number, field: 'startsAt' | 'endsAt') {
|
||||
return slots.find((slot) => slot.periodNumber === period)?.[field]?.slice(0, 5) ?? ''
|
||||
}
|
||||
|
||||
function activeWeek(timetable: any, now: Date) {
|
||||
const start = parseDateOnly(timetable?.term?.startDate)
|
||||
const end = parseDateOnly(timetable?.term?.endDate)
|
||||
if (!start || !end || now < start || now > new Date(end.getTime() + 86400000)) return null
|
||||
const mondayOffset = start.getDay() === 0 ? 6 : start.getDay() - 1
|
||||
const firstMonday = new Date(start)
|
||||
firstMonday.setDate(firstMonday.getDate() - mondayOffset)
|
||||
return Math.floor((now.getTime() - firstMonday.getTime()) / 604800000) + 1
|
||||
}
|
||||
|
||||
function scheduleItems(timetable: any, now: Date): WidgetItem[] {
|
||||
const week = activeWeek(timetable, now)
|
||||
if (!week) return []
|
||||
const weekday = now.getDay() || 7
|
||||
return (timetable?.entries ?? [])
|
||||
.filter((entry: any) =>
|
||||
entry.dayOfWeek === weekday &&
|
||||
week >= entry.startWeek &&
|
||||
week <= entry.endWeek &&
|
||||
(entry.weekPattern === 'All' ||
|
||||
(entry.weekPattern === 'Odd' && week % 2 === 1) ||
|
||||
(entry.weekPattern === 'Even' && week % 2 === 0)))
|
||||
.sort((left: any, right: any) => left.startPeriod - right.startPeriod)
|
||||
.slice(0, 3)
|
||||
.map((entry: any) => {
|
||||
const endPeriod = entry.startPeriod + entry.periodCount - 1
|
||||
const startsAt = slotTime(timetable.slots ?? [], entry.startPeriod, 'startsAt')
|
||||
const endsAt = slotTime(timetable.slots ?? [], endPeriod, 'endsAt')
|
||||
return {
|
||||
title: String(entry.courseName ?? '未命名课程'),
|
||||
subtitle: [entry.buildingName, entry.classroomName].filter(Boolean).join(' · ') || '地点待定',
|
||||
time: startsAt && endsAt ? `${startsAt}—${endsAt}` : `第 ${entry.startPeriod}—${endPeriod} 节`,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function examItems(exams: any[], now: Date): WidgetItem[] {
|
||||
return exams
|
||||
.map((exam) => {
|
||||
const startsAt = new Date(exam.startsAt)
|
||||
const date = Number.isNaN(startsAt.getTime())
|
||||
? parseDateOnly(exam.examDate)
|
||||
: startsAt
|
||||
return { exam, date }
|
||||
})
|
||||
.filter(({ date }) => date && date.getTime() >= new Date(
|
||||
now.getFullYear(), now.getMonth(), now.getDate(),
|
||||
).getTime())
|
||||
.sort((left, right) => left.date!.getTime() - right.date!.getTime())
|
||||
.slice(0, 3)
|
||||
.map(({ exam, date }) => ({
|
||||
title: String(exam.courseName ?? '未命名考试'),
|
||||
subtitle: [
|
||||
exam.buildingName,
|
||||
exam.classroomName,
|
||||
exam.seatNumber ? `${exam.seatNumber} 号座` : '',
|
||||
].filter(Boolean).join(' · ') || '考场待定',
|
||||
time: `${date!.getMonth() + 1}/${date!.getDate()} ${
|
||||
Number.isNaN(new Date(exam.startsAt).getTime())
|
||||
? '时间待定'
|
||||
: new Intl.DateTimeFormat('zh-CN', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
}).format(new Date(exam.startsAt))
|
||||
}`,
|
||||
}))
|
||||
}
|
||||
|
||||
export async function clearNativeWidgets() {
|
||||
if (!native) return
|
||||
try {
|
||||
await NativeHome.clearWidgets()
|
||||
} catch (error) {
|
||||
console.warn('清理 Android 桌面组件失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
export async function syncNativeWidgets(force = false) {
|
||||
if (!native) return
|
||||
if (!localStorage.getItem('jiaowu_token')) {
|
||||
await clearNativeWidgets()
|
||||
return
|
||||
}
|
||||
if (!force && Date.now() - lastSyncAt < syncInterval) return
|
||||
if (syncPromise) return syncPromise
|
||||
|
||||
syncPromise = (async () => {
|
||||
const user = storedUser()
|
||||
const roles = user?.roles ?? []
|
||||
if (!roles.some((role) => role === 'Student' || role === 'Teacher')) {
|
||||
await clearNativeWidgets()
|
||||
return
|
||||
}
|
||||
|
||||
const [timetableResult, examResult] = await Promise.allSettled([
|
||||
http.get('/timetables/mine'),
|
||||
http.get('/exams/my-schedule'),
|
||||
])
|
||||
const now = new Date()
|
||||
const payload: WidgetPayload = {
|
||||
displayName: user?.displayName?.trim() || '同学',
|
||||
scheduleDate: dateKey(now),
|
||||
schedule: timetableResult.status === 'fulfilled'
|
||||
? scheduleItems(timetableResult.value.data, now)
|
||||
: [],
|
||||
exams: examResult.status === 'fulfilled'
|
||||
? examItems(examResult.value.data, now)
|
||||
: [],
|
||||
updatedAt: now.toISOString(),
|
||||
}
|
||||
await NativeHome.updateWidgets({ payload })
|
||||
lastSyncAt = Date.now()
|
||||
})().catch((error) => {
|
||||
console.warn('同步 Android 桌面组件失败', error)
|
||||
}).finally(() => {
|
||||
syncPromise = null
|
||||
})
|
||||
|
||||
return syncPromise
|
||||
}
|
||||
|
||||
function routeForShortcut(route: string) {
|
||||
const roles = storedUser()?.roles ?? []
|
||||
if (route === 'timetable') {
|
||||
return roles.some((role) => role === 'Student' || role === 'Teacher')
|
||||
? '/my-timetable'
|
||||
: '/class-timetable'
|
||||
}
|
||||
if (route === 'exams') return '/exams'
|
||||
if (route === 'attendance') {
|
||||
return roles.includes('Student') ? '/my-attendance' : '/teacher-attendance'
|
||||
}
|
||||
if (route === 'notifications') return '/notifications'
|
||||
return '/dashboard'
|
||||
}
|
||||
|
||||
export function initializeNativeHome(router: Router) {
|
||||
if (!native) return
|
||||
|
||||
const openShortcut = (route?: string) => {
|
||||
if (!route) return
|
||||
if (!localStorage.getItem('jiaowu_token')) {
|
||||
sessionStorage.setItem('mingxu_pending_shortcut', route)
|
||||
void router.push('/login')
|
||||
return
|
||||
}
|
||||
void router.push(routeForShortcut(route))
|
||||
}
|
||||
const shortcutListener = (event: Event) => {
|
||||
const value = event as CustomEvent<{ route?: string }> & { route?: string }
|
||||
const eventRoute = value.detail?.route ?? value.route
|
||||
void NativeHome.getLaunchRoute()
|
||||
.then(({ route }) => openShortcut(route ?? eventRoute))
|
||||
.catch(() => openShortcut(eventRoute))
|
||||
}
|
||||
window.addEventListener('mingxuShortcut', shortcutListener)
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (!document.hidden) void syncNativeWidgets()
|
||||
})
|
||||
window.addEventListener('mingxu-auth-changed', () => {
|
||||
lastSyncAt = 0
|
||||
const pendingShortcut = sessionStorage.getItem('mingxu_pending_shortcut')
|
||||
if (localStorage.getItem('jiaowu_token') && pendingShortcut) {
|
||||
sessionStorage.removeItem('mingxu_pending_shortcut')
|
||||
openShortcut(pendingShortcut)
|
||||
}
|
||||
void syncNativeWidgets(true)
|
||||
})
|
||||
router.afterEach(() => {
|
||||
void syncNativeWidgets()
|
||||
})
|
||||
|
||||
void NativeHome.getLaunchRoute()
|
||||
.then(({ route }) => openShortcut(route))
|
||||
.catch((error) => console.warn('读取 Android 快捷入口失败', error))
|
||||
void syncNativeWidgets()
|
||||
}
|
||||
@@ -24,6 +24,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
user.value = data.user
|
||||
localStorage.setItem('jiaowu_token', data.token)
|
||||
localStorage.setItem('jiaowu_user', JSON.stringify(data.user))
|
||||
window.dispatchEvent(new Event('mingxu-auth-changed'))
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
@@ -38,6 +39,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
user.value = null
|
||||
localStorage.removeItem('jiaowu_token')
|
||||
localStorage.removeItem('jiaowu_user')
|
||||
window.dispatchEvent(new Event('mingxu-auth-changed'))
|
||||
}
|
||||
|
||||
return { token, user, isLoggedIn, isSuperAdmin, login, refresh, logout }
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
export interface SmartGreeting {
|
||||
title: string
|
||||
subtitle: string
|
||||
label: string
|
||||
}
|
||||
|
||||
const dailySubtitles = [
|
||||
'愿今天的课程与计划都清晰顺利。',
|
||||
'新的一天,从有序安排开始。',
|
||||
'把每一次学习,都变成看得见的进步。',
|
||||
]
|
||||
|
||||
function lunarFestival(date: Date) {
|
||||
try {
|
||||
const parts = new Intl.DateTimeFormat('zh-CN-u-ca-chinese', {
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
}).formatToParts(date)
|
||||
const month = parts.find((part) => part.type === 'month')?.value ?? ''
|
||||
const day = parts.find((part) => part.type === 'day')?.value ?? ''
|
||||
|
||||
if (month === '正月' && ['1', '2', '3'].includes(day)) return '春节快乐'
|
||||
if (month === '正月' && day === '15') return '元宵节快乐'
|
||||
if (month === '五月' && day === '5') return '端午安康'
|
||||
if (month === '八月' && day === '15') return '中秋快乐'
|
||||
} catch {
|
||||
// 少数精简 WebView 不支持中国农历日历,继续使用公历与时段问候。
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
function festivalGreeting(date: Date) {
|
||||
const month = date.getMonth() + 1
|
||||
const day = date.getDate()
|
||||
const lunar = lunarFestival(date)
|
||||
if (lunar) return lunar
|
||||
if (month === 1 && day === 1) return '新年快乐'
|
||||
if (month === 5 && day >= 1 && day <= 5) return '劳动节愉快'
|
||||
if (month === 9 && day === 10) return '教师节快乐'
|
||||
if (month === 10 && day >= 1 && day <= 7) return '国庆节快乐'
|
||||
return ''
|
||||
}
|
||||
|
||||
function timeGreeting(date: Date) {
|
||||
const hour = date.getHours()
|
||||
if (hour < 5) return '夜深了'
|
||||
if (hour < 11) return '早上好'
|
||||
if (hour < 14) return '中午好'
|
||||
if (hour < 18) return '下午好'
|
||||
return '晚上好'
|
||||
}
|
||||
|
||||
export function getSmartGreeting(
|
||||
date = new Date(),
|
||||
displayName?: string | null,
|
||||
): SmartGreeting {
|
||||
const greeting = festivalGreeting(date) || timeGreeting(date)
|
||||
const name = displayName?.trim()
|
||||
const weekday = new Intl.DateTimeFormat('zh-CN', { weekday: 'long' }).format(date)
|
||||
const label = new Intl.DateTimeFormat('zh-CN', {
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
}).format(date)
|
||||
const index = Math.abs(date.getFullYear() * 372 + date.getMonth() * 31 + date.getDate())
|
||||
% dailySubtitles.length
|
||||
|
||||
return {
|
||||
title: name ? `${name},${greeting}` : `${greeting},欢迎使用明序教务`,
|
||||
subtitle: date.getDay() === 0 || date.getDay() === 6
|
||||
? '周末也要记得放松一下,查看安排后从容出发。'
|
||||
: dailySubtitles[index],
|
||||
label: `${label} · ${weekday}`,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user