Skip to content

Commit

Permalink
Merge pull request #15 from aotianwinter/test
Browse files Browse the repository at this point in the history
update v0.1.2
  • Loading branch information
aotianwinter authored Mar 10, 2021
2 parents 86319cb + 8807ba5 commit a7d3c2e
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auto-deploy-app",
"version": "0.1.1",
"version": "0.1.2",
"author": "dajiangyou",
"description": "An electron-vue project",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<style>
.welcome-wrap {
margin: 0 auto;
min-height: 100vh;
min-height: 90vh;
display: flex;
align-items: center;
justify-content: center;
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/core/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import Datastore from 'nedb'
import path from 'path'
import { remote } from 'electron'

export const appDB = new Datastore({
autoload: true,
filename: path.join(remote.app.getPath('userData'), '/app.db')
})

export const serverDB = new Datastore({
autoload: true,
filename: path.join(remote.app.getPath('userData'), '/server.db')
Expand Down
18 changes: 18 additions & 0 deletions src/renderer/store/app-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { mapState, mapActions } from 'vuex'

const appMixin = {
computed: {
...mapState({
setting: state => state.app.setting
})
},
methods: {
...mapActions([
'getSetting',
'initSetting',
'updateSetting'
])
}
}

export default appMixin
59 changes: 59 additions & 0 deletions src/renderer/store/modules/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { appDB } from '@/core/datastore'

const state = {
setting: {} // app setting
}

const mutations = {
GET_SETTING (state, obj) {
state.setting = obj
}
}

const actions = {
getSetting ({ commit }) {
return new Promise((resolve, reject) => {
appDB.findOne({}, (err, docs) => {
if (err) {
reject(err)
} else {
console.log()
if (docs) commit('GET_SETTING', docs)
resolve(docs)
}
})
})
},
initSetting ({ commit }, val) {
if (val.logs) delete val.logs
return new Promise((resolve, reject) => {
appDB.insert({ ...val }, (err, docs) => {
if (err) {
reject(err)
} else {
console.log(docs)
resolve()
}
})
})
},
updateSetting ({ commit }, val) {
if (val.logs) delete val.logs
return new Promise((resolve, reject) => {
appDB.update({ _id: val._id }, { ...val }, (err, numReplaced) => {
if (err) {
reject(err)
} else {
console.log(numReplaced)
resolve()
}
})
})
}
}

export default {
state,
mutations,
actions
}
4 changes: 4 additions & 0 deletions src/renderer/store/task-mixin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mapState } from 'vuex'
import toBottom from '@/utils/toBottom'
const _ = require('lodash')
const fs = require('fs')
const join = require('path').join
Expand Down Expand Up @@ -72,6 +73,9 @@ const taskMixin = {
type
}
})
// TODO 更新
const el = document.getElementById('log-view')
if (el) toBottom(el)
},
// clean task log by task id
_cleanTaskLogByTaskId (taskId) {
Expand Down
22 changes: 22 additions & 0 deletions src/renderer/utils/toBottom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// el is the document node need to bottom
function toBottom (el) {
const cubic = value => Math.pow(value, 3)
const easeInOutCubic = value => value < 0.5
? cubic(value * 2) / 2
: 1 - cubic((1 - value) * 2) / 2
const beginTime = Date.now()
const bottomValue = el.scrollHeight
const rAF = window.requestAnimationFrame || (func => setTimeout(func, 16))
const frameFunc = () => {
const progress = (Date.now() - beginTime) / 500
if (progress < 1) {
el.scrollTop += bottomValue * easeInOutCubic(progress)
rAF(frameFunc)
} else {
el.scrollTop = bottomValue
}
}
rAF(frameFunc)
}

export default toBottom
50 changes: 25 additions & 25 deletions src/renderer/views/home/InstanceList.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
<!-- table -->
<a-table style="overflow-y: auto" :columns="columns" rowKey="_id" :data-source="instanceList">
<a-table :columns="columns" rowKey="_id" :data-source="instanceList" :scroll="{ x: 1200 }">
<span slot="status" slot-scope="status">
<a-tag :color="taskStatusOptions[status].color">
{{ taskStatusOptions[status].desc }}
Expand All @@ -10,33 +10,33 @@
<span slot="preCommandList" slot-scope="preCommandList">
<p v-for="(item, index) in preCommandList" :key="index">
<template v-if="item.path && item.command">
<a-tag>{{ item.path }}</a-tag> {{ item.command }}
<span class="path-span">{{ item.path }}</span>
{{ item.command }}
</template>
</p>
</span>
<span slot="releasePath" slot-scope="releasePath">
<span class="path-span">{{ releasePath }}</span>
</span>
<span slot="localPreCommand" slot-scope="localPreCommand">
<p v-if="localPreCommand.path && localPreCommand.command">
<a-tag>{{ localPreCommand.path }}</a-tag>
<span class="path-span">{{ localPreCommand.path }}</span>
<template>{{ localPreCommand.command }}</template>
</p>
</span>
<span slot="projectPath" slot-scope="projectPath">
<a-icon v-if="projectPath" theme="twoTone"
:title="checkDirExist(projectPath) ? 'exist' : 'not exist'"
:type="checkDirExist(projectPath) ? 'check-circle' : 'warning'"
:two-tone-color="checkDirExist(projectPath) ? '#67C23A' : '#E6A23C'" />
{{ projectPath }}
<span class="path-span">{{ projectPath }}</span>
</span>
<span slot="localPostCommand" slot-scope="localPostCommand">
<p v-if="localPostCommand.path && localPostCommand.command">
<a-tag>{{ localPostCommand.path }}</a-tag>
<span class="path-span">{{ localPostCommand.path }}</span>
<template>{{ localPostCommand.command }}</template>
</p>
</span>
<span slot="postCommandList" slot-scope="postCommandList">
<p v-for="(item, index) in postCommandList" :key="index">
<template v-if="item.path && item.command">
<a-tag>{{ item.path }}</a-tag> {{ item.command }}
<span class="path-span">{{ item.path }}</span> {{ item.command }}
</template>
</p>
</span>
Expand Down Expand Up @@ -70,7 +70,6 @@ import dayjs from 'dayjs'
import TaskForm from './TaskForm'
import taskMixin from '@/store/task-mixin'
import instanceMixin from '@/store/instance-mixin'
const fs = require('fs')
export default {
name: 'InstanceList',
mixins: [taskMixin, instanceMixin],
Expand All @@ -84,7 +83,9 @@ export default {
columns: [
{
dataIndex: 'name',
title: '名称'
title: '名称',
fixed: 'left',
width: 100
},
{
dataIndex: 'server.name',
Expand All @@ -101,7 +102,8 @@ export default {
},
{
dataIndex: 'releasePath',
title: '发布路径'
title: '发布路径',
scopedSlots: { customRender: 'releasePath' }
},
{
dataIndex: 'localPreCommand',
Expand All @@ -125,7 +127,8 @@ export default {
},
{
dataIndex: 'lastExecutedTime',
title: '上次执行时间'
title: '上次执行时间',
ellipsis: true
},
{
dataIndex: 'lastCostTime',
Expand All @@ -139,7 +142,9 @@ export default {
{
title: '操作',
key: 'action',
scopedSlots: { customRender: 'action' }
scopedSlots: { customRender: 'action' },
fixed: 'right',
width: 120
}
]
}
Expand All @@ -152,7 +157,6 @@ export default {
},
// on run task
onRunTask (val) {
this.$emit('switchTab', '2')
const task = JSON.parse(JSON.stringify(val))
task.lastExecutedTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
this._addPendingTaskList(JSON.parse(JSON.stringify(task)))
Expand All @@ -173,20 +177,16 @@ export default {
this.deployActionVisible = false
await this.editInstanceList(instance)
this.getInstanceList()
},
// 检查本地目录是否存在
checkDirExist (path) {
try {
fs.accessSync(path)
return true
} catch (err) {
console.log(err)
}
}
}
}
</script>
<style lang="stylus" scoped>
.path-span
text-decoration underline
&:hover
color #409EFF
.anticon
margin-right 6px
font-size 18px
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/home/TaskCenter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</a-popconfirm>
<a-icon title="edit" @click="showEditForm(item)" type="edit" />
</template>
<LogView :logs="item.logs" />
<LogView id="log-view" :logs="item.logs" />
</a-card>
</a-tab-pane>
</a-tabs>
Expand Down
50 changes: 48 additions & 2 deletions src/renderer/views/home/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="app-wrap">
<a-tabs v-model="activeKey" @tabClick="onTabClick">
<a-tabs v-model="activeKey" :tab-position="tabPosition" @tabClick="onTabClick">
<a-tab-pane key="1" tab="Server Center">
<div class="flex-card-wrap">
<ServerList />
Expand All @@ -22,7 +22,26 @@
<a-tab-pane key="3" tab="Task Instance">
<InstanceList @switchTab="handleSwitchTab" />
</a-tab-pane>
<a-icon @click="visible = true" style="fontSize: 18px; margin: 1rem" type="setting" slot="tabBarExtraContent" />
</a-tabs>
<!-- drawer -->
<a-drawer
title="Setting"
placement="right"
:closable="false"
:visible="visible"
@close="visible = false"
>
<a-form>
<a-form-item label="Tab Position" layout="vertical">
<a-radio-group @change="updateTabPosition" v-model="tabPosition" button-style="solid">
<a-radio-button v-for="(item, index) in tabPositionOpions" :key="index" :value="item">
{{ item }}
</a-radio-button>
</a-radio-group>
</a-form-item>
</a-form>
</a-drawer>
<!-- footer -->
<footer class="footer">
<p title="version">
Expand All @@ -46,13 +65,14 @@ import TaskCenter from './TaskCenter'
import InstanceList from './InstanceList'
import taskMixin from '@/store/task-mixin'
import instanceMixin from '@/store/instance-mixin'
import appMixin from '@/store/app-mixin'
import HelpView from './HelpView'
import { version } from '@/../../package.json'
const { shell } = require('electron')
export default {
name: 'Home',
mixins: [taskMixin, instanceMixin],
mixins: [taskMixin, instanceMixin, appMixin],
components: {
ServerList,
AppData,
Expand All @@ -63,12 +83,30 @@ export default {
},
data () {
return {
tabPosition: 'top',
visible: false,
tabPositionOpions: [
'left',
'top',
'right'
],
activeKey: '1',
deployActionVisible: false,
defaultForm: {},
version
}
},
async created () {
const setting = await this.getSetting()
if (!setting) {
console.log('init app setting')
await this.initSetting({
tabPosition: 'top'
})
await this.getSetting()
}
this.tabPosition = this.setting.tabPosition
},
methods: {
// on tab click
onTabClick (activeKey) {
Expand Down Expand Up @@ -105,6 +143,14 @@ export default {
// open url
openUrl (url) {
shell.openExternal(url)
},
// update tabPosition
async updateTabPosition (event) {
await this.updateSetting({
...this.setting,
tabPosition: event.target.value
})
this.getSetting()
}
}
}
Expand Down

0 comments on commit a7d3c2e

Please sign in to comment.