old
宇天 2019-12-03 17:25:16 +08:00
parent 1010b6cdd5
commit 163e2cfaf4
4 changed files with 53 additions and 5 deletions

View File

@ -56,7 +56,7 @@
<span>A</span> <span>A</span>
<wc-input class="long" :duplex="it.value" label="请填写IP"></wc-input> <wc-input class="long" :duplex="it.value" label="请填写IP"></wc-input>
<section> <section>
<wc-switch :duplex="it.enabled"></wc-switch> <wc-switch :duplex="it.enabled" @change="recordChanges(it)"></wc-switch>
<wc-button size="mini" color="red" @active="$remove">删除</wc-button> <wc-button size="mini" color="red" @active="$remove">删除</wc-button>
</section> </section>
<wc-input :duplex="it.remark"></wc-input> <wc-input :duplex="it.remark"></wc-input>

View File

@ -19,6 +19,7 @@ const WIN = remote.getCurrentWindow()
const $doc = Anot(document) const $doc = Anot(document)
var dict = {} var dict = {}
var tmp_records = {}
Anot({ Anot({
$id: 'app', $id: 'app',
@ -33,6 +34,7 @@ Anot({
// this.$refs.preview.show() // this.$refs.preview.show()
this.check() this.check()
}, },
watch: {},
methods: { methods: {
addRecord() { addRecord() {
log('---') log('---')
@ -68,6 +70,17 @@ Anot({
toggleDomain(name) { toggleDomain(name) {
this.curr = name this.curr = name
this.records = dict[name] this.records = dict[name]
tmp_records = Object.create(null)
for (let it of this.records) {
if (tmp_records[it.record]) {
tmp_records[it.record].push(it)
} else {
tmp_records[it.record] = [it]
}
}
setTimeout(() => {
this.$refs.records.scrollTop = 0
}, 50)
}, },
check() { check() {
var check = ipcRenderer.sendSync('dns-host', { type: 'check' }) var check = ipcRenderer.sendSync('dns-host', { type: 'check' })
@ -77,13 +90,34 @@ Anot({
var tmp = [] var tmp = []
for (var k in dict) { for (var k in dict) {
tmp.push(k) if (k) {
tmp.push(k)
} else {
delete dict[k]
}
} }
this.domains = tmp this.domains = tmp
} else { } else {
this.permissionShow = true this.permissionShow = true
} }
}, },
save() {} // 同一个记录, 允许一条被激活
recordChanges(item) {
if (item.enabled) {
if (tmp_records[item.record].length > 1) {
for (let it of tmp_records[item.record]) {
if (it.value !== item.value) {
it.enabled = false
}
}
}
}
},
save() {
if (this.curr) {
dict[this.curr] = this.records.$model
ipcRenderer.send('dns-host', { type: 'set', data: dict })
}
}
} }
}) })

View File

@ -66,7 +66,7 @@ app.once('ready', () => {
win = null win = null
}) })
win.openDevTools() // win.openDevTools()
// 然后加载应用的 index.html // 然后加载应用的 index.html
win.loadURL('app://local/index.html') win.loadURL('app://local/index.html')

View File

@ -44,7 +44,21 @@ ipcMain.on('dns-host', (ev, conn) => {
clearTimeout(timer) clearTimeout(timer)
timer = setTimeout(() => { timer = setTimeout(() => {
fs.echo(JSON.stringify(conn.data), HOST_FILE) fs.echo(JSON.stringify(conn.data), HOST_FILE)
}, 2000) var txt = ''
for (let k in conn.data) {
for (let it of conn.data[k]) {
if (it.enabled) {
var name = it.record === '@' ? '' : it.record
if (name) {
name += '.'
}
txt += `${it.value.padEnd(15, ' ')} ${name + k}\n`
}
}
txt += '\n\n'
}
fs.echo(txt, '/etc/hosts')
}, 1000)
break break
case 'check': case 'check':