소스 검색

fix: merge bug

wzyyy 3 년 전
부모
커밋
f9ac11ce6b

+ 26 - 11
src/pages/account/Center/index.tsx

@@ -37,6 +37,7 @@ const Center = () => {
   const [infos, setInfos] = useState<boolean>(false);
   const [password, setPassword] = useState<boolean>(false);
   const [bindList, setBindList] = useState<any>([]);
+  const [apiUser, setApiUser] = useState<any>();
 
   const iconMap = new Map();
   iconMap.set('dingtalk-ent-app', require('/public/images/notice/dingtalk.png'));
@@ -58,6 +59,17 @@ const Center = () => {
       setImageUrl(res.result.avatar);
     });
   };
+
+  const getApiUser = async () => {
+    const res = await service.queryCurrent();
+    if (res.status === 200) {
+      const isApiUser = res.result.dimensions.find(
+        (item: any) => item.type === 'api-client' || item.type.id === 'api-client',
+      );
+      setApiUser(isApiUser);
+    }
+  };
+
   const uploadProps: UploadProps = {
     showUploadList: false,
     accept: 'image/jpeg,image/png',
@@ -136,6 +148,7 @@ const Center = () => {
 
   useEffect(() => {
     getDetail();
+    getApiUser();
     if (isNoCommunity) {
       getBindInfo();
     }
@@ -330,17 +343,19 @@ const Center = () => {
           </Row>
         </Card>
       )}
-      <Card
-        style={{ marginTop: 15 }}
-        title={
-          <div style={{ fontSize: '22px' }}>
-            <Divider type="vertical" style={{ backgroundColor: '#2F54EB', width: 3 }} />
-            首页视图
-          </div>
-        }
-      >
-        <AccountInit />,
-      </Card>
+      {!apiUser && (
+        <Card
+          style={{ marginTop: 15 }}
+          title={
+            <div style={{ fontSize: '22px' }}>
+              <Divider type="vertical" style={{ backgroundColor: '#2F54EB', width: 3 }} />
+              首页视图
+            </div>
+          }
+        >
+          <AccountInit />,
+        </Card>
+      )}
       {infos && (
         <InfoEdit
           data={data}

+ 4 - 0
src/pages/account/Center/service.ts

@@ -74,6 +74,10 @@ class Service extends BaseService<UserItem> {
     request(`/${SystemConst.API_BASE}/system/config/${scopes}`, {
       method: 'GET',
     });
+  queryCurrent = () =>
+    request(`/${SystemConst.API_BASE}/authorize/me`, {
+      method: 'GET',
+    });
 }
 
 export default Service;

+ 34 - 5
src/pages/device/Category/index.tsx

@@ -13,6 +13,8 @@ import SearchComponent from '@/components/SearchComponent';
 import { PermissionButton } from '@/components';
 import { useDomFullHeight } from '@/hooks';
 import { onlyMessage } from '@/utils/util';
+import { service as api } from '@/pages/device/Product';
+import { Spin } from 'antd';
 
 export const service = new Service('device/category');
 
@@ -55,6 +57,8 @@ const Category = observer(() => {
   const permissionCode = 'device/Category';
   const { permission } = PermissionButton.usePermission(permissionCode);
   const { minHeight } = useDomFullHeight(`.device-category`, 24);
+  const [loading, setLoading] = useState<boolean>(true);
+  const [title, setTitle] = useState<string>('');
 
   const intl = useIntl();
 
@@ -135,11 +139,30 @@ const Category = observer(() => {
           type="link"
           key="delete"
           style={{ padding: 0 }}
+          onClick={async () => {
+            const res: any = await api.queryNoPagingPost({
+              terms: [{ terms: [{ column: 'classifiedId', value: record.id }] }],
+            });
+            if (res.status === 200) {
+              if (res.result.length === 0) {
+                setTitle('确定删除?');
+              } else {
+                setTitle('该数据已被产品引用,确定删除?');
+              }
+              setLoading(false);
+            } else {
+              setLoading(false);
+            }
+          }}
           popConfirm={{
-            title: intl.formatMessage({
-              id: 'pages.system.role.option.delete',
-              defaultMessage: '确定要删除吗',
-            }),
+            title: <>{loading ? <Spin /> : title}</>,
+            okButtonProps: {
+              loading: loading,
+            },
+            onCancel: () => {
+              setTitle('');
+              setLoading(true);
+            },
             onConfirm: async () => {
               const resp = (await service.remove(record.id)) as Response<any>;
               if (resp.status === 200) {
@@ -180,7 +203,13 @@ const Category = observer(() => {
         request={async (params) => {
           const response = await service.queryTree({
             paging: false,
-            sorts: [sortParam],
+            sorts: [
+              sortParam,
+              {
+                name: 'createTime',
+                order: 'desc',
+              },
+            ],
             ...params,
           });
           setTreeData(response.result);

+ 5 - 0
src/pages/device/Instance/Detail/Running/Property/EditProperty.tsx

@@ -32,6 +32,11 @@ const EditProperty = (props: Props) => {
         title: data?.name || '自定义属性',
         required: true,
         'x-decorator': 'FormItem',
+        'x-decorator-props': {
+          gridSpan: 2,
+          labelAlign: 'left',
+          layout: 'vertical',
+        },
         'x-component': 'Input',
       },
     },

+ 38 - 10
src/pages/device/Instance/index.tsx

@@ -258,17 +258,16 @@ const Instance = () => {
       filterMultiple: true,
     },
     {
-      title: intl.formatMessage({
-        id: 'pages.device.instance.registrationTime',
-        defaultMessage: '注册时间',
-      }),
-      dataIndex: 'registryTime',
+      title: '创建时间',
+      dataIndex: 'createTime',
       width: '200px',
       valueType: 'dateTime',
       render: (_: any, row) => {
         return row.registryTime ? moment(row.registryTime).format('YYYY-MM-DD HH:mm:ss') : '';
       },
+      defaultSortOrder: 'descend',
       sorter: true,
+      sortDirections: ['ascend', 'descend'],
     },
     {
       title: intl.formatMessage({
@@ -656,17 +655,46 @@ const Instance = () => {
         params={searchParams}
         options={{ fullScreen: true }}
         columnEmptyText={''}
-        request={(params) =>
-          service.query({
+        // request={(params,sort) =>
+        //   service.query({
+        //     ...params,
+        //     sorts: [
+        //       {
+        //         name: 'createTime',
+        //         order: 'desc',
+        //       },
+        //     ],
+        //   })
+        // }
+        request={async (params, sort) => {
+          let sorts;
+          if (sort.createTime) {
+            sorts = sort.createTime === 'descend' ? 'desc' : 'asc';
+          } else {
+            sorts = 'desc';
+          }
+          console.log(sorts);
+          const res = await service.query({
             ...params,
             sorts: [
               {
                 name: 'createTime',
-                order: 'desc',
+                order: sorts,
               },
             ],
-          })
-        }
+          });
+          return {
+            code: res.message,
+            result: {
+              data: res.result.data,
+              pageIndex: res.result.pageIndex,
+              pageSize: res.result.pageSize,
+              total: res.result.total,
+            },
+            status: res.status,
+          };
+          // return service.queryLog(InstanceModel.detail.id!, params);
+        }}
         rowKey="id"
         search={false}
         tableAlertRender={({ selectedRowKeys }) => <div>已选择 {selectedRowKeys.length} 项</div>}

+ 12 - 6
src/pages/device/components/Metadata/Base/index.tsx

@@ -142,12 +142,18 @@ const BaseMetadata = observer((props: Props) => {
 
   const handleSearch = async (name: string) => {
     if (name) {
-      const result = await DB.getDB()
-        .table(`${type}`)
-        .where('id')
-        .startsWithAnyOfIgnoreCase(name)
-        .toArray();
-      setData(result.sort((a, b) => b?.sortsIndex - a?.sortsIndex));
+      // const result = await DB.getDB()
+      //   .table(`${type}`)
+      //   .where('name')
+      //   .startsWithAnyOfIgnoreCase(name)
+      //   .toArray();
+      // setData(result.sort((a, b) => b?.sortsIndex - a?.sortsIndex));
+      const result = await DB.getDB().table(`${type}`).toArray();
+      const arr = result
+        .filter((item) => item.name.indexOf(name) > -1)
+        .sort((a, b) => b?.sortsIndex - a?.sortsIndex);
+      // console.log(result, arr)
+      setData(arr);
     } else {
       await initData();
     }

+ 20 - 16
src/pages/home/Api/index.tsx

@@ -12,12 +12,16 @@ export default () => {
   const [clientId, setClientId] = useState('');
   const [secureKey, setSecureKey] = useState('');
   const [sdkDetail, setSdkDetail] = useState<any>({});
+  const [loading, setLoading] = useState<boolean>(false);
 
   const getDetail = async (id: string) => {
     const resp = await service.getDetail(id);
     if (resp.status === 200) {
       setClientId(resp.result?.id);
-      setSecureKey(resp.result?.secureKey);
+      setSecureKey(resp.result?.apiServer?.secureKey);
+      setLoading(true);
+    } else {
+      setLoading(true);
     }
   };
 
@@ -46,20 +50,12 @@ export default () => {
     getSDKDetail();
     api.userDetail().then((res) => {
       if (res.status === 200) {
-        api
-          .apiDetail({
-            terms: [
-              {
-                column: 'userId',
-                value: res.result.id,
-              },
-            ],
-          })
-          .then((response) => {
-            if (response.status === 200) {
-              getDetail(response.result.data[0].id);
-            }
-          });
+        api.apiDetail(res.result.id).then((response) => {
+          if (response.status === 200) {
+            console.log(response.result);
+            getDetail(response.result.id);
+          }
+        });
       }
     });
   }, []);
@@ -118,7 +114,15 @@ export default () => {
       </Col>
       <Col span={24}>
         <Card title={'API文档'}>
-          <ApiPage type={'authorize'} showDebugger={true} isShowGranted={true} showHome={true} />
+          {loading && (
+            <ApiPage
+              type={'authorize'}
+              showDebugger={true}
+              isShowGranted={true}
+              showHome={true}
+              code={clientId}
+            />
+          )}
         </Card>
       </Col>
     </Row>

+ 10 - 0
src/pages/home/device/index.tsx

@@ -17,7 +17,9 @@ const Device = () => {
   const rulePermission = PermissionButton.usePermission('rule-engine/Instance').permission;
 
   const [productCount, setProductCount] = useState<number>(0);
+  const [productMessage, setProductMessage] = useState<string>();
   const [deviceCount, setDeviceCount] = useState<number>(0);
+  const [deviceMessage, setDeviceMessage] = useState<string>();
 
   const [productVisible, setProductVisible] = useState<boolean>(false);
   const [deviceVisible, setDeviceVisible] = useState<boolean>(false);
@@ -27,6 +29,9 @@ const Device = () => {
     if (resp.status === 200) {
       setProductCount(resp.result);
     }
+    if (resp.status === 403) {
+      setProductMessage('暂无产品权限');
+    }
   };
 
   const getDeviceCount = async () => {
@@ -34,6 +39,9 @@ const Device = () => {
     if (resp.status === 200) {
       setDeviceCount(resp.result);
     }
+    if (resp.status === 403) {
+      setDeviceMessage('暂无设备权限');
+    }
   };
 
   useEffect(() => {
@@ -95,11 +103,13 @@ const Device = () => {
               name: '产品数量',
               value: productCount,
               children: require('/public/images/home/top-2.png'),
+              permission: productMessage,
             },
             {
               name: '设备数量',
               value: deviceCount,
               children: '',
+              permission: deviceMessage,
             },
           ]}
           title="设备统计"

+ 1 - 1
src/pages/home/index.tsx

@@ -57,7 +57,7 @@ const Home = () => {
           const isApiUser = res.result.dimensions.find(
             (item: any) => item.type === 'api-client' || item.type.id === 'api-client',
           );
-          console.log(isApiUser);
+          // console.log(isApiUser);
           setApiUser(isApiUser);
           service.queryViews().then((resp) => {
             setLoading(false);

+ 9 - 4
src/pages/home/service.ts

@@ -33,10 +33,15 @@ class Service {
     request(`/${SystemConst.API_BASE}/user/detail`, {
       method: 'GET',
     });
-  apiDetail = (data: any) =>
-    request(`/${SystemConst.API_BASE}/api-client/_query`, {
-      method: 'POST',
-      data,
+  // apiDetail = (data: any) =>
+  //   request(`/${SystemConst.API_BASE}/api-client/_query`, {
+  //     method: 'POST',
+  //     data,
+  //   });
+  apiDetail = (id: any) =>
+    request(`/${SystemConst.API_BASE}/application/${id}`, {
+      method: 'GET',
+      // data,
     });
   // settingDetail = (data?: any) =>
   //   request(`/${SystemConst.API_BASE}/system/config/scopes`, {

+ 2 - 2
src/pages/system/Basis/index.tsx

@@ -148,9 +148,9 @@ const Basis = () => {
                   >
                     <UploadImage
                       size={1}
-                      types={['image/x-icon', 'image/jpeg', 'image/png']}
+                      types={['image/x-icon']}
                       backgroundSize={'inherit'}
-                      errorMessage={'请上传.ico.jpg.png.jfif.pjp.pjpeg.jpeg格式的图片'}
+                      errorMessage={'请上传ico格式的图片'}
                     />
                   </Form.Item>
                 </Col>

+ 5 - 2
src/pages/system/Platforms/Api/base.tsx

@@ -38,6 +38,7 @@ interface ApiPageProps {
   isOpenGranted?: boolean;
   type?: 'all' | 'empowerment' | 'authorize';
   showHome?: boolean;
+  code?: string;
 }
 
 export default observer((props: ApiPageProps) => {
@@ -70,7 +71,7 @@ export default observer((props: ApiPageProps) => {
    */
   const getApiGrant = useCallback(() => {
     const param = new URLSearchParams(location.search);
-    const code = param.get('code');
+    const code = props.code ? props.code : param.get('code');
 
     if (props.isOpenGranted === false) {
       service.apiOperations().then((resp: any) => {
@@ -79,18 +80,20 @@ export default observer((props: ApiPageProps) => {
         }
       });
     } else {
+      console.log(props.code, 1111111);
       service.getApiGranted(code!).then((resp: any) => {
         if (resp.status === 200) {
           setGrantKeys(resp.result);
         }
       });
     }
-  }, [location, props.isOpenGranted]);
+  }, [location, props.isOpenGranted, props.code]);
 
   useEffect(() => {
     initModel();
     getOperations();
     getApiGrant();
+    console.log(props.code);
   }, []);
 
   return (

+ 14 - 1
src/pages/system/Platforms/Api/swagger-ui/debugging.tsx

@@ -35,7 +35,20 @@ export default observer(() => {
     );
   };
 
+  const isBody = () => {
+    const obj = Object.keys(ApiModel.debugger?.body || {});
+    const url = ApiModel.swagger.url.indexOf('{' || '}');
+    if (ApiModel.debugger.body && obj.length !== 0) {
+      return true;
+    } else if (url !== -1) {
+      return true;
+    } else {
+      return false;
+    }
+  };
+
   useEffect(() => {
+    console.log('ApiModel.debugger.body', ApiModel.debugger.body);
     if (ApiModel.debugger.body && editor.current) {
       const { editor: MEditor } = editor.current;
       MEditor.setValue(JSON.stringify(ApiModel.debugger.body));
@@ -234,7 +247,7 @@ export default observer(() => {
               <SchemaField schema={schema} />
             </FormProvider>
           )}
-          {ApiModel.debugger.body && (
+          {isBody() && (
             <MonacoEditor
               height={200}
               language={'json'}

+ 2 - 0
src/pages/system/Platforms/Api/swagger-ui/index.tsx

@@ -13,6 +13,8 @@ export default (props: SwaggerProps) => {
       <Button
         onClick={() => {
           ApiModel.showTable = true;
+          ApiModel.swagger = {};
+          ApiModel.debugger = {};
         }}
         className={'platforms-api-swagger-back'}
       >