Skip to content

Commit 5accb54

Browse files
committed
Refactor and add DialogForm
1 parent 875cb0e commit 5accb54

24 files changed

+159
-44
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"dependencies": {
2020
"@fortawesome/fontawesome-free": "^5.1.0",
2121
"@luogu-dev/markdown-it-katex": "^0.0.1",
22+
"axios": "^0.18.0",
2223
"codemirror": "^5.39.0",
2324
"highlight.js": "^9.12.0",
2425
"katex": "^0.9.0",

src/components/MarkdownPalettes.vue renamed to src/MarkdownPalettes.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,17 @@
178178
import '@fortawesome/fontawesome-free/css/solid.css'
179179
import '@fortawesome/fontawesome-free/css/fontawesome.css'
180180
181-
import Dialog from './Dialog.vue'
181+
import Dialog from './components/Dialog/Dialog.vue'
182182
183-
import InputAreaMixin from './InputAreaMixin'
184-
import PreviewAreaMixin from './PreviewAreaMixin'
185-
import ToolbarMixin from './ToolbarMixin'
186-
import ActionMixin from './ActionMixin'
183+
import InputAreaMixin from './mixins/InputAreaMixin'
184+
import PreviewAreaMixin from './mixins/PreviewAreaMixin'
185+
import ToolbarMixin from './mixins/ToolbarMixin'
186+
import ActionMixin from './mixins/ActionMixin'
187187
188-
import { defaultConfig, getConfig } from './DefaultConfig'
189-
import { contentParserFactory } from './ContentParserFactory'
190-
import InjectLnParser from './plugins/InjectLnParser.js'
191-
import { getText } from './i18n'
188+
import { defaultConfig, getConfig } from './utils/DefaultConfig'
189+
import { contentParserFactory } from './parsers/ContentParserFactory'
190+
import InjectLnParser from './parsers/InjectLnParser.js'
191+
import { getText } from './utils/i18n'
192192
193193
export default {
194194
name: 'markdown-palettes',

src/components/Dialog.vue renamed to src/components/Dialog/Dialog.vue

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
</div>
1111

1212
<form class="mp-dialog-body" @submit.prevent="finish">
13-
<div class="mp-dialog-form">
14-
<div class="mp-dialog-field" v-for="field in request.body" :key="field.name">
15-
<component :is="field.type || field.component" :request-field="field" v-model="responseData[field.name]"></component>
16-
</div>
17-
</div>
13+
<dialog-form :fields="this.request.body" v-model="responseData"></dialog-form>
1814

1915
<div class="mp-dialog-footer">
2016
<div>
@@ -71,11 +67,6 @@
7167
padding-bottom: 10px;
7268
}
7369
74-
.mp-dialog-field {
75-
margin: 10px 8px;
76-
overflow:auto;
77-
}
78-
7970
.mp-dialog-footer {
8071
overflow:auto;
8172
}
@@ -114,7 +105,7 @@
114105
</style>
115106

116107
<script>
117-
import DialogComponents from './dialog-input-components/components'
108+
import DialogForm from './DialogForm'
118109
119110
export default {
120111
name: 'editor-dialog',
@@ -146,7 +137,7 @@ export default {
146137
this.$emit('finish', this.response)
147138
}
148139
},
149-
components: DialogComponents,
140+
components: { DialogForm },
150141
inject: ['t']
151142
}
152143
</script>

src/components/dialog-input-components/CodeMirror.vue renamed to src/components/Dialog/DialogCodeMirror.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
</style>
1919

