@xclqmc/base-form 1.0.3 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xclqmc/base-form",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "声明式表单组件 BaseForm(弹窗/抽屉/内嵌三态)及配套基础组件(BasePopup/BaseDrawer/BaseRadio/BaseSelect/BaseEditor)—— 纯源码分发的 Vue3 + ElementPlus 表单组件库",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"dev": "vite",
|
|
23
|
-
"build": "vite build"
|
|
23
|
+
"build": "vite build",
|
|
24
|
+
"release": "npm version patch --no-git-tag-version && npm publish --access public && curl -X PUT https://registry-direct.npmmirror.com/@xclqmc/base-form/sync"
|
|
24
25
|
},
|
|
25
26
|
"peerDependencies": {
|
|
26
27
|
"@element-plus/icons-vue": ">=2.0.0",
|
|
@@ -204,6 +204,12 @@ provide("baseFormDict", (code: string) =>
|
|
|
204
204
|
mergedOptions.value?.api?.dict?.(code),
|
|
205
205
|
);
|
|
206
206
|
|
|
207
|
+
// 向字段控件提供文件上传函数:editor 插入图片/视频时自行调用拿到文件 URL,
|
|
208
|
+
// 读取实时 api.upload(宿主可换接口);单独使用控件(无 BaseForm)时未注入,无法上传
|
|
209
|
+
provide("baseFormUpload", (file: File) =>
|
|
210
|
+
mergedOptions.value?.api?.upload?.(file),
|
|
211
|
+
);
|
|
212
|
+
|
|
207
213
|
//================================================================================================计算函数
|
|
208
214
|
// 显示形态(统一三态,只认 config.mode):dialog=弹窗 / drawer=抽屉 / form=原始表单(内嵌)
|
|
209
215
|
const cptMode = computed<"dialog" | "drawer" | "form">(() => {
|
|
@@ -143,7 +143,7 @@ export interface BaseFormRule {
|
|
|
143
143
|
[key: string]: any;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
/** 表单接口配置(get=详情 / add=新增 / put=修改,按 CRUD 自然顺序;dict
|
|
146
|
+
/** 表单接口配置(get=详情 / add=新增 / put=修改,按 CRUD 自然顺序;dict=字典 / upload=文件上传) */
|
|
147
147
|
export interface BaseFormApi {
|
|
148
148
|
/** 详情接口:可返回 axios 响应({ data })或直接返回数据本体 */
|
|
149
149
|
get?: ((id: any) => Promise<any>) | null;
|
|
@@ -153,6 +153,8 @@ export interface BaseFormApi {
|
|
|
153
153
|
put?: ((data: any) => Promise<any>) | null;
|
|
154
154
|
/** 字典接口:radio / select 的 format 为字符串(字典 code)时,字段控件经 BaseForm 注入按 code 拉取选项列表 */
|
|
155
155
|
dict?: ((code: string) => Promise<any[]>) | null;
|
|
156
|
+
/** 文件上传接口(editor 富文本图片/视频上传用):入参为原始 File,返回上传后的文件访问 URL,BaseEditor 经 BaseForm 注入后调用 */
|
|
157
|
+
upload?: ((file: File) => Promise<string>) | null;
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
/** 弹窗/表单全局配置(属性按使用频率/重要程度排列:主键/标签宽 → 形态/尺寸 → 标题/高度 → 布局 → 抽屉方向) */
|
|
@@ -248,6 +250,7 @@ export const defaultFormOptions: BaseFormOptions = {
|
|
|
248
250
|
add: null,
|
|
249
251
|
put: null,
|
|
250
252
|
dict: null,
|
|
253
|
+
upload: null,
|
|
251
254
|
},
|
|
252
255
|
fields: [
|
|
253
256
|
{
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
import "@wangeditor/editor/dist/css/style.css";
|
|
27
27
|
import {
|
|
28
28
|
reactive,
|
|
29
|
+
inject,
|
|
29
30
|
shallowRef,
|
|
30
31
|
watch,
|
|
31
32
|
onMounted,
|
|
@@ -71,21 +72,6 @@ const props = defineProps({
|
|
|
71
72
|
type: String,
|
|
72
73
|
default: "",
|
|
73
74
|
},
|
|
74
|
-
// 上传地址
|
|
75
|
-
uploadFileUrl: {
|
|
76
|
-
type: String,
|
|
77
|
-
default: "",
|
|
78
|
-
},
|
|
79
|
-
// 上传请求头(如鉴权 token 由宿主注入:{ Authorization: 'Bearer xxx' })
|
|
80
|
-
headers: {
|
|
81
|
-
type: Object,
|
|
82
|
-
default: () => ({}),
|
|
83
|
-
},
|
|
84
|
-
// 上传接口前缀(默认取宿主环境变量 VITE_API_URL,未配置时走同域相对路径)
|
|
85
|
-
baseURL: {
|
|
86
|
-
type: String,
|
|
87
|
-
default: "/",
|
|
88
|
-
},
|
|
89
75
|
});
|
|
90
76
|
|
|
91
77
|
// 定义子组件向父组件传值/事件(change=内容变化,值为 HTML;click=容器点击,入参为原生事件对象)
|
|
@@ -100,25 +86,37 @@ const editorRef = shallowRef<IDomEditor | null>(null);
|
|
|
100
86
|
const wrapRef = ref<HTMLElement | null>(null);
|
|
101
87
|
// 尺寸监听器
|
|
102
88
|
let resizeObserver: ResizeObserver | null = null;
|
|
103
|
-
//
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
89
|
+
// 文件上传函数(由 BaseForm provide,读取 api.upload;单独使用控件且无 BaseForm 时为 null,无法上传)
|
|
90
|
+
const uploadFn = inject<((file: File) => Promise<string>) | null>(
|
|
91
|
+
"baseFormUpload",
|
|
92
|
+
null,
|
|
93
|
+
);
|
|
94
|
+
// 执行上传:调用注入的 api.upload 拿到文件访问 URL 后插入编辑器;未注入 / 失败仅打日志
|
|
95
|
+
const handleUpload = async (file: File, insertFn: (url: string) => void) => {
|
|
96
|
+
if (!uploadFn)
|
|
97
|
+
return console.error("未注入上传接口(api.upload),无法上传文件");
|
|
98
|
+
try {
|
|
99
|
+
const url = await uploadFn(file);
|
|
100
|
+
if (url) insertFn(url);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error("文件上传失败:", err);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
// 编辑器配置:上传走 customUpload(宿主注入的 api.upload),由宿主自行处理请求头/鉴权/返回结构
|
|
116
106
|
const state = reactive({
|
|
117
107
|
editorConfig: {
|
|
118
108
|
placeholder: props.placeholder,
|
|
119
109
|
MENU_CONF: {
|
|
120
|
-
uploadImage:
|
|
121
|
-
|
|
110
|
+
uploadImage: {
|
|
111
|
+
customUpload(file: File, insertFn: (url: string) => void) {
|
|
112
|
+
return handleUpload(file, insertFn);
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
uploadVideo: {
|
|
116
|
+
customUpload(file: File, insertFn: (url: string) => void) {
|
|
117
|
+
return handleUpload(file, insertFn);
|
|
118
|
+
},
|
|
119
|
+
},
|
|
122
120
|
},
|
|
123
121
|
},
|
|
124
122
|
});
|