Skip to content

Commit 9da36a3

Browse files
committed
feat: 新增【重置表单】功能
1 parent f70c67c commit 9da36a3

File tree

8 files changed

+49
-17
lines changed

8 files changed

+49
-17
lines changed

app/store/global-actions.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import types from './mutation-types'
22
import Immutable from 'immutable'
33
import shortid from 'js-shortid'
44

5+
const makeAction = type => {
6+
return ({ commit }, ...args) => commit(type, ...args)
7+
}
8+
59
export default {
610
addRow ({ commit, state }, reload) {
711
let { layoutSections } = state
@@ -67,7 +71,7 @@ export default {
6771
let _list = Immutable.fromJS(layoutSections)
6872
commit(types.UPDATE_LAYOUT_SECTIONS, _list.set(activeSection, newVal).toJS())
6973
},
70-
async delteColComp ({ commit, state, dispatch }, { colIndex, newVal, prop }) {
74+
async deleteColComp ({ commit, state, dispatch }, { colIndex, newVal, prop }) {
7175
let { layoutSections, activeSection } = state
7276
let _list = Immutable.fromJS(layoutSections)
7377
console.log(1)
@@ -123,5 +127,6 @@ export default {
123127
] })
124128
}
125129
commit(types.UPDATE_ACTIVE_PROP, `default_${_propIdx}`)
126-
}
130+
},
131+
resetGlobalStore: makeAction('RESET_GLOBAL_STORE')
127132
}

app/store/global-mutations.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,29 @@ export default {
3030
},
3131
[types.UPDATE_FORM_CONTROL] (state, load) {
3232
state.formControl = Object.assign(state.formControl, load)
33+
},
34+
[types.RESET_GLOBAL_STORE](state, load) {
35+
const originState = {
36+
iterationIdx: 0, // 迭代指针
37+
layoutSections: [], // schema 信息
38+
formModel: {},
39+
formOptions: {},
40+
formLayout: { // 表单布局
41+
gutter: 16,
42+
justify: 'start'
43+
},
44+
formSettings: { // 表单属性
45+
labelPosition: 'left',
46+
size: 'small',
47+
labelWidth: '80px'
48+
},
49+
formControl: { // 布局控制
50+
showGrid: false,
51+
showLayout: false
52+
},
53+
activeSection: 0, // 激活的行数
54+
activeProp: '' // 激活的组件prop
55+
}
56+
state = Object.assign(state, originState)
3357
}
3458
}

app/store/mutation-types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export default {
77
UPDATE_ITERATION_IDX: 'UPDATE_ITERATION_IDX',
88
UPDATE_FORM_SETTING: 'UPDATE_FORM_SETTING',
99
UPDATE_FORM_LAYOUT: 'UPDATE_FORM_LAYOUT',
10-
UPDATE_FORM_CONTROL: 'UPDATE_FORM_CONTROL'
10+
UPDATE_FORM_CONTROL: 'UPDATE_FORM_CONTROL',
11+
RESET_GLOBAL_STORE: 'RESET_GLOBAL_STORE'
1112
}

app/views/form-generator/aside-panel/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default {
9999
'editRow',
100100
'deleteRow',
101101
'changeRow',
102-
'delteColComp'
102+
'deleteColComp'
103103
]),
104104
checkMove (e) {
105105
console.log('Future index: ' + e.draggedContext.futureIndex)
@@ -109,7 +109,7 @@ export default {
109109
isCustom: 'btn-addCol',
110110
colGrid: element.colGrid
111111
}
112-
this.delteColComp({ colIndex, newVal: oldSection, prop: element.prop })
112+
this.deleteColComp({ colIndex, newVal: oldSection, prop: element.prop })
113113
},
114114
onAddRow (data) {
115115
const initVal = data.map((val, idx) => {

app/views/form-generator/config-panel/module/component-panel.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
<figcaption class="component-panel__figcaption">
66
<span>通用属性</span>
77
</figcaption>
8-
<label-layout title="标签名称:">
9-
<el-input v-model="editInfo.formItem.label"></el-input>
10-
</label-layout>
11-
<label-layout title="数据字段:">
12-
<el-input v-model="editInfo.prop"></el-input>
13-
</label-layout>
14-
<label-layout title="栅格数:">
15-
<el-input v-model.number="editInfo.colGrid.span"></el-input>
16-
</label-layout>
8+
<label-layout title="标签名称:">
9+
<el-input v-model="editInfo.formItem.label"></el-input>
10+
</label-layout>
11+
<label-layout title="数据字段:">
12+
<el-input v-model="editInfo.prop"></el-input>
13+
</label-layout>
14+
<label-layout title="栅格数:">
15+
<el-input v-model.number="editInfo.colGrid.span"></el-input>
16+
</label-layout>
1717
</fieldset>
1818
<!-- 定制属性 -->
1919
<fieldset class="component-panel__fieldset">

app/views/form-generator/dialog/PreviewForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
:options="options"
2020
>
2121
</schema-form>
22-
</el-form>
22+
</el-form>
2323
</el-dialog>
2424
</div>
2525
</template>

app/views/form-generator/index.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<el-button type="warning" size="mini" @click="showSchemaCode = true">生成 Schema</el-button>
1212
<el-button type="danger" size="mini" @click="showVueCode = true">生成 Vue 代码</el-button>
1313
<el-button type="success" size="mini" @click="showResult = true">预览表单</el-button>
14+
<el-button size="mini" @click="resetGlobalStore">重置表单</el-button>
1415
</div>
1516
</div>
1617
<el-form
@@ -132,7 +133,8 @@ export default {
132133
},
133134
methods: {
134135
...mapActions([
135-
'addComponent'
136+
'addComponent',
137+
'resetGlobalStore'
136138
]),
137139
handleAddComponent (comp, scope) {
138140
const { rowIndex, colIndex } = scope

docs/.vuepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
title: '指南',
2525
collapsable: false,
2626
children: [
27-
'/guide/',
27+
'',
2828
'快速开始',
2929
'更新日志',
3030
'在线示例',

0 commit comments

Comments
 (0)