2020
<script>
21-
import abstractInputComponent from './AbstractInputComponent'
21+
import AbstractDialogComponent from './AbstractDialogComponent'
2222
import CodeMirror from 'codemirror'
2323
import 'codemirror/lib/codemirror.css'
2424
2525
export default {
2626
name: 'dialog-codemirror',
27-
extends: abstractInputComponent,
27+
extends: AbstractDialogComponent,
2828
data () {
2929
return {
3030
editor: null
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import DialogInput from './DialogInput'
2+
import DialogSelect from './DialogSelect'
3+
import DialogCodeMirror from './DialogCodeMirror'
4+
import DialogFile from './DialogFile'
5+
6+
export default {
7+
'dialog-input': DialogInput,
8+
'dialog-select': DialogSelect,
9+
'dialog-codemirror': DialogCodeMirror,
10+
'dialog-file': DialogFile
11+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<template>
2+
<div class="mp-dialog-input">
3+
<label>{{ title }}</label>
4+
<input type="file" name="picture" @change="handleFile">
5+
</div>
6+
</template>
7+
8+
<style scoped>
9+
.mp-dialog-input {
10+
overflow: auto;
11+
}
12+
13+
.mp-dialog-input label {
14+
float: left;
15+
padding-top: 5px;
16+
vertical-align: top;
17+
margin-right: 10px;
18+
width: 20%;
19+
font-size: 14px;
20+
color: #666;
21+
}
22+
23+
.mp-dialog-input input {
24+
float: left;
25+
width: 70%;
26+
color: #999;
27+
padding: 8px;
28+
border: 1px solid #ddd;
29+
}
30+
</style>
31+
32+
<script>
33+
import abstractInputComponent from './AbstractDialogComponent'
34+
35+
export default {
36+
name: 'file',
37+
extends: abstractInputComponent,
38+
methods: {
39+
async handleFile (event) {
40+
let file = event.target.files[0]
41+
this.fieldValue = await this.param.callback(file)
42+
}
43+
}
44+
}
45+
</script>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<template>
2+
<div class="dialog-form">
3+
<div class="mp-dialog-field" v-for="field in fields" :key="field.name">
4+
<component :is="field.type || field.component" :request-field="field" v-model="data[field.name]"></component>
5+
</div>
6+
</div>
7+
</template>
8+
9+
<script>
10+
import DialogComponents from './DialogComponentMap'
11+
12+
export default {
13+
name: 'dialog-form',
14+
props: {
15+
fields: {
16+
type: Array,
17+
required: true
18+
},
19+
value: {
20+
type: Object,
21+
required: true
22+
}
23+
},
24+
model: {
25+
prop: 'value',
26+
event: 'change'
27+
},
28+
computed: {
29+
data: {
30+
get () {
31+
return this.value
32+
},
33+
set (value) {
34+
this.$emit('change', value)
35+
}
36+
}
37+
},
38+
methods: {
39+
close () {
40+
this.$emit('close')
41+
},
42+
finish () {
43+
this.$emit('finish', this.response)
44+
}
45+
},
46+
components: DialogComponents,
47+
inject: ['t']
48+
}
49+
</script>
50+
51+
<style scoped>
52+
.mp-dialog-field {
53+
margin: 10px 8px;
54+
overflow:auto;
55+
}
56+
</style>

src/components/dialog-input-components/Input.vue renamed to src/components/Dialog/DialogInput.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
</style>
3131

3232
<script>
33-
import abstractInputComponent from './AbstractInputComponent'
33+
import AbstractDialogComponent from './AbstractDialogComponent'
3434
3535
export default {
3636
name: 'dialog-input',
37-
extends: abstractInputComponent
37+
extends: AbstractDialogComponent
3838
}
3939
</script>

src/components/dialog-input-components/Select.vue renamed to src/components/Dialog/DialogSelect.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="mp-dialog-select">
33
<label>{{ title }}</label>
44
<select v-model="value">
5-
<option v-for="option in param.options" :value="option.value">{{ t(option.title) }}</option>
5+
<option v-for="option in param.options" :key="option.title" :value="option.value">{{ t(option.title) }}</option>
66
</select>
77
</div>
88
</template>
@@ -33,10 +33,10 @@
3333
</style>
3434

3535
<script>
36-
import abstractInputComponent from './AbstractInputComponent'
36+
import AbstractDialogComponent from './AbstractDialogComponent'
3737
3838
export default {
3939
name: 'dialog-select',
40-
extends: abstractInputComponent
40+
extends: AbstractDialogComponent
4141
}
4242
</script>

0 commit comments

Comments
 (0)