Kaynağa Gözat

bugfix: 修复几个已知问题,部署站点增加二次确认

tuon 1 yıl önce
ebeveyn
işleme
d9e02e8b1f

+ 40 - 21
src/pages/nginx/components/site/index.tsx

@@ -1,4 +1,4 @@
-import {Button, Drawer, Form, Input, Switch} from "antd";
+import {Button, Drawer, Form, Input, Modal, Switch} from "antd";
 import {
     Message
 } from "planning-tools";
@@ -30,7 +30,8 @@ export const SiteInput = ({ location, onChange }: IProps) => {
 
     const [complete,setComplete] = useState(false)
     const [loading,setLoading] = useState(false)
-    const [form] = Form.useForm()
+    const [form] = Form.useForm();
+    const [modal,modalContextHolder] = Modal.useModal();
 
     const nginx = useAppSelector(state => state.nginx.current);
 
@@ -44,9 +45,9 @@ export const SiteInput = ({ location, onChange }: IProps) => {
             return;
         }
         const initialData :Partial<IDeployReq> = {
-          clear: false,
           ...location.__deploy__ as any,
             nginxId: nginx.id,
+          clear: false,
         }
         if (!initialData.dir){
           if (location.alias){
@@ -61,37 +62,54 @@ export const SiteInput = ({ location, onChange }: IProps) => {
     const updateLocation = (deployData: IDeployReq) => {
       const cacheData = {
         cmd: deployData.cmd,
-        clear: deployData.clear,
         dir: deployData.dir,
       };
       onChange?.({ ...location, __deploy__: cacheData})
     }
 
-    const onSubmitData = async ()=>{
-      if (!nginx?.id){
-          return
-      }
-      const values = await form.validateFields()
-        console.log('onSubmitData',values)
-
+    const onRequest = (postData: IDeployReq)=>{
       setLoading(true)
-        const postData: IDeployReq = {
-          key: "",
-            dir:"",
-          ...editData,
-            ...values,
-          nginxId: nginx.id,
-        }
+
       uploadApis.deploy(postData)
           .then(()=>{
-              Message.success('部署成功!');
-              updateLocation(postData);
+            Message.success('部署成功!');
+            updateLocation(postData);
           })
           .finally(()=>{
-              setLoading(false)
+            setLoading(false)
           })
     }
 
+    const onSubmitData = async ()=>{
+      if (!nginx?.id){
+          return
+      }
+      const values = await form.validateFields()
+      const postData: IDeployReq = {
+        key: "",
+        dir:"",
+        ...editData,
+        ...values,
+        nginxId: nginx.id,
+      }
+        console.log('onSubmitData',postData);
+      if (postData.clear){
+        modal.confirm({
+          title: '警告',
+          content: '您确定要全量部署吗?改操作将会删除部署目录下的所有问题,请谨慎选择!',
+          cancelText: '取消全量部署',
+          okText: '仍然继续',
+          onCancel: ()=>{
+            postData.clear = false;
+            onRequest(postData)
+          },
+          onOk: ()=>onRequest(postData),
+        })
+        return;
+      }
+      await onRequest(postData);
+    }
+
     /**
      * 文件上传完成的回调
      * @param batchId
@@ -135,6 +153,7 @@ export const SiteInput = ({ location, onChange }: IProps) => {
                     </div>
                 </Form>
             </Drawer>
+          {modalContextHolder}
         </>
     )
 }

+ 8 - 6
src/pages/nginx/http/utils.ts

@@ -133,16 +133,18 @@ export const toNginxConf = ( nginx: INginx, data: any)=>{
     // lines.push(`    include ${nginx.nginxDir}/conf.d/*.conf;`)
     lines.push('}')
 
+  if (data.stream){
     lines.push(`stream {`)
     if (nginxObj.stream){
-        Object.keys(nginxObj.stream).forEach(k=>{
-          const value = nginxObj.stream[k]
-          append2Lines(`    `, lines,k,value)
-        })
-        lines.push(`    include ${nginx.dataDir}/stream.d/*.conf;`)
-        // lines.push(`    include ${nginx.nginxDir}/stream.d/*.conf;`)
+      Object.keys(nginxObj.stream).forEach(k=>{
+        const value = nginxObj.stream[k]
+        append2Lines(`    `, lines,k,value)
+      })
+      lines.push(`    include ${nginx.dataDir}/stream.d/*.conf;`)
+      // lines.push(`    include ${nginx.nginxDir}/stream.d/*.conf;`)
     }
     lines.push('}')
+  }
     return lines.join('\n')
 }
 

+ 4 - 0
src/pages/nginx/index.less

@@ -33,5 +33,9 @@
         padding: 20px;
       }
     }
+    .ant-menu{
+      overflow-y: auto;
+      overflow-x: hidden;
+    }
   }
 }

+ 1 - 1
src/pages/nginx/upstream/tab.tsx

@@ -44,7 +44,7 @@ export const UpstreamTab = forwardRef<ITabInstance, IProps>(({server, isStream},
         const upstreams = server?.upstreams;
         if (Array.isArray(upstreams) && upstreams.length){
           const items =upstreams.map((item: any)=>{
-              const copy = {...item};
+              const copy = {...item,editing: false};
             if (!copy.key){
                 copy.key = uniqueKey(20)
             }

+ 19 - 4
src/pages/nginx/utils/index.ts

@@ -1,4 +1,4 @@
-import {INginx, INginxServer} from "../../../models/nginx.ts";
+import {INginx, INginxServer, IUpstream} from "../../../models/nginx.ts";
 import {isBasicData, isFalse, isNull} from "planning-tools";
 import {cloneDeep, isBoolean} from "lodash";
 import {isNgxModuleValue, NgxModuleData} from "../components/input.ts";
@@ -30,8 +30,24 @@ const serverBlacklist:{[key:string]:boolean} = {
  */
 export const renderUpstream = (server: Partial<INginxServer>) =>{
   const lines: string[]= [];
-  lines.push(`### upstream    ${server.isStream ? 'stream': 'http'}`)
-  server.upstreams?.forEach(up=>{
+  lines.push(`### upstream    ${server.isStream ? 'stream': 'http'}`);
+  const upstreamMap: {[key:string]: IUpstream} = {};
+  server.upstreams?.forEach(item=>{
+    if (!item.enable){
+      return
+    }
+    let upstream = upstreamMap[item.name];
+    if (!upstream){
+      upstream = item;
+      upstream.servers = item.servers || [];
+      upstreamMap[item.name] = upstream;
+    }else {
+      upstream.servers = upstream.servers.concat(item.servers);
+    }
+  })
+
+  const upstreams = Object.values(upstreamMap);
+  upstreams?.forEach(up=>{
     if (!up.enable){
       return
     }
@@ -54,7 +70,6 @@ export const renderUpstream = (server: Partial<INginxServer>) =>{
       })
       lines.push('}')
     }
-
   })
   return lines.join('\n')
 }

+ 15 - 0
src/styles/index.less

@@ -93,3 +93,18 @@
     max-width: 900px;
   }
 }
+
+::-webkit-scrollbar {
+  width: 4px;
+  height: 4px;
+}
+::-webkit-scrollbar-thumb {
+  border-radius: 2px;
+  background: var(--disable-25, rgba(0, 0, 0, 0.25));
+  max-height: 60px;
+}
+::-webkit-scrollbar-track {
+  -webkit-box-shadow: none;
+  border-radius: 0;
+  background: none;
+}