From 46570636df39d68d11b807aad643cdd8e2080bf9 Mon Sep 17 00:00:00 2001
From: chenziang <3538995003@qq.com>
Date: Wed, 31 Dec 2025 19:55:55 +0800
Subject: [PATCH 1/2] =?UTF-8?q?config(eslint):=20=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E5=92=8CWeb=20API=E5=85=A8=E5=B1=80?=
=?UTF-8?q?=E5=8F=98=E9=87=8F=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 添加浏览器全局变量如window、document、navigator等
- 添加Vite相关全局变量如import、process等
- 添加Service Worker全局变量如self、caches等
- 添加Web API全局变量如Notification、ServiceWorker等
- 添加Web Storage API全局变量如Storage、StorageEvent等
- 添加WebSocket和Web Workers相关全局变量
---
eslint.config.js | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/eslint.config.js b/eslint.config.js
index 944e82b..dc39e85 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -19,5 +19,48 @@ export default [
rules: {
'vue/multi-word-component-names': 'off',
},
+ },
+ {
+ languageOptions: {
+ globals: {
+ // Browser globals
+ window: 'readonly',
+ document: 'readonly',
+ navigator: 'readonly',
+ localStorage: 'readonly',
+ sessionStorage: 'readonly',
+ console: 'readonly',
+ alert: 'readonly',
+ confirm: 'readonly',
+ prompt: 'readonly',
+ setTimeout: 'readonly',
+ setInterval: 'readonly',
+ fetch: 'readonly',
+ XMLHttpRequest: 'readonly',
+ URL: 'readonly',
+ URLSearchParams: 'readonly',
+ atob: 'readonly',
+ btoa: 'readonly',
+ // Vite globals
+ import: 'readonly',
+ process: 'readonly',
+ // Service Worker globals
+ self: 'readonly',
+ caches: 'readonly',
+ // Web API
+ Notification: 'readonly',
+ ServiceWorker: 'readonly',
+ PushManager: 'readonly',
+ PushSubscription: 'readonly',
+ // Web Storage API
+ Storage: 'readonly',
+ StorageEvent: 'readonly',
+ // Web Socket
+ WebSocket: 'readonly',
+ // Web Workers
+ Worker: 'readonly',
+ SharedWorker: 'readonly',
+ },
+ },
}
]
From 9c78356bf5fa0195d2c469617f90bc56ec84ac22 Mon Sep 17 00:00:00 2001
From: chenziang <3538995003@qq.com>
Date: Wed, 31 Dec 2025 19:56:13 +0800
Subject: [PATCH 2/2] =?UTF-8?q?feat(grid):=20=E4=BC=98=E5=8C=96=E5=8F=AA?=
=?UTF-8?q?=E8=AF=BB=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=9A=84=E4=BD=9C=E4=B8=9A?=
=?UTF-8?q?=E7=BD=91=E6=A0=BC=E7=BB=84=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 实现只读令牌状态检测功能,动态显示不同图标
- 在卡片和按钮中根据只读状态切换图标(加号或取消图标)
- 添加StudentNameManager组件依赖注入
- 重构组件数据结构,添加isReadOnlyToken响应式数据
- 实现异步检查只读状态的方法,支持多种访问方式
- 优化卡片文本显示,只读时显示"当日无作业"提示而不是“点击添加作业”
---
src/components/home/HomeworkGrid.vue | 77 ++++++++++++++++++++++++++--
1 file changed, 72 insertions(+), 5 deletions(-)
diff --git a/src/components/home/HomeworkGrid.vue b/src/components/home/HomeworkGrid.vue
index 46d7949..c821997 100644
--- a/src/components/home/HomeworkGrid.vue
+++ b/src/components/home/HomeworkGrid.vue
@@ -153,7 +153,9 @@
variant="tonal"
@click="handleCardClick('dialog', subject.name)"
>
- mdi-plus
+
+ {{ isReadOnlyToken ? 'mdi-cancel' : 'mdi-plus' }}
+
{{ subject.name }}
@@ -165,7 +167,9 @@
:key="subject.name"
@click="handleCardClick('dialog', subject.name)"
>
- mdi-plus
+
+ {{ isReadOnlyToken ? 'mdi-cancel' : 'mdi-plus' }}
+
{{ subject.name }}
@@ -183,8 +187,14 @@
{{ subject.name }}
- mdi-plus
- 点击添加作业
+
+ mdi-cancel
+ 当日无作业
+
+
+ mdi-plus
+ 点击添加作业
+
@@ -233,10 +243,17 @@ export default {
},
},
emits: ["open-dialog", "open-attendance", "disabled-click"],
- mounted() {
+ data() {
+ return {
+ isReadOnlyToken: false,
+ }
+ },
+ async mounted() {
+ /* eslint-disable no-undef */
this.resizeObserver = new ResizeObserver(() => {
this.resizeAllGridItems();
});
+ /* eslint-enable no-undef */
// Observe the grid container for width changes
if (this.$refs.gridContainer) {
@@ -256,6 +273,9 @@ export default {
});
}
});
+
+ // 检查只读状态
+ await this.checkReadOnlyStatus();
},
updated() {
// When items change, re-observe new items
@@ -276,6 +296,53 @@ export default {
}
},
methods: {
+ async checkReadOnlyStatus() {
+ // 尝试获取父组件中的StudentNameManager引用
+ try {
+ // 在Vue 2中,通过$parent或$root访问父组件
+ let manager = null;
+
+ // 首先尝试直接访问父组件的引用
+ if (this.$parent && this.$parent.$refs && this.$parent.$refs.studentNameManager) {
+ manager = this.$parent.$refs.studentNameManager;
+ } else if (this.$root && this.$root.$refs && this.$root.$refs.studentNameManager) {
+ manager = this.$root.$refs.studentNameManager;
+ }
+
+ if (manager && typeof manager.isReadOnly !== 'undefined') {
+ this.isReadOnlyToken = manager.isReadOnly;
+ } else {
+ // 如果无法直接访问manager,尝试通过全局设置获取token信息
+ // 这里需要使用utils/settings中的函数
+ const { getSetting } = await import('@/utils/settings');
+ const token = getSetting('server.kvToken');
+
+ if (token) {
+ // 通过API获取token信息来判断是否只读
+ const { default: axios } = await import('@/axios/axios');
+ const serverUrl = getSetting('server.domain');
+
+ if (serverUrl) {
+ try {
+ const tokenResponse = await axios.get(`${serverUrl}/kv/_token`, {
+ headers: {
+ Authorization: `Bearer ${token}`
+ }
+ });
+
+ if (tokenResponse.data && typeof tokenResponse.data.isReadOnly !== 'undefined') {
+ this.isReadOnlyToken = tokenResponse.data.isReadOnly;
+ }
+ } catch (err) {
+ console.error('获取Token信息失败:', err);
+ }
+ }
+ }
+ }
+ } catch (error) {
+ console.error('检查只读状态失败:', error);
+ }
+ },
resizeGridItem(item) {
const grid = this.$refs.gridContainer;
if (!grid) return;