EditLabelDialog.vue 2.8 KB

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