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 >
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 >
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