xiaochan 1 gadu atpakaļ
vecāks
revīzija
a2c3512295

+ 1 - 1
src/components/cy/combo-grid/src/CyComboGrid.vue

@@ -7,7 +7,6 @@ import XEUtils, {isArray} from "xe-utils";
 import {ElTag} from "element-plus";
 import CyComboGridProps from "@/components/cy/combo-grid/src/CyComboGridProps";
 
-
 const props = defineProps({...CyComboGridProps})
 
 const emits = defineEmits<{
@@ -252,6 +251,7 @@ defineExpose({
                        :columnConfig="{ resizable: true}"
                        :row-config="{ height: rowHeight, isCurrent: true,isHover:true, useKey: true,keyField: 'value' }"
                        :scroll-y="{enabled: true}"
+                       :loading="props.loading"
             >
               <slot v-if="$slots.default"/>
               <vxe-column

+ 4 - 0
src/components/cy/combo-grid/src/CyComboGridProps.ts

@@ -120,6 +120,10 @@ const CyComboGridProps = {
     showTableHeader: {
         type: Boolean,
         default: true
+    },
+    loading: {
+        type: Boolean,
+        default: false
     }
 }
 

+ 9 - 3
src/components/cy/cy-monaco-editor/CyMonacoEditor.tsx

@@ -199,8 +199,15 @@ export function cyCodeEditorDialog(props: CodeProps, dialogProps?: IsCyDialog) {
     })
 }
 
-export function CyJsonEditorDialog<T extends object>(json: T | string, width: number | string = '60%', height?: number | string)
+export function CyJsonEditorDialog<T extends object>(json: T | string,
+                                                     dialogProps: IsCyDialog)
     : Promise<{ jsonStr: string, json: T }> {
+
+    const defaultProps = {
+        bodyWidth: '60%',
+        ...dialogProps
+    }
+
     const cyJsonEditorRef = ref()
 
     function confirmClick(next: (data: any) => void) {
@@ -210,8 +217,7 @@ export function CyJsonEditorDialog<T extends object>(json: T | string, width: nu
 
     const dialog = (
         <CyDialog title='json编辑'
-                  bodyHeight={height}
-                  bodyWidth={width}
+                  {...defaultProps}
                   confirmClick={confirmClick}
         >
             {{

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

@@ -4,7 +4,9 @@
       :ref="setMainTableRef"
       border
       :export-config="{}"
-      :height="height"
+      height="auto"
+      auto-resize
+      sync-resize
       :column-config="{resizable: true}"
       style="{width: 100%}"
       :row-config="{height: 48 , isCurrent: true,isHover:true, useKey: true} "
@@ -37,7 +39,6 @@ import XEUtils from "xe-utils";
 
 const props = defineProps({
   data: Array,
-  height: Number,
   columns: Array,
   handleTableColumnDefault: {
     type: Function

+ 6 - 2
src/views/data-base/page-editor-help-v2/components/page-editor-v2/PageFormBind.vue

@@ -184,6 +184,9 @@ function render(key: string, item: ComponentBind) {
   }
 }
 
+const AsyncFunction = Object.getPrototypeOf(async function () {
+}).constructor;
+
 function handleClickEdit(key: string, value: any, name: 'on' | 'func') {
   const {currentClickIndex, pageData} = props.store
   currentItem.value = pageData.value.header[currentClickIndex.value]
@@ -205,10 +208,11 @@ function handleClickEdit(key: string, value: any, name: 'on' | 'func') {
           }
           const tempData = XEUtils.clone(data, true)
           try {
-            const func = new Function('pageJson', 'currentBind', 'apiFunc', 'val', 'userInfo', code)
+            const func = new AsyncFunction('pageJson', 'currentBind', 'apiFunc', 'val', 'userInfo', code)
             func(tempData.pageJson, tempData.currentBind, reportQueryCenterApi, value, tempData.userInfo)
           } catch (e) {
-            xcMessage.error('执行失败,请检查代码', e)
+            console.error(e)
+            xcMessage.error('执行失败,请检查代码')
             return false
           }
           return true

+ 8 - 3
src/views/data-base/page-editor-help-v2/components/page-editor-v2/PageHelpOtherConfigurations.vue

@@ -3,6 +3,7 @@ import {copyStrFunc} from "@/utils/public";
 import {PageStore} from "@/views/data-base/page-editor-help-v2/page-help-v2";
 import XEUtils from "xe-utils";
 import {CyJsonEditorDialog} from "@/components/cy/cy-monaco-editor/CyMonacoEditor";
+import {ElButton} from "element-plus";
 
 const props = defineProps<{
   store: PageStore
@@ -36,14 +37,17 @@ function defaultValue() {
   } else {
     temp = props.store.pageData.value.paramsDefaultValue
   }
-  CyJsonEditorDialog(temp, '60%').then(res => {
+  CyJsonEditorDialog(temp, {bodyWidth: '60%'}).then(res => {
     props.store.pageData.value.paramsDefaultValue = res.json
-  }).catch(() => {
-
   })
 }
 
 
+function editorPageJson() {
+  CyJsonEditorDialog(props.store.pageData.value, {fullScreen: true}).then(res => {
+    props.store.mutation.setPageData(res.json)
+  })
+}
 </script>
 
 <template>
@@ -54,6 +58,7 @@ function defaultValue() {
   <el-button @click="generateTableColumns">生成表格列</el-button>
   <el-button @click="saveData">保存</el-button>
   <el-button @click="defaultValue">默认值</el-button>
+  <el-button @click="editorPageJson">编辑页面JSON对象</el-button>
 </template>
 
 <style scoped lang="scss">

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

@@ -7,12 +7,9 @@ import {ElButton, ElForm, ElOption} from "element-plus";
 import PageFormBind from "@/views/data-base/page-editor-help-v2/components/page-editor-v2/PageFormBind.vue";
 import {ArrowLeft, ArrowRight, DeleteFilled} from "@element-plus/icons-vue";
 import {reportQueryCenterApi} from "@/api/base-data/report-center";
-import CyAutoSize from "@/components/cy/auto-size/cy-auto-size.vue";
-import {useElementSize} from "@vueuse/core/index";
 import XEUtils from "xe-utils";
 import {xcMessage} from "@/utils/xiaochan-element-plus";
 import PageAddComponent from "@/views/data-base/page-editor-help-v2/components/page-editor-v2/PageAddComponent.vue";
-import {getWindowSize} from "@/utils/window-size";
 import {userInfoStore} from "@/utils/store-public";
 import {capitalizeFirstLetter, usePageStore, ElAndXc} from "@/views/data-base/page-editor-help-v2/page-help-v2";
 import {shortcutTrigger, xcEvent} from "@/utils/xckeydown";
@@ -39,6 +36,7 @@ const props = defineProps({
     default: null,
   },
   doTest: {
+    type: Function,
     default: null
   },
   isEditor: {
@@ -56,17 +54,17 @@ const {
   clearOnAndFunc,
   tableBind,
   handleSavaData,
-  bindData
+  bindData,
+  mutation
 } = store
 
 const formRef = useCompRef(ElForm)
 const headerRef = ref<HTMLDivElement>()
-const {height: headerHeight} = useElementSize(headerRef)
 const emits = defineEmits(['changeTabs'])
 const userInfo = XEUtils.clone(userInfoStore.value, true)
 
 const render = (item: PageHeader) => {
-  const modelValue = typeof pageData.value.params[item.key] === 'undefined' ? "" : pageData.value.params[item.key]
+  const modelValue = typeof pageData.value.params[item.key] === 'undefined' ? "" : pageData.value.params[item.key];
   const tempProps = {
     modelValue: modelValue,
     "onUpdate:modelValue": (val) => {
@@ -180,18 +178,10 @@ const tableData = ref([])
 const columns = ref([])
 const loading = ref(false)
 
-function requiredInit(setDefaultValue = false) {
+function requiredInit() {
   formRef.value!.resetFields()
   rules.value = []
-  const isEmpty = typeof pageData.value.paramsDefaultValue !== 'undefined' && !XEUtils.isEmpty(pageData.value.paramsDefaultValue)
   pageData.value.header.forEach(item => {
-    if (setDefaultValue) {
-      if (isEmpty) {
-        pageData.value.params = XEUtils.clone(pageData.value.paramsDefaultValue, true)
-      } else {
-        pageData.value.params[item.key] = item.defaultValue
-      }
-    }
     if (item.required) {
       rules.value[item.key] = [{required: true, message: '必填', trigger: 'blur'}]
     }
@@ -218,8 +208,14 @@ async function refresh() {
 
 async function setPageData(data: PageJsonObject, currentIndex = -1) {
   const temp: PageJsonObject = XEUtils.clone(data, true);
+  queryKey.value = {}
+  temp.header.forEach((item, index) => {
+    queryKey.value[item.key] = index
+  })
+  if (!XEUtils.isEmpty(temp.paramsDefaultValue)) {
+    temp.params = XEUtils.clone(temp.paramsDefaultValue, true)
+  }
   await handleOnAndFuncEvent(temp)
-
   pageData.value = temp
   if (currentIndex > 0) {
     await store.changeCurrentBind(pageData.value.header[currentClickIndex.value])
@@ -228,9 +224,11 @@ async function setPageData(data: PageJsonObject, currentIndex = -1) {
   }
   currentClickIndex.value = currentIndex
   initTable()
-  requiredInit(true)
+  requiredInit()
 }
 
+mutation.setPageData = setPageData
+
 function getBindDefaultValue(name: string) {
   const res = {}
   if (XEUtils.has(bindData.value, name)) {
@@ -242,10 +240,19 @@ function getBindDefaultValue(name: string) {
   return res
 }
 
+const AsyncFunction = Object.getPrototypeOf(async function () {
+}).constructor;
+
+const queryKey = ref({})
+
 function newFunc(currentBind, value, funcStr) {
-  const func = new Function('pageJson', 'currentBind', 'apiFunc', 'val', 'userInfo', funcStr)
+  function updateView() {
+    queryKey.value[currentBind.key] += pageData.value.header.length + queryKey.value[currentBind.key]
+  }
+
+  const func = new AsyncFunction('pageJson', 'currentBind', 'apiFunc', 'updateView', 'val', 'userInfo', funcStr)
   try {
-    return func(pageData.value, currentBind, reportQueryCenterApi, value, userInfo)
+    return func(pageData.value, currentBind, reportQueryCenterApi, updateView, value, userInfo)
   } catch (e) {
     console.error('脚本错误', e)
   }
@@ -254,6 +261,7 @@ function newFunc(currentBind, value, funcStr) {
 async function addComponent(data) {
   const temp = XEUtils.clone(data, true)
   Object.assign(temp.bind, getBindDefaultValue(data.name))
+  queryKey.value[temp.key] = pageData.value.header.length
   if (temp.on && temp.on.mounted) {
     try {
       await newFunc(temp, '', temp.on.mounted)
@@ -270,7 +278,7 @@ async function testClick() {
   pageData.value.header.forEach(item => {
     data[item.key] = pageData.value.params[item.key]
   })
-  props.doTest(data)
+  props?.doTest(data)
 }
 
 function openDialogAndSetData(data, title: string = '详情') {
@@ -376,7 +384,7 @@ defineExpose({
 </script>
 
 <template>
-  <CyFlex content-size>
+  <CyFlex>
     <template #header>
       <div class="cy-page_help_v2-header" ref="headerRef">
         <el-form v-bind="pageData.fromConfig"
@@ -385,6 +393,7 @@ defineExpose({
                  :model="pageData.params">
           <div v-for="(item, index) in pageData.header"
                v-if="pageData.header.length > 0"
+               :key="queryKey[item.key]"
                class="page-item_div"
                :class="isActive(index) ? 'page-item_active': ''">
             <div v-if="currentClickIndex === index" class="tool">
@@ -424,16 +433,15 @@ defineExpose({
         </el-form>
       </div>
     </template>
-    <template #content="{height, width}">
+    <template>
       <div class="cy-page_help_v2-main"
-           :style="{width: width +'px'}"
+           style="width: 100%"
            v-loading="loading">
         <PageHelpTable :data="tableBind.data"
                        :store="store"
                        tableRefName="mainTableRef"
                        :columns="tableBind.columns"
                        :handle-table-column-default="handleTableColumnDefault"
-                       :height="height == 0 ? 500 : height "
         />
       </div>
     </template>
@@ -443,18 +451,15 @@ defineExpose({
              :title="dialogTitle"
              width="90%"
              class="page_help-dialog">
-    <cy-auto-size>
-      <template #default="{width}">
-        <PageHelpTable
-            :store="store"
-            table-ref-name="dialogTableRef"
-            :data="dialogTableData.data"
-            :columns="dialogTableData.columns"
-            :handle-table-column-default="handleTableColumnDefault"
-            :height="getWindowSize.h - 500 "
-        />
-      </template>
-    </cy-auto-size>
+    <template>
+      <PageHelpTable
+          :store="store"
+          table-ref-name="dialogTableRef"
+          :data="dialogTableData.data"
+          :columns="dialogTableData.columns"
+          :handle-table-column-default="handleTableColumnDefault"
+      />
+    </template>
     <template #footer>
       <el-button v-if="props.isEditor" @click="dialogTableColumns">生成表格列</el-button>
       <el-button @click="exportExcel(dialogTableData ,store.dialogTableRef)" type="primary">导出Excel</el-button>

+ 20 - 2
src/views/data-base/page-editor-help-v2/page-help-v2.ts

@@ -12,6 +12,8 @@ import {copyStrFunc} from "@/utils/public";
 import SystemDeptSelect from "@/components/system/dept-select/SystemDeptSelect.vue";
 // @ts-ignore
 import SystemStaffSelect from '@/components/system/staff-select/SystemStaffSelect.vue'
+import {BizException, ExceptionEnum} from "@/utils/BizException";
+import {xcMessage} from "@/utils/xiaochan-element-plus";
 
 interface TableData {
     data: any[],
@@ -108,7 +110,17 @@ export function usePageStore(props: any) {
     }
 
     function handleSavaData() {
-        const clone = XEUtils.clone(pageData.value, true)
+        const clone: PageJsonObject = XEUtils.clone(pageData.value, true)
+        if (XEUtils.isEmpty(clone.paramsDefaultValue)) {
+            xcMessage.error('没有设置默认值。')
+            return
+        }
+
+        if (Object.keys(clone.paramsDefaultValue).length !== Object.keys(clone.params).length) {
+            xcMessage.error('有新增的组件没有创建默认值。')
+            return
+        }
+
         clone.params = {}
         clone.header.forEach(item => {
             if (item.name === 'ElSelectV2') {
@@ -165,6 +177,11 @@ export function usePageStore(props: any) {
         compData.value = await reportQueryCenterApi('/reportCenterOption/components/addComponents')
     }
 
+    const mutation = {
+        setPageData: (data: PageJsonObject, currentIndex = -1) => {
+        }
+    }
+
     return {
         currentClickIndex,
         pageData,
@@ -179,7 +196,8 @@ export function usePageStore(props: any) {
         getColumns,
         dialogTableRef,
         compData,
-        addComponentRefresh
+        addComponentRefresh,
+        mutation
     }
 }