<!--
  系统配置页 — 文件对象存储配置
-->
<template>
  <div class="config-page">
    <el-card shadow="never">
      <template #header>
        <div class="card-header-title">
          <el-icon><FolderOpened /></el-icon>
          <span>文件对象存储配置</span>
        </div>
      </template>
      <el-form ref="formRef" :model="form" label-width="140px" style="max-width:600px">
        <el-form-item label="文件服务地址">
          <el-input v-model="form.serviceUrl" placeholder="https://file.wg.zgitm.com" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-permission="'system:config:save'" :loading="saving" @click="handleSave">
            <el-icon><Check /></el-icon>保存配置
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { FolderOpened, Check } from '@element-plus/icons-vue'
import request from '@/utils/request'

const saving = ref(false)
const form = reactive({ serviceUrl: '' })

onMounted(async () => {
  try {
    const res = await request.get('/zgapi/v1/admin/config/list')
    const list: any[] = res.data ?? []
    const cfg = list.find((c: any) => c.configKey === 'file.service.url')
    if (cfg) form.serviceUrl = cfg.configValue || ''
  } catch { /* ignore */ }
})

async function handleSave() {
  saving.value = true
  try {
    await request.post('/zgapi/v1/admin/config/save', {
      configKey: 'file.service.url',
      configValue: form.serviceUrl,
      description: '外部文件对象存储服务地址',
    })
    ElMessage.success('保存成功')
  } catch { /* ignore */ } finally { saving.value = false }
}
</script>

<style scoped>
.config-page { max-width:700px; }
.card-header-title { display:flex; align-items:center; gap:8px; font-weight:600; font-size:14px; color:var(--text-primary); }
</style>
