<!-- 系统管理 语音管理 -->

<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="20" :xs="24">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:tts:add']"
              >新增
            </el-button>
          </el-col>
        </el-row>
      </el-col>
    </el-row>

    <!-- 对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="文本" prop="text">
          <el-input
            v-model="form.text"
            placeholder="请输入语音文本"
            maxlength="200"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name:"SystemTTS",
  data() {
    return {
      title: "转换语音",
      // 遮罩层
      loading: true,
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {
        text: "",
      },
      // 表单校验
      rules: {
        text: [
          { required: true, message: "语音文本不能为空", trigger: "blur" },
          {
            min: 1,
            max: 200,
            message: "语音文本长度必须介于 1 和 200 之间",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {},
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        text: "",
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "转换语音";
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log(this.form);
          this.open = false;
          this.$download.zip(
            "/system/tts/getAudio?text=" + this.form.text,
            "ruoyi"
          );
        }
      });
    },
  },
};
</script>
