Skip to content

Commit e7f261b

Browse files
committed
add select mode
1 parent 6d69268 commit e7f261b

File tree

7 files changed

+124
-25
lines changed

7 files changed

+124
-25
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
import { app, BrowserWindow } from 'electron'
3+
import { app, BrowserWindow, globalShortcut } from 'electron'
44

55
/**
66
* Set `__static` path to static files in production
@@ -30,6 +30,10 @@ function createWindow () {
3030
mainWindow.on('closed', () => {
3131
mainWindow = null
3232
})
33+
34+
globalShortcut.register('CommandOrControl+Alt+k', () => {
35+
mainWindow.webContents.openDevTools()
36+
})
3337
}
3438

3539
app.on('ready', createWindow)

src/renderer/components/LandingPage.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
}
4343
}
4444
},
45+
created () {
46+
this.config = localStorage.getItem('config') ? JSON.parse(localStorage.getItem('config')) : this.config
47+
},
4548
methods: {
4649
open (link) {
4750
this.$electron.shell.openExternal(link)

src/renderer/components/MainPage.vue

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,33 @@
5858
</el-col>
5959
<template v-if="data.type === 'number' || data.type === 'string'">
6060
<el-col :span="3">
61-
<el-input v-model="data._value" placeholder=""></el-input>
62-
</el-col>
63-
<el-col :span="3">
64-
<el-input v-model="data._label" placeholder="标签"></el-input>
65-
</el-col>
66-
<el-col :span="2">
67-
<el-button type="primary" @click="addOption(index)">增加选项</el-button>
61+
<el-select v-model="data._select_type" placeholder="选择类型">
62+
<el-option label="固定" value="fixed"></el-option>
63+
<el-option label="接口" value="api"></el-option>
64+
</el-select>
6865
</el-col>
66+
<template v-if="data._select_type === 'fixed'">
67+
<el-col :span="3">
68+
<el-input v-model="data._value" placeholder=""></el-input>
69+
</el-col>
70+
<el-col :span="3">
71+
<el-input v-model="data._label" placeholder="标签"></el-input>
72+
</el-col>
73+
<el-col :span="1">
74+
<el-button type="primary" @click="addOption(index)">增加</el-button>
75+
</el-col>
76+
</template>
77+
<template v-if="data._select_type === 'api'">
78+
<el-col :span="3">
79+
<el-input v-model="data._api_path" placeholder="接口地址"></el-input>
80+
</el-col>
81+
<el-col :span="2">
82+
<el-input v-model="data._label" placeholder="标签"></el-input>
83+
</el-col>
84+
<el-col :span="2">
85+
<el-input v-model="data._value" placeholder="内容"></el-input>
86+
</el-col>
87+
</template>
6988
</template>
7089
</el-row>
7190
</el-form-item>
@@ -204,14 +223,14 @@
204223
this.$message.error('请选择保存路径')
205224
return
206225
}
207-
const filterDataList = this.dataList.map(data => {
208-
const keys = Object.keys(data).filter(key => !key.startsWith('_'))
209-
const newData = {}
210-
keys.forEach(key => { newData[key] = data[key] })
211-
return newData
212-
})
213-
console.log('filterDataList', filterDataList)
214-
d2Curd(filePath[0], this.dataConfig, filterDataList)
226+
// const filterDataList = this.dataList.map(data => {
227+
// const keys = Object.keys(data).filter(key => !key.startsWith('_'))
228+
// const newData = {}
229+
// keys.forEach(key => { newData[key] = data[key] })
230+
// return newData
231+
// })
232+
console.log('filterDataList', this.dataList)
233+
d2Curd(filePath[0], this.dataConfig, this.dataList)
215234
},
216235
addOption (index) {
217236
const data = this.dataList[index]

src/renderer/templates/add.vue.ejs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
<el-date-picker v-model="form.<%= field.key %>" type="datetime" placeholder="选择日期时间">
99
</el-date-picker>
1010
</el-form-item>
11-
<%_ } else if (field.choices && field.choices.length > 0) { _%>
11+
<%_ } else if (field.choices && (field.choices.length > 0 || field._select_type === 'api')) { _%>
1212
<el-form-item label="<%= field.name %>">
1313
<el-select v-model="form.<%= field.key %>" placeholder="请选择<%= field.name %>">
14-
<%_ field.choices.forEach(function(choice) { _%>
15-
<el-option label="<%= choice.label %>" <% if (field.type === 'number') { %> :<% } %>value="<%= choice.value %>"></el-option>
16-
<%_ }) _%>
14+
<el-option
15+
v-for="item in <%= field.key %>Choices"
16+
:key="item.<%= field._value %>"
17+
:label="item.<%= field._label %>"
18+
:value="item.<%= field._value %>">
19+
</el-option>
1720
</el-select>
1821
</el-form-item>
1922
<%_ } else if (field.type === 'number') { _%>
@@ -81,12 +84,38 @@ export default {
8184
<%_ if (field.type === 'file') { _%>
8285
<%= field.key %>Data: {},
8386
<%= field.key %>FileList: []
87+
<%_ } else if (field.choices && (field.choices.length > 0 || field._select_type === 'api')) { _%>
88+
<%= field.key %>Choices: [
89+
<%_ field.choices.forEach(function(choice){ _%>
90+
{
91+
value: <%- field.type === 'number' ? choice.value : `'${choice.value}'` %>,
92+
label: "<%= choice.label %>"
93+
},
94+
<%_ }) _%>
95+
],
8496
<%_ } _%>
8597
<%_ }) _%>
8698
}
8799
},
88100
created () {
89101
this.initForm()
102+
<%_ fields.forEach(function(field){ _%>
103+
<%_ if (field.choices && (field.choices.length > 0 || field._select_type === 'api')) { _%>
104+
<%_ if (field._select_type === 'api') { _%>
105+
// get choices
106+
this.$axios({
107+
method: 'get',
108+
url: '<%= field._api_path %>',
109+
params: {
110+
page: 1,
111+
pageSize: 500000 // 默认不分页
112+
}
113+
}).then(result => {
114+
this.<%= field.key %>Choices = result.results
115+
})
116+
<%_ } _%>
117+
<%_ } _%>
118+
<%_ }) _%>
90119
},
91120
methods: {
92121
async initForm () {

src/renderer/templates/edit.vue.ejs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<el-date-picker v-model="form.<%= field.key %>" type="datetime" placeholder="选择日期时间">
99
</el-date-picker>
1010
</el-form-item>
11-
<%_ } else if (field.choices && field.choices.length > 0) { _%>
11+
<%_ } else if (field.choices && (field.choices.length > 0 || field._select_type === 'api')) { _%>
1212
<el-form-item label="<%= field.name %>">
1313
<el-select v-model="form.<%= field.key %>" placeholder="请选择<%= field.name %>">
1414
<%_ field.choices.forEach(function(choice) { _%>
@@ -82,12 +82,38 @@ export default {
8282
<%_ if (field.type === 'file') { _%>
8383
<%= field.key %>Data: {},
8484
<%= field.key %>FileList: []
85+
<%_ } else if (field.choices && (field.choices.length > 0 || field._select_type === 'api')) { _%>
86+
<%= field.key %>Choices: [
87+
<%_ field.choices.forEach(function(choice){ _%>
88+
{
89+
value: <%- field.type === 'number' ? choice.value : `'${choice.value}'` %>,
90+
label: "<%= choice.label %>"
91+
},
92+
<%_ }) _%>
93+
],
8594
<%_ } _%>
8695
<%_ }) _%>
8796
}
8897
},
8998
created () {
9099
this.initForm()
100+
<%_ fields.forEach(function(field){ _%>
101+
<%_ if (field.choices && (field.choices.length > 0 || field._select_type === 'api')) { _%>
102+
<%_ if (field._select_type === 'api') { _%>
103+
// get choices
104+
this.$axios({
105+
method: 'get',
106+
url: '<%= field._api_path %>',
107+
params: {
108+
page: 1,
109+
pageSize: 500000 // 默认不分页
110+
}
111+
}).then(result => {
112+
this.<%= field.key %>Choices = result.results
113+
})
114+
<%_ } _%>
115+
<%_ } _%>
116+
<%_ }) _%>
91117
},
92118
methods: {
93119
async initForm () {

src/renderer/templates/list.vue.ejs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<d2-icon :name="scope.row.<%= field.key %> ? 'check': 'close'"/>
4444
</template>
4545
</el-table-column>
46-
<%_ } else if (field.choices && field.choices.length > 0) { _%>
46+
<%_ } else if (field.choices && (field.choices.length > 0 || field._select_type === 'api')) { _%>
4747
<el-table-column
4848
label="<%= field.name %>">
4949
<template slot-scope="scope">
@@ -122,11 +122,11 @@ export default {
122122
multipleSelection: [],
123123
search: '',
124124
<%_ fields.forEach(function(field){ _%>
125-
<%_ if (field.choices && field.choices.length > 0) { _%>
125+
<%_ if (field.choices && (field.choices.length > 0 || field._select_type === 'api')) { _%>
126126
<%= field.key %>Choices: [
127127
<%_ field.choices.forEach(function(choice){ _%>
128128
{
129-
value: <%- field.type === 'number' ? choice.value : `"${choice.value}"` %>,
129+
value: <%- field.type === 'number' ? choice.value : `'${choice.value}'` %>,
130130
label: "<%= choice.label %>"
131131
},
132132
<%_ }) _%>
@@ -137,6 +137,24 @@ export default {
137137
},
138138
created () {
139139
this.getList()
140+
141+
<%_ fields.forEach(function(field){ _%>
142+
<%_ if (field.choices && (field.choices.length > 0 || field._select_type === 'api')) { _%>
143+
<%_ if (field._select_type === 'api') { _%>
144+
// get choices
145+
this.$axios({
146+
method: 'get',
147+
url: '<%= field._api_path %>',
148+
params: {
149+
page: 1,
150+
pageSize: 500000 // 默认不分页
151+
}
152+
}).then(result => {
153+
this.<%= field.key %>Choices = result.results
154+
})
155+
<%_ } _%>
156+
<%_ } _%>
157+
<%_ }) _%>
140158
},
141159
methods: {
142160
getList (page) {

0 commit comments

Comments
 (0)