wenhongquan 1 yıl önce
ebeveyn
işleme
96c1be5e31

+ 1 - 0
ruoyi-ui-vue3/package.json

@@ -20,6 +20,7 @@
     "@vueup/vue-quill": "1.2.0",
     "@vueuse/core": "9.5.0",
     "axios": "0.27.2",
+    "copy-to-clipboard": "^3.3.3",
     "echarts": "5.4.0",
     "element-plus": "2.2.27",
     "file-saver": "2.0.5",

+ 119 - 0
ruoyi-ui-vue3/src/components/AMISRenderer/index.vue

@@ -0,0 +1,119 @@
+<template>
+  <div :id="formid" ref="boxRef" style="height:100%"></div>
+</template>
+<script setup lang="ts">
+import {defineProps,watch,ref} from "vue"
+import {ElMessage} from 'element-plus'
+// import 'amis/sdk/sdk.js'
+//
+//
+// import 'amis/lib/themes/default.css'
+// import 'amis/sdk/color-picker.js'
+// import 'amis/sdk/rest.js'
+
+
+import axios from 'axios'
+import copy from 'copy-to-clipboard'
+import {getUuid} from "@/utils/ruoyi";
+
+const app = getCurrentInstance()
+const eventbus = app.appContext.config.globalProperties.$baseEventBus
+
+const keydata = ref("")
+const props = defineProps({
+  formid: {
+    type: String,
+    default: () => {
+      return "a_"+getUuid().replaceAll("-","M")
+    }
+  },
+  cell: {type:Object,default: null},
+  formjson: {
+    type: Object,
+    default: () => {
+      return {}
+    }
+  }
+})
+
+const datajson  =ref({});
+watch(props.formjson,()=>{
+  datajson.value = props.formjson;
+  if(document.getElementById(props.formid)!=undefined){
+    onRendering(datajson.value)
+  }
+},{immediate: true,deep: true})
+watchEffect(()=>{
+  if(document.getElementById(props.formid)!=undefined){
+    onRendering(datajson.value)
+  }
+})
+
+try{
+  const getNodeData = inject('getNode');
+  const currentNode = getNodeData();
+  // 监听当前节点数据发生了变化
+  if(currentNode.data!=null) {
+    datajson.value = currentNode.data;
+  }
+
+}catch (e){}
+
+
+if(datajson.value!=null && Object.keys(datajson.value).indexOf("pid")!=-1){
+  datajson.value = JSON.parse(JSON.stringify(datajson.value).replaceAll("$uuid",datajson.value["pid"]));
+  eventbus.on(`update:cell_${datajson.value["pid"]}`,(msg)=>{
+    let dd = datajson.value["data"];
+    for (const msgKey in JSON.parse(msg)) {
+      dd[msgKey] = JSON.parse(msg)[msgKey];
+    }
+    datajson.value["data"] = dd;
+    if(document.getElementById(props.formid)!=undefined){
+      onRendering(datajson.value)
+    }
+
+  })
+}
+
+
+
+
+
+// @ts-ignore
+const amis = amisRequire('amis/embed');
+const boxRef = ref(null)
+
+onMounted(() => {
+  if(document.getElementById(props.formid)!=undefined) {
+    onRendering(datajson.value)
+  }
+})
+
+const onRendering = (data:any)=>{
+  let theme = 'cxd'
+  let amisScoped = amis.embed(
+    `#${props.formid}`,
+    data,
+    {
+      updateLocation: (to, replace) => {},
+    },
+    {
+      copy: content => {
+        copy(content);
+        ElMessage.success('内容已复制到粘贴板');
+      },
+      alert:(msg)=>{
+        ElMessage.success(msg);
+      },
+      notify: (type, msg) => {
+        try{
+          eventbus.emit(type,msg)
+        }catch (e){}
+      },
+      theme
+    }
+  )
+}
+</script>
+
+

+ 38 - 0
ruoyi-ui-vue3/src/utils/ruoyi.js

@@ -246,3 +246,41 @@ export function getNormalPath(p) {
 export function blobValidate(data) {
   return data.type !== 'application/json'
 }
+
+export const getUuid = () => {
+  if (typeof crypto === "object") {
+    if (typeof crypto.randomUUID === "function") {
+      return crypto.randomUUID();
+    }
+    if (
+      typeof crypto.getRandomValues === "function" &&
+      typeof Uint8Array === "function"
+    ) {
+      const callback = (c) => {
+        const num = Number(c);
+        return (
+          num ^
+          (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (num / 4)))
+        ).toString(16);
+      };
+      return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, callback);
+    }
+  }
+  let timestamp = new Date().getTime();
+  let perforNow =
+    (typeof performance !== "undefined" &&
+      performance.now &&
+      performance.now() * 1000) ||
+    0;
+  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
+    let random = Math.random() * 16;
+    if (timestamp > 0) {
+      random = (timestamp + random) % 16 | 0;
+      timestamp = Math.floor(timestamp / 16);
+    } else {
+      random = (perforNow + random) % 16 | 0;
+      perforNow = Math.floor(perforNow / 16);
+    }
+    return (c === "x" ? random : (random & 0x3) | 0x8).toString(16);
+  });
+};

+ 0 - 1
ruoyi-ui-vue3/src/utils/websocket.ts

@@ -23,7 +23,6 @@ function creatWebSocket(wsUrl: string) {
   try {
     initWebSocket(wsUrl); // 初始化websocket连接
   } catch (e) {
-    debugger
     console.log("尝试创建连接失败");
     reConnect(wsUrl); // 如果无法连接上 webSocket 那么重新连接!可能会因为服务器重新部署,或者短暂断网等导致无法创建连接
   }

+ 12 - 5
ruoyi-ui-vue3/src/views/device/sensordash/index.vue

@@ -247,7 +247,7 @@
           </el-table-column>
           <el-table-column label="数值" prop="name">
              <template #default="scope">
-                 <span>{{showdata(useWSStore().getMessage()[currentsensor.id][scope.row.name].value,scope.row.unitType)
+                 <span>{{showdata(scope.row.name,scope.row.unitType)
 
                        }}</span>
              </template>
@@ -343,11 +343,18 @@ const router = useRouter();
 const ziduanshow = ref(false);
 
 
-const showdata = (value, un) => {
-  if (un == "~") {
-    return moment(value*1000).format("yyyy-MM-DD HH:mm:ss");
+const showdata = (name, un) => {
+
+  let value = "-";
+  try {
+    value = useWSStore().getMessage()[currentsensor.value.id][name].value
+    if (un == "~") {
+      return moment(value*1000).format("yyyy-MM-DD HH:mm:ss");
+    }
+    value = value ? parseFloat(value)+"" : '-';
+  }catch(e) {
   }
-  return value ? parseFloat(value) : '-';
+  return value;
 }
 
 const tableref = ref(null);