From 3012e2e1f962f7b7ad3d286440a335cd32efd54d Mon Sep 17 00:00:00 2001 From: marvzhang Date: Mon, 20 Apr 2020 11:44:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5API=20Token=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/setting/Setting.vue | 125 ++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/setting/Setting.vue b/frontend/src/views/setting/Setting.vue index eb1ed344..ae33be9b 100644 --- a/frontend/src/views/setting/Setting.vue +++ b/frontend/src/views/setting/Setting.vue @@ -169,6 +169,65 @@ + + + + + +
+ + {{$t('Add')}} + +
+ + + + + + + + +
+ +
@@ -285,7 +344,8 @@ export default { } }, isAllowSendingStatistics: localStorage.getItem('useStats') === '1', - isEnableTutorial: localStorage.getItem('enableTutorial') === '1' + isEnableTutorial: localStorage.getItem('enableTutorial') === '1', + apiTokens: [] } }, computed: { @@ -368,12 +428,63 @@ export default { onEnableTutorialChange (value) { this.$message.success(this.$t('Saved successfully')) localStorage.setItem('enableTutorial', value ? '1' : '0') + }, + onAddApiToken () { + this.$confirm(this.$t('Are you sure to add an API token?'), { + confirmButtonText: this.$t('Confirm'), + cancelButtonText: this.$t('Cancel'), + type: 'warning' + }).then(async () => { + const res = await this.$request.put('/tokens') + if (!res.data.error) { + this.$message.success(this.$t('Added API token successfully')) + await this.getApiTokens() + } + }) + }, + onDeleteToken (row) { + this.$confirm(this.$t('Are you sure to delete this API token?'), { + confirmButtonText: this.$t('Confirm'), + cancelButtonText: this.$t('Cancel'), + type: 'warning' + }).then(async () => { + const res = await this.$request.delete(`/tokens/${row._id}`) + if (!res.data.error) { + this.$message.success(this.$t('Deleted API token successfully')) + await this.getApiTokens() + } + }) + }, + async addApiToken () { + await this.$request.put('/tokens') + }, + async getApiTokens () { + const res = await this.$request.get('/tokens') + this.apiTokens = res.data.data + }, + toggleTokenVisible (row) { + this.$set(row, 'visible', !row.visible) + }, + getMaskValue (str) { + let s = '' + for (let i = 0; i < str.length; i++) { + s += '*' + } + return s + }, + copyToken (str) { + const input = document.getElementById('clipboard') + input.value = str + input.select() + document.execCommand('copy') + this.$message.success(this.$t('Token copied')) } }, async created () { await this.$store.dispatch('user/getInfo') await this.$store.dispatch('user/getGlobalVariable') this.getUserInfo() + await this.getApiTokens() }, mounted () { if (!this.$utils.tour.isFinishedTour('setting')) { @@ -402,4 +513,16 @@ export default { .setting-form >>> .el-form-item__label { height: 40px; } + + .actions { + margin-bottom: 10px; + text-align: right; + } + + #clipboard { + position: fixed; + z-index: -99999; + top: 9999px; + right: 9999px; + }