Selaa lähdekoodia

feat(audio): 增加音频模块场站权限控制

- 在 Audio 组件中添加场站名称状态,并在列表渲染时进行权限控制
- 修改 API 配置,使用相对路径 /api 代替绝对路径
- 在 package.json 中添加针对不同环境的开发脚本
- 优化 tsconfig.json 和 tsconfig.node.json 的配置结构
- 更新 vite.config.ts 中的代理配置
wzg 4 kuukautta sitten
vanhempi
commit
f1d71c17ca
9 muutettua tiedostoa jossa 129 lisäystä ja 30 poistoa
  1. 5 2
      .env
  2. 3 1
      package.json
  3. 1 1
      src/page/audio/drawer.tsx
  4. 35 15
      src/page/audio/index.tsx
  5. 10 4
      tsconfig.json
  6. 7 5
      tsconfig.node.json
  7. 33 0
      vite.center.config.ts
  8. 2 2
      vite.config.ts
  9. 33 0
      vite.edge.config.ts

+ 5 - 2
.env

@@ -1,7 +1,8 @@
 # API配置
-VITE_API_URL=http://192.168.1.112:19801
+VITE_API_URL=/api
 # VITE_API_URL=http://localhost:8080/api
 # VITE_API_URL=http://192.168.1.52:8080/api
+# VITE_API_URL=http://vox-jdk-service:19801
 
 VITE_APP_TITLE="安全生产智能应用平台"
 
@@ -14,4 +15,6 @@ VITE_APP_FILE_NUM= 1
 # 节点配置
 VITE_APP_PERMISSION_KEY='role'
 VITE_APP_PERMISSION_VALUE_C='center'
-VITE_APP_PERMISSION_VALUE_E='edge'
+VITE_APP_PERMISSION_VALUE_E='edge'
+
+

+ 3 - 1
package.json

@@ -5,6 +5,8 @@
   "type": "module",
   "scripts": {
     "dev": "vite",
+    "dev:edge": "vite --config vite.edge.config.ts",
+    "dev:center": "vite --config vite.center.config.ts",
     "build": "vite build",
     "lint": "eslint .",
     "preview": "vite preview"
@@ -33,4 +35,4 @@
     "typescript-eslint": "^8.22.0",
     "vite": "^6.1.0"
   }
-}
+}

+ 1 - 1
src/page/audio/drawer.tsx

@@ -5,7 +5,7 @@ import { uploadTypeList, AccessType } from "./prop";
 import styles from "../../css/Drawer.module.css";
 import { getOrganizations, uploadVoiceFile, getSkillList, uploadSensors } from "../../api/index";
 import { AxiosResponse } from "axios";
-import { validateFn, validateFileLength, validateFileSize, validateFileType } from "@/util/index"
+import { validateFn, validateFileLength, validateFileSize, validateFileType } from "../../util/index"
 
 const { TextArea } = Input;
 const { Option } = Select;

+ 35 - 15
src/page/audio/index.tsx

@@ -20,6 +20,7 @@ interface DataType {
   responsiblePerson: string;
   videoType: string;
   skillUuid: string;
+  ip: string;
 }
 
 
@@ -31,6 +32,7 @@ const Audio: React.FC = () => {
   const [searchValue, setSearchValue] = useState("");
   const [idx, setIdx] = useState(0);
   const [loading, setLoading] = useState(false);
+  const [factoryName, setFactoryName] = useState("");
   const deleteDisable = useMemo(() => {
     return selectedRowKeys.length === 0;
   }, [selectedRowKeys]);
@@ -138,25 +140,39 @@ const Audio: React.FC = () => {
       width: 120,
       render: (text: string) => skillData.find(item => item.uuid === text)?.name ?? '-',
     },
+    {
+      title: "场站",
+      dataIndex: "ip",
+      key: "ip",
+      width: 120,
+      render: (text: string) => text ?? '-',
+    },
     {
       title: "操作",
       dataIndex: "operation",
       key: "operation",
       fixed: "right",
       width: 150,
-      render: (_, record) => (
-        <span style={{ display: "flex" }}>
-          <Button color="primary" variant="link" className={styles.clo} onClick={() => editskill(record, 'show')}>
-            查看
-          </Button>
-          <Button color="primary" variant="link" className={styles.clo} onClick={() => editskill(record, 'edit')}>
-            编辑
-          </Button>
-          <Button color="primary" variant="link" className={styles.clo} onClick={() => deleteFn(record.uuid)}>
-            删除
-          </Button>
-        </span>
-      ),
+      render: (_, record: any) => {
+        return (
+          <span style={{ display: "flex" }}>
+            <Button color="primary" variant="link" className={styles.clo} onClick={() => editskill(record, 'show')}>
+              查看
+            </Button>
+            {record?.ip.trim() === factoryName &&
+              (<>
+                <Button color="primary" variant="link" className={styles.clo} onClick={() => editskill(record, 'edit')}>
+                  编辑
+                </Button>
+                <Button color="primary" variant="link" className={styles.clo} onClick={() => deleteFn(record.uuid)}>
+                  删除
+                </Button>
+              </>)
+            }
+
+          </span>
+        )
+      },
     },
   ];
 
