瀏覽代碼

优化页面编辑

xiaochan 1 年之前
父節點
當前提交
10dffeeb63

+ 1 - 1
src/components/xiao-chan/combo-grid/XcComboGridV2.vue

@@ -50,7 +50,7 @@ const props = defineProps({
   },
   keyName: {
     type: Array,
-    default: ['code', 'name', 'pyCode', 'wCode', 'dCode']
+    default: ['code', 'name', 'pyCode', 'wCode', 'dCode', 'value', 'label']
   },
   width: {
     type: String,

+ 6 - 3
src/views/data-base/page-editor-help-v2/components/left-sidebar/PageTree.vue

@@ -189,7 +189,7 @@ function queryData() {
 }
 
 function handleInputChange(val) {
-  treeRef.value.filter(val)
+  treeRef.value!.filter(val)
 }
 
 function handelFilter(value, data) {
@@ -198,13 +198,17 @@ function handelFilter(value, data) {
 
 function rowClick(row) {
   getPermissionsByUserCode(row.code).then(res => {
-    treeRef.value.setCheckedKeys(res)
+    treeRef.value!.setCheckedKeys(res)
   })
 }
 
 
 onMounted(() => {
   queryData()
+
+  pageHelpV2Mitt.on('queryTree', () => {
+    queryData()
+  })
 })
 </script>
 
@@ -226,7 +230,6 @@ onMounted(() => {
       <div :style="{height : height - headerHeight - 10 + 'px'  , width: width - 5 + 'px' }" style="overflow: auto">
         <el-tree :data="treeData"
                  ref="treeRef"
-                 :show-checkbox="props.editor"
                  :filter-node-method="handelFilter"
                  @node-click="nodeClick"
                  @node-contextmenu="contextmenu"

+ 2 - 3
src/views/data-base/page-editor-help-v2/components/page-editor-v2/PageEditorV2.vue

@@ -9,7 +9,6 @@ const props = defineProps<{
   currentData: ReportForms
 }>()
 
-const headerRef = ref(null)
 const componentAttributeRef = ref(null)
 const pageHelpRef = ref(null)
 const tabsValue = ref('属性配置')
@@ -23,8 +22,8 @@ pageHelpV2Mitt.on('componentReady', (data) => {
 
 pageHelpV2Mitt.on('doTestResult', (data, id, url) => {
   if (props.currentData.id === id) {
-    pageHelpRef.value.setTableData(data)
-    pageHelpRef.value.setUrl(url)
+    pageHelpRef.value!.setTableData(data)
+    pageHelpRef.value!.setUrl(url)
   }
 })
 

+ 36 - 22
src/views/data-base/page-editor-help-v2/components/page-editor-v2/PageHelpV2.vue

@@ -53,7 +53,7 @@ const {currentClickIndex, pageData, clearOnAndFunc, tableBind, handleSavaData} =
 
 const formRef = useCompRef(ElForm)
 const bindRef = ref(null)
-const headerRef = ref(null)
+const headerRef = ref<HTMLDivElement>()
 const {height: headerHeight} = useElementSize(headerRef)
 const emits = defineEmits(['changeTabs'])
 const userInfo = XEUtils.clone(userInfoStore.value, true)
@@ -70,15 +70,13 @@ const render = (item: PageHeader) => {
   if (item.on) {
     for (const onKey in item.on) {
       const key = capitalizeFirstLetter(onKey, 'on')
-      const func = new Function('pageJson', 'currentBind', 'apiFunc', 'val', 'userInfo', item.on[onKey])
-      tempProps[key] = (...val) => func(pageData.value, item, reportQueryCenterApi, val, userInfo)
+      tempProps[key] = (...val) => newFunc(item, val, item.on[onKey])
     }
   }
 
   if (item.func) {
     for (let funcKey in item.func) {
-      const func = new Function('pageJson', 'currentBind', 'apiFunc', 'val', 'userInfo', item.func[funcKey])
-      tempProps[funcKey] = (...val) => func(pageData.value, item, reportQueryCenterApi, val, userInfo)
+      tempProps[funcKey] = (...val) => newFunc(item, val, item.func[funcKey])
     }
   }
 
@@ -139,7 +137,7 @@ async function queryClick() {
   const tempData = {
     ...pageData.value.params
   }
-  await formRef.value.validate()
+  await formRef.value!.validate()
   loading.value = true
   await reportQueryCenterApi(pageData.value.submitUrl, tempData)
       .then(res => {
@@ -175,7 +173,7 @@ const columns = ref([])
 const loading = ref(false)
 
 function requiredInit(setDefaultValue = false) {
-  formRef.value.resetFields()
+  formRef.value!.resetFields()
   rules.value = []
   pageData.value.header.forEach(item => {
     if (setDefaultValue) {
@@ -187,27 +185,27 @@ function requiredInit(setDefaultValue = false) {
   })
 }
 
-function handleOnAndFuncEvent(data: PageJsonObject) {
-  XEUtils.arrayEach(data.header, (item: PageHeader) => {
-    if (item.on) {
-      for (let onKey in item.on) {
-        const func = new Function('pageJson', 'currentBind', 'apiFunc', 'val', 'userInfo', item.on[onKey])
-        if (onKey === 'mounted') {
-          func(data, item, reportQueryCenterApi, '', userInfo)
-        }
+async function handleOnAndFuncEvent(data: PageJsonObject) {
+  for (let i = 0; i < data.header.length; i++) {
+    const item = data.header[i]
+    if (item.on && item.on.mounted) {
+      try {
+        await newFunc(item, '', item.on.mounted)
+      } catch (e) {
+        console.error("执行初始化函数错误", e)
       }
     }
-  })
+  }
 }
 
 async function refresh() {
   clearOnAndFunc();
-  setPageData(pageData.value, currentClickIndex.value)
+  await setPageData(pageData.value, currentClickIndex.value)
 }
 
-function setPageData(data: PageJsonObject, currentIndex = -1) {
+async function setPageData(data: PageJsonObject, currentIndex = -1) {
   const temp = XEUtils.clone(data, true);
-  handleOnAndFuncEvent(temp)
+  await handleOnAndFuncEvent(temp)
   pageData.value = temp
   if (currentIndex > 0) {
     bindRef.value?.changeCurrentBind(pageData.value.header[currentClickIndex.value])
@@ -230,9 +228,25 @@ function getBindDefaultValue(name: string) {
   return res
 }
 
-function addComponent(data) {
+function newFunc(currentBind, value, funcStr) {
+  const func = new Function('pageJson', 'currentBind', 'apiFunc', 'val', 'userInfo', funcStr)
+  try {
+    return func(pageData.value, currentBind, reportQueryCenterApi, value, userInfo)
+  } catch (e) {
+    console.error('脚本错误', e)
+  }
+}
+
+async function addComponent(data) {
   const temp = XEUtils.clone(data, true)
   Object.assign(temp.bind, getBindDefaultValue(data.name))
+  if (temp.on && temp.on.mounted) {
+    try {
+      await newFunc(temp, '', temp.on.mounted)
+    } catch (e) {
+      console.error("执行初始化函数错误", e)
+    }
+  }
   pageData.value.header.push(temp)
 }
 
@@ -252,7 +266,7 @@ async function addComponentRefresh() {
 }
 
 async function testClick() {
-  await formRef.value.validate()
+  await formRef.value!.validate()
   const data = {}
   pageData.value.header.forEach(item => {
     data[item.key] = pageData.value.params[item.key]
@@ -317,7 +331,7 @@ function setTableData(res) {
 function exportExcel(data: {
   data: any[],
   columns: Columns[],
-  fileName: string
+  fileName?: string
 }) {
   if (data.data.length === 0) {
     xcMessage.warning("没有可以导出的数据。")

+ 4 - 1
src/views/data-base/page-editor-help-v2/page-help-v2.ts

@@ -33,6 +33,8 @@ export interface PageHelpV2Mitt {
     doTestResult: (data: any, id: string, url: string) => void;
     getCurrentPageData: () => any
 
+    queryTree: () => void
+
     [key: string]: (...args: any[]) => any;
 }
 
@@ -50,7 +52,7 @@ export interface ComponentBind {
 
 export const pageHelpV2Mitt = new Mitt<PageHelpV2Mitt>();
 
-export function capitalizeFirstLetter(str, prefix: string = '') {
+export function capitalizeFirstLetter(str: string, prefix: string = '') {
     return prefix + str.charAt(0).toUpperCase() + str.slice(1);
 }
 
@@ -101,6 +103,7 @@ export function usePageStore() {
         const data = pageHelpV2Mitt.emit('getCurrentPageData')
         data.pageJson = JSON.stringify(clone)
         saveTheFile(data).then(r => {
+            pageHelpV2Mitt.emit('queryTree')
         })
     }