<template>
  <h2>
    系统
  </h2>
  <hr>
  <div>
    <hr>
    <div class="section mb-2">
      <h4>数据采集模式配置</h4>
      <div>
        保存目录：
        <input type="text" class="form-control" v-model="debug_upload_dir" />
      </div>
      <div>
        类别标签：
        <input type="text" class="form-control" v-model="debug_upload_neg_or_pos" />
      </div>
      <button class="my-1 btn btn-primary" @click="save_debug_upload_configs">保存</button>
    </div>
  </div>
  <div class="fade-in">
    <div class="section">
      <h4>
        备份和恢复
      </h4>
      <hr>
      <BackupRestore />
      <Modal
        title="删除"
        body="确定要删除吗？"
        ref="delete_modal"
        ></Modal>
    </div>
  </div>
</template>

<script>
import BackupRestore from '../components/backup-restore';

export default {
  name: 'SystemSettings',
  props: [],
  components: {
    BackupRestore,
  },
  data: function () {
    return {
      debug_upload_dir: '',
      debug_upload_neg_or_pos: '',
    };
  },
  computed: {
  },
  methods: {
    async reload() {
      var r = await this.$root.api_get("/api/v1/global-config/?name=debug_upload_dir");
      this.debug_upload_dir = r.data.value || '';

      r = await this.$root.api_get("/api/v1/global-config/?name=debug_upload_neg_or_pos");
      this.debug_upload_neg_or_pos = r.data.value || '';
    },
    async save_debug_upload_configs() {
      await this.$root.api_post("/api/v1/global-config/", {
        name: 'debug_upload_dir',
        value: this.debug_upload_dir,
      });
      await this.$root.api_post("/api/v1/global-config/", {
        name: 'debug_upload_neg_or_pos',
        value: this.debug_upload_neg_or_pos,
      });
      await this.reload();
      this.$root.notify("保存成功", "数据采集模式配置已更新");
    },
  },
  mounted() {
    this.reload();
  },
}
</script>

<style scoped>
div.section {
  border: 1px solid #888;
  border-radius: 5px;
  padding: 1rem;
}
</style>

