index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <div class="settings-page">
  3. <h2>系统设置</h2>
  4. <el-tabs v-model="activeTab">
  5. <el-tab-pane label="基础设置" name="basic">
  6. <div class="page-card">
  7. <el-form :model="settings" label-width="150px">
  8. <el-form-item label="开放注册">
  9. <el-switch v-model="settings.allowRegistration" />
  10. <span class="form-tip">允许新用户自行注册账号</span>
  11. </el-form-item>
  12. <el-form-item label="默认用户角色">
  13. <el-select v-model="settings.defaultUserRole" style="width: 200px">
  14. <el-option label="运营" value="operator" />
  15. <el-option label="编辑" value="editor" />
  16. <el-option label="管理员" value="admin" />
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button type="primary" @click="saveSettings">保存设置</el-button>
  21. </el-form-item>
  22. </el-form>
  23. </div>
  24. </el-tab-pane>
  25. <el-tab-pane label="发布代理" name="publish-proxy">
  26. <div class="page-card">
  27. <el-form :model="publishProxy" label-width="150px">
  28. <el-form-item label="神龙产品Key">
  29. <el-input v-model="publishProxy.productKey" placeholder="填写神龙产品Key" style="width: 100%" />
  30. <span class="form-tip">发布时使用该 Key 调用神龙代理获取对应地区的IP</span>
  31. </el-form-item>
  32. <el-form-item label="签名">
  33. <el-input v-model="publishProxy.signature" type="password" show-password placeholder="填写签名" style="width: 100%" />
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button type="primary" @click="savePublishProxy">保存配置</el-button>
  37. <el-button @click="loadPublishProxy">刷新</el-button>
  38. </el-form-item>
  39. </el-form>
  40. </div>
  41. </el-tab-pane>
  42. <el-tab-pane label="Python 服务" name="python-service">
  43. <div class="page-card">
  44. <el-form :model="pythonService" label-width="150px">
  45. <el-form-item label="服务地址">
  46. <el-input v-model="pythonService.url" placeholder="例如:http://localhost:5005" style="width: 100%" />
  47. <span class="form-tip">留空则使用服务端环境变量/默认值(http://localhost:5005)</span>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-button type="primary" @click="savePythonService">保存配置</el-button>
  51. <el-button @click="loadPythonService">刷新</el-button>
  52. <el-button @click="checkPythonService" :loading="checkingPython">测试连接</el-button>
  53. </el-form-item>
  54. </el-form>
  55. <div v-if="pythonCheckResult" style="margin-top: 12px;">
  56. <el-alert
  57. :type="pythonCheckResult.ok ? 'success' : 'error'"
  58. :title="pythonCheckResult.ok ? '连接成功' : '连接失败'"
  59. :description="pythonCheckResult.ok ? `HTTP ${pythonCheckResult.status || ''}` : (pythonCheckResult.error || '请求失败')"
  60. show-icon
  61. />
  62. </div>
  63. </div>
  64. </el-tab-pane>
  65. <el-tab-pane label="用户管理" name="users">
  66. <div class="page-card">
  67. <div class="table-header">
  68. <el-button type="primary" @click="showAddUserDialog = true">
  69. 添加用户
  70. </el-button>
  71. </div>
  72. <el-table :data="users" v-loading="loadingUsers">
  73. <el-table-column prop="username" label="用户名" />
  74. <el-table-column prop="email" label="邮箱" />
  75. <el-table-column prop="role" label="角色" width="100">
  76. <template #default="{ row }">
  77. <el-tag>{{ getRoleText(row.role) }}</el-tag>
  78. </template>
  79. </el-table-column>
  80. <el-table-column prop="status" label="状态" width="100">
  81. <template #default="{ row }">
  82. <el-tag :type="row.status === 'active' ? 'success' : 'danger'">
  83. {{ row.status === 'active' ? '正常' : '禁用' }}
  84. </el-tag>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作" width="150">
  88. <template #default="{ row }">
  89. <el-button type="primary" link size="small" @click="editUser(row)">
  90. 编辑
  91. </el-button>
  92. <el-button
  93. type="danger"
  94. link
  95. size="small"
  96. @click="deleteUser(row.id)"
  97. :disabled="row.id === authStore.user?.id"
  98. >
  99. 删除
  100. </el-button>
  101. </template>
  102. </el-table-column>
  103. </el-table>
  104. </div>
  105. </el-tab-pane>
  106. <el-tab-pane label="系统状态" name="status">
  107. <div class="page-card">
  108. <el-descriptions :column="2" border>
  109. <el-descriptions-item label="数据库">
  110. <el-tag :type="systemStatus.database === 'connected' ? 'success' : 'danger'">
  111. {{ systemStatus.database === 'connected' ? '已连接' : '未连接' }}
  112. </el-tag>
  113. </el-descriptions-item>
  114. <el-descriptions-item label="Redis">
  115. <el-tag :type="systemStatus.redis === 'connected' ? 'success' : 'danger'">
  116. {{ systemStatus.redis === 'connected' ? '已连接' : '未连接' }}
  117. </el-tag>
  118. </el-descriptions-item>
  119. <el-descriptions-item label="在线用户">{{ systemStatus.onlineUsers }}</el-descriptions-item>
  120. <el-descriptions-item label="总用户数">{{ systemStatus.totalUsers }}</el-descriptions-item>
  121. <el-descriptions-item label="平台账号数">{{ systemStatus.totalAccounts }}</el-descriptions-item>
  122. <el-descriptions-item label="发布任务数">{{ systemStatus.totalTasks }}</el-descriptions-item>
  123. <el-descriptions-item label="运行时间">{{ formatUptime(systemStatus.uptime) }}</el-descriptions-item>
  124. </el-descriptions>
  125. </div>
  126. </el-tab-pane>
  127. </el-tabs>
  128. </div>
  129. </template>
  130. <script setup lang="ts">
  131. import { ref, reactive, onMounted } from 'vue';
  132. import { ElMessage, ElMessageBox } from 'element-plus';
  133. import request from '@/api/request';
  134. import { useAuthStore } from '@/stores/auth';
  135. import type { User } from '@media-manager/shared';
  136. const authStore = useAuthStore();
  137. const activeTab = ref('basic');
  138. const loadingUsers = ref(false);
  139. const settings = reactive({
  140. allowRegistration: false,
  141. defaultUserRole: 'operator',
  142. });
  143. const publishProxy = reactive({
  144. productKey: '',
  145. signature: '',
  146. });
  147. const pythonService = reactive({
  148. url: '',
  149. });
  150. const checkingPython = ref(false);
  151. const pythonCheckResult = ref<any | null>(null);
  152. const users = ref<User[]>([]);
  153. const showAddUserDialog = ref(false);
  154. const systemStatus = reactive({
  155. database: 'disconnected',
  156. redis: 'disconnected',
  157. onlineUsers: 0,
  158. totalUsers: 0,
  159. totalAccounts: 0,
  160. totalTasks: 0,
  161. uptime: 0,
  162. });
  163. function getRoleText(role: string) {
  164. const texts: Record<string, string> = {
  165. admin: '管理员',
  166. editor: '编辑',
  167. operator: '运营',
  168. };
  169. return texts[role] || role;
  170. }
  171. function formatUptime(seconds: number) {
  172. const days = Math.floor(seconds / 86400);
  173. const hours = Math.floor((seconds % 86400) / 3600);
  174. const minutes = Math.floor((seconds % 3600) / 60);
  175. return `${days}天 ${hours}小时 ${minutes}分钟`;
  176. }
  177. async function loadSettings() {
  178. try {
  179. const config = await request.get('/api/system/config');
  180. settings.allowRegistration = config.allowRegistration;
  181. settings.defaultUserRole = config.defaultUserRole;
  182. } catch {
  183. // 错误已处理
  184. }
  185. }
  186. async function loadPublishProxy() {
  187. try {
  188. const config = await request.get('/api/system/publish-proxy');
  189. publishProxy.productKey = String(config.productKey || '');
  190. publishProxy.signature = String(config.signature || '');
  191. } catch {
  192. // 错误已处理
  193. }
  194. }
  195. async function savePublishProxy() {
  196. try {
  197. await request.put('/api/system/publish-proxy', {
  198. productKey: publishProxy.productKey,
  199. signature: publishProxy.signature,
  200. });
  201. ElMessage.success('发布代理配置已保存');
  202. loadPublishProxy();
  203. } catch {
  204. // 错误已处理
  205. }
  206. }
  207. async function loadPythonService() {
  208. try {
  209. const config = await request.get('/api/system/python-service');
  210. pythonService.url = String(config.url || '');
  211. } catch {
  212. // 错误已处理
  213. }
  214. }
  215. async function savePythonService() {
  216. try {
  217. await request.put('/api/system/python-service', {
  218. url: pythonService.url,
  219. });
  220. ElMessage.success('Python 服务配置已保存');
  221. loadPythonService();
  222. } catch {
  223. // 错误已处理
  224. }
  225. }
  226. async function checkPythonService() {
  227. checkingPython.value = true;
  228. pythonCheckResult.value = null;
  229. try {
  230. const result = await request.post('/api/system/python-service/check', {
  231. url: pythonService.url || undefined,
  232. });
  233. pythonCheckResult.value = result;
  234. if (result.ok) {
  235. ElMessage.success('连接成功');
  236. } else {
  237. ElMessage.error('连接失败');
  238. }
  239. } catch {
  240. pythonCheckResult.value = { ok: false, error: '请求失败' };
  241. ElMessage.error('连接失败');
  242. } finally {
  243. checkingPython.value = false;
  244. }
  245. }
  246. async function saveSettings() {
  247. try {
  248. await request.put('/api/system/config', settings);
  249. ElMessage.success('设置已保存');
  250. } catch {
  251. // 错误已处理
  252. }
  253. }
  254. async function loadUsers() {
  255. loadingUsers.value = true;
  256. try {
  257. const result = await request.get('/api/users');
  258. users.value = result.items;
  259. } catch {
  260. // 错误已处理
  261. } finally {
  262. loadingUsers.value = false;
  263. }
  264. }
  265. async function loadSystemStatus() {
  266. try {
  267. const status = await request.get('/api/system/status');
  268. Object.assign(systemStatus, status);
  269. } catch {
  270. // 错误已处理
  271. }
  272. }
  273. function editUser(user: User) {
  274. ElMessage.info('编辑功能开发中');
  275. }
  276. async function deleteUser(id: number) {
  277. try {
  278. await ElMessageBox.confirm('确定要删除该用户吗?', '提示', { type: 'warning' });
  279. await request.delete(`/api/users/${id}`);
  280. ElMessage.success('删除成功');
  281. loadUsers();
  282. } catch {
  283. // 取消或错误
  284. }
  285. }
  286. onMounted(() => {
  287. loadSettings();
  288. loadPublishProxy();
  289. loadPythonService();
  290. loadUsers();
  291. loadSystemStatus();
  292. });
  293. </script>
  294. <style lang="scss" scoped>
  295. @use '@/styles/variables.scss' as *;
  296. h2 {
  297. margin: 0 0 20px;
  298. }
  299. .table-header {
  300. margin-bottom: 16px;
  301. }
  302. .form-tip {
  303. margin-left: 12px;
  304. color: $text-secondary;
  305. font-size: 13px;
  306. }
  307. </style>