Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

Commit ffef651

Browse files
committed
fix: 处理 options 相关问题
1 parent f8c53d9 commit ffef651

13 files changed

+131
-168
lines changed

.eslintrc.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const isProd = process.env.NODE_ENV === "production";
12
module.exports = {
23
root: true,
34
env: {
@@ -8,12 +9,9 @@ module.exports = {
89
parser: "babel-eslint"
910
},
1011
rules: {
11-
"vue/no-unused-components":
12-
process.env.NODE_ENV === "production" ? "error" : "warn",
13-
"no-console":
14-
process.env.NODE_ENV === "production"
15-
? ["error", { allow: ["warn", "error"] }]
16-
: "off",
17-
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off"
12+
"no-unused-vars": isProd ? "error" : "warn",
13+
"vue/no-unused-components": isProd ? "error" : "warn",
14+
"no-console": isProd ? ["error", { allow: ["warn", "error"] }] : "off",
15+
"no-debugger": isProd ? "warn" : "off"
1816
}
1917
};

README.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1111
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1212

13-
1413
- [交流群](#%E4%BA%A4%E6%B5%81%E7%BE%A4)
1514
- [介绍](#%E4%BB%8B%E7%BB%8D)
1615
- [注意](#%E6%B3%A8%E6%84%8F)
@@ -394,12 +393,10 @@ export default {
394393

395394
如果你或者你的公司需要`付费`源码讲解和答疑,可加我微信:`dream10nian`。当然也有也有免费的交流群,也是加这个微信。
396395

397-
## f-render 不能做什么?
398-
399-
由于 `vue-ele-form` 原因,
396+
## f-render 问答集锦
400397

401-
- f-render 不支持嵌套的子表单
402-
- 布局由于使用了 `el-row``el-col`,所以仅支持行布局
398+
- [1、f-render 不能做什么?](https://www.yuque.com/chaojie-vjiel/vbwzgu/adz8q8#0nlfc)
399+
- [2、怎么实现 options URL 配置?](https://www.yuque.com/chaojie-vjiel/vbwzgu/adz8q8#gvS8c)
403400

404401
## Props 说明
405402

@@ -449,11 +446,11 @@ props: {
449446
loading: Boolean,
450447

451448
// 表单相关(pure 为 true 时), 同 vue-ele-form
452-
// https://www.yuque.com/chaojie-vjiel/vbwzgu/zbu9mn
453-
value: Object,
449+
// https://www.yuque.com/chaojie-vjiel/vbwzgu/dyw8a7
454450
requestFn: Function,
455451
isLoading: Boolean,
456-
formError: Object
452+
formError: Object,
453+
// ....
457454
},
458455
```
459456

example/main.js

+6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import EleForm from "vue-ele-form";
66
import EleDynamic from "vue-ele-form-dynamic";
77
import "element-ui/lib/theme-chalk/index.css";
88
import "normalize.css";
9+
import axios from "axios";
910

11+
axios.interceptors.response.use(response => {
12+
// 将响应结果返回
13+
return response.data;
14+
});
15+
Vue.prototype.$axios = axios;
1016
Vue.config.productionTip = false;
1117
Vue.use(ElementUI);
1218
Vue.use(EleForm, {

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"lodash": "^4.17.20",
2424
"prismjs": "^1.21.0",
2525
"serialize-javascript": "^4.0.0",
26-
"vue-ele-form-data-editor": "^0.1.5",
26+
"vue-ele-form-data-editor": "^0.1.6",
2727
"vue-ele-form-dynamic": "^0.4.2",
2828
"vue-multipane": "^0.9.5",
2929
"vue-prism-editor": "^1.2.2",
@@ -35,6 +35,7 @@
3535
"@vue/cli-plugin-eslint": "~4.5.0",
3636
"@vue/cli-service": "~4.5.0",
3737
"@vue/eslint-config-prettier": "^6.0.0",
38+
"axios": "^0.20.0",
3839
"babel-eslint": "^10.1.0",
3940
"babel-plugin-lodash": "^3.3.4",
4041
"core-js": "^3.6.5",
@@ -51,7 +52,7 @@
5152
"sass-loader": "^8.0.2",
5253
"standard-version": "^9.0.0",
5354
"vue": "^2.6.11",
54-
"vue-ele-form": "^0.8.35",
55+
"vue-ele-form": "^0.8.36",
5556
"vue-template-compiler": "^2.6.11"
5657
},
5758
"repository": {

src/components/left/index.vue

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export default {
9393
color: #606266;
9494
border: 1px solid #ebeef5;
9595
overflow: hidden;
96+
cursor: move;
9697
white-space: nowrap;
9798
display: inline-block;
9899
text-overflow: ellipsis;

src/components/main/main-content.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@request-success="handleSuccess"
77
ref="ele-form"
88
:formDesc="frender.formDesc"
9-
v-bind="frender.formConfig"
9+
v-bind="frender.formBindConfig"
1010
>
1111
<template v-slot:form-content="{ props, formDesc, formErrorObj }">
1212
<vue-draggable

src/components/right/form-item-common.vue

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
<template>
22
<div>
3-
<template v-if="currentFormItem">
3+
<template v-if="currentFormItem && currentIndex !== null">
44
<attrs-header
55
url="https://www.yuque.com/chaojie-vjiel/vbwzgu/iw5dzf"
66
title="通用配置"
77
v-model="keyword"
88
/>
9+
<!-- 这里不能用 v-model 会产生循环引用 -->
910
<ele-form
10-
v-model="formItemList[currentIndex]"
11+
:formData="formItemList[currentIndex]"
1112
:formDesc="filteredFormDesc"
1213
:formAttrs="{ size: 'small' }"
1314
:isShowBackBtn="false"
1415
:isShowSubmitBtn="false"
1516
:rules="rules"
17+
:options-fn="
18+
frender.formBindConfig['options-fn'] ||
19+
frender.formBindConfig['optionsFn']
20+
"
1621
:span="20"
1722
labelPosition="top"
1823
>
@@ -85,6 +90,23 @@ export default {
8590
return changeFormDescLabel(formDesc);
8691
}
8792
},
93+
watch: {
94+
currentIndex: {
95+
// 默认值在保存后会被删除
96+
// 所以在回显的时候就会有问题,这里需要重新赋值
97+
handler(currentIndex) {
98+
if (currentIndex === null) return;
99+
const currentFormItem = Object.assign(
100+
{},
101+
this.frender.formItemCommon.data,
102+
this.currentFormItem
103+
);
104+
105+
this.frender.updateCurrentFormItem(currentFormItem);
106+
},
107+
immediate: true
108+
}
109+
},
88110
data() {
89111
return {
90112
rules: {
@@ -125,15 +147,6 @@ export default {
125147
console.error(error);
126148
}
127149
}
128-
},
129-
watch: {
130-
// 对 layout 特殊处理
131-
// 如果发现 layout 为 undefined,则赋值为 24
132-
"currentFormItem.layout"(val) {
133-
if (!val) {
134-
this.frender.updateCurrentFormItem({ layout: 24 });
135-
}
136-
}
137150
}
138151
};
139152
</script>

src/f-render.vue

+14-10
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
<!-- 2.使用 -->
1919
<ele-form
20-
v-bind="formConfig"
20+
v-bind="formBindConfig"
2121
:formData="value"
22-
:requestFn="requestFn"
23-
:isLoading="isLoading"
24-
:formError="formError"
2522
v-on="$listeners"
2623
@input="$emit('input', value)"
2724
v-else-if="isShowPure"
@@ -30,7 +27,7 @@
3027

3128
<script>
3229
// 全局组件
33-
import "./extends";
30+
import "./global-components";
3431
3532
import FRenderLeft from "./components/left/index";
3633
import FRenderMain from "./components/main/index";
@@ -110,10 +107,7 @@ export default {
110107
111108
// 表单相关(pure 为 true 时), 同 vue-ele-form
112109
// https://www.yuque.com/chaojie-vjiel/vbwzgu/zbu9mn
113-
value: Object,
114-
requestFn: Function,
115-
isLoading: Boolean,
116-
formError: Object
110+
value: Object
117111
},
118112
watch: {
119113
config: {
@@ -139,11 +133,21 @@ export default {
139133
}
140134
this.formConfig = formConfig;
141135
this.formItemList = objectToArr(formConfig.formDesc, "field");
136+
137+
// 当有数据时,选中第一个
138+
if (this.formItemList.length) {
139+
this.currentIndex = 0;
140+
}
142141
},
143142
immediate: true
144143
}
145144
},
146145
computed: {
146+
// 表单绑定的配置
147+
// 融合了 $attrs
148+
formBindConfig() {
149+
return { ...this.changedFormConfig, ...this.$attrs };
150+
},
147151
// 最终的返回结果
148152
changedFormConfig() {
149153
return {
@@ -196,7 +200,7 @@ export default {
196200
// formDesc 的数组形态(provide)
197201
formItemList: [],
198202
// 当前 formItem的 index 值(provide)
199-
currentIndex: 0
203+
currentIndex: null
200204
};
201205
},
202206
methods: {

0 commit comments

Comments
 (0)