Skip to content

Commit d83dd39

Browse files
authored
Merge pull request #30 from user111192/main
如果token为只读则将“点击添加作业”改为“当日无作业”
2 parents fb4da65 + 9c78356 commit d83dd39

File tree

2 files changed

+115
-5
lines changed

2 files changed

+115
-5
lines changed

eslint.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,48 @@ export default [
1919
rules: {
2020
'vue/multi-word-component-names': 'off',
2121
},
22+
},
23+
{
24+
languageOptions: {
25+
globals: {
26+
// Browser globals
27+
window: 'readonly',
28+
document: 'readonly',
29+
navigator: 'readonly',
30+
localStorage: 'readonly',
31+
sessionStorage: 'readonly',
32+
console: 'readonly',
33+
alert: 'readonly',
34+
confirm: 'readonly',
35+
prompt: 'readonly',
36+
setTimeout: 'readonly',
37+
setInterval: 'readonly',
38+
fetch: 'readonly',
39+
XMLHttpRequest: 'readonly',
40+
URL: 'readonly',
41+
URLSearchParams: 'readonly',
42+
atob: 'readonly',
43+
btoa: 'readonly',
44+
// Vite globals
45+
import: 'readonly',
46+
process: 'readonly',
47+
// Service Worker globals
48+
self: 'readonly',
49+
caches: 'readonly',
50+
// Web API
51+
Notification: 'readonly',
52+
ServiceWorker: 'readonly',
53+
PushManager: 'readonly',
54+
PushSubscription: 'readonly',
55+
// Web Storage API
56+
Storage: 'readonly',
57+
StorageEvent: 'readonly',
58+
// Web Socket
59+
WebSocket: 'readonly',
60+
// Web Workers
61+
Worker: 'readonly',
62+
SharedWorker: 'readonly',
63+
},
64+
},
2265
}
2366
]

src/components/home/HomeworkGrid.vue

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@
153153
variant="tonal"
154154
@click="handleCardClick('dialog', subject.name)"
155155
>
156-
<v-icon start size="small">mdi-plus</v-icon>
156+
<v-icon start size="small">
157+
{{ isReadOnlyToken ? 'mdi-cancel' : 'mdi-plus' }}
158+
</v-icon>
157159
{{ subject.name }}
158160
</v-chip>
159161
</div>
@@ -165,7 +167,9 @@
165167
:key="subject.name"
166168
@click="handleCardClick('dialog', subject.name)"
167169
>
168-
<v-icon start> mdi-plus</v-icon>
170+
<v-icon start>
171+
{{ isReadOnlyToken ? 'mdi-cancel' : 'mdi-plus' }}
172+
</v-icon>
169173
{{ subject.name }}
170174
</v-btn>
171175
</v-btn-group>
@@ -183,8 +187,14 @@
183187
{{ subject.name }}
184188
</v-card-title>
185189
<v-card-text class="text-center">
186-
<v-icon color="grey" size="small"> mdi-plus</v-icon>
187-
<div class="text-caption text-grey">点击添加作业</div>
190+
<template v-if="isReadOnlyToken">
191+
<v-icon color="grey" size="small"> mdi-cancel </v-icon>
192+
<div class="text-caption text-grey"> 当日无作业 </div>
193+
</template>
194+
<template v-else>
195+
<v-icon color="grey" size="small"> mdi-plus </v-icon>
196+
<div class="text-caption text-grey"> 点击添加作业 </div>
197+
</template>
188198
</v-card-text>
189199
</v-card>
190200
</TransitionGroup>
@@ -233,10 +243,17 @@ export default {
233243
},
234244
},
235245
emits: ["open-dialog", "open-attendance", "disabled-click"],
236-
mounted() {
246+
data() {
247+
return {
248+
isReadOnlyToken: false,
249+
}
250+
},
251+
async mounted() {
252+
/* eslint-disable no-undef */
237253
this.resizeObserver = new ResizeObserver(() => {
238254
this.resizeAllGridItems();
239255
});
256+
/* eslint-enable no-undef */
240257
241258
// Observe the grid container for width changes
242259
if (this.$refs.gridContainer) {
@@ -256,6 +273,9 @@ export default {
256273
});
257274
}
258275
});
276+
277+
// 检查只读状态
278+
await this.checkReadOnlyStatus();
259279
},
260280
updated() {
261281
// When items change, re-observe new items
@@ -276,6 +296,53 @@ export default {
276296
}
277297
},
278298
methods: {
299+
async checkReadOnlyStatus() {
300+
// 尝试获取父组件中的StudentNameManager引用
301+
try {
302+
// 在Vue 2中,通过$parent或$root访问父组件
303+
let manager = null;
304+
305+
// 首先尝试直接访问父组件的引用
306+
if (this.$parent && this.$parent.$refs && this.$parent.$refs.studentNameManager) {
307+
manager = this.$parent.$refs.studentNameManager;
308+
} else if (this.$root && this.$root.$refs && this.$root.$refs.studentNameManager) {
309+
manager = this.$root.$refs.studentNameManager;
310+
}
311+
312+
if (manager && typeof manager.isReadOnly !== 'undefined') {
313+
this.isReadOnlyToken = manager.isReadOnly;
314+
} else {
315+
// 如果无法直接访问manager,尝试通过全局设置获取token信息
316+
// 这里需要使用utils/settings中的函数
317+
const { getSetting } = await import('@/utils/settings');
318+
const token = getSetting('server.kvToken');
319+
320+
if (token) {
321+
// 通过API获取token信息来判断是否只读
322+
const { default: axios } = await import('@/axios/axios');
323+
const serverUrl = getSetting('server.domain');
324+
325+
if (serverUrl) {
326+
try {
327+
const tokenResponse = await axios.get(`${serverUrl}/kv/_token`, {
328+
headers: {
329+
Authorization: `Bearer ${token}`
330+
}
331+
});
332+
333+
if (tokenResponse.data && typeof tokenResponse.data.isReadOnly !== 'undefined') {
334+
this.isReadOnlyToken = tokenResponse.data.isReadOnly;
335+
}
336+
} catch (err) {
337+
console.error('获取Token信息失败:', err);
338+
}
339+
}
340+
}
341+
}
342+
} catch (error) {
343+
console.error('检查只读状态失败:', error);
344+
}
345+
},
279346
resizeGridItem(item) {
280347
const grid = this.$refs.gridContainer;
281348
if (!grid) return;

0 commit comments

Comments
 (0)