2020-02-21 09:25:48 -05:00
|
|
|
<template>
|
|
|
|
<el-dialog
|
|
|
|
:title="inputBoxOptions.title || '输入框'"
|
|
|
|
:visible.sync="showInputBoxVisible"
|
|
|
|
:modal-append-to-body="false"
|
|
|
|
>
|
|
|
|
<el-input
|
|
|
|
v-model="inputBoxValue"
|
|
|
|
:placeholder="inputBoxOptions.placeholder"></el-input>
|
|
|
|
<span slot="footer">
|
2020-02-25 07:58:39 -05:00
|
|
|
<el-button @click="handleInputBoxCancel" round>取消</el-button>
|
|
|
|
<el-button type="primary" @click="handleInputBoxConfirm" round>确定</el-button>
|
2020-02-21 09:25:48 -05:00
|
|
|
</span>
|
|
|
|
</el-dialog>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Vue } from 'vue-property-decorator'
|
2022-01-04 10:40:28 -05:00
|
|
|
import { ipcRenderer, IpcRendererEvent } from 'electron'
|
2020-02-21 09:25:48 -05:00
|
|
|
import {
|
|
|
|
SHOW_INPUT_BOX,
|
|
|
|
SHOW_INPUT_BOX_RESPONSE
|
|
|
|
} from '~/universal/events/constants'
|
|
|
|
@Component({
|
|
|
|
name: 'input-box-dialog'
|
|
|
|
})
|
|
|
|
export default class extends Vue {
|
|
|
|
inputBoxValue = ''
|
|
|
|
showInputBoxVisible = false
|
|
|
|
inputBoxOptions = {
|
|
|
|
title: '',
|
|
|
|
placeholder: ''
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2020-02-21 09:25:48 -05:00
|
|
|
created () {
|
|
|
|
ipcRenderer.on(SHOW_INPUT_BOX, this.ipcEventHandler)
|
|
|
|
this.$bus.$on(SHOW_INPUT_BOX, this.initInputBoxValue)
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2020-02-21 09:25:48 -05:00
|
|
|
ipcEventHandler (evt: IpcRendererEvent, options: IShowInputBoxOption) {
|
|
|
|
this.initInputBoxValue(options)
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2020-02-21 09:25:48 -05:00
|
|
|
initInputBoxValue (options: IShowInputBoxOption) {
|
2020-02-23 04:48:12 -05:00
|
|
|
this.inputBoxValue = options.value || ''
|
2020-02-21 09:25:48 -05:00
|
|
|
this.inputBoxOptions.title = options.title || ''
|
|
|
|
this.inputBoxOptions.placeholder = options.placeholder || ''
|
|
|
|
this.showInputBoxVisible = true
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2020-02-25 07:58:39 -05:00
|
|
|
handleInputBoxCancel () {
|
2020-02-21 09:25:48 -05:00
|
|
|
// TODO: RPCServer
|
2020-02-25 07:58:39 -05:00
|
|
|
this.showInputBoxVisible = false
|
2020-02-23 04:48:12 -05:00
|
|
|
ipcRenderer.send(SHOW_INPUT_BOX, '')
|
|
|
|
this.$bus.$emit(SHOW_INPUT_BOX_RESPONSE, '')
|
2020-02-21 09:25:48 -05:00
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2020-02-25 07:58:39 -05:00
|
|
|
handleInputBoxConfirm () {
|
|
|
|
this.showInputBoxVisible = false
|
|
|
|
ipcRenderer.send(SHOW_INPUT_BOX, this.inputBoxValue)
|
|
|
|
this.$bus.$emit(SHOW_INPUT_BOX_RESPONSE, this.inputBoxValue)
|
|
|
|
}
|
2022-01-04 10:40:28 -05:00
|
|
|
|
2020-02-21 09:25:48 -05:00
|
|
|
beforeDestroy () {
|
|
|
|
ipcRenderer.removeListener(SHOW_INPUT_BOX, this.ipcEventHandler)
|
|
|
|
this.$bus.$off(SHOW_INPUT_BOX)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang='stylus'>
|
|
|
|
</style>
|