refs #48 Add another account and change account
This commit is contained in:
parent
8c8a63e860
commit
1c9d36c9e6
|
@ -3,14 +3,12 @@
|
|||
<el-menu
|
||||
:default-active="defaultActive"
|
||||
class="el-menu-vertical account-menu"
|
||||
@open="accountSelected"
|
||||
@close="accountClosed"
|
||||
:collapse="isCollapse"
|
||||
:route="true"
|
||||
background-color="#4a5664"
|
||||
text-color="#909399"
|
||||
active-text-color="#ffffff">
|
||||
<el-menu-item :index="index.toString()" v-for="(account, index) in accounts" v-bind:key="account._id" :route="{path: `/${account._id}/home`}">
|
||||
<el-menu-item :index="index.toString()" v-for="(account, index) in accounts" v-bind:key="account._id" :route="{path: `/${account._id}/home`}" @click="select(account)">
|
||||
<i class="el-icon-menu"></i>
|
||||
<span slot="title">{{ account.domain }}</span>
|
||||
</el-menu-item>
|
||||
|
@ -20,7 +18,7 @@
|
|||
</el-menu-item>
|
||||
</el-menu>
|
||||
<div class="space">
|
||||
<router-view></router-view>
|
||||
<router-view :key="$route.params.id"></router-view>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -59,14 +57,12 @@ export default {
|
|||
})
|
||||
},
|
||||
methods: {
|
||||
accountSelected (key, keyPath) {
|
||||
console.log(key, keyPath)
|
||||
},
|
||||
accountClosed (key, keyPath) {
|
||||
console.log(key, keyPath)
|
||||
},
|
||||
login () {
|
||||
return this.$router.push({ path: '/login' })
|
||||
},
|
||||
select (account) {
|
||||
console.log(account._id)
|
||||
return this.$router.push({ path: `/${account._id}/home` })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,57 +22,64 @@ export default {
|
|||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.7)'
|
||||
})
|
||||
this.$store.dispatch('TimelineSpace/watchShortcutEvents')
|
||||
this.$store.dispatch('TimelineSpace/fetchAccount', this.$route.params.id)
|
||||
.then((account) => {
|
||||
this.$store.dispatch('TimelineSpace/fetchHomeTimeline', account)
|
||||
.then(() => {
|
||||
loading.close()
|
||||
})
|
||||
.catch(() => {
|
||||
loading.close()
|
||||
this.$message({
|
||||
message: 'Could not fetch timeline',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
this.$store.dispatch('TimelineSpace/username', account)
|
||||
.catch(() => {
|
||||
this.$message({
|
||||
message: 'Could not fetch username',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
this.$store.dispatch('TimelineSpace/fetchNotifications', account)
|
||||
.catch(() => {
|
||||
this.$message({
|
||||
message: 'Could not fetch notification',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
|
||||
.catch(() => {
|
||||
this.$message({
|
||||
message: 'Could not start user streaming',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
this.initialize()
|
||||
.then(() => {
|
||||
loading.close()
|
||||
})
|
||||
.catch(() => {
|
||||
loading.close()
|
||||
})
|
||||
},
|
||||
beforeDestroy () {
|
||||
this.$store.dispatch('TimelineSpace/stopUserStreaming')
|
||||
},
|
||||
methods: {
|
||||
async clear () {
|
||||
await this.$store.dispatch('TimelineSpace/clearAccount')
|
||||
await this.$store.dispatch('TimelineSpace/clearUsername')
|
||||
await this.$store.dispatch('TimelineSpace/clearTimeline')
|
||||
await this.$store.dispatch('TimelineSpace/clearNotifications')
|
||||
await this.$store.dispatch('TimelineSpace/removeShortcutEvents')
|
||||
return 'clear'
|
||||
},
|
||||
async initialize () {
|
||||
await this.clear()
|
||||
|
||||
this.$store.dispatch('TimelineSpace/watchShortcutEvents')
|
||||
try {
|
||||
const account = await this.$store.dispatch('TimelineSpace/fetchAccount', this.$route.params.id)
|
||||
try {
|
||||
await this.$store.dispatch('TimelineSpace/fetchHomeTimeline', account)
|
||||
} catch (err) {
|
||||
this.$message({
|
||||
message: 'Could not fetch timeline',
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
try {
|
||||
await this.$store.dispatch('TimelineSpace/username', account)
|
||||
} catch (err) {
|
||||
this.$message({
|
||||
message: 'Could not fetch username',
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
try {
|
||||
await this.$store.dispatch('TimelineSpace/fetchNotifications', account)
|
||||
} catch (err) {
|
||||
this.$message({
|
||||
message: 'Could not fetch notification',
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
this.$store.dispatch('TimelineSpace/startUserStreaming', account)
|
||||
} catch (err) {
|
||||
this.$message({
|
||||
message: 'Could not find account',
|
||||
type: 'error'
|
||||
})
|
||||
})
|
||||
},
|
||||
beforeDestroy () {
|
||||
this.$store.dispatch('TimelineSpace/clearAccount')
|
||||
this.$store.dispatch('TimelineSpace/clearUsername')
|
||||
this.$store.commit('TimelineSpace/clearTimeline')
|
||||
this.$store.commit('TimelineSpace/clearNotifications')
|
||||
this.$store.dispatch('TimelineSpace/stopUserStreaming')
|
||||
this.$store.dispatch('TimelineSpace/removeShortcutEvents')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -77,7 +77,7 @@ const TimelineSpace = {
|
|||
})
|
||||
},
|
||||
clearTimeline (state) {
|
||||
state.timeline = []
|
||||
state.homeTimeline = []
|
||||
},
|
||||
clearNotifications (state) {
|
||||
state.notifications = []
|
||||
|
@ -88,9 +88,11 @@ const TimelineSpace = {
|
|||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('get-local-account', id)
|
||||
ipcRenderer.once('error-get-local-account', (event, err) => {
|
||||
ipcRenderer.removeAllListeners('response-get-local-account')
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-get-local-account', (event, account) => {
|
||||
ipcRenderer.removeAllListeners('error-get-local-account')
|
||||
commit('updateAccount', account)
|
||||
resolve(account)
|
||||
})
|
||||
|
@ -129,11 +131,12 @@ const TimelineSpace = {
|
|||
})
|
||||
})
|
||||
},
|
||||
stopUserStreaming ({ commit }) {
|
||||
async stopUserStreaming ({ commit }) {
|
||||
ipcRenderer.removeAllListeners('update-start-user-streaming')
|
||||
ipcRenderer.removeAllListeners('notification-start-user-streaming')
|
||||
ipcRenderer.removeAllListeners('error-start-user-streaming')
|
||||
ipcRenderer.send('stop-user-streaming')
|
||||
return 'stopUserStreaming'
|
||||
},
|
||||
watchShortcutEvents ({ commit }) {
|
||||
ipcRenderer.on('CmdOrCtrl+N', () => {
|
||||
|
@ -144,9 +147,10 @@ const TimelineSpace = {
|
|||
console.log('reply')
|
||||
})
|
||||
},
|
||||
removeShortcutEvents () {
|
||||
async removeShortcutEvents () {
|
||||
ipcRenderer.removeAllListeners('CmdOrCtrl+N')
|
||||
ipcRenderer.removeAllListeners('CmdOrCtrl+R')
|
||||
return 'removeShortcutEvents'
|
||||
},
|
||||
fetchHomeTimeline ({ commit }, account) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -178,7 +182,15 @@ const TimelineSpace = {
|
|||
})
|
||||
})
|
||||
},
|
||||
clearAccount ({ commit }) {
|
||||
async clearTimeline ({ commit }) {
|
||||
commit('clearTimeline')
|
||||
return 'clearTimeline'
|
||||
},
|
||||
async clearNotifications ({ commit }) {
|
||||
commit('clearNotifications')
|
||||
return 'clearNotifications'
|
||||
},
|
||||
async clearAccount ({ commit }) {
|
||||
commit(
|
||||
'updateAccount',
|
||||
{
|
||||
|
@ -186,9 +198,11 @@ const TimelineSpace = {
|
|||
_id: ''
|
||||
}
|
||||
)
|
||||
return 'clearAccount'
|
||||
},
|
||||
clearUsername ({ commit }) {
|
||||
async clearUsername ({ commit }) {
|
||||
commit('updateUsername', '')
|
||||
return 'clearUsername'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue