Ver Fonte

fix:复制指标生成SQL到剪切板

WanRuixiang há 6 meses atrás
pai
commit
c421df6440

+ 2 - 1
package-lock.json

@@ -31,6 +31,7 @@
         "rc-resize-observer": "^1.4.0",
         "rc-tween-one": "^3.0.6",
         "react": "^18.3.1",
+        "react-copy-to-clipboard": "^5.1.0",
         "react-dom": "^18.3.1",
         "react-i18next": "^14.1.2",
         "react-monaco-editor": "^0.55.0",
@@ -10909,7 +10910,7 @@
     },
     "node_modules/react-copy-to-clipboard": {
       "version": "5.1.0",
-      "resolved": "https://registry.npmjs.org/react-copy-to-clipboard/-/react-copy-to-clipboard-5.1.0.tgz",
+      "resolved": "https://registry.npmmirror.com/react-copy-to-clipboard/-/react-copy-to-clipboard-5.1.0.tgz",
       "integrity": "sha512-k61RsNgAayIJNoy9yDsYzDe/yAZAzEbEgcz3DZMhF686LEyukcE1hzurxe85JandPUG+yTfGVFzuEw3xt8WP/A==",
       "license": "MIT",
       "dependencies": {

+ 1 - 0
package.json

@@ -33,6 +33,7 @@
     "rc-resize-observer": "^1.4.0",
     "rc-tween-one": "^3.0.6",
     "react": "^18.3.1",
+    "react-copy-to-clipboard": "^5.1.0",
     "react-dom": "^18.3.1",
     "react-i18next": "^14.1.2",
     "react-monaco-editor": "^0.55.0",

+ 14 - 3
src/app/pages/IndexDefine/components/IndexDetail.jsx

@@ -8,6 +8,7 @@ import {PureTableCard} from "../../../components/PureTableCard";
 import {FilterPanel} from "../../../components/FilterPanel";
 import {WorkFlowPanel} from "../../../components/WorkFlow";
 import {useAppDispatch} from "../../../../redux/configureStore";
+import {CopyToClipboard} from 'react-copy-to-clipboard';
 import {
   getMetricLineage,
   getMetricSQL,
@@ -81,6 +82,7 @@ export const IndexDetail = memo(({
   const invokeRangeRef = useRef({});
   const [openLog,setOpenLog] = useState(false);
   const logRef = useRef(null);
+  const cacheSQL = useRef(null);
   const vokeConfig = persistence?.defaultConfig && JSON.parse(persistence?.defaultConfig);
   const rangePresets = [
     {
@@ -243,6 +245,8 @@ export const IndexDetail = memo(({
           setVersion(data)
         }
       }))
+
+      handleMetricSQL()
     }
     return () => {
       clear()
@@ -374,8 +378,8 @@ export const IndexDetail = memo(({
 
   /** 获取指标的SQL字符串*/
   const handleMetricSQL = async ()=>{
-    const {data} = await dispatch(getMetricSQL(values?.id))
-    console.log(data)
+    const {payload} = await dispatch(getMetricSQL(values?.id));
+    cacheSQL.current = payload;
   }
 
   /** 调度记录模块 */
@@ -386,7 +390,14 @@ export const IndexDetail = memo(({
         <RangePicker presets={rangePresets} onChange={onRangeChange} />
         <Button type="primary" style={{marginLeft:15}} onClick={()=>onQueryTask()}>{t("button.query")}</Button>
         {admin && <Button style={{marginLeft: 15}} onClick={onInvokeTask}>{t("button.invoke")}</Button>}
-        {admin && <Button style={{marginLeft: 15}} onClick={handleMetricSQL}>复制SQL</Button>}
+        {admin &&
+          <CopyToClipboard
+            text={cacheSQL.current}
+            onCopy={()=>{message.success('已复制到剪切板')}}
+          >
+            <Button style={{marginLeft: 15}}>复制SQL</Button>
+          </CopyToClipboard>
+        }
       </div>
       <Table
         columns={columns}

+ 1 - 1
src/app/pages/IndexDefine/index.jsx

@@ -42,7 +42,7 @@ import useI18NPrefix from "../../hooks/useI18NPrefix";
 // TODO
 //  1.指标SQL创建AS中文,
 //  2.创建指标退出时SQL字段配置重置,
-//  5.批量设置、复制指标生成SQL到剪切板、指标应用权限
+//  5.批量设置、指标应用权限
 //  8.派生指标自动带入来自指标的维度
 export const IndexDefine = () => {
   const t = useI18NPrefix('global');