feat(admin): add edit flows for all catalogs and member authentik sync
This commit is contained in:
@@ -18,12 +18,17 @@
|
||||
|
||||
<el-table v-else :data="modules" stripe border class="w-full shadow-sm">
|
||||
<template #empty><el-empty description="目前無模組" /></template>
|
||||
<el-table-column prop="system_key" label="System Key" width="140" />
|
||||
<el-table-column prop="module_key" label="Module Key" width="160" />
|
||||
<el-table-column prop="system_key" label="System" width="140" />
|
||||
<el-table-column prop="module_key" label="Module Key" width="180" />
|
||||
<el-table-column prop="name" label="名稱" min-width="180" />
|
||||
<el-table-column prop="status" label="狀態" width="120" />
|
||||
<el-table-column label="操作" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-button size="small" @click="openEdit(row)">編輯</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 新增 Dialog -->
|
||||
<el-dialog v-model="showDialog" title="新增模組" @close="resetForm">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
|
||||
<el-form-item label="System Key" prop="system_key">
|
||||
@@ -41,6 +46,27 @@
|
||||
<el-button type="primary" :loading="submitting" @click="handleCreate">確認</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="showEditDialog" title="編輯模組" @close="resetEditForm">
|
||||
<el-form :model="editForm" label-width="120px">
|
||||
<el-form-item label="Module Key">
|
||||
<el-input :model-value="editForm.module_key" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="名稱">
|
||||
<el-input v-model="editForm.name" />
|
||||
</el-form-item>
|
||||
<el-form-item label="狀態">
|
||||
<el-select v-model="editForm.status" style="width: 100%">
|
||||
<el-option label="active" value="active" />
|
||||
<el-option label="inactive" value="inactive" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="showEditDialog = false">取消</el-button>
|
||||
<el-button type="primary" :loading="savingEdit" @click="handleEdit">儲存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -48,7 +74,7 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Plus } from '@element-plus/icons-vue'
|
||||
import { getModules, createModule } from '@/api/modules'
|
||||
import { getModules, createModule, updateModule } from '@/api/modules'
|
||||
|
||||
const modules = ref([])
|
||||
const loading = ref(false)
|
||||
@@ -57,8 +83,11 @@ const errorMsg = ref('')
|
||||
const showDialog = ref(false)
|
||||
const submitting = ref(false)
|
||||
const formRef = ref()
|
||||
const showEditDialog = ref(false)
|
||||
const savingEdit = ref(false)
|
||||
|
||||
const form = ref({ system_key: '', module_key: '', name: '' })
|
||||
const editForm = ref({ module_key: '', name: '', status: 'active' })
|
||||
const rules = {
|
||||
system_key: [{ required: true, message: '請輸入 System Key', trigger: 'blur' }],
|
||||
module_key: [{ required: true, message: '請輸入 Module Key', trigger: 'blur' }],
|
||||
@@ -85,6 +114,19 @@ function resetForm() {
|
||||
form.value = { system_key: '', module_key: '', name: '' }
|
||||
}
|
||||
|
||||
function openEdit(row) {
|
||||
editForm.value = {
|
||||
module_key: row.module_key,
|
||||
name: row.name,
|
||||
status: row.status || 'active'
|
||||
}
|
||||
showEditDialog.value = true
|
||||
}
|
||||
|
||||
function resetEditForm() {
|
||||
editForm.value = { module_key: '', name: '', status: 'active' }
|
||||
}
|
||||
|
||||
async function handleCreate() {
|
||||
const valid = await formRef.value.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
@@ -102,5 +144,22 @@ async function handleCreate() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleEdit() {
|
||||
savingEdit.value = true
|
||||
try {
|
||||
await updateModule(editForm.value.module_key, {
|
||||
name: editForm.value.name,
|
||||
status: editForm.value.status
|
||||
})
|
||||
ElMessage.success('更新成功')
|
||||
showEditDialog.value = false
|
||||
await load()
|
||||
} catch (err) {
|
||||
ElMessage.error('更新失敗')
|
||||
} finally {
|
||||
savingEdit.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user