Skip to content

Commit

Permalink
按钮效果
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyun8023 committed Aug 17, 2024
1 parent cc8a1eb commit 0cd4a68
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions app/calibre-pages/src/views/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<el-table-column fixed="right" label="Action">
<template #default="scope">
<el-button
v-loading="scope.row.loading"
element-loading-background="rgba(122, 122, 122, 0.8)"
type="primary"
size="default"
@click="scope.row.func(scope.row)"
v-loading="scope.row.loading"
element-loading-background="rgba(122, 122, 122, 0.8)"
type="primary"
size="default"
@click="scope.row.func(scope.row)"
>
执行
{{scope.row.operator}}
</el-button>
</template>
</el-table-column>
Expand All @@ -22,16 +22,8 @@
</template>

<script lang="ts">
import { h } from 'vue'
import {
ElButton,
ElContainer,
ElMain,
ElNotification,
ElRow,
ElTable,
ElTableColumn
} from 'element-plus'
import {h} from 'vue'
import {ElButton, ElContainer, ElMain, ElNotification, ElRow, ElTable, ElTableColumn} from 'element-plus'
export default {
name: 'Setting',
Expand All @@ -50,19 +42,22 @@ export default {
name: '更新索引',
description: '更新MeiliSearch索引',
loading: false,
func: this.updateIndex
func: this.updateIndex,
operator: '执行'
},
{
name: '切换主备索引',
description: '切换主备索引',
loading: false,
func: this.switchIndex
func: this.switchIndex,
operator: '执行'
},
{
name: '批量管理',
description: '批量管理书籍',
loading: false,
func: this.redirectToManagerPage
func: this.redirectToManagerPage,
operator: '前往'
}
]
}
Expand All @@ -71,55 +66,55 @@ export default {
async switchIndex(config: { loading: boolean }) {
config.loading = true
try {
const response = await fetch('/api/index/switch', { method: 'POST' })
const response = await fetch('/api/index/switch', {method: 'POST'})
config.loading = false
if (response.ok) {
const responseData = await response.json()
ElNotification({
title: 'Index switched successfully.',
message: h('i', { style: 'color: teal' }, 'Index switched successfully.'),
message: h('i', {style: 'color: teal'}, 'Index switched successfully.'),
type: 'success'
})
} else {
ElNotification({
title: 'Failed to update index.',
message: h('i', { style: 'color: red' }, 'Error: ' + response.statusText),
message: h('i', {style: 'color: red'}, 'Error: ' + response.statusText),
type: 'error'
})
}
} catch (error) {
config.loading = false
ElNotification({
title: 'Failed to update index.',
message: h('i', { style: 'color: red' }, 'Error: ' + (error as Error).message),
message: h('i', {style: 'color: red'}, 'Error: ' + (error as Error).message),
type: 'error'
})
}
},
async updateIndex(config: { loading: boolean }) {
config.loading = true
try {
const response = await fetch('/api/index/update', { method: 'POST' })
const response = await fetch('/api/index/update', {method: 'POST'})
config.loading = false
if (response.ok) {
const responseData = await response.json()
ElNotification({
title: 'Index updated successfully.',
message: h('i', { style: 'color: teal' }, 'Index updated successfully.'),
message: h('i', {style: 'color: teal'}, 'Index updated successfully.'),
type: 'success'
})
} else {
ElNotification({
title: 'Failed to update index.',
message: h('i', { style: 'color: red' }, 'Error: ' + response.statusText),
message: h('i', {style: 'color: red'}, 'Error: ' + response.statusText),
type: 'error'
})
}
} catch (error) {
config.loading = false
ElNotification({
title: 'Failed to update index.',
message: h('i', { style: 'color: red' }, 'Error: ' + (error as Error).message),
message: h('i', {style: 'color: red'}, 'Error: ' + (error as Error).message),
type: 'error'
})
}
Expand Down

0 comments on commit 0cd4a68

Please sign in to comment.