-
Notifications
You must be signed in to change notification settings - Fork 0
/
guoba.support.js
187 lines (182 loc) · 4.83 KB
/
guoba.support.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import fs from 'fs'
import path from 'path'
import { Config } from './model/config.js'
export function supportGuoba() {
const dataDir = path.join(process.cwd(), 'data/class-plugin/data')
let users = []
if (fs.existsSync(dataDir)) {
users = fs.readdirSync(dataDir)
.filter(f => f.endsWith('.json'))
.map(f => ({
label: f.replace('.json', ''),
value: f.replace('.json', '')
}))
}
return {
pluginInfo: {
name: 'class-plugin',
title: '课表插件',
author: '@Dnyo666',
authorLink: 'https://github.com/Dnyo666',
link: 'https://github.com/Dnyo666/class-plugin',
isV3: true,
isV2: false,
description: '课表管理插件',
icon: 'mdi:calendar-clock'
},
configInfo: {
schemas: [
{
field: 'userId',
label: '选择用户',
component: 'Select',
required: true,
componentProps: {
options: users
}
},
{
component: 'Divider',
label: '基础设置'
},
{
field: 'base.startDate',
label: '开学日期',
component: 'DatePicker',
required: true,
componentProps: {
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD'
}
},
{
field: 'base.maxWeek',
label: '学期周数',
component: 'InputNumber',
required: true,
componentProps: {
min: 1,
max: 30
}
},
{
component: 'Divider',
label: '课程设置'
},
{
field: 'courses',
label: '课程管理',
component: 'GSubForm',
componentProps: {
multiple: true,
schemas: [
{
field: 'name',
label: '课程名称',
component: 'Input',
required: true
},
{
field: 'teacher',
label: '教师',
component: 'Input'
},
{
field: 'location',
label: '教室',
component: 'Input'
},
{
field: 'weekDay',
label: '星期',
component: 'Select',
required: true,
componentProps: {
options: [
{ label: '周一', value: 1 },
{ label: '周二', value: 2 },
{ label: '周三', value: 3 },
{ label: '周四', value: 4 },
{ label: '周五', value: 5 }
]
}
},
{
field: 'section',
label: '节次',
component: 'Select',
required: true,
componentProps: {
options: Array(8).fill(0).map((_, i) => ({
label: `第${i + 1}节`,
value: (i + 1).toString()
}))
}
},
{
field: 'weeks',
label: '周数',
component: 'Select',
required: true,
componentProps: {
mode: 'multiple',
options: Array(16).fill(0).map((_, i) => ({
label: `第${i + 1}周`,
value: i + 1
}))
}
}
]
}
},
{
component: 'Divider',
label: '提醒设置'
},
{
field: 'remind.enable',
label: '开启提醒',
component: 'Switch'
},
{
field: 'remind.advance',
label: '提前提醒(分钟)',
component: 'InputNumber',
componentProps: {
min: 1,
max: 60
}
},
{
field: 'remind.mode',
label: '提醒方式',
component: 'Select',
componentProps: {
options: [
{ label: '私聊提醒', value: 'private' },
{ label: '群聊提醒', value: 'group' }
]
}
}
],
getConfigData(form = {}) {
const userId = form.userId
if (!userId) return {}
return Config.getUserConfig(userId)
},
setConfigData(data, { Result }) {
try {
const userId = data.userId
if (!userId) {
return Result.error('请选择用户')
}
delete data.userId
Config.setUserConfig(userId, data)
return Result.ok({}, '保存成功')
} catch(e) {
return Result.error(e.message)
}
}
}
}
}