CreateLabelDialog.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: CreateLabelDialog.vue
  4. * @Description: 负面标签-创建弹窗
  5. * @Author: xinyan
  6. */
  7. import { Close, Finished } from '@element-plus/icons-vue';
  8. import { ElMessage, FormInstance, FormRules } from 'element-plus';
  9. import { useResponse } from '/@/utils/useResponse';
  10. import * as api from '../api';
  11. const props = defineProps({
  12. rowData: <any>Object,
  13. });
  14. const { rowData } = props;
  15. const loading = ref(false);
  16. const createOpen = defineModel({ default: false });
  17. const createDialog = <Ref>useTemplateRef('createDialog');
  18. const emit = defineEmits(['refresh']);
  19. interface RuleForm {
  20. raw_label: any;
  21. kind: any;
  22. }
  23. const ruleFormRef = ref<FormInstance>();
  24. const ruleForm = reactive<RuleForm>({
  25. raw_label: '',
  26. kind: '',
  27. });
  28. const rules = reactive<FormRules<RuleForm>>({
  29. raw_label: [{ required: true, message: '请输入原始标签', trigger: 'blur' }],
  30. });
  31. const submitForm = async (formEl: FormInstance | undefined) => {
  32. if (!formEl) return;
  33. await formEl.validate(async (valid, fields) => {
  34. if (valid) {
  35. const body = {
  36. review: rowData.id,
  37. raw_label: ruleForm.raw_label,
  38. kind: ruleForm.kind,
  39. };
  40. const res = await useResponse(api.createNegativeTags, body, loading);
  41. if (res.code === 2000) {
  42. ElMessage.success({ message: '创建成功', plain: true, icon: 'CirclePlus' });
  43. createOpen.value = false;
  44. emit('refresh');
  45. }
  46. } else {
  47. // createOpen.value = false;
  48. ElMessage.error('创建失败,请检查表单');
  49. }
  50. });
  51. };
  52. function cancelDialog() {
  53. resetForm(ruleFormRef.value);
  54. createDialog.value.visible = false;
  55. }
  56. const resetForm = (formEl: FormInstance | undefined) => {
  57. if (!formEl) return;
  58. formEl.resetFields();
  59. };
  60. </script>
  61. <template>
  62. <el-dialog
  63. ref="createDialog"
  64. v-model="createOpen"
  65. :close-on-click-modal="false"
  66. :close-on-press-escape="false"
  67. :title="`负面标签 - 创建 `"
  68. style="width: 35%"
  69. >
  70. <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" class="mx-2.5 mt-5" label-width="auto" status-icon>
  71. <el-row :gutter="20">
  72. <el-col :span="24">
  73. <el-form-item class="font-medium" label="原始标签" prop="raw_label">
  74. <el-input v-model="ruleForm.raw_label" type="textarea" maxlength="150" show-word-limit :autosize="{ minRows: 2, maxRows: 4 }"/>
  75. </el-form-item>
  76. <el-form-item class="font-medium" label="类别" prop="kind">
  77. <el-input v-model="ruleForm.kind" type="textarea" maxlength="150" show-word-limit/>
  78. </el-form-item>
  79. </el-col>
  80. </el-row>
  81. </el-form>
  82. <template #footer>
  83. <el-button :icon="Close" @click="cancelDialog">取 消</el-button>
  84. <el-button :icon="Finished" :loading="loading" type="primary" @click="submitForm(ruleFormRef)">确 定</el-button>
  85. </template>
  86. </el-dialog>
  87. </template>
  88. <style scoped></style>