Selaa lähdekoodia

Merge branch 'dev' of github.com:allanpk716/ChineseSubFinder into dev

716 3 vuotta sitten
vanhempi
sitoutus
561b1de09a

+ 6 - 3
frontend/src/App.vue

@@ -3,8 +3,11 @@
 </template>
 <script setup>
 import {getJobsStatus, systemState} from 'src/store/systemState';
+import useInterval from 'src/composables/useInterval';
 
-if (systemState.systemInfo?.is_setup) {
-  getJobsStatus();
-}
+useInterval(() => {
+  if (systemState.systemInfo?.is_setup) {
+    getJobsStatus();
+  }
+}, 10000)
 </script>

+ 1 - 1
frontend/src/api/CommonApi.js

@@ -5,7 +5,7 @@ class CommonAPi extends BaseApi {
 
   getDefaultSettings = (params) => this.http('/def-settings', params);
 
-  checkProxy = (params) => this.http('/v1/check-proxy', params, 'POST');
+  checkProxy = (params) => this.http('/check-proxy', params, 'POST');
 
   checkPath = (params) => this.http('/check-path', params, 'POST');
 }

+ 3 - 1
frontend/src/components/ProxyCheckBtn.vue

@@ -41,7 +41,9 @@ const checkList = ref([]);
 
 const checkProxy = async () => {
   checking.value = true;
-  const [res] = await CommonApi.checkProxy(props.url)
+  const [res] = await CommonApi.checkProxy({
+    http_proxy_address: props.url
+  })
   checking.value = false;
   checkList.value = res?.sub_site_status || [];
   show.value = true;

+ 31 - 0
frontend/src/composables/useInterval.js

@@ -0,0 +1,31 @@
+import { onBeforeUnmount, ref } from 'vue';
+
+const useInterval = (fn, ms, autoStart = true) => {
+  const timer = ref(null);
+  if (autoStart) {
+    timer.value = setInterval(() => {
+      fn();
+    }, ms);
+    fn();
+  }
+  const resetInterval = () => {
+    clearInterval(timer.value);
+    timer.value = setInterval(() => {
+      fn();
+    }, ms);
+    fn();
+  };
+  const stopInterval = () => {
+    clearInterval(timer.value);
+  };
+  onBeforeUnmount(() => {
+    clearInterval(timer.value);
+  });
+  return {
+    timer,
+    resetInterval,
+    stopInterval,
+  };
+};
+
+export default useInterval;

+ 5 - 5
frontend/src/pages/access/login/index.vue

@@ -85,12 +85,12 @@ const submit = async () => {
     SystemMessage.error(err.message);
     return;
   }
-  const userData = {username: form.username, ...res};
-  Object.assign(userState, userData)
-  LocalStorage.set('token', {
-    accessToken: userData.access_token,
+  const userData = {
+    accessToken: res.access_token,
     username: form.username
-  })
+  };
+  Object.assign(userState, userData)
+  LocalStorage.set('token', userData)
   router.push('/')
 }
 </script>

+ 13 - 5
frontend/src/pages/jobs/index.vue

@@ -1,15 +1,15 @@
 <template>
   <q-page class="q-pa-md">
-    <q-card class="q-pa-md" flat>
+    <q-card v-if="systemState.jobStatus" class="q-pa-md" flat>
       <header class="column q-gutter-md">
         <div>
           当前任务状态:
-          <q-badge v-if="systemState.running" color="positive">运行中</q-badge>
+          <q-badge v-if="isRunning" color="positive">运行中</q-badge>
           <q-badge v-else color="grey">未运行</q-badge>
         </div>
         <div>
           <q-btn
-            v-if="systemState.running"
+            v-if="isRunning"
             label="强制停止"
             color="negative"
             @click="stopJobs"
@@ -23,9 +23,9 @@
 </template>
 
 <script setup>
-import { systemState } from 'src/store/systemState';
+import {getJobsStatus, systemState} from 'src/store/systemState';
 import { useQuasar } from 'quasar';
-import { ref } from 'vue';
+import {computed, onMounted, ref} from 'vue';
 import JobApi from 'src/api/JobApi';
 import { SystemMessage } from 'src/utils/Message';
 
@@ -33,6 +33,8 @@ const $q = useQuasar();
 
 const submitting = ref(false);
 
+const isRunning = computed(() => systemState.jobStatus?.status === 'running')
+
 const startJobs = () => {
   $q.dialog({
     title: '立即运行任务?',
@@ -45,6 +47,7 @@ const startJobs = () => {
       SystemMessage.error(err.message);
       return;
     }
+    getJobsStatus();
     SystemMessage.success('启动成功');
   });
 };
@@ -60,7 +63,12 @@ const stopJobs = () => {
       SystemMessage.error(err.message);
       return;
     }
+    getJobsStatus();
     SystemMessage.success('停止成功');
   });
 };
+
+onMounted(() => {
+  getJobsStatus();
+})
 </script>

+ 8 - 2
frontend/src/pages/settings/AdvancedSettings.vue

@@ -14,7 +14,13 @@
 
         <q-item v-if="form.proxy_settings.use_http_proxy" class="q-mt-md" dense>
           <q-item-section>
-            <q-input v-model="form.httpProxyUrl" standout dense label="代理服务器地址" style="width: 400px">
+            <q-input
+              v-model="form.proxy_settings.http_proxy_address"
+              standout
+              dense
+              label="代理服务器地址"
+              style="width: 400px"
+            >
               <template v-slot:after>
                 <div style="width: 80px">
                   <proxy-check-btn :url="form.proxy_settings.http_proxy_address" />
@@ -104,7 +110,7 @@
               <div class="row items-center q-gutter-x-md" :class="{ 'q-mt-md': i === 0 }">
                 <q-input
                   v-model="form.custom_video_exts[i]"
-                  placeholder="/media/电影"
+                  placeholder=""
                   standout
                   dense
                   :rules="[(val) => !!val || '不能为空']"

+ 2 - 2
frontend/src/pages/settings/DevelopmentSettings.vue

@@ -8,12 +8,12 @@
             <q-item-label caption>
               项目维护人员使用,一般人员无需关心
             </q-item-label>
-            <div v-if="form.enabled" class="q-mt-sm">
+            <div v-if="form.enable" class="q-mt-sm">
               <q-input v-model="form.bark_server_address" standout dense />
             </div>
           </q-item-section>
           <q-item-section avatar top>
-            <q-toggle v-model="form.enabled" />
+            <q-toggle v-model="form.enable" />
           </q-item-section>
         </q-item>
       </q-list>

+ 1 - 1
frontend/src/pages/settings/useSettings.js

@@ -59,7 +59,7 @@ export const submitting = ref(false);
 
 export const submitAll = async () => {
   submitting.value = true;
-  const [, err] = await SettingApi.patchUpdate(formModel);
+  const [, err] = await SettingApi.update(formModel);
   submitting.value = false;
   if (err !== null) {
     SystemMessage.error(err.message);

+ 2 - 2
frontend/src/store/systemState.js

@@ -4,7 +4,7 @@ import JobApi from 'src/api/JobApi';
 
 export const systemState = reactive({
   systemInfo: null,
-  running: false,
+  jobStatus: null,
 });
 
 export const getInfo = async () => {
@@ -14,5 +14,5 @@ export const getInfo = async () => {
 
 export const getJobsStatus = async () => {
   const [res] = await JobApi.getStatus();
-  systemState.running = !!res?.running;
+  systemState.jobStatus = res;
 };