Przeglądaj źródła

优化接口,表单脚本获取对象

cyy 1 rok temu
rodzic
commit
27d3ed312a

+ 347 - 274
src/business/platform/form/components/hyperlink/index.vue

@@ -1,270 +1,342 @@
 <template>
-  <van-field ref="input" class="field-custom-type" :label="label" :name="name" :border="border" :disabled="disabled"
-    :readonly="readonly" :required="required" :clearable="clearable" :clickable="clickable" :is-link="isLink"
-    :error="error" :error-message="errorMessage" :arrow-direction="arrowDirection" :label-class="labelClass"
-    :label-width="labelWidth" :label-align="labelAlign" :input-align="inputAlign"
-    :error-message-align="errorMessageAlign" :autosize="autosize" :left-icon="leftIcon" :right-icon="rightIcon"
-    :icon-prefix="iconPrefix" :rules="editable?rules:null">
+  <van-field
+    ref="input"
+    class="field-custom-type"
+    :label="label"
+    :name="name"
+    :border="border"
+    :disabled="disabled"
+    :readonly="readonly"
+    :required="required"
+    :clearable="clearable"
+    :clickable="clickable"
+    :is-link="isLink"
+    :error="error"
+    :error-message="errorMessage"
+    :arrow-direction="arrowDirection"
+    :label-class="labelClass"
+    :label-width="labelWidth"
+    :label-align="labelAlign"
+    :input-align="inputAlign"
+    :error-message-align="errorMessageAlign"
+    :autosize="autosize"
+    :left-icon="leftIcon"
+    :right-icon="rightIcon"
+    :icon-prefix="iconPrefix"
+    :rules="editable ? rules : null"
+  >
     <template #label>
-      {{ label }}<van-icon v-if="desc && descPosition==='lableIcon'" name="warning" class="ibps-dialog-icon"
-        @click="$action.descDialog({ title:label, message:desc })" />
+      {{ label
+      }}<van-icon
+        v-if="desc && descPosition === 'lableIcon'"
+        name="warning"
+        class="ibps-dialog-icon"
+        @click="$action.descDialog({ title: label, message: desc })"
+      />
     </template>
     <template #input>
-      <ibps-link v-if="showType === 'link'" :underline="underline" :icon="'ibps-icon'+icon" :disabled="disabled"
-        :type="type" @click="click">{{ showText }}</ibps-link>
-      <van-button v-else :text="showText" :icon="icon" :icon-prefix="iconPrefix" :disabled="disabled" :type="type"
-        size="small" @click="click" />
+      <ibps-link
+        v-if="showType === 'link'"
+        :underline="underline"
+        :icon="'ibps-icon' + icon"
+        :disabled="disabled"
+        :type="type"
+        @click="click"
+        >{{ showText }}</ibps-link
+      >
+      <van-button
+        v-else
+        :text="showText"
+        :icon="icon"
+        :icon-prefix="iconPrefix"
+        :disabled="disabled"
+        :type="type"
+        size="small"
+        @click="click"
+      />
       <!-- 弹窗模式 -->
-      <custom-dialog ref="userDialog" :visible="openDialog" :components="customComponents"
-        @close="visible => openDialog = visible" />
+      <custom-dialog
+        ref="userDialog"
+        :visible="openDialog"
+        :components="customComponents"
+        @close="visible => (openDialog = visible)"
+      />
     </template>
   </van-field>
 </template>
 <script>
-  import { getScriptValue } from '@/api/platform/form/common.js'
-  import request from '@/utils/request'
-  import FieldMixin from '@/mixins/field'
-  import IbpsLink from '@/components/ibps-link'
-  import customDialog from './dialog'
+import { getScriptValue } from '@/api/platform/form/common.js'
+import request from '@/utils/request'
+import FieldMixin from '@/mixins/field'
+import IbpsLink from '@/components/ibps-link'
+import customDialog from './dialog'
 
