Răsfoiți Sursa

暴露自定义XHR接口以通过验证

kagg886 2 luni în urmă
părinte
comite
a9c0c1f2ed

+ 13 - 3
src/components/form-create-designer/config/rule/upload.js

@@ -1,7 +1,7 @@
-import uniqueId from '@form-create/utils/lib/unique';
-import {getInjectArg, localeOptions, localeProps} from '../../utils';
+import uniqueId from '@form-create/utils/lib/unique'
+import { getInjectArg, getOptionArg, localeOptions, localeProps } from '../../utils'
 
-const label = '上传';
+const label = '上传'
 const name = 'upload';
 
 export default {
@@ -61,6 +61,16 @@ export default {
                 name: 'beforeRemove',
             }
         }, {
+					type: 'FnInput',
+					field: 'httpRequest',
+					props: {
+						body: true,
+						button: true,
+						fnx: true,
+						args: [getOptionArg(t)],
+						name: 'httpRequest',
+					}
+				}, {
             type: 'FnInput',
             field: 'onSuccess',
             warning: t('com.upload.info'),

+ 14 - 1
src/components/form-create-designer/locale/zh-cn.js

@@ -118,7 +118,19 @@ const ZhCn = {
             self: '组件的生成规则',
             option: '表单的配置',
             args: '事件的原始参数',
-        }
+        },
+				option: {
+					action: '请求链接',
+					method: '请求方式',
+					data: '请求数据',
+					filename: '文件名',
+					file: '文件',
+					headers: '请求头',
+					onError: '错误回调',
+					onProgress: '进度回调',
+					onSuccess: '成功回调',
+					withCredentials: '是否携带凭证',
+				}
     },
     eventInfo: {
         blur: '失去焦点时触发',
@@ -851,6 +863,7 @@ const ZhCn = {
                 beforeUpload: '上传文件之前触发',
                 onSuccess: '上传成功时触发',
                 beforeRemove: '删除文件之前触发',
+								httpRequest: '自定义XHR拦截器',
                 headers: '设置上传的请求头部',
                 data: '上传时附带的额外参数',
                 name: '上传的文件字段名',

+ 27 - 8
src/components/form-create-designer/utils/index.js

@@ -1,11 +1,11 @@
-import is, {hasProperty} from '@form-create/utils/lib/type';
-import {parseFn} from '@form-create/utils/lib/json';
-import toCase from '@form-create/utils/lib/tocase';
-import {computed, isRef, ref, unref} from 'vue';
-import ZhCn from '../locale/zh-cn';
-import {message} from './message';
+import is, { hasProperty } from '@form-create/utils/lib/type'
+import { parseFn } from '@form-create/utils/lib/json'
+import toCase from '@form-create/utils/lib/tocase'
+import { computed, isRef, ref, unref } from 'vue'
+import ZhCn from '../locale/zh-cn'
+import { message } from './message'
 
-export {formTemplate, formTemplateV3, htmlTemplate} from './template';
+export { formTemplate, formTemplateV3, htmlTemplate } from './template'
 
 
 export function makeRequiredRule() {
@@ -352,6 +352,25 @@ export function getInjectArg(t) {
     }
 }
 
+export function getOptionArg(t) {
+	return {
+		name: '$inject',
+
+		columns: [
+			{label: 'action', info: t('event.option.action'), type: 'string'},
+			{label: 'method', info: t('event.option.method'), type: 'string'},
+			{label: 'data', info: t('event.option.data'), type: 'Record<string, string | Blob | [Blob, string]>'},
+			{label: 'filename', info: t('event.option.filename'), type: 'string'},
+			{label: 'file', info: t('event.option.file'), type: 'UploadRawFile'},
+			{label: 'headers', info: t('event.option.headers'), type: 'Headers | Record<string, string | number | null | undefined>'},
+			{label: 'onError', info: t('event.option.onError'), type: 'function'},
+			{label: 'onProgress', info: t('event.option.onProgress'), type: 'function'},
+			{label: 'onSuccess', info: t('event.option.onSuccess'), type: 'function'},
+			{label: 'withCredentials', info: t('event.option.withCredentials'), type: 'boolean'},
+		]
+	}
+}
+
 export function isElementInside(x, y, element) {
     const rect = element.getBoundingClientRect();
     return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
@@ -409,4 +428,4 @@ export function copyTextToClipboard(text) {
 
 export function uniqueArray(arr) {
     return arr.filter((item, index) => arr.indexOf(item) === index);
-}
+}