Procházet zdrojové kódy

feat(frontend): setup和保存设置时,后端会重启服务,前端添加加载页面提示

Signed-off-by: Myon <[email protected]>
Myon před 3 roky
rodič
revize
065f26a264

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

@@ -0,0 +1,31 @@
+// 程序状态的hook接口
+import { Loading } from 'quasar';
+import JobApi from 'src/api/JobApi';
+
+export const useAppStatusLoading = () => {
+  let timer = null;
+
+  const startLoading = () => {
+    Loading.show({
+      message: '正在应用程序配置',
+      html: true,
+    });
+
+    const handler = async () => {
+      const [res, err] = await JobApi.getStatus();
+      if (res || err?.error?.status <= 401) {
+        clearInterval(timer);
+        Loading.hide();
+      }
+    };
+
+    timer = setInterval(async () => {
+      handler();
+    }, 1000);
+    handler();
+  };
+
+  return {
+    startLoading,
+  };
+};

+ 2 - 0
frontend/src/pages/settings/BasicSettings.vue

@@ -142,6 +142,7 @@
                 dense
                 lazy-rules
                 :rules="[(val) => !!val || '不能为空', validateRemotePath]"
+                style="width: 200px"
               />
               <q-btn
                 v-if="i === 0"
@@ -183,6 +184,7 @@
                 standout
                 dense
                 :rules="[(val) => !!val || '不能为空', validateRemotePath]"
+                style="width: 200px"
               />
               <q-btn
                 v-if="i === 0"

+ 4 - 0
frontend/src/pages/settings/useSettings.js

@@ -2,6 +2,9 @@ import { reactive, ref, watch } from 'vue';
 import SettingApi from 'src/api/SettingApi';
 import { SystemMessage } from 'src/utils/Message';
 import { deepCopy } from 'src/utils/CommonUtils';
+import { useAppStatusLoading } from 'src/composables/useAppStatusLoading';
+
+const { startLoading } = useAppStatusLoading();
 
 export const settingsState = reactive({
   data: null,
@@ -68,6 +71,7 @@ export const submitAll = async () => {
   }
   settingsState.data = { ...settingsState.data, ...deepCopy(formModel) };
   SystemMessage.success('保存成功');
+  startLoading();
 };
 
 /**

+ 3 - 0
frontend/src/pages/setup/index.vue

@@ -59,8 +59,10 @@ import LoginBgArea from 'pages/access/login/LoginBgArea';
 import { deepCopy } from 'src/utils/CommonUtils';
 import { getInfo } from 'src/store/systemState';
 import { SUB_NAME_FORMAT_NORMAL } from 'src/constants/SettingConstants';
+import { useAppStatusLoading } from 'src/composables/useAppStatusLoading';
 
 useSetup();
+const { startLoading } = useAppStatusLoading();
 
 const router = useRouter();
 const step = ref('1');
@@ -134,6 +136,7 @@ const submit = async () => {
   }
   SystemMessage.success('初始化完成');
   await getInfo();
+  startLoading();
   router.push('/access/login');
 };
 </script>