-  export default {
-    name: 'ibps-hyperlink',
-    components: {
-      IbpsLink,
-      customDialog
+export default {
+  name: 'ibps-hyperlink',
+  components: {
+    IbpsLink,
+    customDialog
+  },
+  mixins: [FieldMixin],
+  props: {
+    showType: {
+      // 是按钮还是文本
+      type: String,
+      default: 'link',
+      validator: function(value) {
+        return ['link', 'button'].indexOf(value) !== -1
+      }
+    },
+    text: String,
+    iconPrefix: {
+      type: String,
+      default: 'ibps-icon'
     },
-    mixins: [FieldMixin],
-    props: {
-      showType: { // 是按钮还是文本
-        type: String,
-        default: 'link',
-        validator: function (value) {
-          return ['link', 'button'].indexOf(value) !== -1
-        }
-      },
-      text: String,
-      iconPrefix: {
-        type: String,
-        default: 'ibps-icon'
-      },
 
-      previewEntrance: {
-        type: Boolean,
-        default: false
-      },
-      formData: {
-        type: Object
-      },
-      textJavascript: {
-        type: String
-      },
-      linkType: { // 打开链接的类型
-        type: String,
-        default: 'fixed',
-        validator: function (value) { // fixed 固定值; dynamic groovy脚本; javascript js 脚本
-          return ['fixed', 'dynamic', 'javascript'].indexOf(value) !== -1
-        }
-      },
-      textType: { // 文本展示的类型
-        type: String,
-        default: 'fixed',
-        validator: function (value) { // fixed 固定值; dynamic groovy脚本; javascript js 脚本
-          return ['fixed', 'dynamic', 'javascript'].indexOf(value) !== -1
-        }
-      },
-      link: {
-        type: String
-      },
-      type: {
-        type: String,
-        default: 'default'
-      },
-      underline: {
-        type: Boolean,
-        default: false
-      },
-      disabled: {
-        type: Boolean,
-        default: false
-      },
-      // href: {
-      //   type: String
-      // },
-      icon: {
-        type: String
-      },
-      isNewTab: { // 新开窗口还是弹框显示
-        type: Boolean,
-        default: true
-      },
-      beforeClick: { // 方法参数( linkData, text, cb) cb 是回调函数
-        type: Function
-      },
-      afterClick: {
-        type: Function
+    previewEntrance: {
+      type: Boolean,
+      default: false
+    },
+    formData: {
+      type: Object
+    },
+    textJavascript: {
+      type: String
+    },
+    linkType: {
+      // 打开链接的类型
+      type: String,
+      default: 'fixed',
+      validator: function(value) {
+        // fixed 固定值; dynamic groovy脚本; javascript js 脚本
+        return ['fixed', 'dynamic', 'javascript'].indexOf(value) !== -1
       }
     },
-    data() {
-      return {
-        linkData: '',
-        showText: this.text || '暂无数据',
-        openType: '',
-        openDialog: false,
-        show: true,
-        customComponents: {}
+    textType: {
+      // 文本展示的类型
+      type: String,
+      default: 'fixed',
+      validator: function(value) {
+        // fixed 固定值; dynamic groovy脚本; javascript js 脚本
+        return ['fixed', 'dynamic', 'javascript'].indexOf(value) !== -1
       }
     },
-    watch: {
-      formData(val, oldVal) {
-        // 提供脚本监听属性。
-        console.info(val)
+    link: {
+      type: String
+    },
+    type: {
+      type: String,
+      default: 'default'
+    },
+    underline: {
+      type: Boolean,
+      default: false
+    },
+    disabled: {
+      type: Boolean,
+      default: false
+    },
+    // href: {
+    //   type: String
+    // },
+    icon: {
+      type: String
+    },
+    isNewTab: {
+      // 新开窗口还是弹框显示
+      type: Boolean,
+      default: true
+    },
+    beforeClick: {
+      // 方法参数( linkData, text, cb) cb 是回调函数
+      type: Function
+    },
+    afterClick: {
+      type: Function
+    }
+  },
+  data() {
+    return {
+      linkData: '',
+      showText: this.text || '暂无数据',
+      openType: '',
+      openDialog: false,
+      show: true,
+      customComponents: {}
+    }
+  },
+  watch: {
+    formData(val, oldVal) {
+      // 提供脚本监听属性。
+      console.info(val)
+    },
+    textType: {
+      handler: function(val) {
+        if (!this.previewEntrance) return
+        // this.showText = ''
+        this.setVal(val, 'text', this.textJavascript)
       },
-      textType: {
-        handler: function (val) {
-          if (!this.previewEntrance) return
-          // this.showText = ''
-          this.setVal(val, 'text', this.textJavascript)
-        },
-        immediate: true
+      immediate: true
+    },
+    linkType: {
+      handler: function(val) {
+        if (!this.previewEntrance) return
+        this.setVal(val, 'link', this.link)
       },
-      linkType: {
-        handler: function (val) {
-          if (!this.previewEntrance) return
-          this.setVal(val, 'link', this.link)
-        },
-        immediate: true
+      immediate: true
+    }
+  },
+  methods: {
+    /**
+     * val 属性的值
+     * prop [link]
+     */
+    setVal(val, prop, script, motion) {
+      if (val === 'fixed') {
+        this.showText = this.text || ''
+      } else if (val === 'dynamic') {
+        this.runGroovy(prop, script)
+      } else if (val === 'javascript') {
+        this.runScript(prop, script, motion)
       }
     },
-    methods: {
-      /**
-       * val 属性的值
-       * prop [link]
-       */
-      setVal(val, prop, script, motion) {
-        if (val === 'fixed') {
-          this.showText = this.text || ''
-        } else if (val === 'dynamic') {
-          this.runGroovy(prop, script)
-        } else if (val === 'javascript') {
-          this.runScript(prop, script, motion)
-        }
-      },
-      runScript(prop, scrip, motion) {
-        var formData = this.formData
-        const options = {
-          formData: formData,
-          request: request,
-          router: this.$router,
-          message: this.$notify,
-          link: this,
-          // 本人
-          reportPath: this.$reportPath,
-          reportPaths: this.$reportPaths,
+    runScript(prop, scrip, motion) {
+      var formData = this.formData
+      const options = {
+        formData: formData,
+        request: request,
+        router: this.$router,
+        message: this.$notify,
+        link: this,
+        // 本人
+        reportPath: this.$reportPath,
+        reportPaths: this.$reportPaths
+      }
+      console.log(options, 'optionsoptionsoptionsoptions')
+
+      if (this.$utils.isEmpty(scrip)) return
+      const promise = new window.Promise((resolve, reject) => {
+        new Function('options', 'resolve', scrip)(options, resolve)
+      })
+      promise.then(result => {
+        // 本人
+        if (this.showType === 'link') {
+          this.iframeUrl = result[0].logic.split('url:"')[1].split('"')[0]
+          this.iframeShow = true
+          return
         }
-        if (this.$utils.isEmpty(scrip)) return
-        const promise = new window.Promise((resolve, reject) => {
-          new Function('options', 'resolve', scrip)(options, resolve)
-        })
-        promise.then(result => {
-          // 本人
-          if (this.showType === 'link') {
-            this.iframeUrl = result[0].logic.split('url:"')[1].split('"')[0]
-            this.iframeShow = true
-            return
-          }
 
-          if (this.$utils.isEmpty(result)) {
-            this.showText = '暂无数据'
-            return
-          }
-          options.result = result
-          if (prop === 'text') {
-            this.showText = result || '暂无数据'
-          } else {
-            result.formData = formData
-            this.linkData = result || ''
-            if (result.constructor === Object && result.openType && this.showType === 'link' && motion === 'click') {
-              switch (result.openType) {
-                case 'dialog':
-                  this.customComponents = result
-                  this.openDialog = true
-                  break
-                case 'url':
-                  // this.$router.push({ name: 'iframe', meta: { defaultUrl: result.url }})
-                  window.open(result.url)
-                  break
-                case 'tab':
-                  this.$router.push(result.url)
-                  break
-                default:
-                  break
-              }
-            } else if (this.showType === 'button') {
-              if (result.constructor === Array) {
-                const promise = new window.Promise((resolve, reject) => {
-                  result.forEach(item => {
-                    if (item.event === 'beforeSubmit' && motion !== 'click') {
-                      new Function('options', 'resolve', item.logic)(options, resolve)
-                    } else if (item.event === 'afterSubmit' && motion === 'click') {
-                      new Function('options', 'resolve', item.logic)(options, resolve)
-                    }
-                  })
-                })
-                promise.then(res => {
-                  this.conditionalExecution(res.constructor === Object && res.openType, res, 'openType')
-                })
-              } else {
-                // this.$notify({
-                //   message: '请按规定脚本格式填写脚本',
-                //   type: 'warning'
-                // })
-                this.$message({
-                  message: '请按规定脚本格式填写脚本',
-                  type: 'warning'
+        if (this.$utils.isEmpty(result)) {
+          this.showText = '暂无数据'
+          return
+        }
+        options.result = result
+        if (prop === 'text') {
+          this.showText = result || '暂无数据'
+        } else {
+          result.formData = formData
+          this.linkData = result || ''
+          if (
+            result.constructor === Object &&
+            result.openType &&
+            this.showType === 'link' &&
+            motion === 'click'
+          ) {
+            switch (result.openType) {
+              case 'dialog':
+                this.customComponents = result
+                this.openDialog = true
+                break
+              case 'url':
+                // this.$router.push({ name: 'iframe', meta: { defaultUrl: result.url }})
+                window.open(result.url)
+                break
+              case 'tab':
+                this.$router.push(result.url)
+                break
+              default:
+                break
+            }
+          } else if (this.showType === 'button') {
+            if (result.constructor === Array) {
+              const promise = new window.Promise((resolve, reject) => {
+                result.forEach(item => {
+                  if (item.event === 'beforeSubmit' && motion !== 'click') {
+                    new Function('options', 'resolve', item.logic)(
+                      options,
+                      resolve
+                    )
+                  } else if (
+                    item.event === 'afterSubmit' &&
+                    motion === 'click'
+                  ) {
+                    new Function('options', 'resolve', item.logic)(
+                      options,
+                      resolve
+                    )
+                  }
                 })
-              }
+              })
+              promise.then(res => {
+                this.conditionalExecution(
+                  res.constructor === Object && res.openType,
+                  res,
+                  'openType'
+                )
+              })
+            } else {
+              // this.$notify({
+              //   message: '请按规定脚本格式填写脚本',
+              //   type: 'warning'
+              // })
+              this.$message({
+                message: '请按规定脚本格式填写脚本',
+                type: 'warning'
+              })
             }
           }
-        })
-      },
-      conditionalExecution(condition, res, key) {
-        if (condition) {
-          switch (res[key]) {
-            case 'dialog':
-              this.customComponents = res
-              this.openDialog = true
-              break
-            case 'url':
-              // this.$router.push({ name: 'iframe', meta: { defaultUrl: res.url }})
-              window.open(res.url)
-              break
-            case 'tab':
-              this.$router.push(res.url)
-              break
-            default:
-              break
-          }
         }
-      },
-      // TODO: 待完善
-      runGroovy(prop, scrip) {
-        var formData = this.formData
-        const str = JSON.parse(JSON.stringify(scrip))
-        const arr = []
-        const vars = {}
-        for (var i in formData.models) {
-          if (str.indexOf(i) !== -1) {
-            arr.push(str.substring(str.indexOf(i), str.indexOf(i) + i.length))
-          }
+      })
+    },
+    conditionalExecution(condition, res, key) {
+      if (condition) {
+        switch (res[key]) {
+          case 'dialog':
+            this.customComponents = res
+            this.openDialog = true
+            break
+          case 'url':
+            // this.$router.push({ name: 'iframe', meta: { defaultUrl: res.url }})
+            window.open(res.url)
+            break
+          case 'tab':
+            this.$router.push(res.url)
+            break
+          default:
+            break
         }
-        arr.forEach(a => {
-          vars[a] = formData.models[a]
+      }
+    },
+    // TODO: 待完善
+    runGroovy(prop, scrip) {
+      var formData = this.formData
+      const str = JSON.parse(JSON.stringify(scrip))
+      const arr = []
+      const vars = {}
+      for (var i in formData.models) {
+        if (str.indexOf(i) !== -1) {
+          arr.push(str.substring(str.indexOf(i), str.indexOf(i) + i.length))
+        }
+      }
+      arr.forEach(a => {
+        vars[a] = formData.models[a]
+      })
+      if (this.$utils.isNotEmpty(scrip)) {
+        getScriptValue({
+          script: scrip,
+          vars: JSON.stringify(vars) || ''
         })
-        if (this.$utils.isNotEmpty(scrip)) {
-          getScriptValue({
-            script: scrip,
-            vars: JSON.stringify(vars) || ''
-          }).then(res => {
+          .then(res => {
             this[scrip + 'Data'] = res.content
             if (prop === 'text') {
               this.showText = res.data || '暂无数据'
@@ -279,50 +351,51 @@
               message: '动态脚本执行成功!',
               type: 'success'
             })
-          }).catch(err => {
+          })
+          .catch(err => {
             console.log(err)
           })
-        }
-      },
-      click() {
-        this.setVal(this.linkType, 'link', this.link, 'click')
       }
-      // handleClick(e) {
-      //   this.$emit('click', e)
-      // }
+    },
+    click() {
+      this.setVal(this.linkType, 'link', this.link, 'click')
     }
+    // handleClick(e) {
+    //   this.$emit('click', e)
+    // }
   }
+}
 </script>
 <style lang="scss">
-  .field-custom-type {
-    .van-button--info {
-      color: #FFF;
-      background-color: #909399;
-      border-color: #909399;
-    }
+.field-custom-type {
+  .van-button--info {
+    color: #fff;
+    background-color: #909399;
+    border-color: #909399;
+  }
 
-    .van-button--success {
-      color: #FFF;
-      background-color: #67C23A;
-      border-color: #67C23A;
-    }
+  .van-button--success {
+    color: #fff;
+    background-color: #67c23a;
+    border-color: #67c23a;
+  }
 
-    .van-button--warning {
-      color: #FFF;
-      background-color: #E6A23C;
-      border-color: #E6A23C;
-    }
+  .van-button--warning {
+    color: #fff;
+    background-color: #e6a23c;
+    border-color: #e6a23c;
+  }
 
-    .van-button--danger {
-      color: #FFF;
-      background-color: #F56C6C;
-      border-color: #F56C6C;
-    }
+  .van-button--danger {
+    color: #fff;
+    background-color: #f56c6c;
+    border-color: #f56c6c;
+  }
 
-    .van-button--primary {
-      color: #FFF;
-      background-color: #409EFF;
-      border-color: #409EFF;
-    }
+  .van-button--primary {
+    color: #fff;
+    background-color: #409eff;
+    border-color: #409eff;
   }
-</style>
+}
+</style>

+ 504 - 504
src/business/platform/form/formrender/formrender.vue

@@ -1,41 +1,41 @@
 <template>
-    <div class="van-fr ibps-fixed-toolbar">
-        <!-- fr-header  表头-->
-        <slot v-if="formDef.name" name="fr-header">
-            <div class="van-block__title van-ellipsis">
-                {{ formDef.name }}
-            </div>
-            <div v-if="formDef.desc" class="van-block__desc">
-                {{ formDef.desc }}
-            </div>
-        </slot>
-        <!-- fr-header  表单内容-->
-        <div :style="bodyStyle" class="van-fr-body">
-            <ibps-dynamic-form
-                ref="dynamicForm"
-                v-model="formData"
-                :form-def="formDefData"
-                :permissions="permissions"
-                :readonly="readonly"
-                :params="params"
-                :input-align="inputAlign"
-                :initialization="initialization"
-                :cur-active-step.sync="curActiveStep"
-                @load-script="loadScript"
-            />
-        </div>
-        <!-- fr-toolbar  表单操作按钮-->
-        <slot name="fr-toolbar">
-            <ibps-toolbar
-                v-if="hasActions"
-                ref="frToolbar"
-                :actions="actions"
-                :more-actions="moreActions"
-                icon-prefix="ibps-icon"
-            />
-        </slot>
-        <slot ref="frExt" name="fr-ext" />
+  <div class="van-fr ibps-fixed-toolbar">
+    <!-- fr-header  表头-->
+    <slot v-if="formDef.name" name="fr-header">
+      <div class="van-block__title van-ellipsis">
+        {{ formDef.name }}
+      </div>
+      <div v-if="formDef.desc" class="van-block__desc">
+        {{ formDef.desc }}
+      </div>
+    </slot>
+    <!-- fr-header  表单内容-->
+    <div :style="bodyStyle" class="van-fr-body">
+      <ibps-dynamic-form
+        ref="dynamicForm"
+        v-model="formData"
+        :form-def="formDefData"
+        :permissions="permissions"
+        :readonly="readonly"
+        :params="params"
+        :input-align="inputAlign"
+        :initialization="initialization"
+        :cur-active-step.sync="curActiveStep"
+        @load-script="loadScript"
+      />
     </div>
+    <!-- fr-toolbar  表单操作按钮-->
+    <slot name="fr-toolbar">
+      <ibps-toolbar
+        v-if="hasActions"
+        ref="frToolbar"
+        :actions="actions"
+        :more-actions="moreActions"
+        icon-prefix="ibps-icon"
+      />
+    </slot>
+    <slot ref="frExt" name="fr-ext" />
+  </div>
 </template>
 
 <script>
@@ -46,496 +46,496 @@ import IbpsToolbar from '@/components/ibps-toolbar' // 工具栏
 const JFormId = 'JForm'
 
 export default {
-    components: {
-        IbpsToolbar
-    },
-    props: {
-        formDef: {
-            type: Object,
-            required: true
-        },
-        data: {
-            type: Object
-        },
-        /**
-       * @description 工具栏
-       */
-        buttons: {
-            type: Array
-        },
-        /**
-       * 是否只读 (流程实例时候控制)
-       */
-        readonly: {
-            type: Boolean,
-            default: false
-        },
-        /**
-       *  @description 扩展参数 比如流程id等
-       *流程相关信息:
-       * taskId:任务id
-       * instId:流程实例
-       * defId:定义Id
-       * formOpinionData: 流程意见配置及已经审批的意见数据
-       */
-        params: {
-            type: Object
-        },
-        mode: {
-            // 表单模式
-            type: String
-        },
-        inputAlign: {
-            type: String
-        }
+  components: {
+    IbpsToolbar
+  },
+  props: {
+    formDef: {
+      type: Object,
+      required: true
+    },
+    data: {
+      type: Object
+    },
+    /**
+     * @description 工具栏
+     */
+    buttons: {
+      type: Array
+    },
+    /**
+     * 是否只读 (流程实例时候控制)
+     */
+    readonly: {
+      type: Boolean,
+      default: false
+    },
+    /**
+     *  @description 扩展参数 比如流程id等
+     *流程相关信息:
+     * taskId:任务id
+     * instId:流程实例
+     * defId:定义Id
+     * formOpinionData: 流程意见配置及已经审批的意见数据
+     */
+    params: {
+      type: Object
+    },
+    mode: {
+      // 表单模式
+      type: String
     },
-    data() {
-        return {
-            loading: false,
-            formData: {},
-            permissions: null,
-            initialization: false,
-            formParams: {},
-            curActiveStep: 0,
-            curTime: new Date().getTime(),
-            stepLoading: false,
+    inputAlign: {
+      type: String
+    }
+  },
+  data() {
+    return {
+      loading: false,
+      formData: {},
+      permissions: null,
+      initialization: false,
+      formParams: {},
+      curActiveStep: 0,
+      curTime: new Date().getTime(),
+      stepLoading: false,
 
-            btnNum: this.getBtnNumByWidth()
-        }
+      btnNum: this.getBtnNumByWidth()
+    }
+  },
+  computed: {
+    formDefData() {
+      return JSON.parse(JSON.stringify(this.formDef))
     },
-    computed: {
-        formDefData() {
-            return JSON.parse(JSON.stringify(this.formDef))
-        },
 
-        actions() {
-            if (this.toolbars.length > this.btnNum) {
-                return this.toolbars.slice(0, this.btnNum)
-            } else {
-                return this.toolbars
-            }
-        },
-        moreActions() {
-            if (this.toolbars.length > this.btnNum) {
-                return this.toolbars.slice(this.btnNum, this.toolbars.length)
-            } else {
-                return null
-            }
-        },
-        toolbars() {
-            return this.getActions()
-        },
-        hasActions() {
-            // this.hasStepButton ||
-            return this.actions && this.actions.length > 0
-        },
-        dynamicForm() {
-            return this.$refs ? this.$refs.dynamicForm : null
-        },
-        hasStepButton() {
-            return this.$utils.isNotEmpty(this.stepButtons) && this.mode !== 'dialog'
-        },
-        stepNum() {
-            if (this.$utils.isEmpty(this.step)) {
-                return 0
-            }
-            return this.step.field_options.columns.length
-        },
-        finishStep() {
-            return this.stepNum - 1 === this.curActiveStep
-        },
-        stepButtons() {
-            return this.getStepButtons()
-        },
-        step() {
-            return this.getFormStep()
-        },
-        bodyStyle() {
-            if (this.$isServer) {
-                return
-            }
-            // header高度82px, fr actions高度50px,如果改动了样式自己传下bodyOffsetTop调整下
-            const maxHeight = window.innerHeight - this.bodyOffsetTop
-            return {
-                maxHeight: maxHeight + 'px'
-            }
+    actions() {
+      if (this.toolbars.length > this.btnNum) {
+        return this.toolbars.slice(0, this.btnNum)
+      } else {
+        return this.toolbars
+      }
+    },
+    moreActions() {
+      if (this.toolbars.length > this.btnNum) {
+        return this.toolbars.slice(this.btnNum, this.toolbars.length)
+      } else {
+        return null
+      }
+    },
+    toolbars() {
+      return this.getActions()
+    },
+    hasActions() {
+      // this.hasStepButton ||
+      return this.actions && this.actions.length > 0
+    },
+    dynamicForm() {
+      return this.$refs ? this.$refs.dynamicForm : null
+    },
+    hasStepButton() {
+      return this.$utils.isNotEmpty(this.stepButtons) && this.mode !== 'dialog'
+    },
+    stepNum() {
+      if (this.$utils.isEmpty(this.step)) {
+        return 0
+      }
+      return this.step.field_options.columns.length
+    },
+    finishStep() {
+      return this.stepNum - 1 === this.curActiveStep
+    },
+    stepButtons() {
+      return this.getStepButtons()
+    },
+    step() {
+      return this.getFormStep()
+    },
+    bodyStyle() {
+      if (this.$isServer) {
+        return
+      }
+      // header高度82px, fr actions高度50px,如果改动了样式自己传下bodyOffsetTop调整下
+      const maxHeight = window.innerHeight - this.bodyOffsetTop
+      return {
+        maxHeight: maxHeight + 'px'
+      }
+    }
+  },
+  watch: {
+    formDef: {
+      handler: function(val, oldVal) {
+        if (val && val !== oldVal) {
+          this.initialization = false
+          this.initUI()
         }
+      },
+      immediate: true
     },
-    watch: {
-        formDef: {
-            handler: function(val, oldVal) {
-                if (val && val !== oldVal) {
-                    this.initialization = false
-                    this.initUI()
-                }
-            },
-            immediate: true
-        },
-        data: {
-            handler: function(val, oldVal) {
-                if (val && val !== oldVal) {
-                    const data = JSON.parse(JSON.stringify(val))
-                    // 表单数据
-                    this.formData = data.responses || {}
-                    // 表单权限
-                    this.permissions = data.permissions || null
-                }
-            },
-            immediate: true,
-            deep: true
-        },
-        curActiveStep() {
-            this.$emit('cur-active-step', this.curActiveStep)
+    data: {
+      handler: function(val, oldVal) {
+        if (val && val !== oldVal) {
+          const data = JSON.parse(JSON.stringify(val))
+          // 表单数据
+          this.formData = data.responses || {}
+          // 表单权限
+          this.permissions = data.permissions || null
         }
+      },
+      immediate: true,
+      deep: true
     },
-    created() {
-        this.initUI()
+    curActiveStep() {
+      this.$emit('cur-active-step', this.curActiveStep)
+    }
+  },
+  created() {
+    this.initUI()
+  },
+  destroyed() {
+    const script = document.getElementById(JFormId)
+    if (script) {
+      script.parentNode.removeChild(script)
+    }
+  },
+  methods: {
+    getBtnNumByWidth() {
+      const width = document.documentElement.clientWidth
+      if (width >= 375) return 3
+      else return 2
     },
-    destroyed() {
-        const script = document.getElementById(JFormId)
-        if (script) {
-            script.parentNode.removeChild(script)
-        }
+    initUI() {
+      if (!this.initialization) {
+        this.initJForm()
+        this.initialization = true
+        this.$nextTick(() => {
+          setTimeout(() => {
+            this.loadScript()
+          }, 10)
+        })
+      }
     },
-    methods: {
-        getBtnNumByWidth() {
-            const width = document.documentElement.clientWidth
-            if (width >= 375) return 3
-            else return 2
-        },
-        initUI() {
-            if (!this.initialization) {
-                this.initJForm()
-                this.initialization = true
-                this.$nextTick(() => {
-                    setTimeout(() => {
-                        this.loadScript()
-                    }, 10)
-                })
-            }
-        },
-        getActions() {
-            if (this.$utils.isEmpty(this.buttons)) {
-                return []
-            }
+    getActions() {
+      if (this.$utils.isEmpty(this.buttons)) {
+        return []
+      }
 
-            const actions = []
-            this.buttons.forEach((btn, i) => {
-                const key = btn.getAlias()
-                let disabled = false
-                let hidden = false
-                // if (btn.getAlias() !== 'close' && this.hasStepButton && !this.finishStep) {
-                //   disabled = true
-                // }
+      const actions = []
+      this.buttons.forEach((btn, i) => {
+        const key = btn.getAlias()
+        let disabled = false
+        let hidden = false
+        // if (btn.getAlias() !== 'close' && this.hasStepButton && !this.finishStep) {
+        //   disabled = true
+        // }
 
-                hidden = this.onLoadActions(key, btn, 'hidden', hidden)
-                disabled = this.onLoadActions(key, btn, 'disabled', disabled)
+        hidden = this.onLoadActions(key, btn, 'hidden', hidden)
+        disabled = this.onLoadActions(key, btn, 'disabled', disabled)
 
-                const button = {
-                    key: key,
-                    name: btn.getLabel(),
-                    icon: btn.getIcon(),
-                    type: btn.getStyle(),
-                    plain: btn.getPlain(),
-                    disabled: disabled,
-                    hidden: hidden,
-                    callback: () => {
-                        if (i >= this.btnNum) {
-                            this.closeMoreAction()
-                        }
-                        // 前置事件
-                        this.beforeScript(btn.getAlias(), result => {
-                            if (result) {
-                                return btn.action.apply(this, [btn])
-                            }
-                        })
-                    }
-                }
-                actions.push(button)
-            })
-            return actions
-        },
-        closeMoreAction() {
-            this.$refs.frToolbar.closeMoreAction()
-        },
-        // 自定义按钮数据事件
-        onLoadActions: function(key, button, type, defaultVal) {
-            const buttonActionResult = JForm._onLoadActions(this, key, button, type)
-            if (typeof buttonActionResult !== 'undefined' && buttonActionResult) {
-                return true
+        const button = {
+          key: key,
+          name: btn.getLabel(),
+          icon: btn.getIcon(),
+          type: btn.getStyle(),
+          plain: btn.getPlain(),
+          disabled: disabled,
+          hidden: hidden,
+          callback: () => {
+            if (i >= this.btnNum) {
+              this.closeMoreAction()
             }
-            return defaultVal
-        },
-        handleButtonEvent(button, position, data, index) {
-            const action = this.actions.find(action => {
-                return button.key === action.key
+            // 前置事件
+            this.beforeScript(btn.getAlias(), result => {
+              if (result) {
+                return btn.action.apply(this, [btn])
+              }
             })
-            if (action) {
-                action.callback()
-            }
-        },
-        handleActionEvent(actionKey, args = {}) {
-            this.$emit('action-event', actionKey, args)
-        },
-        disabledStepButton(key) {
-            if (key === 'prev') {
-                return this.curActiveStep === 0
-            } else {
-                return this.stepNum - 1 === this.curActiveStep
-            }
-        },
-        /** **Step 处理 */
-        getStepButtons() {
-            if (this.$utils.isEmpty(this.step)) {
-                return []
-            }
-            if (this.$utils.isNotEmpty(this.step.field_options.buttons)) {
-                return this.step.field_options.buttons
+          }
+        }
+        actions.push(button)
+      })
+      return actions
+    },
+    closeMoreAction() {
+      this.$refs.frToolbar.closeMoreAction()
+    },
+    // 自定义按钮数据事件
+    onLoadActions: function(key, button, type, defaultVal) {
+      const buttonActionResult = JForm._onLoadActions(this, key, button, type)
+      if (typeof buttonActionResult !== 'undefined' && buttonActionResult) {
+        return true
+      }
+      return defaultVal
+    },
+    handleButtonEvent(button, position, data, index) {
+      const action = this.actions.find(action => {
+        return button.key === action.key
+      })
+      if (action) {
+        action.callback()
+      }
+    },
+    handleActionEvent(actionKey, args = {}) {
+      this.$emit('action-event', actionKey, args)
+    },
+    disabledStepButton(key) {
+      if (key === 'prev') {
+        return this.curActiveStep === 0
+      } else {
+        return this.stepNum - 1 === this.curActiveStep
+      }
+    },
+    /** **Step 处理 */
+    getStepButtons() {
+      if (this.$utils.isEmpty(this.step)) {
+        return []
+      }
+      if (this.$utils.isNotEmpty(this.step.field_options.buttons)) {
+        return this.step.field_options.buttons
+      } else {
+        const defaultButtons = [
+          {
+            key: 'prev',
+            icon: 'angle-left',
+            label: '上一步'
+          },
+          {
+            key: 'next',
+            icon: 'angle-right',
+            label: '下一步'
+          }
+        ]
+        return defaultButtons
+      }
+    },
+    getFormStep() {
+      const step = {}
+      if (this.$utils.isEmpty(this.formDef)) {
+        return
+      }
+      for (let i = 0; i < this.formDef.fields.length; i++) {
+        const field = this.formDef.fields[i]
+        if (field.field_type === 'steps') {
+          return field
+        }
+      }
+      return step
+    },
+    handleStepButtonEvent(button) {
+      const key = button.key
+      if (key === 'next' && this.curActiveStep === this.stepNum - 1) {
+        ActionUtils.warning('没有更多')
+        return
+      }
+      if (key === 'prev' && this.curActiveStep === 0) {
+        ActionUtils.warning('没有上一步')
+        return
+      }
+      this.stepLoading = true
+      const curDate = new Date().getTime()
+      let time = 0
+      if (this.curTime + 1500 >= curDate) {
+        time = 1000
+      }
+      this.curTime = curDate
+      setTimeout(() => {
+        if (key === 'next') {
+          this.validate(valid => {
+            if (valid) {
+              this.curActiveStep++
             } else {
-                const defaultButtons = [
-                    {
-                        key: 'prev',
-                        icon: 'angle-left',
-                        label: '上一步'
-                    },
-                    {
-                        key: 'next',
-                        icon: 'angle-right',
-                        label: '下一步'
-                    }
-                ]
-                return defaultButtons
-            }
-        },
-        getFormStep() {
-            const step = {}
-            if (this.$utils.isEmpty(this.formDef)) {
-                return
-            }
-            for (let i = 0; i < this.formDef.fields.length; i++) {
-                const field = this.formDef.fields[i]
-                if (field.field_type === 'steps') {
-                    return field
-                }
-            }
-            return step
-        },
-        handleStepButtonEvent(button) {
-            const key = button.key
-            if (key === 'next' && this.curActiveStep === this.stepNum - 1) {
-                ActionUtils.warning('没有更多')
-                return
-            }
-            if (key === 'prev' && this.curActiveStep === 0) {
-                ActionUtils.warning('没有上一步')
-                return
-            }
-            this.stepLoading = true
-            const curDate = new Date().getTime()
-            let time = 0
-            if (this.curTime + 1500 >= curDate) {
-                time = 1000
-            }
-            this.curTime = curDate
-            setTimeout(() => {
-                if (key === 'next') {
-                    this.validate(valid => {
-                        if (valid) {
-                            this.curActiveStep++
-                        } else {
-                            this.formErrorToast()
-                        }
-                    })
-                } else {
-                    this.curActiveStep--
-                }
-                this.stepLoading = false
-            }, time)
-        },
-        callback() {
-            this.$emit('callback')
-        },
-        closeDialog() {
-            this.$emit('close')
-        },
-        getForm() {
-            return this.$refs.dynamicForm
-        },
-        getFormValidator() {
-            return this.getForm().getFormValidator()
-        },
-        /**
-       * 获取表单验证
-       */
-        validate(callback) {
-            this.getFormValidator()
-                .then(() => {
-                    callback(true)
-                })
-                .catch(e => {
-                    if (e && e[0]) {
-                        this.getForm().scrollToField(e[0].name)
-                    }
-                    callback(false, e)
-                })
-        },
-        formErrorToast(e) {
-            this.$notify({
-                type: 'warning',
-                message: this.$t('common.formError')
-            })
-        },
-        // 处理表单提交验证
-        formSubmitVerify(callback) {
-            if (!this.hasScript()) {
-                if (callback) {
-                    this.getForm().formSubmitVerify(callback)
-                }
-                return
+              this.formErrorToast()
             }
+          })
+        } else {
+          this.curActiveStep--
+        }
+        this.stepLoading = false
+      }, time)
+    },
+    callback() {
+      this.$emit('callback')
+    },
+    closeDialog() {
+      this.$emit('close')
+    },
+    getForm() {
+      return this.$refs.dynamicForm ? this.$refs.dynamicForm : this.dynamicForm
+    },
+    getFormValidator() {
+      return this.getForm().getFormValidator()
+    },
+    /**
+     * 获取表单验证
+     */
+    validate(callback) {
+      this.getFormValidator()
+        .then(() => {
+          callback(true)
+        })
+        .catch(e => {
+          if (e && e[0]) {
+            this.getForm().scrollToField(e[0].name)
+          }
+          callback(false, e)
+        })
+    },
+    formErrorToast(e) {
+      this.$notify({
+        type: 'warning',
+        message: this.$t('common.formError')
+      })
+    },
+    // 处理表单提交验证
+    formSubmitVerify(callback) {
+      if (!this.hasScript()) {
+        if (callback) {
+          this.getForm().formSubmitVerify(callback)
+        }
+        return
+      }
 
-            JForm._onValidate(this, (result, errorMsg) => {
-                if (!result) {
-                    return callback(result, errorMsg || '验证不通过,请检查表单')
-                }
-                this.getForm().formSubmitVerify(callback)
-            })
-        },
+      JForm._onValidate(this, (result, errorMsg) => {
+        if (!result) {
+          return callback(result, errorMsg || '验证不通过,请检查表单')
+        }
+        this.getForm().formSubmitVerify(callback)
+      })
+    },
 
-        /**
-       * 获取表单数据
-       */
-        getFormData() {
-            return this.getForm().getFormData()
-        },
-        /**
-       * 获取字段数据
-       */
-        getData(name) {
-            const data = this.getFormData()
-            return data[name]
-        },
-        /**
-       * 设置字段数据
-       */
-        setData(name, value) {
-            return this.getForm().setFieldData(name, value)
-        },
-        /**
-       * 设置表单权限
-       */
-        getFormRights(name) {
-            return this.getForm().getFormRights(name)
-        },
-        /**
-       * 设置表单权限
-       */
-        setFormRights(name, value) {
-            return this.getForm().setFormRights(name, value)
-        },
-        hasFormOpinion() {
-            return this.getForm().hasFormOpinion()
-        },
-        /**
-       * 表单意见数据
-       */
-        getFormOpinionData() {
-            return this.getForm().getFormOpinionData()
-        },
-        /**
-       * 获取审批意见验证
-       */
-        formOpinionValidate(calback, flag) {
-            this.getForm().formOpinionValidate(calback, flag)
-        },
+    /**
+     * 获取表单数据
+     */
+    getFormData() {
+      return this.getForm().getFormData()
+    },
+    /**
+     * 获取字段数据
+     */
+    getData(name) {
+      const data = this.getFormData()
+      return data[name]
+    },
+    /**
+     * 设置字段数据
+     */
+    setData(name, value) {
+      return this.getForm().setFieldData(name, value)
+    },
+    /**
+     * 设置表单权限
+     */
+    getFormRights(name) {
+      return this.getForm().getFormRights(name)
+    },
+    /**
+     * 设置表单权限
+     */
+    setFormRights(name, value) {
+      return this.getForm().setFormRights(name, value)
+    },
+    hasFormOpinion() {
+      return this.getForm().hasFormOpinion()
+    },
+    /**
+     * 表单意见数据
+     */
+    getFormOpinionData() {
+      return this.getForm().getFormOpinionData()
+    },
+    /**
+     * 获取审批意见验证
+     */
+    formOpinionValidate(calback, flag) {
+      this.getForm().formOpinionValidate(calback, flag)
+    },
 
-        /**
-           * 获取表单字段组件实例
-           */
-        getRefs(fieldName) {
-            return this.getForm().getRefs(fieldName)
-        },
-        /**
-       * 获取表单字段的具体控件组件实例
-       */
-        getRefsField(fieldName) {
-            return this.getForm().getRefsField(fieldName)
-        },
-        /* 给与表头赋值关联对话框及数据*/
-        getTableList(list) {
-            return this.getForm().getTableList(list)
-        },
-        /* 获取统计页面或记录页面*/
-        getStatisOrRecord(type) {
-            return this.getForm().getStatisOrRecord(type)
-        },
-        /* 表头点击事件*/
-        clickTableHeand(a) {
-            return this.getForm().clickTableHeand(a)
-        },
+    /**
+     * 获取表单字段组件实例
+     */
+    getRefs(fieldName) {
+      return this.getForm().getRefs(fieldName)
+    },
+    /**
+     * 获取表单字段的具体控件组件实例
+     */
+    getRefsField(fieldName) {
+      return this.getForm().getRefsField(fieldName)
+    },
+    /* 给与表头赋值关联对话框及数据*/
+    getTableList(list) {
+      return this.getForm().getTableList(list)
+    },
+    /* 获取统计页面或记录页面*/
+    getStatisOrRecord(type) {
+      return this.getForm().getStatisOrRecord(type)
+    },
+    /* 表头点击事件*/
+    clickTableHeand(a) {
+      return this.getForm().clickTableHeand(a)
+    },
 
-        /**
-       * 初始化脚本
-       */
-        initJForm() {
-            let script = document.getElementById(JFormId)
-            if (script) {
-                script.parentNode.removeChild(script)
-            }
-            if (
-                this.formDef.attrs &&
-          (this.formDef.attrs.mobile_script || this.formDef.attrs.script)
-            ) {
-                const codeScript =
-            this.formDef.attrs.mobile_script || this.formDef.attrs.script
-                script = document.createElement('script')
-                script.type = 'text/javascript'
-                script.id = JFormId
-                document.body.appendChild(script)
-                try {
-                    script.appendChild(document.createTextNode(codeScript))
-                } catch (ex) {
-                    console.error(ex)
-                    script.text = codeScript
-                }
-                document.body.appendChild(script)
-            }
-        },
-        // 处理脚本
-        hasScript() {
-            return this.getForm().hasScript
-        },
-        // 加载脚本
-        loadScript() {
-            this.$emit('load', this)
-            if (!this.hasScript()) {
-                return
-            }
-            JForm._onLoad(this, this.getForm)
-        },
-        // 前置脚本
-        beforeScript(action, callback) {
-            if (!this.hasScript()) {
-                if (callback) {
-                    const flag = true
-                    callback(flag)
-                }
-                return
-            }
-            JForm._beforeSubmit(this, action, this.getFormData(), callback)
-        },
-        // 后置脚本
-        afterScript(action, params, callback) {
-            this.formParams = params
-            if (!this.hasScript()) {
-                if (callback) {
-                    const flag = true
-                    callback(flag)
-                }
-                return
-            }
-            JForm._afterSubmit(this, action, this.getFormData(), callback)
+    /**
+     * 初始化脚本
+     */
+    initJForm() {
+      let script = document.getElementById(JFormId)
+      if (script) {
+        script.parentNode.removeChild(script)
+      }
+      if (
+        this.formDef.attrs &&
+        (this.formDef.attrs.mobile_script || this.formDef.attrs.script)
+      ) {
+        const codeScript =
+          this.formDef.attrs.mobile_script || this.formDef.attrs.script
+        script = document.createElement('script')
+        script.type = 'text/javascript'
+        script.id = JFormId
+        document.body.appendChild(script)
+        try {
+          script.appendChild(document.createTextNode(codeScript))
+        } catch (ex) {
+          console.error(ex)
+          script.text = codeScript
+        }
+        document.body.appendChild(script)
+      }
+    },
+    // 处理脚本
+    hasScript() {
+      return this.getForm().hasScript
+    },
+    // 加载脚本
+    loadScript() {
+      this.$emit('load', this)
+      if (!this.hasScript()) {
+        return
+      }
+      JForm._onLoad(this, this.getForm)
+    },
+    // 前置脚本
+    beforeScript(action, callback) {
+      if (!this.hasScript()) {
+        if (callback) {
+          const flag = true
+          callback(flag)
+        }
+        return
+      }
+      JForm._beforeSubmit(this, action, this.getFormData(), callback)
+    },
+    // 后置脚本
+    afterScript(action, params, callback) {
+      this.formParams = params
+      if (!this.hasScript()) {
+        if (callback) {
+          const flag = true
+          callback(flag)
         }
+        return
+      }
+      JForm._afterSubmit(this, action, this.getFormData(), callback)
     }
+  }
 }
 </script>

+ 50 - 46
src/utils/remote.js

@@ -89,68 +89,72 @@ const cacheTransTime = new Map()
  * @param id 参数配置
  * @returns {Promise<any>|Promise<T | never>}
  */
-export function remoteTransRequest(prefix, id) {
+ export function remoteTransRequest (prefix, id) {
   const curTime = new Date().getTime()
-
+  const timeOut = 200
   let time = cacheTransTime.get(prefix)
   if (time == null) {
-    cacheTransTime.set(prefix, curTime)
-    time = curTime
+      cacheTransTime.set(prefix, curTime)
+      time = curTime
   }
-  if (curTime - 2000 >= time) { // 2秒内的请求都重新请求
-    // 清除缓存换个请求
-    cacheTransTime.clear()
-    cacheTransTime.set(prefix, curTime)
-    time = curTime
+  if (curTime - timeOut >= time) { // 2秒内的请求都重新请求
+      // 清除缓存换个请求
+      cacheTransTime.clear()
+      cacheTransTime.set(prefix, curTime)
+      time = curTime
   }
+
   const key = prefix + '#' + time
   // 汇总接口
   let item = cacheTrans.get(key)
 
   let idVal = id
   if (Object.prototype.toString.call(id) === '[object Object]') {
-    idVal = JSON.stringify(id)
+      idVal = JSON.stringify(id)
   }
 
-  if (item == null || item.error === true) {
-    // 还没加载过
-    if (item == null) {
-      item = { loading: true, ids: new Set(), callbacks: [] }
-      cacheTrans.set(key, item)
-    }
-    item.loading = true
-    item.ids = item.ids.add(idVal)
-
-    const remoteFunc = (ids) => {
-      return new Promise((resolve) => {
-        resolve(ids)
-      })
-    }
-
-    return remoteFunc(item.ids).then((ids) => {
-      item.ids = ids
-      // 之前注册过的callback全部触发
-      for (const callback of item.callbacks) {
-        callback(ids)
+  // 20230814调整缓存判断机制,若缓存中的值与当前id不匹配,则不走缓存
+  if (item == null || item.error === true || (item.loading === false && !item.ids.has(idVal))) {
+      // 还没加载过
+      if (item == null) {
+          item = { loading: true, ids: new Set(), callbacks: [] }
+          cacheTrans.set(key, item)
+      }
+      item.loading = true
+      item.ids = item.ids.add(idVal)
+
+      const remoteFunc = (ids) => {
+          return new Promise((resolve) => {
+              setTimeout(() => {
+                  resolve(ids)
+              }, 100)
+          })
       }
-      item.loading = false
-      item.callbacks = []
 
-      return ids
-    })
+      return remoteFunc(item.ids).then((ids) => {
+          item.ids = ids
+          // 之前注册过的callback全部触发
+          for (const callback of item.callbacks) {
+              callback(ids)
+          }
+          item.loading = false
+          item.callbacks = []
+
+          return ids
+      })
   } else if (item.loading === true) {
-    // 正在加载中,注册callback,等加载完了之后,再统一触发,就只需要向服务器请求一次数据模版
-    return new Promise((resolve) => {
-      const callback = (ids) => {
-        item.ids = ids.add(idVal)
-        resolve(item.ids)
-      }
-      item.callbacks.push(callback)
-    })
+      // 正在加载中,注册callback,等加载完了之后,再统一触发,就只需要向服务器请求一次数据模版
+      return new Promise((resolve) => {
+          const callback = (ids) => {
+              item.ids = ids.add(idVal)
+              resolve(item.ids)
+          }
+          item.callbacks.push(callback)
+      })
   } else {
-    //  从缓存拿
-    return new Promise((resolve) => {
-      resolve(item.ids)
-    })
+      //  从缓存拿
+      return new Promise((resolve) => {
+          resolve(item.ids)
+      })
   }
 }