@@ -193,8 +209,9 @@ const Audio: React.FC = () => {
   const listFn = () => {
     setLoading(true);
     getSensors(params).then((res) => {
-      setDataSource(res.data.records ?? [])
-      setTotal(res.data.total ?? 0)
+      setFactoryName(res.data.edgeName?.trim())
+      setDataSource(res.data.soundSensors.records ?? [])
+      setTotal(res.data.soundSensors.total ?? 0)
       setLoading(false);
     });
   }
@@ -205,6 +222,9 @@ const Audio: React.FC = () => {
   const rowSelection: TableRowSelection<DataType> = {
     selectedRowKeys,
     onChange: onSelectChange,
+    getCheckboxProps: (record: DataType) => ({
+      disabled: record?.ip.trim() !== factoryName
+    }),
     selections: [
       Table.SELECTION_ALL,
       Table.SELECTION_INVERT,

+ 10 - 4
tsconfig.json

@@ -1,13 +1,19 @@
 {
   "files": [],
   "references": [
-    { "path": "./tsconfig.app.json" },
-    { "path": "./tsconfig.node.json" }
+    {
+      "path": "./tsconfig.app.json"
+    },
+    {
+      "path": "./tsconfig.node.json"
+    }
   ],
   "compilerOptions": {
     "baseUrl": ".",
     "paths": {
-      "@/*": ["src/*"]
+      "@/*": [
+        "src/*"
+      ]
     }
   }
-}
+}

+ 7 - 5
tsconfig.node.json

@@ -2,17 +2,17 @@
   "compilerOptions": {
     "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
     "target": "ES2022",
-    "lib": ["ES2023"],
+    "lib": [
+      "ES2023"
+    ],
     "module": "ESNext",
     "skipLibCheck": true,
-
     /* Bundler mode */
     "moduleResolution": "bundler",
     "allowImportingTsExtensions": true,
     "isolatedModules": true,
     "moduleDetection": "force",
     "noEmit": true,
-
     /* Linting */
     "strict": true,
     "noUnusedLocals": true,
@@ -20,5 +20,7 @@
     "noFallthroughCasesInSwitch": true,
     "noUncheckedSideEffectImports": true
   },
-  "include": ["vite.config.ts"]
-}
+  "include": [
+    "vite.config.ts"
+  ]
+}

+ 33 - 0
vite.center.config.ts

@@ -0,0 +1,33 @@
+import { defineConfig } from "vite";
+import react from "@vitejs/plugin-react";
+import path from "path";
+
+// https://vite.dev/config/
+export default defineConfig({
+  plugins: [react()],
+  css: {
+    modules: {
+      generateScopedName: "[name]__[local]___[hash:base64:5]", // 自定义类名生成规则
+    },
+  },
+  resolve: {
+    alias: {
+      "@": path.resolve(__dirname, "src"),
+    },
+    // mainFields: ['module', 'jsnext:main', 'jsnext', 'main'],
+  },
+  server: {
+    host: true,
+    port: 8080,
+    open: true,
+    cors: true,
+    // vite 反向代理
+    proxy: {
+      "/api": {
+        target: "http://192.168.1.112:19802",
+        changeOrigin: false,
+        rewrite: (path) => path.replace(/^\/api/, ""),
+      },
+    },
+  },
+});

+ 2 - 2
vite.config.ts

@@ -24,10 +24,10 @@ export default defineConfig({
     // vite 反向代理
     proxy: {
       "/api": {
-        target: "http://192.168.1.120:19801",
+        target: "http://192.168.1.112:19802",
         changeOrigin: false,
         rewrite: (path) => path.replace(/^\/api/, ""),
       },
     },
   },
-});
+});

+ 33 - 0
vite.edge.config.ts

@@ -0,0 +1,33 @@
+import { defineConfig } from "vite";
+import react from "@vitejs/plugin-react";
+import path from "path";
+
+// https://vite.dev/config/
+export default defineConfig({
+  plugins: [react()],
+  css: {
+    modules: {
+      generateScopedName: "[name]__[local]___[hash:base64:5]", // 自定义类名生成规则
+    },
+  },
+  resolve: {
+    alias: {
+      "@": path.resolve(__dirname, "src"),
+    },
+    // mainFields: ['module', 'jsnext:main', 'jsnext', 'main'],
+  },
+  server: {
+    host: true,
+    port: 8080,
+    open: true,
+    cors: true,
+    // vite 反向代理
+    proxy: {
+      "/api": {
+        target: "http://192.168.1.112:19801",
+        changeOrigin: false,
+        rewrite: (path) => path.replace(/^\/api/, ""),
+      },
+    },
+  },
+});