浏览代码

fix: 修复bug

huangziyang 2 天之前
父节点
当前提交
45bb83d67a

+ 8 - 8
form/index.html

@@ -1,9 +1,9 @@
 <!DOCTYPE html><html lang=""><head>
     <meta charset="UTF-8">
-    <link rel="icon" href="/saas/form/favicon.ico">
+    <link rel="icon" href="/form/favicon.ico">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>Vite App</title>
-    <script crossorigin="">import('/saas/form/static/index.IlBjmAfx.js').finally(() => {
+    <script crossorigin="">import('/form/static/index.B1AbEp1S.js').finally(() => {
             
     const qiankunLifeCycle = window.moudleQiankunAppLifeCycles && window.moudleQiankunAppLifeCycles['curstom-form'];
     if (qiankunLifeCycle) {
@@ -14,12 +14,12 @@
     }
   
           })</script>
-    <link rel="modulepreload" crossorigin="" href="/saas/form/static/.pnpm.CRLYFuod.js">
-    <link rel="modulepreload" crossorigin="" href="/saas/form/static/lodash-es.C-xrcuFl.js">
-    <link rel="modulepreload" crossorigin="" href="/saas/form/static/element-plus.Dozcb0Co.js">
-    <link rel="modulepreload" crossorigin="" href="/saas/form/static/@form-create/designer.BQ8hZRqe.js">
-    <link rel="stylesheet" crossorigin="" href="/saas/form/static/element-plus.D92rDM1h.css">
-    <link rel="stylesheet" crossorigin="" href="/saas/form/static/index.nPkbAqeq.css">
+    <link rel="modulepreload" crossorigin="" href="/form/static/.pnpm.CRLYFuod.js">
+    <link rel="modulepreload" crossorigin="" href="/form/static/lodash-es.C-xrcuFl.js">
+    <link rel="modulepreload" crossorigin="" href="/form/static/element-plus.Dozcb0Co.js">
+    <link rel="modulepreload" crossorigin="" href="/form/static/@form-create/designer.BQ8hZRqe.js">
+    <link rel="stylesheet" crossorigin="" href="/form/static/element-plus.D92rDM1h.css">
+    <link rel="stylesheet" crossorigin="" href="/form/static/index.nPkbAqeq.css">
   </head>
   <body>
     <div id="app"></div>

+ 7 - 3
src/App.vue

@@ -15,7 +15,6 @@ import { MenuOptions } from './plugins/menu/options.ts'
 import type { FcDesignerInstance } from '@form-create/designer' // 注册组件
 import type { Options, Rule } from '@form-create/element-ui'
 import type { Option } from './components/rc-options/createOptions.ts'
-import formCreate from '@form-create/element-ui'
 
 /**
  * @see https://view.form-create.com/methods
@@ -60,14 +59,17 @@ const onSave = async (config: { options: string; rule: string }) => {
   })
 }
 
+const onDelete = (rule: Rule) => {
+  if (rule.type !== 'rc-image') return
+  designer.value.form.rule[1].value = ''
+}
+
 onMounted(async () => {
   // 注册拖拽规则
   designer.value?.addMenu(MenuOptions)
   designer.value?.addComponent(RcSelect)
   designer.value?.addComponent(RcRadio)
   designer.value?.addComponent(RcCheckbox)
-  console.log(designer.value)
-
   const des = designer.value
   window.__QIANKUN__EVENT__.on('formCoverChange', (cover: string) => {
     const newRule = des?.getRule() as Rule[]
@@ -82,6 +84,7 @@ onMounted(async () => {
     } else {
       newRule.unshift({
         type: 'rc-image',
+        field: new Date().getTime().toString(),
         props: {
           cover,
         },
@@ -112,6 +115,7 @@ onMounted(async () => {
     :handle="handle"
     :config="config"
     v-model:api="api"
+    @delete="onDelete"
     @save="onSave"
   />
 </template>

+ 3 - 1
src/components/rc-checkbox/rc-checkbox.vue

@@ -8,6 +8,8 @@ const props = defineProps<{
     field: string
   }
   defaultValue: string
+  // eslint-disable-next-line @typescript-eslint/no-explicit-any
+  options: any[]
 }>()
 
 const checkList = ref<string[]>([])
@@ -19,7 +21,7 @@ onMounted(() => {
 })
 </script>
 <template>
-  <RcCreateOption :formCreateInject="formCreateInject" v-slot="{ options }">
+  <RcCreateOption :formCreateInject="formCreateInject">
     <el-checkbox-group v-model="checkList" v-bind="$attrs">
       <el-checkbox
         v-for="item in options"

+ 8 - 0
src/components/rc-image/rc-image.vue

@@ -1,7 +1,15 @@
 <script setup lang="ts" name="rc-image">
+import type { FormCreateProps } from '@form-create/element-ui'
+import { onUnmounted } from 'vue'
+
 defineProps<{
+  formCreateInject: FormCreateProps
   cover: string
 }>()
+
+onUnmounted(() => {
+  window.__QIANKUN__EVENT__.emit('unMountd')
+})
 </script>
 <template>
   <div>

+ 1 - 0
src/components/rc-options/create-option.vue

@@ -23,6 +23,7 @@ window.__QIANKUN__EVENT__?.on(props.formCreateInject.field, (tags: Option[]) =>
         value: item.label,
       }
     })
+
   options.value = tags
 })
 

+ 8 - 2
src/components/rc-radio/rc-radio.vue

@@ -1,17 +1,23 @@
+<!-- eslint-disable @typescript-eslint/no-explicit-any -->
 <script lang="ts" name="rc-radio" setup>
 import type { FormCreateProps } from '@form-create/element-ui'
 import RcCreateOption from '../rc-options/create-option.vue'
-import { onMounted, ref } from 'vue'
+import { onMounted, ref, watchEffect } from 'vue'
 
 const props = defineProps<{
   formCreateInject: FormCreateProps & {
     field: string
   }
   defaultValue: string
+  options: any[]
 }>()
 
 const radioValue = ref('')
 
+watchEffect(() => {
+  console.log(props.options)
+})
+
 onMounted(() => {
   if (props.defaultValue) {
     radioValue.value = props.defaultValue
@@ -19,7 +25,7 @@ onMounted(() => {
 })
 </script>
 <template>
-  <RcCreateOption :formCreateInject="formCreateInject" v-slot="{ options }">
+  <RcCreateOption :formCreateInject="formCreateInject">
     <el-radio-group v-model="radioValue" v-bind="$attrs">
       <el-radio v-for="item in options" size="large" :key="item.key" :value="item.label">{{
         item.label

+ 1 - 0
src/components/rc-select/rc-select.vue

@@ -1,3 +1,4 @@
+<!-- eslint-disable @typescript-eslint/no-explicit-any -->
 <script lang="ts" name="rc-select" setup>
 import type { FormCreateProps } from '@form-create/element-ui'
 import RcCreateOption from '../rc-options/create-option.vue'

+ 86 - 27
src/form.config.ts

@@ -86,57 +86,115 @@ export const formConfig: Config = {
   // showPropsForm: false, // 隐藏组件的属性配置
   switchType: false, // 是否可以切换类型
   showEventForm: false, // 隐藏组件的事件配置
+  showBaseForm: false, // 隐藏组件的基础配置
   showCustomProps: false, //是否显示自定义props按钮
   // 自定义右侧菜单
   componentRule: {
     default: {
       prepend: true,
-      rule(rule) {
+      rule(rule: any) {
         return [
           {
             type: 'input',
-            field: 'defaultValue',
-            label: '提示词',
-            title: '提示词',
+            field: 'title',
+            label: '标题',
+            title: '标题',
             on: {
               change: (val: string) => {
-                rule.value = val
+                rule.title = val
+              },
+            },
+          },
+          {
+            type: 'input',
+            field: 'placeholder',
+            label: '提示文本',
+            title: '提示文本',
+            on: {
+              change: (val: string) => {
+                rule.placeholder = val
+              },
+            },
+          },
+          {
+            type: 'switch',
+            field: 'require',
+            label: '是否必填',
+            title: '是否必填',
+            on: {
+              change(val: any) {
+                console.log(val)
+                rule.$required = !!val
               },
             },
           },
         ]
       },
     },
-    input: (rule) => {
+    input(rule) {
       return [
         {
-          type: 'rc-switch',
-          field: 'synchronize_field',
-          label: '高级功能',
-          title: '高级功能',
-          props: {
-            rule,
+          type: 'inputNumber',
+          field: 'maxlength',
+          label: '最大输入长度',
+          title: '最大输入长度',
+          on: {
+            change: (val: string) => {
+              console.log(rule)
+              rule!.props!.maxlength = val
+            },
           },
         },
       ]
     },
-
-    textarea: {
-      append: true,
-      rule(rule) {
-        return [
-          {
-            type: 'rc-switch',
-            field: 'synchronize_field',
-            label: '高级功能',
-            title: '高级功能',
-            props: {
-              rule,
+    textarea(rule) {
+      return [
+        {
+          type: 'inputNumber',
+          field: 'maxlength',
+          label: '最大输入长度',
+          title: '最大输入长度',
+          on: {
+            change: (val: string) => {
+              console.log(rule)
+              rule!.props!.maxlength = val
             },
           },
-        ]
-      },
+        },
+      ]
     },
+    // input: {
+    //   append: true,
+    //   rule(rule) {
+    //     return [
+    //       {
+    //         type: 'rc-switch',
+    //         field: 'synchronize_field',
+    //         label: '高级功能',
+    //         title: '高级功能',
+    //         props: {
+    //           rule,
+    //         },
+    //       },
+    //     ]
+    //   },
+    // },
+    // textarea: {
+    //   append: true,
+    //   rule(rule) {
+    //     return [
+    //       {
+    //         type: 'rc-switch',
+    //         field: 'synchronize_field',
+    //         label: '高级功能',
+    //         title: '高级功能',
+    //         props: {
+    //           rule,
+    //         },
+    //       },
+    //     ]
+    //   },
+    // },
   },
   // 自定义表单事件
   formRule() {
@@ -190,7 +248,7 @@ const formatOptions = (result: any) => {
         const formContentValue = {
           field_name: item.title, // 字段名称
           field_type: item.type.startsWith('rc-') ? item.type.substring(3) : item.type, // rc- 前缀
-          default_text: item.value || '', // 默认文本
+          default_text: item.placeholder || '', // 默认文本
           is_required: item.$required ? 1 : 0, // 是否必填
           field_options: item.options?.map((op: any) => ({
             count: 0,
@@ -199,6 +257,7 @@ const formatOptions = (result: any) => {
           })),
           synchronize_field: item.synchronize_field,
           submit_count: 0,
+          click_count: 0,
         }
 
         if (item.props?.type === 'textarea') {

+ 0 - 1
src/plugins/components/rc-checkbox.config.ts

@@ -17,7 +17,6 @@ export const RcCheckbox: DragRule = {
       title: '多选框',
       props: {
         clearable: true,
-        value: [1],
       },
     }
   },

+ 0 - 1
src/plugins/components/rc-radio.config.ts

@@ -17,7 +17,6 @@ export const RcRadio: DragRule = {
       title: '单选框',
       props: {
         clearable: true,
-        value: '1',
       },
     }
   },

+ 2 - 1
vite.config.ts

@@ -10,7 +10,8 @@ export default defineConfig(({ mode }) => {
   const chunkName = ['lodash-es', 'element-plus', '@form-create/designer']
 
   // 根据环境变量设置 base
-  const base = mode === 'test' ? '/saas/form/' : '/'
+  const base = mode === 'test' ? '/saas/form/' : '/form'
+  console.log('base:', base)
   return {
     plugins: [
       vue(),