xieyonghong 3 лет назад
Родитель
Сommit
8ce5a883d2

+ 35 - 9
src/pages/system/Platforms/View/index.tsx

@@ -1,9 +1,10 @@
 import { PageContainer } from '@ant-design/pro-layout';
-import { Button, Card, Col, Popover, Row } from 'antd';
+import { Button, Card, Col, Input, Popover, Row } from 'antd';
 import ApiPage from '../Api/base';
 import { useEffect, useState } from 'react';
 import { useLocation } from 'umi';
 import { service } from '@/pages/system/Platforms';
+import * as moment from 'moment';
 
 const defaultHeight = 50;
 
@@ -12,6 +13,7 @@ export default () => {
 
   const [clientId, setClientId] = useState('');
   const [secureKey, setSecureKey] = useState('');
+  const [sdkDetail, setSdkDetail] = useState<any>({});
 
   const getDetail = async (id: string) => {
     const resp = await service.getDetail(id);
@@ -21,6 +23,26 @@ export default () => {
     }
   };
 
+  const getSDKDetail = async () => {
+    const resp = await service.getSdk();
+    if (resp.status === 200) {
+      setSdkDetail(resp.result[0]);
+    }
+  };
+
+  const downLoad = (url: string) => {
+    if (url) {
+      const downNode = document.createElement('a');
+      downNode.href = url;
+      downNode.download = `${moment(new Date()).format('YYYY-MM-DD-HH-mm-ss')}.sdk`;
+      downNode.style.display = 'none';
+      downNode.setAttribute('target', '_blank');
+      document.body.appendChild(downNode);
+      downNode.click();
+      document.body.removeChild(downNode);
+    }
+  };
+
   useEffect(() => {
     const param = new URLSearchParams(location.search);
     const code = param.get('code');
@@ -31,25 +53,29 @@ export default () => {
 
   useEffect(() => {
     //  请求SDK下载地址
+    getSDKDetail();
   }, []);
 
   const downLoadJDK = (
     <div>
       <div
         style={{
-          width: 300,
-          height: 120,
-          padding: 12,
-          border: '1px solid #e9e9e9',
+          width: 500,
           borderRadius: 2,
           marginBottom: 12,
         }}
       >
-        暂时没有接口
-      </div>
-      <div>
-        <Button type={'primary'}>jar下载</Button>
+        <Input.TextArea value={sdkDetail?.dependency} rows={6} readOnly />
       </div>
+      <Button
+        type={'primary'}
+        style={{ width: '100%' }}
+        onClick={() => {
+          downLoad(sdkDetail.sdk);
+        }}
+      >
+        jar下载
+      </Button>
     </div>
   );
 

+ 11 - 3
src/pages/system/Platforms/save.tsx

@@ -1,4 +1,4 @@
-import { createForm } from '@formily/core';
+import { createForm, onFieldValueChange } from '@formily/core';
 import type { Field } from '@formily/core';
 import { createSchemaField } from '@formily/react';
 import {
@@ -79,6 +79,13 @@ export default (props: SaveProps) => {
     () =>
       createForm({
         validateFirst: false,
+        effects() {
+          onFieldValueChange('enableOAuth2', (field) => {
+            form.setFieldState('redirectUrl', (state) => {
+              state.display = field.value ? 'visible' : 'none';
+            });
+          });
+        },
       }),
     [props.data],
   );
@@ -100,7 +107,8 @@ export default (props: SaveProps) => {
       } else {
         form.setValues({
           enableOAuth2: true,
-          id: randomString(),
+          id: randomString(16),
+          secureKey: randomString(),
         });
       }
     } else {
@@ -362,7 +370,7 @@ export default (props: SaveProps) => {
             ],
           },
           redirectUrl: {
-            type: 'boolean',
+            type: 'string',
             title: 'redirectUrl',
             required: true,
             'x-decorator': 'FormItem',

+ 6 - 1
src/pages/system/Platforms/service.ts

@@ -4,7 +4,7 @@ import SystemConst from '@/utils/const';
 
 class Service extends BaseService<platformsType> {
   queryRoleList = (params?: any) =>
-    request(`${SystemConst.API_BASE}/role/_query/no-paging?paging=false`, {
+    request(`/${SystemConst.API_BASE}/role/_query/no-paging?paging=false`, {
       method: 'GET',
       params,
     });
@@ -66,6 +66,11 @@ class Service extends BaseService<platformsType> {
    */
   apiOperations = () =>
     request(`/${SystemConst.API_BASE}/api-client/operations`, { method: 'GET' });
+
+  /**
+   * 获取可授权的接口ID
+   */
+  getSdk = () => request(`${this.uri}/sdk`, { method: 'GET' });
 }
 
 export default Service;